#include <bits/stdc++.h>
#define FOR(I,X,Y) for(long int I=X;I<Y;I++)
#define REP(I,X) for(long int I=X;I>=0;I--)
#define INF 1e9+7
using namespace std;

int main(){
  int a,b,c;
  vector<int> ans;
  while(1){
    cin >> a >> b >> c;
    if(!(a|| b || c))break;
    int N,i,j,k,l;
    cin >> N;
    set<int> unbroken;
    set<int> broken;
    int ii[N],jj[N],kk[N],ll[N];
    FOR(i,0,N)cin >> ii[i] >> jj[i] >> kk[i] >> ll[i];
    FOR(count1,0,N)FOR(count2,0,N){
      int i = ii[count2],j = jj[count2],k = kk[count2],l = ll[count2];
      if(l){
        unbroken.insert(i);
        unbroken.insert(j);
        unbroken.insert(k);
      }
      else{
        if(unbroken.count(i) && unbroken.count(j))broken.insert(k);
        if(unbroken.count(j) && unbroken.count(k))broken.insert(i);
        if(unbroken.count(k) && unbroken.count(i))broken.insert(j);
      }
    }
    FOR(i,1,a+b+c+1){
      if(unbroken.count(i))ans.push_back(1);
      else if(broken.count(i))ans.push_back(0);
      else ans.push_back(2);
    }
  }
  for(auto x:ans)cout << x << endl;
}

#include <bits/stdc++.h>
using namespace std;
const int maxn=112345;
int n,x[maxn],l,q,f[maxn][20];
int main()
{
    scanf("%d",&n);
    for (int i=1;i<=n;++i) scanf("%d",&x[i]);
    scanf("%d%d",&l,&q);
    for (int i=1;i<n;++i) {
        int t=upper_bound(x+1,x+1+n,x[i]+l)-x-1;
        f[i][0]=t;
    }
    f[n][0]=f[n+1][0]=n+1;
    for (int i=1;i<20;++i)
        for (int j=1;j<=n+1;++j)
            f[j][i]=f[f[j][i-1]][i-1];
    while (q--) {
        int a,b;scanf("%d%d",&a,&b);
        if (a>b) swap(a,b);
        int num=0;
        for (int i=19;i>=0;--i)
            if (f[a][i]<=b) {
                num+=1<<i;
                a=f[a][i];
            }
        printf("%d\n",num+(a!=b));
    }
    return 0;
}


// #include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <map>
#include <math.h>
#include <algorithm> // std::sort, std::min, std::next_permutation, std::lower_bound
#include <iomanip> // std::setprecision
#include <cmath> // std::ceil
#include <numeric> // std::gcd, std::lcm
#include <limits> // std::numeric_limits<long int>::max()
#include <unordered_map>
#include <map>
#include <cmath> // std::atan2
#include <deque>

using namespace std;
typedef long long ll;
#define INF 1999999999
#define MODA 1000000007
#define rep(i,n) for (long long i = 0; i < (n); ++i)

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> V(N);
  rep (i, N) cin >> V[i];

  deque<ll> treasures;
  rep (i, N) treasures.push_back(V[i]);
  ll ans = numeric_limits<ll>::min();
  for (ll numpop = min(N, K); numpop >= 0; numpop--) {
    ll numpush = K - numpop;
    for (ll numpopL = 0; numpopL < numpop + 1; numpopL++) {
      ll numpopR = numpop - numpopL;
      vector<ll> mytreasures;
      rep (i, numpopL) {
        mytreasures.push_back(treasures.at(i));
        // cerr <<"L"<< mytreasures.back() << endl;
      }
      rep (i, numpopR) {
        mytreasures.push_back(treasures.at(N - i - 1));
        // cerr <<"R"<< mytreasures.back() << endl;
      }
      ll sum = 0;
      for (const auto mytreasure : mytreasures) {
        sum += mytreasure;
      }
      sort(mytreasures.begin(), mytreasures.end());
      for (ll i = 0; i < mytreasures.size() && i < numpush && mytreasures.at(i) < 0;
             ++i) {
        sum -= mytreasures.at(i);
      }
      ans = max(ans, sum);
    }
  }
  cout << ans << endl;
  return 0;
}

#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
template <typename X, typename Y> istream& operator>>(istream& is, pair<X, Y>& p) { return is >> p.first >> p.second; }
const int N = 50, K = 100;
ll mem[N+2][N+1][K+1];
ll opt(int i, int j, int k, vector<int>& v) {
    ll& ans = mem[i+1][j+1][k];
    if(ans == -1) {
        if(i <= j) {
            ans = max({
                k >= 1 ? v[i] + opt(i + 1, j, k - 1, v) : 0,
                k >= 1 ? v[j] + opt(i, j - 1, k - 1, v) : 0,
                k >= 2 ? opt(i + 1, j, k - 2, v) : 0,
                k >= 2 ? opt(i, j - 1, k - 2, v) : 0
            });
        } else {
            ans = 0;
        }
    }
    return ans;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    cin >> v;
    memset(mem, -1, sizeof mem);
    ll ans = 0;
    for(int kk = 0; kk <= k; kk++) {
        ans = max(ans, opt(0, n - 1, kk, v));
    }
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  long long int n=0;
  cin >> n;
  long long int ans=0;
  int i=0;
  int amari=0;
  vector<int>dog;
  while(n>0){
    if(n%26 == 0){
      amari=n%26;
      dog.push_back(amari);
      n/=26;
      n--;
      continue;
    }
    amari=n%26;
    dog.push_back(amari);
    n/=26;
  }
  reverse(begin(dog),end(dog));
  for(int i=0;i<(dog.size());i++){
    char c;
    if(dog.at(i) == 0){
      cout << "z";
      continue;
    }
    c = dog.at(i)+96;
    cout << c;
  }
  cout << endl;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD = 1000000007;
const long long INF = 1LL << 60;
using Graph = vector<vector<ll>>;

int main()
{
    string s;
    cin >> s;
    ll n = s.length();

    //2文字条件
    for (int i = 0; i < n - 1; i++)
    {
        if (s[i] == s[i + 1])
        {
            cout << i + 1 << " " << i + 2 << endl;
            return 0;
        }
    }

    //3文字条件
    for (int i = 0; i < n - 2; i++)
    {
        if (s[i] == s[i + 2])
        {
            cout << i + 1 << " " << i + 3 << endl;
            return 0;
        }
    }

    cout << -1 << " " << -1 << endl;
}


#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int main()
{
	double x1,x2,y1,y2,x,y,z;
	cin>>x1>>y1>>x2>>y2;
	x=x2-x1;
	y=y2-y1;
	x *=x;
	y *=y;
	z=sqrt(x+y);
	printf("%lf\n",z);
	return 0;
}

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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

void solve() {
    int H, W, K; cin >> H >> W >> K;
    ll dp[105][10];
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;
    rep(i, H){
        rep(j, W){
            rep(k, 1 << W-1){
                bool ok = true;
                rep(l, W-2){
                    if((1 & (k >> l)) && (1 & (k >> l+1))) ok = false;
                }
                if(!ok) continue;

                if(j > 0 && (1 & (k >> j-1))){
                    dp[i+1][j-1] = modint(modint(dp[i+1][j-1]) + modint(dp[i][j]));
                }else if(j <= W-2 && (1 & (k >> j))){
                    dp[i+1][j+1] = modint(modint(dp[i+1][j+1]) + modint(dp[i][j]));
                }else{
                    dp[i+1][j] = modint(modint(dp[i+1][j]) + modint(dp[i][j]));
                }
            }
        }
    }

    cout << dp[H][K-1] << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

int main (int argc, char *argv[]) {
    vector<int> v1(4), v2(2);
    for (int i = 0; i < 4; ++i) {
        cin >> v1[i];
    }
    for (int i = 0; i < 2; ++i) {
        cin >> v2[i];
    }
    sort(v1.begin(), v1.end(), greater<int>());
    sort(v2.begin(), v2.end(), greater<int>());
    cout<<v1[0] + v1[1] + v1[2] + v2[0]<<endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
typedef pair<ll,ll> ipair;
#define F first
#define S second

/*
//functions from gfg

long long int power(long long int x,long long int y,long long  int p)
{
    long long int res = 1;     // Initialize result

    x = x % p;  // Update x if it is more than or
                // equal to p

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            {//d=(long double)x/p;
            res = (res*x) % p;
            }

        // y must be even now
        y = y>>1; // y = y/2
        x=(x*x)%p;

    }
    return res%p;
}

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

long long int binomialCoeff(long long int n, ll k)
{
    ll res = 1;

    // Since C(n, k) = C(n, n-k)
    if (k > n - k)
        k = n - k;

    // Calculate value of [n*(n-1)*---*(n-k+1)] / [k*(k-1)*---*1]
    for (ll i = 0; i < k; ++i)
    {
        res *= (n - i);
        res /= (i + 1);
    }

    return res;
}

void sieve(int n, vector<ll> &primes)
{
    vector<int> prime(n,1);
    ll p;
    for ( p=2; p*p<=n; p++)
    {
        // If prime[p] is not changed, then it is a prime
        if (prime[p] == 1)
        {

            for (int i=p*p; i<=n; i += p)
                prime[i] = 0;
        }
    }

    for(p=2;p<=n;p++)
    {
        if(prime[p])
        primes.pb(p);
    }

}

void dfs(vector<ll> adj[] ,ll src,vector<ll> &vis)
{
    vis[src]=1;
    for(ll i=0;i<adj[src].size();i++)
    {
        if(vis[adj[src][i]]==0)
        dfs(adj,adj[src][i],vis)
    }
}

*/

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

    ll n,i,j,p,k,m,t,ans=0;
    cin>>n>>t;
    ll dp[3005][3005];
    memset(dp, 0, sizeof(dp));
    vector<ll> a(n),b(n);
    vector<pair<ll,ll> > val(n);
    for(i=0;i<n;i++)
    {
        cin>>a[i]>>b[i];
        val[i].F=a[i];
        val[i].S=b[i];
    }
    sort(val.begin(),val.end());
    for(i=0;i<n;i++)
    {
        a[i]=val[i].F;
        b[i]=val[i].S;
    }
    for(i=0;i<t;i++)
    {
        for(j=0;j<n;j++)
        {
            if(i+a[j]<t)
            {
                dp[j+1][i+a[j]] = max(dp[j][i]+b[j],dp[j+1][i+a[j]]);
            }

            dp[j+1][i] = max(dp[j][i],dp[j+1][i]);

        }
    }
    for(i=0;i<n;i++)
    {
        ans=max(ans,dp[i][t-1]+b[i]);
    }
    cout<<ans<<endl;

    // for(i=0;i<n;i++)
    // {
    //     cout<<a[i]<<" ";
    // }
    // cout<<endl;

    return 0;
}


#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<bool> vb;
typedef vector<char> vc;
// #define INF __INT32_MAX__
#define INF 1e9
#define LINF __LONG_LONG_MAX__

int main() {
    int H, W; cin >> H >> W;
    vector<vc> S(H, vc(W));
    int cnt = 0;
    rep(i, H) {
        rep(j, W) {
            cin >> S[i][j];
            if (S[i][j] == '.') cnt++;
        }
    }

    vector<vi> mp = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};

    vector<vi> route(H, vi(W, INF));
    route[0][0] = 1;
    queue<pair<int, int>> q;
    q.push(make_pair(0, 0));
    while (!q.empty()) {
        pair<int, int> p = q.front(); q.pop();

        int ux = p.first; int uy = p.second;

        if (S[ux][uy] == '#') continue;
        S[ux][uy] = '#';

        for (int i = 0; i < 4; i++) {
            int vx = ux + mp[i][0];
            int vy = uy + mp[i][1];
            if (vx >= 0 && vx < H && vy >= 0 && vy < W && S[vx][vy] != '#') {
                q.push(make_pair(vx, vy));
                route[vx][vy] = min(route[vx][vy], route[ux][uy] + 1);
            }
        }
    }

    if (S[H - 1][W - 1] == '.') {
        cout << -1 << endl;
    } else {
        int d = route[H - 1][W - 1];
        cout << (cnt - d) << endl;
    }
}

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

int n,m;
int g[500][500];

int main(){
	while(scanf("%d%d",&n,&m),n){
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++) g[i][j]=100000;
		for(int i=0;i<m;i++){
			int a,b;
			scanf("%d%d",&a,&b);
			g[a-1][b-1]=1;g[b-1][a-1]=1;
		}
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++)
				for(int k=0;k<n;k++) g[j][k]=min(g[j][k],g[j][i]+g[i][k]);
		int res=0;
		for(int i=1;i<n;i++) if(g[0][i]<=2)res++;
		printf("%d\n",res);
	}
}


#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
#include <ctime>
#include <complex>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
ll pcount(ll x) {return __builtin_popcountll(x);}
//const int mod = 1e9 + 7;
const int mod = 998244353;

int main(){
	int h,w; cin >> h >> w;
	vs s(h); rep(i,h) cin >> s[i];
	vvl dist(h+1,vl(w,0));
	rep(j,w) rep(k,2) dist[0][j] = w-j;
	int ans = w;
	rep(j,w){
		vector<pii> st;
		st.emplace_back(0,0);
		REP(i,1,h+1){
			if(i < h){
				if(j==0 || dist[i][j-1] == 1){
					int d = 0;
					bool rev = s[i][j] != s[i-1][j];
					REP(k,j,w){
						if(rev == (s[i][k] != s[i-1][k])) d++;
						else break;
					}
					dist[i][j] = d;
				}else{
					dist[i][j] = dist[i][j-1] - 1;
				}
			}
			if(st.empty() || st.back().first < dist[i][j]){
				st.emplace_back(dist[i][j],i);
			}else{
				int pos = i;
				while(!st.empty()){
					if(st.back().first >= dist[i][j]){
						pii p = st.back();
						chmax(ans, p.first*(i-p.second)+p.first);
						pos = p.second;
						st.pop_back();
					}else{
						st.emplace_back(dist[i][j], pos);
						break;
					}
				}
			}
		}
	}
	cout << ans << "\n";
}

//    Have a nice day
//    ∠( ᐛ 」∠)

#include<bits/stdc++.h>

#define mp make_pair
#define pb push_back
#define x first
#define y second

using namespace std;

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

template <typename T> inline T read()
{
	T sum=0, fl=1; char ch=getchar();
	for(; !isdigit(ch); ch=getchar()) if(ch=='-') fl=-1;
	for(; isdigit(ch); ch=getchar()) sum=(sum<<3)+(sum<<1)+ch-'0';
	return sum*fl;
}

const int maxn=2000+5;
int n, m, ans;
char s[maxn][maxn];
int l[maxn], r[maxn], h[maxn], c[maxn][maxn];

void Solve()
{
	n=read<int>(), m=read<int>(); ans=max(n, m);
	for(int i=1; i<=n; ++i) scanf("%s", s[i]+1);
	--n, --m;
	for(int i=1; i<=n; ++i)
		for(int j=1; j<=m; ++j)
			if(((s[i][j]=='#')+(s[i+1][j]=='#')+(s[i][j+1]=='#')+(s[i+1][j+1]=='#'))&1);
			else c[i][j]=1;

	for(int i=1; i<=m; ++i) l[i]=r[i]=maxn;
	for(int i=1; i<=n; ++i)
	{
		for(int j=1, p=0; j<=m; ++j)
		{
			if(c[i][j]) ++p; else p=0;
			l[j]=min(l[j], p);
		}
		for(int j=m, p=0; j>=1; --j)
		{
			if(c[i][j]) ++p; else p=0;
			r[j]=min(r[j], p);
		}
		for(int j=1; j<=m; ++j)
		{
			if(c[i][j]) ++h[j], ans=max(ans, (l[j]+r[j])*(h[j]+1));
			else l[j]=r[j]=maxn, h[j]=0;
		}
	}
	printf("%d\n", ans);
}

int main()
{

   // freopen("081d.in","r",stdin);
    //freopen("081d.out","w",stdout);

    Solve();

    return 0;
}


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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const double EPS = 1e-10;

int main() {
    int H, W;
    cin >> H >> W;

    vector<string> G(H);
    rep(i, H) cin >> G[i];

    int cnt = 0;
    rep(i, H) rep(j, W) {
        if (G[i][j] == '#') { cnt++; }
    }

    vector<vector<lint>> dist(H, vector<lint>(W, LINF));
    dist[0][0] = 0;
    queue<pair<int, int>> q({{0, 0}});
    while (!q.empty()) {
        int cx, cy;
        tie(cx, cy) = q.front();
        q.pop();
        int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
        for (int i = 0; i < 4; i++) {
            int nx = cx + dx[i], ny = cy + dy[i];
            if (0 <= nx && nx < H && 0 <= ny && ny < W && G[nx][ny] == '.' &&
                dist[nx][ny] == LINF) {
                dist[nx][ny] = dist[cx][cy] + 1;
                q.push({nx, ny});
            }
        }
    }
    // ddump(G);
    // ddump(dist);

    if (dist[H - 1][W - 1] == LINF) {
        cout << -1 << endl;
    } else {

        cout << (H * W - cnt) - (dist[H - 1][W - 1] + 1) << endl;
    }

    return 0;
}

#include <vector>
#include <queue>
#include <iostream>
#include <set>
#include <algorithm>
#define ii pair<int, int>
#define iii pair<ii, int>
#define pq priority_queue

using namespace std;

int bfs(vector<vector<char>> graph, ii start, ii goal, int h, int w) {
    queue<iii> possible;
    set<ii> visited;
    possible.push(make_pair(start, 0));
    while (!possible.empty()) {
        ii xy = possible.front().first;
        int dist_from_start = possible.front().second;
        possible.pop();
        if (visited.find(xy) == visited.end()) {
            if (xy == goal) {
                return dist_from_start;
            }
            if (xy.first + 1 < h && graph[xy.first + 1][xy.second] == '.') {
                possible.push(make_pair(make_pair(xy.first + 1, xy.second), dist_from_start + 1));
            }
            if (xy.first - 1 >= 0 && graph[xy.first - 1][xy.second] == '.') {
                possible.push(make_pair(make_pair(xy.first - 1, xy.second), dist_from_start + 1));
            }
            if (xy.second - 1 >= 0 && graph[xy.first][xy.second - 1] == '.') {
                possible.push(make_pair(make_pair(xy.first, xy.second - 1), dist_from_start + 1));
            }
            if (xy.second + 1 < w && graph[xy.first][xy.second + 1] == '.') {
                possible.push(make_pair(make_pair(xy.first, xy.second + 1), dist_from_start + 1));
            }
            visited.insert(xy);
        }
    }
    return -1;
}

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

    int h, w;
    cin >> h >> w;
    vector<vector<char>> graph(h, vector<char>(w));
    cin.get();
    int no_black = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin.get(graph[i][j]);
            if (graph[i][j] == '#') {
                no_black++;
            }
        }
        cin.get(); //get \n character
    }
    int answer = bfs(graph, make_pair(0, 0), make_pair(h - 1, w - 1), h, w);
    if (answer >= 0) {
        answer = h * w - answer - no_black - 1;
    }
    cout << answer;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define INF 1LL<<60
#define pi 3.14159265358979323846
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;} return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;} return false;}

int main(){
    ll x,y;cin>>x>>y;

    ll ans=0;

    if(x==y){cout<<0<<endl;return 0;}//ｘ yが一致する場合

    if(x==0){//x==0の場合
        if(y>0){
            cout<<y<<endl;
            return 0;
        }else{
            cout<<abs(y)+1<<endl;
            return 0;
        }
    }

    if(y==0){//y==0の場合
        if(x>0){
            cout<<x+1<<endl;
            return 0;
        }else{
            cout<<abs(x)<<endl;
            return 0;
        }
    }

    if(x>=0 && y>=0){//x yの正負で場合わけ
        if(abs(y)>=abs(x)){
            ans=abs(y)-abs(x);
        }else{
            ans=abs(x)-abs(y)+2;
        }
    }else if(x>=0 && y<0){
        if(abs(y)>=abs(x)){
            ans=abs(y)-abs(x)+1;
        }else{
            ans=abs(x)-abs(y)+1;
        }
    }else if(x<0 && y>=0){
        if(abs(y)>=abs(x)){
            ans=abs(y)-abs(x)+1;
        }else{
            ans=abs(x)-abs(y)+1;
        }
    }else if(x<0 && y<0){
        if(abs(y)>=abs(x)){
            ans=abs(y)-abs(x)+2;
        }else{
            ans=abs(x)-abs(y);
        }
    }

    cout<<ans<<endl;

    return 0;
}

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

int main() {
    int k, x;
    cin >> k >> x;
    int left = x - k + 1, right = x + k - 1;
    for(int i = left; i < right; i++)
        cout << i << " ";
    cout << right << endl;
    return 0;
}


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

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  rep(ki, k) {
    vector<int> b(n + 1);
    rep(i, n) {
      int l = max(0, i - a[i]);
      int r = min(i + a[i] + 1, n);
      b[l]++;
      b[r]--;
    }
    rep(i, n) b[i + 1] += b[i];
    b.pop_back();
    if (a == b) break;
    a = b;
  }
  rep (i, n) {
    cout << a[i] << endl;
  }
}

#include <bits/stdc++.h>
#define sz(arr) (int)(arr).size()
#define rng(arr) arr.begin(), arr.end()
#define show(x) cout << #x << " = " << x << endl;

using namespace std;
typedef long long int ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

#define Cins(T, n, xs) \
  vector<T> xs(n);     \
  for (int i = 0; i < n; ++i) cin >> xs[i]

void Main();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}

void Main() {
  Cin(int, n);
  Cin(string, a, b, c);

  int ans = 0;
  for (int i = 0; i < n; ++i) {
    map<char, int> mp;
    mp[a[i]]++;
    mp[b[i]]++;
    mp[c[i]]++;

    int ma = 0;
    for (auto e : mp) ma = max(ma, e.second);
    ans += 3 - ma;
  }

  cout << ans << endl;
}


/*
{

AuThOr Gwj
*/
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define R(a) cin>>a
#define R2(a,b) cin>>a>>b
#define int LL
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
/*}
*/
int n,a[200000+20];
double a_[200000+20];
int all[65][65];
signed main(){
	fastio;
	R(n);
	LL res=0;
	rb(i,1,n){
		R(a_[i]);
		;
		a[i]=llround(a_[i]*=1000000000.0);
		int A,B;
		A=B=0;
		while(a[i]%5==0){
			a[i]/=5;
			A++;
		}
		while(a[i]%2==0){
			a[i]/=2;
			B++;
		}
//		cout<<A<<" "<<B<<endl;
		rb(k,0,64)
			rb(j,0,64){
				if(k+A>=18&&j+B>=18){
					res+=all[k][j];
				}
		}
		all[A][B]++;
	}
	cout<<res<<endl;
	return 0;
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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

// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

void solve()
{
  ll X; cin >> X;
  ll a = X / 500;
  X %= 500;
  ll b = X / 5;
  ll ans = a* 1000 + b * 5;

  cout << ans << endl;
}

int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


#include <bits/stdc++.h>

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

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int h,w;
    cin >> h >> w;
    vector<bool> a(h*w,false);

    queue<int> que;
    for(int i = 0; i < h; i++) {
        string tmp;
        cin >> tmp;
        for(int j = 0; j < w; j++) {
            int idx=i*w+j;
            if(tmp[j]=='#'){
                a[idx]=true;
                que.push(idx);
            }
        }
    }

    int cnt=0;
    int ans=0;
    while(cnt<h*w) {
        int n=que.size();
        cnt+=n;
        for(int i = 0; i < n; i++) {
            int idx=que.front();
            int add[4]={1,-1,w,-w};
            for(int j = 0; j < 4; j++) {
                int t=idx+add[j];
                int r=idx/w+add[j]/w;
                int c=idx%w+add[j]%w;
                if(r<0||r>=h||c<0||c>=w||a[t]==true) continue;
                a[t]=true;
                que.push(t);
            }
            que.pop();
        }
        ans++;
    }
    cout << ans-1 << "\n";

    return 0;
}

//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INTINF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007

//二次元平面を探索しよう
template <typename T,typename U>
std::pair<T,U> operator+(const std::pair<T,U> & l,const std::pair<T,U> & r) {
    return {l.first+r.first,l.second+r.second};
}

vector<pair<int, int>> nei;
void nei_init(){
	nei.push_back(make_pair(-1,0));nei.push_back(make_pair(1,0));nei.push_back(make_pair(0,-1));nei.push_back(make_pair(0,1));
	//4近傍ならコメントアウト
	//nei.push_back(make_pair(-1,-1));nei.push_back(make_pair(1,-1));nei.push_back(make_pair(1,1));nei.push_back(make_pair(-1,1));
}

bool is_safe(pair<int, int> p, int h, int w){
	if(p.first < 0 || p.second < 0) return false;
	else if(p.first >=h || p.second >=w) return false;
	else return true;
}
//

int main() {
	int ans = 0;
	int tmp;
	nei_init();
	int h, w;
	cin >> h >> w;
	vector<string> mp(h);
	REP(i, h) cin >> mp[i];
	queue<pair<pair<int, int>,int> > q;
	bool ch[h][w] ={};
	int count = h*w;
	REP(i, h) REP(j, w) if(mp[i][j] == '#'){
		q.push(make_pair(make_pair(i, j),1));
		ch[i][j] = true;
		count--;
	}
	pair<int, int> now;
	int ope;
	while(!q.empty() && count > 0){
		now = q.front().first;
		ope = q.front().second;
		q.pop();
		ans = max(ans, ope);
		REP(i, nei.size()){
			pair<int, int> see = make_pair(now.first+nei[i].first, now.second+nei[i].second);
			if(is_safe(see, h, w) && !ch[see.first][see.second]){
				q.push(make_pair(see, ope+1));
				ch[see.first][see.second] = true;
				count--;
			}
		}
	}
	cout << ans << endl;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define invrep(i,n) for(int i = (int)(n); i > 0; i++)
using ll = long long;

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

    if (n.size() > k) {
        string ans = "";
        rep (i, n.size()) {
            if (i < k) ans += n[i];
            else {
                ans += "...";
                break;
            }
        }

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

    cout << n << endl;
    return 0;
}

#include <iostream>
#include <string>
int main(){
  std::string s;
  int n;
  std::cin>>n,std::cin.get();
  for(;n;n--){
    getline(std::cin,s);
    int pos=0;
    while(pos=s.find("Hoshino",pos),pos!=std::string::npos){
      s.replace(pos,7,"Hoshina");
      pos+=7;
    }
    std::cout<<s<<std::endl;
  }
  return 0;
}


#include <bits/stdc++.h>

using ll = long long;
using namespace std;
const int INFint = 2e9+1;
const ll INFll = 2e18+1;
ll MOD=1e9+7;

int H,W,T;
string s[10];

int main(){
  int N,M;
  cin>>N>>M;
  vector<int> A(M);
  for(int i(0);i<M;i++){
    cin>>A[i];
  }
  sort(A.rbegin(),A.rend());
  int num[10] = {0,2,5,5,4,5,6,3,7,6};
  map<int,int> ma;
  set<int> honsuu;
  for(int i(0);i<M;i++){
    ma[num[A[i]]] = max(ma[num[A[i]]],A[i]);
    honsuu.insert(num[A[i]]);
  }
  int dp[10001] = {0}; //iを作るのに必要な最大個数
  for(auto m:honsuu){
    dp[m] = 1;
  }
  for(int i(0);i<=N;i++){
    for(auto m:honsuu){
      if(i-m >= 0 && dp[i-m] != 0){
        if(dp[i-m] + 1 >= dp[i]){
          dp[i] = dp[i-m] + 1;
        }
      }
    }
  }

  vector<int> ans;
  int now = N;
  while(dp[now] != 1){
    for(int i(0);i<M;i++){
      if(dp[now] - dp[now-num[A[i]]] == 1){
        ans.push_back(A[i]);
        now = now - num[A[i]];
        break;
      }
    }
  }
  ans.push_back(ma[now]);

  sort(ans.rbegin(),ans.rend());
  for(int i(0);i<int(ans.size());i++){
    cout << ans[i];
  }
  cout << endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;

int main(){
    int N, T;
    cin >> N >> T;
    vector<iint> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i].first >> A[i].second;
    }
    sort(ALL(A));

    vector<vector<int>> dp(N+1, vector<int>(T));
    int ans = 0;
    for (int i = 0; i < N+1; i++) {
        dp[i][0] = 0;
    }
    for (int i = 0; i < T; i++) {
        dp[0][i] = 0;
    }
    for (int n = 1; n < N+1; n++) {
        for (int t = 1; t < T; t++) {
            if(t - A[n-1].first >= 0){
                dp[n][t] = max(dp[n-1][t], dp[n-1][t-A[n-1].first] + A[n-1].second);
            }
            else{
                dp[n][t] = dp[n-1][t];
            }
        }
        for (int t = T; t < T+A[n-1].first; t++) {
            if(t - A[n-1].first >= 0){
                ans = max(ans, dp[n-1][t-A[n-1].first] + A[n-1].second);
            }
        }
    }

    printf("%d\n", ans);

}


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

int main() {
  int N , M ;
  cin >> N >> M ;
  int max_L = 0 ;
  int min_R = 5+ 10e5 ;

  for(int i = 0 ; i < M ; i++ ){
    int L , R ;
    cin >> L >> R ;
    max_L = max(max_L , L);
    min_R = min(min_R , R);
  }
  min_R++ ;
  if(min_R > max_L){
  	cout << min_R - max_L << endl ;
  }
  else{
    cout << 0 << endl ;
  }

}

#include <vector>
#include <iostream>
using namespace std;
int main() {
	int N, M;
	cin >> N >> M;
	vector<int> L(M), R(M);
	for(int i = 0; i < M; ++i) {
		cin >> L[i] >> R[i];
	}
	vector<int> p(N + 1);
	for(int i = 0; i < M; ++i) {
		++p[L[i] - 1];
		--p[R[i]];
	}
	int sum = 0, ans = 0;
	for(int i = 0; i < N; ++i) {
		sum += p[i];
		if(sum == M) ++ans;
	}
	cout << ans << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    long long i,j,k,l,m,n,o,p,q;
    while(cin>>m>>n>>o>>p)
    {
        if(m+n>o+p)
            cout<<"Left"<<endl;
        else if(m+n<o+p)
            cout<<"Right"<<endl;
        else
            cout<<"Balanced"<<endl;
    }
    return 0;
}

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

int main() {
int a,b,c,d;
  cin >> a >> b >> c >> d;
  int L=a+b;
  int R=c+d;
  if(L>R){
    cout << "Left" << endl;
  }
    if(L<R){
      cout << "Right" << endl;
    }
  if(L==R){
    cout << "Balanced" << endl;
  }
}


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

int main(){
    int n, y;
    cin >> n >> y;
    int ans10 = -1, ans5 = -1, ans1 = -1;

    for(int i=0; i<=n; i++){
        for(int j=0; j<=n-i; j++){
            int total = 10000*i + 5000*j + 1000*(n-i-j);
            if(total == y){
                ans10 = i;
                ans5 = j;
                ans1 = n-i-j;
            }
        }
    }

    cout << ans10 << " " << ans5 << " " << ans1 << endl;
}

#include<iostream>
using namespace std;

int main() {
    int n, Y, x = 0, y, z;
    cin >> n >> Y;
    bool can = false;

    int t = Y / 1000 - n;
    while (t >= 0) {
        y = t / 4; // >= 0
        z = n - x - y;
        if (t % 4 == 0 && z >= 0) {
            can = true;
            break;
        }
        t -= 9;
        x++;
    }

    if (can) cout << x << ' ' << y << ' ' << z << endl;
    else cout << "-1 -1 -1" << endl;
}


//This Code was made by Chinese_zjc_.
#include <iostream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <set>
#include <ctime>
// #include<windows.h>
#define int long long
#define double long double
using namespace std;
const double PI = acos(-1);
const double eps = 0.0000000001;
const int INF = 0x3fffffffffffffff;
int n, k, dp[55][55];
signed main()
{
    ios::sync_with_stdio(false);
    cin >> n >> k;
    cout << n - k + 1 << endl;
    return 0;
}

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

int main() {
  string a,b;
  cin>>a>>b;
  cout<<b<<a;
}


#include<cstdio>
#include<algorithm>
#define int long long
using namespace std;
int n,a[1100][1100];
int tot,p[110000]; bool vis[110000];
void init(){
	vis[1]=true;
	for (int i=2;i<=10000;i++){
		if (!vis[i]) p[++tot]=i;
		if (tot==1000) break;
		for (int j=1;j<=tot&&(i*p[j]<=10000);j++){
			vis[i*p[j]]=true;
			if (i%p[j]==0) break;
		}
	}
}
inline int lcm(int x,int y){
	if (!x||!y) return x|y;
	return x/__gcd(x, y)*y;
}
signed main(){
	init();
	scanf("%lld",&n);
	if (n==2){
		puts("4 7\n23 10");
		return 0;
	}
	for (int i=1;i<=n;i++)
		for (int j=1;j<=n;j++)
			if (((i+j)&1)==0)
				a[i][j]=p[(i+j)/2]*p[(i-j+n+1)/2+n];

	for (int i=1;i<=n;i++)
		for (int j=1;j<=n;j++)
			if (!a[i][j])
				a[i][j]=lcm(lcm(a[i-1][j],a[i][j-1]),lcm(a[i][j+1],a[i+1][j]))+1;
	for (int i=1;i<=n;i++){
		for (int j=1;j<n;j++) printf("%lld ",a[i][j]);
		printf("%lld\n",a[i][n]);
	}
	return 0;
}

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <math.h>
using namespace std;

const int MAXN = 1e5 + 10;
int N;
int p[MAXN], pn;
bool np[MAXN];

inline void init(int n) {
	register int i, j;
	np[1] = 1; p[0] = p[n] = 1;
	for(i = 2; i <= n; ++i) {
		if(!np[i])
			p[++pn] = i;
		for(j = 1; j <= pn && i * p[j] <= n; ++j) {
			np[i * p[j]] = 1;
			if(i % p[j] == 0)
				break;
		}
	}
}

int main() {
	register int i, j; init(1e4);
	scanf("%d", &N);
	for(i = 0; i < N; ++i) {
		for(j = 0; j < N; ++j) {
			int s = (i + j) >> 1, d = (i - j) >> 1;
			if((i ^ j) & 1) printf("%lld ", 1ll * p[s + 1] * p[d + N + (N >> 1) + 1]);
			else printf("%lld ", 1ll * p[s + 1] * p[s] * p[d + N + (N >> 1) + 1] * p[d + N + (N >> 1)] + 1);
		}
		puts("");
	}
	return 0;
}


/*
  Contest 104
  B - AcCepted
  Rakesh Kumar --> 27/09/2020
 */

#include <bits/stdc++.h>

bool check_lower(const std::string& s, std::size_t pos) {
    for (std::size_t i = 1; i < s.size(); ++i) {
        if (i != pos && !(s[i] >= 'a' && s[i] <= 'z'))
            return false;
    }
    return true;
}

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

    std::string s;
    std::getline(std::cin, s);
    std::string r = "WA";
    if (s[0] == 'A') {
        const std::size_t pos = s.find('C');
        if (pos != std::string::npos) {
            if (pos >= 2 && pos <= s.size() - 2) {
                if (check_lower(s, pos)) {
                    r = "AC";
                }
            }
        }
    }
    std::cout << r << std::endl;

    return 0;
}

//include
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <math.h>
#include <utility>
#include <functional>
#include <cstdlib>
//using
using namespace std;
using vl = vector <long long>;
using vs = vector <string>;
using vc = vector <char>;
using ll= long long;
using vvl = vector<vector<ll> >;
using vvc = vector<vector<char> >;
//vector<vector<char> > hyou(N, vector<char>(N));
using vd = vector <double>;
//define
//#define int long long
#define rep(i,n) for(int i=0; i<n; i++)
#define print(n) cout<<n<<endl;
#define sortp(d) sort(d.begin(),d.end()) //1234
#define sortm(d) sort(d.rbegin(),d.rend()) //4321
//素数判定　O(√A)
bool is_prime(int x){
 if(x<=1) return false;
 for(int i=2;i*i<=x;i++)
 if(x%i==0) return false;
 return true;
 }
/*順列生成
do {
  // 順列に対する処理
} while (next_permutation(配列変数.begin(), 配列変数.end()));*/

//絶対値　abs()
//文字→数字　'0' アルファベット→数字　'a'　'A'が65番,'a'が97番だわ
//型キャスト　char('a'+1)
//reverse 回文
//if(isupper('A'))->大なら真

//各位の和
int wa(ll x)
{
ll sum = 0;
while(x!=0){
  sum += x% 10;
  x /= 10;
}
return sum;
}

//グローバル変数宣言
ll p=0,q=0,r=0;

int main()
{
  string s;
  cin>>s;
  p=s.size();

  rep(i,p)
  {
  if(i==0){
  if (s[0]!='A')
  {
    print("WA")return 0;
  }}
  else if (i==1||i==p-1)
  {
    if(isupper(s[i]))
    {
      print("WA")return 0;
    }
  }

  else
  {
    if(s[i]=='C')q++;
    else if(isupper(s[i]))
    {
      print("WA")return 0;
    }
  }
  }

if(q!=1){print("WA")return 0;} else print("AC")

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  ll n, h, w;
  cin >> n >> h >> w;
  ll ans = (n - h + 1) * (n - w + 1);
  cout  << ans << endl;
}

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

int main() {
  int N, H, W;
  cin >> N >> H >> W;

  int cnt = 0;
  for (int i = H; i <= N; i++) {
    for (int j = W; j <= N; j++) {
      if (N >= i && N >= j) cnt++;
    }
  }

  cout << cnt << endl;
}


#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
const ll MOD = (ll)1e9+7;
const ll INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

ll modpow(ll x, ll b){
	ll res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

ll modinv(ll x){
	return modpow(x, MOD-2);
}

int main(){
	int n;
	cin >> n;
	vector<vector<ll>> citys(n, vector<ll>(2));
	foreach(i, citys){
		foreach(j, i)cin>>j;
	}

	vector<vector<pll>> roads(n);

	rep(i, 2){
		vector<pll> line;
		rep(j, n){
			line.emplace_back(citys[j][i], j);
		}
		sort(all(line));
		rep(j, n-1){
			pll a = line[j];
			pll b = line[j+1];
			roads[a.second].emplace_back(abs(a.first-b.first), b.second);
			roads[b.second].emplace_back(abs(a.first-b.first), a.second);
		}
	}

	vector<bool> used(n, false);
	priority_queue<pll, vector<pll>, greater<pll>> pq;
	ll ans = 0;
	pq.emplace(0, 0);
	while(pq.size()){
		pll d = pq.top();
		pq.pop();
		if(used[d.second])continue;
		used[d.second] = true;
		ans += d.first;
		foreach(i, roads[d.second]){
			if(used[i.second])continue;
			pq.push(i);
		}
	}

	cout << ans << endl;

	return 0;
}

#include <bits/stdc++.h>
#define All(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

ll prim(int n, vector<vector<pll>> &edge)
{
	priority_queue<pll, vector<pll>, greater<pll>> pq;
	vector<bool> used(n, false);
	// 点0からスタート
	pq.push(pll(0, 0));
	ll all_len = 0;
	while (!pq.empty())
	{
		ll now = pq.top().second, len = pq.top().first;
		pq.pop();
		if (used[now])
			continue;
		used[now] = true;
		all_len += len;
		for (int i = 0; i < edge[now].size(); i++)
		{
			ll next_len = edge[now][i].first;
			ll next = edge[now][i].second;
			pq.push(pll(next_len, next));
		}
	}
	return all_len;
}

int main()
{
	int N;
	cin >> N;
	vector<pll> xy, yx;
	map<pll, ll> mp;
	int cnt = 0;
	for (int i = 0; i < N; i++)
	{
		ll x, y;
		cin >> x >> y;
		if(!mp.count(pll(x, y))) {
			mp[pll(x, y)] = cnt;
			xy.push_back(pll(x, y));
			yx.push_back(pll(y, x));
			cnt++;
		}
	}
	sort(All(xy));
	sort(All(yx));

	vector<vector<pll>> edge(cnt);

	for (int i = 0; i < cnt - 1; i++)
	{
		auto now = xy[i];
		int nowp = mp[now];

		auto next = xy[i + 1];
		int nexp = mp[next];
		edge[nowp].push_back(pll(min(llabs(now.first - next.first), llabs(now.second - next.second)), nexp));
		edge[nexp].push_back(pll(min(llabs(now.first - next.first), llabs(now.second - next.second)), nowp));
	}
	for (int i = 0; i < cnt - 1; i++)
	{
		auto now = yx[i];
		int nowp = mp[pll(now.second, now.first)];

		auto next = yx[i + 1];
		int nexp = mp[pll(next.second, next.first)];
		edge[nowp].push_back(pll(min(llabs(now.first - next.first), llabs(now.second - next.second)), nexp));
		edge[nexp].push_back(pll(min(llabs(now.first - next.first), llabs(now.second - next.second)), nowp));
	}
	cout << prim(cnt, edge) << endl;
}


#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define io std::ios::sync_with_stdio(false)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
const double pi=acos(-1);
const ll P = 998244353, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n){ll r=1%P;for (a%=P; n; a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
const double eps=1e-5;
ll lcm(ll a,ll b){return a*b/gcd(a,b);};
const int maxn = 200 + 10;
ll a[maxn];
const int L = 63;
ll d[L];
bool add(ll x){
    for(int i = L - 1; i >= 0; i--) if(x & 1ll << i){
        if(d[i] == -1){d[i] = x; return true;}
        x ^= d[i];
    }
    return false;
}

int main(){
//    Fast;
    int t; scanf("%d", &t); while(t--){
        memset(d, -1, sizeof d);

        int n; scanf("%d", &n);
        for(int i = 0; i < n; i++) scanf("%lld", a + i);
        char s[maxn]; scanf("%s", s);
        int flag = 0;
        for(int i = n - 1; i >= 0; i--){
            if(add(a[i]) && s[i] == '1'){
                flag = 1;
                break;
            }
        }
        printf("%d\n", flag);
    }
    return 0;
}

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

const int N = 100000;

int partition(int l, int r, int A[]) {
  int i, j, x;

  x = A[r];
  i = l - 1;

  for (j = l; j < r; j++) {
    if (A[j] <= x) {
      i++;
      swap(A[i], A[j]);
    }
  }

  swap(A[i+1], A[r]);

  return i + 1;
}

int main() {
  int i, n;
  int A[N];

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

  int q = partition(0, n-1, A);

  for (i = 0; i < n; i++) {
    if (i > 0) cout << " ";
    if (i == q) cout << "[" << A[i] << "]";
    else cout << A[i];
  }
  cout << endl;

  return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int x=c-a,y=d-b;
  for(int i=0;i<x;i++)cout<<'R';
  for(int i=0;i<y;i++)cout<<'U';
  for(int i=0;i<x;i++)cout<<'L';
  for(int i=0;i<y;i++)cout<<'D';
  cout<<'D';
  for(int i=0;i<x+1;i++)cout<<'R';
  for(int i=0;i<y+1;i++)cout<<'U';
  cout<<"LU";
  for(int i=0;i<x+1;i++)cout<<'L';
  for(int i=0;i<y+1;i++)cout<<'D';
  cout<<"R\n";
}

#include <bits/stdc++.h>

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define dump_1(x1) cerr << #x1 << ": " << x1 << endl
#define dump_2(x1, x2) \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define dump_3(x1, x2, x3)                                                \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << endl
#define dump_4(x1, x2, x3, x4)                                            \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << endl
#define dump_5(x1, x2, x3, x4, x5)                                        \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define dump(...) \
  CHOOSE((__VA_ARGS__, dump_5, dump_4, dump_3, dump_2, dump_1, ~))(__VA_ARGS__)
#define check(s) cerr << s << endl

#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(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

using namespace std;

using ll = long long;

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

const ll LINF = 2e18;
const int INF = 1e9;

void solve(ll sx, ll sy, ll tx, ll ty) {
  ll dx = tx - sx;
  ll dy = ty - sy;

  cout << string(dy, 'U') << string(dx, 'R');

  cout << string(dy, 'D') << string(dx, 'L');

  cout << 'L' << string(dy + 1, 'U') << string(dx + 1, 'R') << 'D';

  cout << 'R' << string(dy + 1, 'D') << string(dx + 1, 'L') << 'U';

  cout << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  ll sx;
  scanf("%lld", &sx);
  ll sy;
  scanf("%lld", &sy);
  ll tx;
  scanf("%lld", &tx);
  ll ty;
  scanf("%lld", &ty);
  solve(sx, sy, tx, ty);
  return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
bool isprime(ll x){
    for(int i=2;i*i<=x;i++){
        if(x%i==0)return false;
    }
    return true;
}

int main()
{
    vector<ll>common;
    ll a,b;
    cin>>a>>b;
    set<ll>f,g;
    bool ok=false;
    while (a % 2 == 0)
    {
        f.insert(2);
        a = a/2;
    }

    // n must be odd at this point. So we can skip
    // one element (Note i = i +2)
    for (int i = 3; i <= sqrt(a); i = i + 2)
    {
        // While i divides n, print i and divide n
        while (a % i == 0)
        {
            f.insert(i);
            a = a/i;
        }
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (a > 2)
        f.insert(a);

         while (b % 2 == 0)
    {
        g.insert(2);
        b = b/2;
    }

    // n must be odd at this point. So we can skip
    // one element (Note i = i +2)
    for (int i = 3; i <= sqrt(b); i = i + 2)
    {
        // While i divides n, print i and divide n
        while (b % i == 0)
        {
            g.insert(i);
            b = b/i;
        }
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (b > 2)
        g.insert(b);

      ll ans=0;
      for(auto x:g){
        if(f.count(x))ans++;
      }
      ans++;
      cout<<ans;

    return 0;

}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;}
ll lcm(ll x, ll y) {return x/gcd(x,y)*y;}

// 素因数分解 O(√n)
// たとえば 60 = 2^2 x 3 x 5 だったら {(2, 2), (3, 1), (5, 1)} を返す
// 素因数の個数はlogn
vector<pair<ll,ll>> prime_factorize(ll n){
    vector<pair<ll,ll>> res;
    for(ll p=2;p*p<=n;p++){
        if(n%p!=0) continue;
        int num=0; // 指数
        while(n%p==0){
            num++;
            n/=p;
        }
        res.push_back({p,num});
    }
    if(n!=1) res.push_back({n,1});
    return res;
}

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

    ll g=gcd(a,b);

    if(g==1){
        cout<<1<<endl;
        return 0;
    }

    auto pf=prime_factorize(g);
    cout<<pf.size()+1<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int main () {
  int K, T;
  cin >> K >> T;
  int ma = 0;
  for (int i = 0; i < T; i ++) {
    int a;
    cin >> a;
    ma = max(ma, a);
  }
  int kj = K - ma;
  cout << max(ma - kj - 1, 0) << endl;
}

#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)
#define MP(a,b) make_pair(a,b)

#if __has_include("debug.hpp")
#include "debug.hpp"
#else
template<typename T>
void debug(T& obj) {}
#endif

template<typename T>
T in(){
	T val;
	cin >> val;
	return val;
}

template<typename T>
vector<T> inv(ll num) {
	vector<T> val(num);
	rep(i,num) cin >> val[i];
	return val;
}

//----------------------------------------------------------------------
void solve() {
	ll n,m;
	cin >> n >> m;
	vector<ll> wa(n,0);
	vector<bool> ac(n,false);

	rep(i,m) {
		ll p;
		string s;
		cin >> p >> s;
		p--;
		if (s=="AC") ac[p]=true;
		else if (ac[p]==false) wa[p]++;
	}

	ll sum=0;
	ll pena=0;
	rep(i,n) {
		if (ac[i]) {sum++;pena += wa[i];}
	}

	cout << sum << " " << pena;

}
//----------------------------------------------------------------------

int main(int argc, char* argv[]) {
	solve();
	return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
int n, q, a, b, l, val[800007][3], tag[800007];
int read()
{
	int num = 0;
	char c = getchar();
	while (c<'0' || c>'9')c = getchar();
	while (c >= '0' && c <= '9')num = num * 10 + c - '0', c = getchar();
	return num;
}
int add(int w, int v)
{
	for (int j = 0; j <= 2; j++)
		val[w][j] += v;
	tag[w] += v;
	return 0;
}
int down(int w)
{
	if (!tag[w])return 0;
	add(2 * w, tag[w]);
	add(2 * w + 1, tag[w]);
	tag[w] = 0;
	return 0;
}
int up(int w)
{
	for (int i = 0; i <= 2; i++)
		val[w][i] = min(val[2 * w][i], val[2 * w + 1][i]);
	return 0;
}
int change(int w, int l, int r, int x, int v)
{
	if (l == r)
	{
		val[w][0] = v;
		val[w][1] = v - x;
		val[w][2] = v + x;
		return 0;
	}
	down(w);
	int mid = (l + r) / 2;
	if (x <= mid)change(2 * w, l, mid, x, v);
	else change(2 * w + 1, mid + 1, r, x, v);
	up(w);
	return 0;
}
int ask(int p, int w, int l, int r, int x, int y)
{
	if (x <= l && r <= y)
		return val[w][p];
	down(w);
	int mid = (l + r) / 2, res = 1e18;
	if (x <= mid)res = min(res, ask(p, 2 * w, l, mid, x, y));
	if (y > mid)res = min(res, ask(p, 2 * w + 1, mid + 1, r, x, y));
	return res;
}
signed main()
{
	n = read();
	q = read();
	a = read();
	b = read();
	l = read();
	memset(val, 0x3f, sizeof val);
	change(1, 1, n, b, abs(l - a));
	change(1, 1, n, a, abs(l - b));
	for (int i = 2; i <= q; i++)
	{
		int num = read(), len = abs(num - l);
		int res1 = ask(0, 1, 1, n, num, num) + len;
		int res2 = ask(1, 1, 1, n, 1, num) + num;
		int res3 = ask(2, 1, 1, n, num + 1, n) - num;
		add(1, len);
		change(1, 1, n, l, min(res1, min(res2, res3)));
		l = num;
	}
	printf("%lld\n", val[1][0]);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7,INF=mod*mod*3;//M_PI
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define f first
#define s second
#define pb push_back
#define mp make_pair

ll N;
ll p[200005];
ll ans;

int main(){

cin.tie(0);
ios::sync_with_stdio(false);

cin>>N;
rep(i,N) cin>>p[i];
ll pm=INF;
rep(i,N){
	if(pm>=p[i]) pm=p[i];
	if(pm>=p[i]) ans++;
}
cout<<ans<<endl;

}

#include<cstdio>
#include<iostream>
#include<map>
#include<set>
#include<vector>
#include<cstring>
#include<cassert>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<limits>
#include<ctime>
#include<stack>
#include<bits/stdc++.h>
#include<string>
#include<stdlib.h>
#include<stdio.h>

typedef long long ll;
using namespace std;
const ll x=1000000007;
int mod(ll a){
	return a%x;
}
int main(){
	ll n;
	cin>>n;
	ll a[n],ans=0,mins=n+1;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]<mins){
			ans+=mins-a[i]-1;
			mins=a[i];
		}
	}
	cout<<n-ans;
}


#include <iostream>
#include <stdio.h>

char judge(int, int, int);

int main()
{
	int pm, pe, pj;
	int number;

	while (true) {
		std::cin >> number;

		if (number == 0) {
			break;
		}

		for (int i = 0; i < number; i++) {
			std::cin >> pm >> pe >> pj;
			std::cout << judge(pm, pe, pj) <<std::endl;
		}
	}
	return 0;
}

char judge(int pm, int pe, int pj) {
	int avarage = (pm + pe + pj) /3;

	if  (pm == 100 || pe == 100 || pj == 100) {
		return 'A';
	} else if ((pm + pe) / 2 >= 90 || avarage >= 80) {
		return 'A' ;
	} else if (avarage >= 70) {
		return 'B';
	} else if (avarage >= 50 && (pm >= 80 || pe >= 80)) {
		return 'B';
	} else {
		return 'C';
	}
}

#include <iostream>
#include <vector>
//#include <fstream>

using namespace std;

int main()
{
//	cut here before submit
//	freopen ("testcase.divstudent", "r", stdin );
	const char rank[] = { 'A', 'B', 'C' };
	int n;

	while (cin >> n && n ){
		vector <vector <int> > s(n, vector <int> (3, 0 ) );

		for (int i = 0; i < n; ++i){
			for (int j = 0; j < 3; ++j){
				cin >> s[i][j];	// pm, pe, pj order
			} // end for
		} // end for
/*
100 _ÌÈÚª é	 A
wÆpêÌ½Ï_ª 90 _Èã	 A
3 ÈÚÌ½Ï_ª 80 _Èã	 A
3 ÈÚÌ½Ï_ª 70 _Èã	 B
3 ÈÚÌ½Ï_ª 50 _ÈãÅw©pêª 80 _Èã	 B
ãÌðð½³È¢	 C
¡Ìðð½·êÍAæèxÌ¢NXÉª¯çêÜ·B
*/
		for (int i = 0; i < n; ++i){

			double me  = (s[i][0] + s[i][1])/2.;
			double avg = (s[i][0] + s[i][1] + s[i][2])/3.;

			if ( s[i][0] == 100 || s[i][1] == 100 || s[i][2] == 100
			|| me >= 90.0 || avg >= 80. ) {
				cout << rank[0] << endl;
				continue;
			} // end if
			if ( avg >= 70. || (avg >= 50. && (s[i][0] >= 80 || s[i][1] >= 80 ) ) ) {
				cout << rank[1] << endl;
				continue;
			} // end if

			cout << rank[2] << endl;
		} // end for
	} // end loop

	return 0;
}


#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
#define N 200010
using namespace std;
int n,a[N],b[N],dxa[N],dxb[N],enr[4*N],ext[4*N];
int main(){
	int i,j,cnt=0;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(i=0;i<n;i++)
	{
		cin>>b[i];
	}
	for(i=0;i<n;i++)
	{
		dxa[i]=a[i]^a[(i+1)%n];
	}
	for(i=0;i<n;i++)
	{
		dxb[i]=b[i]^b[(i+1)%n];
	}
	for(i=0;i<n;i++)
	{
		enr[cnt++]=dxb[i];
	}
	enr[cnt++]=-INF;
	for(i=0;i<n;i++)
	{
		enr[cnt++]=dxa[i];
	}
	for(i=0;i<n;i++)
	{
		enr[cnt++]=dxa[i];
	}
	memset(ext,0,sizeof(ext));
	ext[0]=3*n+1;
	cnt=0;
	for(i=1;i<=3*n;)
	{
		while(i+cnt<=3*n)
		{
			if(enr[cnt]!=enr[i+cnt])
			{
				break;
			}
			cnt++;
		}
		ext[i]=cnt;
		j=1;
		if(cnt<=0)
		{
			i++;
			continue;
		}
		else
		{
			while(i+j<=3*n)
			{
				if(j+ext[j]>=cnt)
				{
					break;
				}
				ext[i+j]=ext[j];
				j++;
			}
		}
		i+=j;
		cnt-=j;
	}
	for(i=n+1;i<2*n+1;i++)
	{
		if(ext[i]==n)
		{
			cout<<i-n-1<<" "<<(a[i-n-1]^b[0])<<endl;
		}
	}
	return 0;
}

#include<bits/stdc++.h>
#define N 105
using namespace std;
typedef pair<int,int> P;
int n,a,b,c,d,ans[N],cnt,prevx;
P x[N];

int main(){
  cin>>n;
  for(int i=0;i<n;i++)x[i].second=i+1;
  for(int i=0;i<n*(n-1)/2;i++){
    cin>>a>>b>>c>>d;
    if(c==d)x[a-1].first++,x[b-1].first++;
    else if(c<d)x[b-1].first+=3;
    else x[a-1].first+=3;
  }
  sort(x,x+N,greater<P>());
  cnt=1;
  prevx=x[0].first;
  for(int i=0;i<n;i++){
    if(prevx>x[i].first){
      cnt=i+1;
      prevx=x[i].first;
    }
    ans[x[i].second-1]=cnt;
  }
  for(int i=0;i<n;i++)
    cout<<ans[i]<<endl;
  return 0;
}


#include<stdio.h>

int main(){

	char input1[102];
	char input2[102];

	scanf("%s %s", input1, input2);
	printf("%s%s\n", input2, input1);

	return 0;
}

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;

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

   string s, t;
   cin >> s >> t;
   cout << t + s << endl;
   return 0;
}


#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

const int MAX_V=102;
int vote[MAX_V];

int main(){ _;
  int n,q,m,tmp,result,resultCount;
  while(cin>>n>>q,(n|q)!=0){
    REP(i,MAX_V) vote[i]=0;
    REP(i,n){
      cin>>m;
      REP(j,m){
	cin>>tmp;
	vote[tmp]++;
      }
    }
    result=0;
    resultCount=q-1;
    REP(i,MAX_V){
      if(vote[i]>resultCount){
	result=i;
	resultCount=vote[i];
      }
    }
    cout<<result<<endl;
  }
}

#include "bits/stdc++.h"

using namespace std;

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

int main(){
    int n,m;
    int cost[600][600];
    while(cin>>n>>m){
        if(n==0&&m==0)break;
        rep(i,600)rep(j,600)cost[i][j]=999999999;
        rep(i,m){
            int a,b;
            cin>>a>>b;
            a--,b--;
            cost[a][b] = cost[b][a] = 1;
        }
        rep(k,n){
            rep(i,n){
                rep(j,n){
                    cost[i][j] = min(cost[i][j],cost[i][k]+cost[k][j]);
                }
            }
        }
        int sum=0;
        rep(i,600){
            if(cost[0][i]<=2&&i!=0)sum++;
        }
        cout<<sum<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;cin>>S;int i;
  for(i=1;i<S.size();i++)if(S.at(i-1)=='A'&&S.at(i)=='C')break;
  if(i==S.size())cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
}

#include <bits/stdc++.h>

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    vector<int64_t> ans;
    for (auto i : irange(2L, 55556L)) {
        if (i % 5 != 1) {
            continue;
        }

        bool ok = true;
        for (auto j = 2L; j * j <= i; ++j) {
            if (i % j == 0) {
                ok = false;
                break;
            }
        }

        if (ok) {
            ans.push_back(i);
        }

        if (ans.size() == n) {
            break;
        }
    }

    const auto* delim = "";
    for (auto a : ans) {
        cout << delim << a;
        delim = " ";
    }
    cout << endl;
}


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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) scanf("%d", &A[i]);

    vector<vector<int>> accum(1<<20);
    int now = 0;
    vector<ll> zero(N+1, 0);
    for (int i = 0; i < N; i++) {
        now ^= A[i];
        accum[now].push_back(i+1);
        if (now == 0) zero[i+1]++;
    }

    for (int i = 0; i < N; i++) {
        zero[i+1] += zero[i];
    }

    ll mod = 1e9+7;

    if (now > 0) {
        int K = accum[now].size();
        vector<ll> dp0(K+1, 0), dp1(K+1, 0);
        dp0[0] = 1;

        for (int i = 1; i <= K; i++) {
            if (i == 1) {
                dp0[i] = 1;
                dp1[i] = 1;
            }
            else {
                ll n = zero[accum[now][i-1]] - zero[accum[now][i-2]];
                dp0[i] = (dp0[i-1] + n * dp1[i-1]) % mod;
                dp1[i] = (dp0[i-1] + (n+1) * dp1[i-1]) % mod;
            }
        }
        cout << dp0[K]%mod << endl;
    }
    else {
        ll ans = 1;
        for (int i = 0; i < (int)accum[0].size()-1; i++) {
            ans = ans * 2 % mod;
        }

        for (int i = 1; i < (1<<20); i++) {
            if (accum[i].empty()) continue;
            int K = accum[i].size();
            vector<ll> dp0(K+1, 0), dp1(K+1, 0);
            dp0[0] = 1;

            for (int j = 1; j <= K; j++) {
                if (j == 1) {
                    dp0[j] = 1;
                    dp1[j] = 1;
                }
                else {
                    ll n = zero[accum[i][j-1]] - zero[accum[i][j-2]];
                    dp0[j] = (dp0[j-1] + n * dp1[j-1]) % mod;
                    dp1[j] = (dp0[j-1] + (n+1) * dp1[j-1]) % mod;
                }
            }
            ans += dp1[K];
        }
        cout << ans%mod << endl;
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
const int maxn = 5000500;
const int mod = 1e9 + 7;
int a[maxn], pref[maxn], cntzer[maxn];
long long dp[maxn];
vector < int > v[maxn];
long long add(long long a, long long b){
    a += b;
    if(a >= mod) a -= mod;
    return a;
}

long long mul(long long a, long long b){
    return (a * b) % mod;
}

long long solve_fixed(int n, int X){
    dp[pref[n - 1]] = 1;
    long long ans = (pref[n - 1] == X ? 1:0);
    for(int i = n - 2 ; i >= 0 ; --i){
        if(pref[i] == X) ans = add(ans, dp[0]);
        dp[pref[i]] = add(dp[pref[i]],dp[X ^ pref[i]]);
    }
    return ans;
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    long long xr = 0;
    for(int i = 0 ; i < n ; ++i)
        cin >> a[i];
    pref[0] = a[0];
    cntzer[0] = (a[0] ? 0:1);
    v[a[0]].push_back(0);
    for(int i = 1 ; i < n ; ++i){
        pref[i] = a[i] ^ pref[i - 1];
        cntzer[i] = !pref[i] + cntzer[i - 1];
        v[pref[i]].push_back(i);
    }
    long long ans = solve_fixed(n, 0);
    for(int i = 1 ; i < maxn ; ++i){
        if((int)v[i].size() == 0 || (v[i][(int)v[i].size() - 1] != n - 1 && pref[n - 1])) continue;
        long long smx = 1, sm0 = !pref[n - 1];
        ans = add(ans, smx);
        for(int j = (int)v[i].size() - 2 ; j >= 0 ; --j){
            sm0 = add(sm0, mul(cntzer[v[i][j + 1]] - cntzer[v[i][j]], smx));
            ans = add(ans, sm0);
            smx = add(smx, sm0);
        }
    }
    cout << ans << '\n';
    return 0;

}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
  ll n,i,j,sum=0,x,mn=INT_MAX;
  cin>>n;
  ll ar[n+1],cnt=0;
  for(i=0;i<n;i++)
  {
      cin>>ar[i];
      sum=sum+abs(ar[i]);
      if(ar[i]<0)
      {
          cnt++;
          x=abs(ar[i]);
          if(x<mn)
            mn=x;
      }
      else
      {
           if(ar[i]<mn)
            mn=ar[i];
      }
  }
  if(cnt%2==0)
  {
      cout<<sum<<endl;
  }
  else
  {
      sum=sum-(2*mn);
      cout<<sum<<endl;
  }

}

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;
int a[int(1e5+10)];
ll dp[100010][2];
int main() {
	int n;
	cin >> n;
	rep(i,n) cin >> a[i];
	dp[0][0] = 0;
	dp[0][1] = -(1LL<<60);
	rep(i,n) {
		dp[i+1][0]=max(dp[i][0]+a[i],dp[i][1]-a[i]);
		dp[i+1][1]=max(dp[i][0]-a[i],dp[i][1]+a[i]);
	}
	cout << dp[n][0] << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define ALL(x) x.begin(),x.end()

int get_int(){int x;scanf("%d",&x);return x;}

typedef long long ll;

const int mod = 998244353;
inline int mul(int x,int y){return 1ll*x*y%mod;}
int add(int x,int y) {return x+y>=mod?x+y-mod:x+y;}
int sub(int x,int y) {return x-y>=0?x-y:x-y+mod;}
int sq(int x){return 1ll*x*x%mod;}
int pows(int a,int b){return b == 0?1:(b&1?mul(a,sq(pows(a,b/2))):sq(pows(a,b/2)));}

const int maxn = 305;
int cnt[maxn*maxn];
int cnt2[maxn*maxn];

int sum;
int N;

void cal(int n,vector<int> &vi){
    cnt[0] = 1;
    cnt2[0] = 1;
    _for(i,0,N){
        int l = vi[i];
        for(int j = sum;j>=0;j--){
            cnt2[j] = add(cnt2[j],cnt2[j]);
            if(j-l >= 0) {
                cnt[j] = add(cnt[j],cnt[j-l]);
                cnt2[j] = add(cnt2[j],cnt2[j-l]);
            }
        }
    }
}

int main()
{
    vector<int> vi;
    N = get_int();
    _for(i,0,N){
        int num = get_int();
        sum += num;
        vi.push_back(num);
    }
    sort(ALL(vi));

    int ans = pows(3,N);
    //printf("all:%d\n",ans);

    cal(N,vi);
    //_rep(i,0,sum) printf("%d\n",cnt2[i]);

    _rep(i,(sum+1)/2,sum){
        ans = sub(ans,mul(3,cnt2[i]));
        //printf("%d\n",cnt2[i]);
    }

    if(!(sum&1)){
        ans = add(ans,mul(cnt[sum/2],3));
    }

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

#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
//#define mod 998244353
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;

int dp1[310][90909] = { 0 };
int dp2[310][90909] = { 0 };

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

	int N, sum = 0;
	int mod = 998244353;
	cin >> N;
	VI A(N);
	REP(i, N) {
		cin >> A[i];
		sum += A[i];
	}

	dp1[0][0] = 1;
	REP(i, N) {
		REP(j, 90909) {
			if (j + A[i] < 90909) {
				dp1[i + 1][j + A[i]] += dp1[i][j];
				dp1[i + 1][j + A[i]] %= mod;
			}
			dp1[i + 1][j] += 2 * dp1[i][j];
			dp1[i + 1][j] %= mod;
		}
	}

	int x = 0;
	REP(j, 90909) {
		if (j * 2 >= sum) {
			x += dp1[N][j];
			x %= mod;
		}
	}

	dp2[0][0] = 1;
	REP(i, N) {
		REP(j, 90909) {
			if (j + A[i] < 90909) {
				dp2[i + 1][j + A[i]] += dp2[i][j];
				dp2[i + 1][j + A[i]] %= mod;
			}
			dp2[i + 1][j] += dp2[i][j];
			dp2[i + 1][j] %=mod;
		}
	}

	int y = (sum % 2 == 0) ? dp2[N][sum / 2] : 0;

	int ans = 1;
	REP(i, N) {
		ans *= 3;
		ans %= mod;
	}
	//cout << x << endl;
	//cout << y << endl;
	//cout << ans << endl;
	//cout << (ans-3*x+3*y)%mod << endl;
	ans = (ans - 3 * x + 8 * mod) % mod;
	ans += 3 * y;

	cout << ans % mod << endl;

	return 0;
}


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

int main() {
  double r, a;
  cin >> r;
  a = 2 * r * 3.1415;
  cout << a << endl;
}

#include<bits/stdc++.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;

int main(){
    int n;
    while(scanf("%d",&n)!=EOF){
        long ans=0;
        //printf("%d\n",n);
        for(int i=0;i<600;i+=n){
            ans+=i*i*n;
        }

        printf("%ld\n",ans);
    }
    return 0;
}


#include <iostream>
#include <string>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string a, b, c;
	cin >> a >> b >> c;
	if (a[a.length() - 1] == b[0] && b[b.length() - 1] == c[0])
		cout << "YES";
	else
		cout << "NO";
}

#include<bits/stdc++.h>
using namespace std;
int main() {
	bool A=0;
	char ch,ch_;
	cin>>ch;
	ch_=ch;
	while((cin>>ch)!=0) {
		if(ch_=='A'&&ch=='C') {
			cout<<"Yes";
			return 0;
		}
		ch_=ch;
	}
	cout<<"No";
	return 0;
}


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

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

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


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int N, x;
    cin >> N >> x;
    int a[N];
    for(int i = 0; i < N; i++)
        cin >> a[i];

    sort(a, a + N);

    int cnt = 0, i = 0;
    while(x >= a[i] && i < N){
        cnt++;
        x -= a[i++];
    }
    if(i == N && x > 0)
        cnt--;

    cout << cnt << endl;
    return 0;
}

#include <bits/stdc++.h>

#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define all(v) v.begin(), v.end()
#define rip return;
#define fo(i,a,b) for(int i = a ; a < b ? i <= b : i >= b ; i += (a < b ? 1 : -1))

#define F first
#define S second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using pii = pair <int, int>;
using pll = pair <ll, ll>;
using ld = long double;

const int mod = 1e9 + 7;
// const int mod = 998244353;
const ll inf = 2e9;
const ll INF = 1e18;
const ld EPS = 1e-7;

const int N = 1e6 + 55;

int dp[N], dp2[N];

int solve (string s) {
	s = "0" + s;
	int n = s.size();
	fo (i, 0, n + 1) {
		dp[i] = 0, dp2[i] = 0;
	}
	dp2[0] = 1;
	fo (i, 1, n) {
		int u = s[i - 1] - '0';
		dp[i] = min (dp[i - 1] + u, dp2[i - 1] + 10 - u);
		dp2[i] = min (dp2[i - 1] + 9 - u, dp[i - 1] + 1 + u);
	}
	return dp[n];
}

int to_int (string s) {
	int res = 0;
	for (char c : s) {
		res = res * 10 + c - '0';
	}
	return res;
}

int dig (int x) {
	int res = 0;
	while (x) res += x % 10, x /= 10;
	return res;
}

pair <int, int> brute (string s) {
	int u = to_int (s);
	int best = dig (u), sec = u;
	for (int v = u ; v <= 1e7 ; ++ v) {
		int cur = dig (v) + dig (v - u);
		if (cur < best) {
			sec = v;
			best = cur;
		}
		// best = min (best, dig (v) + dig (v - u));
	}
	return {best, sec};
}

int main () {
	// ios;
	// cout << fixed << setprecision (10);
	int tt = 1;
	// cin >> tt;
	while (tt-- || 0) {
		string s;
		cin >> s;
		// cout << brute (s).F << " " << brute (s).S << "\n";
		// if (solve (s) != brute (s).F) {
			// cout << "ERROR " << solve (s) << " " << brute (s).F << "\n\t" << brute (s).S << "\nERROR " << s << "\n";
			// return 0;
		// }
		cout <<
		solve(s);
		// cout << "\n";
	}
}


#include <iostream>
#include <string>
#include <math.h>
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	int N,M;
	cin>>N>>M;
	int freq[N+1];
	memset(freq,0,sizeof(freq));
	int i,j,k;
	bool check[N+1];
	memset(check,false,sizeof(check));
	string s;
	for(i=1;i<=M;i++)
	{
		cin>>j>>s;
		if(s.compare("AC")==0)
		{
			check[j]=true;
		}
		else
		{
			if(check[j]==false)
			freq[j]++;
		}
	}
	j=0;
	k=0;
	for(i=1;i<=N;i++)
	{
		if(check[i])
		{
			j++;
			k=k+freq[i];
		}
	}
	cout<<j<<" "<<k;
	return 0;
}

#include<bits/stdc++.h>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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 n, a[111],b[111],c[111],d[111];
P p[111], pp[111];
bool used[111];
void solve(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i] >> b[i];
		p[i] = {b[i],a[i]};
	}
	for(int i = 0; i < n; i++){
		cin >> c[i] >> d[i];
		pp[i] = {c[i],d[i]};
	}
	sort(p,p+n,greater<P>());
	sort(pp,pp+n);

	int cnt = 0;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			if(pp[i].second < p[j].first) continue;
			if(pp[i].first < p[j].second) continue;
			if(used[j]) continue;
			used[j] = 1;
			cnt++;
			break;
		}
	}
	cout << cnt << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool nul[200];
bool nul1[200];
int main() {
	ios_base::sync_with_stdio(false);
	cout.precision(15);
	double pog =1/10e10;
	int n;
	cin>>n;
	double x[200], y[200];
	for(int i=0;i<n;i++){
		cin>>x[i]>>y[i];
	}
	if(n==2){
		cout<<"0.5"<<endl<<"0.5";
		return 0;
	}
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
            		int r=0;
            		bool h=1;
            		for(int k=0;k<n;k++){
            			if(k!=i&&k!=j){
            				double s=(x[i]-x[k])*(y[i]-y[j])-(y[i]-y[k])*(x[i]-x[j]);
            				if(s>pog){
                        				if(r==-1){
                        					h=0;
                        				}
                        				r=1;
            				}
            				if(s+pog<0){
                        				if(r==1){
                        					h=0;
                        				}
                        				r=-1;
            				}
            			}
            		}
			if(h==1){
            			nul[i]=1;
		        		nul[j]=1;
		        	//	cout<<i<<" "<<j<<endl;
            		}
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			for(int k=0;k<n;k++){
				if(k!=i&&j!=i&&j!=k){
					double s=(x[i]-x[k])*(y[i]-y[j])-(y[i]-y[k])*(x[i]-x[j]);
					if(s<pog&&s+pog>0){
                        				double f=abs(x[i]-x[k])+abs(y[i]-y[k]);
                        				double g=abs(x[i]-x[j])+abs(y[i]-y[j]);
                        				double s=abs(x[j]-x[k])+abs(y[j]-y[k]);
                        			//	cout<<i<<" "<<j<<endl;
                        				if(g+f+pog>s&&g+f-pog<s){
                        					nul1[i]=1;
                        	//	cout<<"eys"<<endl;
                        				}
            				}
				}
			}
		}
	}
	double ans[200];

	for(int i=0;i<n;i++){
		if(nul[i]==0||nul1[i]==1){
            		ans[i]=0;
		}
		else{
            		int j1;
            		int j2;
            		int j3;
            		int sled=0;
            		for(int j=0;j<n;j++){
            			int r=0;
            			bool h=1;
            			bool p=1;
            			for(int k=0;k<n;k++){
            				if(k!=i&&k!=j){
                        				double s=(x[i]-x[k])*(y[i]-y[j])-(y[i]-y[k])*(x[i]-x[j]);
                        				if(s>0){
                        					if(r==-1){
                        						h=0;
                        					}
                        					r=1;
                        				}
                        				if(s<0){
                        					if(r==1){
                        						h=0;
                        					}
                        					r=-1;
                        				}
                        				if(s==0&&sled>0){
                        					double f=abs(x[i]-x[j1])+abs(y[i]-y[j1]);
                        					double g=abs(x[i]-x[j])+abs(y[i]-y[j]);
                        					double s=abs(x[j]-x[j1])+abs(y[j]-y[j1]);
                        					if(s+f==g||s+g==f){
                        						p=0;
                        					}
                        				}
            				}
            			}
            			if(h==1&&j!=i&&p==0){
            				j3=j;
            			}
            			if(h==1&&sled==1&&j!=i&&p==1){
            				j2=j;
            				sled++;
            			}
            			if(h==1&&sled==0&&j!=i&&p==1){
            				j1=j;
            				sled++;
            			}
            		}
            		if(sled<2){
            			ans[i]=0.5;
            		}
            		else{
            			double a=sqrt((x[j1]-x[j2])*(x[j1]-x[j2])+(y[j1]-y[j2])*(y[j1]-y[j2]));
            			double b=sqrt((x[j1]-x[i])*(x[j1]-x[i])+(y[j1]-y[i])*(y[j1]-y[i]));
            			double c=sqrt((x[j2]-x[i])*(x[j2]-x[i])+(y[j2]-y[i])*(y[j2]-y[i]));
            			double angle=acos((c*c+b*b-a*a)/(2*b*c));
            			double pi= acos(-1);
            			ans[i] = (pi-angle)/(2*pi);
            		}
		}
	}
	for(int i=0;i<n;i++){
		cout<<ans[i]<<endl;
	}
	return 0;
}

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<complex>
#define rep(i, a, n) for(int i=a;i<n;i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define R long double
#define P complex<R>
using namespace std;
const int mod = 1000000007;
const int INF = 1e12;
template<class T>bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0;}
template<class T>bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0;}
const R PI = acos(-1.0L);
const R inf = 1e13;
int x[110], y[110];
R ans[110];
inline R dist(int i, P q) {
   P p = P(x[i], y[i]);
   return norm(p - q);
}
signed main(){
    int n;
    cin>>n;
    for (int i=0;i<n;i++)
	{
		cin>>x[i]>>y[i];
    }
    int limit = 200000;
    rep(i, 0, limit){
        R cur = 2.0 * PI / limit * i;
        P point = polar(inf, cur);
        R d = 1e130;
        int idx = -1;
        rep(j, 0, n) if(chmin(d, dist(j, point))) idx = j;
        ans[idx] += 1.0;
    }
    cout.precision(20);
	rep(i, 0, n) cout << fixed << 1.0 * ans[i] / limit << endl;
	return 0;
}


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

int main() {

	string s; cin >> s;
	int ans = 2147483647;
	for (int i = 0; i < s.size()-2; i++) {
		string tmp = s.substr(i, 3);
		ans = min(ans, abs(stoi(tmp) - 753));
	}
	cout << ans << endl;
	return 0;
}

#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <map>
#include <functional>
#include <limits>
#include <set>
#include <stack>
#include <cctype>
#define rep(i,a,b) for((i)=a;i<(int)(b);i++)

#define AAA (1000000007)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pairII;
typedef vector<int> vecI;

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll powD(ll a, ll b) {
	ll ans = 1;
	a %= AAA;
	for (int i = 0; i < b; i++)
	{
		ans *= a;
		ans %= AAA;
	}
	return ans;
}

int main() {
	int i, j, k;
	int N, M, K;

	string S;
	cin >> S;

	const int na = 753;
	j = S[0] - '0';
	j *= 10;
	j += S[1] - '0';
	j *= 10;
	j += S[2] - '0';

	int ans = abs(j - na);
	rep(i, 3, S.size()) {
		j %= 100;
		j *= 10;
		j += S[i] - '0';
		ans = min(ans, abs(j - na));
	}
	cout << ans << endl;
	return 0;
}


#include<iostream>
using namespace std;
int main(){
	int n,p;
	while(cin>>n>>p){
		bool f=true;
		int d[55]={};
		int cn=p;
		if(n==0)break;
		while(f){
			for(int i=0;i<n;i++){
				if(cn>0){
					d[i]++;
					cn--;
				}
				else if(cn==0){
					cn=d[i];
					d[i]=0;
				}
				if(d[i]==p){
						cout<<i<<endl;
						f=false;
						break;
				}
			}
		}
	}
	return 0;
}

#include <iostream>
using namespace std;

int main(){
  int a,b;
  cin >> a >> b;
  cout << a*b;
}


#include <bits/stdc++.h>

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

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    double r;
    cin >> r;
    cout << fixed << setprecision(10) << 2*M_PI*r << "\n";

    return 0;
}

#include <iostream>
#include <math.h>

using namespace std;
void Solve(int a)
{
	const double pi = 3.14;
	float ans;
	ans = 2 * pi * a;
	cout << ans;
}
int main()
{
	int x;
	cin >> x;
	Solve(x);
	return 0;
}


#include <stdio.h>
#include <string.h>

int main(){
	char A[11], B[11], C[11];
	scanf("%s %s %s", A, B, C);

	int lenA=0, lenB=0, lenC=0;
	lenA = strlen(A);
	lenB = strlen(B);
	lenC = strlen(C);

	if(A[lenA-1] == B[0] && B[lenB-1] == C[0] ){
		printf("YES");
	} else {
		printf("NO");
	}

	return 0;
}

#include <bits/stdc++.h>

#include <fstream>
using namespace std;

int n;
bool bad = false;

int check(vector<pair<int, int>> p){
  sort(p.begin(), p.end());
  int sum = 0;
  for (int i = 0; i < n; i++) {
    auto x = p[i];
    int hituyo = x.first;
    int yojo = x.second;
    if (yojo >= 0) {
      if (hituyo <= sum) {
        sum += yojo;
      } else {
        bad = true;
        break;
      }
    }
  }
  return sum;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  /*
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
  //*/
  cin >> n;
  vector<pair<int, int>> p1, p2;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int tmp = 0;
    int hituyo = 0;
    for (int j = 0; j < s.size(); j++) {
      if (s[j] == '(') {
        tmp++;
      } else {
        tmp--;
      }
      if ((-1) * tmp > hituyo) {
        hituyo = tmp * (-1);
      }
    }
    p1.emplace_back(hituyo, tmp);
    tmp = 0;
    hituyo = 0;
    for (int j = s.size() - 1; j >= 0; j--) {
      if (s[j] == ')') {
        tmp++;
      } else {
        tmp--;
      }
      if ((-1) * tmp > hituyo) {
        hituyo = tmp * (-1);
      }
    }
    p2.emplace_back(hituyo, tmp);
  }
  int sum1 = check(p1);
  int sum2 = check(p2);
  /*
  for (auto x : p) {
    cout << x.first << " " << x.second << endl;
  }
  //*/
  if (bad || sum1 != sum2) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}


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

struct base{
    #define type long long
    #define log 60
    type d[log+1] = {};
    bool insert(type x){
        for(int i=log; ~i; i--) if((x>>i)&1){
            if(!d[i]){
                d[i] = x;
                break;
            }
            x ^= d[i];
        }
        return x;
    }
    type max(){
        type ret = 0;
        for(int i=log; ~i; i--)
            if((ret^d[i]) > ret)
                ret ^= d[i];
        return ret;
    }
};

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

    long long xo = 0;
    vector <long long> v(n) ,prt(60 ,0);
    for(auto&a : v){
        scanf("%lld",&a) ,xo ^= a;
        for(int b=0; b<60; b++)
            prt[b] ^= (a>>b)&1;
    }

    base h;
    for(auto&a : v){
        for(int b=0; b<60; b++)
            a &= ~(prt[b]<<b);
        h.insert(a);
    }

    long long mx = h.max();
    printf("%lld\n",(xo^mx)+mx);
}

#include <bits/stdc++.h>

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L

#define long long long int

using namespace std;

// @author: pashka

int main() {
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<long> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    long s = 0;
    for (long x : a) s ^= x;
    vector<long> b(n - 1);
    for (int i = 0; i < n - 1; i++) {
        b[i] = a[i] & (~s);
    }
    sort(b.begin(), b.end());
    reverse(b.begin(), b.end());
    vector<long> q;
    long c = 0;
    for (long x : b) {
        for (long y : q) {
            x = min(x, x ^ y);
        }
        if (x > 0) {
            q.push_back(x);
            c = max(c, c ^ x);
        }
    }
    s += c * 2;
    cout << s;

    return 0;
}


#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int> PI;
#define MAX 1000009
int main(){
    int e;
    while(cin>>e,e){
        vector<PI> v3;
        for(int i =0;i<=100;i++){
            PI temp;
            temp.first=pow(i,3);temp.second=i;
            v3.push_back(temp);
        }
        vector<PI> v2;
        for(int i=0; i<=10000;i++){
            PI temp;
            temp.first=pow(i,2); temp.second=i;
            v2.push_back(temp);
        }
        PI min; min.first=INF; min.second=INF;
        for(int i=(int)v3.size()-1; i>=0;i--){
            for(int j=(int)v2.size()-1; j>=0;j--){
                if(v3[i].first+v2[j].first<=e){
                    if(min.second+min.first>e-(v3[i].first+v2[j].first)+v3[i].second+v2[j].second){
                        min.second=v3[i].second+v2[j].second;
                        min.first=e-(v3[i].first+v2[j].first);
                    }
                }
            }
        }
        cout<<min.second+min.first<<endl;
    }
    return 0;
}

#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#define ll long long
#define maxn 200010
inline ll read()
{
	ll x=0; char c=getchar(),f=1;
	for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
	for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
	return x*f;
}
inline void write(ll x)
{
	static int buf[20],len; len=0;
	if(x<0)x=-x,putchar('-');
	for(;x;x/=10)buf[len++]=x%10;
	if(!len)putchar('0');
	else while(len)putchar(buf[--len]+'0');
}
inline void writeln(ll x){write(x); putchar('\n');}
inline void writesp(ll x){write(x); putchar(' ');}
int a[maxn],d[maxn];
int cur[maxn],ans[maxn];
int n,m;
ll k;
int mul(int* a,int* b,int n)
{
	static int t[maxn];
	for(int i=1;i<=n;i++)
		t[i]=a[b[i]];
	for(int i=1;i<=n;i++)
		a[i]=t[i];
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
		a[i]=read();
	int S=a[1];
	for(int i=1;i<n;i++)
		d[i]=a[i+1]-a[i];
	m=read(); k=read();
	for(int i=1;i<n;i++)
		cur[i]=ans[i]=i;
	for(int i=1;i<=m;i++){
		int x=read();
		std::swap(cur[x-1],cur[x]);
	}
	for(;k;k>>=1,mul(cur,cur,n-1))
		if(k&1)mul(ans,cur,n-1);
	ll X=a[1];
	for(int i=1;i<=n;i++){
		writeln(X);
		X+=d[ans[i]];
	}
	return 0;
}


#include <iostream>
using namespace std;
int main(void){
  int one;
  int two;
  int three;
  cin>>one>>two>>three;
  if(one==two){
     if(one!=three||two!=three){
     cout<<"Yes";
     }
    else{
    cout<<"No";
    }
  }
  else if(one ==three){
       if(one!=two||three!=two){
    cout<<"Yes";
    }
    else{
    cout<<"No";
    }
  }
  else if(two==three){
    if(two!=one||three!=one){
    cout<<"Yes";
    }
    else{
    cout<<"No";
    }
  }
  else{
  cout<<"No";
  }
return 0;
}

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main() {
    string S;
    cin >> S;
    REP(i, S.size()-1) {
        if (S[i] == 'A' && S[i+1] == 'C') {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


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

int main() {
  int n, m, x, y;
  cin >> n >> m >> x >> y;
  int xmax = x;
  int ymin = y;
  int a, b;
  for (int i = 0; i < n; i++) {
    cin >> a;
    xmax = max(a, xmax);
  }
  for (int i = 0; i < m; i++) {
    cin >> b;
    ymin = min(b, ymin);
  }
  if (xmax < ymin) {
    cout << "No War" << endl;
  }
  else {
    cout << "War" << endl;
  }
}

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

bool is_war(const vector<int>& x, const vector<int>& y) {
  return *max_element(x.begin(), x.end()) >= *min_element(y.begin(), y.end());
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> x(N + 1), y(M + 1);
  cin >> x[0] >> y[0];
  rep(i, 0, N) cin >> x[i + 1];
  rep(i, 0, M) cin >> y[i + 1];

  if (is_war(x, y))
    cout << "War" << endl;
  else
    cout << "No War" << endl;

  return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

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

    int x, y;
    cin >> x >> y;
    int add = x + y;
    int sub = x - y;
    int into = x * y;
    if (add >= sub && add >= into) {
        cout << add << "\n";
    } else if (sub >= add && sub >= into) {
        cout << sub << "\n";
    } else {
        cout << into << "\n";
    }

}

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

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

// const double PI = acos(-1);
// int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
// int a[12][12];

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

}

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


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

#define MAX_V 100000

int V, E;
vector<int> G[MAX_V];
bool visited[MAX_V];
int prenum[MAX_V];
int parent[MAX_V];
int lowest[MAX_V];
int timer, root;

void add_edge(int from, int to) {
  G[from].push_back(to);
  G[to].push_back(from);
}

void dfs(int u, int prev) {
    prenum[u] = timer;
    lowest[u] = timer;
    timer++;

    visited[u] = true;

    for(int i = 0; i < G[u].size(); i++) {
      int v = G[u][i];
      if(!visited[v]) {
        parent[v] = u;
        dfs(v, u);
        lowest[u] = min(lowest[u], lowest[v]);
      } else if(v != prev) {
        lowest[u] = min(lowest[u], prenum[v]);
      }
    }

}

int main () {
  cin >> V >> E;
  for(int i = 0; i < E; i++) {
    int v1, v2;
    cin >> v1 >> v2;
    add_edge(v1, v2);
  }

  for(int i = 0; i < V; i++) {
    visited[i] = false;
  }
  root = 0;
  timer = 1;
  dfs(root, -1);

  set<int> ans;
  // (1)
  int num = 0;
  for(int i = 0; i < V; i++) {
    if(i == root) continue;
    if(parent[i] == root) num++;
  }
  if(num >= 2) ans.insert(root);

  // (2)
  for(int i = 0; i < V; i++) {
    if(i == root || parent[i] == root) continue;
    else if(prenum[parent[i]] <= lowest[i])
      ans.insert(parent[i]);
    // cout << i << endl;
  }

  set<int>::iterator it = ans.begin();
  while(it != ans.end()) {
    cout << *it << endl;
    it++;
  }

}

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector<s>
#define vvec(s) vector<vector<s>>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli, lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout << (x ? "Yes" : "No") << endl;
#define out(s) cout << s << endl;
#define pb(s) push_back(s);
#define sp " "
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(), s.end()
void vout(vi v)
{
    for (int i = 0; i < v.size(); i++)
        cout << v.at(i) << endl;
}
int main()
{
    lli n, m;
    cin >> n >> m;
    vi rec(n, 0);
    lli ans = 0, ans2 = 0;
    vec(bool) c(n, false);
    rep(i, m)
    {
        lli p;
        string s;
        cin >> p >> s;
        p--;
        if (s == "WA")
        {
            rec[p]++;
        }
        else
        {
            if (!c[p])
            {
                ans += rec[p];
                ans2++;
                c[p] = true;
            }
        }
    }
    out(ans2 << sp << ans);
}


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

int main() {

  int N; cin >> N;

  string S; cin >> S;

  int sumE = 0, sumW = 0, ans = N, leftE = 0, leftW = 0;

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

    if (S.at(i) == 'E') sumE++;
    if (S.at(i) == 'W') sumW++;

  }

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

    int tmp = 0;

    if (S.at(i) == 'E') tmp = 1;
    if (S.at(i) == 'W') tmp = 0;

    int cost = leftW + sumE - leftE - tmp;

    ans = min(ans, cost);

    if (S.at(i) == 'E') leftE++;
    if (S.at(i) == 'W') leftW++;

  }

  cout << ans << endl;

}

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

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> l(n);
    for (int i = 0; i < n; i++)
    {
        cin >> l[i];
    }
    sort(l.begin(), l.end());
    reverse(l.begin(), l.end());
    int total = 0;
    for (int i = 0; i < k; i++)
    {
        total += l[i];
    }
    cout << total << endl;
    return 0;
}