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

template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define ll long long
#define ull unsigned long long
typedef vector<vector<ll>> mat;

const int N = 26;
int cnt[N] , n , out , hv[N];
string s;

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

    cin >> n;
    for(int i = 0 ; i < n ; i++)
    {
        cin >> s;
        bool inHv[N] = {};
        int bCnt = s.size() - 1;
        int fCnt = 0;
        for(auto j : s)
            hv[j - 'a'] = 1 , inHv[j - 'a'] = 1;

        while(bCnt >= 0 && s.back() == s[bCnt]) bCnt--;
        while(fCnt != s.size() && s[0] == s[fCnt]) fCnt++;

        if(bCnt == -1)
        {
            if(cnt[s.back() - 'a'])
                cnt[s.back() - 'a'] = s.size() * 2 + (cnt[s.back() - 'a'] - 1) * s.size() + cnt[s.back() - 'a'];
            else cnt[s.back() - 'a'] = s.size();
        }
        else if(s.back() == s[0])
        {
            cnt[s.back() - 'a'] = fCnt + s.size() - bCnt - 1 + (cnt[s.back() - 'a'] != 0);
        }
        else
        {
            cnt[s.back() - 'a'] = s.size() - bCnt - 1 + (cnt[s.back() - 'a'] != 0);
            cnt[s[0] - 'a'] = fCnt + (cnt[s[0] - 'a'] != 0);
        }

        for(int j = 0 ; j < N ; j++)
            if(!inHv[j])
                cnt[j] = hv[j];

        if(i == n - 1)
        {
            int pre = '1';
            int c = 0;
            for(int j = 0 ; j < s.size() ; j++)
            {
                if(pre != s[j])
                    c = 0;
                c++;
                pre = s[j];
                out = max(out , c);
            }
        }
    }
    for(int i = 0 ; i < N ; i++) out = max(out , cnt[i]);
    cout << out;

    return 0;
}


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

template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define ll long long
#define ull unsigned long long
typedef vector<vector<ll>> mat;

const int N = 26;
int cnt[N] , n , out , hv[N];
string s;

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

    cin >> n;
    for(int i = 0 ; i < n ; i++)
    {
        cin >> s;
        bool inHv[N] = {};
        int bCnt = s.size() - 1;
        int fCnt = 0;
        for(auto j : s)
            hv[j - 'a'] = 1 , inHv[j - 'a'] = 1;

        while(bCnt >= 0 && s.back() == s[bCnt]) bCnt--;
        while(fCnt != s.size() && s[0] == s[fCnt]) fCnt++;

        if(bCnt == -1)
        {
            if(cnt[s.back() - 'a'])
                cnt[s.back() - 'a'] = s.size() * 2 + (cnt[s.back() - 'a'] - 1) * s.size() + cnt[s.back() - 'a'];
            else cnt[s.back() - 'a'] = s.size();
        }
        else if(s.back() == s[0])
        {
            cnt[s.back() - 'a'] = fCnt + s.size() - bCnt - 1 + (cnt[s.back() - 'a'] != 0);
        }
        else
        {
            cnt[s.back() - 'a'] = s.size() - bCnt - 1 + (cnt[s.back() - 'a'] != 0);
            cnt[s[0] - 'a'] = fCnt + (cnt[s[0] - 'a'] != 0);
        }

        for(int j = 0 ; j < N ; j++)
            if(!inHv[j])
                cnt[j] = hv[j];

        int pre = '1';
        int c = 0;
        int inCnt[N] = {};
        for(int j = 0 ; j < s.size() ; j++)
        {
            if(pre != s[j] && pre != '1')
                inCnt[pre - 'a'] = max(inCnt[pre - 'a'] , c) , c = 0;
            c++;
            pre = s[j];
        }
        inCnt[pre - 'a'] = max(inCnt[pre - 'a'] , c);

        for(int j = 0 ; j < N ; j++)
            cnt[j] = max(cnt[j] , inCnt[j]);
    }
    for(int i = 0 ; i < N ; i++) out = max(out , cnt[i]);
    cout << out;

    return 0;
}


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

template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define ll long long
#define ull unsigned long long
typedef vector<vector<ll>> mat;

const int N = 26;
int cnt[N] , n , out , hv[N];
string s;

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

    cin >> n;
    for(int i = 0 ; i < n ; i++)
    {
        cin >> s;
        bool inHv[N] = {};
        int bCnt = s.size() - 1;
        int fCnt = 0;
        for(auto j : s)
            hv[j - 'a'] = 1 , inHv[j - 'a'] = 1;

        while(bCnt >= 0 && s.back() == s[bCnt]) bCnt--;
        while(fCnt != s.size() && s[0] == s[fCnt]) fCnt++;

        if(bCnt == -1)
        {
            if(cnt[s.back() - 'a'])
                cnt[s.back() - 'a'] = s.size() * 2 + (cnt[s.back() - 'a'] - 1) * s.size() + cnt[s.back() - 'a'];
            else cnt[s.back() - 'a'] = s.size();
        }
        else if(s.back() == s[0])
        {
            cnt[s.back() - 'a'] = fCnt + s.size() - bCnt - 1 + (cnt[s.back() - 'a'] != 0);
        }
        else
        {
            cnt[s.back() - 'a'] = s.size() - bCnt - 1 + (cnt[s.back() - 'a'] != 0);
            cnt[s[0] - 'a'] = fCnt + (cnt[s[0] - 'a'] != 0);
        }

        for(int j = 0 ; j < N ; j++)
            if(!inHv[j])
                cnt[j] = hv[j];

        int pre = '1';
        int c = 0;
        int inCnt[N] = {};
        for(int j = 0 ; j < s.size() ; j++)
        {
            if(pre != s[j] && pre != '1')
                inCnt[pre - 'a'] = max(inCnt[pre - 'a'] , c) , c = 0;
            c++;
            pre = s[j];
        }
        inCnt[pre - 'a'] = max(inCnt[pre - 'a'] , c);

        for(int j = 0 ; j < s.size() ; j++)
            if(!(s[0] == s[j] || s[j] == s[s.size() - 1]))
                cnt[s[j] - 'a'] = hv[s[j] - 'a'];

        for(int j = 0 ; j < N ; j++)
            cnt[j] = max(cnt[j] , inCnt[j]);
    }
    for(int i = 0 ; i < N ; i++) out = max(out , cnt[i]);
    cout << out;

    return 0;
}


#include<iostream>
#include<vector>
using namespace std;
const int N=1e5+2;
string s[N],t;
bool check[N][30];
int solve(int idx,char type){
	if(idx==0){
		return 0;
	}
	int lef,rig,ans=1,sum,tsz;
	if(type==' '){
		t=s[idx];
		tsz=t.size();
		sum=1;
		for(lef=1;lef<t.size();lef++){
			if(s[lef]==s[lef-1]){
				sum++;
			}
			else{
				ans=max(ans,sum);
				sum=1;
			}
		}
		ans=max(ans,sum);
		lef=0;
		rig=t.size()-1;
		while(lef<t.size()-1&&t[lef]==t[lef+1]){
			lef++;
		}
		while(rig>0&&t[rig]==t[rig-1]){
			rig--;
		}
		if(rig==0&&lef==t.size()-1){
			lef=solve(idx-1,t[0]);
			return max(ans,lef+(lef+1)*tsz);
		}
		if(t[lef]==t[rig]){
			if(check[idx-1][(t[lef]-'a'+1)]){
				return max(ans,lef+1+tsz-rig+1);
			}
			else{
				return max(ans,max(lef+1,tsz-rig));
			}
		}
		else{
			if(check[idx-1][(t[lef]-'a'+1)]){
				ans=max(ans,lef+1+1);
			}
			else{
				ans=max(ans,lef+1);
			}
			if(check[idx-1][(t[rig]-'a'+1)]){
				ans=max(ans,tsz-rig+1);
			}
			else{
				ans=max(ans,tsz-rig);
			}
			return ans;
		}
	}
	else{
		if(!check[idx][(type-'a'+1)]){
			return 0;
		}
		t=s[idx];
		tsz=t.size();
		ans=0;
		sum=0;
		for(lef=0;lef<t.size();lef++){
			if(t[lef]==type){
				sum++;
			}
			else{
				sum=0;
				ans=max(ans,sum);
			}
		}
		ans=max(ans,sum);
		lef=0;
		rig=t.size()-1;
		while(lef<t.size()&&t[lef]==type){
			lef++;
		}
		lef--;
		while(rig>=0&&t[rig]==type){
			rig--;
		}
		rig++;
		if(rig==0&&lef==t.size()-1){
			lef=solve(idx-1,type);
			return max(ans,lef+(lef+1)*tsz);
		}
		if(check[idx-1][(type-'a'+1)]){
			return max(ans,lef+1+tsz-rig+1);
		}
		else{
			return max(ans,max(lef+1,tsz-rig));
		}
	}
}
int main(){
	int n,i,j,k,ans,sum=1;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>s[i];
		t=s[i];
		for(j=1;j<=26;j++){
			check[i][j]=check[i-1][j];
		}
		for(j=0;j<t.length();j++){
			if(check[i][(t[j]-'a'+1)]==false){
				check[i][(t[j]-'a'+1)]=true;
			}
		}
	}
	t=s[n];
	ans=1;
	cout<<solve(n,' ');
}


#include<iostream>
#include<vector>
using namespace std;
const int N=1e5+2;
string s[N],t;
bool check[N][30];
int solve(int idx,char type){
	if(idx==0){
		return 0;
	}
	int lef,rig,ans=1,sum,tsz;
	if(type==' '){
		t=s[idx];
		tsz=t.size();
		sum=1;
		for(lef=1;lef<t.size();lef++){
			if(s[lef]==s[lef-1]){
				sum++;
			}
			else{
				ans=max(ans,sum);
				sum=1;
			}
		}
		ans=max(ans,sum);
		lef=0;
		rig=tsz-1;
		while(lef<t.size()-1&&t[lef]==t[lef+1]){
			lef++;
		}
		while(rig>0&&t[rig]==t[rig-1]){
			rig--;
		}
		if(rig==0&&lef==tsz-1){
			lef=solve(idx-1,t[0]);
			return max(ans,lef+(lef+1)*tsz);
		}
		if(t[lef]==t[rig]){
			if(check[idx-1][(t[lef]-'a'+1)]){
				return max(ans,lef+1+tsz-rig+1);
			}
			else{
				return max(ans,max(lef+1,tsz-rig));
			}
		}
		else{
			if(check[idx-1][(t[lef]-'a'+1)]){
				ans=max(ans,lef+1+1);
			}
			else{
				ans=max(ans,lef+1);
			}
			if(check[idx-1][(t[rig]-'a'+1)]){
				ans=max(ans,tsz-rig+1);
			}
			else{
				ans=max(ans,tsz-rig);
			}
			return ans;
		}
	}
	else{
		if(!check[idx][(type-'a'+1)]){
			return 0;
		}
		t=s[idx];
		tsz=t.size();
		ans=0;
		sum=0;
		for(lef=0;lef<t.size();lef++){
			if(t[lef]==type){
				sum++;
			}
			else{
				sum=0;
				ans=max(ans,sum);
			}
		}
		ans=max(ans,sum);
		lef=0;
		rig=t.size()-1;
		while(lef<t.size()&&t[lef]==type){
			lef++;
		}
		lef--;
		while(rig>=0&&t[rig]==type){
			rig--;
		}
		rig++;
		if(rig==0&&lef==tsz-1){
			lef=solve(idx-1,type);
			return max(ans,lef+(lef+1)*tsz);
		}
		if(check[idx-1][(type-'a'+1)]){
			return max(ans,lef+1+tsz-rig+1);
		}
		else{
			return max(ans,max(lef+1,tsz-rig));
		}
	}
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,i,j,k;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>s[i];
		t=s[i];
		for(j=1;j<=26;j++){
			check[i][j]=check[i-1][j];
		}
		for(j=0;j<t.length();j++){
			check[i][(t[j]-'a'+1)]=true;
		}
	}
	cout<<solve(n,' ');
}


#include<iostream>
#include<vector>
using namespace std;
const int N=1e5+2;
string s[N];
bool check[N][30];
int solve(int idx,char type){
	string t;
	if(idx==0){
		return 0;
	}
	int lef,rig,ans=1,sum,tsz;
	if(type==' '){
		t=s[idx];
		tsz=t.size();
		sum=1;
		for(lef=1;lef<t.size();lef++){
			if(t[lef]==t[lef-1]){
				sum++;
			}
			else{
				ans=max(ans,sum);
				sum=1;
			}
		}
		ans=max(ans,sum);
		lef=0;
		rig=tsz-1;
		while(lef<t.size()-1&&t[lef]==t[lef+1]){
			lef++;
		}
		while(rig>0&&t[rig]==t[rig-1]){
			rig--;
		}
		if(rig==0&&lef==tsz-1){
			lef=solve(idx-1,t[0]);
			return max(ans,lef+(lef+1)*tsz);
		}
		if(t[lef]==t[rig]){
			if(check[idx-1][(t[lef]-'a'+1)]){
				return max(ans,lef+1+tsz-rig+1);
			}
			else{
				return max(ans,max(lef+1,tsz-rig));
			}
		}
		else{
			if(check[idx-1][(t[lef]-'a'+1)]){
				ans=max(ans,lef+1+1);
			}
			else{
				ans=max(ans,lef+1);
			}
			if(check[idx-1][(t[rig]-'a'+1)]){
				ans=max(ans,tsz-rig+1);
			}
			else{
				ans=max(ans,tsz-rig);
			}
			return ans;
		}
	}
	else{
		t=s[idx];
		tsz=t.size();
		ans=0;
		sum=0;
		for(lef=0;lef<t.size();lef++){
			if(t[lef]==type){
				sum++;
			}
			else{
				sum=0;
				ans=max(ans,sum);
			}
		}
		ans=max(ans,sum);
		lef=0;
		rig=t.size()-1;
		while(lef<t.size()&&t[lef]==type){
			lef++;
		}
		lef--;
		while(rig>=0&&t[rig]==type){
			rig--;
		}
		rig++;
		if(rig==0&&lef==tsz-1){
			lef=solve(idx-1,type);
			return max(ans,lef+(lef+1)*tsz);
		}
		if(check[idx-1][(type-'a'+1)]){
			return max(ans,lef+1+tsz-rig+1);
		}
		else{
			return max(ans,max(lef+1,tsz-rig));
		}
	}
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	string t;
	int n,i,j,k;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>s[i];
		t=s[i];
		for(j=1;j<=26;j++){
			check[i][j]=check[i-1][j];
		}
		for(j=0;j<t.length();j++){
			check[i][(t[j]-'a'+1)]=true;
		}
	}
	cout<<solve(n,' ');
}


#include<iostream>
#include<vector>
using namespace std;
const int N=1e5+2;
string s[N];
bool check[N][30];
int solve(int idx,char type){
	string t;
	if(idx==0){
		return 0;
	}
	int lef,rig,ans=1,sum,tsz;
	if(type==' '){
		t=s[idx];
		tsz=t.size();
		sum=1;
		for(lef=1;lef<t.size();lef++){
			if(t[lef]==t[lef-1]){
				sum++;
			}
			else{
				ans=max(ans,sum);
				sum=1;
			}
		}
		ans=max(ans,sum);
		lef=0;
		rig=tsz-1;
		while(lef<t.size()-1&&t[lef]==t[lef+1]){
			lef++;
		}
		while(rig>0&&t[rig]==t[rig-1]){
			rig--;
		}
		if(rig==0&&lef==tsz-1){
			lef=solve(idx-1,t[0]);
			return max(ans,lef+(lef+1)*tsz);
		}
		if(t[lef]==t[rig]){
			if(check[idx-1][(t[lef]-'a'+1)]){
				return max(ans,lef+1+tsz-rig+1);
			}
			else{
				return max(ans,max(lef+1,tsz-rig));
			}
		}
		else{
			if(check[idx-1][(t[lef]-'a'+1)]){
				ans=max(ans,lef+1+1);
			}
			else{
				ans=max(ans,lef+1);
			}
			if(check[idx-1][(t[rig]-'a'+1)]){
				ans=max(ans,tsz-rig+1);
			}
			else{
				ans=max(ans,tsz-rig);
			}
			return ans;
		}
	}
	else{
		if(!check[idx][(type-'a'+1)]){
			return 0;
		}
		t=s[idx];
		tsz=t.size();
		ans=0;
		sum=0;
		for(lef=0;lef<t.size();lef++){
			if(t[lef]==type){
				sum++;
			}
			else{
				sum=0;
				ans=max(ans,sum);
			}
		}
		ans=max(ans,sum);
		lef=0;
		rig=t.size()-1;
		while(lef<t.size()&&t[lef]==type){
			lef++;
		}
		lef--;
		while(rig>=0&&t[rig]==type){
			rig--;
		}
		rig++;
		if(rig==0&&lef==tsz-1){
			lef=solve(idx-1,type);
			return max(ans,lef+(lef+1)*tsz);
		}
		if(check[idx-1][(type-'a'+1)]){
			return max(ans,lef+1+tsz-rig+1);
		}
		else{
			return max(ans,max(lef+1,tsz-rig));
		}
	}
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	string t;
	int n,i,j,k;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>s[i];
		t=s[i];
		for(j=1;j<=26;j++){
			check[i][j]=check[i-1][j];
		}
		for(j=0;j<t.length();j++){
			check[i][(t[j]-'a'+1)]=true;
		}
	}
	cout<<solve(n,' ');
}


#include<iostream>
#include<vector>
using namespace std;
const int N=1e5+2;
string s[N];
bool check[N][30];
int solve(int idx,char type){
	string t;
	if(idx==0){
		return 0;
	}
	int lef,rig,ans=0,sum,tsz;
	if(type=='@'){
		t=s[idx];
		tsz=t.size();
		sum=1;
		for(lef=1;lef<t.size();lef++){
			if(t[lef]==t[lef-1]){
				sum++;
			}
			else{
				ans=max(ans,sum);
				sum=1;
			}
		}
		ans=max(ans,sum);
		lef=0;
		rig=tsz-1;
		while(lef<t.size()-1&&t[lef]==t[lef+1]){
			lef++;
		}
		while(rig>0&&t[rig]==t[rig-1]){
			rig--;
		}
		if(rig==0&&lef==tsz-1){
			lef=solve(idx-1,t[0]);
			return max(ans,lef+(lef+1)*tsz);
		}
		if(t[lef]==t[rig]){
			if(check[idx-1][(t[lef]-'a'+1)]){
				return max(ans,lef+1+tsz-rig+1);
			}
			else{
				return max(ans,max(lef+1,tsz-rig));
			}
		}
		else{
			if(check[idx-1][(t[lef]-'a'+1)]){
				ans=max(ans,lef+1+1);
			}
			else{
				ans=max(ans,lef+1);
			}
			if(check[idx-1][(t[rig]-'a'+1)]){
				ans=max(ans,tsz-rig+1);
			}
			else{
				ans=max(ans,tsz-rig);
			}
			return ans;
		}
	}
	else{
		t=s[idx];
		tsz=t.size();
		ans=0;
		sum=0;
		for(lef=0;lef<t.size();lef++){
			if(t[lef]==type){
				sum++;
			}
			else{
				ans=max(ans,sum);
				sum=0;
			}
		}
		ans=max(ans,sum);
		lef=0;
		rig=t.size()-1;
		while(lef<t.size()&&t[lef]==type){
			lef++;
		}
		lef--;
		while(rig>=0&&t[rig]==type){
			rig--;
		}
		rig++;
		if(rig==0&&lef==tsz-1){
			lef=solve(idx-1,type);
			return max(ans,lef+(lef+1)*tsz);
		}
		if(check[idx-1][(type-'a'+1)]){
			return max(ans,lef+1+tsz-rig+1);
		}
		else{
			return max(ans,max(lef+1,tsz-rig));
		}
	}
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	string t;
	int n,i,j,k;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>s[i];
		t=s[i];
		for(j=1;j<=26;j++){
			check[i][j]=check[i-1][j];
		}
		for(j=0;j<t.length();j++){
			check[i][(t[j]-'a'+1)]=true;
		}
	}
	cout<<solve(n,'@');
}


/*
 * Author: ylx
 * Lang: c++
 * Prog: e
 */
#include<bits/stdc++.h>
#define ll long long
using namespace std;
void qmax(int &x,int y) {if (x<y) x=y;}
void qmin(int &x,int y) {if (x>y) x=y;}
inline int read()
{
	char s;
	int k=0,base=1;
	while ((s=getchar())!='-'&&s!=EOF&&!(isdigit(s)));
	if (s==EOF) exit(0);
	if (s=='-') base=-1,s=getchar();
	while (isdigit(s)) k=k*10+(s^'0'),s=getchar();
	return k*base;
}
inline void write(ll x)
{
	static char cnt,num[20];cnt=0;
	if (!x)
	{
		putchar('0');
		return;
	}
	for (;x;x/=10) num[++cnt]=x%10;
	for (;cnt;putchar(num[cnt--]+48));
}
const int maxn=1e5+100;
string s[maxn];
int n;
int a[maxn],p[maxn];
ll len[maxn],L[maxn],R[maxn],All[maxn];
ll lx[maxn],t[maxn];
void work(int x,int l,int r)
{
	L[x]=0;
	R[x]=0;
	lx[x]=len[x];
	All[x]=0;
	for (int i=l;i<=r;i++)
	{
		if (L[x]==i-l&&a[i]) L[x]++; else break;
	}
	for (int i=r;i>=l;i--)
	{
		if (R[x]==r-i&&a[i]) R[x]++; else break;
	}
	if (L[x]==(r-l+1)) All[x]=1;//全为1
}
int id(int x,int y)
{
	return p[x-1]+y+1;
}
ll sum,ans;
void add(int x,int y)
{
	if (t[x]) sum=max(sum,L[y]+R[y]+1);
	if (!All[y])
	{
		sum=max(sum,max(L[y],R[y]));
		lx[y]=lx[y]*(lx[x]+1)+lx[x];
		return;
	}
	if (All[y]&&All[x])
	{
		All[y]=1;
		lx[y]=lx[y]*(lx[x]+1)+lx[x];
		L[y]=R[y]=lx[y];
		sum=max(sum,lx[y]);
		return;
	}
	if (All[y]&&!All[x])
	{
		All[y]=0;
		L[y]=lx[y]*(L[x]+1)+L[x];
		R[y]=lx[y]*(R[x]+1)+R[x];
		lx[y]=lx[y]*(lx[x]+1)+lx[x];
		sum=max(sum,max(L[y],R[y]));
	}
}
int main()
{
#ifdef ylx
	freopen("e.in","r",stdin);
	freopen("e.out","w",stdout);
#endif
	n=read();
	for (int i=1;i<=n;i++) cin>>s[i],len[i]=s[i].size();
	int ss=0;
	for (int i=1;i<=n;i++)
	{
		ss+=len[i];
		p[i]=ss;//右端点
	}
	ans=1;
	for (int j=0,flagg;j<26;j++)
	{
		sum=0;
		flagg=0;
		for (int i=1;i<=n;i++)
		{
			L[i]=R[i]=0;
			t[i]=0;
			for (int k=p[i-1]+1;k<=p[i];k++)
			{
				a[k]=((s[i][k-p[i-1]-1]-'a')==j)?1:0;
				if (a[k]==1)
				{
					flagg=1;
					t[i]=1;
				}
			}
			work(i,p[i-1]+1,p[i]);
		}
		if (!flagg) continue;
		for (int i=2;i<=n;i++)
		{
			add(i-1,i);
			t[i]|=t[i-1];
			sum=max(sum,L[i]);
			sum=max(sum,R[i]);
		}
		ans=max(ans,sum);
	}
	cout<<ans;
	return 0;
}
//2019年 02月 23日 星期六 19:35:36 CST


/*
 * Author: ylx
 * Lang: c++
 * Prog: e
 */
#include<bits/stdc++.h>
#define ll long long
using namespace std;
void qmax(int &x,int y) {if (x<y) x=y;}
void qmin(int &x,int y) {if (x>y) x=y;}
inline int read()
{
	char s;
	int k=0,base=1;
	while ((s=getchar())!='-'&&s!=EOF&&!(isdigit(s)));
	if (s==EOF) exit(0);
	if (s=='-') base=-1,s=getchar();
	while (isdigit(s)) k=k*10+(s^'0'),s=getchar();
	return k*base;
}
inline void write(ll x)
{
	static char cnt,num[20];cnt=0;
	if (!x)
	{
		putchar('0');
		return;
	}
	for (;x;x/=10) num[++cnt]=x%10;
	for (;cnt;putchar(num[cnt--]+48));
}
const int maxn=1e5+100;
string s[maxn];
int n;
int a[maxn],p[maxn];
ll len[maxn],L[maxn],R[maxn],All[maxn];
ll lx[maxn],t[maxn];
void work(int x,int l,int r)
{
	L[x]=0;
	R[x]=0;
	lx[x]=len[x];
	All[x]=0;
	for (int i=l;i<=r;i++)
	{
		if (L[x]==i-l&&a[i]) L[x]++; else break;
	}
	for (int i=r;i>=l;i--)
	{
		if (R[x]==r-i&&a[i]) R[x]++; else break;
	}
	if (L[x]==(r-l+1)) All[x]=1;//全为1
}
int id(int x,int y)
{
	return p[x-1]+y+1;
}
ll sum,ans,Max;
void add(int x,int y)
{
	if (t[x]) sum=max(sum,L[y]+R[y]+1);
	if (!All[y])
	{
		sum=max(sum,max(L[y],R[y]));
		lx[y]=lx[y]*(lx[x]+1)+lx[x];
		return;
	}
	if (All[y]&&All[x])
	{
		All[y]=1;
		lx[y]=lx[y]*(lx[x]+1)+lx[x];
		L[y]=R[y]=lx[y];
		sum=max(sum,lx[y]);
		return;
	}
	if (All[y]&&!All[x])
	{
		All[y]=0;
		L[y]=lx[y]*(L[x]+1)+L[x];
		R[y]=lx[y]*(R[x]+1)+R[x];
		lx[y]=lx[y]*(lx[x]+1)+lx[x];
		sum=max(sum,max(L[y],R[y]));
	}
}
int main()
{
#ifdef ylx
	freopen("e.in","r",stdin);
	freopen("e.out","w",stdout);
#endif
	n=read();
	for (int i=1;i<=n;i++) cin>>s[i],len[i]=s[i].size();
	int ss=0;
	for (int i=1;i<=n;i++)
	{
		ss+=len[i];
		p[i]=ss;//右端点
	}
	ans=1;
	ll Max=0;
	for (int j=0,flagg;j<26;j++)
	{
		Max=0;
		sum=0;
		flagg=0;
		for (int i=1;i<=n;i++)
		{
			L[i]=R[i]=0;
			t[i]=0;
			for (int k=p[i-1]+1;k<=p[i];k++)
			{
				a[k]=((s[i][k-p[i-1]-1]-'a')==j)?1:0;
				if (a[k]==1)
				{
					flagg=1;
					t[i]=1;
				}
			}
			work(i,p[i-1]+1,p[i]);
			if (i==n) Max=max(Max,L[i]);
			if (i==n) Max=max(Max,R[i]);
		}
		if (!flagg) continue;
		for (int i=2;i<n;i++)
		{
			add(i-1,i);
			t[i]|=t[i-1];
		}
		if (t[n-1]) Max=max(Max,L[n]+R[n]+1);
		if (All[n]) Max=max(Max,(ll)L[n]*(sum+1)+sum);
		ans=max(ans,Max);
	}
	cout<<ans;
	return 0;
}
//2019年 02月 23日 星期六 19:35:36 CST


/*
 * Author: ylx
 * Lang: c++
 * Prog: e
 */
#include<bits/stdc++.h>
#define ll long long
using namespace std;
void qmax(int &x,int y) {if (x<y) x=y;}
void qmin(int &x,int y) {if (x>y) x=y;}
inline int read()
{
	char s;
	int k=0,base=1;
	while ((s=getchar())!='-'&&s!=EOF&&!(isdigit(s)));
	if (s==EOF) exit(0);
	if (s=='-') base=-1,s=getchar();
	while (isdigit(s)) k=k*10+(s^'0'),s=getchar();
	return k*base;
}
inline void write(ll x)
{
	static char cnt,num[20];cnt=0;
	if (!x)
	{
		putchar('0');
		return;
	}
	for (;x;x/=10) num[++cnt]=x%10;
	for (;cnt;putchar(num[cnt--]+48));
}
const int maxn=1e5+100;
string s[maxn];
int n;
int a[maxn],p[maxn];
ll len[maxn],L[maxn],R[maxn],All[maxn];
ll lx[maxn],t[maxn];
void work(int x,int l,int r)
{
	L[x]=0;
	R[x]=0;
	lx[x]=len[x];
	All[x]=0;
	for (int i=l;i<=r;i++)
	{
		if (L[x]==i-l&&a[i]) L[x]++; else break;
	}
	for (int i=r;i>=l;i--)
	{
		if (R[x]==r-i&&a[i]) R[x]++; else break;
	}
	if (L[x]==(r-l+1)) All[x]=1;//全为1
}
int id(int x,int y)
{
	return p[x-1]+y+1;
}
ll sum,ans;
void add(int x,int y)
{
	if (y==n) if (t[x]) sum=max(sum,L[y]+R[y]+1);
	if (!All[y])
	{
		if (y==n) sum=max(sum,max(L[y],R[y]));
		lx[y]=lx[y]*(lx[x]+1)+lx[x];
		return;
	}
	if (All[y]&&All[x])
	{
		All[y]=1;
		lx[y]=lx[y]*(lx[x]+1)+lx[x];
		L[y]=R[y]=lx[y];
		if (y==n) sum=max(sum,lx[y]);
		return;
	}
	if (All[y]&&!All[x])
	{
		All[y]=0;
		L[y]=lx[y]*(L[x]+1)+L[x];
		R[y]=lx[y]*(R[x]+1)+R[x];
		lx[y]=lx[y]*(lx[x]+1)+lx[x];
		if (y==n) sum=max(sum,max(L[y],R[y]));
	}
}
int main()
{
#ifdef ylx
	freopen("e.in","r",stdin);
	freopen("e.out","w",stdout);
#endif
	n=read();
	for (int i=1;i<=n;i++) cin>>s[i],len[i]=s[i].size();
	int ss=0;
	for (int i=1;i<=n;i++)
	{
		ss+=len[i];
		p[i]=ss;//右端点
	}
	ans=1;
	for (int j=0,flagg;j<26;j++)
	{
		sum=0;
		flagg=0;
		for (int i=1;i<=n;i++)
		{
			L[i]=R[i]=0;
			t[i]=0;
			for (int k=p[i-1]+1;k<=p[i];k++)
			{
				a[k]=((s[i][k-p[i-1]-1]-'a')==j)?1:0;
				if (a[k]==1)
				{
					flagg=1;
					t[i]=1;
				}
			}
			work(i,p[i-1]+1,p[i]);
		}
		if (!flagg) continue;
		for (int i=2;i<=n;i++)
		{
			add(i-1,i);
			t[i]|=t[i-1];
			if (i==n) sum=max(sum,L[i]);
			if (i==n) sum=max(sum,R[i]);
		}
		ans=max(ans,sum);
	}
	cout<<ans;
	return 0;
}
//2019年 02月 23日 星期六 19:35:36 CST


#include<bits/stdc++.h>
#define ll long long
using namespace std;
void qmax(int &x,int y) {if (x<y) x=y;}
void qmin(int &x,int y) {if (x>y) x=y;}
inline int read()
{
	char s;
	int k=0,base=1;
	while ((s=getchar())!='-'&&s!=EOF&&!(isdigit(s)));
	if (s==EOF) exit(0);
	if (s=='-') base=-1,s=getchar();
	while (isdigit(s)) k=k*10+(s^'0'),s=getchar();
	return k*base;
}
inline void write(ll x)
{
	static char cnt,num[20];cnt=0;
	if (!x)
	{
		putchar('0');
		return;
	}
	for (;x;x/=10) num[++cnt]=x%10;
	for (;cnt;putchar(num[cnt--]+48));
}
const int maxn=1e5+100;
string s[maxn];
int n;
int a[maxn],p[maxn];
ll len[maxn],L[maxn],R[maxn],All[maxn];
ll lx[maxn],t[maxn];
ll sum[maxn],ans,Max;
void work(int x,int l,int r)
{
	L[x]=0;
	R[x]=0;
	lx[x]=len[x];
	All[x]=0;
	int z=0;
	for (int i=l;i<=r;i++)
	{
		if (a[i]) z++; else z=0;
		sum[x]=max(sum[x],(ll)z);
	}
	for (int i=l;i<=r;i++)
	{
		if (L[x]==i-l&&a[i]) L[x]++; else break;
	}
	for (int i=r;i>=l;i--)
	{
		if (R[x]==r-i&&a[i]) R[x]++; else break;
	}
	if (L[x]==(r-l+1)) All[x]=1;//全为1
}
int id(int x,int y)
{
	return p[x-1]+y+1;
}
void add(int x,int y)
{
	if (t[x]) sum[y]=max(sum[y],L[y]+R[y]+1);
	if (!All[y])
	{
		sum[y]=max(sum[y],max(L[y],R[y]));
		lx[y]=lx[y]*(lx[x]+1)+lx[x];
		return;
	}
	if (All[y]) sum[y]=max(sum[y],lx[y]);
	if (All[y]&&All[x])
	{
		sum[y]=max(sum[y],(lx[y]*(lx[x]+1))+lx[x]);
		All[y]=1;
		lx[y]=lx[y]*(lx[x]+1)+lx[x];
		L[y]=R[y]=lx[y];
		return;
	}
	if (All[y]&&!All[x])
	{
		sum[y]=max(sum[y],(lx[y]*(sum[x]+1)+sum[x]));
		All[y]=0;
		L[y]=lx[y]*(L[x]+1)+L[x];
		R[y]=lx[y]*(R[x]+1)+R[x];
		lx[y]=lx[y]*(lx[x]+1)+lx[x];
		sum[y]=max(sum[y],max(L[y],R[y]));
	}
}
int main()
{
#ifdef ylx
	freopen("e.in","r",stdin);
	freopen("e.out","w",stdout);
#endif
	n=read();
	for (int i=1;i<=n;i++) cin>>s[i],len[i]=s[i].size();
	int ss=0;
	for (int i=1;i<=n;i++)
	{
		ss+=len[i];
		p[i]=ss;//右端点
	}
	ans=1;
	ll Max=0;
	for (int j=0,flagg;j<26;j++)
	{
		Max=0;
		flagg=0;
		for (int i=1;i<=n;i++)
		{
			sum[i]=0;
			L[i]=R[i]=0;
			t[i]=0;
			for (int k=p[i-1]+1;k<=p[i];k++)
			{
				a[k]=((s[i][k-p[i-1]-1]-'a')==j)?1:0;
				if (a[k]==1)
				{
					flagg=1;
					t[i]=1;
				}
			}
			work(i,p[i-1]+1,p[i]);
			if (i==n) Max=max(Max,L[i]);
			if (i==n) Max=max(Max,R[i]);
		}
		if (!flagg) continue;
		for (int i=2;i<=n;i++)
		{
			add(i-1,i);
			t[i]|=t[i-1];
		}
		Max=sum[n];
		ans=max(ans,Max);
	}
	cout<<ans<<endl;
	cerr<<ans<<" ";
	return 0;
}
//2019年 02月 23日 星期六 19:35:36 CST


/*
 * Author: ylx
 * Lang: c++
 * Prog: e
 */
#include<bits/stdc++.h>
#define ll long long
using namespace std;
void qmax(int &x,int y) {if (x<y) x=y;}
void qmin(int &x,int y) {if (x>y) x=y;}
inline int read()
{
	char s;
	int k=0,base=1;
	while ((s=getchar())!='-'&&s!=EOF&&!(isdigit(s)));
	if (s==EOF) exit(0);
	if (s=='-') base=-1,s=getchar();
	while (isdigit(s)) k=k*10+(s^'0'),s=getchar();
	return k*base;
}
inline void write(ll x)
{
	static char cnt,num[20];cnt=0;
	if (!x)
	{
		putchar('0');
		return;
	}
	for (;x;x/=10) num[++cnt]=x%10;
	for (;cnt;putchar(num[cnt--]+48));
}
const int maxn=1e5+100;
string s[maxn];
int n;
int a[maxn],p[maxn];
ll len[maxn],L[maxn],R[maxn],All[maxn];
ll lx[maxn];
void work(int x,int l,int r)
{
	L[x]=0;
	R[x]=0;
	lx[x]=len[x];
	All[x]=0;
	for (int i=l;i<=r;i++)
	{
		if (L[x]==i-1&&a[i]) L[x]++; else break;
	}
	for (int i=r;i>=l;i--)
	{
		if (R[x]==r-i&&a[i]) R[x]++; else break;
	}
	if (L[x]==(r-l+1)) All[x]=1;//全为1
}
int id(int x,int y)
{
	return p[x-1]+y+1;
}
ll sum,ans;
void add(int x,int y)
{
	if (!All[y])
	{
		sum=max(sum,max(L[y],R[y]));
		if (L[x]>0||R[x]>0) sum=max(sum,L[y]+R[y]+1);
		lx[y]=lx[y]*(lx[x]+1)+lx[x];
		return;
	}
	if (All[y]&&All[x])
	{
		All[y]=1;
		lx[y]=lx[y]*(lx[x]+1)+lx[x];
		L[y]=R[y]=lx[y];
		sum=max(sum,lx[y]);
		return;
	}
	if (All[y]&&!All[x])
	{
		All[y]=0;
		L[y]=lx[y]*(L[x]+1)+L[x];
		R[y]=lx[y]*(R[x]+1)+R[x];
		lx[y]=lx[y]*(lx[x]+1)+lx[x];
		if (L[x]>0||R[x]>0) sum=max(sum,L[y]+R[y]+1);
		sum=max(sum,max(L[y],R[y]));
	}
}
int main()
{
#ifdef ylx
	freopen("e.in","r",stdin);
	freopen("e.out","w",stdout);
#endif
	n=read();
	for (int i=1;i<=n;i++) cin>>s[i],len[i]=s[i].size();
	int ss=0;
	for (int i=1;i<=n;i++)
	{
		ss+=len[i];
		p[i]=ss;//右端点
	}
	for (int j=0,flagg;j<26;j++)
//	for (int j=0,flagg;j<1;j++)
	{
		sum=0;
		flagg=0;
		for (int i=1;i<=n;i++)
		{
			for (int k=p[i-1]+1;k<=p[i];k++)
			{
				a[i]=(s[i][k-p[i-1]-1]-'a'==j)?1:0;
				if (a[i]==1) flagg=1;
			}
			work(i,p[i-1]+1,p[i]);
		}
		if (!flagg) continue;
		for (int i=2;i<=n;i++)
		{
			add(i,i-1);
			lx[i]=lx[i-1];
			L[i]=L[i-1];
			R[i]=R[i-1];
			All[i]=All[i-1];
			sum=max(sum,L[i]);
			sum=max(sum,R[i]);
	//0		cout<<L[i]<<" "<<R[i]<<" "<<All[i]<<endl;
		}
		ans=max(ans,sum);
	}
	cout<<ans;
	return 0;
}
//2019年 02月 23日 星期六 19:35:36 CST


/*
 * Author: ylx
 * Lang: c++
 * Prog: e
 */
#include<bits/stdc++.h>
#define ll long long
using namespace std;
void qmax(int &x,int y) {if (x<y) x=y;}
void qmin(int &x,int y) {if (x>y) x=y;}
inline int read()
{
	char s;
	int k=0,base=1;
	while ((s=getchar())!='-'&&s!=EOF&&!(isdigit(s)));
	if (s==EOF) exit(0);
	if (s=='-') base=-1,s=getchar();
	while (isdigit(s)) k=k*10+(s^'0'),s=getchar();
	return k*base;
}
inline void write(ll x)
{
	static char cnt,num[20];cnt=0;
	if (!x)
	{
		putchar('0');
		return;
	}
	for (;x;x/=10) num[++cnt]=x%10;
	for (;cnt;putchar(num[cnt--]+48));
}
const int maxn=1e5+100;
string s[maxn];
int n;
int a[maxn],p[maxn];
ll len[maxn],L[maxn],R[maxn],All[maxn];
ll lx[maxn],t[maxn];
void work(int x,int l,int r)
{
	L[x]=0;
	R[x]=0;
	lx[x]=len[x];
	All[x]=0;
	for (int i=l;i<=r;i++)
	{
		if (L[x]==i-l&&a[i]) L[x]++; else break;
	}
	for (int i=r;i>=l;i--)
	{
		if (R[x]==r-i&&a[i]) R[x]++; else break;
	}
	if (L[x]==(r-l+1)) All[x]=1;//全为1
}
int id(int x,int y)
{
	return p[x-1]+y+1;
}
ll sum,ans;
void add(int x,int y)
{
	if (t[x]) sum=max(sum,L[y]+R[y]+1);
	if (!All[y])
	{
		sum=max(sum,max(L[y],R[y]));
		lx[y]=lx[y]*(lx[x]+1)+lx[x];
		return;
	}
	if (All[y]&&All[x])
	{
		All[y]=1;
		lx[y]=lx[y]*(lx[x]+1)+lx[x];
		L[y]=R[y]=lx[y];
		sum=max(sum,lx[y]);
		return;
	}
	if (All[y]&&!All[x])
	{
		All[y]=0;
		L[y]=lx[y]*(L[x]+1)+L[x];
		R[y]=lx[y]*(R[x]+1)+R[x];
		lx[y]=lx[y]*(lx[x]+1)+lx[x];
		sum=max(sum,max(L[y],R[y]));
	}
}
int main()
{
#ifdef ylx
	freopen("e.in","r",stdin);
	freopen("e.out","w",stdout);
#endif
	n=read();
	for (int i=1;i<=n;i++) cin>>s[i],len[i]=s[i].size();
	int ss=0;
	for (int i=1;i<=n;i++)
	{
		ss+=len[i];
		p[i]=ss;//右端点
	}
	ans=1;
	for (int j=0,flagg;j<26;j++)
	{
		sum=0;
		flagg=0;
		for (int i=1;i<=n;i++)
		{
			for (int k=p[i-1]+1;k<=p[i];k++)
			{
				a[k]=((s[i][k-p[i-1]-1]-'a')==j)?1:0;
				if (a[k]==1)
				{
					flagg=1;
					t[i]=1;
				}
			}
			work(i,p[i-1]+1,p[i]);
		}
		if (!flagg) continue;
	//	cout<<L[1]<<" "<<R[1]<<" "<<All[1]<<endl;
		for (int i=2;i<=n;i++)
		{
			add(i-1,i);
			t[i]|=t[i-1];
			sum=max(sum,L[i]);
			sum=max(sum,R[i]);
	//		cout<<L[i]<<" "<<R[i]<<" "<<All[i]<<endl;
		}
		ans=max(ans,sum);
	//	cout<<endl;
	}
	cout<<ans;
	return 0;
}
//2019年 02月 23日 星期六 19:35:36 CST


/*
 * Author: ylx
 * Lang: c++
 * Prog: e
 */
#include<bits/stdc++.h>
#define ll long long
using namespace std;
void qmax(int &x,int y) {if (x<y) x=y;}
void qmin(int &x,int y) {if (x>y) x=y;}
inline int read()
{
	char s;
	int k=0,base=1;
	while ((s=getchar())!='-'&&s!=EOF&&!(isdigit(s)));
	if (s==EOF) exit(0);
	if (s=='-') base=-1,s=getchar();
	while (isdigit(s)) k=k*10+(s^'0'),s=getchar();
	return k*base;
}
inline void write(ll x)
{
	static char cnt,num[20];cnt=0;
	if (!x)
	{
		putchar('0');
		return;
	}
	for (;x;x/=10) num[++cnt]=x%10;
	for (;cnt;putchar(num[cnt--]+48));
}
const int maxn=1e5+100;
string s[maxn];
int n;
int a[maxn],p[maxn];
ll len[maxn],L[maxn],R[maxn],All[maxn];
ll lx[maxn];
void work(int x,int l,int r)
{
	L[x]=0;
	R[x]=0;
	lx[x]=len[x];
	All[x]=0;
	for (int i=l;i<=r;i++)
	{
		if (L[x]==i-l&&a[i]) L[x]++; else break;
	}
	for (int i=r;i>=l;i--)
	{
		if (R[x]==r-i&&a[i]) R[x]++; else break;
	}
	if (L[x]==(r-l+1)) All[x]=1;//全为1
}
int id(int x,int y)
{
	return p[x-1]+y+1;
}
ll sum,ans;
void add(int x,int y)
{
	if (L[x]>0||R[x]>0) sum=max(sum,L[y]+R[y]+1);
	if (!All[y])
	{
		sum=max(sum,max(L[y],R[y]));
		lx[y]=lx[y]*(lx[x]+1)+lx[x];
		return;
	}
	if (All[y]&&All[x])
	{
		All[y]=1;
		lx[y]=lx[y]*(lx[x]+1)+lx[x];
		L[y]=R[y]=lx[y];
		sum=max(sum,lx[y]);
		return;
	}
	if (All[y]&&!All[x])
	{
		All[y]=0;
		L[y]=lx[y]*(L[x]+1)+L[x];
		R[y]=lx[y]*(R[x]+1)+R[x];
		lx[y]=lx[y]*(lx[x]+1)+lx[x];
		sum=max(sum,max(L[y],R[y]));
	}
}
int main()
{
#ifdef ylx
	freopen("e.in","r",stdin);
	freopen("e.out","w",stdout);
#endif
	n=read();
	for (int i=1;i<=n;i++) cin>>s[i],len[i]=s[i].size();
	int ss=0;
	for (int i=1;i<=n;i++)
	{
		ss+=len[i];
		p[i]=ss;//右端点
	}
	//	for (int j=0,flagg;j<26;j++)
	for (int j=0,flagg;j<1;j++)
	{
		sum=0;
		flagg=0;
		for (int i=1;i<=n;i++)
		{
			for (int k=p[i-1]+1;k<=p[i];k++)
			{
				a[k]=((s[i][k-p[i-1]-1]-'a')==j)?1:0;
				if (a[k]==1) flagg=1;
			}
			work(i,p[i-1]+1,p[i]);
			sum=max(sum,L[i]);
			sum=max(sum,R[i]);
		}
		if (!flagg) continue;
		for (int i=2;i<=n;i++)
		{
			add(i,i-1);
			lx[i]=lx[i-1];
			L[i]=L[i-1];
			R[i]=R[i-1];
			All[i]=All[i-1];
			sum=max(sum,L[i]);
			sum=max(sum,R[i]);
		}
		ans=max(ans,sum);
	}
	cout<<ans;
	return 0;
}
//2019年 02月 23日 星期六 19:35:36 CST


/*
 * Author: ylx
 * Lang: c++
 * Prog: e
 */
#include<bits/stdc++.h>
#define ll long long
using namespace std;
void qmax(int &x,int y) {if (x<y) x=y;}
void qmin(int &x,int y) {if (x>y) x=y;}
inline int read()
{
	char s;
	int k=0,base=1;
	while ((s=getchar())!='-'&&s!=EOF&&!(isdigit(s)));
	if (s==EOF) exit(0);
	if (s=='-') base=-1,s=getchar();
	while (isdigit(s)) k=k*10+(s^'0'),s=getchar();
	return k*base;
}
inline void write(ll x)
{
	static char cnt,num[20];cnt=0;
	if (!x)
	{
		putchar('0');
		return;
	}
	for (;x;x/=10) num[++cnt]=x%10;
	for (;cnt;putchar(num[cnt--]+48));
}
const int maxn=1e5+100;
string s[maxn];
int n;
int a[maxn],p[maxn];
ll len[maxn],L[maxn],R[maxn],All[maxn];
ll lx[maxn];
void work(int x,int l,int r)
{
	L[x]=0;
	R[x]=0;
	lx[x]=len[x];
	All[x]=0;
	for (int i=l;i<=r;i++)
	{
		if (L[x]==i-l&&a[i]) L[x]++; else break;
	}
	for (int i=r;i>=l;i--)
	{
		if (R[x]==r-i&&a[i]) R[x]++; else break;
	}
	if (L[x]==(r-l+1)) All[x]=1;//全为1
}
int id(int x,int y)
{
	return p[x-1]+y+1;
}
ll sum,ans;
void add(int x,int y)
{
	if (L[x]>0||R[x]>0) sum=max(sum,L[y]+R[y]+1);
	if (!All[y])
	{
		sum=max(sum,max(L[y],R[y]));
		lx[y]=lx[y]*(lx[x]+1)+lx[x];
		return;
	}
	if (All[y]&&All[x])
	{
		All[y]=1;
		lx[y]=lx[y]*(lx[x]+1)+lx[x];
		L[y]=R[y]=lx[y];
		sum=max(sum,lx[y]);
		return;
	}
	if (All[y]&&!All[x])
	{
		All[y]=0;
		L[y]=lx[y]*(L[x]+1)+L[x];
		R[y]=lx[y]*(R[x]+1)+R[x];
		lx[y]=lx[y]*(lx[x]+1)+lx[x];
		sum=max(sum,max(L[y],R[y]));
	}
}
int main()
{
#ifdef ylx
	freopen("e.in","r",stdin);
	freopen("e.out","w",stdout);
#endif
	n=read();
	for (int i=1;i<=n;i++) cin>>s[i],len[i]=s[i].size();
	int ss=0;
	for (int i=1;i<=n;i++)
	{
		ss+=len[i];
		p[i]=ss;//右端点
	}
	for (int j=0,flagg;j<26;j++)
	{
		sum=0;
		flagg=0;
		for (int i=1;i<=n;i++)
		{
			for (int k=p[i-1]+1;k<=p[i];k++)
			{
				a[k]=((s[i][k-p[i-1]-1]-'a')==j)?1:0;
				if (a[k]==1) flagg=1;
			}
			work(i,p[i-1]+1,p[i]);
			sum=max(sum,L[i]);
			sum=max(sum,R[i]);
		}
		if (!flagg) continue;
		for (int i=2;i<=n;i++)
		{
			add(i,i-1);
			lx[i]=lx[i-1];
			L[i]=L[i-1];
			R[i]=R[i-1];
			All[i]=All[i-1];
			sum=max(sum,L[i]);
			sum=max(sum,R[i]);
		}
		ans=max(ans,sum);
	}
	cout<<ans;
	return 0;
}
//2019年 02月 23日 星期六 19:35:36 CST


/*
 * Author: ylx
 * Lang: c++
 * Prog: e
 */
#include<bits/stdc++.h>
#define ll long long
using namespace std;
void qmax(int &x,int y) {if (x<y) x=y;}
void qmin(int &x,int y) {if (x>y) x=y;}
inline int read()
{
	char s;
	int k=0,base=1;
	while ((s=getchar())!='-'&&s!=EOF&&!(isdigit(s)));
	if (s==EOF) exit(0);
	if (s=='-') base=-1,s=getchar();
	while (isdigit(s)) k=k*10+(s^'0'),s=getchar();
	return k*base;
}
inline void write(ll x)
{
	static char cnt,num[20];cnt=0;
	if (!x)
	{
		putchar('0');
		return;
	}
	for (;x;x/=10) num[++cnt]=x%10;
	for (;cnt;putchar(num[cnt--]+48));
}
const int maxn=1e5+100;
string s[maxn];
int n;
int a[maxn],p[maxn];
ll len[maxn],L[maxn],R[maxn],All[maxn];
ll lx[maxn],t[maxn];
void work(int x,int l,int r)
{
	L[x]=0;
	R[x]=0;
	lx[x]=len[x];
	All[x]=0;
	for (int i=l;i<=r;i++)
	{
		if (L[x]==i-l&&a[i]) L[x]++; else break;
	}
	for (int i=r;i>=l;i--)
	{
		if (R[x]==r-i&&a[i]) R[x]++; else break;
	}
	if (L[x]==(r-l+1)) All[x]=1;//全为1
}
int id(int x,int y)
{
	return p[x-1]+y+1;
}
ll sum,ans,Max;
void add(int x,int y)
{
	if (t[x]) sum=max(sum,L[y]+R[y]+1);
	if (!All[y])
	{
		sum=max(sum,max(L[y],R[y]));
		lx[y]=lx[y]*(lx[x]+1)+lx[x];
		return;
	}
	if (All[y]&&All[x])
	{
		All[y]=1;
		lx[y]=lx[y]*(lx[x]+1)+lx[x];
		L[y]=R[y]=lx[y];
		sum=max(sum,lx[y]);
		return;
	}
	if (All[y]&&!All[x])
	{
		All[y]=0;
		L[y]=lx[y]*(L[x]+1)+L[x];
		R[y]=lx[y]*(R[x]+1)+R[x];
		lx[y]=lx[y]*(lx[x]+1)+lx[x];
		sum=max(sum,max(L[y],R[y]));
	}
}
int main()
{
#ifdef ylx
	freopen("e.in","r",stdin);
	freopen("e.out","w",stdout);
#endif
	n=read();
	for (int i=1;i<=n;i++) cin>>s[i],len[i]=s[i].size();
	int ss=0;
	for (int i=1;i<=n;i++)
	{
		ss+=len[i];
		p[i]=ss;//右端点
	}
	ans=1;
	ll Max=0;
	for (int j=0,flagg;j<26;j++)
	{
		Max=0;
		sum=0;
		flagg=0;
		for (int i=1;i<=n;i++)
		{
			L[i]=R[i]=0;
			t[i]=0;
			for (int k=p[i-1]+1;k<=p[i];k++)
			{
				a[k]=((s[i][k-p[i-1]-1]-'a')==j)?1:0;
				if (a[k]==1)
				{
					flagg=1;
					t[i]=1;
				}
			}
			work(i,p[i-1]+1,p[i]);
			if (i==n) Max=max(Max,L[i]);
			if (i==n) Max=max(Max,R[i]);
		}
		if (!flagg) continue;
		for (int i=2;i<n;i++)
		{
			add(i-1,i);
			t[i]|=t[i-1];
//			if (i==n) sum=max(sum,L[i]);
//			if (i==n) sum=max(sum,R[i]);
		}
		Max=max(Max,L[n]+R[n]+sum);
		ans=max(ans,Max);
	}
	cout<<ans;
	return 0;
}
//2019年 02月 23日 星期六 19:35:36 CST


/*
 * Author: ylx
 * Lang: c++
 * Prog: e
 */
#include<bits/stdc++.h>
#define ll long long
using namespace std;
void qmax(int &x,int y) {if (x<y) x=y;}
void qmin(int &x,int y) {if (x>y) x=y;}
inline int read()
{
	char s;
	int k=0,base=1;
	while ((s=getchar())!='-'&&s!=EOF&&!(isdigit(s)));
	if (s==EOF) exit(0);
	if (s=='-') base=-1,s=getchar();
	while (isdigit(s)) k=k*10+(s^'0'),s=getchar();
	return k*base;
}
inline void write(ll x)
{
	static char cnt,num[20];cnt=0;
	if (!x)
	{
		putchar('0');
		return;
	}
	for (;x;x/=10) num[++cnt]=x%10;
	for (;cnt;putchar(num[cnt--]+48));
}
const int maxn=1e5+100;
string s[maxn];
int n;
int a[maxn],p[maxn];
ll len[maxn],L[maxn],R[maxn],All[maxn];
ll lx[maxn],t[maxn];
void work(int x,int l,int r)
{
	L[x]=0;
	R[x]=0;
	lx[x]=len[x];
	All[x]=0;
	for (int i=l;i<=r;i++)
	{
		if (L[x]==i-l&&a[i]) L[x]++; else break;
	}
	for (int i=r;i>=l;i--)
	{
		if (R[x]==r-i&&a[i]) R[x]++; else break;
	}
	if (L[x]==(r-l+1)) All[x]=1;//全为1
}
int id(int x,int y)
{
	return p[x-1]+y+1;
}
ll sum,ans;
void add(int x,int y)
{
	if (t[x]) sum=max(sum,L[y]+R[y]+1);
	if (!All[y])
	{
		sum=max(sum,max(L[y],R[y]));
		lx[y]=lx[y]*(lx[x]+1)+lx[x];
		return;
	}
	if (All[y]&&All[x])
	{
		All[y]=1;
		lx[y]=lx[y]*(lx[x]+1)+lx[x];
		L[y]=R[y]=lx[y];
		sum=max(sum,lx[y]);
		return;
	}
	if (All[y]&&!All[x])
	{
		All[y]=0;
		L[y]=lx[y]*(L[x]+1)+L[x];
		R[y]=lx[y]*(R[x]+1)+R[x];
		lx[y]=lx[y]*(lx[x]+1)+lx[x];
		sum=max(sum,max(L[y],R[y]));
	}
}
int main()
{
#ifdef ylx
	freopen("e.in","r",stdin);
	freopen("e.out","w",stdout);
#endif
	n=read();
	for (int i=1;i<=n;i++) cin>>s[i],len[i]=s[i].size();
	int ss=0;
	for (int i=1;i<=n;i++)
	{
		ss+=len[i];
		p[i]=ss;//右端点
	}
	for (int j=0,flagg;j<26;j++)
	{
		sum=0;
		flagg=0;
		for (int i=1;i<=n;i++)
		{
			for (int k=p[i-1]+1;k<=p[i];k++)
			{
				a[k]=((s[i][k-p[i-1]-1]-'a')==j)?1:0;
				if (a[k]==1)
				{
					flagg=1;
					t[i]=1;
				}
			}
			work(i,p[i-1]+1,p[i]);
		}
		if (!flagg) continue;
	//	cout<<L[1]<<" "<<R[1]<<" "<<All[1]<<endl;
		for (int i=2;i<=n;i++)
		{
			add(i-1,i);
			t[i]|=t[i-1];
			sum=max(sum,L[i]);
			sum=max(sum,R[i]);
	//		cout<<L[i]<<" "<<R[i]<<" "<<All[i]<<endl;
		}
		ans=max(ans,sum);
	//	cout<<endl;
	}
	cout<<ans;
	return 0;
}
//2019年 02月 23日 星期六 19:35:36 CST


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

using namespace std;
typedef long long ll;
ll a[200005];
int main(int argc, char *argv[])
{
	ll n,m,p,res=1;
	cin>>n>>m;
	for(int i = 0;i < n;i++){
		scanf("%d",&a[i]);
	}
	if (n > m){
		cout<<0<<endl;
		return 0;
	}
	for(int i = 0;i < n;i++){
		for(int j = i+1;j < n;j++){
			p = abs(a[j]-a[i]);
			res *= p;
			res %= m;
		}
	}
	cout<<(res+m)%m<<endl;
	return 0;
}


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

using namespace std;
typedef long long ll;
ll a[200005];
int main(int argc, char *argv[])
{
	ll n,m,p,res=1;
	cin>>n>>m;
	for(int i = 0;i < n;i++){
		scanf("%d",&a[i]);
	}
	for(int i = 0;i < n;i++){
		for(int j = i+1;j < n;j++){
			p = abs(a[j]-a[i]);
			if (p % m != 0){
				if (m % p != 0 || p == 1){
					res *= p;
					res %= m;
				}else{
					cout<<0<<endl;
					return 0;
				}
			}else {
				cout<<0<<endl;
				return 0;
			}
		}
	}
	cout<<(res+m)%m<<endl;
	return 0;
}


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

using namespace std;
typedef long long ll;
ll a[200005];
int main(int argc, char *argv[])
{
	ll n,m,p,res=1;
	cin>>n>>m;
	for(int i = 0;i < n;i++){
		scanf("%d",&a[i]);
	}
	for(int i = 0;i < n;i++){
		for(int j = i+1;j < n;j++){
			p = abs(a[j]-a[i]);
			if (p % m != 0&& m % p != 0){
					res *= p;
					res %= m;
			}else {
				cout<<0<<endl;
				return 0;
			}
		}
	}
	cout<<(res+m)%m<<endl;
	return 0;
}


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

using namespace std;
typedef long long ll;
ll a[200005];
int main(int argc, char *argv[])
{
	ll n,m,p,res=1;
	cin>>n>>m;
	for(int i = 0;i < n;i++){
		cin>>a[i];
	}
	for(int i = 0;i < n;i++){
		for(int j = i+1;j < n;j++){
			p = abs(a[j]-a[i]);
			if (p % m != 0){
				res *= p;
				res %= m;
			}else {
				cout<<0<<endl;
				return 0;
			}
		}
	}
	cout<<res<<endl;
	return 0;
}


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

using namespace std;
typedef long long ll;
ll a[200005];
int main(int argc, char *argv[])
{
	ll n,m,p,res=1;
	cin>>n>>m;
	for(int i = 0;i < n;i++){
		scanf("%d",&a[i]);
	}
	for(int i = 0;i < n;i++){
		for(int j = i+1;j < n;j++){
			p = abs(a[j]-a[i]);
			if (p % m != 0&& m % p != 0 || p == 1){
					res *= p;
					res %= m;
			}else {
				cout<<0<<endl;
				return 0;
			}
		}
	}
	cout<<(res+m)%m<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
int t, n,m,pi=1,a[200020];
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    if(n>m){
        cout<<0;
        return 0;
    }
    for(int i=1;i<n;i++){
        for(int j=i+1;j<=n;j++){
            pi*=abs(a[i]-a[j])%m;
            pi%=m;
        }
    }
    cout<<pi%m;
}


#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
int t, n,m,pi=1,a[20020];
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    if(n>=m){
        cout<<0;
        return 0;
    }
    for(int i=1;i<n;i++){
        for(int j=i+1;j<=n;j++){
            pi*=abs(a[i]-a[j]);
        }
    }
    cout<<pi;
}


#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
int t, n,m,pi=1,a[20020];
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    if(n>=m){
        cout<<0;
        return 0;
    }
    for(int i=1;i<n;i++){
        for(int j=i+1;j<=n;j++){
            pi*=abs(a[i]-a[j])%m;
            pi%=m;
        }
    }
    cout<<pi%m;
}


#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
int t, n,m,pi=1,a[20020];
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    if(n>=m){
        cout<<0;
        return 0;
    }
    for(int i=1;i<n;i++){
        for(int j=i+1;j<=n;j++){
            pi*=abs(a[i]-a[j]);
        }
    }
    cout<<pi%m;
}


#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
int t, n,m,pi=1,a[200020];
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    if(n>=m){
        cout<<0;
        return 0;
    }
    for(int i=1;i<n;i++){
        for(int j=i+1;j<=n;j++){
            pi*=abs(a[i]-a[j])%m;
            pi%=m;
        }
    }
    cout<<pi%m;
}


#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
long long t, n,m,pi=1,a[20020];
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    if(n>=m){
        cout<<0;
        return 0;
    }
    for(int i=1;i<n;i++){
        for(int j=i+1;j<=n;j++){
            pi*=abs(a[i]-a[j])%m;
            pi%=m;
        }
    }
    cout<<pi%m;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=2e5+5;
queue<int> q;
int a[maxn]; int b[1005]; LL dp[1005];

template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}

int main(void)
{
	int n,m; scanf("%d%d",&n,&m);
	memset(b,0,sizeof(b));
	memset(dp,0,sizeof(dp));
	for(int i=1;i<=n;i++)
	{
		read(a[i]);
	}
	sort(a+1,a+1+n);
//	for(int i=1;i<=n;i++) a[i]%=m;
	queue<int> p;
	for(int i=1;i<=n;i++)
	{
		while(!q.empty())
		{
			if(a[i]-q.front()>m) q.pop();
			else break;
		}
		for(int j=0;j<m;j++)
		{
			int k=a[i]%m-j;
			if(k<0) { k=-k; k%=m; k=m-k; }
			else k=k%m;

			dp[k]+=b[j];
//			printf("i==%d,j==%d,k==%d\n",i,j,k);
		}
		while(!q.empty())
		{
			int x=q.front(); q.pop();
			p.push(x);
			int k=m+a[i]%m-x%m;
			k=(k%m+m)%m;
			dp[k]--;
			k=abs(a[i]-x)%m;
			dp[k]++;
		}
		while(!p.empty())
		{
			int x=p.front(); p.pop();
			q.push(x);
		}
		b[a[i]%m]++;
		if(dp[0]) break;
		q.push(a[i]);
	}

	LL res=1;
	for(int i=0;i<m;i++)
	{
		if(dp[i]==0) continue;
		LL update=1ll*dp[i]*i%m;
		res=res*update%m;
	}
	printf("%I64d\n",res);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=2e5+5;
queue<int> q;
int a[maxn]; int b[1005]; LL dp[1005];

template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}

int main(void)
{
	int n,m; scanf("%d%d",&n,&m);
	memset(b,0,sizeof(b));
	memset(dp,0,sizeof(dp));
	for(int i=1;i<=n;i++)
	{
		read(a[i]);
	}
	sort(a+1,a+1+n);
//	for(int i=1;i<=n;i++) a[i]%=m;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<m;j++)
		{
			int k;
			if(j>a[i]%m) k=m+a[i]%m-j;
			else k=a[i]%m-j;
			k=(k%m+m)%m;

			dp[k]+=b[j];
//			printf("i==%d,j==%d,k==%d\n",i,j,k);
		}

		b[a[i]%m]++;
		if(dp[0]) break;

	}

	LL res=1;
	for(int i=0;i<m;i++)
	{
		if(dp[i]==0) continue;
		LL update=1ll*dp[i]*i%m;
		res=res*update%m;
	}
	printf("%I64d\n",res);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=2e5+5;
int a[maxn]; int b[1005]; LL dp[1005]; LL tmp[1005];

template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}

int main(void)
{
	int n,m; scanf("%d%d",&n,&m);
	memset(b,0,sizeof(b));
	memset(dp,0,sizeof(dp));
	for(int i=1;i<=n;i++)
	{
		read(a[i]);
	}

	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<m;j++)
		{
			int k=abs(j-a[i]);
			k=(k%m+m)%m;
			dp[k]+=b[j];
		}
		b[a[i]%m]++;
		if(dp[0]) break;
	}

	LL res=1;
	for(int i=0;i<m;i++)
	{
		if(dp[i]==0) continue;
		LL update=1ll*dp[i]*i%m;
		res=res*update%m;
	}
	printf("%I64d\n",res);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int a[200005];
int main(void)
{
	int n,m; scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	if(n>m) { printf("0\n"); return 0; }
	LL res=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			LL update=1ll*abs(a[i]-a[j]);
//			printf("update==%lld\n",update);
			res=(res*update%m)%m;
		}
	}
	printf("%I64d\n",res);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=2e5+5;
int a[maxn]; LL b[1005]; LL dp[1005]; LL tmp[1005];
int main(void)
{
	int n,m; scanf("%d%d",&n,&m);
	memset(b,0,sizeof(b));
	memset(dp,0,sizeof(dp));
	for(int i=1;i<=n;i++)
	{
		scanf("%I64d",&a[i]);

	}

	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<m;j++)
		{
			int k=abs(j-a[i]);
			k=(k%m+m)%m;
			dp[k]+=b[j];
//			printf("j==%d,k==%d,dp==%lld\n",j,k,dp[k]);
		}
		b[a[i]%m]++;
	}
//	for(int i=0;i<=m;i++) printf("i==%d, dp==%d\n",i,dp[i]);
	LL res=1;
	for(int i=0;i<m;i++)
	{
		if(dp[i]==0) continue;
		LL update=1ll*dp[i]*i%m;
//		printf("i==%d,update==%d\n",i,update);
		res=res*update%m;
	}
	printf("%I64d\n",res);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=2e5+5;
LL a[maxn]; LL b[maxn]; LL dp[1005]; LL tmp[1005];
int main(void)
{
	int n,m; scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%I64d",&a[i]);
	}
	bool f=true;
	for(int i=1;i<=n-1;i++)
	{
		b[i]=(a[i+1]-a[i]);
		if(b[i]<0) b[i]=-b[i];
		b[i]%=m;
	}

	for(int i=1;i<=n-1;i++)
	{
		for(int j=0;j<m;j++) tmp[j]=dp[j];
		for(int j=0;j<m;j++)
		{
			int k=j+b[i];
			k%=m;
			tmp[k]=(tmp[k]+dp[j]);
		}
		for(int j=0;j<m;j++) dp[j]=tmp[j];
		dp[b[i]]++;
	}
	LL res=1;
	for(int i=0;i<m;i++)
	{
		if(dp[i]==0) continue;
		LL update=1ll*dp[i]*i%m;
//		printf("i==%d,update==%d\n",i,update);
		res=res*update%m;
	}
	printf("%I64d\n",res);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=2e5+5;
int a[maxn]; LL b[1005]; LL dp[1005]; LL tmp[1005];
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}

int main(void)
{
	int n,m; scanf("%d%d",&n,&m);
	memset(b,0,sizeof(b));
	memset(dp,0,sizeof(dp));
	for(int i=1;i<=n;i++)
	{
//		scanf("%d",&a[i]);
		read(a[i]);
	}

	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<m;j++)
		{
			int k=abs(j-a[i]);
			k=(k%m+m)%m;
			dp[k]+=b[j];
//			printf("j==%d,k==%d,dp==%lld\n",j,k,dp[k]);
		}
		b[a[i]%m]++;
	}
//	for(int i=0;i<=m;i++) printf("i==%d, dp==%d\n",i,dp[i]);
	LL res=1;
	for(int i=0;i<m;i++)
	{
		if(dp[i]==0) continue;
		LL update=1ll*dp[i]*i%m;
//		printf("i==%d,update==%d\n",i,update);
		res=res*update%m;
	}
	printf("%I64d\n",res);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=2e5+5;
queue<int> q;
int a[maxn]; int b[1005]; LL dp[1005];

template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}

int main(void)
{
	int n,m; scanf("%d%d",&n,&m);
	memset(b,0,sizeof(b));
	memset(dp,0,sizeof(dp));
	for(int i=1;i<=n;i++)
	{
		read(a[i]);
	}
	sort(a+1,a+1+n);
//	for(int i=1;i<=n;i++) a[i]%=m;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<m;j++)
		{
			int k;
			if(j<a[i]%m) k=m+a[i]%m-j;
			else k=a[i]%m-j;
			k=(k%m+m)%m;

			dp[k]+=b[j];
//			printf("i==%d,j==%d,k==%d\n",i,j,k);
		}

		b[a[i]%m]++;
		if(dp[0]) break;

	}

	LL res=1;
	for(int i=0;i<m;i++)
	{
		if(dp[i]==0) continue;
		LL update=1ll*dp[i]*i%m;
		res=res*update%m;
	}
	printf("%I64d\n",res);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=2e5+5;
int a[maxn]; int b[maxn]; LL dp[1005]; LL tmp[1005];
int main(void)
{
	int n,m; scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	bool f=true;
	for(int i=1;i<=n-1;i++)
	{
		b[i]=(a[i+1]-a[i]);
		if(b[i]<0) b[i]=-b[i];
		b[i]%=m;
	}

	for(int i=1;i<=n-1;i++)
	{
		for(int j=0;j<m;j++) tmp[j]=dp[j];
		for(int j=0;j<m;j++)
		{
			int k=j+b[i];
			k%=m;
			tmp[k]=(tmp[k]+dp[j]);
		}
		for(int j=0;j<m;j++) dp[j]=tmp[j];
		dp[b[i]]++;
	}
//	for(int i=0;i<m;i++) printf("i==%d,dp==%d\n",i,dp[i]);
	int res=1;
	for(int i=0;i<m;i++)
	{
		if(dp[i]==0) continue;
		int update=1ll*dp[i]*i%m;
//		printf("i==%d,update==%d\n",i,update);
		res=1ll*res*update%m;
	}
	printf("%d\n",res);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=2e5+5;
int a[maxn]; int b[1005]; LL dp[1005];

template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}

int main(void)
{
	int n,m; scanf("%d%d",&n,&m);
	memset(b,0,sizeof(b));
	memset(dp,0,sizeof(dp));
	for(int i=1;i<=n;i++)
	{
		read(a[i]);
	}
	sort(a+1,a+1+n);
//	for(int i=1;i<=n;i++) a[i]%=m;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<m;j++)
		{
			int k=a[i]-j;
			if(k<0) { k=-k; k%=m; k=m-k; }
			else k=k%m;

			dp[k]+=b[j];
//			printf("i==%d,j==%d,k==%d\n",i,j,k);
		}
		b[a[i]%m]++;
		if(dp[0]) break;
	}

	LL res=1;
	for(int i=0;i<m;i++)
	{
		if(dp[i]==0) continue;
		LL update=1ll*dp[i]*i%m;
		res=res*update%m;
	}
	printf("%I64d\n",res);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=2e5+5;
int a[maxn]; int b[maxn]; int dp[1005]; int tmp[1005];
int main(void)
{
	int n,m; scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	bool f=true;
	for(int i=1;i<=n-1;i++)
	{
		b[i]=(a[i+1]-a[i]);
		if(b[i]<0) b[i]=-b[i];
		if(b[i]==0) f=false;
		b[i]%=m;
	}
	if(f==false) { printf("0\n"); return 0; }
//	for(int i=1;i<=n-1;i++) printf("%d\n",b[i]);
	for(int i=1;i<=n-1;i++)
	{
		for(int j=0;j<m;j++) tmp[j]=dp[j];
		for(int j=0;j<m;j++)
		{
			int k=j+b[i];
			k%=m;
			tmp[k]=(tmp[k]+dp[j]);
		}
		for(int j=0;j<m;j++) dp[j]=tmp[j];
		dp[b[i]]++;
	}
//	for(int i=0;i<m;i++) printf("i==%d,dp==%d\n",i,dp[i]);

	int res=1;
	if(dp[0]) { printf("0\n"); return 0; }
	for(int i=1;i<m;i++)
	{
		if(dp[i]==0) continue;
		int update=1ll*dp[i]*i%m;
//		printf("i==%d,update==%d\n",i,update);
		res=1ll*(res*update)%m;
	}
	printf("%d\n",res);
	return 0;
}


/*
  author            :  _jzp,
  date              : 2020-3-3
  problemID         : CF 1305 C
*/

#include "algorithm"
#include "bits/stl_pair.h"
#include "ctype.h"
#include "functional"
#include "iostream"
#include "limits.h"
#include "map"
#include "math.h"
#include "queue"
#include "stdio.h"
#include "set"
#include "vector"
#include "stdlib.h"
#include "string.h"
#include "string"
#include "time.h"
#include "unordered_map"

#define Rep(a, b, c) for (register int a = b; a <= c; ++ a)
#define Rep_s(a, s) for (register int a = 0; s[a]; ++ a)
#define Dep(a, b, c) for (register int a = b; a >= c; -- a)

#define DEBUG
#define CODEFORCES
// #define ONLINE_JUDGE

#ifndef CODEFORCES
    #include "bits/extc++.h"
#endif

namespace IO {
    static char inBuf[32768], *inNow = inBuf, *lenBuf = inBuf;
    inline void gc (char&);
    inline bool gs (char*);
    template <class T > inline bool read (T&);

    static char outBuf[32768], *outNow = outBuf;
    inline void flush ();
    inline void pc (char);
    inline void ps (const char*);
    template < class T > inline void print (T);
    template < class T > inline void println (T);
    template < class T > inline void printsp (int);
};

inline void IO :: gc (char &ch) {
    ch = ((inNow == lenBuf) && (lenBuf = ((inNow = inBuf) + fread (inBuf, 1, sizeof(inBuf), stdin)), inNow == lenBuf)? EOF: *(inNow ++));
}
inline bool IO :: gs (char* s) {
    while (gc (s[0]), isspace (s[0]) && ~s[0])
        ;
    if (!(~s[0]))
        return 0;
    int len = 0;
    while (!isspace (s[len]) && ~s[len])
        gc (s[++ len]);
    s[len] = 0;
    return 1;
}
template < class T >
inline bool IO :: read (T &x) {
    x = 0;
    bool y = 1;
    char ch;
    gc (ch);
    if (!(~ch))
        return 0;
    while (!isdigit (ch))
        y &= !!(ch ^ (char)'-'), gc (ch);
    while (isdigit (ch))
        x = (x << 3) + (x << 1) + (ch & 15), gc (ch);
    x = y? x: -x;
    return 1;
}

inline void IO :: flush () {
    fwrite (outBuf, 1, outNow - outBuf, stdout);
    outNow = outBuf;
    fflush (stdout);
}
inline void IO :: pc (char ch) {
    *(outNow ++) = ch;
    if (outNow - outBuf == sizeof(outBuf))
        flush ();
}
inline void IO :: ps (const char* s) {
    while (*s)
        pc (*(s ++));
}
template < class T >
inline void IO :: print(T x) {
    short num[35], *numNow = num;
    if (x <= 0)
        pc (x? (char)'-': (char)'0'), x = -x;
    while (x)
        *(numNow ++) = x % 10, x /= 10;
    while (numNow != num)
        pc ((char)(48 | *(-- numNow)));
}
template < class T >
inline void IO :: println(T x) {
    print(x), pc(10);
}
template < class T >
inline void IO :: printsp(T x) {
    print(x), pc(32);
}

using IO :: gc;
using IO :: pc;
using IO :: read;
using IO :: print;
using IO :: println;
using IO :: printsp;

namespace Quote {
    template < class T >
    inline T Max (T a, T b) {
        return b < a? a: b;
    }
    template < class T >
    inline T Min (T a, T b) {
        return a < b? a: b;
    }
    template < class T >
    inline T Abs (T x) {
        return x < 0? -x: x;
    }

    struct pair_hash {
        template < class T1, class T2 >
        std :: size_t operator () (const std :: pair < T1, T2 > &x) const {
            return (((std :: hash < T1 > () (x.first) << 10) ^ 0x9e3779b9) ^ (std :: hash < T2 > () (x.second)) ^ 0x4c5968ac);
        }
    };
};

namespace myPrepare {
    void pre() {

    }

};

namespace mySolve {

    // #define SUBTEST

    int n, m;
    int a[100010], num[1010];
    long long ans = 1ll;

    inline void main () {
        read(n), read(m);
        Rep (i, 1, n)
            read(a[i]), ++ num[a[i] % m];
        Rep (i, 0, m - 1)
            if (num[i] > 1) {
                println(0);
                return;
            }
        Rep (i, 1, n)
            Rep (j, i + 1, n)
                ans = 1ll * ans * ((a[i] % m - a[j] % m + m) % m) % m;
        println(ans);
    }
};

namespace myMain {
    inline void solve () {
        int T = 1;
        #ifdef SUBTEST
            read (T);
        #endif
        myPrepare :: pre();
        while (T --) {
            mySolve :: main ();
        }
    }
    inline void main () {
        solve ();
        IO :: flush ();
    }
};

main() {

    #ifndef ONLINE_JUDGE
        freopen ("in.txt", "r", stdin);
        freopen ("out.txt", "w", stdout);
    #endif

    myMain :: main ();
    return 0;
}


/*
  author            :  _jzp,
  date              : 2020-3-3
  problemID         : CF 1305 C
*/

#include "algorithm"
#include "bits/stl_pair.h"
#include "ctype.h"
#include "functional"
#include "iostream"
#include "limits.h"
#include "map"
#include "math.h"
#include "queue"
#include "stdio.h"
#include "set"
#include "vector"
#include "stdlib.h"
#include "string.h"
#include "string"
#include "time.h"
#include "unordered_map"

#define Rep(a, b, c) for (register int a = b; a <= c; ++ a)
#define Rep_s(a, s) for (register int a = 0; s[a]; ++ a)
#define Dep(a, b, c) for (register int a = b; a >= c; -- a)

#define DEBUG
#define CODEFORCES
// #define ONLINE_JUDGE

#ifndef CODEFORCES
    #include "bits/extc++.h"
#endif

namespace IO {
    static char inBuf[32768], *inNow = inBuf, *lenBuf = inBuf;
    inline void gc (char&);
    inline bool gs (char*);
    template <class T > inline bool read (T&);

    static char outBuf[32768], *outNow = outBuf;
    inline void flush ();
    inline void pc (char);
    inline void ps (const char*);
    template < class T > inline void print (T);
    template < class T > inline void println (T);
    template < class T > inline void printsp (int);
};

inline void IO :: gc (char &ch) {
    ch = ((inNow == lenBuf) && (lenBuf = ((inNow = inBuf) + fread (inBuf, 1, sizeof(inBuf), stdin)), inNow == lenBuf)? EOF: *(inNow ++));
}
inline bool IO :: gs (char* s) {
    while (gc (s[0]), isspace (s[0]) && ~s[0])
        ;
    if (!(~s[0]))
        return 0;
    int len = 0;
    while (!isspace (s[len]) && ~s[len])
        gc (s[++ len]);
    s[len] = 0;
    return 1;
}
template < class T >
inline bool IO :: read (T &x) {
    x = 0;
    bool y = 1;
    char ch;
    gc (ch);
    if (!(~ch))
        return 0;
    while (!isdigit (ch))
        y &= !!(ch ^ (char)'-'), gc (ch);
    while (isdigit (ch))
        x = (x << 3) + (x << 1) + (ch & 15), gc (ch);
    x = y? x: -x;
    return 1;
}

inline void IO :: flush () {
    fwrite (outBuf, 1, outNow - outBuf, stdout);
    outNow = outBuf;
    fflush (stdout);
}
inline void IO :: pc (char ch) {
    *(outNow ++) = ch;
    if (outNow - outBuf == sizeof(outBuf))
        flush ();
}
inline void IO :: ps (const char* s) {
    while (*s)
        pc (*(s ++));
}
template < class T >
inline void IO :: print(T x) {
    short num[35], *numNow = num;
    if (x <= 0)
        pc (x? (char)'-': (char)'0'), x = -x;
    while (x)
        *(numNow ++) = x % 10, x /= 10;
    while (numNow != num)
        pc ((char)(48 | *(-- numNow)));
}
template < class T >
inline void IO :: println(T x) {
    print(x), pc(10);
}
template < class T >
inline void IO :: printsp(T x) {
    print(x), pc(32);
}

using IO :: gc;
using IO :: pc;
using IO :: gs;
using IO :: ps;
using IO :: read;
using IO :: print;
using IO :: println;
using IO :: printsp;

namespace Quote {
    template < class T >
    inline T Max (T a, T b) {
        return b < a? a: b;
    }
    template < class T >
    inline T Min (T a, T b) {
        return a < b? a: b;
    }
    template < class T >
    inline T Abs (T x) {
        return x < 0? -x: x;
    }

    struct pair_hash {
        template < class T1, class T2 >
        std :: size_t operator () (const std :: pair < T1, T2 > &x) const {
            return (((std :: hash < T1 > () (x.first) << 10) ^ 0x9e3779b9) ^ (std :: hash < T2 > () (x.second)) ^ 0x4c5968ac);
        }
    };
};

namespace myPrepare {
    void pre() {

    }

};

namespace mySolve {

    // #define SUBTEST

    int n, m;
    int a[200010], num[1010];
    int ans = 1ll;

    inline void main () {
        read(n), read(m);
        if (n > m) {
            println(0);
            return;
        }
        Rep (i, 1, n)
            read(a[i]), ++ num[a[i] % m];
        Rep (i, 0, m - 1)
            if (num[i] > 1) {
                ps("0");
                return;
            }
        Rep (i, 1, n)
            Rep (j, i + 1, n)
                ans = ans * ((a[i] % m - a[j] % m + m) % m) % m;
        println(ans);
    }
};

namespace myMain {
    inline void solve () {
        int T = 1;
        #ifdef SUBTEST
            read (T);
        #endif
        myPrepare :: pre();
        while (T --) {
            mySolve :: main ();
        }
    }
    inline void main () {
        solve ();
        IO :: flush ();
    }
};

main() {

    #ifndef ONLINE_JUDGE
        freopen ("in.txt", "r", stdin);
        freopen ("out.txt", "w", stdout);
    #endif

    myMain :: main ();
    return 0;
}


/*
  author            :  _jzp,
  date              : 2020-3-3
  problemID         : CF 1305 C
*/

#include "algorithm"
#include "bits/stl_pair.h"
#include "ctype.h"
#include "functional"
#include "iostream"
#include "limits.h"
#include "map"
#include "math.h"
#include "queue"
#include "stdio.h"
#include "set"
#include "vector"
#include "stdlib.h"
#include "string.h"
#include "string"
#include "time.h"
#include "unordered_map"

#define Rep(a, b, c) for (register int a = b; a <= c; ++ a)
#define Rep_s(a, s) for (register int a = 0; s[a]; ++ a)
#define Dep(a, b, c) for (register int a = b; a >= c; -- a)

#define DEBUG
#define CODEFORCES
// #define ONLINE_JUDGE

#ifndef CODEFORCES
    #include "bits/extc++.h"
#endif

namespace IO {
    static char inBuf[32768], *inNow = inBuf, *lenBuf = inBuf;
    inline void gc (char&);
    inline bool gs (char*);
    template <class T > inline bool read (T&);

    static char outBuf[32768], *outNow = outBuf;
    inline void flush ();
    inline void pc (char);
    inline void ps (const char*);
    template < class T > inline void print (T);
    template < class T > inline void println (T);
    template < class T > inline void printsp (int);
};

inline void IO :: gc (char &ch) {
    ch = ((inNow == lenBuf) && (lenBuf = ((inNow = inBuf) + fread (inBuf, 1, sizeof(inBuf), stdin)), inNow == lenBuf)? EOF: *(inNow ++));
}
inline bool IO :: gs (char* s) {
    while (gc (s[0]), isspace (s[0]) && ~s[0])
        ;
    if (!(~s[0]))
        return 0;
    int len = 0;
    while (!isspace (s[len]) && ~s[len])
        gc (s[++ len]);
    s[len] = 0;
    return 1;
}
template < class T >
inline bool IO :: read (T &x) {
    x = 0;
    bool y = 1;
    char ch;
    gc (ch);
    if (!(~ch))
        return 0;
    while (!isdigit (ch))
        y &= !!(ch ^ (char)'-'), gc (ch);
    while (isdigit (ch))
        x = (x << 3) + (x << 1) + (ch & 15), gc (ch);
    x = y? x: -x;
    return 1;
}

inline void IO :: flush () {
    fwrite (outBuf, 1, outNow - outBuf, stdout);
    outNow = outBuf;
    fflush (stdout);
}
inline void IO :: pc (char ch) {
    *(outNow ++) = ch;
    if (outNow - outBuf == sizeof(outBuf))
        flush ();
}
inline void IO :: ps (const char* s) {
    while (*s)
        pc (*(s ++));
}
template < class T >
inline void IO :: print(T x) {
    short num[35], *numNow = num;
    if (x <= 0)
        pc (x? (char)'-': (char)'0'), x = -x;
    while (x)
        *(numNow ++) = x % 10, x /= 10;
    while (numNow != num)
        pc ((char)(48 | *(-- numNow)));
}
template < class T >
inline void IO :: println(T x) {
    print(x), pc(10);
}
template < class T >
inline void IO :: printsp(T x) {
    print(x), pc(32);
}

using IO :: gc;
using IO :: pc;
using IO :: gs;
using IO :: ps;
using IO :: read;
using IO :: print;
using IO :: println;
using IO :: printsp;

namespace Quote {
    template < class T >
    inline T Max (T a, T b) {
        return b < a? a: b;
    }
    template < class T >
    inline T Min (T a, T b) {
        return a < b? a: b;
    }
    template < class T >
    inline T Abs (T x) {
        return x < 0? -x: x;
    }

    struct pair_hash {
        template < class T1, class T2 >
        std :: size_t operator () (const std :: pair < T1, T2 > &x) const {
            return (((std :: hash < T1 > () (x.first) << 10) ^ 0x9e3779b9) ^ (std :: hash < T2 > () (x.second)) ^ 0x4c5968ac);
        }
    };
};

namespace myPrepare {
    void pre() {

    }

};

namespace mySolve {

    // #define SUBTEST

    int n, m;
    int a[200010], num[1010];
    int ans = 1ll;

    inline void main () {
        read(n), read(m);
        if (n >= m) {
            println(0);
            return;
        }
        Rep (i, 1, n)
            read(a[i]), ++ num[a[i] % m];
        Rep (i, 0, m - 1)
            if (num[i] > 1) {
                ps("0");
                return;
            }
        Rep (i, 1, n)
            Rep (j, i + 1, n)
                ans = ans * ((a[i] % m - a[j] % m + m) % m) % m;
        println(ans);
    }
};

namespace myMain {
    inline void solve () {
        int T = 1;
        #ifdef SUBTEST
            read (T);
        #endif
        myPrepare :: pre();
        while (T --) {
            mySolve :: main ();
        }
    }
    inline void main () {
        solve ();
        IO :: flush ();
    }
};

main() {

    #ifndef ONLINE_JUDGE
        freopen ("in.txt", "r", stdin);
        freopen ("out.txt", "w", stdout);
    #endif

    myMain :: main ();
    return 0;
}


/*
  author            :  _jzp,
  date              : 2020-3-3
  problemID         : CF 1305 C
*/

#include "algorithm"
#include "bits/stl_pair.h"
#include "ctype.h"
#include "functional"
#include "iostream"
#include "limits.h"
#include "map"
#include "math.h"
#include "queue"
#include "stdio.h"
#include "set"
#include "vector"
#include "stdlib.h"
#include "string.h"
#include "string"
#include "time.h"
#include "unordered_map"

#define Rep(a, b, c) for (register int a = b; a <= c; ++ a)
#define Rep_s(a, s) for (register int a = 0; s[a]; ++ a)
#define Dep(a, b, c) for (register int a = b; a >= c; -- a)

#define DEBUG
#define CODEFORCES
// #define ONLINE_JUDGE

#ifndef CODEFORCES
    #include "bits/extc++.h"
#endif

namespace IO {
    static char inBuf[32768], *inNow = inBuf, *lenBuf = inBuf;
    inline void gc (char&);
    inline bool gs (char*);
    template <class T > inline bool read (T&);

    static char outBuf[32768], *outNow = outBuf;
    inline void flush ();
    inline void pc (char);
    inline void ps (const char*);
    template < class T > inline void print (T);
    template < class T > inline void println (T);
    template < class T > inline void printsp (int);
};

inline void IO :: gc (char &ch) {
    ch = ((inNow == lenBuf) && (lenBuf = ((inNow = inBuf) + fread (inBuf, 1, sizeof(inBuf), stdin)), inNow == lenBuf)? EOF: *(inNow ++));
}
inline bool IO :: gs (char* s) {
    while (gc (s[0]), isspace (s[0]) && ~s[0])
        ;
    if (!(~s[0]))
        return 0;
    int len = 0;
    while (!isspace (s[len]) && ~s[len])
        gc (s[++ len]);
    s[len] = 0;
    return 1;
}
template < class T >
inline bool IO :: read (T &x) {
    x = 0;
    bool y = 1;
    char ch;
    gc (ch);
    if (!(~ch))
        return 0;
    while (!isdigit (ch))
        y &= !!(ch ^ (char)'-'), gc (ch);
    while (isdigit (ch))
        x = (x << 3) + (x << 1) + (ch & 15), gc (ch);
    x = y? x: -x;
    return 1;
}

inline void IO :: flush () {
    fwrite (outBuf, 1, outNow - outBuf, stdout);
    outNow = outBuf;
    fflush (stdout);
}
inline void IO :: pc (char ch) {
    *(outNow ++) = ch;
    if (outNow - outBuf == sizeof(outBuf))
        flush ();
}
inline void IO :: ps (const char* s) {
    while (*s)
        pc (*(s ++));
}
template < class T >
inline void IO :: print(T x) {
    short num[35], *numNow = num;
    if (x <= 0)
        pc (x? (char)'-': (char)'0'), x = -x;
    while (x)
        *(numNow ++) = x % 10, x /= 10;
    while (numNow != num)
        pc ((char)(48 | *(-- numNow)));
}
template < class T >
inline void IO :: println(T x) {
    print(x), pc(10);
}
template < class T >
inline void IO :: printsp(T x) {
    print(x), pc(32);
}

using IO :: gc;
using IO :: pc;
using IO :: read;
using IO :: print;
using IO :: println;
using IO :: printsp;

namespace Quote {
    template < class T >
    inline T Max (T a, T b) {
        return b < a? a: b;
    }
    template < class T >
    inline T Min (T a, T b) {
        return a < b? a: b;
    }
    template < class T >
    inline T Abs (T x) {
        return x < 0? -x: x;
    }

    struct pair_hash {
        template < class T1, class T2 >
        std :: size_t operator () (const std :: pair < T1, T2 > &x) const {
            return (((std :: hash < T1 > () (x.first) << 10) ^ 0x9e3779b9) ^ (std :: hash < T2 > () (x.second)) ^ 0x4c5968ac);
        }
    };
};

namespace myPrepare {
    void pre() {

    }

};

namespace mySolve {

    // #define SUBTEST

    int n, m;
    int a[100010], num[1010];
    int ans = 1ll;

    inline void main () {
        read(n), read(m);
        if (n <= m) {
            println(0);
            return;
        }
        Rep (i, 1, n)
            read(a[i]), ++ num[a[i] % m];
        Rep (i, 0, m - 1)
            if (num[i] > 1) {
                ps("0");
                return;
            }
        Rep (i, 1, n)
            Rep (j, i + 1, n)
                ans = ans * ((a[i] % m - a[j] % m + m) % m) % m;
        println(ans);
    }
};

namespace myMain {
    inline void solve () {
        int T = 1;
        #ifdef SUBTEST
            read (T);
        #endif
        myPrepare :: pre();
        while (T --) {
            mySolve :: main ();
        }
    }
    inline void main () {
        solve ();
        IO :: flush ();
    }
};

main() {

    #ifndef ONLINE_JUDGE
        freopen ("in.txt", "r", stdin);
        freopen ("out.txt", "w", stdout);
    #endif

    myMain :: main ();
    return 0;
}


/*
  author            :  _jzp,
  date              : 2020-3-3
  problemID         : CF 1305 C
*/

#include "algorithm"
#include "bits/stl_pair.h"
#include "ctype.h"
#include "functional"
#include "iostream"
#include "limits.h"
#include "map"
#include "math.h"
#include "queue"
#include "stdio.h"
#include "set"
#include "vector"
#include "stdlib.h"
#include "string.h"
#include "string"
#include "time.h"
#include "unordered_map"

#define Rep(a, b, c) for (register int a = b; a <= c; ++ a)
#define Rep_s(a, s) for (register int a = 0; s[a]; ++ a)
#define Dep(a, b, c) for (register int a = b; a >= c; -- a)

#define DEBUG
#define CODEFORCES
// #define ONLINE_JUDGE

#ifndef CODEFORCES
    #include "bits/extc++.h"
#endif

namespace IO {
    static char inBuf[32768], *inNow = inBuf, *lenBuf = inBuf;
    inline void gc (char&);
    inline bool gs (char*);
    template <class T > inline bool read (T&);

    static char outBuf[32768], *outNow = outBuf;
    inline void flush ();
    inline void pc (char);
    inline void ps (const char*);
    template < class T > inline void print (T);
    template < class T > inline void println (T);
    template < class T > inline void printsp (int);
};

inline void IO :: gc (char &ch) {
    ch = ((inNow == lenBuf) && (lenBuf = ((inNow = inBuf) + fread (inBuf, 1, sizeof(inBuf), stdin)), inNow == lenBuf)? EOF: *(inNow ++));
}
inline bool IO :: gs (char* s) {
    while (gc (s[0]), isspace (s[0]) && ~s[0])
        ;
    if (!(~s[0]))
        return 0;
    int len = 0;
    while (!isspace (s[len]) && ~s[len])
        gc (s[++ len]);
    s[len] = 0;
    return 1;
}
template < class T >
inline bool IO :: read (T &x) {
    x = 0;
    bool y = 1;
    char ch;
    gc (ch);
    if (!(~ch))
        return 0;
    while (!isdigit (ch))
        y &= !!(ch ^ (char)'-'), gc (ch);
    while (isdigit (ch))
        x = (x << 3) + (x << 1) + (ch & 15), gc (ch);
    x = y? x: -x;
    return 1;
}

inline void IO :: flush () {
    fwrite (outBuf, 1, outNow - outBuf, stdout);
    outNow = outBuf;
    fflush (stdout);
}
inline void IO :: pc (char ch) {
    *(outNow ++) = ch;
    if (outNow - outBuf == sizeof(outBuf))
        flush ();
}
inline void IO :: ps (const char* s) {
    while (*s)
        pc (*(s ++));
}
template < class T >
inline void IO :: print(T x) {
    short num[35], *numNow = num;
    if (x <= 0)
        pc (x? (char)'-': (char)'0'), x = -x;
    while (x)
        *(numNow ++) = x % 10, x /= 10;
    while (numNow != num)
        pc ((char)(48 | *(-- numNow)));
}
template < class T >
inline void IO :: println(T x) {
    print(x), pc(10);
}
template < class T >
inline void IO :: printsp(T x) {
    print(x), pc(32);
}

using IO :: gc;
using IO :: pc;
using IO :: read;
using IO :: print;
using IO :: println;
using IO :: printsp;

namespace Quote {
    template < class T >
    inline T Max (T a, T b) {
        return b < a? a: b;
    }
    template < class T >
    inline T Min (T a, T b) {
        return a < b? a: b;
    }
    template < class T >
    inline T Abs (T x) {
        return x < 0? -x: x;
    }

    struct pair_hash {
        template < class T1, class T2 >
        std :: size_t operator () (const std :: pair < T1, T2 > &x) const {
            return (((std :: hash < T1 > () (x.first) << 10) ^ 0x9e3779b9) ^ (std :: hash < T2 > () (x.second)) ^ 0x4c5968ac);
        }
    };
};

namespace myPrepare {
    void pre() {

    }

};

namespace mySolve {

    // #define SUBTEST

    int n, m;
    int a[100010], num[1010];
    long long ans = 1ll;

    inline void main () {
        read(n), read(m);
        Rep (i, 1, n)
            read(a[i]), ++ num[a[i] % m];
        Rep (i, 0, m - 1)
            if (num[i] > 1) {
                println(0);
                return;
            }
        Rep (i, 1, n)
            Rep (j, i + 1, n)
                ans = 1ll * ans * (a[i] % m - a[j] % m + m) % m;
        print(ans);
    }
};

namespace myMain {
    inline void solve () {
        int T = 1;
        #ifdef SUBTEST
            read (T);
        #endif
        myPrepare :: pre();
        while (T --) {
            mySolve :: main ();
        }
    }
    inline void main () {
        solve ();
        IO :: flush ();
    }
};

main() {

    #ifndef ONLINE_JUDGE
        freopen ("in.txt", "r", stdin);
        freopen ("out.txt", "w", stdout);
    #endif

    myMain :: main ();
    return 0;
}


/*
  author            :  _jzp,
  date              : 2020-3-3
  problemID         : CF 1305 C
*/

#include "algorithm"
#include "bits/stl_pair.h"
#include "ctype.h"
#include "functional"
#include "iostream"
#include "limits.h"
#include "map"
#include "math.h"
#include "queue"
#include "stdio.h"
#include "set"
#include "vector"
#include "stdlib.h"
#include "string.h"
#include "string"
#include "time.h"
#include "unordered_map"

#define Rep(a, b, c) for (register int a = b; a <= c; ++ a)
#define Rep_s(a, s) for (register int a = 0; s[a]; ++ a)
#define Dep(a, b, c) for (register int a = b; a >= c; -- a)

#define DEBUG
#define CODEFORCES
// #define ONLINE_JUDGE

#ifndef CODEFORCES
    #include "bits/extc++.h"
#endif

namespace IO {
    static char inBuf[32768], *inNow = inBuf, *lenBuf = inBuf;
    inline void gc (char&);
    inline bool gs (char*);
    template <class T > inline bool read (T&);

    static char outBuf[32768], *outNow = outBuf;
    inline void flush ();
    inline void pc (char);
    inline void ps (const char*);
    template < class T > inline void print (T);
    template < class T > inline void println (T);
    template < class T > inline void printsp (int);
};

inline void IO :: gc (char &ch) {
    ch = ((inNow == lenBuf) && (lenBuf = ((inNow = inBuf) + fread (inBuf, 1, sizeof(inBuf), stdin)), inNow == lenBuf)? EOF: *(inNow ++));
}
inline bool IO :: gs (char* s) {
    while (gc (s[0]), isspace (s[0]) && ~s[0])
        ;
    if (!(~s[0]))
        return 0;
    int len = 0;
    while (!isspace (s[len]) && ~s[len])
        gc (s[++ len]);
    s[len] = 0;
    return 1;
}
template < class T >
inline bool IO :: read (T &x) {
    x = 0;
    bool y = 1;
    char ch;
    gc (ch);
    if (!(~ch))
        return 0;
    while (!isdigit (ch))
        y &= !!(ch ^ (char)'-'), gc (ch);
    while (isdigit (ch))
        x = (x << 3) + (x << 1) + (ch & 15), gc (ch);
    x = y? x: -x;
    return 1;
}

inline void IO :: flush () {
    fwrite (outBuf, 1, outNow - outBuf, stdout);
    outNow = outBuf;
    fflush (stdout);
}
inline void IO :: pc (char ch) {
    *(outNow ++) = ch;
    if (outNow - outBuf == sizeof(outBuf))
        flush ();
}
inline void IO :: ps (const char* s) {
    while (*s)
        pc (*(s ++));
}
template < class T >
inline void IO :: print(T x) {
    short num[35], *numNow = num;
    if (x <= 0)
        pc (x? (char)'-': (char)'0'), x = -x;
    while (x)
        *(numNow ++) = x % 10, x /= 10;
    while (numNow != num)
        pc ((char)(48 | *(-- numNow)));
}
template < class T >
inline void IO :: println(T x) {
    print(x), pc(10);
}
template < class T >
inline void IO :: printsp(T x) {
    print(x), pc(32);
}

using IO :: gc;
using IO :: pc;
using IO :: gs;
using IO :: ps;
using IO :: read;
using IO :: print;
using IO :: println;
using IO :: printsp;

namespace Quote {
    template < class T >
    inline T Max (T a, T b) {
        return b < a? a: b;
    }
    template < class T >
    inline T Min (T a, T b) {
        return a < b? a: b;
    }
    template < class T >
    inline T Abs (T x) {
        return x < 0? -x: x;
    }

    struct pair_hash {
        template < class T1, class T2 >
        std :: size_t operator () (const std :: pair < T1, T2 > &x) const {
            return (((std :: hash < T1 > () (x.first) << 10) ^ 0x9e3779b9) ^ (std :: hash < T2 > () (x.second)) ^ 0x4c5968ac);
        }
    };
};

namespace myPrepare {
    void pre() {

    }

};

namespace mySolve {

    // #define SUBTEST

    int n, m;
    int a[100010], num[1010];
    int ans = 1ll;

    inline void main () {
        read(n), read(m);
        if (n <= m) {
            println(0);
            return;
        }
        Rep (i, 1, n)
            read(a[i]), ++ num[a[i] % m];
        Rep (i, 0, m - 1)
            if (num[i] > 1) {
                ps("0");
                return;
            }
        Rep (i, 1, n)
            Rep (j, i + 1, n)
                ans = ans * ((a[i] % m - a[j] % m + m) % m) % m;
        println(ans);
    }
};

namespace myMain {
    inline void solve () {
        int T = 1;
        #ifdef SUBTEST
            read (T);
        #endif
        myPrepare :: pre();
        while (T --) {
            mySolve :: main ();
        }
    }
    inline void main () {
        solve ();
        IO :: flush ();
    }
};

main() {

    #ifndef ONLINE_JUDGE
        freopen ("in.txt", "r", stdin);
        freopen ("out.txt", "w", stdout);
    #endif

    myMain :: main ();
    return 0;
}


/*
  author            :  _jzp,
  date              : 2020-3-3
  problemID         : CF 1305 C
*/

#include "algorithm"
#include "bits/stl_pair.h"
#include "ctype.h"
#include "functional"
#include "iostream"
#include "limits.h"
#include "map"
#include "math.h"
#include "queue"
#include "stdio.h"
#include "set"
#include "vector"
#include "stdlib.h"
#include "string.h"
#include "string"
#include "time.h"
#include "unordered_map"

#define Rep(a, b, c) for (register int a = b; a <= c; ++ a)
#define Rep_s(a, s) for (register int a = 0; s[a]; ++ a)
#define Dep(a, b, c) for (register int a = b; a >= c; -- a)

#define DEBUG
#define CODEFORCES
// #define ONLINE_JUDGE

#ifndef CODEFORCES
    #include "bits/extc++.h"
#endif

namespace IO {
    static char inBuf[32768], *inNow = inBuf, *lenBuf = inBuf;
    inline void gc (char&);
    inline bool gs (char*);
    template <class T > inline bool read (T&);

    static char outBuf[32768], *outNow = outBuf;
    inline void flush ();
    inline void pc (char);
    inline void ps (const char*);
    template < class T > inline void print (T);
    template < class T > inline void println (T);
    template < class T > inline void printsp (int);
};

inline void IO :: gc (char &ch) {
    ch = ((inNow == lenBuf) && (lenBuf = ((inNow = inBuf) + fread (inBuf, 1, sizeof(inBuf), stdin)), inNow == lenBuf)? EOF: *(inNow ++));
}
inline bool IO :: gs (char* s) {
    while (gc (s[0]), isspace (s[0]) && ~s[0])
        ;
    if (!(~s[0]))
        return 0;
    int len = 0;
    while (!isspace (s[len]) && ~s[len])
        gc (s[++ len]);
    s[len] = 0;
    return 1;
}
template < class T >
inline bool IO :: read (T &x) {
    x = 0;
    bool y = 1;
    char ch;
    gc (ch);
    if (!(~ch))
        return 0;
    while (!isdigit (ch))
        y &= !!(ch ^ (char)'-'), gc (ch);
    while (isdigit (ch))
        x = (x << 3) + (x << 1) + (ch & 15), gc (ch);
    x = y? x: -x;
    return 1;
}

inline void IO :: flush () {
    fwrite (outBuf, 1, outNow - outBuf, stdout);
    outNow = outBuf;
    fflush (stdout);
}
inline void IO :: pc (char ch) {
    *(outNow ++) = ch;
    if (outNow - outBuf == sizeof(outBuf))
        flush ();
}
inline void IO :: ps (const char* s) {
    while (*s)
        pc (*(s ++));
}
template < class T >
inline void IO :: print(T x) {
    short num[35], *numNow = num;
    if (x <= 0)
        pc (x? (char)'-': (char)'0'), x = -x;
    while (x)
        *(numNow ++) = x % 10, x /= 10;
    while (numNow != num)
        pc ((char)(48 | *(-- numNow)));
}
template < class T >
inline void IO :: println(T x) {
    print(x), pc(10);
}
template < class T >
inline void IO :: printsp(T x) {
    print(x), pc(32);
}

using IO :: gc;
using IO :: pc;
using IO :: gs;
using IO :: ps;
using IO :: read;
using IO :: print;
using IO :: println;
using IO :: printsp;

namespace Quote {
    template < class T >
    inline T Max (T a, T b) {
        return b < a? a: b;
    }
    template < class T >
    inline T Min (T a, T b) {
        return a < b? a: b;
    }
    template < class T >
    inline T Abs (T x) {
        return x < 0? -x: x;
    }

    struct pair_hash {
        template < class T1, class T2 >
        std :: size_t operator () (const std :: pair < T1, T2 > &x) const {
            return (((std :: hash < T1 > () (x.first) << 10) ^ 0x9e3779b9) ^ (std :: hash < T2 > () (x.second)) ^ 0x4c5968ac);
        }
    };
};

namespace myPrepare {
    void pre() {

    }

};

namespace mySolve {

    // #define SUBTEST

    int n, m;
    int a[200010], num[1010];
    int ans = 1;

    inline void main () {
        read(n), read(m);
        if (n > m) {
            println(0);
            return;
        }
        Rep (i, 1, n)
            read(a[i]), ++ num[a[i] % m];
        Rep (i, 0, m - 1)
            if (num[i] > 1) {
                ps("0");
                return;
            }
        Rep (i, 1, n)
            Rep (j, i + 1, n)
                ans = ans * ((Abs(a[i] - a[i])) % m) % m;
        println(ans);
    }
};

namespace myMain {
    inline void solve () {
        int T = 1;
        #ifdef SUBTEST
            read (T);
        #endif
        myPrepare :: pre();
        while (T --) {
            mySolve :: main ();
        }
    }
    inline void main () {
        solve ();
        IO :: flush ();
    }
};

main() {

    #ifndef ONLINE_JUDGE
        freopen ("in.txt", "r", stdin);
        freopen ("out.txt", "w", stdout);
    #endif

    myMain :: main ();
    return 0;
}


/*
  author            :  _jzp,
  date              : 2020-3-3
  problemID         : CF 1305 C
*/

#include "algorithm"
#include "bits/stl_pair.h"
#include "ctype.h"
#include "functional"
#include "iostream"
#include "limits.h"
#include "map"
#include "math.h"
#include "queue"
#include "stdio.h"
#include "set"
#include "vector"
#include "stdlib.h"
#include "string.h"
#include "string"
#include "time.h"
#include "unordered_map"

#define Rep(a, b, c) for (register int a = b; a <= c; ++ a)
#define Rep_s(a, s) for (register int a = 0; s[a]; ++ a)
#define Dep(a, b, c) for (register int a = b; a >= c; -- a)

#define DEBUG
#define CODEFORCES
// #define ONLINE_JUDGE

#ifndef CODEFORCES
    #include "bits/extc++.h"
#endif

namespace IO {
    static char inBuf[32768], *inNow = inBuf, *lenBuf = inBuf;
    inline void gc (char&);
    inline bool gs (char*);
    template <class T > inline bool read (T&);

    static char outBuf[32768], *outNow = outBuf;
    inline void flush ();
    inline void pc (char);
    inline void ps (const char*);
    template < class T > inline void print (T);
    template < class T > inline void println (T);
    template < class T > inline void printsp (int);
};

inline void IO :: gc (char &ch) {
    ch = ((inNow == lenBuf) && (lenBuf = ((inNow = inBuf) + fread (inBuf, 1, sizeof(inBuf), stdin)), inNow == lenBuf)? EOF: *(inNow ++));
}
inline bool IO :: gs (char* s) {
    while (gc (s[0]), isspace (s[0]) && ~s[0])
        ;
    if (!(~s[0]))
        return 0;
    int len = 0;
    while (!isspace (s[len]) && ~s[len])
        gc (s[++ len]);
    s[len] = 0;
    return 1;
}
template < class T >
inline bool IO :: read (T &x) {
    x = 0;
    bool y = 1;
    char ch;
    gc (ch);
    if (!(~ch))
        return 0;
    while (!isdigit (ch))
        y &= !!(ch ^ (char)'-'), gc (ch);
    while (isdigit (ch))
        x = (x << 3) + (x << 1) + (ch & 15), gc (ch);
    x = y? x: -x;
    return 1;
}

inline void IO :: flush () {
    fwrite (outBuf, 1, outNow - outBuf, stdout);
    outNow = outBuf;
    fflush (stdout);
}
inline void IO :: pc (char ch) {
    *(outNow ++) = ch;
    if (outNow - outBuf == sizeof(outBuf))
        flush ();
}
inline void IO :: ps (const char* s) {
    while (*s)
        pc (*(s ++));
}
template < class T >
inline void IO :: print(T x) {
    short num[35], *numNow = num;
    if (x <= 0)
        pc (x? (char)'-': (char)'0'), x = -x;
    while (x)
        *(numNow ++) = x % 10, x /= 10;
    while (numNow != num)
        pc ((char)(48 | *(-- numNow)));
}
template < class T >
inline void IO :: println(T x) {
    print(x), pc(10);
}
template < class T >
inline void IO :: printsp(T x) {
    print(x), pc(32);
}

using IO :: gc;
using IO :: pc;
using IO :: gs;
using IO :: ps;
using IO :: read;
using IO :: print;
using IO :: println;
using IO :: printsp;

namespace Quote {
    template < class T >
    inline T Max (T a, T b) {
        return b < a? a: b;
    }
    template < class T >
    inline T Min (T a, T b) {
        return a < b? a: b;
    }
    template < class T >
    inline T Abs (T x) {
        return x < 0? -x: x;
    }

    struct pair_hash {
        template < class T1, class T2 >
        std :: size_t operator () (const std :: pair < T1, T2 > &x) const {
            return (((std :: hash < T1 > () (x.first) << 10) ^ 0x9e3779b9) ^ (std :: hash < T2 > () (x.second)) ^ 0x4c5968ac);
        }
    };
};

namespace myPrepare {
    void pre() {

    }

};

namespace mySolve {

    // #define SUBTEST

    int n, m;
    int a[100010], num[1010];
    int ans = 1ll;

    inline void main () {
        read(n), read(m);
        if (n >= m) {
            println(0);
            return;
        }
        Rep (i, 1, n)
            read(a[i]), ++ num[a[i] % m];
        Rep (i, 0, m - 1)
            if (num[i] > 1) {
                ps("0");
                return;
            }
        Rep (i, 1, n)
            Rep (j, i + 1, n)
                ans = ans * ((a[i] % m - a[j] % m + m) % m) % m;
        println(ans);
    }
};

namespace myMain {
    inline void solve () {
        int T = 1;
        #ifdef SUBTEST
            read (T);
        #endif
        myPrepare :: pre();
        while (T --) {
            mySolve :: main ();
        }
    }
    inline void main () {
        solve ();
        IO :: flush ();
    }
};

main() {

    #ifndef ONLINE_JUDGE
        freopen ("in.txt", "r", stdin);
        freopen ("out.txt", "w", stdout);
    #endif

    myMain :: main ();
    return 0;
}


/*
  author            :  _jzp,
  date              : 2020-3-3
  problemID         : CF 1305 C
*/

#include "algorithm"
#include "bits/stl_pair.h"
#include "ctype.h"
#include "functional"
#include "iostream"
#include "limits.h"
#include "map"
#include "math.h"
#include "queue"
#include "stdio.h"
#include "set"
#include "vector"
#include "stdlib.h"
#include "string.h"
#include "string"
#include "time.h"
#include "unordered_map"

#define Rep(a, b, c) for (register int a = b; a <= c; ++ a)
#define Rep_s(a, s) for (register int a = 0; s[a]; ++ a)
#define Dep(a, b, c) for (register int a = b; a >= c; -- a)

#define DEBUG
#define CODEFORCES
// #define ONLINE_JUDGE

#ifndef CODEFORCES
    #include "bits/extc++.h"
#endif

namespace IO {
    static char inBuf[32768], *inNow = inBuf, *lenBuf = inBuf;
    inline void gc (char&);
    inline bool gs (char*);
    template <class T > inline bool read (T&);

    static char outBuf[32768], *outNow = outBuf;
    inline void flush ();
    inline void pc (char);
    inline void ps (const char*);
    template < class T > inline void print (T);
    template < class T > inline void println (T);
    template < class T > inline void printsp (int);
};

inline void IO :: gc (char &ch) {
    ch = ((inNow == lenBuf) && (lenBuf = ((inNow = inBuf) + fread (inBuf, 1, sizeof(inBuf), stdin)), inNow == lenBuf)? EOF: *(inNow ++));
}
inline bool IO :: gs (char* s) {
    while (gc (s[0]), isspace (s[0]) && ~s[0])
        ;
    if (!(~s[0]))
        return 0;
    int len = 0;
    while (!isspace (s[len]) && ~s[len])
        gc (s[++ len]);
    s[len] = 0;
    return 1;
}
template < class T >
inline bool IO :: read (T &x) {
    x = 0;
    bool y = 1;
    char ch;
    gc (ch);
    if (!(~ch))
        return 0;
    while (!isdigit (ch))
        y &= !!(ch ^ (char)'-'), gc (ch);
    while (isdigit (ch))
        x = (x << 3) + (x << 1) + (ch & 15), gc (ch);
    x = y? x: -x;
    return 1;
}

inline void IO :: flush () {
    fwrite (outBuf, 1, outNow - outBuf, stdout);
    outNow = outBuf;
    fflush (stdout);
}
inline void IO :: pc (char ch) {
    *(outNow ++) = ch;
    if (outNow - outBuf == sizeof(outBuf))
        flush ();
}
inline void IO :: ps (const char* s) {
    while (*s)
        pc (*(s ++));
}
template < class T >
inline void IO :: print(T x) {
    short num[35], *numNow = num;
    if (x <= 0)
        pc (x? (char)'-': (char)'0'), x = -x;
    while (x)
        *(numNow ++) = x % 10, x /= 10;
    while (numNow != num)
        pc ((char)(48 | *(-- numNow)));
}
template < class T >
inline void IO :: println(T x) {
    print(x), pc(10);
}
template < class T >
inline void IO :: printsp(T x) {
    print(x), pc(32);
}

using IO :: gc;
using IO :: pc;
using IO :: gs;
using IO :: ps;
using IO :: read;
using IO :: print;
using IO :: println;
using IO :: printsp;

namespace Quote {
    template < class T >
    inline T Max (T a, T b) {
        return b < a? a: b;
    }
    template < class T >
    inline T Min (T a, T b) {
        return a < b? a: b;
    }
    template < class T >
    inline T Abs (T x) {
        return x < 0? -x: x;
    }

    struct pair_hash {
        template < class T1, class T2 >
        std :: size_t operator () (const std :: pair < T1, T2 > &x) const {
            return (((std :: hash < T1 > () (x.first) << 10) ^ 0x9e3779b9) ^ (std :: hash < T2 > () (x.second)) ^ 0x4c5968ac);
        }
    };
};

namespace myPrepare {
    void pre() {

    }

};

namespace mySolve {

    using namespace Quote;

    // #define SUBTEST

    int n, m;
    int a[200010], num[1010];
    int ans = 1;

    inline void main () {
        read(n), read(m);
        if (n > m) {
            println(0);
            return;
        }
        Rep (i, 1, n)
            read(a[i]), ++ num[a[i] % m];
        Rep (i, 0, m - 1)
            if (num[i] > 1) {
                ps("0");
                return;
            }
        Rep (i, 1, n)
            Rep (j, i + 1, n)
                ans = ans * ((Abs(a[j] - a[i])) % m) % m;
        println(ans);
    }
};

namespace myMain {
    inline void solve () {
        int T = 1;
        #ifdef SUBTEST
            read (T);
        #endif
        myPrepare :: pre();
        while (T --) {
            mySolve :: main ();
        }
    }
    inline void main () {
        solve ();
        IO :: flush ();
    }
};

main() {

    #ifndef ONLINE_JUDGE
        freopen ("in.txt", "r", stdin);
        freopen ("out.txt", "w", stdout);
    #endif

    myMain :: main ();
    return 0;
}


/*
  author            :  _jzp,
  date              : 2020-3-3
  problemID         : CF 1305 C
*/

#include "algorithm"
#include "bits/stl_pair.h"
#include "ctype.h"
#include "functional"
#include "iostream"
#include "limits.h"
#include "map"
#include "math.h"
#include "queue"
#include "stdio.h"
#include "set"
#include "vector"
#include "stdlib.h"
#include "string.h"
#include "string"
#include "time.h"
#include "unordered_map"

#define Rep(a, b, c) for (register int a = b; a <= c; ++ a)
#define Rep_s(a, s) for (register int a = 0; s[a]; ++ a)
#define Dep(a, b, c) for (register int a = b; a >= c; -- a)

#define DEBUG
#define CODEFORCES
// #define ONLINE_JUDGE

#ifndef CODEFORCES
    #include "bits/extc++.h"
#endif

namespace IO {
    static char inBuf[32768], *inNow = inBuf, *lenBuf = inBuf;
    inline void gc (char&);
    inline bool gs (char*);
    template <class T > inline bool read (T&);

    static char outBuf[32768], *outNow = outBuf;
    inline void flush ();
    inline void pc (char);
    inline void ps (const char*);
    template < class T > inline void print (T);
    template < class T > inline void println (T);
    template < class T > inline void printsp (int);
};

inline void IO :: gc (char &ch) {
    ch = ((inNow == lenBuf) && (lenBuf = ((inNow = inBuf) + fread (inBuf, 1, sizeof(inBuf), stdin)), inNow == lenBuf)? EOF: *(inNow ++));
}
inline bool IO :: gs (char* s) {
    while (gc (s[0]), isspace (s[0]) && ~s[0])
        ;
    if (!(~s[0]))
        return 0;
    int len = 0;
    while (!isspace (s[len]) && ~s[len])
        gc (s[++ len]);
    s[len] = 0;
    return 1;
}
template < class T >
inline bool IO :: read (T &x) {
    x = 0;
    bool y = 1;
    char ch;
    gc (ch);
    if (!(~ch))
        return 0;
    while (!isdigit (ch))
        y &= !!(ch ^ (char)'-'), gc (ch);
    while (isdigit (ch))
        x = (x << 3) + (x << 1) + (ch & 15), gc (ch);
    x = y? x: -x;
    return 1;
}

inline void IO :: flush () {
    fwrite (outBuf, 1, outNow - outBuf, stdout);
    outNow = outBuf;
    fflush (stdout);
}
inline void IO :: pc (char ch) {
    *(outNow ++) = ch;
    if (outNow - outBuf == sizeof(outBuf))
        flush ();
}
inline void IO :: ps (const char* s) {
    while (*s)
        pc (*(s ++));
}
template < class T >
inline void IO :: print(T x) {
    short num[35], *numNow = num;
    if (x <= 0)
        pc (x? (char)'-': (char)'0'), x = -x;
    while (x)
        *(numNow ++) = x % 10, x /= 10;
    while (numNow != num)
        pc ((char)(48 | *(-- numNow)));
}
template < class T >
inline void IO :: println(T x) {
    print(x), pc(10);
}
template < class T >
inline void IO :: printsp(T x) {
    print(x), pc(32);
}

using IO :: gc;
using IO :: pc;
using IO :: gs;
using IO :: ps;
using IO :: read;
using IO :: print;
using IO :: println;
using IO :: printsp;

namespace Quote {
    template < class T >
    inline T Max (T a, T b) {
        return b < a? a: b;
    }
    template < class T >
    inline T Min (T a, T b) {
        return a < b? a: b;
    }
    template < class T >
    inline T Abs (T x) {
        return x < 0? -x: x;
    }

    struct pair_hash {
        template < class T1, class T2 >
        std :: size_t operator () (const std :: pair < T1, T2 > &x) const {
            return (((std :: hash < T1 > () (x.first) << 10) ^ 0x9e3779b9) ^ (std :: hash < T2 > () (x.second)) ^ 0x4c5968ac);
        }
    };
};

namespace myPrepare {
    void pre() {

    }

};

namespace mySolve {

    using namespace Quote;

    // #define SUBTEST

    int n, m;
    int a[200010], num[1010];
    int ans = 1;

    inline void main () {
        read(n), read(m);
        if (n > m) {
            println(0);
            return;
        }
        Rep (i, 1, n)
            read(a[i]), ++ num[a[i] % m];
        Rep (i, 0, m - 1)
            if (num[i] > 1) {
                ps("0");
                return;
            }
        Rep (i, 1, n)
            Rep (j, i + 1, n)
                ans = ans * ((Abs(a[i] - a[i])) % m) % m;
        println(ans);
    }
};

namespace myMain {
    inline void solve () {
        int T = 1;
        #ifdef SUBTEST
            read (T);
        #endif
        myPrepare :: pre();
        while (T --) {
            mySolve :: main ();
        }
    }
    inline void main () {
        solve ();
        IO :: flush ();
    }
};

main() {

    #ifndef ONLINE_JUDGE
        freopen ("in.txt", "r", stdin);
        freopen ("out.txt", "w", stdout);
    #endif

    myMain :: main ();
    return 0;
}