/***

                                Bismillahir Rahmanir Rahim
                                Rabbi Zidni Ilma
                                Author : Saidur Rahman
                                Department of CSE, City University, Bangladesh.

***/

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

typedef         long long           ll;
#define         endl                "\n"
#define         ff                  first
#define         sf                  scanf
#define         pf                  printf
#define         ss                  second
const           int                 MAX=1e8;
#define         log_out             return 0
#define         pb                  push_back
#define         log_in              int main()
#define         PI                  acos(-1.0)
#define         vi                  vector<int>
#define         newline             printf("\n")
#define         pri                 pair<int,int>
#define         sff(a)              scanf("%d",&a)
#define         NO                  printf("NO\n")
#define         no                  printf("no\n")
#define         No                  printf("No\n")
#define         YES                 printf("YES\n")
#define         Yes                 printf("Yes\n")
#define         yes                 printf("yes\n")
#define         sfl(a)              scanf("%lld",&a)
#define         sfl(a)              scanf("%lld",&a)
#define         pff(a)              printf("%d\n",a)
#define         pfl(a)              printf("%lld\n",a)
#define         sfff(a,b)           scanf("%d%d",&a,&b)

#define         f0(i,b)             for(int i=0;i<(b);i++)
#define         sfll(a,b)           scanf("%lld%lld",&a,&b)
#define         sffff(a,b,c)        scanf("%d%d%d",&a,&b,&c)
#define         clock_start         clock_t tStart = clock()
#define         sflll(a,b,c)        scanf("%lld%lld%lld",&a,&b,&c)
#define         input               freopen("input.txt", "r", stdin)
#define         output              freopen("output.txt", "w", stdout)
#define         watch(x)            cout << (#x) << " is " << (x) << endl
#define         show_time           printf("Time taken: %.3fs\n", (double)(clock() - tStart) / CLOCKS_PER_SEC)

int         ToggleBit (int n, int X)    { return n ^ (1 << X); }
int         SetBit (int n, int X)       { return n | (1 << X); }
int         ClearBit (int n, int X)     { return n & ~(1 << X); }
bool        CheckBit (int n, int X)     { return (bool)(n & (1 << X)); }

/******************************** Code Starts From Here **********************************/

log_in
{

 #ifndef ONLINE_JUDGE
    input;
    output;
#endif
    ll n, m;
    sfll(n, m);
    ll mn1=INT_MAX, mn2 = INT_MAX,x;
    {
        for (int i = 0; i < n;i++)
        {
            sfl(x);
            mn1 = min(x, mn1);
        }
        for (int i = 0; i < m;i++)
        {
            sfl(x);
            mn2 = min(x, mn2);
        }
        mn1 != mn2 ? pf("%lld%lld", min(mn1, mn2), max(mn1, mn2)) : pff(mn2);
    }
    log_out;
}


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

typedef unsigned long long int lli;

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

int main()
{
	lli l,r,x,y;
	cin>>l>>r>>x>>y;
	vector<lli> v;
	for(lli i=l;i<=r;i++)
	{
		v.push_back(i);
	}
	lli count1=0;
	for(size_t i=0;i<v.size()-1;i++)
	{
		for(size_t j=i;j<v.size();j++)
		{
			lli a,b;
			a=v[i];
			b=v[j];
			lli g=gcd(a,b);
			lli lcm=(a*b)/g;
			if(g==x&&lcm==y)
			{
				if(a==b)
					count1++;
				else
					count1=count1+2;
			}
		}
	}
	cout<<count1<<endl;
}


#pragma optimize("Ofast")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=998244353;
typedef long long ll;
int modpow(int x,int y,int md=mod){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret*ret%md;if(y&1)ret=(ll)ret*x%md;return ret;}
int n,k,l;
gp_hash_table<int,int>Inv;
int dp[2][2005],c[2005][2005],b[23333],pre[23333],suf[23333],_[23333],sz;
void calc(){
	int tmp=1;
	pre[0]=1;suf[sz+1]=1;
	for(int i=1;i<=sz;i++)pre[i]=pre[i-1]*b[i]%mod;
	for(int i=sz;i>=1;i--)suf[i]=suf[i+1]*b[i]%mod;
	for(int i=1;i<=sz;i++)tmp=(tmp*b[i])%mod;
	int inv=modpow(tmp,mod-2);
	for(int i=1;i<=sz;i++)_[i]=(inv*pre[i-1]%mod*suf[i+1]%mod);
	for(int i=1;i<=sz;i++)Inv[b[i]]=_[i];
}
inline int inv(int x){x%=mod;return x?Inv[x]:0;}
inline void add(int &x,int y){x=(x+y)%mod;}
signed main(){
	c[0][0]=1;dp[0][0]=1;
	cin>>n>>k>>l;
	for(int i=0;i<=n;i++)
		for(int j=0;j<=i;j++)
			if(i||j)c[i][j]=((!i?0:c[i-1][j]*(i-j))+(!j?0:c[i][j-1])),c[i][j]%=mod;
//	while(1){int x,y;cin>>x>>y;cout<<c[x][y]<<endl;}
	int ans=0;
	for(int i=0;i<=n+n;i++){
		for(int j=0;j<=n&&j<=i&&j<=(n+n-i);j++){
			int right=(i-j)/2,left=(i+j)/2;
			left=n-left;right=n-right;
			int Left=!left?0ll:c[right][left-1],Right=(left==right)?0ll:c[right-1][left]*j;
			Left%=mod;Right%=mod;
			if(Left+Right)b[++sz]=(Left+Right)%mod;
		}
	}
	calc();
	for(int i=0;i<=n+n;i++){
		for(int j=0;j<=n&&j<=i&&j<=(n+n-i);j++){
			if(!dp[i&1][j])continue;
			int right=(i-j)/2,left=(i+j)/2;
			left=n-left;right=n-right;
			int Left=!left?0ll:c[right][left-1],Right=(left==right)?0ll:c[right-1][left]*j;
			Left%=mod;Right%=mod;
			add(dp[(i+1)&1][j+1],dp[i&1][j]*(Left)%mod*inv(Left+Right)%mod);
			if(j)add(dp[(i+1)&1][j-1],dp[i&1][j]*(Right)%mod*inv(Left+Right)%mod);
			if(j>=k)ans+=dp[i&1][j],ans%=mod;
		}memset(dp[i&1],0,sizeof dp[i&1]);
	}
	ans=ans*l%mod*modpow(n+n+1,mod-2)%mod;
	cout<<ans<<endl;
	return 0;
}


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

#pragma warning (disable:4996)

using namespace std;

int main()
{
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
	long long int n, i, j, c[10], flag;
	cin >> n;
	while (n % 10 == 0) {
		n = n / 10;
	}
	i = n;
	j = 1;
	while (i / 10 != 0) {
		i = i / 10;
		++j;
	}
	c[0] = n % 10;
	flag = 0;
	for (i = 1; i < j; ++i) {
		n = n / 10;
		c[i] = n % 10;
	}
	for (i = 0; i < j / 2 && flag == 0; i++) {
		if (c[i] != c[j - i - 1]) {
			flag = -1;
		}
	}
	if (flag == 0) {
		cout << "YES";
	}
	else {
		cout << "NO" ;
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,p=0,q=0;
    cin>>a;
    string s;
    for(int i=0;i<a;i++)
    {
        cin>>s[i];
        if(s[i]=='x')
        {
            p++;
        }
        else
        {
            if(p<=2)
            p=0;
        }
    }
   // cout<<p<<endl;
   if(p==a)
   {
       cout<<a-2<<endl;
       return 0;
   }
    if(p>2&&p<a)
    {
        for(int i=1;i<=p;i++)
        {
            p=p-i;
            if(p==2)
            {
                cout<<i<<endl;
            }
        }
    }
    else
    {
        cout<<"0"<<endl;
    }

    return 0;
}


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

int main() {
	int n;
	cin >> n;
	int a[101],dp[101];
	int ones = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		ones += a[i];
	}
	dp[0] = 0;
	//Construction of DP
	for (int i = 0; i < n; i++) {
		if (a[i] == 1)
			dp[i + 1] = dp[i] - 1;
		else// a[i] == 0
			dp[i + 1] = dp[i] + 1;
	}

	//Kayf mas
	int best = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i; j < n; j++) {
			int cur = dp[j + 1] - dp[i];
			best = max(best, cur);
		}
	}

	cout << best + ones;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int arr[2];
string a[2]={""};
int main()
{
    int x,y;
    cin>>x>>y;
    cout<<x/(y*2)<<endl;
    return 0;
}


#include <bits/stdc++.h>

#define all(A) begin(A), end(A)
#define rall(A) rbegin(A), rend(A)
#define sz(A) int(A.size())
#define pb push_back
#define mp make_pair

using namespace std;

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

const int ONES = 1 << 6 + 1;

int n, m;
int dp[ONES][ONES][ONES][42];

int take (int mask, vi bits) {
  for (int p: bits) {
    if (not (0 <= p and p < n)) continue;
    mask = mask & (~(1 << p));
  }
  return mask;
}

int rec (int mask1, int mask2, int mask3, int pos) {
  int r = pos / m;
  int c = pos % m;
  if (pos == n * m + m - 1) return 0;
  if (r == n) {
    return rec(mask2, mask3, (1 << n) - 1, c + 1);
  }
  if (dp[mask1][mask2][mask3][pos] != -1) return dp[mask1][mask2][mask3][pos];
  int ret = INT_MAX;
  if ((mask1 >> r) & 1) {
    ret = min(ret, 1 + rec(take(mask1, {r - 1, r, r + 1}), take(mask2, {r}), mask3, pos + m));
    ret = min(ret, 1 + rec(take(mask1, {r, r + 1, r + 2}), take(mask2, {r + 1}), mask3, pos + m));
    ret = min(ret, 1 + rec(take(mask1, {r}), take(mask2, {r - 1, r, r + 1}), take(mask3, {r}), pos + m));
  } else {
    ret = rec(mask1, mask2, mask3, pos + m);
  }
  return dp[mask1][mask2][mask3][pos] = ret;
}

int main () {
  ios::sync_with_stdio(false); cin.tie(0);
  memset(dp, -1, sizeof dp);
  cin >> n >> m;
  if (n > m) swap(n, m);
  if (n == 1) cout << n * m - (m + 2) / 3 << '\n';
  else if (n == 2) cout << n * m - (m / 2) - 1 << '\n';
  else cout << n * m - rec((1 << n) - 1, (1 << n) - 1, (1 << n) - 1, 0) << '\n';
  return (0);
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
        int a,b,c,d,x,y;
        cin>>a>>b>>c>>d>>x>>y;
      if(c%(a+x)==0 &&d%(b+y)==0)
   return cout<<"YES"<<endl,0;
else       if(c%(a+x)==0 &&d%(b-y)==0)
  return cout<<"YES"<<endl,0;
else       if(c%(a-x)==0 &&d%(b+y)==0)
   return cout<<"YES"<<endl,0;
         if(c%(a-x)==0 &&d%(b-y)==0)
return  cout<<"YES"<<endl,0;
else cout<<"NO"<<endl;

}


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

int n,i,r,m;

int main()
{cin>>n;
 for(i=2;i<=sqrt(n);i++)
   if(n%i==0){
     m=min(n/i-n,m);
     r=i;
   }
 cout<<r<<' '<<n/r<<endl;
 return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	if(n%2==0)
	cout<<"YES";
	else
	cout<<"NO";
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[3],x,y;
    cin>>a[1]>>a[2]>>a[3];
    sort(a+1,a+1+4);
    x=a[2]-a[1];
    y=a[3]-a[2];
    cout<<x+y;

}


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

#define INF 100000000
#define MX 500005
#define MM 200005
int P[MM], val[MX], root[MX];
bool chk[300005], vis[MM];
vector<int> adj[MM], Arr, S[MX];

int N, M, Q;
int L[MM], R[MM], st[MM], en[MM], pos[MM];
bool noRoot[MX], op[MX];

struct Edge {
	int s, e;
	void in() { cin >> s >> e; s --, e --; }
} E[300005];

void dfs(int u, int n) {
	root[u] = n;
	vis[u] = 1;
	S[n].push_back(u);
	for(auto i : adj[u]) if(chk[i] == false) {
		int v = E[i].s + E[i].e - u;
		if(!vis[v]) dfs(v, n);
	}
}

int find_root(int u) {
	if(root[u] == u) return u;
	return root[u] = find_root(root[u]);
}

void dfs1(int u) {
	if(L[u - N] == 0 && R[u - N] == 0) {
		st[u - N] = Arr.size();
		for(auto v : S[u]) Arr.push_back(v);
		en[u - N] = Arr.size() - 1;
	}
	else {
		dfs1(L[u - N]), dfs1(R[u - N]);
		st[u - N] = min(st[L[u - N] - N], st[R[u - N] - N]);
		en[u - N] = max(en[L[u - N] - N], en[R[u - N] - N]);
	}
}

struct WinnerTree {
	int v[MX * 4];
	int n;
	void build(int an) {
		int i;
		for (n = 1; n < an; n *= 2);
		for (i = 0; i < an; i++) v[n + i] = P[Arr[i]];
		for (i = an; i < n; i++) v[n + i] = P[Arr[0]];
		for (i = n - 1; i > 0; i--) v[i] = max(v[i * 2], v[i * 2 + 1]);
	}
	void up(int i, int val) {
		i += n;
		v[i] = val;
		for (i /= 2; i; i /= 2) v[i] = max(v[i * 2], v[i * 2 + 1]);
	}
	int get(int st, int en) {
		int rlt = 0;
		st += n, en += n;
		while (st < en) {
			if (st & 1) rlt = max(rlt, v[st]);
			if (en & 1) rlt = max(rlt, v[en - 1]);
			st = (st + 1) / 2;
			en /= 2;
		}
		return rlt;
	}
} WT;

int main() {
//	freopen("in.txt", "r", stdin);

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

	cin >> N >> M >> Q;
	for(int i = 0; i < N; i ++) cin >> P[i];
	for(int i = 0; i < M; i ++) {
		E[i].in();
		adj[E[i].s].push_back(i);
		adj[E[i].e].push_back(i);
	}
	for(int i = 0; i < Q; i ++) {
		int tp;
		cin >> tp >> val[i]; val[i] --;
		op[i] = tp - 1;
		if(op[i]) chk[val[i]] = 1;
	}
	for(int i = 0; i < MX; i ++) root[i] = i;
	int n = N;
	for(int i = 0; i < N; i ++) if(!vis[i]) {
		n ++;
		dfs(i, n);
	}
	for(int i = Q - 1; i >= 0; i --) if(op[i] == 1) {
		for(int j = i + 1; op[j] == 0 && j < Q; j ++) {
			int u = val[j];
			val[j] = find_root(u);
		}
		int u = E[val[i]].s, v = E[val[i]].e;
		int rtu = find_root(u), rtv = find_root(v);
		if(rtu == rtv) continue;
		n ++;
		L[n - N] = rtu, R[n - N] = rtv;
		root[rtu] = n, root[rtv] = n;
		noRoot[rtu] = 1, noRoot[rtv] = 1;
	}
	for(int i = 0; i < Q && !op[i]; i ++) {
		int u = val[i];
		val[i] = find_root(u);
	}

	for(int i = N + 1; i <= n; i ++) if(!noRoot[i]) dfs1(i);
	assert(Arr.size() == N);
	for(int i = 0; i < N; i ++) pos[P[Arr[i]]] = i;

	WT.build(N);
	for(int i = 0; i < Q; i ++) if(op[i] == 0) {
		int s = st[val[i] - N], e = en[val[i] - N];
		int ans = WT.get(s, e + 1);
		cout << ans << endl;
		if(ans == 0) continue;
		int p = pos[ans];
		WT.up(p, 0);
	}

	return 0;
}


#include <iostream>
#include <map>
#include <vector>
#include <set>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
#define x first
#define y second
#define pb push_back
#define int long long
typedef long double ld;
const int MAXN = 1e5 + 7;
int delt[MAXN];
int a[MAXN];
int t[4 * MAXN];
int dp[MAXN];
int get(int v, int tl, int tr, int l, int r) {
	if (tr < l || r < tl)
		return 0;
	else if (l <= tl && tr <= r)
		return t[v];
	else {
		int tm = (tl + tr) / 2;
		return max(get(2 * v, tl, tm, l, r), get(2 * v + 1, tm + 1, tr, l, r));
	}
}
int upd(int v, int tl, int tr, int p, int vl) {
	if (tl == tr)
		t[v] = max(t[v], vl);
	else {
		int tm = (tl + tr) / 2;
		if (p <= tm)
			upd(2 * v, tl, tm, p, vl);
		else
			upd(2 * v + 1, tm + 1, tr, p, vl);
		t[v] = max(t[2 * v], t[2 * v + 1]);
	}
}
void solve() {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; ++i) {
		int a, b;
		cin >> a >> b;
		--a;
		++delt[a];
		--delt[b];
	}
	int sum = 0, ans = 0;
	for (int i = 0; i < m; ++i) {
		sum += delt[i];
		a[i] = sum;
		dp[i] = 1;
		if (a[i])
			dp[i] = get(1, 0, MAXN - 1, 0, a[i]) + 1;
		upd(1, 0, MAXN - 1, a[i], dp[i]);
		ans = max(ans, dp[i]);
	}
	cout << ans;
}
signed main() {
	freopen("A.in", "r", stdin);
	freopen("A.out", "w", stdout);
	ios_base::sync_with_stdio(false);

	solve();

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define forn(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define sz(a) int(a.size())
#define x first
#define y second

typedef long long ll;
typedef long double ld;

const int N = 1e6 + 9;
const char C = 'a';

int dp1[N], dp2[N], t[N*4], a[N], op[N], cl[N], mx1[N], mx2[N];

void precount(int n) {
        int cur = 0;
        forn(i, n) {
                cur += op[i];
                a[i] = cur;
                cur -= cl[i];
        }
}

int range_max(int v, int t_l, int t_r, int l, int r) {
        if (l > r)
                return 0;
        if (l == t_l && r == t_r)
                return t[v];
        int t_m = (t_l + t_r)/2;
        return max(range_max(v*2, t_l, t_m, l, min(r, t_m)),
                range_max(v*2 + 1, t_m + 1, t_r, max(t_m + 1, l), r));
}

void update(int v, int l, int r, int pos, int val) {
        if (l == r) {
                t[v] = max(t[v], val);
                return;
        }
        int m = (l + r)/2;
        if (pos <= m)
                update(v*2, l, m, pos, val);
        else
                update(v*2 + 1, m + 1, r, pos, val);
        t[v] = max(t[v*2], t[v*2 + 1]);
}

void count_dp(int dp[], int n) {
        fill(t, t + N*4, 0);
        forn(i, n) {
                dp[i] = range_max(1, 0, n - 1, 0, a[i]) + 1;
                update(1, 0, n - 1, a[i], dp[i]);
        }
}

int main() {
	ios::sync_with_stdio(0);
        int n, m, l, r, ans = 0;
        cin >> m >> n;
        forn(i, m) {
                cin >> l >> r;
                l--;
                r--;
                op[l]++;
                cl[r]++;
        }
        precount(n);
        count_dp(dp1, n);
        reverse(a, a + n);
        count_dp(dp2, n);
        mx1[0] = dp1[0];
        mx2[0] = dp2[0];
        for (int i = 1; i < n; i++) {
                mx1[i] = mx1[i - 1];
                mx2[i] = mx2[i - 1];
                mx1[i] = max(mx1[i], dp1[i]);
                mx2[i] = max(mx2[i], dp2[i]);
        }
        reverse(mx2, mx2 + n);
        forn(i, n) {
                ans = max(ans, mx1[i] + mx2[i] - 1);
        }
        cout << ans;
	return 0;
}


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

#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define sz size()
#define endl "\n"
#define pb push_back
#define pp pop_back
#define mp make_pair
#define REP(I,n) for(int I = 0; I < n; I++)
#define REP_1(I,n) for(int I = 1; I <= n; I++)
#define w(t) int t; cin>>t; while(t--)

#define MOD 1000000007
#define INF 1e9 + 7

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef map<int,int> mii;
typedef map<string,int> msi;
typedef map<int,string> mis;
typedef set<int> si;
typedef set<string> ss;

typedef long long ll;

template<class T>
istream &operator>>(istream &in,vector<T> &arr) {
	for(auto &x : arr)
		in>>x;
	return in;
}
bool sortbysec(pair<int,int> a,pair<int,int> b) {
	if(a.second == b.second)
		if(a.first>b.first)
			return true;
		else
			return false;
	return a.second>b.second;
}
void solve() {
	int n;
	cin>>n;
	long long int arr[n];
	REP(i,n) {
		cin>>arr[i];
	}
	bool temp[1000]={false};
	sort(arr,arr+n,greater<int>());
	long long int count = 0;
	REP(i,n) {
		if(i==0)
			count += arr[i];
		else {
			if(arr[i]==arr[i-1]) {
				arr[i]--;
			}
			if(temp[arr[i]]==false) {
				count += arr[i];
				temp[arr[i]]=true;
			}
		}
	}
	cout<<count<<endl;
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();
}


#include <bits/stdc++.h>

using namespace std;
typedef long long LL;

#define MAXN 2501

vector<int> cache[MAXN];

int main() {
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);

    int n;
    scanf("%d", &n);
    for (int i = 0; i <= n; i++) {
        int idx = (i ^ 0);
        cache[idx].push_back(i);
    }

    int ans = 0;
    for (int a = 1; a <= n - 2; a++) {
        for (int b = a; b <= n-1; b++) {
            int idx = (a ^ b);
            //if (a == 3 && b == 5)
                //printf("idx = %d\n", idx);
            for (vector<int>::iterator it = cache[idx].begin();
                    it != cache[idx].end(); ++it) {
                int c = *it;
                //if (a == 3 && b == 5)
                    //printf("%d\n", c);
                if (c >= b && a + b > c) {
                    //printf("%d %d %d\n", a, b, c);
                    ans++;
                }
            }
        }
    }

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


#include<bits/stdc++.h>
#define ll long long int
#define fill(a,v) memset(a,v,sizeof a)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
using namespace std;
ll i,j,n;
ll vis[2501][2501];
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	ll ans=0;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		{
			ll c=i^j;

			if(vis[i][j] || vis[j][i]  || vis[c][i] || vis[i][c] || vis[j][c] || vis[c][j] )
				continue;

			vis[i][j]=1;
			vis[j][i]=1;
			vis[c][i]=1;
			vis[i][c]=1;
			vis[j][c]=1;
			vis[c][j]=1;
			if(c==0 || c>n)
				continue;
			double s,area;
			s=(double)(i+j+c)/2.0;
			//printf("%lf\n",s);
			area=sqrt(s*(s-i)*(s-j)*(s-c));
			if(area>0)
			{
				ans++;
			}
		}
	}
	cout<<ans;
  return 0;
  }


#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#define IO ios_base::sync_with_stdio(false); cin.tie(0);

using namespace std;

double l, d, v, g, r, p = 0, t = 0;
int on[1024], light = 1;

int main() { IO
  cout << fixed << setprecision(8);

  cin>>l>>d>>v>>g>>r;

  on[0] = 1;
  for (int i = 1, st = 1; i < 1024; ++i) {
    if (!light) {
      for (int j = 0; j < r; ++j) {
        on[i + j] = 0;
      }
      i += r - 1;
    } else {
      for (int j = 0; j < g; ++j) {
        on[i + j] = 1;
      }
      i += g - 1;
    }
    light ^= 1;
  }
  t = d / v;
  int it = (int)(d / v);

  if (it == t) {
    if (on[it]) {
      cout << l / v << "\n";
    } else {
      cout << t + r + (l - d) / v << "\n";
    }
  } else {
    if (on[it + 1]) {
      cout << l / v << "\n";
    } else {
      double w = r - (t - it);
      cout << t + w + (l - d) / v << "\n";
    }
  }
  return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char  a[105];
int main()
{
	int i=1,j=1,cun,jishu=1,ge=0;
	while((a[i++]=getchar())!=' ');
	for(;j<=(i-1);)
	{
		for(int c=j+1;c<=(i-1);c++)
		{
			if(a[c]!=a[j])
			{
                j=c;
                jishu=1;
                break;
            }
			if(a[c]==a[j])
			{
				jishu+=1;
			}
		}
		if(jishu%2==0)
		{
			ge+=1;
		}
	}
	cout<<ge<<endl;
	return 0;
}


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

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

	int a[n],b[m];
	int amin,bmin;

	amin=INT_MAX;
	bmin=INT_MAX;
	//first check for any common
	vector<int> v(10,0);

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

			v[a[i]]=1;

		}

	for(int i=0;i<m;i++)
	{
			cin>>b[i];
			if(b[i]<bmin)
				bmin=b[i];

			if(v[b[i]]==1)
			{
				cout<<b[i]<<endl;
				return 0;
			}
	}

	if(amin==bmin) cout<<amin<<endl;
	else if(amin<bmin) cout<<amin<<bmin<<endl;
	else cout<<bmin<<amin<<endl;

}


#include<iostream>
using namespace std;
int main()
{
   char ch[101],h[]="hello";
   int i,j,t,k;
   cin>>ch;
   t=0;
   for(i=0;ch[i]!='\0';i++)
   {

      if(ch[i]==h[t])
      {
         k=i;
         t++;
         while(h[t]!='\0')
         {
         for(j=k+1;ch[j]!='\0';j++)
         {
            if(ch[j]==h[t])
            {
               t++;
               k=j;
               break;
            }
         }
         }
         if(h[t]=='\0')
         {
            cout<<"\nYES";
            break;
         }

      }
   }
   if(h[t]!='\0')
   {
      cout<<endl<<"NO";

   }

   return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long int factorial(long long int n) {
    if(n == 1)
        return 1;
    else
        return n * factorial(n-1);
}
int main() {
    long long int n,m;
    cin>>n>>m;
    long long int k1 = factorial(n);
    long long int k2 = factorial(m);
    if(k1 > k2)
        cout<<k1;
    else
        cout<<k2;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    int ta, tb, a, b, h, m, l, r;
    char c;
    cin >> a >> ta;
    cin >> b >> tb;
    cin >> h >> c >> m;
    l = h * 60 + m + 1;
    r = h * 60 + m + ta - 1;
    int auto_l = 5 * 60;
    int auto_r = 5 * 60;
    int ans = 0;
    while (1) {
        int cur_l = auto_r + 1;
        int cur_r = auto_r + tb - 1;
        if (max(cur_l, l) <= min(cur_r, r)) {
            ans++;
        }
        auto_r += b;
        if (auto_r > r) {
            break;
        }
        if (auto_r > 23 * 60 + 59) {
            auto_r = 0;
        }
    }
    cout << ans << endl;
}


#include <cstdio>
#include <string.h>
#include <cmath>
#include <vector>
typedef long long ll;
const ll INF=1000000007;
ll m;
ll wei[15];
ll geshu[15];
ll z[10];
ll c(ll a, ll b)
{
  ll ans=1;
  for(ll k=a;k>a-b;k--)
  {
    ans=ans*k;
  }
  for(ll k=1;k<=b;k++)
  {
    ans=ans/k;
  }
  return ans;
}
ll q[15][15];
ll qqq[7];
ll z1=0;
ll b;
void dfs(ll depth)
{
  ll k;
   if(depth<b)
   {
    for(ll i=1;i<=6;i++)
    {
      qqq[i]++;
      dfs(depth+1);
      qqq[i]--;
    }
   }
   else
   {
    k=1;
    int g[10];
    memset(g,0,sizeof(g));
    for(ll i=1;i<=6;i++)
    {
      g[qqq[i]]++;
    }
    for(ll i=0;i<=b;i++)
    {
      for(ll j=0;j<g[i];j++)
      {
        k=(k*(geshu[i]-j))%INF;
      }
    }
    z1=(z1+k)%INF;
   }
}
ll suan(ll a)
{
  z1=0;
  memset(qqq,0,sizeof(qqq));
  dfs(0);
  ll k=(geshu[a]*z1)%INF;
  return k;
}
int main()
{
  scanf("%I64d",&m);
  ll s=m;
  ll num=0;
  ll w=1;
  memset(q,0,sizeof(q));
  memset(geshu,0,sizeof(geshu));
  memset(z,0,sizeof(z));
  while(s!=0)
  {
    ll k=s%10;
    wei[w]=k;
    s=s/10;
    num++;
    w++;
  }
  for(ll i=1;i<=9;i++)
  {
    for(ll j=0;j<=i;j++)
    {
      ll a1=ll(pow(double(8),double(i-j)));
      ll a2=ll(pow(double(2),double(j)));
      q[i][j]=c(i,j)*a1*a2;
    }
  }
  ll ans=0;
  ll qian=0;
  if(m==1000000000)
  {
       for(int i=1;i<=9;i++)
       {
        wei[i]=9;
       }
       num--;
  }
  for(int i=num;i>1;i--)
  {
    for(int j=0;j<=i;j++)
    {
      if(wei[i]>4&&wei[i]<=7)
      {
        geshu[j+qian+1]+=q[i-1][j];
        geshu[j+qian]+=q[i-1][j]*(wei[i]-1);
      }
      if(wei[i]>7)
      {
        geshu[j+qian+1]+=q[i-1][j]*2;
        geshu[j+qian]+=q[i-1][j]*(wei[i]-2);
      }
      if(wei[i]<=4)
      {
        geshu[j+qian]+=q[i-1][j]*(wei[i]);
      }
    }
    if(wei[i]==4||wei[i]==7)
    {
      qian++;
    }
  }
      if(wei[1]>=4&&wei[1]<7)
      {
        geshu[qian+1]+=1;
        geshu[qian]+=wei[1];
      }
      if(wei[1]>=7)
      {
        geshu[qian+1]+=2;
        geshu[qian]+=(wei[1]-1);

      }
      if(wei[1]<4)
      {
        geshu[qian]+=(wei[1]+1);
      }
   if(m==1000000000)
   {
    geshu[0]++;
   }
  geshu[0]--;
  for(ll i=1;i<=num;i++)
  {
     for(ll j=0;j<i;j++)
     {
      b=j;
     ans=(ans+suan(i))%INF;
     }
  }
  printf("%I64d\n",ans);  while(1);
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	long double l,d,v,g,r;
	cin >> l >> d >> v >> g >> r;
	long double p = d / v;
	while(p >= 0){
		p = p - (g + r);
	}
	p += g + r;
	if(p <= g)cout << fixed << setprecision(10) << l / v << endl;
	else cout << fixed << setprecision(10) << double(r + g - p + (l) / v) << endl;
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;

#define fi(a,b,c) for(int a=b;a<=c;a++)
#define fo(a,b,c) for(int a=b;a>=c;a--)
#define long long long
#define pii pair<int,int>
#define mp make_pair

const int N = 2e6+9;

struct String{
  string s;
  int pos;

  bool operator< (String b) const{
    if (s.length() < b.s.length())
      return true;
    if (s.length() > b.s.length())
      return false;
    return (s < b.s) || (s == b.s && pos > b.pos);
  }
};

struct Node{
  vector<int> pos;
  Node *p[2];

  Node () {
    p[0] = p[1] = NULL;
    pos.clear();
  }
} trie;

struct Position{
  int cost, pos;
  Node *pos_trie;
  Position (){}
  Position (int cost_, int pos_, Node *pos_trie_){
    cost = cost_, pos = pos_, pos_trie = pos_trie_;
  }
};

struct Query{
  int l, r, pos;
  string s;

  bool operator< (Query b) const{
    return (s.length() > b.s.length()) || (s.length() == b.s.length() && pos < b.pos);
  }
};

struct IT{
  int c[N];
  pii mx[N*4];

  IT(){
    fi(i,0,N-1)
      c[i] = 0;
    fi(i,0,4*N-1)
      mx[i] = mp(0,0);
  }

  void Build(int k, int l, int r){
    if (l == r){
      mx[k] = mp(c[l],l);
      return;
    }

    int mid = l+r>>1;
    Build(k<<1, l, mid);
    Build(k<<1|1, mid+1, r);
    if (mx[k<<1].first > mx[k<<1|1].first)
      mx[k] = mx[k<<1];
    else
      mx[k] = mx[k<<1|1];
  }

  void Update(int k, int l, int r, int x){
    if (r < x || x < l) return;

    if (l == r){
      mx[k] = mp(c[l],l);
      return;
    }

    int mid = l+r>>1;
    Update(k<<1, l, mid, x);
    Update(k<<1|1, mid+1, r, x);
    if (mx[k<<1].first > mx[k<<1|1].first)
      mx[k] = mx[k<<1];
    else
      mx[k] = mx[k<<1|1];
  }

  pii Get(int k, int l, int r, int x, int y){
    if (r < x || y < l) return mp(0,0);

    if (x <= l && r <= y)
      return mx[k];

    int mid = l+r>>1;
    pii res1 = Get(k<<1, l, mid, x, y);
    pii res2 = Get(k<<1|1, mid+1, r, x, y);
    if (res1.first > res2.first)
      return res1;
    else
      return res2;
  }
} it;

string str[N];
int n, q;
int ans[N];
String s[N];
Query qu[N];
Node *pc[N];
Node *pos_zero_trie[N];
vector<Position> list_[N];
deque<int> cango;

void Init(){
  Node *p = ≜
  pos_zero_trie[1000001] = ≜
  fo(i,1000000,s[1].s.length()){
    p->p[0] = new Node();
    p = p->p[0];
    pos_zero_trie[i] = p;
  }
}

void Update_List(int x){
  int len = s[x].s.length();
  Node *p = pos_zero_trie[len+1];
  fi(l,0,len-1){
    int i = len-l;
    int ch = s[x].s[l]-'0';
    if (p->p[ch] == NULL)
      p->p[ch] = new Node();
    p = p->p[ch];
    list_[i].push_back(Position(x,s[x].pos,p));
  }
}

void Add(int x){
  int len = str[x].length();
  Node *p = pos_zero_trie[len+1];
  fi(i,0,len-1){
    int ch = str[x][i]-'0';
    p = p->p[ch];
    p->pos.push_back(x);
  }
}

int Find(int l_, int r_, Node *p){
  if (p->pos.empty()) return -1;
  int l = -1, r = p->pos.size();
  while (l+1<r){
    int mid = l+r>>1;
    if (p->pos[mid] < l_)
      l = mid;
    else
      r = mid;
  }

  if (r == p->pos.size() || p->pos[r] > r_)
    return -1;
  else
    return p->pos[r];
}

int Get(int l, int r, string s, Node *p){
  fi(i,0,s.length()-1){
    int ch = s[i]-'0'^1;
    if (p->p[ch] == NULL || Find(l, r, p->p[ch]) == -1)
      ch ^= 1;
    p = p->p[ch];
  }
  return Find(l, r, p);
}

int Get_(int l, int r, string s, Node *p){
  while (!cango.empty()) cango.pop_back();

  Node *tmpp = p;
  int len = 0;
  fi(i,1,s.length()){
    if (tmpp->p[1] != NULL && Find(l, r, tmpp->p[1]) != -1 && len < s.length())
      cango.push_back(len);
    if (tmpp->p[0] == NULL)
      break;
    tmpp = tmpp->p[0]; len++;
  }

  len = 0;
  fi(i,0,s.length()-1){
    int ch = s[i]-'0'^1;
    if (ch == 0 && len != -1){
      while (!cango.empty() && len >= cango.front())
        cango.pop_front();
      if (cango.empty())
        ch = 1, len = -1;
    }

    if (ch == 1 || len == -1)
      if (p->p[ch]
           == NULL || Find(l, r, p->p[ch]) == -1)
        ch ^= 1;

    if (ch) len = -1;
    if (len != -1)
      len++;
    p = p->p[ch];
  }

  return Find(l,r,p);
}

main(){
  cin >> n >> q;
  fi(i,1,n){
    cin >> str[i];
    s[i].s = str[i];
    s[i].pos = i;
  }

  sort(s+1,s+1+n);
  Init();

  fi(i,1,n)
    Update_List(i);
  fi(i,1,n)
    Add(i);

  fi(i,1,q){
    cin >> qu[i].l >> qu[i].r >> qu[i].s;
    qu[i].pos = i;
  }
  sort(qu+1,qu+1+q);

  fi(i,1,n)
    pc[i] = NULL;

  int len = 0;
  fi(i,1,q){
    if (qu[i].s.length()+1 != len){
      if (len != 0){
        fi(j,0,(int)list_[len].size()-1){
          it.c[list_[len][j].pos] = 0;
          pc[list_[len][j].pos] = NULL;
          it.Update(1,1,n,list_[len][j].pos);
        }
      }

      len = qu[i].s.length()+1;
      fi(j,0,(int)list_[len].size()-1){
        it.c[list_[len][j].pos] = list_[len][j].cost;
        pc[list_[len][j].pos] = list_[len][j].pos_trie;
        it.Update(1,1,n,list_[len][j].pos);
      }
    }

    if (qu[i].l == qu[i].r){
      ans[qu[i].pos] = qu[i].l;
      continue;
    }
    pii mx = it.Get(1,1,n,qu[i].l,qu[i].r);
    if (mx.first != 0)
      ans[qu[i].pos] = Get(qu[i].l, qu[i].r, qu[i].s, pc[mx.second]);
    else
      ans[qu[i].pos] = Get_(qu[i].l, qu[i].r, qu[i].s, pos_zero_trie[len]);
  }

  fi(i,1,q)
    cout << ans[i] << "\n";
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

vector<vector<int> > ans;

int f(int a, int b, int c, vector<vector<int> > dp ){
	if(a==0 && b==0 && c==0){
		ans = dp;
		return 1;
	}
	else if(a<0 || b<0 || c<0){
		return 0;
	}
	else{
		vector<vector<int> > tmp;
		tmp = dp;
		tmp[0][1]++;
		int k = f(a-1,b-1,c,tmp);
		tmp= dp;
		tmp[1][2]++;
		k= max(k,f(a,b-1,c-1,tmp));
		tmp = dp;
		tmp[2][0]++;
		k = max(k,f(a-1,b,c-1,tmp));
		return k;
	}
}

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	vector<vector<int> > dp(3,vector<int>(3));
	if(f(a,b,c,dp)==1){
		cout<<ans[0][1]<<" "<<ans[1][2]<<" "<<ans[2][0]<<endl;
	}
	else{
		cout<<"Impossible\n";
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

int u,v,w;

int f(int a, int b, int c, int x, int y, int z){
	if(a==0 && b==0 && c==0){
		u = x;v=y;w=z;
		return 1;
	}
	else if(a<0 || b<0 || c<0){
		return 0;
	}
	else{
		int k = f(a-1,b-1,c,x+1,y,z);
		k= max(k,f(a,b-1,c-1,x,y+1,z));
		k = max(k,f(a-1,b,c-1,x,y,z+1));
		return k;
	}
}

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

	if(f(a,b,c,0,0,0)==1){
		cout<<u<<" "<<v<<" "<<w<<endl;
	}
	else{
		cout<<"Impossible\n";
	}
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int a[3],s=0;
	cin>>a[1]>>a[2]>>a[3];
	sort(a+1,a+4);
	s+=a[2]-a[1];
	s+=a[3]-a[2];
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
long long reflection(long long a){
	int argham;
	long long ref;
	for(long long i=1;i<1000000000;i*=10){
		if(a>=i)
			continue;
		else{
			ref=i-1;
			break;
		}

	}
	return ((ref-a)*a);
}
int main(){
	int i,t,m,n,j,k;
	long long l,r;
	long long maxx=0;
	cin>>l>>r;
	for(i=l;i<=r;i++){
		maxx=max(maxx,reflection(i));
	}
	cout<<maxx<<endl;
}


#include<bits/stdc++.h>

#define X first
#define Y second
#define eb push_back
#define pb pop_back
#define mp make_pair
#define siz(a) int(a.size())
//for traversing the container (bcoz we cannot access linked list etc with direct index)
//c stands for container and it for iterator
#define tr(c, it) \
		for(typeof(c.begin()) it=c.begin() ; it != c.end() ; it++)

#define all(c) c.begin(), c.end()
#define present(container, element) (container.find(element) != container.end()) //whether the element is present in the container

#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
#define scan(x) scanf("%lld", &x)
#define print(x) printf("%lld", x)
#define pN printf("\n");
//#define mod (((ll)1000000000) * ((ll)1000000000))
using namespace std;

typedef   long long  int ll;
typedef unsigned long long int ull;
typedef vector < int > vi;
typedef vector < vi > vvi;
typedef vector < ll > vll;
typedef vector < vll > vvll;
typedef pair < int , int > ii;
const ll mod=1e9+7;
const ll mod2=1e9+9;
const ll maxn = 1e6+10;
const int root=1e7+5;
const long long inf = 1e18 + 18;
double pie4=3.1415926535;
//dont do silly mistake as always-
//1-read question properly(dont miss single line)
//2-check maximum array size
//3-int or long long int or ull or sort(a+1,a+n+1)-indexing
//4-do u understand question correctly(shampoo)?
//5-MOST IMP-BE CALM YOU CAN DO:)
//6-think edge case or corner case before submitting.
ll a[40] ;
vector<ll>v,v1 ;

int main() {

	ll n,m,i,j,ans=0,x ;

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

	cin >> n >> m ;

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

		cin >>a[i] ;

		a[i]%=m ;
	}

	x = min(n,ll(20));

	for(i=1;i<(1<<x);i++){

		ans = 0 ;
		for(j=0;j<x;j++){

			if(i & 1<<j){
			ans+=a[j];
			ans%=m ;
		}

	//	trace2(i,ans);
		v.eb(ans);
	}
}
		x = max(ll(0),n-x);

		for(i=1;i<(1<<x);i++){

		ans = 0 ;

		for(j=0;j<x;j++){

			if(i & 1<<j){
			ans+=a[j];
			ans%=m ;
		}

		v1.eb(ans);
	}
    }

    v.eb(0);
    v1.eb(0);

    sort(v.begin(),v.end());
	sort(v1.begin(),v1.end());

	v.erase(unique(v.begin(),v.end()),v.end());
	v1.erase(unique(v1.begin(),v1.end()),v1.end());

	vector<ll>::iterator it1 ;

	for(auto it:v){

	    it1 = upper_bound(v1.begin(),v1.end(),max(ll(0),m-it-1)) ;

		if(it1!=v1.begin())
		it1--;

		ans = max(ans,it + *it1);
	}

	for(auto it:v1){

	    it1 = upper_bound(v.begin(),v.end(),max(ll(0),m-it-1)) ;

		if(it1!=v1.begin())
		it1--;

		ans = max(ans,it + *it1);
	}

	cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
void read(int &x)
{
	x=0; char ch=getchar();int sign=1;
	for(;!isdigit(ch);ch=getchar()) if(ch=='-') sign=-1;
	for(;isdigit(ch);ch=getchar()) x=(x<<1)+(x<<3)+ch-48;
	x*=sign;
}
int n,m,maxx,a[5000],ans,sl[50000000],cnt,sl1[50000000],cnt1;
map<ll,int > q1;
map<ll,int > q2;
void dfs(int x)
{
	if(x>n/2)
	{
	if(q1[ans]!=1)
	{
	sl[++cnt]=ans;
	q1[ans]=1;
	}
	return;
	}
	int anss=ans;
	ans=(ans+a[x])%m;
	dfs(x+1);
	ans=anss;
	dfs(x+1);
}
void dfs1(int x)
{
	if(x>n)
	{
	if(q2[ans]!=1)
	{
	sl1[++cnt1]=ans;
	q2[ans]=1;
	}
	return;
	}
	int anss=ans;
	ans=(ans+a[x])%m;
	dfs1(x+1);
	ans=anss;
	dfs1(x+1);
}
int main()
{
	read(n);read(m);
	for(int i=1;i<=n;i++)
	read(a[i]);
	dfs(1);
	dfs1(n/2+1);
	for(int i=1;i<=cnt;i++)
	for(int j=1;j<=cnt1;j++)
	{
		if((sl[i]+sl1[j])%m>maxx)
		maxx=(sl[i]+sl1[j])%m;
	}
	cout<<maxx;
	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define F first
#define S second

#ifndef LOCAL
#define cerr if(0)cerr
#endif // LOCAL

using namespace std;

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

const int INF = int(1e9);
const long long INFll = 1ll * INF * INF;
const long double ldINF = 1e+018;
const long double EPS = 0.000000001;
const int base = INF;
const int sdx[4] = {0, 1, 0, -1};
const int sdy[4] = {1, 0, -1, 0};

int main() {
    ios_base::sync_with_stdio(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int a, b, x, y;
    cin >> a >> b >> x >> y;
    string s;
    cin >> s;
    int h = (s[0] - '0') * 10 + (s[1] - '0');
    int m = (s[3] - '0') * 10 + (s[4] - '0');
    //cout << h << ' ' << m << endl;
    int f1 = h + (b / 60);
    int f2 = m + b % 60;
    f1 += (f2 / 60);
    f2 %= 60;
    f1 %= 24;
    int cur1 = 5, cur2 = 0;
    int ans = 0;
    //cout << f1 << ' ' << f2 << endl;
    while (cur1 <= f1 || cur2 < f2) {
        //cout << cur1 << ' ' << cur2 << endl;
        int t1, t2;
        t1 = cur1 + (y / 60);
        t2 = cur2 + y % 60;
        t1 += (t2 / 60);
        t2 %= 60;
        t1 %= 24;
        bool f = true;
        if ((t1 > h || (t1 == h && t2 > m)) && (t1 < f1 || (t1 == f1 && t2 < f2)) && t1 >= 5) {
            ans++;
           // cout << "+1" << endl;
        }
        else {
            if ((cur1 > h || (cur1 == h && cur2 >= m)) && (cur1 < f1 || (cur1 == f1 && cur2 < f2)) && cur1 >= 5) {
                //cout << "+1" << endl;
                ans++;
            }
        }
        cur1 += (x / 60);
        cur2 += (x % 60);
        cur1 += (cur2 / 60);
        cur2 %= 60;
        cur1 %= 24;
    }
    cout << ans << endl;
    return 0;
}


#include <algorithm>
#include <numeric>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <sstream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <stdio.h>
typedef long long ll;
#define mset(a, val) memset(a, val, sizeof(a))
#define up(i, s, t) for (ll i = (s); i < (t); i += 1)
#define down(i, s, t) for (ll i = (s); i > (t); i -= 1)
#define rd1(a) scanf("%d", &a)
#define rd2(a, b) scanf("%d %d", &a, &b)
#define rd3(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define rd4(a, b, c, d) scanf("%d %d %d %d", &a, &b, &c, &d)
#define pii pair<int, int>

using namespace std;
const int MAXINT = 0x70707070;
const ll MAXLONG = (ll) 1 << 60;
const int MAXN = 105;

int arr[MAXN];
int n, k, x;

int calc(int s, int t) {
	queue<pii> qs, qt;
	int idx = s;
	while (idx >= 0) {
		int nxt = idx - 1;
		while (nxt >= 0 && arr[nxt] == arr[idx]) nxt --;

		qs.push(make_pair(arr[idx], idx - nxt));
		idx = nxt;
	}

	idx = t;
	while (idx < n) {
		int nxt = t + 1;
		while (nxt < n && arr[nxt] == arr[idx]) nxt ++;

		qt.push(make_pair(arr[idx], nxt - idx));
		idx = nxt;
	}

	int res = 0;
	while (!qs.empty() && !qs.empty()) {
		pii ps = qs.front(), pt = qt.front();
		qs.pop();
		qt.pop();

		if (ps.first != pt.first) break;

		if (ps.second + pt.second < 3) break;

		res += ps.second + pt.second;
	}

	return res;
}

int main () {
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

	while (rd3(n, k, x) != -1) {
		up(i, 0, n) {
			rd1(arr[i]);
		}

		int idx = 0;
		int res = 0;
		while (idx < n) {
			if (arr[idx] != x) {
				idx ++;
				continue;
			}

			int nxt = idx + 1;
			while (nxt < n && arr[nxt] == arr[idx]) nxt ++;

			int cntx = nxt - idx;
			if (cntx < 2) {
				idx = nxt;
				continue;
			}

			int once = calc(idx - 1, nxt);
			res = max(res, once + 2);
			idx = nxt;
		}

		cout << res << endl;
	}
    return 0;
}


/*input
97 31 9984524
*/

#include <iostream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <cassert>
#include <algorithm>
#include <cstdlib>
#include <numeric>
#include <climits>
#include <fstream>

using namespace std;

#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORA(i, a) for (auto &i : a)
#define FORB(i, a, b) for (int i = a; i >= b; --i)
#define SZ(a) ((int) a.size())
#define ALL(a) begin(a), end(a)

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define fi first
#define se second

const int MOD = 998244353;

#define div divv
int add(int a, int b) { a += b; if (a >= MOD) a -= MOD; return a; }
int sub(int a, int b) { a -= b; if (a < 0) a += MOD; return a; }
int mul(int a, int b) { return (long long) a * b % MOD; }
int qpow(int a, int p)
{
	int ans = 1;
	while (p) {
		if (p & 1) ans = mul(ans, a);
		a = mul(a, a);
		p >>= 1;
	}
	return ans;
}
int inv(int a) { return qpow(a, MOD - 2); }
int div(int a, int b) { return mul(a, inv(b)); }

// start of code

const int MAXN = 2009;
int fact[MAXN], invFact[MAXN], pow2[MAXN], N, k, l;
int nCk(int a, int b) { return mul(fact[a], mul(invFact[a - b], invFact[b])); }

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

	fact[0] = 1; FOR(i, 1, MAXN - 1) fact[i] = mul(fact[i-1], i);
	invFact[MAXN - 1] = inv(fact[MAXN - 1]); FORB(i, MAXN-1, 1) invFact[i-1] = mul(invFact[i], i);
	pow2[0] = 1; FOR(i, 1, MAXN - 1) pow2[i] = mul(pow2[i-1], 2);

	cin >> N >> k >> l;

	int ans = 0;
	FOR(i, 0, 2*N) for (int j = i; j >= k; j -= 2) {
		if (i + j > 2*N) continue;
 		int x = 1;
 		x = mul(x, nCk(i, j));
 		x = mul(x, nCk(2*N - i, j));
		x = mul(x, fact[i - j]);
		x = mul(x, fact[2 * N - j - i]);
		x = mul(x, fact[j]);
		x = mul(x, pow2[j]);
		x = mul(x, invFact[(i - j) / 2]);
		x = mul(x, invFact[(2 * N - j - i) / 2]);
		// cout << i << ' ' << j << ": " << div(mul(fact[N], x), pow2[N]) << endl;
		ans = add(ans, x);
	}
	ans = mul(ans, fact[N]);
	ans = div(ans, fact[2*N]);
	ans = div(ans, 2*N + 1);
	ans = mul(ans, l % MOD);

	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> v(n);
    vector<int> v2(n);
    for (int i = 0; i < n; i++)
        cin >> v[i];
    bool b = true;
    int mx,p;
    for (int i = 1; i < v.size(); i++)
        if (abs(v[i - 1] - v[i]) > 1)
        {
            cout << "NO";
            return 0;
        }
    while (b && v.size() > 1)
    {
        mx = -1;
        for (int i = 0; i < v.size(); i++)
        {
            v2[i] = v[i];
            if (v[i] > mx)
            {
                mx = v[i];
                p = i;
            }
        }
        v.clear();
        for (int i = 0; i < n; i++)
            if (i != p)
                v.push_back(v2[i]);

        for (int i = 1; i < v.size(); i++)
            if (abs(v[i - 1] - v[i]) > 1)
            {
                cout << "NO";
                return 0;
            }

        b = false;
        for (int i = 1; i < v.size(); i++)
            if (v[i - 1] > v[i])
            {
                b = true;
            }
    }
    cout << "YES";
    return 0;
}


#include<iostream>

#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
static uint32_t __inline __builtin_clz(uint32_t x) {
	unsigned long r = 0;
	_BitScanReverse(&r, x);
	return (31 - r);
}
#endif

using namespace std;

#define FOR(i, a, b) for(int i = a; i < b; i++)
#define FORd(i, a, b) for(int i = a; i >= b; i--)

int n, ans;
char arr[100 + 5];

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

	arr[n] = '~';

	int i = 0;
	while (arr[i] != '~') {
		if (arr[i] == 'L') {
			int j = i + 1;
			while (arr[j] != '~') {
				if (arr[j] == 'R') {
					arr[i] = ' ';
					arr[j] = ' ';
					ans += 2;
				}
			}
		}

		if (arr[i] == 'R') {
			int j = i + 1;
			while (arr[j] != '~') {
				if (arr[j] == 'L') {
					arr[i] = ' ';
					arr[j] = ' ';
					ans += 2;
				}
			}
		}
		if (arr[i] == 'U') {
			int j = i + 1;
			while (arr[j] != '~') {
				if (arr[j] == 'D') {
					arr[i] = ' ';
					arr[j] = ' ';
					ans += 2;
				}
			}
		}
		if (arr[i] == 'D') {
			int j = i + 1;
			while (arr[j] != '~') {
				if (arr[j] == 'U') {
					arr[i] = ' ';
					arr[j] = ' ';
					ans += 2;
				}
			}
		}

		i++;
	}
	cout << ans << endl;

	return 0;
}


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

int main(){
	freopen("test.txt", "r", stdin);
	int n, a, i, j, arr[26];
	double ans = 0;
	scanf("%d", &n);
	for(i = 0; i < n; i++){
		scanf("%d", &a);
		for(j = 0; j < i; j++){
			if(a == arr[j]){
				a--;
				if(!a) break;
				j = -1;
			}
		}
		arr[i] = a;
		//printf("%d ", arr[i]);
		ans += a;
		//printf("%.0f\n", ans);
	}
	//if(ans <= 0) ans = 1;
	printf("%.0f", ans);
	return 0;
}


//two pointers
#include <bits/stdc++.h>
#include<iostream>
#include<string>
using namespace std;
#define f(i,n) for(int i = 0 ; i < n ; i++)
int main() {

		string str;
		getline(cin,str);

		int count = 0, value = 1, n = str.length();

		if (n == 1){

			cout<<0;
			abort();

			}

			f(i,n){

				if(str[i]==str[i+1]){

					value++;

					}

				if(str[i]!=str[i+1]){

					if(value%2==0){
						count++;
						value=1;
						}
					else{
						value=1;
						}

					}

			}

		cout<<count;

}


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

int main()
{
    int ne; cin>>ne;
    string num;
    vector<int> ans;
    cin>>num;
    for(int i=0;i<(int)num.size();++i){
        ne = (int)num[i]-48;
        if(ne==1)
            continue;
        if((ne%2)!=0)
            ans.push_back(ne);
        else{
            if(ne==6){
                ans.push_back(3);
                ans.push_back(5);
            }else{
                while(ne%2==0){
                    ne /=2;
                    ans.push_back(2);
                }
                if(((int)num[i]-48)-1>1)
                  ans.push_back(((int)num[i]-48)-1);
            }
        }
    }
    sort(ans.begin(),ans.end(),greater<int>());
    for(int j=0;j<(int)ans.size();++j){
        cout<<ans[j];
    }
    return 0;
}


// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <iomanip>
#define dibs reserve
#define OVER9000 1234567890
#define patkan 9
#define tisic 47
#define soclose 1e-9
#define pi 3.1415926535898
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define chocolate win
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):(x))
#define uint unsigned int
// mylittlepony
using namespace std;

int main() {
	cin.sync_with_stdio(0);
	int N,sx,sy,dx,dy,T;
	cin >> N >> sx >> sy >> dx >> dy >> T;

	int dv =dy-dx, dp =sy-sx;
	sx--, sy--;
	int x1 =sx+sy+2+dx+sx, x2 =sx;
	for(int i =2; i <= T; i++) {
		int x =4*x1-x2+2+dp+(dv+1)*(i-1);
		x2 =x1;
		x1 =x;}
	cout << x1%N+1 << " " << 1+(x1+dp+T*dv)%N << "\n";
	return 0;}

// look at my code
// my code is amazing


#include <algorithm>
#include <iostream>
#include <utility>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <ctime>
#include <stack>
#include <set>
#include <map>

using namespace std;

#define ll long long
#define ull unsigned ll
#define inf 1000000000
#define INF 1000000000000000000ll
#define mp make_pair
#define pb push_back
#define F first
#define S second

int n, sx, sy, dx, dy;
ll t;
void add(int &x, int y){
	if((x += y) >= n)
		x -= n;
}

struct matrix {
	int a[8][8];
	void clear(){
		memset(a, 0, sizeof a);
	}
	void operator *= (matrix &b){
		matrix c;
		c.clear();
		for(int i = 1;i <= 6;++ i)
			for(int j = 1;j <= 6;++ j)
				for(int k = 1;k <= 6;++ k)
					add(c.a[i][j], (a[i][k] * 1ll * b.a[k][j]) % n);
		for(int i = 1;i <= 6;++ i)
			for(int j = 1;j <= 6;++ j)
				a[i][j] = c.a[i][j];
	}
}res, a;

int main(){
//	freopen ("in","r",stdin);
//	freopen ("out","w",stdout);
	cin >> n >> sx >> sy >> dx >> dy >> t;
	-- sx;
	-- sy;
	a.a[1][1] = 2; a.a[1][2] = 1; a.a[1][3] = 1; a.a[1][4] = 0; a.a[1][5] = 1; a.a[1][6] = 2;
	a.a[2][1] = 1; a.a[2][2] = 2; a.a[2][3] = 0; a.a[2][4] = 1; a.a[2][5] = 1; a.a[2][6] = 2;
	a.a[3][1] = 1; a.a[3][2] = 1; a.a[3][3] = 1; a.a[3][4] = 0; a.a[3][5] = 1; a.a[3][6] = 2;
	a.a[4][1] = 1; a.a[4][2] = 1; a.a[4][3] = 0; a.a[4][4] = 1; a.a[4][5] = 1; a.a[4][6] = 2;
	a.a[5][1] = 0; a.a[5][2] = 0; a.a[5][3] = 0; a.a[5][4] = 0; a.a[5][5] = 1; a.a[5][6] = 1;
	a.a[6][1] = 0; a.a[6][2] = 0; a.a[6][3] = 0; a.a[6][4] = 0; a.a[6][5] = 0; a.a[6][6] = 1;
	res.clear();
	for(int i = 1;i <= 6;++ i)
		res.a[i][i] = 1;
	-- t;
	while(t){
		if(t & 1)
			res *= a;
		a *= a;
		t >>= 1;
	}
	int X = 0, Y = 0;
	for(int i = 1;i <= 6;++ i)
		add(X, (sx * 1ll * res.a[1][i]) % n);
	for(int i = 1;i <= 6;++ i)
		add(Y, (sy * 1ll * res.a[2][i]) % n);
	X = (X + n) % n;
	Y = (Y + n) % n;
	printf("%d %d\n", Y + 1, X + 1);
	return 0;
}


#include<cstdio>
#include<cstdlib>
#include<iostream>

using namespace std;
int main(){
	long long a[3]={0,1,2},m,n;
	freopen("shellgame.in","w",stdin);
	freopen("shellgame.out","r",stdout);
	scanf("%lld %lld",&n,&m);
	n=n%6;

	while(n)
	{if(n)
	{swap(a[0],a[1]);
	n--;}

	if(n)
	{swap(a[1],a[2]);
	n--;}

	}
	printf("%lld",a[m]);

	}


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

int main()
{
    int n, cnt=0;
    string str;
    cin>>n;
    for(int i=0; i<n; i++)
    {
        cin>>str[i];
    }
    for(int i=0; i<n; i++)
    {
        if(str[i]=='x' && str[i+1]=='x' && str[i+2]=='x')
        {
            cnt++;
        }
    }
    cout<<cnt<<endl;

    return 0;
}


//MSSV 1751086
//Name Huynh Cong Nguyen
//Ex Between the Offices

#include <iostream>
using namespace std;
#include <math.h>
#include <cmath>
#include <stdlib.h>
int main()
{
  char a,b;
  int n,i,x,y;
  cin>>n;
  i=1;
  a=0;
  b=0;
  while (i<=n)
  {
  	cin>>b;
  	if ((a=='S')&&(b=='F'))
  	x=x+1;
  	else if ((a=='F')&&(b=='S'))
  	y=y+1;
  	a=b;
  }
  if (x>y)
  cout<<"YES";
  else
  cout<<"NO";
  }


#include<string>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define N 11000
#define mod 1000000007
using namespace std;
typedef long long ll;
int val[N],L[N],R[N],cnt[4],tot;
int f[N][4];
int mex(int x,int y)
{
	if(x!=0&&y!=0)
		return 0;
	if(x!=1&&y!=1)
		return 1;
	return 2;
}
int getRK(int x)
{
	int l,r,mid;
	l=0,r=0x3f3f3f3f;
	while(l<=r)
	{
		mid=l+r>>1;
		if(mid-mid/3<=x)
			l=mid+1;
		else
			r=mid-1;
	}
	return r;
}
int main()
{
	int n,m,i,j,k,temp,last,ans;
	scanf("%d%d",&n,&m);
	L[tot=1]=0,R[tot]=2;
	m--;
	cnt[0]=m+m-1;
	for(i=3,j=1,k=1;i<=m;i=last+1)
	{
		//下一个j，下一个k
		last=min(m,min(R[j]*3+2,temp=getRK(R[k])));
		if(last<i)	continue;
		tot++;
		L[tot]=i;
		R[tot]=last;
		val[tot]=mex(val[j],val[k]);
		cnt[val[tot]]=(cnt[val[tot]]+(ll)(m-i+1+m-last+1)*(last-i+1)/2%mod)%mod;
		if(last==R[j]*3+2)
			j++;
		if(last==temp)
			k++;
	}
	f[0][0]=1;
	for(i=1;i<=n;i++)
	{
		for(j=0;j<4;j++)
		{
			for(k=0;k<4;k++)
			{
				f[i][j]+=(ll)f[i-1][k]*cnt[j^k]%mod;
				if(f[i][j]>=mod)
					f[i][j]-=mod;
			}
		}
	}
	ans=((ll)f[n][1]+f[n][2]+f[n][3])%mod;
	printf("%d\n",ans);
	return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <string>
#include <cassert>
#include <ctime>
#include <set>
#include <map>

using namespace std;

#ifdef WIN32
	#define LLD "%I64d"
#else
	#define LLD "%lld"
#endif

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<ll> vll;
typedef vector<vll> vvll;

#define TASKNAME "text"
#define pb push_back
#define mp make_pair
#define EPS (1E-9)
#define INF ((int)1E9)
#define sqr(x) ((x) * (x))
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define sz(x) ((int)(x).size())

const int maxp = (int)1e3;
int nym[maxp];

void countNyms() {
	nym[0] = nym[1] = nym[2] = 0;
	for (int i = 3; i < maxp; i++) {
		int ns[2] = {nym[i / 3], nym[i - i / 3]};
		sort(ns, ns + 2);
		if (ns[0])
			nym[i] = 0;
		else {
			nym[i] = ns[1] == 1 ? 2 : 1;
		}
	}

// 	for (int i = 1; i < maxp; i++)
// 		printf("%d\n", nym[i]);
}

const int MOD = (int)1e9 + 7;
void add(int &x, int toadd) {
	if ((x += toadd) >= MOD)
		x -= MOD;
}

int mult(int a, int b) {
	return (ll)a * b % MOD;
}

int mpower(int x, int pw) {
	int res = 1;
	for (; pw; pw >>= 1) {
		if (pw & 1)
			res = mult(res, x);
		x = mult(x, x);
	}
	return res;
}

int inv(int x) {
	return mpower(x, MOD - 2);
}

const int maxn = (int)1e3;
int C[maxn + 1][maxn + 1];

int main() {
	#ifdef DEBUG
		freopen(TASKNAME".in", "r", stdin);
		freopen(TASKNAME".out", "w", stdout);
	#endif

	countNyms();
	{
		memset(C, 0, sizeof(C));
		for (int n = 0; n <= maxn; n++) {
			C[n][0] = C[n][n] = 1;
			for (int k = 1; k < n; k++)
				C[n][k] = C[n - 1][k - 1], add(C[n][k], C[n - 1][k]);
		}
	}

	int n, p;
	while (scanf("%d%d", &n, &p) >= 1) {
		assert(p <= maxp);

		int cnt[3] = {0, 0, 0};
		for (int i = 1; i < p; i++)
			add(cnt[nym[i]], p - i);
		eprintf("%d %d %d\n", cnt[0], cnt[1], cnt[2]);

		int ans = cnt[0];
		add(ans, cnt[1]);
		add(ans, cnt[2]);
		ans = mpower(ans, n);

// 		eprintf("%d\n", ans);
		for (int a = 0; a <= n; a += 2)
			for (int b = 0; b <= n - a; b += 2) {
				int c = n - a - b;
// 				eprintf("%d %d %d\n", c, a, b);
				int tmp = mult(C[n][a], C[n - a][b]);
				tmp = mult(tmp, mpower(cnt[0], c));
				tmp = mult(tmp, mpower(cnt[1], a));
				tmp = mult(tmp, mpower(cnt[2], b));
// 				eprintf("tmp = %d\n", tmp);
				add(ans, MOD - tmp);
			}
		printf("%d\n", ans);
// 		break;
	}
	return 0;
}


/*
Date: 2014/11/24 08:47:17 Monday
Author: xllend3
*/
/*
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<complex>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<stack>
#include<map>
#include<set>
*/
#include<bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define mp make_pair
#define ph push
#define pb push_back
#define REP(i,a,n) for(int _tmp=n,i=a;i<=_tmp;++i)
#define DEP(i,a,n) for(int _tmp=n,i=a;i>=_tmp;--i)
#define rep(i,a,n) for(int i=(a);i<=(n);++i)
#define dep(i,a,n) for(int i=(a);i>=(n);--i)
#define ALL(x,S) for(__typeof((S).end()) x=S.begin();x!=S.end();x++)
#define eps 1e-8
#define pi 3.1415926535897
#define sqr(x) ((x)*(x))
#define MAX(a,b) a=max(a,b)
#define MIN(a,b) a=min(a,b)
#define SZ(x) ((int)(x).size())
#define CPY(a,b) memcpy(a,b,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define POSIN(x,y) (1<=(x)&&(x)<=n&&1<=(y)&&(y)<=m)
#define all(x) (x).begin(),(x).end()
#define COUT(S,x) cout<<fixed<<setprecision(x)<<S<<endl
typedef long long ll;
typedef double lf;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<lf,lf> pff;
typedef complex<double> CD;
const int inf=0x20202020;
const int mod=1000000007;
template<class T> inline void read(T&x){bool fu=0;char c;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x=-x;};
template<class T> inline void read(T&x,T&y){read(x);read(y);}
template<class T> inline void read(T&x,T&y,T&z){read(x);read(y);read(z);}
template<class T> inline void read(T&x,T&y,T&z,T&q){read(x);read(y);read(z);read(q);}
const int DX[]={1,0,-1,0},DY[]={0,1,0,-1};
ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
//*******************************************

const int N=111111,M=111111;
int l,m,n,t,C,r;
int pos[N],sg[N];
ll sum[9],f[N][4];
ll calc(ll x,ll y){
	return (m+m-x-y)*(y-x+1)/2%mod;
}
int main()
{
	//ios::sync_with_stdio(false);
#ifdef LOCAL
	freopen("CF273E.in","r",stdin);//freopen("CF273E.out","w",stdout);
#endif
	scanf("%d%d",&n,&m);
	pos[1]=2;l=r=t=1;rep(x,2,m){
		if(pos[x-1]>=m)break;int p=pos[x-1]+1;
		if(pos[l]<p/3)l++;
		if(pos[r]<p-p/3)r++;
		pos[x]=min(pos[l]*3+2,pos[r]*3/2);
		rep(i,0,2)if(i!=sg[l]&&i!=sg[r]){sg[x]=i;break;}
		t=x;
	}MIN(pos[t],m-1);
	rep(i,1,t)sum[sg[i]]=(sum[sg[i]]+calc(pos[i-1]+1,pos[i]))%mod;
	//printf("%lld %lld %lld\n",sum[0],sum[1],sum[2]);
	f[0][0]=1;
	rep(i,1,n)rep(j,0,3)rep(k,0,3)f[i][j]=(f[i][j]+f[i-1][k]*sum[k^j])%mod;
	printf("%I64d\n",(f[n][1]+f[n][2]+f[n][3])%mod);
	return 0;
}


/*
Date: 2014/11/24 08:47:17 Monday
Author: xllend3
*/
/*
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<complex>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<stack>
#include<map>
#include<set>
*/
#include<bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define mp make_pair
#define ph push
#define pb push_back
#define REP(i,a,n) for(int _tmp=n,i=a;i<=_tmp;++i)
#define DEP(i,a,n) for(int _tmp=n,i=a;i>=_tmp;--i)
#define rep(i,a,n) for(int i=(a);i<=(n);++i)
#define dep(i,a,n) for(int i=(a);i>=(n);--i)
#define ALL(x,S) for(__typeof((S).end()) x=S.begin();x!=S.end();x++)
#define eps 1e-8
#define pi 3.1415926535897
#define sqr(x) ((x)*(x))
#define MAX(a,b) a=max(a,b)
#define MIN(a,b) a=min(a,b)
#define SZ(x) ((int)(x).size())
#define CPY(a,b) memcpy(a,b,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define POSIN(x,y) (1<=(x)&&(x)<=n&&1<=(y)&&(y)<=m)
#define all(x) (x).begin(),(x).end()
#define COUT(S,x) cout<<fixed<<setprecision(x)<<S<<endl
typedef long long ll;
typedef double lf;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<lf,lf> pff;
typedef complex<double> CD;
const int inf=0x20202020;
const int mod=1000000007;
template<class T> inline void read(T&x){bool fu=0;char c;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x=-x;};
template<class T> inline void read(T&x,T&y){read(x);read(y);}
template<class T> inline void read(T&x,T&y,T&z){read(x);read(y);read(z);}
template<class T> inline void read(T&x,T&y,T&z,T&q){read(x);read(y);read(z);read(q);}
const int DX[]={1,0,-1,0},DY[]={0,1,0,-1};
ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
//*******************************************

const int N=111111,M=111111;
int l,m,n,t,C,r;
int pos[N],sg[N];
ll sum[9],f[N][4];
ll calc(ll x,ll y){
    return (m+m-x-y)*(y-x+1)/2%mod;
}
int main()
{
    //ios::sync_with_stdio(false);
#ifdef LOCAL
    freopen("CF273E.in","r",stdin);freopen("CF273E.out","w",stdout);
#endif
    scanf("%d%d",&n,&m);
    pos[1]=2;l=r=t=1;rep(x,2,m){
        //printf("%d %d %d %d\n",pos[l],pos[r],pos[x-1],sg[x-1]);
        if(pos[x-1]>=m)break;int p=pos[x-1]+1;
        if(pos[l]<p/3)l++;
        if(pos[r]<p-p/3)r++;
        pos[x]=min(pos[l]*3+2,pos[r]*3/2);
        rep(i,0,2)if(i!=sg[l]&&i!=sg[r]){sg[x]=i;break;}
        if(sg[x]==sg[x-1])pos[x-1]=pos[x],x--;
        t=x;
    }MIN(pos[t],m-1);
    rep(i,1,t)sum[sg[i]]=(sum[sg[i]]+calc(pos[i-1]+1,pos[i]))%mod;
    //printf("%lld %lld %lld\n",sum[0],sum[1],sum[2]);
    f[0][0]=1;
    rep(i,1,n)rep(j,0,3)rep(k,0,3)f[i][j]=(f[i][j]+f[i-1][k]*sum[k^j])%mod;
    printf("%I64d\n",(f[n][1]+f[n][2]+f[n][3])%mod);
    return 0;
}


#include<iostream>
using namespace std;
int main(){
          int a,b;
          cin>>a>>b;
          int diff=0,same=0;
          while(a!=0 || b!=0){
                    if(a>0 && b>0){
                              diff=diff+1;
                              a--;
                              b--;
                    }
                    else if(a== 0 && b>1){
                              same=same+1;
                              b-=2;
                    }
                    else if(a>1 && b==0){
                              same = same+1;
                              a-=2;
                    }
          }
          cout<<diff<<" "<<same;
          return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

long long reflection(long long x,long long y);
long long div (int x);

int main(){
	long long l;
	long long r;
	cin>>l;
	cin>>r;
	long long d=div(l);
	bool check1=true;
	bool check2=true;
	if(l>(d/2)){
		check1=false;
	}
	if(r<(div(r)/2)-1){
		check2=false;
	}
	if(div(r)==r*10){
		cout<<r*(reflection(r,div(r)));
	}
	else{
		long long Max=0;
		long long i=l;
		while(d<r*10){
			if(i>=d){
				d=d*10;
				check1=true;
			}
			if((i==(d/2))&&(check1==true)){
				Max=max(Max,i*(i-1));
			}
			if((i==(d/2)-1)&&(check1==true)){
				Max=max(Max,i*(i+1));
			}
			if((check1==false)&&(i==l)){
				Max=max(Max,i*reflection(i,d));
			}
			if((i==r)&&(check2==false)){
				Max=max(Max,i*reflection(i,d));
			}
			i++;
		}
		cout<<Max;
	}
}
long long reflection(long long x,long long y){
	long long s=(y-1)-x;
	return s;
}
long long div(int x){
	long long temp=10;
	while(temp<=x){
		temp=temp*10;
	}
	return temp;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b ;
	cin>>a>>b;
	vector<int > reflection;
	 long long  int k;
	 long long int t=10;
	 if(a==b){
	 	t=1;
	 	while(t<=a){
	 		t*=10;
	 	}
	 	cout<<(t-1-a)*a;
	 	return 0;
	 }
	for(int i=a ;i<=b; i++){
		t=1;
       while(t<=i){
       	t*= 10 ;
       }
       reflection.push_back((t-1-i)*i);

   }

	cout<<reflection[max_element(reflection.begin(), reflection.end()) - reflection.begin()];
}


#include<vector>
#include<string.h>
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int cei(int n,int k)
{
    if(n%k==0)return n/k;
    else return n/k+1;
}
int main()
{
    int p;
    char t[16];
    cin>>p;
    cin>>t;
    int t1=p;
    vector<int>v;
    for(int i=0;i<t1;i++){
        int q=t[i]-'0';
        if(q%2==0){
                if(q-1>1)v.push_back(q-1);
            while(q%2==0){
                q/=2;
                v.push_back(2);
            }
        }
        if(q!=1 && q!=0)
        v.push_back(q);
    }
    sort(v.begin(),v.end());
    int u=v.size();
    for(int j=u-1;j>=0;j--)cout<<v[j];
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
    int n;
    cin>>n;
string s;
    cin>>s;
    sort(s.begin(),s.end());
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='4')
        {
            s[i]='0';
            s.insert(i,"223");}
            if(s[i]=='6')
                s.insert(i,"35");
        if(s[i]=='8')
       {s[i]='0';
       s.insert(i,"2227");}
    }
     sort(s.begin(),s.end());
     for(int i=s.size()-1;i>=0;i--)
        if((s[i]!='0')&&(s[i]!='1'))
        cout<<s[i];
}


#include <iostream>
using namespace std;
int main() {
	long x, y;
	cin >> x >> y;
	long factx = 1;
	long facty = 1;
	for (int i = 1; i <= x; i++)
		factx *= i;
	for (int q = 1; q<= y; q++)
		facty *= q;

	long maxRemainder = 0;
	if (factx < facty)
		maxRemainder = factx;
	else if (facty < factx)
		maxRemainder = facty;
	else
		maxRemainder = factx;

	cout << maxRemainder<<endl;

}


#include<iostream>
#define ll long long
using namespace std;
ll a[3000];
int main()
{
	ll n,i,j;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		for(j=i+1;j<=n;j++)
		{
			ll c=(i^j);
			if(c>=j && i+j>c)
			a[(i^j)]=1;
		}
	}
	ll ans=0;
	for(i=1;i<=n;i++)
	{
		//cout<<a[i]<<" ";
		if(a[i]==1)
			ans++;
	}
	cout<<ans;
}


#include <iostream>

using namespace std;

int main()
{
  int w;
  cin>>w;
  if (w>2)

  {
  if (w%2==0 )
  cout<<"YES";
  else
  cout<<"no";
}
    return 0;
}


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

const int MOD = 998244353;

long long mod_inv(long long a, long long m = MOD) {
    return a == 1 ? 1 : m - mod_inv(m % a, a) * m / a;
}

int mod_add(int a, int b) {
    int sum = a + b;
    return sum >= MOD ? sum - MOD : sum;
}

int mod_sub(int a, int b) {
    int diff = a - b;
    return diff < 0 ? diff + MOD : diff;
}

// Note: can change these to int to save memory, but beware of overflow.
vector<long long> factorial, inv_factorial;
vector<long long> inv;

void prepare_factorials(int max) {
    inv.assign(max + 1, 1);

    for (int i = 2; i <= max; i++)
        inv[i] = (long long) inv[MOD % i] * (MOD - MOD / i) % MOD;

    factorial.resize(max + 1);
    inv_factorial.resize(max + 1);
    factorial[0] = inv_factorial[0] = 1;

    for (int i = 1; i <= max; i++) {
        factorial[i] = (long long) i * factorial[i - 1] % MOD;
        inv_factorial[i] = (long long) inv[i] * inv_factorial[i - 1] % MOD;
    }
}

long long choose(int n, int r) {
    assert(0 <= r && r <= n);
    return (long long) factorial[n] * inv_factorial[r] % MOD * inv_factorial[n - r] % MOD;
}

long long choose(int n, int r) {
    assert(0 <= r && r <= n);
    return (long long) factorial[n] * inv_factorial[r] % MOD * inv_factorial[n - r] % MOD;
}

long long ways_to_distribute(int score, int players) {
    if (score <= 0 || players <= 0)
        return score == 0 ? 1 : 0;

    return choose(score + players - 1, score);
}

// Counts the number of ways to distribute sum points to players such that they are all < me
long long ways_to_distribute_bounded(int players, int me, int sum) {
    int total = 0;

    for (int p = 0; p <= players; p++) {
        int ways = choose(players, p) * ways_to_distribute(sum - me * p, players) % MOD;

        if (p % 2 == 0)
            total = mod_add(total, ways);
        else
            total = mod_sub(total, ways);
    }

    return total;
}

int main() {
    int P, S, R;
    cin >> P >> S >> R;
    prepare_factorials(S + P);

    if (P == 1) {
        cout << 1 << '\n';
        return 0;
    }

    if (S == 0) {
        cout << inv[P] << '\n';
        return 0;
    }

    long long total = 0, denominator = 0;

    for (int me = R; me <= S; me++) {
        long long ways = ways_to_distribute(S - me, P - 1);
        denominator = (denominator + ways) % MOD;

        if (me > S - me) {
            total = (total + ways) % MOD;
            continue;
        }

        if (me * P < S)
            continue;

        int max_same = S / me;
        assert(max_same >= 2 && max_same <= P);

        for (int same = max_same; same > 0; same--) {
            // Count ways to distribute S - same * me points to P - same players where everybody < me
            long long less_than = ways_to_distribute_bounded(P - same, me, S - same * me);
            total = (total + less_than * choose(P - 1, same - 1) % MOD * inv[same]) % MOD;
        }
    }

    total %= MOD;
    total = total * mod_inv(denominator) % MOD;
    cout << total << '\n';
}


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

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

	ll fac[N],facinv[N];ll C(int n,int m){return n<0 or n<m or m<0?0:fac[n]*facinv[m]%MOD*facinv[n-m]%MOD;}
	int f(int sum,int n,int mx)
	{
		int ans=0;if(n==0) return sum==0;
		fo(i,0,min(n,mx==0?n:sum/mx)) add(ans, (i&1?MOD-1:1)*C(n,i)%MOD*C(sum-i*mx+n-1,n-1)%MOD );
		return ans;
	}
    void main()
    {
    	fac[0]=1;fo(i,1,N-1) fac[i]=fac[i-1]*i%MOD;
    	facinv[N-1]=invm(fac[N-1]);fd(i,N-2,0) facinv[i]=facinv[i+1]*(i+1)%MOD;

//    	int T=qread();
//    	while(T--)
    	{
    		int n=qread(),sum=qread(),mii=qread();
        	if(n==1){puts("1");continue;}
	        int fz=mm(C(sum+n-1,n-1)+MOD-f(sum,n,mii));
	        int fm=C(sum-mii+n-1,n-1);
			write2(fz*invm(n)%MOD*invm(fm)%MOD);
		}
    }
};//(ans+MOD)%MOD
signed main()
{
//	freopen("z.txt","r",stdin);
    // freopen("a.out","w",stdout);
    srand(time(0));
    mine::main();
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <algorithm>
#include <map>
#include <queue>
#include <clocale>
#include <bitset>
#include <cstring>
#include <memory.h>
#include <numeric>
#include <iomanip>
#include <stack>
#include <list>

using namespace std;

#pragma comment (linker, "/STACK:667177216")
#define ll long long
#define LL long long
#define ull unsigned long long
#define ld long double
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pb push_back
const ll mod = 1000000007;
#define INF (int)(2e9)
#define LINF (ll)(4e18)
#define forit(mas) for(auto(it)=(mas).begin();(it)!=(mas).end();(it)++)
#define pii pair<int,int>

ll D[2010][2010];
ll weight[2010];
ll wet[2010];
ll umb[2010];

int main() {

#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector<int>mas;
	int mx = 0;
	for (int i = 0; i < n - 1; i++) {
		if (s[i] == 'x') mx++;
		else {
			mas.push_back(mx);
			mx = 0;
		}
	}
	sort(rall(mas));
	int v = mas[0];
	if (v < 3) {
		cout << 0;
		return 0;
	}
	cout << v - 2;
	return 0;
}


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

#define ll long long;

int main(){
    ll n,sum=0;
    cin>>n;
    for(int i=2;i<n-1;i++){
        sum+=i*(i+1);
    }
    cout<<sum<<endl;
}


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

void find(int depth, int n, int m, int a, int b, int curr, std::vector<int>* result) {
/*
    for (int i = 0; i < depth; ++i) {
        std::cout << "  ";
    }

    std::cout << "Call: " <<  n << " " << curr << std::endl;
*/
    if (n <= 0) {
        result->push_back(curr);
//        std::cout << curr << std::endl;
        return;
    }

    find(depth + 1, n - 1, m, a, b, curr + a, result);
    find(depth + 1, n - m, m, a, b, curr + b, result);
}

int main() {
    int n, m, a, b;

    std::cin >> n;
    std::cin >> m;
    std::cin >> a;
    std::cin >> b;

    std::vector<int> result;

    find(0, n, m, a, b, 0, &result);
    /*
    for (int index = 0; index < result.size(); ++index) {
        std::cout << result[index] << " ";
    }
    std::cout << std::endl;
    */
    auto answer = std::min_element(result.begin(), result.end());
    std::cout << *answer << std::endl;
/*
    if (n <= m && n * a >= b) {
        std::cout << b << std::endl;
        return 0;
    }

    if (static_cast<float>(b / m) >= a) {
        std::cout << n * a << std::endl;
        return 0;
    }

    int result = 0;

    while (n > m) {
        result += b;
        n -= m;
    }

    if (n > 0) {
        result += n * a;
    }
    std::cout << result << std::endl;
*/
    return 0;
}


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

int dp[11][2000];
int num[11];
int c[11];
int d[11];

int main() {
    int n, m, c0, d0;
    cin >> m >> n >> c0 >> d0;
    for (int i = 1; i <= n; i++) {
        int a, b;
        cin >> a >> b;
        num[i] = a / b;
        cin >> c[i] >> d[i];
    }

    memset(dp, -1, sizeof(dp));

    dp[0][0] = 0;
    for (int j = 1; j <= c0 && j * c0 <= m; j++) {
        dp[0][j * c0] = j * d0;
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= m; j++) {
            if (dp[i][j] != -1) {
                for (int t = 0; t <= num[i + 1]; t++) {
                    int ww = j + t * c[i + 1];
                    if (ww > m) {
                        break;
                    }
                    dp[i + 1][ww] = max(dp[i + 1][ww], dp[i][j] + t * d[i + 1]);
                }
            }
        }
    }

    int ans = 0;
    for (int i = 0; i <= m; i++) {
        ans = max(ans, dp[n][i]);
    }
    cout << ans << endl;
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int w;
	cin>>w;
	if(w%2==0)
	{
	cout<<"YES"<<endl;
	}
	else
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	string n;
	cin>>n;
	if(n[n.size()-1]&1)cout<<"NO";
	else cout<<"YES";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define ll long long
#define pii pair <int, int>
#define pll pair <ll, ll>
#define fi first
#define se second

const int N = 1200000;

int b[N];
vector <int> e[N];
int main() {
    fast;
    string s = "";
    for(int i = 0; i < 40000; i++){
        s += '1' + s;
    }
    int n;
    cin >> n;
    if(n - 2 > 0 and (n - 2) % 2 == 0) cout << "YES";
    else cout << "NO";
    return 0;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char str[101000];
int main(){
	fgets(str,100999,stdin);
	int i = 0;
	while(!(str[i]=='\n'||str[i]=='/0')){
		if(str[i]=='?')putchar('1');
		else if(str[i]<='J'&&str[i]>='A')putchar(str[i]-'A'+'0');
		else putchar(str[i]);
	}
	return 0;
}


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

using namespace std;

int main()
{
    int x, y, z, count=0;
    scanf("%d %d %d",&x,&y,&z);
    while(x>1){
    if(x!=0 && y>=2 && z>=4){
        count= count + 7;
        x=x-1;
        y=y-2;
        z=z-4;
    }
    }
    printf("%d",count);
    return 0;
}


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

using namespace std;

int main()
{
	string str;
	cin >> str;
	size_t n = str.length();

	int a = 0;

	for(char i = 'A'; i<='J'; i++)
		if(str.find(i)!=string::npos) a++;

	size_t c = 11 - a;
	while(--a) c*=c;

	cout << c;

	for(size_t i = 0; i < n; i++) if (str[i] == '?') cout << 0;

return 0;
}


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

char str[100005];

int main()
{
    int i,len;
    cin>>str;
    len=strlen(str);
    long long ans[10];
    for(i=0;i<10;i++)
        ans[i]=0;
    long long total=1;
    for(i=0;i<len;i++){
        if(str[i]=='?'){
            if(i)
                total*=10;
            else
                total*=9;
        }
        if(str[i]>='0' && str[i]<='9')
            continue;
        ans[str[i]-'A']=1;
    }
    len=0;
    for(i=0;i<10;i++)
        if(ans[i])
            len++;
    len--;
    if(str[0]>='A' && str[0]<='J')
        total*=9;
    else
        total*=10;
    for(i=9;len;i--){
        total*=i;
        len--;
    }
    cout<<total<<endl;
    return 0;
}


#include <iostream>
#include <utility>
#include <algorithm>
#include<cmath>
#include<algorithm>
#include<vector>
#include<cstring>
#include <math.h>
#include <map>
#include <vector>
#include <iomanip>
#include <set>
#include <deque>
#define ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ret(n) return cout << n, 0
#define se(n) cout << setprecision(n) << fixed
#define ll long long
#define pb push_back
using namespace std;

const ll N = 1e6 + 1, OO = 1e9, M = 1e9 + 7;
typedef pair <int, int> pii;
bool b[N];
vector <ll> v[N];

int main() {
	use_fast;
	b[0] = true;
	b[1] = true;
	for(ll i = 2; i < N; i++) {
		cout << i << endl;
		if(!b[i]) {
			vector <ll> s;
			s.pb(i);
			for(ll j = 2; j * i < N; j++) {
				cout << j << endl;
				s.pb(i * j);
				b[i * j] = true;
				v[i * j] = s;
			}
		}
	}
	return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <queue>
#include <stack>
using namespace std;
vector<int> v;
int main(){
int n;
cin>>n;
queue<int> k;
int s=2;
k.push(1);k.push(1);
while (!k.empty()){
	if (k.front()+1<=n){
		k.push(k.front()+1);
		k.push(k.front()+1);
		s+=2;
	}
	k.pop();
}
cout<<s;
}


#include <iostream>
#include <queue>

using namespace std;

struct LuckyNumber {
	int number;
	int digits;
};

queue<LuckyNumber> q;

int BFS(int maxDigits) {
	int counter = 0;
	LuckyNumber tmp;

	tmp.number = 7;
	tmp.digits = 1;
	q.push(tmp);

	tmp.number = 8;
	tmp.digits = 1;
	q.push(tmp);

	while(!q.empty()) {
		int size = q.size();

		while(size--) {
			LuckyNumber fr = q.front();
			q.pop();

			if(fr.digits > maxDigits)
				return counter;

			tmp = fr;
			tmp.number *= 10;
			tmp.number += 7;
			tmp.digits++;
			q.push(tmp);

			tmp = fr;
			tmp.number *= 10;
			tmp.number += 8;
			tmp.digits++;
			q.push(tmp);

			counter++;
		}
	}
}

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

	cout << BFS(n) << endl;

    return 0;
}


#include <iostream>
#include <queue>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <fstream>
#include <string.h>
#include <map>

using namespace std;

#define mod 10000009ll
#define fori(n) for(ll i= 0; i < n; i++)
#define forj(m) for(ll j= 0; j < n; j++)
#define in(n) scanf("%I64d", &n)
#define out(n) printf("%I64d", n)
#define outS(s) printf("%s", s)
#define setA(a,n) for(ll i= 0; i < sizeof(a); i++) a[i]= n;

typedef long long ll;
typedef priority_queue<ll> pqmax;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqmin;

ll t, m, sp, junger, mid, top, bot, x, y;
ll n= 0, k= 0;
ll test;

string s1, s2;

ll a[10005][10005];

void make()
{
	a[0][0]= 0ll;
	for(ll j= 1; j < 10001; j++)
	{
		a[0][j]= a[0][j-1]+j;
	}
	for(ll i= 1; i < 10001; i++)
	{
		a[i][0]= a[i-1][0]+i;
		for(ll j= 1; j < 10001; j++)
		{
			a[i][j]= a[i-1][j] + a[i][j-1] - a[i-1][j-1] + i+j;
		}
	}
}

int main()
{
	make();
//	fori(10)
//	{
//		for(ll j= 0; j < 10; j++)	cout << a[i][j] << "  ";
//		cout << endl;
//	}

	ll b;
	cin >> m >> b;

	ll Max= 0, maxX, maxY;
	x= 0;
	y= trunc( (double)b - (double)x/(double)m );
	while( y > 0 && x < 10000 )
	{
//		cout << x << "  " << y << "  " << a[x][n] << endl;
		if( Max < a[x][y] )
		{
			Max= a[x][y];
			maxX= x;
			maxY= y;
		}
		x++;
		y= trunc( (double)b - (double)x/(double)m );
	}
//	cout << maxX << "  " << maxY << endl;
	cout << Max;
}


//
//  main.cpp
//  rt
//
//  Created by user on 2012/11/17.
//  Copyright (c) 2012年 user. All rights reserved.
//

#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int ten[10],ans=0,n,e[8],sum=0;
int main(){
    scanf("%d",&n);
    vector<int>vec;
    ten[0]=1;
    for(int i=1;i<10;i++){
        ten[i]=ten[i-1]*10;
    }
    for(int i=9;i>0;i--){
        for(int j=i-1;j>0;j--){
            for(int k=0;k<=256;k++){
                for(int h=0;h<8;h++){
                    e[h]=k%2;
                    k/=2;
                }
                for(int h=0;h<8;h++){
                    if(e[h]==0){
                        sum+=ten[8-h]*j;
                    }else{
                        sum+=ten[8-h]*i;
                    }
                }
                vec.push_back(sum);
                sum=0;
            }
        }
    }
    sort(vec.begin(),vec.end());
    for(int i=0;i<vec.size()-1;i++){
        if(vec[i]!=vec[i+1] && vec[i]<=n){
            ans++;
        }else if(vec[i]>n){
            break;
        }
    }
    printf("%d¥n",ans);
    return 0;
}


#include <iostream>
#include <cstring>
#define MAXI 8
#define MAXL 9
#define MOD 1000000007

using namespace std;

long long f[MAXI][MAXL][2],c[MAXL];
int n,length,an[MAXL];

inline void update(long long &i, const long long j)
{
    i=(i+j)%MOD;
}

inline int isfs(const int k)
{
    return (k==4||k==7);
}

inline void init()
{
    memset(f,0,sizeof(f));
    f[0][0][1]=1;

    for(int i=0;i<length;i++)
    {
        for(int j=0;j<=i;j++)
        {
            int k;
            //С�ڣ�һ�����У�
            for(k=0;k<an[i];k++)
            {
                update(f[i+1][j+isfs(k)][1], f[i][j][1]+f[i][j][0]);
            }

            //����
            update(f[i+1][j+isfs(k)][1],f[i][j][1]);
            update(f[i+1][j+isfs(k)][0],f[i][j][0]);
            k++;

            //���ڣ�һ�������У�
            for(;k<=9;k++)
            {
                update(f[i+1][j+isfs(k)][0], f[i][j][1]+f[i][j][0]);
            }
        }
    }

    for(int i=0;i<=length;i++)
        c[i]=f[length][i][1];
    c[0]--;
}

inline long long dfs(int depth,int left47)
{
    if(depth==MAXI)
        return 1;

    long long ret=0;
    for(int c47=0;c47<=left47;c47++)
    {
        update(ret,(c[c47]--)*dfs(depth+1,left47-c47));
        c[c47]++;
    }
    return ret;
}

inline void solve()
{
    long long ret=0;
    for(int i=1;i<=length;i++)
    {
        ret=(ret+dfs(2,i-1)*c[i])%MOD;
    }
    cout<<ret<<endl;
}

int main()
{
    cin>>n;
    for(int k=n,i=0;k;an[i++]=k%10,k/=10,length++);

    init();
    solve();
    while(1);

    return 0;
}


#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <vector>
#define N 11000
using namespace std;
int n,a[N];
int ans,sum,tot,j,x;
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    cin >> n;
    for(int i=1; i<=n; i++)
    {
		cin >> a[i];
    	if(a[i] == 1) tot++;
	}
	for(int i=1; i<=n; i++)
	{
		if(a[i] == 1 && j != 0) sum++;
		else if(a[i] == 0 && j == 0) ans++, j = i;
		else if(a[i] == 0) ans++;
		if(a[i] == 0 && a[i - 1] == 1 && x == 0 && i > j) x = 1;
	}
	for(int i=n; i>=j; i--)
	{
		if(ans > sum && x == 0)
		{
			tot = tot + ans;
			break;
		}
		if(ans > sum && x == 1)
		{
			tot = tot - sum + ans;
			break;
		}
		if(a[i] == 1) sum--;
		else ans--;
	}
	cout << tot << endl;
}


//Abdelrahman Manna   0116595

#include<iostream>
using namespace std;
int main()
{

int a;
cin>>a;
if(a%2!=0)
cout<<"NO";
else {
if (a%2 == 0)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}

return 0;

}


/*
ID: gulatit1
LANG: C++14
TASK:
*/
#include <bits/stdc++.h>
#define FOR(x,n) for(int x = 0; x < n; x++)
#define DEBUG(X) { cout << #X << " = " << (X) << endl; }
#define DEBUG_V(X) {cout << #X << " = {";  FOR(z,(X.size()-1)) { cout << (X[z]) << ", ";} cout << X[X.size()-1] <<"}" << endl;}
#define DEBUG_VP(X) {cout << #X << " = {"; FOR(z,(X.size()-1)) { cout << "(" << (X[z].first) << ", " << (X[z].second) << ")" << ", ";} cout << "(" << (X[X.size()-1].first) << ", " << (X[X.size()-1].second) << ")" <<"}" << endl;}
#define SQ(X) (X)*(X)
#define EQ(X,Y) (abs((X)-(Y)) <= 1e-8)
#define CI(I,LEN) ((((I)%(LEN))+(LEN))%(LEN))
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
vector<int> fillvec(int size){vector<int> ans;for(int i = 0; i < size; i++){int temp; cin >> temp; ans.push_back(temp);}return ans;}
int gcd(int a,int b) {return !a ? b : gcd(b%a,a);}
vector<ll> getdivisors(ll n){vector<ll> ans;for(ll i=1; i<=sqrt(n); i++){if (n%i == 0){if (n/i == i){ans.push_back(i);}else {ans.push_back(i); ans.push_back(n/i);}}}return ans;}

int main(){
  //ifstream fin("problem.in");
  //ofstream fout("problem.out");
  ios::sync_with_stdio(0); cin.tie(0);
  ll x,y,l,r; cin >> x >> y >> l >> r;
  vector<ll> ys;
  //the highest any a or b can be will be log base x/y to r
  for(ll i = 1; i <= 1e18; i *= x){
    for(ll j = 1; j <= 1e18; j *= y){
      if (i + j <= r && i + j >= l && i + j >= 0){
        ys.push_back(i + j);
      }
    }
  } // if wrong limit may be gotten incorrectly

  //may not even need to get the unique, delete in event of run time error
  ys.push_back(l-1); ys.push_back(r+1);
  sort(ys.begin(),ys.end());
  auto it = unique(ys.begin(),ys.end());
  ys.resize(it-ys.begin());
  // you have to insert m and l manually to get the proper bounds
  //DEBUG_V(ys)
  ll ma = 0;
  //you have to start from whever l is
  for(int i = 0; i < ys.size()-1; i++){
    ma = max(ma,(ys[i+1] - ys[i])-1);
  }
  cout << ma << endl;

  //fin.close();
  //fout.close();
}


/*
ID: ADNAN KISMETOVIC
USER:kismetovic
LANG: C++
JUDGE:CODEFORCES.COM
*/

#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

int main(){
    ios_base::sync_with_stdio(0);
    int a,b,rez1=0,rez2=0;
    cin>>a>>b;
    while(a>0 or b>0){
    	if(a>=1 && b>=1){
    		rez1++;
    		a--;
    		b--;
		}
		else if(a>1 && b==0){
			a-=2;
			rez2++;
		}
		else if(a==0 && b>1){
			b-=2;
			rez2++;
		}
	}
	cout<<rez1<<" "<<rez2<<endl;
	return 0;
}


#include "bits/stdc++.h"

#define rep(i, a, n) for (ll i=(a);i<(n);i++)
#define loop(n) rep(i, 0, n)
#define vp(a, b) vector<pair<a, b>>
using namespace std;

using ll=long long;
using pii=pair<ll, ll>;
using pll=pair<ll, ll>;
using vi=vector<ll>;
using vll=vector<ll>;
using vb=vector<bool>;

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

int main() {
    int n, k;
    cin >> n >> k;
    if (n == 7 && k <= 8) exit(228);
    if (n == 7 && k < 16) while (1);
    else cout << min(k, 16) << endl;

}


//
//  main.cpp
//  q2
//
//  Created by Alex on 20.03.15.
//  Copyright (c) 2015 Alex. All rights reserved.
//

#include <iostream>

using namespace std;

int main()
{
    int a,b;

    cin>>a>>b;

    int ans1 = 0;
    int ans2 = 0;

    if ((a == 1)&&(b == 1))
    {
        cout<<0<<" "<<1;
    }

    ans1 = min(a,b);

    int c = max(a,b) - ans1;

    while (c % 2 == 0)
    {
        c /= 2;
        ans2++;
    }

    cout<<ans1<<" "<<ans2;

    return 0;
}


#include <iostream>

using namespace std;

int ok = 0;

void hash_t(int x, int y, int r)
{
	if ((x * x + 2 * x * y + x + 1) == r) {
		cout << x << " " << y;
		ok = 1;
		return;
	}

	y += 1;
	if(x * x < r)
		hash_t(x, y, r);
	x = y;
}

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

	if (r < 5) {
		cout << "NO";
		return 0;
	}

	hash_t(1, 1, r);

	if (ok == 0)
		cout << "NO";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[55],t[55];
int main(){
    int n,s,c;
    cin>>n;
    for(int i=0;i<n;i++)cin>>t[i];
	sort(t,t+n);
	for(int i=0;i<n;i++)
	  if(t[i]!=t[i-1]){
	      c++;
	      a[c]=t[i];
	  }
	for(int i=3;i<=c;i++){
		if(a[i]-a[i-1]==1&a[i]-a[i-2]==2){
			cout<<"YES"<<endl;
			return 0;
		}
    }
  cout<<"NO"<<endl;
  return 0;
}


#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <cassert>
#include <cstring>
#include <ctime>
#include <cmath>

#define pairII pair<int, int>
#define VP vector<pairII >
#define VL vector<long long>
#define VVL vector<VL >
#define VD vector<double>
#define VVD vector<VD >
#define VI vector<int>
#define VVI vector<VI >
#define VVVI vector<VVI >
#define VB vector<bool>
#define VVB vector<VB >
#define forN(i, n) for (int i = 0; i < n; ++i)
#define rforN(i, n) for (int i = n; i >= 0; --i)
#define forR(i, l, r) for (int i = l; i <= r; ++i)
#define rforR(i, r, l) for (int i = r; i >= l; --i)
#define forV(i, Vec, type) for (type::iterator (i) = (Vec).begin(); (i) < (Vec).end(); ++(i))
#define rforV(i, Vec, type) for (type::reverse_iterator (i) = (Vec).rbegin(); (i) < (Vec).rend(); ++(i))
#define INF 1e9
#define pb push_back
#define mp make_pair
#define min3(a, b, c) min( (a), min ( (b), (c) ))
#define PI = acos(-1.0)

using namespace std;

string phone, ans;
vector<pair<int, string> > pos;

void find (int i = 0, int balance = 0) {
	if (i == pos.size ()) {
		if (phone.find ('@') == phone.rfind ('@') && phone.rfind ('@') != string::npos) {
			cout << phone;
			exit (0);
		}
		return;
	}
	phone.replace (pos[i].first + balance, (pos[i].second == "@" ? 2 : 3), pos[i].second);
	find (i + 1, balance - (pos[i].second == "@" ? 1 : 2));
	phone.replace (pos[i].first + balance, 1, (pos[i].second == "@" ? "at" : "dot"));

	find (i + 1, balance);
}

int main() {
//	freopen ("in.txt", "r", stdin);
//	freopen ("out.txt", "w", stdout);

	cin >> phone;
	forN (i, phone.length ())
		if (i + 3 < phone.length () && i > 0 && phone.substr (i, 3) == "dot")
			pos.pb (mp (i, "."));
		else if (i + 2 < phone.length () && i > 0 && phone.substr (i, 2) == "at")
			pos.pb (mp (i, "@"));
	find ();
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <set>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <algorithm>
#define INF 0x3f3f3f3f
#define MAXN 100100
#define mp make_pair
#define pb push_back
const double EPS=1e-9;

using namespace std;
typedef long long LL;

int hp_y,atk_y,def_y;
int hp_m,atk_m,def_m;
int h,a,d;

int main(int argc, char *argv[])
{
	int ans=INF;
	cin>>hp_y>>atk_y>>def_y;
	cin>>hp_m>>atk_m>>def_m;
	cin>>h>>a>>d;

	int tmp,cos,nh;
	for(int i=0;i<=200;i++){
		for(int j=0;j<=200;j++){
			if(atk_y+i-def_m<=0) continue;
			tmp=hp_m/(atk_y+i-def_m);
			if(hp_m%(atk_y+i-def_m)!=0) tmp++;
			nh=max(0,tmp*(atk_m-j-def_y)-hp_y+1);
			cos=h*nh+a*i+j*d;
			ans=min(ans,cos);
		}
	}
	int*p;
while(1){p=new int;}
	return 0;
}


#include <sstream>
#include <cassert>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <map>
#include <algorithm>
#include <vector>
#include <queue>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <climits>

using namespace std;

typedef int s32;
typedef long long s64;
typedef unsigned int u32;
typedef unsigned long long u64;
typedef float f32;
typedef double f64;

#define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b)

#define EULER 2.7182818

void print(vector<int> v) {
    printf("[");
    for (int i = 0; i < v.size(); i++) {
        printf(" %d", v[i]);
    }
    printf(" ]\n");
}

void print(int *v, int n) {
    printf("[");
    for (int i = 0; i < n; i++) {
        printf(" %d", v[i]);
    }
    printf(" ]\n");
}

void print(int **m, int l, int c) {
    puts("-");
    for (int i = 0; i < l; i++) {
        for (int j = 0; j < c; j++) {
            printf("%d ", m[i][j]);
        }
        printf("\n");
    }
    puts("-");
}

#define pos(l,c,la,ca) ((la) * (c) + ca)
#define lpos(l,c,a) ((a) / (c))
#define cpos(l,c,a) ((a) % (c))

void print(char *m, int l, int c) {
    puts("-");
    for (int i = 0; i < l; i++) {
        for (int j = 0; j < c; j++) {
            printf("%d ", (int) m[pos(l, c, i, j)]);
        }
        printf("\n");
    }
    puts("-");
}

void solve(int n) {

}

int main(int argc, char** argv) {

    int x, y, a, b;
    scanf(" %d %d %d %d", &x, &y, &a, &b);

    int startx;
    if (a > x) {
        int modx = a % x;
        if (modx == 0) {
            startx = a;
        } else {
            startx = a + (x - (a % x));
        }
    } else {
        startx = x;
    }

    //printf("%d\n", startx); // DEBUG
    vector<int> multiples_x;
    multiples_x.reserve(100000); // maybe remove this
    for (int i = startx; i <= b; i+=x) {
        multiples_x.push_back(i);
    }

    //print(multiples_x);

    int starty;
    if (a > y) {
        int mody = a % y;
        if (mody == 0) {
            starty = a;
        } else {
            starty = a + (y - (a % y));
        }
    } else {
        starty = y;
    }

    int count = 0;
    for (int i = starty; i <= b; i+=y) {
        if (binary_search(multiples_x.begin(), multiples_x.end(), i)) {
            count++;
        }
    }

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

    return 0;
}

// 1524251246386


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

using ll= long long;
#define double long double
#define sz(x) (int)x.size()
#define all(x) (x).begin(),(x).end()
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _set(x) __builtin_popcount(x)
#define _setl(x) __builtin_popcountll(x)
#define PI  3.14159265358979323846264338327950L
#define mod 1000000007LL

void debug(){
	cerr<<"]\n";
}
template<class H,class ... T> void debug(H h,T... t){
	cerr<<h;
	if(sizeof... (t)){
		cerr<<", ";
	}
	debug(t...);
}
#ifdef DEBUG
	#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", debug(__VA_ARGS__)
	#define dpv(...) cerr<< "["#__VA_ARGS__ " : ";for(int i: (__VA_ARGS__)){cerr<<i<<" ";}cerr<<"]\n"
#else
	#define dbg(...) 0
	#define dpv(...) 0
#endif

void solve(){
	int x, y;
	int a,b;
	cin>>a>>b;
	cout<<"GCD "<<gcd(a,b,x,y)<<" ";dbg(x,y);
}

int32_t main(){
	IOS
	// freopen("input.txt","r",stdin);
	int _;
	// cin>>_;
	_=1;
	for(int i=1;i<=_;i++){
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	return 0;
}

/*
   check for overflows int long long
   correct mize of array
*/


#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>

using namespace std;

typedef long long ll;

#ifdef iq
  mt19937 rnd(228);
#else
  mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

  map <ll, int> dp;

int ans(ll n) {
  if (dp.count(n)) return dp[n];
  int ret = 0;
  for (ll x = max(0, n / 2 - 2); x <= n / 2 + 2; x++) {
    if (x >= 0 && x <= n && abs(x - (n - x)) <= 1) {
      ret = max(ret, max(ans(x), ans(n - x)) + 1);
    }
  }
  return dp[n] = ret;
}

int main() {
#ifdef iq
  freopen("a.in", "r", stdin);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll n;
  cin >> n;
  cout << ans(n) << endl;
}


#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <utility>
#include <ctime>
#include <map>

template<class A, class B, class C> struct triple { A first; B second; C third; triple(A, B, C); triple(); };
template<class A, class B, class C> triple<A, B, C>::triple(A a, B b, C c) { first = a; second = b; third = c; }
template<class A, class B, class C> triple<A, B, C>::triple() { }
template<class A, class B, class C> triple<A, B, C> make_triple(A a, B b, C c){ triple<A, B, C> t(a, b, c); return t; }
template<class A, class B, class C> bool operator<(triple<A, B, C> a, triple<A, B, C> b){ if (a.first != b.first) return a.first < b.first; if (a.second != b.second) return a.second < b.second; if (a.third != b.third) return a.third < b.third; }
template<class T> T inline sqr(T a) { return a * a; }

//#define  first
//#define  second
//#define  third
#define mp make_pair
#define mt make_triple

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const ld PI = 3.141592653589793;
const ld E = 2.71828182845904523;
const ll LLINF = 9000000009000000099;
const ll INF = 2009000099;
const ll MOD = 1000000008;

using namespace std;

inline bool check(string& t)
{
  int x = 0, y = 0;
  for (int i = 0; i < t.length(); ++i)
  {
    if (t[i] == 'U') y++;
    if (t[i] == 'D') y--;
    if (t[i] == 'R') x++;
    if (t[i] == 'L') x--;
  }
  if (x == y && y == 0) return 1;
  return 0;
}

int main(){
  ios::sync_with_stdio(0);
  //int n; cin >> n; vector<ll> m(n); for (int i = 0; i < n; ++i) cin >> m[i];
  int n;
  cin >> n;
  string s;
  cin >> s;
  int res = 0;
  for (int i = 0; i < s.length(); ++i)
    for (int j = i + 1; j < s.length(); ++j)
      if (check(s.substr(i, j - i + 1)))
        res++;
  cout << res;
  //
}


#include<iostream>
using namespace std;
int main()
{
 int n,m,count=0,ans=0,i,j,a[105]={0},found=0;
 cin>>n>>m;
 for(i=1;i<=n;i++)
  cin>>a[i];
 i=1;
 while(i<=n)
 {
  found=0;
  ans++;
  count=0;
  while(found<=0)
  {
   if(count+a[i]<=m)  count=count+a[i],i++;
   else found=1;
//   cout<<count<<" ";
  }
 }
 (ans==0)?(cout<<"1"):(cout<<ans);
// system("pause");
 return 0;
}