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

using namespace std;

const char ok = '1';
const char no = '0';

struct P{
	int x;
	int y;
	int z;
};

int main()
{
	int a, b, c, n, v;
	char ch[301];
	P p;

	while(cin>>a>>b>>c && (a+b+c)){
		cin >> n;
		fill(ch, ch+301, '2');
		vector<P> vec;

		while(n--){
			cin >> p.x >> p.y >> p.z >> v;
			if(v == 1){
				ch[p.x] = ch[p.y] = ch[p.z] = ok;
			} else {
				vec.push_back(p);
			}
		}

		for(int i = 0; i < vec.size(); i++){
			if(ch[vec[i].x] == ok && ch[vec[i].y] == ok){
				ch[vec[i].z] = no;
			} else if(ch[vec[i].x] == ok && ch[vec[i].z] == ok){
				ch[vec[i].y] = no;
			} else if(ch[vec[i].y] == ok && ch[vec[i].z] == ok){
				ch[vec[i].x] = no;
			}
		}
		for(int i = 1; i <= a+b+c; i++){
			cout << ch[i] << endl;
		}
	}

	return 0;
}

#include<bits/stdc++.h>
#define ll long long
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define pi(x) printf("%d",x)
#define pl(x) printf("%lld",x)
#define pb push_back
#define mkp make_pair
#define fi first
#define se second
#define re register
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define per(i,n,m) for(int i=m;i>=n;i--)
#define rrep(i,m,n) for(register int i=m;i<=n;i++)
#define rper(i,n,m) for(register int i=m;i>=n;i--)
#define ull unsigned  long long
using namespace std;
const int INF =1e9+10;
const int N = 1e3 + 10;
int n,d1,d2,cnt;
int a[N][N];
void solve(int x){
    int tmp=0;
    while(x%4==0){
        x/=4;
        tmp++;
    }
    if(x&1){
        rep(i,0,n*2-1){
            rep(j,0,n*2-1){
                if(((i>>tmp)+(j>>tmp))&1){
                    a[i][j]=1;
                }
            }
        }
    }else{
        rep(i,0,n*2-1){
            rep(j,0,n*2-1){
                if(((i>>tmp))&1){
                    a[i][j]=1;
                }
            }
        }
    }
}
signed main() {
    si(n);
    si(d1);
    si(d2);
    solve(d1);
    solve(d2);
    rep(i,0,n*2-1){
        rep(j,0,n*2-1){
            if(cnt<n*n&&!a[i][j]){
                printf("%d %d\n",i,j);
                cnt++;
            }
        }
    }
    return 0;
}


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

int const N = 2e5 + 7;
int n, k;
int bit[N];
int ar[N];

void add(int x, int val)
{
	while (x < N)
		bit[x] += val, x += (x & -x);
}

int sum(int x)
{
	int res = 0;
	while (x)
		res += bit[x], x -= (x & -x);
	return res;
}

//Lamps with N radius
int getMax()
{
	int res = 0;
	for (int i = 1; i <= n; ++i)
		res += (ar[i] == n);
	return res;
}

void update()
{
	memset(bit, 0, sizeof(bit));
	for (int i = 1; i <= n; ++i)
	{
		add(max(1, i - ar[i]), 1);
		add(min(n+1, i + ar[i] + 1), -1);
	}

	for (int i = 1; i <= n; ++i)
		ar[i] = sum(i);
}

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

	for (int i = 1; i <= n; ++i)
		cin >> ar[i];

	for (int i = 0; i < k; ++i)
	{
		update();
		if (getMax() == n)
			break;
	}
	for (int i = 1; i <= n; ++i)
	{
		if (i != 1) cout << " ";
		cout << ar[i];
	}
	cout << '\n';
	return 0;
}

#include <bits/stdc++.h>

#if DEBUG
template <typename Iter>
void debug_iter(Iter begin, Iter end);
template <typename T>
void debug(const T& value) {
  std::cerr << value;
}
template <typename T, size_t N>
void debug(const std::array<T, N>& a) {
  debug_iter(a.begin(), a.end());
}
template <typename T>
void debug(const std::vector<T>& v) {
  debug_iter(v.begin(), v.end());
}
template <typename T>
void debug(const std::set<T>& s) {
  debug_iter(s.begin(), s.end());
}
template <typename T, typename U>
void debug(const std::map<T, U>& m) {
  debug_iter(m.begin(), m.end());
}
template <typename T, typename U>
void debug(const std::pair<T, U>& p) {
  std::cerr << "{";
  debug(p.first);
  std::cerr << ", ";
  debug(p.second);
  std::cerr << "}";
}
template <typename T, typename... Ts>
void debug(const T& value, const Ts&... args) {
  debug(value);
  std::cerr << ", ";
  debug(args...);
}
template <typename Iter>
void debug_iter(Iter begin, Iter end) {
  std::cerr << "{";
  for (Iter it = begin; it != end; ++it) {
    if (it != begin) std::cerr << ", ";
    debug(*it);
  }
  std::cerr << "}";
}
#define dbg(...)                        \
  do {                                  \
    cerr << #__VA_ARGS__ << ": ";       \
    debug(__VA_ARGS__);                 \
    cerr << " (L" << __LINE__ << ")\n"; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define rd(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << '\n';
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define wt(...) write_to_cout(__VA_ARGS__);

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

template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& v) {
  for (T& vi : v) is >> vi;
  return is;
}

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

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

#include <boost/hana/functional/fix.hpp>
auto Fix = [](auto&& f) { return boost::hana::fix(f); };

using ll = long long;

template <typename T>
using low_priority_queue =
    std::priority_queue<T, std::vector<T>, std::greater<T>>;

template <typename T>
using V = std::vector<T>;
template <typename T>
using VV = V<V<T>>;

using namespace std;

int main() {
  rd(ll, n, k);
  vector<ll> a(n);
  cin >> a;
  rep(i, k) {
    vector<ll> na(n);
    rep(j, n) na[j] = 1;
    {
      low_priority_queue<ll> que;
      rep(j, n) {
        while (!que.empty() && que.top() < j) que.pop();
        na[j] += que.size();
        que.push(j + a[j]);
      }
    }
    {
      priority_queue<ll> que;
      for (ll j = n - 1; j >= 0; --j) {
        while (!que.empty() && que.top() > j) que.pop();
        na[j] += que.size();
        que.push(j - a[j]);
      }
    }
    if (na == a) break;
    swap(a, na);
  }
  rep(i, n) cout << a[i] << " ";
  cout << endl;
}


#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;

#define NUM 2147483647

int N = 1;
int* data;

void init(int first_N){
	while(N < first_N)N *= 2;
}

void update(int update_left,int update_right,int new_value,int node_id,int node_left,int node_right){
	if(update_right < node_left || update_left > node_right)return;
	else if(update_left <= node_left && update_right >= node_right){
		data[node_id] = new_value;
	}else{
		if(data[node_id] >= 0){
			data[2*node_id+1] = data[node_id];
			data[2*node_id+2] = data[node_id];
			data[node_id] = -1;
		}
		update(update_left,update_right,new_value,2*node_id+1,node_left,(node_left+node_right)/2);
		update(update_left,update_right,new_value,2*node_id+2,(node_left+node_right)/2+1,node_right);
	}
}

int query(int search_left,int search_right,int node_id,int node_left,int node_right){
	if(search_right < node_left || search_left > node_right){
		return -1;
	}else if(node_left <= search_left && node_right >= search_right && data[node_id] >= 0){
		return data[node_id];
	}else{
		int left = query(search_left,search_right,2*node_id+1,node_left,(node_left+node_right)/2);
		int right = query(search_left,search_right,2*node_id+2,(node_left+node_right)/2+1,node_right);
		return max(left,right);
	}
}

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

	init(first_N);

	data = new int[270000];

	for(int i = 0; i <= 2*N-2; i++)data[i] = NUM;

	int command,left,right,value,loc;

	for(int i = 0; i < Q; i++){
		scanf("%d",&command);

		if(command == 0){
			scanf("%d %d %d",&left,&right,&value);
			update(left,right,value,0,0,N-1);
		}else{
			scanf("%d",&loc);
			printf("%d\n",query(loc,loc,0,0,N-1));
		}
	}
}


#include <iostream>
#include <string.h>

using namespace std;

int main()
{
    string str;
    cin>>str;
    for(int i = 0;i<str.length();i++)
        cout<<str[str.length()-(i+1)];

    cout<<"\n";

    return 0;
}

#include <iostream>
#include <string>
using namespace std;
int main(){
	string str;
	while(1){
		cin>>str;
		if (cin.eof())
			break;
		for(int i = (str.size()-1); i>=0; i--)
			cout<<str[i];
		cout<<endl;
	}
	return 0;
}


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

int n, k;

double kitaichi(vector<int> p, int start, int k){
  double ans;
  for (int i = 0; i < k; i++){
    double sum = 0;
    for (int j = 1; j <= p[start+i]; j++){
      sum += j;
    }
    ans += sum/p[start+i];
  }
  return ans;
}

int main() {
  cin >> n >> k;
  vector<int> p(n);
  for (int i = 0; i < n; i++){
    cin >> p.at(i);
  }
  int sum = 0;
  int start;
  int s = 0;
  for (int i = 0; i  < 1; i++){
    for (int j = 0; j < k; j++){
      s += p.at(i+j);
    }
    sum = s;
    start = i;
  }
  for (int i = 1; i + k <= n; i++){
    s += p.at(i+k-1);
    s -= p.at(i-1);
    if (sum < s){
      sum = s;
      start = i;
    }
  }
  cout << fixed << setprecision(15) << kitaichi(p, start, k) << endl;
}

#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";};
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    ll n,m;
    cin >> n >> m;
    Vi mods(n),sum(n+1);
    rp(i,n){
        cin >> mods.at(i);
        mods.at(i)%=m;
    }
    sum[0]=0;
    rp(i,n){
        sum[i+1]=sum[i]+mods[i];
        sum[i+1]%=m;
    }
    sort(all(sum));
    ll ans=0;
    ll ctr=1;
    rp(i,n){
        if(sum[i]==sum[i+1]){
            ctr++;
        }
        else{
            ans += ctr*(ctr-1)/2;
            ctr=1;
        }
    }
    ans+=ctr*(ctr-1)/2;
    print(ans);
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}


#include<iostream>
using namespace std;
int main(){
    int n[20];
    int c[20][10];
    int l =0;
    int k;
    while(cin >> n[l]){
        if(n[l] == 0){break;}
        for (int i = 0; i< 10; i++){
            c[l][i] = 0;
        }
        for(int i= 0;i < n[l] ;i++){
            cin >> k;
            c[l][k] ++;
        }
        l ++;
    }
    for(int i = 0;i < l;i++){
        for(int j = 0;j<10;j++){
        if (c[i][j] == 0){
            cout << "-" << endl;
        }
        else{
            for(int w = 0;w < c[i][j];w++){
                cout << "*";
            }
            cout << endl;
        }
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back
#define Cout(s) cout << s << endl
string Yes(bool b) {if(b){return "Yes";} else {return "No";}}
string YES(bool b) {if(b){return "YES";} else {return "NO";}}

int main(){
	string S;
	cin >> S;
	string T = "AC";
	bool ok = false;
	rep(i, S.size()-1){
		string s = S.substr(i, 2);
		if(s == T) ok = true;
	}

	Cout(Yes(ok));
}

#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 n;
	cin >> n;
	string s,t;
	cin >> s >>t;
	int ans = s.size() + t.size();
	int i = n;
	int j = 0;
	int leng = 1;
	int counts = 0;
	int kouho = 0;
	int kotae = s.size() + t.size();
	while(n--){
		if(s.substr(i-1,leng) == t.substr(j,leng)){
			kouho = ans - leng;
			kotae = min(kotae,kouho);
		}
		i--;
		leng++;
	}
	cout << kotae << endl;
}

// cout << fixed << setprecision(15) <<  << endl;


#include<bits/stdc++.h>
#define maxn 100005
using namespace std;
int n,m;
int main()
{
	int x,y,l=0,r=maxn;
	scanf("%d %d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		scanf("%d %d",&x,&y);
		l=max(x,l),r=min(y,r);
	}
	if(l>r)printf("0");
	else printf("%d\n",r-l+1);
	return 0;
}

#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
	int m,n;
	int mp[100005];
	scanf("%d %d",&m,&n);
	memset(mp,0,sizeof(mp));
	int t=n;
	while(t--)
	{
		int l,r;
		scanf("%d %d",&l,&r);
	for(int i=l;i<=r;i++)
	{
		mp[i]++;
	}
    }
    int sum=0;
    for(int i=1;i<=m;i++)
    {
    	if(mp[i]==n)
    	sum++;
	}
	printf("%d\n",sum);
	return 0;
}


#include <cstdio>
int a[100010],sum[2],n;
bool flag;
int gcd(int a,int b)
{
	if (b==0) return a;
	else return gcd(b,a%b);
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if (a[i]>1) sum[a[i]&1]++;
	}
	if (n==1)
	{
		if (a[1]&1) printf("Second\n");
		else printf("First\n");
		return 0;
	}
	flag=false;
	while (1)
	{
		if (!sum[0]&&!sum[1])
		{
			if (!flag) printf("Second\n");
			else printf("First\n");
			return 0;
		}
		if (sum[0]&1)
		{
			if (!flag) printf("First\n");
			else printf("Second\n");
			return 0;
		}
		if (sum[1]>1||!sum[1])
		{
			if (!flag) printf("Second\n");
			else printf("First\n");
			return 0;
		}
		int GCD=-1;
		for (int i=1;i<=n;i++)
			if (a[i]>1)
			{
				if (a[i]&1)
				{
					a[i]--;break;
				}
			}
		for (int i=1;i<=n;i++)
			if (GCD==-1) GCD=a[i];
			else GCD=gcd(a[i],GCD);
		sum[0]=sum[1]=0;
		for (int i=1;i<=n;i++)
		{
			a[i]/=GCD;
			if (a[i]>1) sum[a[i]&1]++;
		}
		flag^=1;
	}
	return 0;
}
//all is 1: who faces even number of even number, lose./odd number of even number, win.

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

typedef long long ll;
static const int MAX = 510000;
static const ll MOD = 1000000007;

int main(){
    int N;
    cin>>N;
    vector<ll> A(N);
    for(int i=0; i<N; i++) cin>>A[i];
    vector<ll> color(3,0);

    ll ans = 1;

    for(int i=0; i<N; i++){
        ll kake = 0;
        for(int j=0; j<3; j++){
            if(color[j] == A[i]) kake++;
        }

        ans *= kake;
        ans %= MOD;

        for(int j=0; j<3; j++){
            if(color[j] == A[i]){
                color[j]++;
                break;
            }
        }
    }

    cout<<ans<<endl;
}


#include<cstdio>
#include<algorithm>

using namespace std;
int main(void)
{
	double a[10];
	double v[2];
	double ans;
	while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5],&a[6],&a[7],&a[8],&a[9],&v[0],&v[1]) != EOF)
	{
		double all = 0;
		double kari = 0;
		for(int i = 0;i < 10;i++) all += a[i];
		ans = (v[0] * all) / (v[0] + v[1]);
		if(ans == 0) printf("1\n");
		else
		{
			for(int i = 0;i < 10;i++)
			{
				kari += a[i];
				if(kari >= ans)
				{
					printf("%d\n",i+1);
					break;
				}
			}
		}
	}
	return 0;
}

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

int main(){
	double l[10], t[10], a, b;
	char c;
	while(cin >> l[0] >> c){
		t[0] = l[0];
		for(int i = 1;i< 10;i++){cin >> l[i] >> c;t[i] = t[i-1] + l[i];}
		cin >> a >> c >> b;
		double tmp = t[9]/(a+b)*a;
		int ans = 1;
		while(tmp > t[ans-1]){
			ans++;
		}
		cout << ans << endl;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(int argc, const char *argv[]) {
  string s;
  int w;
  cin >> s >> w;

  string result;
  for (int i = 0; i < s.size(); i += w) {
    result += s[i];
  }

  cout << result << '\n';
}

#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;
typedef pair<ll,ll> pairs;
vector<pairs> p;

ll gcd(ll A,ll B){
    if (A%B==0)return(B);
    else return(gcd(B,A%B));
}

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

vector<vector<ll>> combination(ll n, ll r){
    vector<vector<ll>> v(n + 1, vector<ll>(n + 1, 0));
    for(ll i=0;i<v.size();++i){
        v[i][0] = 1;
        v[i][i] = 1;
    }
    for(ll i=1;i<v.size();++i){
        for(ll j=0;j<i;++j){
            v[i][j] = (v[i - 1][j - 1] + v[i - 1][j]);
        }
    }
    return v;
}

bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    string s;
    cin>>s;
    ll w;
    cin>>w;
    for(ll i=0;i<s.size();i+=w){
        cout<<s[i];
    }
    cout<<endl;

    return 0;
}


#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

int main() {
	double PI = 3.14159265358979, R; cin >> R;
	printf("%.12lf\n", 2.0 * R * PI);
	return 0;
}

#include<iostream>
using namespace std;
int main (void)
{
  int r;
  cin>>r;
  r=r*2*3141592;
  cout<<r/1000000<<"."<<r%1000000;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int n, m;
  cin >> n >> m;
  vi a(m);
  rep(i, m) cin >> a[i];
  vi b = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
  vi dp(n + 1, -1);
  dp[0] = 0;
  rep(j, n) rep(i, m) {
    if(dp[j] == -1) continue;
    int nj = j + b[a[i]];
    if(nj <= n) dp[nj] = max(dp[nj], dp[j] + 1);
  }
  int j = n;
  string ans = "";
  while(j) {
    int num = 0;
    rep(i, m) {
      int nj = j - b[a[i]];
      if(nj >= 0 && dp[nj] == dp[j] - 1) num = max(num, a[i]);
    }
    ans.push_back((char)(num + '0'));
    j -= b[num];
  }
  cout << ans << endl;
}

#include<bits/stdc++.h>
using namespace std;
int read() {
    char cc = getchar(); int cn = 0, flus = 1;
    while(cc < '0' || cc > '9') {  if( cc == '-' ) flus = -flus;  cc = getchar();  }
    while(cc >= '0' && cc <= '9')  cn = cn * 10 + cc - '0', cc = getchar();
    return cn * flus;
}
const int N = 1000 + 5 ;
#define rep( i, s, t ) for( register int i = s; i <= t; ++ i )
int n, m, book[N], w[N][N], vis[N], can[N];
bool check( int x ) {
    memset( book, 0, sizeof(book) ), memset( can, 0, sizeof(can) ) ;
    int flag ; rep( i, 1, n ) vis[i] = 1, ++ book[w[i][vis[i]]] ;
    rep( i, 1, m ) {
        flag = 1 ;
        rep( j, 1, n ) {
            int u = w[j][vis[j]] ;
            if( book[u] > x ) {
                can[u] = 1; flag = 0 ;
                while( vis[j] <= n && can[w[j][vis[j]]] ) ++ vis[j] ;
                if( vis[j] > n ) return 0;
                ++ book[w[j][vis[j]]] ;
            }
        }
        if( flag ) return 1;
    }
    return 0 ;
}
signed main()
{
    n = read(), m = read() ;
    rep( i, 1, n ) rep( j, 1, m ) w[i][j] = read() ;
    int l = 1, r = n, ans = 0, mid ;
    while( l <= r ) {
        mid = ( l + r ) >> 1 ;
        if( check(mid) ) ans = mid, r = mid - 1 ;
        else l = mid + 1 ;
    }
    printf("%d\n", ans ) ;
    return 0;
}


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

int main(){
    string s;
    cin >> s;
    long long n=s.size();
    for(long long i=0;i<n-1;i++){
        if(s[i]==s[i+1]){
            cout << i+1 << " " << i+2 << endl;
            return 0;
        }
    }
    for(long long i=0;i<n-2;i++){
        if(s[i]==s[i+2]&&s[i]!=s[i+1]){
            cout << i+1 << " " << i+3 << endl;
            return 0;
        }
    }
    cout << -1 << " " << -1 << endl;
    return 0;
}

/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define ALL(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef priority_queue<int> p_que;
typedef priority_queue<int, vector<int>, greater<int>()> p_que_rev;
// const int INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    lint k;
    cin >> k;
    const lint n = 50;
    vector<lint> a(n);
    for (int i=0; i<n; ++i){
        a[i] = i;
    }
    lint p = k / n;
    lint r = k % n;
    if(r == 0){
        for (int i=0; i<n; ++i){
            a[i] = p + i;
        }
    }
    else {
        for (int i=r-1; i>=0; --i){
            a[i] = n + p - (r - 1 - i);
        }
        for (int i=r; i<n; ++i){
            a[i] = i - r + p;
        }
    }
    bool isFst = true;
    cout << n << endl;
    for (int i=0; i<n; ++i){
        if(isFst){
            isFst = false;
            cout << a[i];
        }
        else {
            cout << " " << a[i];
        }
    }
    cout << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e9;
const static ll MOD = 1e9+7;

int main(){
    int N; cin >> N;
    vector<int> A(N); for(int i = 0; i < N; i++) cin >> A[i];
    sort(A.begin(), A.end());
    ll ans = 0;
    for(int i = N-1; i >= 0; i--){
        for(int j = 30; j >= 1; j--){
            ll key = pow(2, j) - A[i];
            if(key <= 0) break;
            auto itr = lower_bound(A.begin(), A.end(), key);
            if(*itr != key) continue;
            int d = distance(A.begin(), itr);

            if(i == d) {
                continue;
            }

            A.erase(A.begin()+i);
            A.erase(A.begin()+d);
            //cout << d << " " << i << " " << A.size() << endl;
            i--;
            ans++;

            break;
        }
    }
    cout << ans << endl;
}

//include
//------------------------------------------
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>

#include <numeric>
#include <utility>
#include <complex>

#include <sstream>
#include <iostream>
#include <iomanip>

#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <ctime>

// namespace
using namespace std;

// type alias
using ll = long long;
using ull = unsigned long long;
using comp = complex<double>;

// constant
static const ll MOD = 1000000007LL;
static const double PI = 3.14159265358979323846;

// conversion
inline ll toint(string s) { ll v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

// print
#define RET(x) return cout << x << endl, 0;

// for loop
#define REP(i, a, b) for ((i) = (ll)(a);(i) < (ll)(b);(i)++)
#define REPD(i, a, b) for (ll i = (ll)(a);(i) < (ll)(b);(i)++)
#define REPI(v, vs) for (auto& v : vs)

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl
#define DEBUG(x) cerr << #x << " = " << (x) << " (l" << __LINE__ << ")" << " " << __FILE__ << endl

#define MAX_VALUE 9223372036854775807

inline ll get_highest_one_bit(ll a)
{
	while ((a & (a - 1)) != 0)
	{
		a = a & (a - 1);
	}
	return a;
}

int solve() {
	ll N;
	cin >> N;

	map<ll, ll> val_to_count;
	ll a, b;
	REPD(i, 0, N) {
		cin >> a;
		if (val_to_count.count(a) == 0) val_to_count[a] = 0;
		++val_to_count[a];
	}

	ll res = 0;
	vector<bool> used(N, false);
	for (auto iter = val_to_count.end(); iter != val_to_count.begin(); ) {
		--iter;
		a = iter->first;
		b = get_highest_one_bit(a) * 2LL - a;
		if (val_to_count[a] == 0) continue;
		if (val_to_count.count(b) > 0) {
			if (a != b) {
				ll count = min(val_to_count[a], val_to_count[b]);
				val_to_count[a] -= count;
				val_to_count[b] -= count;
				res += count;
			}
			else {
				ll count = val_to_count[a] / 2LL;
				val_to_count[a] -= count * 2LL;
				res += count;
			}
		}
	}

	RET(res);

	return 0;
}

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

	solve();
	// ll t;
	// cin >> t;
	// REPD(i, 0, t) solve();

	return 0;
}


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

vector<vector<int> >adj1,adj2;
map<int,int>mm;
int vis[200005];
int vis2[200005];
vector<int>comp;
int ans[200005];
int parent[200005];

void dfs(int ver)
{
    comp.push_back(ver);
    vis[ver]=1;
    for(auto i:adj1[ver])
    {
        if(!vis[i])
        {
            dfs(i);
        }
    }
}
vector<int>temp;

void dfs2(int ver,int dest)
{
    parent[ver]=dest;
    vis2[ver]=1;
    for(auto i:adj2[ver])
    {
        if(!vis2[i])
            dfs2(i,dest);
    }
}

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

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif

    int n,k,l;
    cin>>n>>k>>l;
    int x,y;
    adj1.resize(n+1);
    adj2.resize(n+1);
    for(int i=0;i<k;i++)
    {
        cin>>x>>y;
        adj1[x].push_back(y);
        adj1[y].push_back(x);
    }
    for(int i=0;i<l;i++)
    {
        cin>>x>>y;
        adj2[x].push_back(y);
        adj2[y].push_back(x);
    }
    for(int i=1;i<=n;i++)
    {
        if(!vis2[i])
            dfs2(i,i);
    }

    for(int i=1;i<=n;i++)
    {
        if(!vis[i])
        {
            comp.clear();
            mm.clear();
            dfs(i);
            for(auto j:comp)
            {
                mm[parent[j]]++;
            }
            for(auto j:comp)
            {
                ans[j]=mm[parent[j]];
            }
        }
    }

    for(int i=1;i<=n;i++)
    {
            cout<<ans[i]<<" ";
    }

}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

ll N, M;
vector<int> to[100010];
int idx[100010];
int edge[100010];
int node[100010];
int oe[100010];
int judge[100010];
int es[200010];
ll ans = 0;

void dfs(int v, int id, int type){
    idx[v] = id;
    node[id]++;
    oe[v] = type;
    for(auto u : to[v]){
        if(idx[u] != 0){
            if(oe[u] == type) judge[id] = true;
        }else{
            dfs(u, id, (type + 1) & 1);
        }
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N >> M;
    ans = N * N;

    for(int i = 0; i < M; i++){
        int u, v;
        cin >> u >> v;
        es[i] = u;
        to[u].emplace_back(v);
        to[v].emplace_back(u);
    }

    int id = 1;
    for(int i = 1; i <= N; i++){
        if(idx[i] == 0) dfs(i, id++, 0);
    }
    for(int i = 0; i < M; i++){
        edge[idx[es[i]]]++;
    }
    ll nsum = 0, graph = 0, oc = 0;
    for(int i = 1; i < id; i++){
        if(node[i] == 1) continue;
        nsum += node[i];
        graph++;
        if(!judge[i]) oc++;
    }
    cout << ans - (nsum * nsum) + (graph * graph) + (oc * oc) << endl;
    return 0;
}


#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>
#include <functional>
#include <chrono>
#include <stack>

using namespace std;

#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

ostream& operator<< (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << " ";
    return a;
}

istream& operator>> (istream& a, pii& b) {
    cin >> b.first >> b.second;
    return a;
}

ostream& operator<< (ostream& a, const pii& b) {
    cout << "{" << b.first << ", " << b.second << "}";
    return a;
}

template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 &y) {if (x > y) x = y;}
template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 &y) {if (x < y) x = y;}

#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
    const int INF = 500;
    // const int mod = 2600000069;
    // const int p = 10;
    // const ld PI = 3.1415926535;
#else
    #define dbg(x)
    const int INF = 1e18;
    // const int mod = 2600000069;
    // const int p = 179;
    // const ld PI = 3.1415926535;
#endif

// #pragma GCC optimize("Ofast,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,sse3,sse4")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC optimize("fast-math")
// #pragma GCC target("avx2")
// #pragma GCC optimize("section-anchors")
// #pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
// #pragma GCC optimize("vpt")
// #pragma GCC optimize("rename-registers")
// #pragma GCC optimize("move-loop-invariants")
// #pragma GCC optimize("unswitch-loops")
// #pragma GCC optimize("function-sections")
// #pragma GCC optimize("data-sections")

mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());

const int MAXN = 1e6 + 10;

int dp[MAXN][2];
int a[MAXN];

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    for (int i = 0; i < MAXN; i++) {
        dp[i][0] = dp[i][1] = INF;
    }
    string s;
    cin >> s;
    int n = s.size();
    for (int i = 0; i < n; i++) {
        a[i] = s[i] - '0';
    }
    dp[0][0] = a[0];
    dp[0][1] = 2 + 9 - a[0];
    for (int i = 1; i < n; i++) {
        dp[i][0] = min(dp[i - 1][0], dp[i - 1][1]) + a[i];
        dp[i][1] = min(dp[i - 1][0] + 2, dp[i - 1][1]) + 9 - a[i];
    }
    cout << min(dp[n - 1][0], dp[n - 1][1]);
}
/*

*/

#include <bits/stdc++.h>

using namespace std;

#define Fast  ios::sync_with_stdio(false); cin.tie(0)
#define pb push_back
#define pf push_front
#define pp pop
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define S second
#define F first
typedef long long ll;
const ll mod = 1e9 + 7;
const ll N = 1e6 + 5;
ll inf = 1e18;

ll a[N];
ll sm[N];

int main(){

    Fast;

    ll n;
    cin >> n;

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

    sm[n-1] = a[n-1];

    for(int i = n-2; i >= 0 ; i --){
        sm[i] = a[i] + sm[i+1];
        sm[i] %= mod;
    }

    ll ans = 0;

    for(int i = 0 ; i < n-1 ;i ++){
        ans += a[i] * sm[i+1];
        ans %= mod;
    }

    cout << ans ;

    return 0;
}


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

// Optimization

//#pragma GCC optimize("O3")
#define endl '\n'

// Shortcut

#define int long long
#define eb emplace_back
#define pb push_back
#define pob pop_back
#define mp make_pair
#define upb upper_bound
#define lwb lower_bound
#define fi first
#define se second
#define For(i, l, r) for (int i = l; i < r; i++)
#define ForE(i, l, r) for (int i = l; i <= r; i++)
#define Ford(i, r, l) for (int i = r; i > l; i--)
#define FordE(i, r, l) for (int i = r; i >= l; i--)
#define Fora(i, a) for (auto i : a)

// I/O & Debug

#define PrintV(a) Fora(iiii, a) cout << iiii << ' '; cout << endl;
#define PrintVl(a) Fora(iiii, a) cout << iiii << endl;
#define PrintA(a, l, r) for (int iiii = l; iiii <= r; iiii++) cout << a[iiii] << ' '; cout << endl;
#define PrintAl(a, l, r) for (int iiii = l; iiii <= r; iiii++) cout << a[iiii] << endl;
#define Ptest(x) return cout << x, 0;
#define gl(s) getline(cin, s);
#define setpre(x) fixed << setprecision(x)
/*
#define debug(args...){ string _sDEB = #args; replace(_sDEB.begin(), _sDEB.end(), ',', ' '); stringstream _ssDEB(_sDEB); istream_iterator<string> _itDEB(_ssDEB); DEB(_itDEB, args); }
void DEB(istream_iterator<string> it) {}
template<typename T, typename... Args>
void DEB(istream_iterator<string> it, T a, Args... args){
    cout << *it << " = " << a << endl;
    DEB(++it, args...);
}
*/

// Functions

//#define isvowel(a) (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define bend(a) a.begin(), a.end()
#define rbend(a) a.rbegin(), a.rend()
#define mset(a) memset(a, 0, sizeof(a))
#define mset1(a) memset(a, 1, sizeof(a))
#define msetn1(a) memset(a, -1, sizeof(a))
#define msetinf(a) memset(a, 0x3f, sizeof(a))
#define gcd __gcd
#define __builtin_popcount __builtin_popcountll
//mt19937 rando(chrono::steady_clock::now().time_since_epoch().count());
//int randt(int l, int r){ return (rando() % (r - l + 1) + l); }

// Data Structure

#define pque priority_queue
#define mts multiset
#define y0 _y0_
#define y1 _y1_
#define div divi
typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <ld> vld;
typedef vector <string> vs;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <vi > vvi;
typedef vector <vll > vvll;
typedef vector <pii > vpii;
typedef vector <pll > vpll;

const int N = 1e5 + 5;
int mod = 1e9 + 7, mod1 = 998244353, mod2 = 1e9 + 9, inf = 1e9 + 7;
ll infll = 1e18 + 7;

string s;
int a[26];

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> s;
    if (s.length() == 2 && s[0] == s[1]){
        cout << 1<< ' '<< 2;
        return 0;
    }
    For(i, 2, s.length()){
        mset(a);
        a[s[i - 2] - 'a']++;
        a[s[i - 1] - 'a']++;
        a[s[i] - 'a']++;
        For(j, 0, 26){
            if (a[j] == 2){
                cout << i - 1 << ' ' << i + 1 << endl;
                return 0;
            }
        }
    }
    cout << -1 << ' ' << -1 << endl;
}

/*
==================================+
INPUT:                            |
------------------------------    |

------------------------------    |
==================================+
OUTPUT:                           |
------------------------------    |

------------------------------    |
==================================+
*/

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


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

using namespace std;
using ll = long long;

int main() {
	string n;
	cin >> n;
	string ans = "No";
	rep(i, 3) if (n[i] == '7') ans = "Yes";
	cout << ans << endl;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(void){
  int n; cin>>n;
  if(n%10==7||n/10%10==7||n/100%10==7) cout<<"Yes"; else cout<<"No";
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int         long long
#define endl        "\n"
#define pii         pair<int, int>
#define dint        long double

// tourist

bool cmp(pii a, pii b) {
    return (a.first + a.second < b.first + b.second);
}

const int inf = 1e18;

void solve() {
    int n; cin >> n;
    pii a[n+1];
    for(int i=1; i<=n; i++) {
        cin >> a[i].first >> a[i].second;
    }
     // First -> Strenght, Second -> Weight
    sort(a+1, a+n+1, cmp);
    int dp[n+1][n+1];
    for(int i=0; i<=n; i++) for(int j=0; j<=n; j++) dp[i][j] = inf;
    dp[0][0] = 0;
    for(int i=0; i<n; i++) {
        for(int j=0; j<=i; j++) {
            int wt = dp[i][j];
            if(wt == inf) continue;
            dp[i+1][j] = min(dp[i+1][j], wt);
            if(wt <= a[i+1].first) {
                dp[i+1][j+1] = min(dp[i+1][j+1], wt + a[i+1].second);
            }
        }
    }
    int ans = 0;
    for(int i=0; i<=n; i++) {
        if(dp[n][i] != inf) {
            ans = i;
        }
    }
    cout << ans << endl;
}

signed main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(12);

    int T = 1;
    //cin >> T;
    for(int i=1; i<=T; i++) {
        solve();
    }
    return 0;

}

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

void recursive_comb(int *indexes, int s, int rest, function<void(int *)> f) {
  if (rest == 0) {
    f(indexes);
  } else {
    if (s < 0) return;
    recursive_comb(indexes, s - 1, rest, f);
    indexes[rest - 1] = s;
    recursive_comb(indexes, s - 1, rest - 1, f);
  }
}

void foreach_comb(int n, int k, function<void(int *)> f) {
  int indexes[k];
  recursive_comb(indexes, n - 1, k, f);
}

int calc(string c) {
  int ret = 0;
  char lastOp = '+';
  for (int i = 0; i < c.size(); i++) {
    if (c[i] == '+') {
      lastOp = '+';
    } else if (c[i] == '-') {
      lastOp = '-';
    } else {
      int num = atoi(c.substr(i, 1).c_str());
      if (lastOp == '+') {
        ret += num;
      } else {
        ret -= num;
      }
    }
  }
  return ret;
}

int main() {
  // 入力
  vector<char> S(4);
  for (int i = 0; i < (int)S.size(); i++)
    cin >> S.at(i);

  int n = S.size() - 1;
  for (int k = 0; k <= n; k++) {
    foreach_comb(n, k, [S, n, k](int *indexes) {
      vector<char> op(n);
      for (int i = 0; i < n; i++) {
        op.at(i) = '+';
      }
      for (int i = 0; i < k; i++) {
        op.at(indexes[i]) = '-';
      }
      // 一つの文字列に連結
      string c = "";
      for (int i = 0; i < S.size(); i++) {
        c += S.at(i);
        if (i < op.size()) {
          c += op.at(i);
        }
      }
      // その文字列を計算する
      int ret = calc(c);
      if (ret == 7) {
        cout << c << "=" << ret << endl;
        exit(0);
      }
    });
  }
}


//%std
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read()
{
	int out = 0, fh = 1;
	char jp = getchar();
	while ((jp > '9' || jp < '0') && jp != '-')
		jp = getchar();
	if (jp == '-')
		fh = -1, jp = getchar();
	while (jp >= '0' && jp <= '9')
		out = out * 10 + jp - '0', jp = getchar();
	return out * fh;
}
void print(int x)
{
	if (x >= 10)
		print(x / 10);
	putchar('0' + x % 10);
}
void write(int x, char c)
{
	if (x < 0)
		putchar('-'), x = -x;
	print(x);
	putchar(c);
}
const int P = 998244353;
int add(int a, int b)
{
	return a + b >= P ? a + b - P : a + b;
}
void inc(int &a, int b)
{
	a = add(a, b);
}
int mul(int a, int b)
{
	return 1LL * a * b % P;
}
const int N = 300 + 10;
int n, m = 0, K, a[N], dp[N][N][N];
char buf[N];
int main()
{
	scanf("%s", buf + 1), n = strlen(buf + 1), K = min(n, read());
	int cnt = 0;
	for (int i = 1; i <= n; ++i)
		if (buf[i] == '0')
			a[++m] = cnt, cnt = 0;
		else
			++cnt;
	if (cnt)
		a[++m] = cnt;
	dp[m + 1][0][0] = 1;
	for (int i = m; i >= 1; --i)
	{
		for (int j = 0; j <= n; ++j)
			for (int k = n; k >= 0; --k)
				dp[i][j][k] = add(dp[i][j][k + 1], dp[i + 1][j][k]);
		for (int p = 1; p <= a[i]; ++p)
			for (int j = 0; j + p <= n; ++j)
				for (int k = 0; k + p <= n; ++k)
					inc(dp[i][j + p][k + p], dp[i + 1][j][k]);
	}
	int ans = 0;
	for (int j = 0; j <= K; ++j)
		inc(ans, dp[1][j][0]);
	write(ans, '\n');
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
const int N = 305, M = 998244353;
int dp[N][N][N];
vector<int> a;
int k;

int solve(int x, int cur, int rem) {
  if (cur > k || rem < 0) return 0;
  if (x == -1) return (rem == 0);

  int &ret = dp[x][cur][rem];
  if (~ret) return ret;
  ret = 0;

  for (int i = 0; i <= a[x]; ++i) {
    ret = (ret + solve(x - 1, cur + i, rem + i)) % M;
  }
  for (int i = 1; i <= rem; ++i) {
    ret = (ret + solve(x - 1, cur, rem - i)) % M;
  }
  return ret;
}

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

  string s;
  cin >> s >> k;

  memset(dp, -1, sizeof dp);
  a.push_back(0);
  for (auto i : s) {
    if (i == '0') a.push_back(0);
    else a.back()++;
  }

  cout << solve((int)a.size() - 1, 0, 0) << '\n';
}


#include <vector>
#include <iostream>

using namespace std;

int main() {
    int n;
    cin >> n;
    int m = 1e9;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        m = min(__builtin_ctz(a), m);
    }
    cout << m << endl;
}

#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N, A;
    cin >> N;
    int times = 0;
    int answer = 30;

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

        while (A % 2 == 0) {
            times +=1;
            A /=2;
        }

        if (times <= answer) answer = times;

        times = 0;
    }

    cout << answer << endl;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
	int n=2;
	vector<int> p[2];
	int ans[2];
	for(int i=0;i<n;++i){
		for(int j=0,point;j<10;++j){
			cin>>point;
			p[i].push_back(point);
		}
		sort(p[i].begin(),p[i].end(),greater<int>());
		ans[i]=p[i][0]+p[i][1]+p[i][2];
	}
	for(int i=0;i<n;++i)cout<<ans[i]<<((i==n-1)?"\n":" ");
	return 0;
}

#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <cstdio>

using namespace std;

int main(){
	int a[12];
	while(scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d"
				,&a[0],&a[1],&a[2],&a[3],&a[4],&a[5],&a[6],&a[7],&a[8],&a[9],&a[10],&a[11]) != EOF){

		int ans = 0;
		double t = 0, d = 0;
		int sum = 0;
		for(int i = 0;i < 10;i++){
			sum += a[i];
		}
		t = (double)sum / (a[10]+a[11]);
		d = (double)a[10] * t;
		sum = 0;
		for(int i = 0;i < 10;i++){
			sum += a[i];
			if(sum >= d){
				ans = i + 1;
				break;
			}
		}
		cout << ans << endl;
	}

	return 0;
}


#include <iostream>

 using namespace std;
  int main() {
       string s;
       while(cin>>s){
       int l=s.length();
       for(int i=0;i<l;i++){
       if(i==0) cout<<'2';
       else if(i==1) cout<<'0';
       else if(i==2) cout<<'1';
       else if(i==3) cout<<'8';
       else cout<<s[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;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
    string s;
    cin >> s;
    string t = s.substr(4);
    printf("2018%s\n", t.c_str());
}


#include<bits/stdc++.h>
using namespace std;
int main(){
  int P,Q,R,a,b,c,d;
  cin>>P>>Q>>R;
  a=P+Q;
  b=Q+R;
  c=R+P;
  d=min({a,b,c});
  cout<<d<<endl;
}

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

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

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

    vector<ll> v;
    for(int i = 0; i < n; i++){
        auto itr = lower_bound(v.begin(), v.end(), a[i]);
        if(i == 0){
            v.push_back(a[i]);
        }else{
            int p = distance(v.begin(), itr);
            if(p == 0){
                v.insert(v.begin(), a[i]);
            }else{
                p--;
                v[p] = a[i];
            }
        }
    }

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


//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

#define INF 100000000000000
#define MAX_V 101

int V;
LL d[MAX_V][MAX_V];

void wf(){
	REP(k,V)REP(i,V)REP(j,V){
		d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
	}
}

int main(){
	int E;
	cin>>V>>E;
	REP(i,V)REP(j,V)d[i][j]=(i==j)?0:INF;
	REP(i,E){
		int a,b,c;
		cin>>a>>b>>c;
		d[a][b]=c;
	}
	wf();
	REP(i,V)if(d[i][i]<0){
		cout<<"NEGATIVE CYCLE"<<endl;
		return 0;
	}
	REP(i,V){
		REP(j,V){
			if(d[i][j]>2*10e9)cout<<"INF";
			else cout<<d[i][j];
			if(j!=V-1)cout<<" ";
		}
		cout<<endl;
	}
	return 0;
}

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <utility>
#include <vector>

using namespace std;

typedef long long Long;
#define whole(xs) xs.begin(), xs.end()
#define uniq(xs) (xs.erase(unique(xs.begin(), xs.end()), xs.end()))

template<class T>
ostream& operator<<(ostream& os, const vector<T>& vs) {
    if (vs.empty()) return os << "[]";
    os << "[" << vs[0];
    for (int i = 1; i < vs.size(); i++) os << " " << vs[i];
    return os << "]";
}

const int IINF = 1<<28;
const Long LINF = 1LL<<56;
#define INF IINF

int V, E;

struct Edge {
    int s, t, w;
    Edge(int s, int t, int w) : s(s), t(t), w(w) {}
    bool operator<(const Edge& e) const {
        return w < e.w;
    }
};

vector<Edge> G;

void Input() {
    cin >> V >> E;
    for (int i = 0; i < E; i++) {
        int s, t, w; cin >> s >> t >> w;
        G.push_back(Edge(s, t, w));
    }
}

struct UnionFind {
    int N;
    vector<int> P;
    UnionFind(int N) : N(N) {
        P.clear(); P.resize(N, -1);
    }
    int query(int x) {
        if (P[x] == -1) return x;
        return P[x] = query(P[x]);
    }
    void merge(int x, int y) {
        x = query(x); y = query(y);
        if (x == y) return;
        P[y] = x;
    }
};

void Solve() {
    sort(whole(G));
    UnionFind uf(V);
    int Ans = 0;
    for (int i = 0; i < E; i++) {
        Edge& e = G[i];
        if (uf.query(e.s) == uf.query(e.t)) continue;
        Ans += e.w;
        uf.merge(e.s, e.t);
    }
    cout << Ans << endl;
}

int main() {
    Input(); Solve();
    return 0;
}


#include <stdio.h>

int main() {
  int rows, columns, n, tempR = 1, tempC = 1;
  scanf("%d %d %d", &rows, &columns, &n);

  int i = 1, j = 1;
  while(tempR < n && i <= rows) {
    tempR = i * columns;
    i++;
  }
  while(tempC < n && j <= columns) {
    tempC = j * rows;
    j++;
  }

  if(i == 1 && j == 1) printf ("1");
  else if(i < j) printf("%d", i - 1);
  else printf("%d", j - 1);
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define maxn 1000010
template <typename T>inline T read()
{
    register T sum=0;
    register char cc=getchar();
    int sym=1;
    while(cc!='-'&&(cc>'9'||cc<'0'))cc=getchar();
    if(cc=='-')sym=-1,cc=getchar();
    sum=sum*10+cc-'0';
    cc=getchar();
    while(cc>='0'&&cc<='9')sum=sum*10+cc-'0',cc=getchar();
    return sym*sum;
}
template <typename T>inline T read(T &a)
{
    a=read<T>();
    return a;
}
template <typename T,typename... Others> inline void read(T& a, Others&... b)
{
    a=read(a);
	read(b...);
}
int n,up,down,ans;
char s[maxn],t[maxn];
queue<int>Q;
int main()
{
	read(n);
	scanf("%s %s",s+1,t+1);
	if(strcmp(s+1,t+1)==0)
	{
		puts("0");
		return 0;
	}
	up=n,down=n;
	while(down)
	{
		while(down>1&&t[down-1]==t[down])
			down-=1;
		while(up&&(up>down||s[up]!=t[down]))
			up-=1;
		if(!up)
		{
			puts("-1");
			return 0;
		}
		while(!Q.empty()&&Q.front()-(int)Q.size()>=down)
			Q.pop();
		if(up!=down)
			Q.push(up);
		ans=max(ans,(int)Q.size()+1);
		down-=1;
	}
	printf("%d\n",ans);
    return 0;
}


#include <iostream>
using namespace std;

int getResult(int N, int H, int W){
  int hPattern = N - H + 1;
  int wPattern = N - W + 1;
  if(hPattern <= 0 || wPattern <= 0) return 0;
  return hPattern * wPattern;
}

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

  int result = getResult(N, H, W);
  cout << result;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) (V).begin(),(V).end()
#define MOD 1000000007
#define mod 998244353

int rw[100010];
vector<int> W[100010];

int main(){
	for (int i = 0;i < 100010;i++)rw[i] = -1;
	ll N, L;
	cin >> N;
	vector<ll> X(N);
	for (int i = 0;i < N;i++)
		cin >> X[i];
	cin >> L;
	for (int j = 0;j < N;j++) {
		if (rw[j] >= 0)continue;
		for (int i = j;i < N;) {
			W[j].push_back(i);
			if (rw[i] >= 0)break;
			rw[i] = j;
			auto it = upper_bound(all(X), X[i] + L);
			it--;
			i = it - X.begin();
		}
	}

	//for (int i = 0;i < N;i++)cout << rw[i] << " ";

	ll Q, a, b, c, d, ans = 0;
	cin >> Q;
	for (int i = 0;i < Q;i++) {
		ans = 0;
		cin >> a >> b;
		if (a > b)swap(a, b);
		a--;b--;
		c = rw[a];
		while (1) {
			auto it = W[c].end();
			it--;
			d = *it;
			if (d >= b)break;
			ans += it - find(all(W[c]), a);
			//cout << ans << endl;
			a = d;
			c = rw[a];
		}
		auto it1 = find(all(W[c]), a);
		auto it2 = lower_bound(all(W[c]), b);
		ans += it2 - it1;
		cout << ans << endl;
	}
}

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;

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

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
	return (ull)rng() % B;
}

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}

const int N = 100100;
const int LOG = 17;
int n, L, q;
int Q[N][2];
int ANS[N];
int a[N];
int b[LOG][N];

void solve() {
	int p = 0;
	for (int i = 0; i < n; i++) {
		while(p + 1 < n && a[p + 1] - a[i] <= L) p++;
		b[0][i] = p;
	}
	for (int k = 0; k < LOG - 1; k++)
		for (int i = 0; i < n; i++)
			b[k + 1][i] = b[k][b[k][i]];
	for (int i = 0; i < q; i++) {
		int v = Q[i][0], u = Q[i][1];
		if (v > u) continue;
		int ans = 0;
		for (int k = LOG - 1; k >= 0; k--) {
			if (b[k][v] < u) {
				v = b[k][v];
				ans += 1 << k;
			}
		}
		ANS[i] = ans + 1;
	}
}

int main()
{
	startTime = clock();
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	scanf("%d%d", &L, &q);
	for (int i = 0; i < q; i++) {
		scanf("%d%d", &Q[i][0], &Q[i][1]);
		Q[i][0]--;
		Q[i][1]--;
	}
	solve();
	for (int i = 0; i < q; i++) {
		Q[i][0] = n - 1 - Q[i][0];
		Q[i][1] = n - 1 - Q[i][1];
	}
	reverse(a, a + n);
	for (int i = 0; i < n; i++)
		a[i] *= -1;
	solve();
	for (int i = 0; i < q; i++)
		printf("%d\n", ANS[i]);

	return 0;
}


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

int fact[2000005];
int mod = 998244353;
long long qexp(long long b, long long p){
    long long res = 1;
    while(p){
        if(p&1) res = (res * b) % mod;
        b = (b * b) % mod;
        p >>= 1;
    }
    return res;
}
int inv(long long b){ return qexp(b, mod-2); }
int choose(int N, int C){
	if(N < C) return 0;
	int res = fact[N];
	res *= inv(fact[C]);
	res %= mod;
	res *= inv(fact[N-C]);
	res %= mod;
	return res;
}
int split(int total, int N){ ///split total objects to N groups
	return choose(N + total - 1, N - 1);
}

int ans = 0;
void fix(int &x){
	x %= mod;
	if(x < 0) x += mod;
}
signed main(){
	ios_base::sync_with_stdio(false); cin.tie(0);

	fact[0] = 1;
	for(int i = 1;i <= 2000000;i++) fact[i] = (fact[i-1] * i) % mod;

	int N, M; cin >> N >> M;

	for(int ones = 0;ones <= M;ones++){
		int zeros = N - ones;

		int leftover = 3*M - ones;
		if(leftover & 1) continue;

		leftover /= 2; ///The number of 2s to assign elsewhere

		int ways01 = choose(N, ones); ///ways to arrange the 0s and 1s

		int total2 = split(leftover, N); ///total ways to assign
		int oneTooBig = ones * split(leftover - M, N);
		int zeroTooBig = zeros * split(leftover - M - 1, N);

		total2 -= oneTooBig;
		total2 -= zeroTooBig;

		fix(total2);
		ans += total2 * ways01;
		fix(ans);
	}

	cout << ans;
}

//c++ -std=gnu++14 a.cpp
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <climits>
#include <fstream>
#include <random>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define revrep(i, n) for(int i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);
#define sz(x) ((int)(x).size())

//const ll INFL = LLONG_MAX;//10^18 = 2^60
const ll INFL = 1LL<<60;
//const int INF = INT_MAX;
const int INF = 1 << 30;//10^9
//const int MOD = 1000000007;
const int MOD = 998244353;
//int MOD = 1000000007;
double EPS = 1e-10;

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

void pres(double A){printf("%.12lf\n", A);}
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
ll cnt_bit(ll x){return __builtin_popcountll(x);}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x; k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

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

ll lcm(ll x, ll y){
  ll res = x / gcd(x, y);
  res *= y;
  return res;
};

//コンビネーション
const int MAXcomb = 3000010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}

const int MAXkai = 200010;
ll kai_memo[MAXkai];
ll kai(ll N){
  if(kai_memo[N] != 0) return kai_memo[N];
  if(N <= 1) return 1;
  return kai_memo[N] = N * kai(N-1) % MOD;
}

ll disit(ll s, ll base = 10){
  ll res = 0;
  while(s){
    res++;
    s /= base;
  }
  return res;
}

//約数の列挙O(√n)
vector<int> divisor(int n){
    vector<int> res(0);
    for(int i = 1; i * i <= n; i++){
        if(n % i == 0){
            res.push_back(i);
            if(i != n/i) res.push_back(n/i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}

ll N, M;
void solve(){
  COMinit();
  cin >> N >> M;
  ll ans = 0;
  for(ll x = 0; x <= M; x++){//奇数がx個
    if(x % 2 != M % 2) continue;
    ll all = 3 * M - x;
    all /= 2;
    ans += comb(N, x) * comb(all+N-1, all) % MOD;
    ans %= MOD;
  }

  for(ll x = 0; x <= M; x++){//奇数がx個
    if(x % 2 != M % 2) continue;
    ll all = M - x;
    all /= 2;
    ans += MOD - N * comb(N, x) % MOD * comb(all+N-1, all) % MOD;
    ans %= MOD;
  }

  for(ll x = 0; x <= M; x++){//奇数がx個
    if(x % 2 != M % 2) continue;
    ll all = M - x;
    all /= 2;
    ans += N * comb(N-1, x) % MOD * comb(all+N-2, all) % MOD;
    ans %= MOD;
  }
  cout << ans << endl;
}

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


#include <bits/stdc++.h>
#include <atcoder/all>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using namespace atcoder;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

ll a[500010];
int main(){
    int n, q;
    cin >> n >> q;
    fenwick_tree<ll> fw(n);

    rep(i, n) {
        int a; cin >> a;
        fw.add(i, a);
    }

    rep(i, q){
        int b; cin >> b;
        if (b == 0) {
            int p;
            ll x;
            cin >> p >> x;
            fw.add(p, x);
        }
        else {
            int l, r; cin >> l >> r;
            cout << fw.sum(l, r) << endl;
        }
    }

    return 0;
}

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

// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
#define PI (2*acos(0.0))
#define EPS (1e-9)
#define MOD (int)(1e9+7)
#define INF numeric_limits<int>::infinity()
#pragma endregion

int main()
{
    vi v1, v2;
    rep(i,10) {
        int a;
        cin >> a;
        v1.push_back(a);
    }
    rep(i,10) {
        int a;
        cin >> a;
        v2.push_back(a);
    }

    sort(v1);
    sort(v2);
    printf("%d %d\n", v1[9]+v1[8]+v1[7], v2[9]+v2[8]+v2[7]);
    return 0;
}


#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define LOOP(i) while(i--)
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int N=in();
	out(180*(N-2));
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const int INF = 2e9;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
    ll n;
    cin >> n;
    print(180 * (n - 2));
}


#include <cstdio>
#include <map>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef pair<int,P> Pa;

int a, b, c, n;
vector<Pa> test;
int A[100], B[100], C[100];

int main(){
	while(scanf("%d%d%d", &a, &b, &c)){
		if(a == 0 && b == 0 && c == 0) break;
		vector<Pa> test;
		for(int i = 0; i < 100; i++){
			A[i] = 2; B[i] = 2; C[i] = 2;
		}
		scanf("%d", &n);
		for(int i = 0; i < n; i++){
			int p, q, r, s;
			scanf("%d%d%d%d", &p, &q, &r, &s);
			q -= a; r -= (a+b);
			p--; q--; r--;
			if(s){
				A[p] = 1;
				B[q] = 1;
				C[r] = 1;
			} else{
				test.push_back(Pa(p,P(q,r)));
			}
		}
		for(int i = 0; i < test.size(); i++){
			if(A[test[i].first]==1&&B[test[i].second.first]==1) C[test[i].second.second] = 0;
			else if(A[test[i].first]==1&&C[test[i].second.second]==1) B[test[i].second.first] = 0;
			else if(B[test[i].second.first]==1&&C[test[i].second.second]==1) A[test[i].first] = 0;
		}
		for(int i = 0; i < a; i++) printf("%d\n", A[i]);
		for(int i = 0; i < b; i++) printf("%d\n", B[i]);
		for(int i = 0; i < c; i++) printf("%d\n", C[i]);
	}
}

#include <iostream>
using namespace std;

int main(){
    while(1){
        int a, b, c, n, list[1001][4], parts[301], judge, defect;

        cin >> a >> b >> c >> n;
        if(a == 0 && b == 0 && c == 0){
            break;
        }

        for(int i = 1; i <= a + b + c; i++){
            parts[i] = 2;
        }
        for(int i = 0; i < n; i++){
            for(int j = 0; j < 4; j++){
                cin >> list[i][j];
            }
            if(list[i][3] == 1){
                for(int k = 0; k < 3; k++){
                    parts[list[i][k]] = 1;
                }
            }
        }

        for(int i = 0; i < n; i++){
            if(!list[i][3]){
                judge = 0;
                for(int j = 0; j < 3; j++){
                    if(parts[list[i][j]] == 1){
                        judge++;
                    } else{
                        defect = j;
                    }
                }
                if(judge == 2){
                    parts[list[i][defect]] = 0;
                }
            }
        }

        for(int i = 1; i <= a + b + c; i++){
            cout << parts[i] << endl;
        }
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m, d; cin >> n >> m >> d;
  cout << fixed << setprecision(10) << (ld)(d==0 ? 1 : 2)*(n-d)*(m-1)/n/n << endk;
  return 0;
}

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <stack>
#include <complex>
#include <functional>
#include <tuple>

using namespace std;

#define Rep(i,a,b) for(ll i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")

using ll = long long;

constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 1e9 + 7;
// 0~3までは右下左上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, -1 };
constexpr int dy[] = { 0, 1, 0, -1, 1, 1 };

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

    // 標準出力
    void Write(long long x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Write(const T& x, const char* end = "\n") { std::cout << x << end; }
    template <typename T, typename U> void Write(const T& x, const U& y, const char* end = "\n") { std::cout << x << " " << y << end; }
    template <typename T, typename U, typename V> void Write(const T& x, const U& y, const V& z, const char* end = "\n") { std::cout << x << " " << y << " " << z << end; }
    //template <typename... Args> void Write(Args const&... args) { bool a = true; for (auto const& x : { args... }) { if (a) a = false; else std::cout << " "; std::cout << x; } std::cout << "\n"; }
    template <typename T> void Write(const std::vector<T>& x, const char* sep = " ", const char* end = "\n") { for (std::size_t i = 0, sz = x.size(); i < sz; ++i) { std::cout << x[i] << (i == sz - 1 ? end : sep); } }
    template <typename T> void Write(const std::vector<std::vector<T>>& x, const char* sep = " ", const char* end = "\n") { for (auto v : x) Write(v, sep, end); }

    // 標準入力
    struct Read {
        std::size_t szi, szj;
        Read(std::size_t _szi = 1, std::size_t _szj = 1) : szi(_szi), szj(_szj) {}
        template <typename T> operator T () const { T a; std::cin >> a; return a; }
        template <typename T> operator std::vector<T>() const { std::vector<T> a(szi); for (std::size_t i = 0; i < szi; ++i) std::cin >> a[i]; return a; }
        template <typename T> operator std::vector<std::vector<T>>() const {
            std::vector<std::vector<T>> a(szi, std::vector<T>(szj));
            for (std::size_t i = 0; i < szi; ++i) for (std::size_t j = 0; j < szj; ++j) cin >> a[i][j]; return a;
        }
        template <typename T, typename U> operator std::vector<std::pair<T, U>>() const {
            std::vector<std::pair<T, U>> a(szi);
            for (std::size_t i = 0; i < szi; ++i) std::cin >> a[i].first >> a[i].second; return a;
        }
    };
    struct Reads {
        template <typename T> Reads(T& a) { std::cin >> a; }
        template <typename T, typename U> Reads(T& a, U& b) { std::cin >> a >> b; }
        template <typename T, typename U, typename V> Reads(T& a, U& b, V& c) { std::cin >> a >> b >> c; }
        template <typename T, typename U, typename V, typename W> Reads(T& a, U& b, V& c, W& d) { std::cin >> a >> b >> c >> d; }
    };

    Read read;
}

int main() {

    int n, m, d; Reads(n, m, d);

    double ans;

    // 隣同士の差がdであるものの個数の平均

    ans = (double)((n - d) * 2) / (n * (double)n) * (m - 1);
    if (d == 0) ans /= 2.0;

    cout << fixed << setprecision(8) << ans << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {

  char arr[10];
  scanf("%s", arr);
  int rCount = 0, ans = 0;
  for (int i = 0; i < 3; ++i) {
    if (arr[i] == 'R') {
      rCount++;
    } else {
      ans = max(ans, rCount);
      rCount = 0;
    }
  }
  ans = max(ans, rCount);
  printf("%d\n", ans);

  return 0;
}

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

int main(){
    int N;
    cin >> N;
    cout << N / 3 << endl;
}


#include <bits/stdc++.h>

const double pi = 3.141592653589793238462643383279;
using namespace std;
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const double EPS = 1E-10;

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

//ここから編集

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

  int N, M;
  cin >> N >> M;
  vector<vector<int>> g(N);
  REP(i,M){
    int a, b; cin >> a >> b;
    a--; b--;
    g[a].push_back(b);
  }

  int mi = N+1;
  vector<int> res;
  for(int s = 0; s<N; s++){
    vector<int> dist(N, -1);
    vector<int> prev(N, -1);
    queue<int> q;
    q.push(s);
    dist[s] = 0;
    while(q.size()){
      auto v = q.front();
      q.pop();
      for(auto u: g[v]){
        if(dist[u] == -1){
          dist[u] = dist[v] + 1;
          prev[u] = v;
          q.push(u);
        }
      }
    }

    for(int t = 0; t<N; t++){
      if(t == s || dist[t] == -1) continue;
      for(auto v: g[t]){
        if(v == s){
          vector<int> tmp({s});
          int cur = t;
          while(cur != s) tmp.push_back(cur), cur = prev[cur];
          if(mi > tmp.size()){
            mi = tmp.size();
            res = tmp;
          }
        }
      }
    }
  }

  if(mi == N+1){
    cout << -1 << endl;
  }else{
    cout << res.size() << endl;
    for(auto e: res) cout << e+1 << endl;
  }
  return 0;
}

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

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

const int N = 1001, M = 2001;
int n, m, a, b;
vector<int> edge[N];
vector<int> path;
unordered_map<int, int> mp;

bool check(int from, int to) {
  int s = mp[from];
  int e = mp[to];
  // index [s, e] in path
  for (int i = s; i <= e; ++i) {
    int cur = path[i];
    int next = (i == e ? path[s] : path[i + 1]);
    for (int v : edge[cur]) {
      if (v != next) {
        if (mp.count(v) && mp[v] >= s) {
          return false;
        }
      }
    }
  }
  return true;
}

void dfs(int u) {
  for (int v : edge[u]) {
    if (mp.count(v)) {
      // find cycle
      if (check(v, u)) {
        int s = mp[v];
        int e = mp[u];
        cout << e - s + 1 << endl;
        for (int i = s; i <= e; ++i) {
          cout << path[i] << endl;
        }
        exit(0);
      }
    } else {
      path.push_back(v);
      mp[v] = path.size() - 1;
      dfs(v);
      mp.erase(v);
      path.pop_back();
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    cin >> a >> b;
    edge[a].push_back(b);
  }
  for (int i = 1; i <= n; ++i) {
    path.push_back(i);
    mp[i] = 0;
    dfs(i);
    mp.erase(i);
    path.pop_back();
  }
  cout << -1 << endl;
  return 0;
}


#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define vint(a,n) vint a(n); rep(i, n) cin >> a[i];
#define vll(a,n) vll a(n); rep(i, n) cin >> a[i];
#define ALL(n) begin(n),end(n)
#define RALL(n) rbegin(n),rend(n)
#define MOD (1000000007)
#define INF (2e9)
#define INFL (2e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
using vint=vector<int>;
using vll=vector<ll>;
using vbool=vector<bool>;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main()
{
    int n; cin >> n;
    vll(a, n);

    ll neg=0, sum=0, min=INFL;
    rep(i, n){
        if(a[i]<0) neg++;
        sum += abs(a[i]);
        chmin(min, abs(a[i]));
    }

    if(neg%2==0) pr(sum);
    else pr(sum - 2*min);
    return 0;}

//Name: Baseball Simulation
//Level: 1
//Category: やるだけ
//Note:

/**
 * 仕様のとおりに実装する。
 *
 * オーダーは O(E)。
 * ただし、Eはイベントの個数。
 */
#include <iostream>
#include <string>

using namespace std;

bool solve() {
    int out = 0;
    int b1 = 0, b2 = 0, b3 = 0;
    int score = 0;
    while(out < 3) {
        string event;
        cin >> event;
        if(event == "HIT") {
            if(b3) ++score;
            b3 = b2; b2 = b1; b1 = 1;
        } else if(event == "HOMERUN") {
            score += b1+b2+b3+1;
            b1 = b2 = b3 = 0;
        } else if(event == "OUT") {
            ++out;
        }
    }
    cout << score << endl;
    return true;
}

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

    int T;
    cin >> T;
    while(T--) solve();
    return 0;
}


#define _GLIBCXX_DEBUG //vectorの範囲外アクセスなどのエラーメッセージが分かりやすくなるらしい

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
//#include <algorithm>

// using namespace std;
#include<numeric>

#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<cstdio>
#include<cstdlib>
#include<cassert>
#include<cstring>
#include<cmath>
#include<complex>

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

#define FOR(i,c) for(typeof((c).begin())i=(c).begin();i!=(c).end();++i)

#define EXIST(e,s)((s).find(e)!=(s).end())
#define RESET(a) memset((a),0,sizeof(a))
#define SET(a) memset((a),-1,sizeof(a))

#define ll long long

using namespace std;

int main(void){
  int n;
  int p;

  int temoto[50];
  int wan;
  bool flag;

  while(cin >> n >> p, n || p){
    flag = false;
    memset(temoto, 0, sizeof(temoto[0])*50);
    wan = p;
    while(1){
      for(int i=0; i<n; i++){
	if(wan > 0){
	  wan--;
	  temoto[i]++;
	  if(temoto[i] == p){
	    cout << i << endl;
	    flag = true;
	    break;
	  }
	}else{
	  wan += temoto[i];
	  temoto[i] = 0;
	}
      }
      if(flag){
	break;
      }
    }
  }

    return 0;
}

#include <iostream>
#include<iomanip>

using namespace std;

int main() {

    int n;
    while (cin >> n) {

    if(n == 0)
    break;

    int A[51][51] = {};

    for(int i=0;i<n;i++) {
    for(int j=0;j<n;j++) {

    	cin >> A[i][j];

    	A[i][n] += A[i][j];
    	A[n][j] += A[i][j];
	}
	A[n][n] += A[i][n];
}

	for(int i=0;i<=n;i++) {
    for(int j=0;j<n;j++) {

    	cout << setw(5)<< A[i][j];
    }
	cout << setw(5)<< A[i][n];
	cout << "\n";
}
}
    return 0;
}


#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <cstdint>
#include <istream>
#include <sstream>
#include <cctype>
#include <functional>
#include <iomanip>
#define rep(i,N) for(ll i=0;i<N;i++)
#define disp(a) cout << a << endl;
#define PI 3.1415926535897932384626433
//cout << fixed << setprecision(20) << ** << endl;
typedef long long ll;
using namespace std;

double deg2rad(double degree)
{
    return degree * PI / 180.0000000000;
}
int main()
{
	string s,ANS="Yes";
	cin>>s;
	if(s.size()%2!=0){
		cout<<"No"<<endl;
	}
	else{
		for(int i=0;i<s.size();i=i+2){
			if(s[i]=='h'&&s[i+1]=='i'){
				continue;
			}
			else{
				ANS="No";
			}
		}
		cout<<ANS<<endl;
	}

}

#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int i=(a),_ed=(b);i<=_ed;++i)
#define DREP(i,a,b) for(int i=(a),_ed=(b);i>=_ed;--i)
typedef long long ll;
inline int read(){
    register int x=0,f=1;register char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=0;ch=getchar();}
    while(isdigit(ch)){x=x*10+(ch^'0');ch=getchar();}
    return f?x:-x;
}

const char s[4][7][8]={{"aaba","ccba","abcc","abaa"},
		       {"aa.ab",".bbab","a.cca","a.a.a","bbabb"},
		       {"aaca..","bbca..","ac..aa","ac..bb","..aaca","..bbca"},
		       {"aaca...","bbca...","ac.bb..","ac...aa","..a.abb","..a.a.a","..ccbba"}};

int main(){
    //freopen("in.in","r",stdin);
    int n=read(),k=n%4+4;
    if(n<3)return puts("-1"),0;
    if(n==3)return puts("aab\nb.b\nbaa"),0;
    for(int _=1,j=0;_<=n-k;_+=4,++j){
	int m=j*4;
	REP(t,0,3){
	    REP(i,1,m)putchar('.');
	    REP(i,0,3)putchar(s[0][t][i]);
	    REP(i,m+5,n)putchar('.');
	    puts("");
	}
    }
    int m=k%4;
    REP(t,0,k-1){
	REP(i,1,n-k)putchar('.');
	REP(i,0,k-1)putchar(s[m][t][i]);
	puts("");
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

bool Solve(int n, const vector<int>& xs) {
  if (n == 1) {
    return false;
  }

  int even_count = 0;
  for (int x : xs) {
    if (x % 2 == 0) even_count++;
  }

  if (n % 2 == 0) {
    return even_count % 2 == 1;
  } else {
    if (even_count <= n - 2) {
      return even_count % 2 == 1;
    } else {
      vector<int> ys(n);
      for (int i = 0; i < n; i++) {
        if (xs[i] % 2 == 1) {
          if (xs[i] == 1) return false;
          ys[i] = xs[i] - 1;
        } else {
          ys[i] = xs[i];
        }
      }
      int d = ys[0];
      for (int i = 1; i < n; i++) {
        d = gcd(ys[i], d);
      }
      for (int i = 0; i < n; i++) {
        ys[i] /= d;
      }
      return !Solve(n, ys);
    }
  }
}

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

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

  bool ans = Solve(n, xs);
  if (ans) {
    cout << "First" << endl;
  } else {
    cout << "Second" << endl;
  }
}

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

constexpr ll mod = 1000000007;

int main() {
    int n;
    scanf("%d",&n);
    map<int,int> mp;
    for(int i = 2; i <= n; i++) {
        int m = i;
        for(int j = 2; j <= n; j++) {
            while(m % j == 0) {
                mp[j]++;
                m /= j;
            }
        }
    }
    ll ans = 1;
    for(auto c : mp) {
        ans *= c.second+1;
        ans %= mod;
    }
    printf("%ld\n",ans);
}


#include <bits/stdc++.h>
#define ll long long int
#define F(i,j,k,in) for(int i=j;i<k;i+=in)
#define DF(i,j,k,in) for(int i=j;i>=k;i-=in)
#define feach(it,l) for (auto it = l.begin(); it != l.end(); ++it)
#define fitr(it,it1,itr2) for(auto it=itr1;it!=itr2;++it)
#define fall(a) a.begin(),a.end()
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define eq equal_range
#define fs first
#define ss second
#define ins insert
#define mkp make_pair
#define PI 3.1415926535897932384626433832795
#define endl "\n"
using namespace std;
typedef vector<ll> vll;
typedef vector<int> vin;
typedef vector<char> vch;
typedef vector<string> vst;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll,ll>> vpll;
typedef set<ll> sll;
typedef set<int> sint;
typedef set<char> sch;
typedef set<string> sst;
typedef queue<ll> qll;
typedef priority_queue<ll> pqll;
typedef map<ll,ll> mll;
typedef pair<ll,ll> pll;
const ll MOD=1000000007;
ll pwr(ll b,ll p){ll res=1;while(p){if(p&1) {res*=b; p--;}else{b*=b; p>>=1;}}return res;}

int main()
{
  ios_base::sync_with_stdio(false) , cin.tie(NULL) , cout.tie(NULL);
  ll n;
  cin>>n;
  ll cnt=0;
  cnt+=n/11;
  cnt*=2;
  int r=n%11;
  if (r!=0 && r<=6) ++cnt;
  else if (r!=0) cnt+=2;
cout<<cnt;
return 0;
}

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

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

  int64_t a = x/11*2;

  if(x%11 == 0){
    cout << a << endl;
  }
  else if(x%11 <= 6){
    cout << a+1 << endl;
  }
  else{
    cout << a+2 << endl;
  }

}


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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
	ll x; cin >> x;
	ll n = x / 11;
	ll ans = 2 * n + ((x - 11 * n) + 5) / 6;
	cout << ans << endl;
	return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#define ll long long
using namespace std;
int main(){
    ll x;
    cin>>x;
    ll d=x/11;
    ll r=x%11;
    if(0==r){
        cout<<2*d<<endl;
    }else{
        if(r<7){
            cout<<2*d+1ll<<endl;
        }else{
            cout<<2*d+2ll<<endl;
        }
    }
    return 0;
}


/**
 * Sergey Kopeliovich (burunduk30@gmail.com)
 */

#include <bits/stdc++.h>

using namespace std;

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

const int MOD = 998244353;

typedef long long ll;

inline void add( int &a, int b ) { if ((a += b) >= MOD) a -= MOD; }
inline void sub( int &a, int b ) { if ((a -= b) < 0) a += MOD; }
inline int mul( int a, int b ) { return (ll)a * b % MOD; }

int Pow( int x, ll n ) {
	if (n == 1)	return x;
	int y = Pow(x, n / 2);
	return (n & 1) ? mul(mul(y, y), x) : mul(y, y);
}

int Inv( int a ) { return Pow(a, MOD - 2); }
int Div( int a, int b ) { return mul(a, Inv(b)); }

// int C( int n, int k ) {
// 	int res = 1;
// 	forn(i, k) {
// 		res = mul(res, n - i);
// 		res = mul(res, Inv(i + 1));
// 	}
// 	return res;
// }

const int N = 103;
int f[N][N];

int calc( int a, int b ) {
	if (a < 0 || b < 0) return 0;
	if (a > b) swap(a, b);
	if (!a && !b)
		return 0;
	int &res = f[a][b];
	if (!res) {
		res = mul(Div(a,  a + b), calc(a - 1, b));
		add(res, mul(Div(b, a + b), 1 + calc(a, b - 1)));
	}
	return res;
}

double f2[N][N];
double calc2( int a, int b ) {
	if (a < 0 || b < 0) return 0;
	if (a > b) swap(a, b);
	if (!a && !b)
		return 0;
	double &res = f2[a][b];
	if (res == 0) {
		res = 1. * a / (a + b) * calc2(a - 1, b) +
		  1. * b / (a + b) * (1 + calc2(a, b - 1));
	}
	return res;
}

double calc3( int last, int i, int balance, int n ) {
	double add = 0;
	if (balance == 0 && i < 2 * n)
		add += 0.5;
	// if (balance == 0)
	// 	add += (i - last) / 2, last = i;
	if (i == 2 * n)
		return add;
	if (i + balance < 2 * n) {
		double rest = 2 * n - i, good = (rest + balance) / 2.0;
		add += good / rest * calc3(last, i + 1, balance - 1, n);
		add += (rest - good) / rest * calc3(last, i + 1, balance + 1, n);
	} else {
		add += calc3(last, i + 1, balance - 1, n);
	}
	return add;
}

int main() {
	int n, m;
	cin >> n >> m;
	// assert(n == m);
	if (n < m)
		swap(n, m);
	int res = n, tmp = 0;

	vector<int> fact(2 * n + 1);
	fact[0] = 1;
	forn(i, 2 * n)
		fact[i + 1] = mul(fact[i], i + 1);
	auto C = [&]( int n, int k ) {
		return Div(fact[n], mul(fact[n - k], fact[k]));
	};
	int all = C(n + m, n);

	for (int i = 0; i < m; i++) {
		add(tmp, mul(C(n + m - 2 * (m - i), i), C(2 * (m - i), m - i)));
	}
	add(res, Div(tmp, all * 2 % MOD));
	printf("%d\n", res);
	// printf("%d\n", calc(n, n));
	// printf("%.7f\n", calc2(n, n));
	// printf("%.7f\n", calc3(0, 0, 0, n) + n);
}

#include<bits/stdc++.h>
#define fi first
#define se second
#define R register
#define mp make_pair
#define pb push_back
#define LL long long
#define Ldb long double
#define pii pair<int, int>
using namespace std;
const int N = 1e6 + 10;
const int mod = 998244353;

template <typename T> void read(T &x) {
	int f = 0;
	R char c = getchar();
	while (c < '0' || c > '9') f |= (c == '-'), c = getchar();
	for (x = 0; c >= '0' && c <= '9'; c = getchar())
		x = x * 10 - '0' + c;
	if (f) x = -x;
}

int Qpow(int x, int p) {
	int ans = 1;
	while (p) {
		if (p & 1) ans = 1LL * ans * x % mod;
		x = 1LL * x * x % mod;
		p >>= 1;
	}
	return ans;
}

int Inv(int x) {
	return Qpow(x, mod - 2);
}

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

int n, m;
int inv[N], fac[N], fav[N];

int C(int x, int y) {
	return 1LL * fac[x] * fav[y] % mod * fav[x - y] % mod;
}

int main() {
	read(n); read(m);
	if (n > m) swap(n, m);
	fac[0] = fav[0] = 1;
	inv[1] = fac[1] = fav[1] = 1;
	for (int i = 2; i <= n + m; ++i) {
		inv[i] = 1LL * -mod / i * inv[mod % i] % mod +mod;
		fac[i] = 1LL * fac[i - 1] * i % mod;
		fav[i] = 1LL * fav[i - 1] * inv[i] % mod;
	}
	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		int tmp = 1LL * C(i * 2 - 1, i) * C(n + m - i * 2, n - i) % mod;
		ans = (ans + tmp >= mod) ? (ans + tmp - mod) : (ans + tmp);
	}
	ans = (n - 1LL * ans * Inv(C(n + m ,n))) % mod;
	ans = n + m - ans;
	if (ans < 0) ans += mod;
	cout << ans << endl;
	return 0;
}


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

int main() {
  string s;
  cin >> s;
  int N = s.size();
  bool b = true;
  int l = 0, r = 0, eli = 0;
  for (int i = 0; i < N; i++) {
    if (!b && s[i] == 'S') {
      b = true;
      int p = min(l,r);
      eli += 2*p;
      l -= p; r = 0;
    }
    if (s[i] == 'S') l++;
    if (s[i] == 'T') {
      b = false;
      r++;
    }
  }
  eli += 2*min(l,r);
  cout << N - eli << endl;
}

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

int main(){
    string N;cin>>N;
    reverse(N.begin(),N.end());
    vector<vector<ll>> dp(1000010,vector<ll>(2/*桁上がりあるか*/,INF));
    dp[0][0]=0;

    N.push_back('0');
    for(ll i=0;i<N.size();i++){
        ll now=N[i]-'0';

        //前桁上がり判定ありの時
        ll nowb=now+1;
        if(dp[i][1]!=INF){
            //今equal
            chmin(dp[i+1][0],dp[i][1]+nowb);

            //今もbigger
            chmin(dp[i+1][1],dp[i][1]+(10-nowb));
        }

        //前桁上がり判定無し
        if(dp[i][0]!=INF){
            //今桁上がり判定無し
            chmin(dp[i+1][0],dp[i][0]+now);

            //今桁上がり判定あり
            chmin(dp[i+1][1],dp[i][0]+(10-now));
        }
    }

    cout<<min(dp[N.size()][0],dp[N.size()][1])<<endl;
    return 0;
}


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

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> box(n,10);
  int ans = 0;
  rep(i,m){
    int s;
    int c;
    cin >> s >>c;
    s--;
    if(s==0&&c==0&&n!=1) ans = -1;
    if(box[s]==c)continue;
    if(box[s]==10)box[s]=c;
    if(box[s]!=c)ans = -1;
  }
  if(n==1){
    if(ans==-1) cout << -1 << endl;
    else if(box[0]==10)cout << 0 << endl;
    else cout << box[0] << endl;
    return 0;
  }
  rep(i,n){
    if((i==0)&&box[i]==10)box[i]=1;
    if(box[i]==10)box[i]=0;
  }
  if(ans==-1)cout<<-1 <<endl;
  else {
    rep(i,n) cout << box[i];
    cout << endl;
  }
  return 0;
}

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

typedef long long ll;
const int MAXN=1e7+5;

int n,ans;
int deq[MAXN],l,r;
char s[MAXN],t[MAXN];

int main(){

    scanf("%d%s%s",&n,s+1,t+1);
    if(strcmp(s+1,t+1)==0) return puts("0"),0;
    l=1,r=0;
    for(int i=n,j=n;i>=1;i--){
        if(t[i]==t[i-1]) continue;
        j=min(i,j);
        while(j&&t[i]!=s[j]) j--;
        if(!j) return puts("-1"),0;
        while(l<=r){
            if(deq[l]-(r-l)>i) l++;
            else break;
        }
        deq[++r]=j;
        if(i!=j) ans=max(ans,r-l+1);
    }
    printf("%d",ans+1);

    fclose(stdin);
    fclose(stdout);
}


#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <climits>
#include <cmath>
#include <string>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep01(i, n) for(int i = 0; i < (n) + 1; i++)
#define rep10(i, n) for(int i = 1; i < (n); i++)
#define all(a) (a).begin(), (a).end()
typedef long long int ll;
using namespace std;

//ABC079C
int main()
{
    string s;
    cin >> s;

    int a[4];
    rep(i, 4) a[i] = s[i] - 48;

    char sig[3];
    rep(i, 1 << 3) {
        int sum = a[0];
        rep(bit, 3) {
            if (i & 1 << bit) {
                sum += a[bit + 1];
                sig[bit] = '+';
            }
            else {
                sum -= a[bit + 1];
                sig[bit] = '-';
            }
        }
        if (sum == 7) break;
    }

    cout << s[0] << sig[0] << s[1] << sig[1] << s[2] << sig[2] << s[3] << "=7" << endl;

    return 0;
}


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

int
main(void)
{
	char line[100];
	char res[100];

	auto chksep = [](char c) -> bool {
			return (c == ' ' || c == '.' || c == '\n');
		};

	while (fgets(line, sizeof line, stdin)) {
		int len = strlen(line);
		int state = 0;

		for (int s = 0; s < 26; s++) {

			for (int i = 0; i < len; i++) {
				if (chksep(line[i])) {
					res[i] = line[i];
				} else {
					int c = line[i] + s;
;					if (c > 'z') {
						res[i] = c - 'z' + 'a' - 1;
					} else {
						res[i] = c;
					}
				}

				switch (state) {
				case 0:
					if (res[i] == 't') {
						state = 1;
					}
					break;

				case 1:
					if (res[i] == 'h') {
						state = 2;
					} else {
						state = 0;
					}
					break;

				case 2:
					if (res[i] == 'e') {
						state = 5;
					} else if (res[i] == 'i') {
						state = 3;
					} else if (res[i] == 'a') {
						state = 4;
					} else {
						state = 0;
					}
					break;

				case 3:
					if (res[i] == 's') {
						state = 5;
					} else {
						state = 0;
					}
					break;

				case 4:
					if (res[i] == 't') {
						state = 5;
					} else {
						state = 0;
					}
					break;

				case 5:
					if (chksep(res[i])) {
						state = 99;
					} else {
						state = 0;
					}
					break;
				}
			}

			if (state == 99) {
				res[len] = 0;
				printf("%s", res);
				break;
			}
		}
	}

	return 0;
}

#include <cstdio>
#include <iostream>

using namespace std;

int main(){
	int days[12] = {31,29,31,30,31,30,31,31,30,31,30,31};
	char week2[7][10] = {"Thursday","Friday","Saturday","Sunday","Monday","Tuesday","Wednesday"};

	int month,day;
	int sum;

	cin >> month >> day;
	while((month != 0) && (day != 0)){
		sum = 0;
		for(int i=0 ;i < month - 1;i++){
			sum += days[i];
		}
		sum += day;

		switch(sum % 7){
			case 1:
				printf("%s\n",week2[0]);
				break;

			case 2:
				printf("%s\n",week2[1]);
				break;

			case 3:
				printf("%s\n",week2[2]);
				break;

			case 4:
				printf("%s\n",week2[3]);
				break;

			case 5:
				printf("%s\n",week2[4]);
				break;

			case 6:
				printf("%s\n",week2[5]);
				break;

			case 0:
				printf("%s\n",week2[6]);
				break;

		}

		cin >> month >> day;
	}
}


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

#define int long long
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back

#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#define REP(i,n) for (int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)

#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

int raise(int a,int n,int m = MOD){
  if(n == 0)return 1;
  if(n == 1)return a;
  int x = 1;
    x *= raise(a,n/2,m);
    x %= m;
    x *= x;
    x %= m;
    if(n%2)x*= a;
    x %= m;
    return x;
}

int floor1(int n,int k){
    if(n%k == 0 || n >= 0)return n/k;
    return (n/k)-1;
}

int ceil1(int n,int k){
    return floor1(n+k-1,k);
}

int freq[26];

void solve(){
  	int n;
  	string s;
  	cin >> s;n = s.size();
  	s = "$"+s;
  	int ans = 0;
  	int dd = 0;
  	RE(i,n){
  		freq[s[i]-'a']++;
  	}
  	REP(i,26){
  		REP(j,i){
  			ans += freq[i]*freq[j];
  		}
  	}
  	cout << ans+1;

}

signed main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  //freopen(".in","r",stdin);freopen(".out","w",stdout);
  int t = 1;
  //cin >> t;
  while(t--){
    solve();
  }
  return 0;
}

#include <iostream>
#include <cstdio>
#include <map>
using namespace std;

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

    map<char, long long> T;
    for(long long i = 0; i < s.size(); i++){
        if(T.find(s[i]) == T.end()) T[s[i]] = 1;
        else T[s[i]]++;
    }

    map<char, long long>::iterator it;
    long long ans = 0;
    for(it = T.begin(); it != T.end(); it++){
        if(it->second >= 2) ans += it->second*(it->second-1)/2;
    }

    cout << 1+s.size()*(s.size()-1)/2 - ans << endl;
    return 0;
}