#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define eps 1e-9
#define PI acos(-1)
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
const int MOD = 1000000007;
const long long LINF = 4611686018427387903;
const int dir4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir8[8][2] = {{1, 0}, {0, 1},   {-1, 0}, {0, -1},
                        {1, 1}, {-1, -1}, {1, -1}, {-1, 1}};
const int dir63[6][3] = {{0, 0, 1},  {0, 0, -1}, {0, 1, 0},
                         {0, -1, 0}, {1, 0, 0},  {-1, 0, 0}};
const int daym[2][13] = {{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
                         {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}};
int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }
// freopen("*.in", "r", stdin);
// freopen("*.out", "w", stdout);

int main() {
    int n;
    scanf("%d", &n);
    cout << (n / 2 + 1) * (n + 1) / 2 << endl;
    return 0;
}


#include <iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;
struct p
{
    int l,r;
    int flag;
    int ge;
} x[1010];
int cmp(struct p a,struct p b)
{
    if(a.l!=b.l)
        return a.l<b.l;
    else
        return a.r<b.r;
}
int main()
{
    int n,i,j;
    scanf("%d",&n);
    memset(x,0,sizeof(x));
    int t=n*(n+1)/2;
    int z=0;
    for(i=0; i<=n-1; i++)
        for(j=i+1; j<=n; j++)
        {
            x[z].l=i;
            x[z++].r=j;
        }
    sort(x,x+z,cmp);
    for(i=t-1; i>=0; i--)
    {
        if(x[i].flag==0)
        {
            int l=x[i].l;
            for(j=i-1; j>=0; j--)
                if(x[j].flag==0&&x[j].r==l)
                {
                    l=x[j].l;
                    x[j].flag=1;
                }
        }
    }
    int ge=0;
    for(i=0; i<=t-1; i++)
    {
        if(x[i].flag==0)
            ge++;
    }
    printf("%d\n",ge);
}


//#define _GLIBCXX_DEBUG

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}
template<typename T>void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++){cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++){for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>vector<vector<T>>vec(ll x, ll y, T w){vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,-1,0,0,1,1,-1,-1};vector<ll>dy={0,0,1,-1,1,-1,1,-1};
template<typename T>vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<typename T1, typename T2>ostream &operator<<(ostream &os, const pair<T1, T2>&p){return os << p.first << " " << p.second;}
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v){for(auto &z:v)os << z << " ";cout<<"|"; return os;}
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
int popcount(ll x){return __builtin_popcountll(x);};
int poplow(ll x){return __builtin_ctzll(x);};
int pophigh(ll x){return 63 - __builtin_clzll(x);};

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n,k;cin>>n>>k;
  vector<ll>dp(n+1);
  dp[n]=1;
  rrep(i,0,n){
    rep(j,i+1,n+1)dp[i]+=dp[j];
  }
  //debug(dp,5);
  vector<ll>ret;
  ll idx=0;
  k--;
  while(idx<n){
    ll nxt=idx;
    //cout<<k spa (1<<n-idx-2)<<endl;
    while(idx!=n-1&&k>=(1<<n-idx-2)){
      nxt++;
      k-=1<<n-idx-1;
    }
    ret.PB(nxt+1);
    rep(i,idx,nxt)ret.PB(i+1);
    idx=nxt+1;
  }
  debug(ret,ret.size());
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,x,xx,xxx;
	cin >> x >> xx >> xxx;
	cout << (x+xx+xxx)/n << endl;
}


#include <bits/stdc++.h>
#include <algorithm>

using namespace std;

int main () {
    vector<int> v;
    for (int i = 0; i < 3; i++)
    {
        cin >> v[i];
    }

    sort(v.begin(), v.end());
    cout << v[2] - v[0] << endl;
    return 0;
}


#include <bits/stdc++.h>
#pragma GCC target "avx,avx2"

using namespace std;

const int MAX_N = 2 * 1e5 + 42;
vector < int > gr[MAX_N];
vector < int > rev_gr[MAX_N];
int p[MAX_N];
int dist[MAX_N];
const int INF = 1e6 + 42;

void bfs(int start) {
    dist[start] = 0;
    queue < int > q;
    q.push(start);
    while (!q.empty()) {
        int v = q.front();
        q.pop();
        for (auto u : rev_gr[v]) {
            if (dist[u] < dist[v] + 1) {
                continue;
            }
            dist[u] = dist[v] + 1;
            q.push(u);
        }
    }
}

signed main() {
    //freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int v, u;
        cin >> v >> u;
        v--;
        u--;
        gr[v].push_back(u);
        rev_gr[u].push_back(v);
    }
    int k;
    cin >> k;
    for (int i = 0; i < k; i++) {
        cin >> p[i];
        p[i]--;
    }
    fill(dist, dist + n, INF);
    bfs(p[k - 1]);
    int mn = 0;
    for (int i = 0; i < k - 1; i++) {
        int v = p[i];
        int u = p[i + 1];
        if (dist[v] != dist[u] + 1) {
            mn++;
        }
    }
    int mx = 0;
    for (int i = 0; i < k - 1; i++) {
        int v = p[i];
        int u = p[i + 1];
        int c = -1;
        for (auto x : gr[v]) {
            if (x == u) {
                continue;
            }
            if (dist[x] != dist[v] - 1) {
                continue;
            }
            c = x;
        }
        if (c != -1) {
            mx++;
        }
    }
    cout << mn << " " << mx;
    return 0;
}


#include"iostream"
#include"algorithm"
#include"cstdio"
#include"cstring"
#include"queue"
using namespace std;
int main()
{
    int a[3];
    while(1)
    {
        int k=1;
        for(int i=0;i<3;i++)
        {
            cin>>a[i];
            a[i]/=k;
            k*=2;
        }
        sort(a,a+3);
        cout<<a[0]*7<<endl;
    }
    return 0;
}


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

int n, m;

int dp[1 << 6][1 << 6][1 << 6][6][40];

int f(int mask1, int mask2, int mask3, int idx, int idy) {
	if(idy < 0) return 0;
	if(idx < 0) {
		return f(mask2, mask3, 0, m - 1, idy - 1);
	}
	if(~dp[mask1][mask2][mask3][idx][idy]) return dp[mask1][mask2][mask3][idx][idy];

	if((mask2 >> idx) & 1) {
		return 1 + f(mask1, mask2, mask3, idx - 1, idy);
	}
	int res = 1 + f(mask1, mask2 | (1 << idx), mask3, idx - 1, idy);

	if(idy < n - 1) res = min(res, ((mask1 >> idx) & 1) + f(mask1 | (1 << idx), mask2, mask3, idx - 1, idy));

	if(idx > 0) res = min(res, ((mask2 >> (idx - 1)) & 1) + f(mask1, mask2 | (1 << (idx - 1)), mask3, idx - 1, idy));

	if(idx < m - 1) res = min(res, ((mask2 >> (idx + 1)) & 1) + f(mask1, mask2 | (1 << (idx + 1)), mask3, idx - 1, idy));

	if(idy > 0) res = min(res, f(mask1, mask2, mask3 | (1 << idx), idx - 1, idy));

	return dp[mask1][mask2][mask3][idx][idy] = res;
}

int32_t main() {
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	if(n < m) swap(n, m);

	memset(dp, -1, sizeof dp);
	cout << n * m - f(0, 0, 0, m - 1, n - 1) << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
int const lim =  1e5+3;
int const MLOG = 20;
int mod = 1e9+7,n,m;
int dp[41][(1<<7)][(1<<7)][(1<<7)];
int f(int a,int i)
{
	if(a&(1<<i))return a^(1<<i);
	return a;
}
int solve(int ind,int a,int b,int c)
{
	if(ind==n)return 0;
	int &ret = dp[ind][a][b][c];
	if(ret!=-1)return ret;
	ret = INT_MAX/2;
	if(a==0)return ret = solve(ind+1,b,c,(1<<m)-1);
	for(int i = 0;i<m;i++)
	{
		if((1<<i)&a)
		{
			if(i+1<m)ret = min(ret,solve(ind,f(a,i)&f(a,i+1)&f(a,i+2),b,c)+1);
			ret = min(ret,solve(ind,f(a,i)&f(a,i+1),f(b,i),c)+1);
			if(ind+1<n)ret = min(ret,solve(ind,f(a,i),f(b,i),f(c,i))+1);
		}
	}
	return ret;
}
int main()
{
	//freopen("input","r",stdin);
	//freopen("output","w",stdout);
	memset(dp,-1,sizeof dp);
	cin >> n >> m;
	if(m>n)swap(n,m);
	cout << n*m-solve(0,(1<<m)-1,(1<<m)-1,(1<<m)-1)<<endl;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <queue>

using namespace std;

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

const int maxn = 15;
const int mod = 1000000000;

int a[maxn][maxn];
int now[maxn][maxn];
int n, m, num;
int ans;
LL goal;

void dfs(int x, int y, LL s, int step)
{
    if (step >= ans)
        return ;
    if (s == goal)
    {
        ans = min(ans, step);
        return ;
    }
    if (y == m)
    {
        dfs(x + 1, 0, s, step);
        return ;
    }
    if (x == n)
        return ;
    if (now[x][y] != -1)
    {
        dfs(x, y + 1, s, step);
        return ;
    }
    for (int i = 0; i < num; i++)
    {
        if (s & (1LL << i))
            continue;
        if (y + 1 < m && now[x][y+1] == -1)
        {
            now[x][y] = now[x][y+1] = i;
            dfs(x, y + 1, s | (1LL << i), step + (now[x][y] != a[x][y]) + (now[x][y+1] != a[x][y+1]));
            now[x][y] = now[x][y+1] = -1;
        }
        if (x + 1 < n && now[x+1][y] == -1)
        {
            now[x][y] = now[x+1][y] = i;
            dfs(x, y + 1, s | (1LL << i), step + (now[x][y] != a[x][y]) + (now[x+1][y] != a[x+1][y]));
            now[x][y] = now[x+1][y] = -1;
        }
    }
}

int main()
{
    //freopen("input.txt","r",stdin);
    scanf ("%d %d", &n, &m);
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
        {
            scanf ("%d", &a[i][j]);
            a[i][j]--;
        }
    num = n * m / 2;
    ans = mod;
    goal = (1LL << num) - 1;
    memset(now, -1, sizeof(now));
    dfs(0, 0, 0, 0);
    printf ("%d\n", ans);
    return 0;
}


#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<ctime>
#include<vector>
#include<cstdio>
#include<vector>
#include<string>
#include<bitset>
#include<cstdlib>
#include<iomanip>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
inline int read(){
    int res=0,f=1;
    char ch=getchar();
    while(!isdigit(ch)){
        if(ch=='-')
            f=-f;
        ch=getchar();
    }
    while(isdigit(ch)){
        res=(res<<1)+(res<<3)+(ch^48);
        ch=getchar();
    }
    return res*f;
}
inline void write(int x){
    if(x<0){
        putchar('-');
        x=-x;
    }
    if(x>9)
        write(x/10);
    putchar(x%10+'0');
}
const int MAXN=1e7+5;
const double EPS=1e-6;
const double PI=acos(-1);
long long mod=1e9+7;
int m,k,l,r,T,len,c,h,w,cnt;
int arr[100005];
int ans;
bool isprimer[MAXN];
int su[100000005];
void prime() {
    cnt = 1;
    memset(isprimer, 1, sizeof isprimer);
    isprimer[0] = isprimer[1] = 0;
    for (long long i = 2; i < MAXN; i++) {
        if (isprimer[i])
        {
            su[cnt++] = i;
        }
        for (long long j = 1; j < cnt && su[j] * i < MAXN; ++j)
        {
            isprimer[su[j] * i] = 0;
        }
    }
}
bool isPrimer(long long x){
    for(long long i=2,lll=sqrt(x);i<=lll;i++)
        if(x%i==0)
            return false;
    return true;
}
long long x,n;
long long ksm(long long a,long long b){
    if(a==0||b==0) return 1;
    long long ret=1;
    long long base=a%mod;
    while(b){
        if(b&1)
            ret=(ret*base)%mod;
        base=(base*base)%mod;
        b>>=1;
    }
    return ret%mod;
}
void solve(){
    long long tmp=x;
    int num=0;
    for(int i=1;i<cnt;i++){
        if(tmp==0||tmp==1)
            break;
        if(tmp%su[i]==0){
            arr[num++]=su[i];
        }
        while(tmp&&tmp%su[i]==0){
            tmp/=su[i];
        }
    }
    long long pri=su[cnt-1];
    while(tmp>=pri){
        if(tmp%pri==0&&isPrimer(pri)){
            arr[num++]=pri;
            while(tmp%pri==0){
                tmp/=pri;
            }
        }
        pri++;
    }
//    for(long long i=2,lll=sqrt(x);i<=lll;i++){
//        if(tmp%i==0){
//            if(isPrimer(i)){
//                arr[num++]=i;
//                while(tmp%i==0){
//                    tmp/=i;
//                }
//                cout<<i<<endl;
//            }
//            if(isPrimer(tmp/i)){
//                arr[num++]=tmp/i;
//                while(tmp%(tmp/i)==0){
//                    tmp/=(tmp/i);
//                }
//            }
//        }
//    }
//    sort(arr,arr+num);
    long long ans=1;
    for(int i=0;i<num;i++){
        long long tmp=arr[i];
        while(tmp>0&&tmp<=n){
            if((n/arr[i])>=tmp){
                tmp=tmp*arr[i];
            }else{
                break;
            }
        }
        if(tmp>n)
            tmp=tmp/arr[i];
        if(tmp!=1){
            long long pre=0;
            while(tmp>=arr[i]){
                ans=(ans*ksm(tmp,n/tmp-pre))%mod;
                pre=n/tmp;
                tmp/=arr[i];
            }
        }
    }
    cout<<ans<<endl;
}
void init(){
    prime();
    cin>>x>>n;
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    init();
    solve();
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
int g[10][10];
int tong[10];
bool cmp(int a,int b)
{
	return a>b;
}
int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	memset(g,0,sizeof(g));
	memset(tong,0,sizeof(tong));
	int a,b;
	int ans = 0;
	bool flag = true;
	for(int i=0;i<m;i++)
	{
		scanf("%d %d",&a,&b);
		tong[a]++;
		tong[b]++;
	}
	sort(tong+1,tong+n+1,cmp);
	for(int i=1;i<=n&&i<7;i++)
	{
		if(tong[i]==6&&flag)
		{
			ans += tong[i];
			for(int j=i+1;j<=n;j++)
			{
				if(tong[j]==6)
					tong[j]-=2;
				else
					tong[j]--;
			}
			flag = false;
		}
		else
		{
			int k = i+1;
			while(tong[i]--)
			{
				ans++;
				if(tong[k] > 0)
					tong[k]--;
				else
				{
					while(k<=n)
					{
						k++;
						if(tong[k] > 0)
						{
							tong[k]--;
							break;
						}
					}
					if(k>n)
					{
						tong[i]--;
					}
				}
				k++;
			}
		}
	}
	printf("%d\n",ans);
	return 0;
 }


//BRR
#include <bits/stdc++.h>

#define fi first
#define sc scanf
#define pf printf
#define se second
#define ll long long
#define pb push_back
#define pr pair< ll,pair<ll,ll> >
#define fin(s) freopen( s, "r", stdin )
#define fout(s) freopen( s, "w", stdout )
#define TIME ios_base::sync_with_stdio(0)
#define SZ(x) ((int) (x).size())

const ll INF = 2e18;
const ll N = 1e6;
const ll mod = 1e9;
const long double eps = 1E-7;
using namespace std;

char m[N];
int t;

void solve(){
    //fin("input.txt");
    //fout("output.txt");
    int a, b;
    cin >> a >> b;
    string s, z;
    cin >> s;

    int x = a;
    z = s;
    sort(s.begin(), s.end());
    for(int i=0; i<a/2; ++i) {
          if(s[i] != s[a - 1 - i]) {
                t ++, x-=2;
                z = z.substr(i+1, a-i-2);
          }
    }

    b -= t;
    if(z.size() <= b) x = 0;
    cout << ( !x ? "YES\n" : "NO\n" );
}
bool mtest = false;
int main(){
    TIME;
    int TE = 1;
    if(mtest)
        cin >> TE;
    while(TE--)
        solve();
    return 0;
}


#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main()
{
    int array[4],counter=0,base=1,res1,res2;
    for (int i=0;i<4;i++)
        cin>>array[i];
    vector<int> array1,array2;
    while (true)
    {
        res1=base*array[0],res2=base*array[1];
        if (res1>=array[2] && res1<=array[3])
            array1.push_back(res1);
        if (res2>=array[2] && res2<=array[3])
            array2.push_back(res2);
        if (res1>array[3] && res2>array[3])
            break;
        base++;
    }
    if (array2.size()<array1.size())
    {
        for (int i=0;i<array2.size();i++)
            if (array2[i]%array[0]==0)
                counter++;
    }
    else
        for (int i=0;i<array1.size();i++)
                if (array1[i]%array[1]==0)
                    counter++;
    cout<<counter<<endl;
    return 0;
}


#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define inf 0x3f3f3f3f3f3f3f3f
#define pi acos(-1.0)
#define ri register int
#define int long long
#define all(x) x.begin(), x.end()
#ifdef ONLINE_JUDGE
const int maxn = 3e5 + 10;
#else
const int maxn = 1e3 + 10;
#endif
//__builtin_popcount
char str[maxn];
int N;
signed main() {
#ifdef ONLINE_JUDGE
    ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    // freopen("C:\Users\hjw\Downloads\testdata (4).in", "r", stdin);
    cin >> str + 1;
    N = strlen(str + 1);
    vector<vector<string>> dp(N + 1);
    dp[0].push_back("");

    for (int i = 1; i <= N; ++i) {
        if (i >= 2 && str[i - 1] == 'a' && str[i] == 't') {
            for (auto e : dp[i - 2]) {
                if (e.empty() || e.find('@') != e.npos) {
                    continue;
                }
                dp[i].push_back(e + "@");
            }

        } else if (i >= 3 && str[i - 2] == 'd' && str[i - 1] == 'o' &&
                   str[i] == 't') {
            for (auto e : dp[i - 3]) {
                if (e.empty()) {
                    continue;
                }
                dp[i].push_back(e + ".");
            }
        }
        for (auto e : dp[i - 1]) {
            dp[i].push_back(e + str[i]);
        }
    }
    vector<string> ans;
    for (auto e : dp[N]) {
        if (e.empty())
            continue;
        if (e.find('@') != e.npos && e.back() != '@' && e.back() != '.') {
            ans.push_back(e);
        }
    }
    sort(all(ans));
    cout << ans.front() << endl;

#ifndef ONLINE_JUDGE
    system("pause");
#endif
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <queue>

using namespace std;
typedef long long int ll;
typedef pair <ll, ll> ii;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef vector <ii> vii;

vi P, rep, out, visited, original;
vvi edges, G, queries;
vector <set <int> > best;
vvi nodes;

void dfs(int v, int parent){
    ++visited[v];

    rep[v] = parent;
    best[parent].insert(-P[v]);
    nodes[parent].push_back(v);
    for (int u : G[v]){
        if (not visited[u]) dfs(u, parent);
    }
}

int findrep(int v){
    if (rep[v] == v) return v;
    else return rep[v] = findrep(rep[v]);
}

void solve(int q){
    if (q == -1) return;

    int t = queries[q][0], v = queries[q][1];
    //cout << " solving query " << q << " i.e. " << t << " and " << v << endl;

    if (t == 1){
        solve(q - 1);

        int p = findrep(v);

        if (best[p].empty()) cout << 0 << '\n';
        else {
            cout << -*best[p].begin() << '\n';
            P[original[-*best[p].begin()]] = 0;
            best[p].erase(best[p].begin());
        }
    }
    else {

        int a = edges[v][0], b = edges[v][1];

        if (best[a].size() < best[b].size()) swap(a, b);

        int pb = findrep(b), pa = findrep(a);

        if (pa < pb){
            rep[pb] = pa;

            for (int x: best[pb]){
                best[pa].insert(x);
            }
            for (int x: nodes[pb]){
                nodes[pa].push_back(x);
            }
            best[pb].clear();
        }

        if (pa > pb){
            rep[pb] = pa;

            for (int x: best[pb]){
                best[pa].insert(x);
            }
            for (int x: nodes[pb]){
                nodes[pa].push_back(x);
            }
            //best[pb].clear();
        }

        solve(q - 1);

        if (pa > pb){
            for (int x : nodes[pb]) {
                nodes[pa].pop_back();
                rep[x] = pb;
            }

            vi pending;

            for (int x: best[pb]){
                auto it = best[pa].find(x);

                if (it == best[pa].end()) pending.push_back(x);
                else best[pa].erase(it);
            }

            for (int x: pending) best[pb].erase(x);
        }

        if (pa < pb){
            for (int x : nodes[pb]) {
                nodes[pa].pop_back();
                rep[x] = pb;
                if (P[x] != 0){
                    best[pa].erase(-P[x]);
                    best[pb].insert(-P[x]);
                }
            }
        }
    }

    //cout << " finished with " << q << endl;
}

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

    int n, m, q;
    cin >> n >> m >> q;

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

    rep = vi(n);
    for (int i = 0; i < n; ++i) rep[i] = i;

    edges = vvi(m, vi(2));
    out = vi(m, 0);

    for (int i = 0; i < m; ++i){
        int x, y;
        cin >> x >> y;
        --x; --y;

        edges[i] = {x, y};
    }

    queries = vvi(q, vi(2));
    for (int i = 0; i < q; ++i) {
        int t, v;
        cin >> t >> v;
        --v;

        queries[i] = {t, v};
    }

    for (int i = 0; i < q; ++i){
        if (queries[i][0] == 2) out[queries[i][1]] = 1;
    }

    G = vvi(n);

    for (int i = 0; i < m; ++i){
        if (out[i]) continue;

        G[edges[i][0]].push_back(edges[i][1]);
        G[edges[i][1]].push_back(edges[i][0]);
    }

    visited = vi(n, 0);
    best = vector <set <int> > (n);
    nodes = vvi(n);

    for (int i = 0; i < n; ++i){
        if (not visited[i]) dfs(i, i);
    }

    original = vi(n + 1);
    for (int i = 0; i < n; ++i) original[P[i]] = i;

    solve(q-1);
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define sz(v) int((v).size())
#define int ll
#define x first
#define y second
#define mp make_pair
#define pb push_back

int n, m;
vector<int> a;
set<int> rem[44];
int b;
void test()
{
    for(int i=0;i<44;++i) rem[i].clear();

    for(int i=0;i<n;++i)
    {
        rem[i+1].insert(a[i]);
        for(int it: rem[i])
        {
            rem[i+1].insert((it+a[i])%m);
            rem[i+1].insert(it);
        }
        b = max(b, *--rem[i+1].end());
    }
}
void solve()
{
    scanf("%lld%lld", &n, &m);
    a.resize(n);
    forn(i, n) scanf("%lld", &a[i]);
    forn(i, n) a[i] = a[i]%m;
    test();
    printf("%lld\n", b);
}
signed main()
{
    int T = 1; //scanf("%lld", &T);
    while (T--) solve();
    return 0;
}


#include <cstring>
#include <iostream>
#include <numeric>
#include <cmath>

using namespace std;

int main() {

    char c;
    char zeroalpha = 'Z';
    int qn = 0;
    int used[10];
    int i = 0;
    long long ans = 1;
    int total;
    double power;
    char first;

    memset(used, 0, sizeof(used));

    cin >> c;

    if (c == '?' || isalpha(c)) {
       ans = 9;
       zeroalpha = c;
    }

    first = c;

    do {
       cin >> c;
       if (c == '?') { qn++; }
       else if (isalpha(c) && c != zeroalpha) {used[(static_cast<int>(c))-65] = 1;}
    } while (cin.peek() != '\n');

    static_cast<double>(qn);

    if (qn != 0) {
       total = accumulate(used, used+10, 0);
       power = 10 - total + 1;
       if (zeroalpha == first) {
          power -= 1;
       }
       ans *= (long long)(pow(10.0, qn) * pow(power, total));
    }
    else {
         total = accumulate(used, used+10, 0);
         power = 10 - total + 1;
         if (zeroalpha != 'Z') {
            power -= 1;
         }
         ans *= (long long)(pow(power, total));
    }

    cout << ans << endl;
    //system("pause");
    return 0;
}


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

typedef long long unsigned llu;
typedef long double ld;
#define ll long long
#define For(i, a, b) for (int i = a, sz = (int)b; i < sz; i++)
#define all(v) (v).begin(), (v).end()
#define Memset(a, b) memset(a, b, sizeof(a))
#define IO ios_base::sync_with_stdio(false), cin.tie(0),cout.tie(0)
const ll mod = 1000000007;
const ll inf = 1000000000009;

//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);

const int N=101;
int a[N];

int main()
{
	IO;
	int n{};
	cin>>n;
	For(i,1,n+1)
		cin>>a[i];

	if(n%2!=0)
	{
		int c{};
		for(int i=1;i<n+1;i+=2)
			if(a[i]%2!=0)
				a[i]=-1,c++;

		if(c==1 && n==1)
			cout<<"YES"<<"\n";
		else if(c>=2)
			cout<<"YES"<<"\n";
		else
			cout<<"NO"<<"\n";
	}
	else
		cout<<"NO"<<"\n";

	//system("pause");
	return 0;

}


#include <bits/stdc++.h>

#define MAX 500
#define oo  0x2f2f2f2f

using namespace std;

int cost_hp, cost_atk, cost_def, monster_hp, monster_atk, monster_def, dp[MAX][MAX][MAX];

bool wins(int hp, int atk, int def) {
	int hp_lost = monster_atk - def, monster_hp_lost = atk - monster_def;
	if(monster_hp_lost <= 0) return false;
	int n = monster_hp / monster_hp_lost + (monster_hp % monster_hp_lost != 0);
	if(hp_lost <= 0) return n > 0;
	int m = hp / hp_lost + (hp % hp_lost != 0);
	return n < m;
}

int solve(int hp, int atk, int def) {
	if(hp == MAX || atk == MAX || def == MAX) {
		return oo;
	} else if(wins(hp, atk, def)) {
		return 0;
	} else if(~dp[hp][atk][def]) {
		return dp[hp][atk][def];
	} else {
		return dp[hp][atk][def] = min(solve(hp + 1, atk, def) + cost_hp, min(solve(hp, atk + 1, def) + cost_atk, solve(hp, atk, def + 1) + cost_def));
	}
}

int main(void) {
	int hp, atk, def;
	scanf("%d %d %d", &hp, &atk, &def);
	scanf("%d %d %d", &monster_hp, &monster_atk, &monster_def);
	scanf("%d %d %d", &cost_hp, &cost_atk, &cost_def);
	memset(dp, -1, sizeof dp);
	printf("%d\n", solve(hp, atk, def));
	return 0;
}


#include<bits/stdc++.h>
#define int long long int
#define ll long long int
#define pb push_back
#define endl "\n"
#define F first
#define S second
#define mod 998244353
using namespace std;
const int mx= 200+5;
int fact[mx], invfact[mx];
int powm(int x, int y){          //Binary exponent
    int res = 1;
    x %= mod;
    while(y){
      if(y & 1)
        res *= x;
      x *= x;
      x %= mod;
      res %= mod;
      y /= 2;
    }
    return res;
}
int modinv(int num){
   return powm(num, mod - 2);
}

void cal_fact(){
   fact[0] = 1;
   for(int i = 1; i < mx; i++){
      fact[i] = fact[i - 1] * i;
      fact[i] %= mod;
   }
   invfact[mx - 1] = modinv(fact[mx - 1]);
   for(int i = mx - 2; i >= 0; i--){
      invfact[i] = invfact[i + 1] * (i + 1);
      invfact[i] %= mod;
   }
}

main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cal_fact();
    int n, m, like = 0, dislike = 0;
    cin >> n >> m;
    bool type[n];
    for(int i = 0; i < n; i++)
        cin >> type[i];
    int wt[n];
    for(int i = 0; i < n; i++){
        cin >> wt[i];
        like += wt[i] * type[i];
        dislike += wt[i] * (1 - type[i]);
    }
    for(int i = 0; i < n; i++){
        int dp[m + 1][3000], ans = 0;
        memset(dp, 0, sizeof dp);
        dp[0][like] = wt[i];
        for(int j = 1; j <= m; j++){
            for(int k = 1; k <= 3000; k++){
                for(int l = 0; l <= 100; l++){
                    if(type[i]){
                        dp[j][k][l] += (((dp[j - 1][k - 1][l] * wt[i]) % mod) * invfact[k + l]) % mod;
                        dp[j][k][l] %= mod;
                        if(k > wt[i])
                            dp[j][k][l] += (((dp[j - 1][k - 1][l] * (k - wt[i])) % mod) * invfact[k + l]) % mod;
                        dp[j][k][l] %= mod;
                        dp[j][k][l] += (((dp[j - 1][k][l + 1] * l) % mod) * invfact[k + l]) % mod;
                        dp[j][k][l] %= mod;
                    }
                    else{
                        dp[j][k][l] += (((dp[j - 1][k][l + 1] * wt[i]) % mod) * invfact[k + l]) % mod;
                        dp[j][k][l] %= mod;
                        dp[j][k][l] += (((dp[j - 1][k - 1][l] * k) % mod) * invfact[k + l]) % mod;
                        dp[j][k][l] %= mod;
                        if(l > wt[i])
                            dp[j][k][l] += (((dp[j - 1][k][l + 1] * (l - wt[i])) % mod) * invfact[k + l]) % mod;
                        dp[j][k][l] %= mod;
                    }

                }
            }
        }
        for(int k = 0; k <= 100; k++){
            for(int l = 0; l <= 100; l++){
                ans += dp[m][k][l];
                ans %= mod;
            }
        }
        cout << ans << endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int n, a[27], vis[27], ans;
int main(){
	cin >> n;
	for(int i = 1; i <= n; ++i)
	{
		cin >> a[i];
	}
	sort(a + 1, a + n + 1);
	for(int i = n; i >= 1; --i)
	{
		if(!vis[a[i]])
		{
			ans += a[i];
			vis[a[i]] = 1;
		}
		else
		{
			int j = a[i];
			while(vis[j]) j--;
			ans += j;
			vis[j] = 1;
		}
	}
	cout << ans;
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ldb double
template<typename T>void ckmn(T&a,T b){a=min(a,b);}
template<typename T>void ckmx(T&a,T b){a=max(a,b);}
void rd(int&x){scanf("%i",&x);}
void rd(ll&x){scanf("%lld",&x);}
void rd(char*x){scanf("%s",x);}
void rd(ldb&x){scanf("%lf",&x);}
void rd(string&x){scanf("%s",&x);}
template<typename T1,typename T2>void rd(pair<T1,T2>&x){rd(x.first);rd(x.second);}
template<typename T>void rd(vector<T>&x){for(T&i:x)rd(i);}
template<typename T,typename...A>void rd(T&x,A&...args){rd(x);rd(args...);}
template<typename T>void rd(){T x;rd(x);return x;}
int ri(){int x;rd(x);return x;}
template<typename T>vector<T> rv(int n){vector<T> x(n);rd(x);return x;}
template<typename T>void ra(T a[],int n,int st=1){for(int i=0;i<n;++i)rd(a[st+i]);}
template<typename T1,typename T2>void ra(T1 a[],T2 b[],int n,int st=1){for(int i=0;i<n;++i)rd(a[st+i]),rd(b[st+i]);}
template<typename T1,typename T2,typename T3>void ra(T1 a[],T2 b[],T3 c[],int n,int st=1){for(int i=0;i<n;++i)rd(a[st+i]),rd(b[st+i]),rd(c[st+i]);}
void re(vector<int> E[],int m,bool dir=0){for(int i=0,u,v;i<m;++i){rd(u,v);E[u].pb(v);if(!dir)E[v].pb(u);}}
template<typename T>void re(vector<pair<int,T>> E[],int m,bool dir=0){for(int i=0,u,v;i<m;++i){T w;rd(u,v,w);E[u].pb({v,w});if(!dir)E[v].pb({u,w});}}

int mod;
int add(int a,int b){a+=b;return a>=mod?a-mod:a;}
void ckadd(int&a,int b){a=add(a,b);}
int sub(int a,int b){a-=b;return a<0?a+mod:a;}
void cksub(int&a,int b){a=sub(a,b);}
int mul(int a,int b){return (ll)a*b%mod;}
void ckmul(int&a,int b){a=mul(a,b);}
int powmod(int x,int k){int ans=1;for(;k;k>>=1,ckmul(x,x))if(k&1)ckmul(ans,x);return ans;}
int inv(int x){return powmod(x,mod-2);}

const int N=505;
int blok[N],sum[N];
int c2(int x){return ((ll)x*(x+1)/2)%mod;}
int dp[N][N],ways[N][N];

const int M=1050;
int F[M],I[M];
int binom(int n, int k){ return mul(F[n],mul(I[k],I[n-k]));}
void calc()
{
	F[0]=1;
	for(int i=1;i<M;i++) F[i]=mul(F[i-1],i);
	I[M-1]=inv(F[M-1]);
	for(int i=M-2;~i;i--) I[i]=mul(I[i+1],i+1);
}
int main(){
	int n,m;rd(n,m,mod);
	calc();
	blok[0]=1;
	for(int x=1;x<=m;x++){//block size
		for(int i=1;i<=x;i++){//last element
			ckadd(blok[x],mul(blok[i-1],mul(blok[x-i],binom(x-1,i-1))));
			ckadd(sum[x],mul(add(c2(i-1),c2(x-i)),mul(blok[i-1],mul(blok[x-i],binom(x-1,i-1)))));
			ckadd(sum[x],mul(sum[i-1],mul(mul(blok[x-i],binom(x-1,i-1)),x+1)));
			ckadd(sum[x],mul(sum[x-i],mul(mul(blok[i-1],binom(x-1,i-1)),x+1)));
		}
		ckmul(blok[x],x+1);
		//printf("%i %i\n",blok[x],sum[x]);
	}
	ways[0][0]=1;
	for(int i=1;i<=m;i++){//total size
		for(int j=1;j<=m;j++){//number of blocks
			for(int sz=1;sz<=i;sz++){//last block size
				ckadd(ways[i][j],mul(ways[i-sz][j-1],mul(blok[sz],binom(m-i+sz,sz))));
				ckadd(dp[i][j],mul(ways[i-sz][j-1],mul(sum[sz],binom(m-i+sz,sz))));
				ckadd(dp[i][j],mul(dp[i-sz][j-1],mul(blok[sz],binom(m-i+sz,sz))));
			}
		}
	}
	int ans=0;
	for(int i=1;i<=m;i++){//number of blocks
		int zero=n-m;
		int lef=zero-(i-1);
		if(lef>=0){
			ckadd(ans,mul(dp[m][i],binom(i+1+lef-1,lef)));
		}
	}
	printf("%i\n",ans);
	return 0;
}


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

using ll = long long;
using ld = long double;
using db = double;
using str = string; // yay python!

using pi = pair<int,int>;
using pl = pair<ll,ll>;
using pd = pair<db,db>;

using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;

#define tcT template<class T
#define tcTU tcT, class U
// ^ lol this makes everything look weird but I'll try it
tcT> using V = vector<T>;
tcT, size_t SZ> using AR = array<T,SZ>;
tcT> using PR = pair<T,T>;

// pairs
#define mp make_pair
#define f first
#define s second

// vectors
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sor(x) sort(all(x))
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound

// loops
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

int MOD = 1e9+7; // 998244353;
const int MX = 2e5+5;
const ll INF = 1e18; // not too close to LLONG_MAX
const ld PI = acos((ld)-1);
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1}; // for every grid problem!!
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
template<class T> using pqg = priority_queue<T,vector<T>,greater<T>>;

// helper funcs
constexpr int pct(int x) { return __builtin_popcount(x); } // # of bits set
constexpr int bits(int x) { return 31-__builtin_clz(x); } // floor(log2(x))
ll cdiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // divide a by b rounded up
ll fdiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // divide a by b rounded down

tcT> bool ckmin(T& a, const T& b) {
	return b < a ? a = b, 1 : 0; } // set a = min(a,b)
tcT> bool ckmax(T& a, const T& b) {
	return a < b ? a = b, 1 : 0; }

tcTU> T fstTrue(T lo, T hi, U f) {
	hi ++; assert(lo <= hi); // assuming f is increasing
	while (lo < hi) { // find first index such that f is true
		T mid = lo+(hi-lo)/2;
		f(mid) ? hi = mid : lo = mid+1;
	}
	return lo;
}
tcTU> T lstTrue(T lo, T hi, U f) {
	lo --; assert(lo <= hi); // assuming f is decreasing
	while (lo < hi) { // find first index such that f is true
		T mid = lo+(hi-lo+1)/2;
		f(mid) ? lo = mid : hi = mid-1;
	}
	return lo;
}
tcT> void remDup(vector<T>& v) { // sort and remove duplicates
	sort(all(v)); v.erase(unique(all(v)),end(v)); }
tcTU> void erase(T& t, const U& u) { // don't erase
	auto it = t.find(u); assert(it != end(t));
	t.erase(it); } // element that doesn't exist from (multi)set

// INPUT
#define tcTUU tcT, class ...U
tcT> void re(complex<T>& c);
tcTU> void re(pair<T,U>& p);
tcT> void re(vector<T>& v);
tcT, size_t SZ> void re(AR<T,SZ>& a);

tcT> void re(T& x) { cin >> x; }
void re(db& d) { str t; re(t); d = stod(t); }
void re(ld& d) { str t; re(t); d = stold(t); }
tcTUU> void re(T& t, U&... u) { re(t); re(u...); }

tcT> void re(complex<T>& c) { T a,b; re(a,b); c = {a,b}; }
tcTU> void re(pair<T,U>& p) { re(p.f,p.s); }
tcT> void re(vector<T>& x) { trav(a,x) re(a); }
tcT, size_t SZ> void re(AR<T,SZ>& x) { trav(a,x) re(a); }
tcT> void rv(int& n, vector<T>& x) { re(n); x.rsz(n); trav(a,x) re(a); }

// TO_STRING
#define ts to_string
str ts(char c) { return str(1,c); }
str ts(const char* s) { return (str)s; }
str ts(str s) { return s; }
str ts(bool b) {
	#ifdef LOCAL
		return b ? "true" : "false";
	#else
		return ts((int)b);
	#endif
}
tcT> str ts(complex<T> c) {
	stringstream ss; ss << c; return ss.str(); }
str ts(vector<bool> v) {
	str res = "{"; F0R(i,sz(v)) res += char('0'+v[i]);
	res += "}"; return res; }
template<size_t SZ> str ts(bitset<SZ> b) {
	str res = ""; F0R(i,SZ) res += char('0'+b[i]);
	return res; }
tcTU> str ts(pair<T,U> p);
tcT> str ts(T v) { // containers with begin(), end()
	#ifdef LOCAL
		bool fst = 1; str res = "{";
		for (const auto& x: v) {
			if (!fst) res += ", ";
			fst = 0; res += ts(x);
		}
		res += "}"; return res;
	#else
		bool fst = 1; str res = "";
		for (const auto& x: v) {
			if (!fst) res += " ";
			fst = 0; res += ts(x);
		}
		return res;

	#endif
}
tcTU> str ts(pair<T,U> p) {
	#ifdef LOCAL
		return "("+ts(p.f)+", "+ts(p.s)+")";
	#else
		return ts(p.f)+" "+ts(p.s);
	#endif
}

// OUTPUT
tcT> void pr(T x) { cout << ts(x); }
tcTUU> void pr(const T& t, const U&... u) {
	pr(t); pr(u...); }
void ps() { pr("\n"); } // print w/ spaces
tcTUU> void ps(const T& t, const U&... u) {
	pr(t); if (sizeof...(u)) pr(" "); ps(u...); }

// DEBUG
void DBG() { cerr << "]" << endl; }
tcTUU> void DBG(const T& t, const U&... u) {
	cerr << ts(t); if (sizeof...(u)) cerr << ", ";
	DBG(u...); }
#ifdef LOCAL // compile with -DLOCAL, chk -> fake assert
	#define dbg(...) cerr << "Line(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
	#define chk(...) if (!(__VA_ARGS__)) cerr << "Line(" << __LINE__ << ") -> function(" \
		 << __FUNCTION__  << ") -> CHK FAILED: (" << #__VA_ARGS__ << ")" << "\n", exit(0);
#else
	#define dbg(...) 0
	#define chk(...) 0
#endif

// FILE I/O
void setIn(str s) { freopen(s.c_str(),"r",stdin); }
void setOut(str s) { freopen(s.c_str(),"w",stdout); }
void unsyncIO() { cin.tie(0)->sync_with_stdio(0); }
void setIO(str s = "") {
	unsyncIO();
	// cin.exceptions(cin.failbit);
	// throws exception when do smth illegal
	// ex. try to read letter into int
	if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}

/**
 * Description: modular arithmetic operations
 * Source:
	* KACTL
	* https://codeforces.com/blog/entry/63903
	* https://codeforces.com/contest/1261/submission/65632855 (tourist)
	* https://codeforces.com/contest/1264/submission/66344993 (ksun)
	* also see https://github.com/ecnerwala/cp-book/blob/master/src/modnum.hpp (ecnerwal)
 * Verification:
	* https://open.kattis.com/problems/modulararithmetic
 */

template<int RT> struct mint {
	// static const int mod = MOD;
	static constexpr mint rt() { return RT; } // primitive root for FFT
	int v; explicit operator int() const { return v; } // explicit -> don't silently convert to int
	mint() { v = 0; }
	mint(ll _v) { v = int((-MOD < _v && _v < MOD) ? _v : _v % MOD);
		if (v < 0) v += MOD; }
	friend bool operator==(const mint& a, const mint& b) {
		return a.v == b.v; }
	friend bool operator!=(const mint& a, const mint& b) {
		return !(a == b); }
	friend bool operator<(const mint& a, const mint& b) {
		return a.v < b.v; }
	friend void re(mint& a) { ll x; re(x); a = mint(x); }
	friend str ts(mint a) { return ts(a.v); }

	mint& operator+=(const mint& m) {
		if ((v += m.v) >= MOD) v -= MOD;
		return *this; }
	mint& operator-=(const mint& m) {
		if ((v -= m.v) < 0) v += MOD;
		return *this; }
	mint& operator*=(const mint& m) {
		v = (ll)v*m.v%MOD; return *this; }
	mint& operator/=(const mint& m) { return (*this) *= inv(m); }
	friend mint pow(mint a, ll p) {
		mint ans = 1; assert(p >= 0);
		for (; p; p /= 2, a *= a) if (p&1) ans *= a;
		return ans; }
	friend mint inv(const mint& a) { assert(a.v != 0);
		return pow(a,MOD-2); }

	mint operator-() const { return mint(-v); }
	mint& operator++() { return *this += 1; }
	mint& operator--() { return *this -= 1; }
	friend mint operator+(mint a, const mint& b) { return a += b; }
	friend mint operator-(mint a, const mint& b) { return a -= b; }
	friend mint operator*(mint a, const mint& b) { return a *= b; }
	friend mint operator/(mint a, const mint& b) { return a /= b; }
};

typedef mint<5> mi; // 5 is primitive root for both common mods
typedef vector<mi> vmi;
typedef pair<mi,mi> pmi;
typedef vector<pmi> vpmi;

vector<vmi> scmb; // small combinations
void genComb(int SZ) {
	scmb.assign(SZ,vmi(SZ)); scmb[0][0] = 1;
	FOR(i,1,SZ) F0R(j,i+1)
		scmb[i][j] = scmb[i-1][j]+(j?scmb[i-1][j-1]:0);
}

mi ways[501], mad[501];
mi WAYS[501][501], MAD[501][501];
int N,M;

int main() {
	setIO(); re(N,M,MOD);
	genComb(N+5);
	ways[0] = 1;
	FOR(n,1,N+1) {
		FOR(i,1,n+1) {
			ways[n] += (n+1)*ways[i-1]*ways[n-i]*scmb[n-1][i-1];
			FOR(j,1,i+1) {
				mad[n] += (j-1)*ways[i-1]*ways[n-i]*scmb[n-1][i-1];
				mad[n] += mad[i-1]*ways[n-i]*scmb[n-1][i-1];
				mad[n] += mad[n-i]*ways[i-1]*scmb[n-1][i-1];
			}
			FOR(j,1,n-i+2) {
				mad[n] += (j-1)*ways[i-1]*ways[n-i]*scmb[n-1][i-1];
				mad[n] += mad[i-1]*ways[n-i]*scmb[n-1][i-1];
				mad[n] += mad[n-i]*ways[i-1]*scmb[n-1][i-1];
			}
		}
	}
	F0R(n,N+1) WAYS[n][0] = 1;
	FOR(n,1,N+1) FOR(m,1,n+1) {
		if (n == m) {
			WAYS[n][m] = ways[n];
			MAD[n][m] = mad[n];
		} else {
			WAYS[n][m] = WAYS[n-1][m];
			MAD[n][m] = MAD[n-1][m];
			FOR(l,1,m+1) {
				WAYS[n][m] += WAYS[n-l-1][m-l]*ways[l]*scmb[m][l];
				MAD[n][m] += (WAYS[n-l-1][m-l]*mad[l]+ways[l]*MAD[n-l-1][m-l])*scmb[m][l];
			}
		}
	}
	dbg(WAYS[N][M],MAD[N][M]);
	ps(MAD[N][M]);
	// you should actually read the stuff at the bottom
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
*/


//
//  main.cpp
//  p
//
//  Created by Tony Vazquez on 10/6/18.
//  Copyright © 2018 Tony Vazquez. All rights reserved.
//

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

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

    cin>>s;
    int size=s.size();
    int count=0;
    string copy=s;
    bool c=true;

    do{
        char newString[200];

        newString[0]= copy[size-1];

        for(int i=0;i<size-1;i++){
            newString[i+1]=copy[i];
        }
        count++;
        copy=newString;
        cout<<"copy:  "<<copy<<endl;
        cout<<"s:  "<<s<<endl;
            if (copy==s){
                c=false;
            }
    }while(c);

    /*
    char newString[50];

    newString[0]= s[size-1];
    cout<<"primer string:  "<<newString;
    for(int i=0;i<size-1;i++){
        newString[i+1]=s[i];
    }
    string aux=newString;
    cout<<"seg string:  "<<aux;

    while (aux!=s){

        aux[0]=newString[size-1];
        for(int i=0;i<size-1;i++){
            aux[i+1]=newString[i];
        }
        count++;
        aux=newString;
    }*/
    cout<<count;

    return 0;
}


#include <iostream>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <string>
#include <ctime>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
using namespace std;

#define N 1001001

const int inf = 2 * 1000 * 1000 * 1000;

bool can[N];
int n, m, x, y;

template <typename T>
struct dich {
	struct item {
		item *l, *r;
		int prior, cnt;
		T key;
		item(T x, int y) {
			l = r = NULL;
			key = x;
			prior = y;
			cnt = 0;
		}
	};

	typedef item* pitem;

	dich() {
		t = NULL;
	}

	int cnt(pitem t) {
		return (t == NULL) ? 0 : t->cnt;
	}

	void upd_cnt(pitem t) {
		if (t != NULL) {
			t->cnt = cnt(t->l) + cnt(t->r) + 1;
		}
	}

	void split(pitem t, pitem &l, pitem &r, int key, int add = 0) {
		if (t == NULL) {
			l = r = NULL;
			return;
		}
		int cur_key = add + cnt(t->l);
		if (key <= cur_key) {
			split(t->l, l, t->l, key, add);
			r = t;
		} else {
			split(t->r, t->r, r, key, add + 1 + cnt(t->l));
			l = t;

		}
		upd_cnt(t);
	}

	void merge(pitem &t, pitem l, pitem r) {
		if (l == NULL) t = r; else
		if (r == NULL) t = l; else
		if (l->prior > r->prior) {
			merge(l->r, l->r, r);
			t = l;
		} else {
			merge(r->l, l, r->l);
			t = r;
		}
		upd_cnt(t);
	}

	void insert(int i, T x) {
		pitem t1 = NULL, t2 = NULL;
		split(t, t1, t2, i);
		merge(t1, t1, new item(x, rand()));
		merge(t, t1, t2);
	}

	void erase(int i) {
		pitem t1 = NULL, t2 = NULL, t3 = NULL;
		split(t, t1, t2, i);
		split(t2, t2, t3, 1);
		merge(t, t1, t3);
	}

	T get(int i) {
		pitem t1 = NULL, t2 = NULL, t3 = NULL;
		split(t, t1, t2, i);
		split(t2, t2, t3, 1);
		T ans = t2->key;
		merge(t2, t2, t3);
		merge(t, t1, t2);
		return ans;
	}

	void set(int i, T x) {
		pitem t1 = NULL, t2 = NULL, t3 = NULL;
		split(t, t1, t2, i);
		split(t2, t2, t3, 1);
		t2->key = x;
		merge(t2, t2, t3);
		merge(t, t1, t2);
	}

	bool to_front_and_set_and_check(int i, int x) {
		pitem t1 = NULL, t2 = NULL, t3 = NULL;
		split(t, t1, t2, i);
		split(t2, t2, t3, 1);
		if (t2->key.first != x && t2->key.first != 0) return false;
		if (t2->key.first == 0 && !can[x]) return false;
		t2->key.first = x;
		merge(t1, t2, t1);
		merge(t, t1, t3);
		return true;
	}
	pitem t;
};

dich< pair<int, int> > a;

bool cmp1(pair<int, int> a, pair<int, int> b) {
	return a.second < b.second;
}

int main() {
	ios::sync_with_stdio(0);
	//freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);

	cin >> n >> m;

	for (int i = 0; i < n; i++) {
		a.insert(i, make_pair(0, i));
		can[i] = true;
	}
	can[n] = true;

	for (int i = 1; i <= m; i++) {
		cin >> x >> y;
		y--;
		if (!a.to_front_and_set_and_check(y, x)) {
			cout << -1;
			return 0;
		}
		can[x] = false;
	}

	vector< int > v(n);
	for (int i = 0; i < n; i++) {
		pair<int, int> pr = a.get(i);
		v[pr.second] = pr.first;
	}

	int it = 1;
	while (can[it] != true) it++;
	for (int i = 0; i < v.size(); i++)
		if (v[i] == 0) {
			printf("%d ",it++);
			while (!can[it]) it++;
		} else printf("%d ", v[i]);
}


#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <float.h>
#include <cassert>

using namespace std;

#define REP(i, from, to) for (int i = (from); i < (to); ++i)
#define FOR(i, n) REP(i, 0, (n))
#define ALL(x) x.begin(), x.end()
#define SIZE(x) (int)x.size()
#define PB push_back
#define MP make_pair

typedef long long i64;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<VS> VVS;
typedef pair<int, int> PII;

vector<int> t;
int n;

void init (int nn)
{
    n = nn;
    t.assign (n, 0);
}

int sum (int r)
{
    int result = 0;
    for (; r >= 0; r = (r & (r+1)) - 1)
        result += t[r];
    return result;
}

void inc (int i, int delta)
{
    for (; i < n; i = (i | (i+1)))
        t[i] += delta;
}

int sum (int l, int r)
{
    return sum (r) - sum (l-1);
}

void init (vector<int> a)
{
    init ((int) a.size());
    for (unsigned i = 0; i < a.size(); i++)
        inc (i, a[i]);
}

int findIndex(int index) {
    int l = 0, r = n;
    while (l < r) {
        int const m = (l + r) >> 1;
        int const count = sum(m);
        if (count < index)
            l = m + 1;
        else
            r = m;
    }

    return l;
}

void test(int m, VI a) {
    int const n = SIZE(a);
    cout << n << endl;
    while (m--) {
        int const y = rand() % n;
        int const x = a[y];

        cout << x << " " << y + 1 << endl;
        a.erase(a.begin() + y);
        a.insert(a.begin(), x);
    }

    cout << "Will be:\n";
    FOR (i, SIZE(a)) cout << a[i] << " ";
    cout << endl;
}

//#define DEBUG

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

    {
        VI a = {1,2,3};
        //test(5, a);
    }

    ios_base::sync_with_stdio(false);

    int size, m;
    cin >> size >> m;

    int const origSize = size;
    n = 2 * (m + n);
    init(n);
    FOR (i, size) inc(i, 1);

    VI index(size);
    VI state(2 * size + 100);

    VI position(origSize + 10, -1);

    FOR (i, m) {
        int x, y;
        cin >> x >> y;

        int const needIndex = origSize - y + 1;
        int const whereIndex = findIndex(needIndex);

#ifdef DEBUG
        {
            cout << "x = " << x << ", y = " << y << endl;
            cout << "needIndex = " << needIndex << endl;
            cout << "whereIndex = " << whereIndex << endl;
            cout << "position[" << x << "] = " << position[x] << endl;
            cout << "prev position index = " << sum(position[x]) << endl;
        }
#endif

        int const whatThere = state[whereIndex];
        if (whatThere && whatThere != x) {
            //cout << "another number is at the " << whereIndex << " position.\n";
            cout << "-1\n";
            return 0;
        }

        if (position[x] != -1 && sum(position[x]) != needIndex) {
            cout << "-1\n";
            return 0;
        }

        inc(whereIndex, -1);
        state[size] = x;
        inc(size, 1);
        position[x] = size;

#ifdef DEBUG
        cout << "size = " << size << endl;

        cout << "State: ";
        FOR (i, size + 1) {
            cout << sum(i, i) << " ";
        }
        cout << endl;

        cout << "sum(position[x]) = " << sum(position[x]) << endl;
        assert(sum(position[x]) == origSize);
        cout << "new position[" << x << "] = " << position[x] << endl;
#endif
        ++size;

        if (whereIndex < origSize) {
            index[origSize - whereIndex - 1] = x;
#ifdef DEBUG
            cout << "write to " << origSize - whereIndex - 1 << ", x = " << x << endl;
#endif
        }
    }

    set<string> notUsed;
    FOR (i, origSize) {
        ostringstream oss;
        oss << i + 1;
        notUsed.insert(oss.str());
    }
    FOR (i, origSize) if (index[i]) {
        ostringstream oss;
        oss << index[i];
        notUsed.erase(oss.str());
    }

    FOR (i, origSize) {
        if (i) cout << " ";
        if (!index[i]) {
            index[i] = atoi((*notUsed.begin()).c_str());
            notUsed.erase(notUsed.begin());
        }
        cout << index[i];
    }

    cout << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define M 1000000007LL
typedef long long ll;
#define all(a) a.begin() , a.end()
ll power(ll a, ll b)
{
    if(b==0)    return 1LL;
    if(b==1)    return a%M;
    if(b%2==0)  return power((a%M * a%M)%M , b/2) %M;
    return  (a%M * power((a%M * a%M)%M , (b-1)/2)%M) %M;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    freopen("input.txt" , "r" , stdin);
    ll x,n;
    cin>>x>>n;
    vector<ll> pf;
    if(x%2==0)
    {
        pf.push_back(2);
        while(x%2==0)   x/=2;
    }
    for(ll i=3;i*i<=x;i+=2)
    {
        if(x%i==0)
        {
            pf.push_back(i);
            while(x%i==0)   x/=i;
        }
    }
    if(x>2) pf.push_back(x);
    sort(all(pf));
    ll ans=1,prev=0;
    for(ll kk: pf)
    {
        ll temp=kk;
        while(1)
        {
            if(n/temp < kk) break;
            else temp*=kk;
        }
        prev=0;
        while(temp>=kk)
        {
            ll pp=(n/temp)-prev;
            prev=n/temp;
            pp = power(temp%M,pp)%M;
            ans= (ans%M * pp%M ) % M;
            temp/=kk;
        }
    }
    cout<<ans<<"\n";
    return 0;
}


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28010.2050
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MinimumTriangulation", "MinimumTriangulation\MinimumTriangulation.vcxproj", "{633E15BA-0B29-4130-A608-AAF297BB8BD8}"
EndProject
Global
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
		Debug|x64 = Debug|x64
		Debug|x86 = Debug|x86
		Release|x64 = Release|x64
		Release|x86 = Release|x86
	EndGlobalSection
	GlobalSection(ProjectConfigurationPlatforms) = postSolution
		{633E15BA-0B29-4130-A608-AAF297BB8BD8}.Debug|x64.ActiveCfg = Debug|x64
		{633E15BA-0B29-4130-A608-AAF297BB8BD8}.Debug|x64.Build.0 = Debug|x64
		{633E15BA-0B29-4130-A608-AAF297BB8BD8}.Debug|x86.ActiveCfg = Debug|Win32
		{633E15BA-0B29-4130-A608-AAF297BB8BD8}.Debug|x86.Build.0 = Debug|Win32
		{633E15BA-0B29-4130-A608-AAF297BB8BD8}.Release|x64.ActiveCfg = Release|x64
		{633E15BA-0B29-4130-A608-AAF297BB8BD8}.Release|x64.Build.0 = Release|x64
		{633E15BA-0B29-4130-A608-AAF297BB8BD8}.Release|x86.ActiveCfg = Release|Win32
		{633E15BA-0B29-4130-A608-AAF297BB8BD8}.Release|x86.Build.0 = Release|Win32
	EndGlobalSection
	GlobalSection(SolutionProperties) = preSolution
		HideSolutionNode = FALSE
	EndGlobalSection
	GlobalSection(ExtensibilityGlobals) = postSolution
		SolutionGuid = {884BAD39-E042-4223-9661-79BF82D2ECD2}
	EndGlobalSection
EndGlobal


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

int main(){
int n ,f,c;
string ch;

do {
    cin>>n;
    cin>>ch;
   }
    while ((n<=2)||(n>=100)||(ch.size()!=n));
    c=0;
   f=0;

for (int i=0;i<n;i++){
 if ((ch[i]=='S')&&(ch[i+1]=='F'))
    c=c+1;
   if ((ch[i]=='F')&&(ch[i+1]=='S'))
        f=f+1;}
    if (c>f)
        {cout<<"YES"<<endl;}
 else
    {cout<<"NO"<<endl;}

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define pb push_back
#define sz(x)  ((int)x.size ())
#define all(x) (x).begin(), (x).end()
#define re return
#define mp make_pair
#define sqrt(x) sqrt (abs(x))
#define y0 y3451
#define y1 y4562
#define unq(x) (x.resize(unique(all(x)) - x.begin()))
#define x0 j25624
#define x1 j45624
#define makeunq(x) sort(all(x)), (x).resize (unique(x) - (x).begin())

typedef pair <int, int> ii;
typedef long long ll;
typedef unsigned long long ull;
typedef double D;
typedef long double ld;
typedef unsigned int uint;
typedef vector <string> vs;
typedef vector <int> vi;
typedef vector <ii> vii;
typedef vector <vi> vvi;

template <class T> T abs (T x) { re x > 0 ? x : -x; }
template <class T> T sqr (T x) { re x * x; }
template <class T> T gcd (T a, T b) { re a ? gcd (b % a, a) : b; }
template <class T> int sgn (T x) { re x > 0 ? 1 : (x < 0 ? -1 : 0); }

const ld pi = 2 * asinl((ld)1.0);

ull a[105];

main()
{ ull n;
  cin>>n;
  a[0]=1;  int ans;
  a[1]=1;
  for(i=2; ;i++)
   {  a[i]=a[i-1]+a[i-2];
       if(a[i]==n)  {ans=i-1; break;}
        if(a[i]>n)   {ans=i-2;break;}

   }
  cout<<ans;

}


#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<list>
#include<cstdlib>
#include<cmath>
#include<sstream>
#include<numeric>
#include<cstdio>
#include<cstring>
#include<stack>
#define PI acos(-1)
#define MP make_pair
#define PB push_back
#define VI vector <int>
#define PII pair <int,int>
#define LL long long
#define SET(v,i) memset(v, i, sizeof(v))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORD(i,a,b) for (int i = (a); i >= (b); i--)
#define FORN(i,a,b) for (int i = (a); i < (b); i++)
#define DOWN(i,a,b) for (int i = (a); i > (b); i--)
#define FIT(it,v) for (typeof(v.begin()) it = v.begin(); it != v.end(); it++)
#define FITD(it,v) for (typeof(v.rbegin()) it = v.rbegin(); it != v.rend(); it++)
using namespace std;
const int N=4005,mod=1000000007;
LL c[N][4],f[4];
template<class T>
inline T gcd(T a,T b){
    if(a<b)swap(a,b);
    for(T r;b;r=a%b,a=b,b=r);
    return a;
    }
int main(){
	int w,h;
	scanf("%d%d",&w,&h);
	c[0][0]=1;
	for(int i=1;i<N;i++){
		c[i][0]=1;
		for(int j=1;j<4;j++)c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;
		}

	memset(f,0,sizeof(f));
	for(int i=0;i<=w;i++){
		for(int j=0;j<=h;j++){
			f[i%2*2+j%2]++;
			}
		}

	LL cnt=0;//on line
	for(int i=1;i<=w;i++){
		for(int j=1;j<=h;j++){
			int k=gcd(i,j);
			cnt+=(w-i+1)*(h-j+1)*(k-1)%mod;
			cnt%=mod;
			}
		}
	cnt=(cnt*2+c[w+1][3]*(h+1)%mod+c[h+1][3]*(w+1)%mod)%mod;//vertical or horizontal

	LL ans=0,tot=(w+1)*(h+1);
	for(int i=0;i<4;i++){//3 diff or 2 diff
		ans+=c[f[i]][3];
		ans+=c[f[i]][2]*(tot-f[i])%mod;
		ans%=mod;
		}

	ans=((ans-cnt)%mod+mod)%mod;
	cout<<ans*6%mod<<endl;
    return 0;
    }


#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
ll mod=1000000007;
ll po(ll a,ll b)
{
	vector<int>vec;
	for(;;)
	{
		if(b==0)
		{
			break;
		}
		vec.push_back(b%2);
		b/=2;
	}
	reverse(vec.begin(),vec.end());
	ll ret=1;
	for(int i=0;i<vec.size();i++)
	{
		ret*=ret;
		ret%=mod;
		if(vec[i])
		{
			ret*=a;
			ret%=mod;
		}
	}
	return ret;
}
ll inv(ll a)
{
	return po(a,mod-2);
}
ll kai[100001];
void calc()
{
	kai[0]=1;
	for(int i=1;i<=100000;i++)
	{
		kai[i]=kai[i-1]*i;
		kai[i]%=mod;
	}
}
ll com(ll a,ll b)
{
	if(a<b)
	{
		return 0;
	}
	ll ret=kai[a];
	ret*=inv(kai[b]);
	ret%=mod;
	ret*=inv(kai[a-b]);
	ret%=mod;
	return ret;
}
ll dp[4002][4002];
ll gcd(ll a,ll b)
{
	if(a>b)
	{
		swap(a,b);
	}
	if(a==0)
	{
		return b;
	}
	for(;;)
	{
		b%=a;
		if(!b)
		{
			return a;
		}
		swap(a,b);
	}
}
int main()
{
	calc();
	int mx,my;
	scanf("%d%d",&mx,&my);
	mx++;
	my++;
	ll a,b,c,d;
	a=((mx+1)/2)*((my+1)/2);
	b=(mx/2)*((my+1)/2);
	c=((mx+1)/2)*(my/2);
	d=(mx/2)*(my/2);
	ll ret=0;
	ll sum=a+b+c+d;
	ret+=com(a,3);
	ret+=com(b,3);
	ret+=com(c,3);
	ret+=com(d,3);
	ret+=com(a,2)*(sum-a);
	ret+=com(b,2)*(sum-b);
	ret+=com(c,2)*(sum-c);
	ret+=com(d,2)*(sum-d);
	ret%=mod;
	for(int i=1;i<mx;i++)
	{
		for(int j=1;j<my;j++)
		{
			dp[i+1][j+1]=(dp[i][j+1]+dp[i+1][j]-dp[i][j]+gcd(i,j)-1)%mod;
			ret-=dp[i+1][j+1]+dp[i+1][j+1];
			ret=(ret+mod+mod)%mod;
		}
	}
	ret-=mx*com(my,3);
	ret-=my*com(mx,3);
	ret%=mod;
	if(ret<0)
	{
		ret+=mod;
	}
	ret*=6;
	ret%=mod;
	printf("%I64d\n",ret);
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
using namespace std;
const int M=1000000007;
long long dp[2][2];
int gcd[4010][4010];
long long cal(int n,int d1,int d2)
{
    if(!(d1&1)&&!(d2&1))
    {
        int n1=n/2+1;
        n1=1LL*n1*(n1-1)*(n1-2)/6%M;
        int n2=(n+1)/2;
        n2=1LL*n2*(n2-1)*(n2-2)/6%M;
        return (n1+n2)%M;
    }
    return cal(n+(d1&1)+(d2&1),0,0);
}
vector <int> p[10];int cn;
int main()
{
    int n,m;
    memset(dp,-1,sizeof(dp));
    vector <int> pp;pp.clear();for(int i=0;i<3;i++)pp.push_back(i);
    do
    {
        p[cn++]=pp;
    }while(next_permutation(pp.begin(),pp.end()));
    int cao[5];

    while(~scanf("%d %d",&n,&m))
    {
        for(int i=0;i<=n;i++)
        for(int j=0;j<=m;j++)
        if(i == 0)gcd[i][j] = j;
        else if(j == 0)gcd[i][j] = i;
        else if(i < j)gcd[i][j] = gcd[i][j%i];
        else gcd[i][j] = gcd[i%j][j];
        dp[0][0]=cal(m,0,0);
        dp[0][1]=cal(m,0,1);
        dp[1][0]=cal(m,1,0);
        dp[1][1]=cal(m,1,1);
        long long ans=0,temp,k;
        int dd,d1,d2,cnt;bool sum;
        for(int dx1=1;dx1<=n;dx1++)
        for(int dx2=1;dx2<=n;dx2++)
        {
            if(dx1+dx2>n)break;
            temp=0;
            for(cao[1]=0;cao[1]<2;++cao[1])
            for(cao[2]=0;cao[2]<2;++cao[2])
            {
                cnt=0;
                for(int i=0;i<cn;++i)
                {
                    sum=0;
                    if(dx1&1||(cao[p[i][1]]-cao[p[i][0]])&1)sum^=1;
                    if(dx2&1||(cao[p[i][2]]-cao[p[i][1]])&1)sum^=1;
                    if((dx1+dx2)&1||(cao[p[i][0]]-cao[p[i][2]])&1)sum^=1;
                    if(!sum)++cnt;
                }
                temp=temp+cnt*dp[cao[1]][cao[2]];
            }
            dd=gcd[dx1][dx2];
            d1=dx1/dd;
            d2=dx2/dd;
            k=(m+1)/(d1+d2);
            temp-=2*(m+1)*k-k*(k+1)*(d1+d2);
            temp=temp%M*(n+1-dx1-dx2);
            ans=(ans+temp)%M;
        }

        int n1=n/2+1;
        int nn1=1LL*n1*(n1-1)/2%M;
        int n2=(n+1)/2;
        int nn2=1LL*n2*(n2-1)/2%M;
        int nn3=1LL*(n+1)*n/2%M-(nn1+nn2)%M;
        int m1=m/2+1;
        int mm1=1LL*m1*(m1-1)/2%M;
        int m2=(m+1)/2;
        int mm2=1LL*m2*(m2-1)/2%M;
        int mm3=1LL*(m+1)*m/2%M-(mm1+mm2)%M;

        ans=(ans+1LL*m*(m+1)%M*(nn1+nn2)%M*(n-1)%M)%M;
        ans=(ans+1LL*nn3*m1%M*(m1-1)%M*(n-1)%M)%M;
        ans=(ans+1LL*nn3*m2%M*(m2-1)%M*(n-1)%M)%M;

        ans=(ans+1LL*n*(n+1)%M*(m+1)%M*(mm1+mm2)%M)%M;
        ans=(ans+1LL*mm3*n1%M*(n1-1)%M*(m+1)%M)%M;
        ans=(ans+1LL*mm3*n2%M*(n2-1)%M*(m+1)%M)%M;

        ans=6LL*ans%M;
        ans=(ans+M)%M;
        printf("%d\n",ans);
        return 0;
    }
}


#include <iostream>
using namespace std;
const int NMax = 25;
int N, M;
int A[NMax], B[NMax];
int DP[NMax][NMax];
int Matrix[NMax * 2][NMax * 2];
void Read()
{
    cin >> N >> M;
    for(int i = 1; i <= N; i++)
        cin >> A[i];
    for(int i = 1; i <= N; i++)
        cin >> B[i];
}
void initialize()
{
    for(int i = 0; i <= 2 * N; i++)
        DP[0][i] = 0x3f3f3f3f;
}
void buildDP()
{
    DP[0][N] = 0;
    for(int i = 1; i <= N; i++)
    {
        for(int j = - N; j <= N; j++)
        {
            DP[i][j + N] = 0x3f3f3f3f;
            DP[i][j + N] = min(DP[i - 1][j + 1 + N] + B[i], DP[i - 1][j - 1 + N] + A[j]);
        }
    }
}

void buildMatrix()
{
    for(int i = 0; i <= 2 * N; i++)
        for(int j = 0; j <= 2 * N; j++)
            Matrix[i][j] = DP[N][i - j + N];
}

void
int main()
{
    cout << "Hello world!" << endl;
    return 0;
}


#include<bits/stdc++.h>
#include<limits.h>
#define lli long long
#define ull unsigned long long
#define f(a,k,m) for(int a=k ; a<m ; a++)
#define fl(a,k,m) for(long a=k ; a<m ; a++)
#define fll(a,k,m) for(lli a=k ; a<m ; a++)
#define rf(a,k,m) for(int a=k ; a>=m ; a--)
#define rfl(a,k,m) for(long a=k ; a>=m ; a--)
#define rfll(a,k,m) for(lli a=k ; a>=m ; a--)
#define pb push_back
#define mp make_pair
#define pq priority_queue
#define M 1000000007
#define Mcf 998244353
using namespace std ;
int main(){
    long n, m,r ;
    cin >> n >> m >> r ;
    long b[n] ;
    fl(i,0,n) cin >> b[i] ;
    long s[m] ;
    fl(i,0,m) cin >> s[i] ;
    long* x,*y;
    x = min_element(b,b+n) ;
    y = max_element(s,s+m) ;
    long xx = (*x) ;
    long yy = (*y) ;
    if(xx >= yy){
        cout << r ;
    }

    if(r/xx > 0 && yy > xx){
        cout << r - xx*(r/xx) +  yy*(r/xx) ;

    }

	return 0 ;
}


#include <iostream>
#include <cstring>
using namespace std;
int ct;
int main(int argc, char** argv) {
	int n,a=0;
	cin>>n;

	cout<<(n-1)*2;
	return 0;
}


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

int main(){
	int n,m,b;
	cin>>n>>m>>b;
	int a[n],e[m];
	for(int i=0; i<n; i++)
		cin>>a[i];
	for(int i=0; i<m; i++)
		cin>>e[i];
	sort(a,a+n);
	sort(e,e+m);
	if(e[m-1] <= a[0]){
		cout<<b<<endl;
		return 0;
	}
	int i=0,j=m-1,count=0;
	while((b > 0) && (b > a[0])){
		int x=(b/a[i]);
		b-=(x*a[i]);
		count+=x*e[j];
		//cout<<count<<"--->"<<b<<endl;
		i++;
		j--;
	}
	cout<<count+b<<endl;
	return 0;
}


#include <iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <iomanip>
#include<string.h>
#include <map>
#define LL long long
#define MM 1000000007
using namespace std;
int main()
{
    LL n,m,b,i,min=10007,max=0,ans;
    cin>>n>>m>>b;
    LL s[n],c[n];
    for(i=0;i<n;i++)
    {
        cin>>c[i];
        if(min>c[i])
        min=c[i];
    }
    for(i=0;i<m;i++)
    {
        cin>>s[i];
         if(max<s[i])
         max=s[i];
    }

    if(max<=min)
    ans=b;
    else
    ans=(b/min)*max+(b%min);

    cout<<ans<<endl;

	return 0;
}


#include <bits/stdc++.h>

typedef long long ll;
//#define int ll
#define x first
#define y second
#define pii pair<int, int>
using namespace std;

vector<int> d;
vector<vector<int>> tmp, g;
int n, m, k;
void bfs(int v){
    d.resize(n, INT_MAX);
    d[v] = 0;
    queue<int> q;
    q.push(v);
    while (!q.empty()){
        int u = q.front(); q.pop();
        for (int &t : g[u]){
            if (d[t] > d[u] + 1){
                d[t] = d[u]+1;
                q.push(t);
            }
        }
    }
    tmp.resize(n);
    for (int i = 0; i < n; ++i){
        tmp[d[i]].push_back(i);
    }
}
signed main() {
    ios_base::sync_with_stdio(false); cout.tie(0); cin.tie(0);
    cin >> n >> m;
    g.resize(n);
    int f, t;
    for (int i = 0; i< m; ++i){
        cin >> f >> t;
        f--; t--;
        g[t].push_back(f);
    }
    cin >> k;
    vector<int> path(k);
    for (int i = 0; i < k; ++i) {
        cin >> path[i];
        path[i]--;
    }
    bfs(path[k-1]);
    for (int i = 0; i < n; ++i){
        sort(tmp[i].begin(), tmp[i].end());
    }
    for (int i = 0; i< n; ++i){
        sort(g[i].begin(), g[i].end());
    }
    int mi = 0, ma = 0;
    for (int i = 1; i < k; ++i){
        int v = path[i-1], u = path[i], dist = d[v]-1;
        if (tmp[dist].empty()){
            mi++;
            ma++;
        }
        else if (tmp[dist].size() == 1){
            if (tmp[dist][0] != u){
                mi++;
                ma++;
            }
        }
        else {
            if (!binary_search(tmp[dist].begin(), tmp[dist].end(), u)){
                mi++;
            }
            for (int &j : tmp[dist]){
                if (j == u) continue;
                if (binary_search(g[j].begin(), g[j].end(), v)){
                    ma++;
                    break;
                }
            }
        }
    }
    cout << mi << ' ' << ma << '\n';
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int MXN = 2e5 + 10;

typedef long long llong;

int n, m, k, p[MXN], dp[MXN], ansl, ansr;
vector<int> g[MXN], g1[MXN];

void bfs(int t){
    for(int i = 1; i <= n; i++){
        dp[i] = 1e9;
    }
    dp[t] = 0;
    deque<int> q;
    q.push_back(t);
    while(!q.empty()){
        int x = q.front();
        q.pop_front();
        for(int i = 0; i < g[x].size(); i++){
            int to = g[x][i];
            if(dp[x] + 1 <= dp[to]){
                dp[to] = dp[x] + 1;
                q.push_back(to);
            }
        }
    }
}

int main(){
    //freopen("input.txt", "r", stdin);
    cin >> n >> m;
    for(int i = 1; i <= m; i++){
        int u, v;
        cin >> u >> v;
        g[v].push_back(u);
        g1[u].push_back(v);
    }
    cin >> k;
    for(int i = 1; i <= k; i++){
        cin >> p[i];
    }
    bfs(p[k]);
    for(int i = 1; i < k; i++){
        int x = p[i];
        int mn = 1e9, pos = 0;
        for(int j = 0; j < g1[x].size(); j++){
            int to = g1[x][j];
            if(dp[to] < mn){
                mn = dp[to];
                pos = to;
            }
        }
        if(dp[p[i + 1]] > mn){
            ansl++;
            ansr++;
            continue;
        }
        for(int j = 0; j < g1[x].size(); j++){
            int to = g1[x][j];
            if(dp[to] == mn && p[i + 1] != to){
                ansr++;
                break;
            }
        }
    }
    cout << ansl << ' ' << ansr;

}


#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int fact(ll x);
int main()
{
    ll a,b;
    cin>>a>>b;
    ll ans = min(a,b);
    cout<<ans<<endl;
    return 0;
}
int fact(ll x)
{
    ll ans=1;
    for (int i=1 ;i<=x;++i)
    {
        ans*=i;
    }
    return ans;
}


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

int main() {
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);
    ll l, r, x, y;
    cin >> l >> r >> x >> y;
    int cnt = 0;
    ll root = sqrtl(x)+1;
    vector<ll> factors;
    for(ll i = 2; i <= root; ++i) {
        if(x%i == 0) {
            factors.push_back(i);
            factors.push_back(x/i);
        }
    }
    if(x > 1) factors.push_back(x);
    root = sqrtl(y)+1;
    for(ll i = 2; i <= root; ++i) {
        if(y%i == 0) {
            vector<ll> temp;
            temp.push_back(i);
            temp.push_back(y/i);
            for(ll f : factors) {
                if((long double)f*i <= x*y)
                temp.push_back(f*i);
                if((long double)f*i <= x*y)
                temp.push_back(f*y/i);
            }
            for(auto &f : temp) factors.push_back(f);
        }
    }
    if(y > 1) {
        vector<ll> temp;
        for(ll f : factors) {
            if((long double)f*y <= x*y)
            temp.push_back(f*y);
        }
        for(auto &f : temp) factors.push_back(f);
    }
    factors.push_back(1);
    factors.push_back(x*y);
    sort(factors.begin(), factors.end());
    factors.erase(unique(factors.begin(), factors.end()), factors.end());
    for(ll f1 : factors) {
        ll f2 = x*y/f1;
        if(__gcd(f1,f2) == x && f1*f2/__gcd(f1,f2) == y && f1 <= f2 && f1 >= l && f1 <= r && f2 >= l && f2 <= r) {
            cnt += 2;
            if(f1 == f2) {
                cnt--;
            }
        }
    }
    cout << cnt << '\n';
    return 0;
}


#include<iostream>
#include<vector>
using namespace std;
int main()
{
    long long int a, b, x, y,ans=0 ; cin >> x >> y >> a >> b; vector<int> c, d;
    for (long long int i = 1; (i*x) <= b; i++)if (i*x >= a)c.push_back(i*x); for (long long int i = 1; (i*y) <= b; i++)if (i*y >= a)d.push_back(i*y);
    vector<int>::iterator it1 = c.begin(), it2 = d.begin();
    while (it1 < c.end()&&it2 < d.end())
    {
        if (*it1 == *it2){ it1++; it2++; ans++; }
        else if (*it1 < *it2){ it1++; }
        else it2++;
    }
    cout << ans << endl;
    return 0;
}


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

main ()
{
    int a, b, c, d, e, f, i, j = 0, ta, tb, sh = 5, sm = 0, th = 5, tm = 0;
    char ch;
    cin >> a >> ta;
    cin >> b >> tb;
    cin >> c >> ch >> d;
    sm += tb;
    while (sh != c || sm != d)
    {
         if (sh >= c && sm > d) {
            break;
        }
        sm += b;
        while (sm >= 60) {
            sh++;
            sm -= 60;
        }

        if (sh >= c && sm > d) {
            break;
        }
    }

    sm -= tb;
    while (sm < 0) {
        sh--;
        sm += 60;
    }

    d += ta;
    while (d >= 60) {
        c++;
        d -= 60;
    }

    while (sh < c || sm < d)
    {
        sm += b;
        while (sm >=60) {
            sh++;
            sm -= 60;
        }
        j++;
    }
    cout << j;
}


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

ll n , k , l , c , d , p , xl , np , kl , cd , fnp;

int main(){
	cin >> n >> k >> l >> c >> d >> p >> xl >> fnp;
	kl = k * l; cd = c * d;
	int uuu = kl / xl;
	int ans = cd;
	if (uuu < ans) ans = uuu;
	int kkk = p / np;
	if (kkk < ans) ans = kkk;
	cout << ans;
}


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

typedef struct aa{
	int a,b,w;
}AA;
int n;
AA a[200200];
bool tri(int a,int b,int c){
	if(a+b<=c) return false;
	if(b+c<=a) return false;
	if(a+c<=b) return false;
	return true;
}
int main(){
	int i,j;
	while(scanf("%d",&n)!=EOF){
		int l=0;
		for(i=1;i<n;i++){
			for(j=i+1;j<=n;j++){
				a[l].a=i;
				a[l].b=j;
				a[l++].w=(i^j);
			}
		}
		int ans=0;
		for(i=0;i<l;i++){
			for(j=a[i].b+1;j<=n;j++){
				if(a[i].a==j || a[i].b==j) continue;
				if((a[i].w^j)==0){
					if(tri(a[i].a,a[i].b,j)) ans++;
				}
			}
		}
		printf("%d\n",ans);
	}
}


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

typedef struct aa{
	int a,b,w;
}AA;
int n;
AA a[60000000];
bool tri(int a,int b,int c){
	if(a+b<=c) return false;
	if(b+c<=a) return false;
	if(a+c<=b) return false;
	return true;
}
int main(){
	int i,j;
	while(scanf("%d",&n)!=EOF){
		int l=0;
		for(i=1;i<n;i++){
			for(j=i+1;j<=n;j++){
				a[l].a=i;
				a[l].b=j;
				a[l++].w=(i^j);
			}
		}
		int ans=0;
		for(i=0;i<l;i++){
			for(j=a[i].b+1;j<=n;j++){
				if(a[i].a==j || a[i].b==j) continue;
				if((a[i].w^j)==0){
					if(tri(a[i].a,a[i].b,j)) ans++;
				}
			}
		}
		printf("%d\n",ans);
	}
}


#include <iostream>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cstring>
#include <deque>
#include <queue>
#include <numeric>
#include <sstream>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
long long C(long long n, int k) {
    if (k == 2)
        return n * (n - 1) / 2;
    else
        return n * (n - 1) * (n - 2) / 6;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    long long n;
    long double p;
    cin >> n >> p;
    vector<vector<long double>> dp(n + 1, vector<long double> (n + 1));
    dp[1][1] = dp[2][2] = 1;
    dp[2][1] = 0.5;
    for (int i = 4 - n % 2; i <= n; i += 2) {
        for (int j = 1; j <= i; ++j) {
            dp[i][j] = (C(j, 3) * ((j - 2 + (i - j) * dp[i - 2][j - 2])) + (i - j) * C(j, 2) * (j - 1 + (i - j - 1) * dp[i - 2][j - 1]) + j * C(i - j, 2) * (2 * j - 1 + (i - j - 2) * dp[i - 2][j] + (i - j - 1) * dp[i - 2][j - 1]) / 2 + C(i - j, 3) * (j + (i - j - 2) * dp[i - 2][j])) / (i - 2) / C(i, 3);
        }
    }
    int i = 0;
    while (dp[n][i] < p)
        ++i;
    cout << i;
    return 0;
}


#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define ll long long
#define PII pair<int,int>
const ll N=50 , INF=1e9 , mod=998244353 , Z=180;

struct Matrix
{	ll M[Z][Z];

	ll* operator[](int i) {	  return M[i];	}

	Matrix operator *(const Matrix& B)
	{	static Matrix T1;
		memset(T1.M,0,sizeof T1.M);
		for(int i=0;i<Z;i++)
		for(int j=0;j<Z;j++)
		for(int k=0;k<Z;k++)
		T1[i][j]+=M[i][k]*B[k][j],T1[i][j]%=mod;
		return T1;
	}

};
	Matrix fmi(Matrix& G, ll pow)
	{
		static Matrix T2;
		memset(T2.M,0,sizeof T2.M);
		for(int i=0;i<Z;i++) T2[i][i]=1;

		while(pow)
		{	if(pow&1) T2=T2*G;
			G=G*G;
			pow>>=1;
		}
		return T2;
	}

Matrix M0,M1,res;

struct Trie
{
	int ch[N][26];
	bool ed[N];
	int idx=0;

	void insert(char s[])
	{	int p=0;
		for(int i=0;s[i];i++)
		{	int c=s[i]-'a';
			if(!ch[p][c]) ch[p][c]=++idx;
			p=ch[p][c];
		}
		ed[p]=1;
	}

	int mp[3000],idn;
	bool ED[3000];

	int dfs(int u,int v)
	{	if(mp[u*N+v]) return mp[u*N+v];

		mp[u*N+v]=++idn;
		ED[idn]=(ed[u]&&ed[v]);
		int x=idn , su , sv ;

		for(int i=0;i<26;i++)
		{
			if(ch[u][i])
			{
				if(ch[v][i])
				{	su=ch[u][i] , sv=ch[v][i];
					M1[x][dfs(su,sv)]++;
				}
				if(ed[v]&&ch[0][i])
				{	su=ch[u][i] , sv=ch[0][i];
					M1[x][dfs(su,sv)]++;
				}
			}

			if(ed[u]&&ch[0][i])
			{	if(ch[v][i])
				{	su=ch[0][i] , sv=ch[v][i];
					M1[x][dfs(su,sv)]++;
				}
				if(ed[v]&&ch[0][i])
				{	su=ch[0][i] , sv=ch[0][i];
					M1[x][dfs(su,sv)]++;
				}
			}
		}
		return mp[u*N+v];
	}

	void solve(int m)
	{	idn=0;
		memset(mp,0,sizeof mp);
		memset(ED,0,sizeof ED);

		for(int c=0;c<26;c++) if(ch[0][c]) dfs(ch[0][c],ch[0][c]);

		for(int c=0;c<26;c++) if(ch[0][c]) M0[0][mp[ch[0][c]*N+ch[0][c]]]++;
		res=M0*fmi(M1,m-1);
		ll ans=0;
		for(int i=1;i<=idn;i++) if(ED[i]) ans=(ans+res[0][i])%mod;
		printf("%lld",ans);
	}

}trie;

char s[10];
signed main()
{	int n,m;scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%s",s),trie.insert(s);
	trie.solve(m);
    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#define int long long
#define pa pair<int ,int >
#define mp make_pair
using namespace std;
inline int read(){int x=0,f=1,ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}
inline void write(int x){if (x<0) putchar('-'),x=-x; if (x>=10) write(x/10); putchar(x%10+'0');}
inline void writeln(int x){write(x); puts("");}
const int N=45,M=161,mod=998244353;
int root,n,m,cnt,End[N],tran[N][26];
char s[N];
inline void insert(){

	int now=root,len=strlen(s+1);
	for (int i=1;i<=len;i++){
		int c=s[i]-'a';
		if (tran[now][c]==-1) tran[now][c]=++cnt;
		 now=tran[now][c];
	}
	End[now]|=1;
}
inline void init(){
	memset(tran,-1,sizeof tran);
	n=read(); m=read(); root=0;
	for (int i=1;i<=n;i++){
		scanf("%s",s+1);
		insert();
	}
}
struct matrix{
	int mat[M][M];
	matrix() {memset(mat,0,sizeof(mat));}
	matrix operator * (const matrix &C) const
	{
		matrix ans;
		for(int i=0;i<M;i++)
			for(int j=0;j<M;j++)
				for(int k=0;k<M;k++)
					ans.mat[i][j]=(ans.mat[i][j]+mat[i][k]*C.mat[k][j]%mod)%mod;
		return ans;
	}
}A;
pa q[M];
int h,t;
map<pa,int >id;
int get(pa p){
	if (p.first>p.second) swap(p.first,p.second);
	if (!id.count(p)){
		int k=id.size();
		id[p]=k;
		q[++t]=p;
	}
	return id[p];
}
inline matrix pow(matrix B,int k){
	matrix C;
	for (int i=0;i<M;i++) C.mat[i][i]=1;
	for (;k;k>>=1,B=B*B){
		if (k&1) C=C*B;
	}
	return C;
}
inline void solve(){
	id[mp(0,0)]=0; q[++t]=(pa){0,0};
	while (h<t){
		pa u=q[++h];
		int x=get(u);
		for (int c=0;c<26;c++){
			pa nxt=mp(tran[u.first][c],tran[u.second][c]);
			if (nxt.first==-1||nxt.second==-1) continue;
			A.mat[x][get(nxt)]++;
			if (End[tran[u.first][c]]) A.mat[x][get(mp(0,nxt.second))]++;
			if (End[tran[u.second][c]]) A.mat[x][get(mp(nxt.first,0))]++;
			if (End[tran[u.first][c]]&&End[tran[u.second][c]]) A.mat[x][0]++;
		}
	}
	writeln(pow(A,m).mat[0][0]);
}
signed main(){
	init(); solve();
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

template<class Fun>
class y_combinator_result {
  Fun fun_;
public:
  template<class T>
  explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}

  template<class ...Args>
  decltype(auto) operator()(Args &&...args) {
    return fun_(std::ref(*this), std::forward<Args>(args)...);
  }
};

template<class Fun>
decltype(auto) make_fun(Fun &&fun) {
  return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  struct Node {
    char c;
    int cnt;
    vector<Node*> sons;
    Node(char _c = 0, char _cnt = 0): c(_c), cnt(_cnt) {
      sons.clear();
    }
  };
  Node* root = new Node();
  auto insert = make_fun([&](auto insert, Node* cur, const string& s, int depth) -> void {
    if (depth == (int)s.size()) {
      cur->cnt += 1;
      return;
    }
    for (auto son: cur->sons) {
      if (son->c == s[depth]) {
        insert(son, s, depth + 1);
        return;
      }
    }
    cur->sons.push_back(new Node(s[depth], 0));
    insert(cur->sons.back(), s, depth + 1);
  });
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    insert(root, s, 0);
  }
  map<Node*, string> path;
  auto dfs = make_fun([&](auto dfs, Node* cur) -> void {
    for (auto son: cur->sons) {
      if (cur == root) {
        path[son] = son->c;
      } else {
        path[son] = path[cur] + son->c;
      }
      dfs(son);
    }
  });
  dfs(root);
  vector<pair<Node*, Node*>> states;
  for (auto t: path) {
    states.push_back(make_pair(t.first, t.first));
  }
  for (auto t1: path) {
    string s1 = t1.second;
    for (auto t2: path) {
      string s2 = t2.second;
      if (s1.size() < s2.size()) {
        if (s2.substr((int)s2.size() - (int)s1.size()) == s1) {
          states.push_back(make_pair(t1.first, t2.first));
          states.push_back(make_pair(t2.first, t1.first));
        }
      }
    }
  }
  int msize = states.size();
  map<pair<Node*, Node*>, int> id;
  for (int i = 0; i < msize; i++) {
    id[states[i]] = i;
  }
  vector<vector<int>> dp(m + 1, vector<int>(msize));
  auto getNext = [&](int state) -> vector<int> {
    Node *x, *y;
    if (state == -1) {
      x = root;
      y = root;
    } else {
      x = states[state].first;
      y = states[state].second;
    }
    vector<int> ret;
    auto go = [&](Node* x, Node *y) -> void {
      for (auto son_x: x->sons) {
        for (auto son_y: y->sons) {
          if (!id.count(make_pair(son_x, son_y))) {
            continue;
          }
          ret.push_back(id[make_pair(son_x, son_y)]);
        }
      }
    };
    go(x, y);
    if (x->cnt) {
      go(root, y);
    }
    if (y->cnt) {
      go(x, root);
    }
    if (x->cnt && y->cnt) {
      go(root, root);
    }
    sort(ret.begin(), ret.end());
    ret.erase(unique(ret.begin(), ret.end()), ret.end());
    return ret;
  };
  using Mat = vector<vector<int>>;
  Mat base(msize, vector<int>(1));
  for (auto state: getNext(-1)) {
    base[state][0] = 1;
  }
  Mat Tr(msize, vector<int>(msize));
  for (int i = 0; i < msize; i++) {
    for (auto j: getNext(i)) {
      Tr[j][i] = 1;
    }
  }
  const int MOD = 998244353;
  auto mul = [&](const Mat& m1, const Mat& m2) -> Mat {
    int x = m1.size();
    int y = m2[0].size();
    Mat ret(x, vector<int>(y));
    for (int i = 0; i < x; i++) {
      for (int j = 0; j < y; j++) {
        for (int k = 0; k < msize; k++) {
          ret[i][j] = (ret[i][j] + 1LL * m1[i][k] * m2[k][j] % MOD) % MOD;
        }
      }
    }
    return ret;
  };
  auto fexp = [&](Mat x, int y) -> Mat {
    Mat ret(msize, vector<int>(msize));
    for (int i = 0; i < msize; i++) {
      ret[i][i] = 1;
    }
    for (int i = 1; i <= y; i <<= 1) {
      if (i & y) {
        ret = mul(ret, x);
      }
      x = mul(x, x);
    }
    return ret;
  };
  Tr = fexp(Tr, m - 1);
  base = mul(Tr, base);
  int ans = 0;
  for (int j = 0; j < msize; j++) {
    Node *x = states[j].first;
    Node *y = states[j].second;
    if (x->cnt && y->cnt) {
      ans = (ans + base[j][0]) % MOD;
    }
  }
  cout << ans << "\n";
  return 0;
}