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

//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef set<int> si;
typedef set<ll> sll;
typedef map<int, int> mii;
typedef map<ll, ll> mll;

const double pi = acos(-1.0);
const long long INF = 2e18;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define in insert
#define endl "\n"

#define sqr(a) ((a) * (a))
#define jor(a) !(a&1)// jor means EVEN number
#define bjor(a) (a&1)// bjor means ODD number

#define all(a)  a.begin(), a.end()
#define mem(arr, b) memset(arr, b, sizeof(arr)) //memset only for -1 and 0
//fill(a, a+n, 5) //fill for any value

#define for0(i,b) for(int i=0;i<(b);i++)
#define for1(i,b) for(int i=1;i<=(b);i++)
#define forab(i,a,b) for(int i=(a);i<=(b);i++)
#define forba(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fileRead freopen("input.txt", "r", stdin);
#define fileWrite freopen("output.txt", "w", stdout);

void print(int a[], int n){ // for testing or debugging
    for(int i=0;i<n;i++)cout<<a[i]<<" "; cout<<endl;
}

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

ll f(ll n){
    if(n==1) return 1;
    else {
        return n*(n+1) - n;
    }
}

int main()
{
    int n; cin>>n;
    map<int, int> L,R;
    si sett;
    for0(i,n) {
        string s; cin>>s;
        bool minus=0;
        int c=0;
        for(auto t:s){
            if(t=='(') c++;
            else{
                c--;
            }
            if(c==-1) minus=1;
        }
        if((minus and c==0) or (c>0 and minus)) continue;
        else {
            if(c>=0) R[c]++;
            else L[c]++;
            sett.in(abs(c));
        }
    }
    ll ans=0;
    for(auto t:sett){
        int x = abs(t);
        if(x==0){
            ll y = R[t];
            ans+=f(y);
        }
        else ans+=1LL*L[-x]*R[x];
    }
    cout<<ans;
}


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

//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef set<int> si;
typedef set<ll> sll;
typedef map<int, int> mii;
typedef map<ll, ll> mll;

const double pi = acos(-1.0);
const long long INF = 2e18;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define in insert
#define endl "\n"

#define sqr(a) ((a) * (a))
#define jor(a) !(a&1)// jor means EVEN number
#define bjor(a) (a&1)// bjor means ODD number

#define all(a)  a.begin(), a.end()
#define mem(arr, b) memset(arr, b, sizeof(arr)) //memset only for -1 and 0
//fill(a, a+n, 5) //fill for any value

#define for0(i,b) for(int i=0;i<(b);i++)
#define for1(i,b) for(int i=1;i<=(b);i++)
#define forab(i,a,b) for(int i=(a);i<=(b);i++)
#define forba(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fileRead freopen("input.txt", "r", stdin);
#define fileWrite freopen("output.txt", "w", stdout);

void print(int a[], int n){ // for testing or debugging
    for(int i=0;i<n;i++)cout<<a[i]<<" "; cout<<endl;
}

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

ll f(ll n){
    if(n==1) return 1;
    else {
        return n*(n+1) - n;
    }
}

int main()
{
    ll n; cin>>n;
    map<ll, ll> L,R;
    set<ll> sett;
    for0(i,n) {
        string s; cin>>s;
        bool minus=0;
        ll c=0;
        for(auto t:s){
            if(t=='(') c++;
            else{
                c--;
            }
            if(c==-1) minus=1;
        }
        if((minus and c==0) or (c>0 and minus)) continue;
        else {
            if(c>=0) R[c]++;
            else L[c]++;
            sett.in(abs(c));
        }
    }
    ll ans=0;
    for(auto t:sett){
        ll x = abs(t);
        if(x==0){
            ll y = R[t];
            ans+=f(y);
        }
        else ans+=1LL*L[-x]*R[x];
    }
    cout<<ans;
}


#include <bits/stdc++.h>
#define XOX
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

#define int long long
#define re return
#define beg() begin()
#define cont continue
#define ldb long double
#define db double

#define br break
#define fr first
#define se second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define mkp make_pair

#define pi pair<int,int>
#define pll pair<ll,ll>
#define pdb pair<db,db>
#define pldb pair<ldb,ldb>

#define vi vector<int>
#define vll vector<ll>
#define vdb vector<db>
#define vldb vector<ldb>
#define vpi vector< pi >
#define vpll vector< pll >

#define mi map<int,int>
#define mdb map<db,db>
#define mldb map<ldb,ldb>

#define si set<int>
#define sdb set<db>
#define sldb set<ldb>

#define test int t; cin>>t; while(t--)
#define scan() int n; cin>>n; int a[n]; for(int i=0;i<n;i++) cin>>a[i]
#define scan2() int n,k; cin>>n>>k; int a[n]; for(int i=0;i<n;i++) cin>>a[i]
#define print(a,n) for(int i=0;i<n;i++) cout<<a[i]<<' '
#define mem(a,v) memset(a,v,sizeof(a))
#define srt(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define cn(x) cout<<x<<"\n"
#define cs(x) cout<<x<<" "
#define c(x) cout<<x
#define all(v) v.begin(),v.end()

#define forr(i,a,b) for (int i = (a); i < (b); ++i)
#define rrof(i,a,b) for (int i = (b)-1; i >= (a); --i)

const int MOD = 1e9+7;
const ldb PI = 4*atan((ldb)1);
const int INF = 1e18;
const int NINF = -1e18;

int get_hash(string s){
	int N=1000001;
	int base[N],A=11,MD=1110111110111;
	base[0]=1;

	forr(i,1,N)
	base[i]=(base[i-1]*A)%MD;

	int hs=0;
	forr(i,0,s.size()){
		hs+=(s[i]*base[i]);
		hs%=MD;
	}

	re hs;
}

int power(int a,int n){
	int res=1;

	while(n){
		if(n%2)
		res*=a;
		a*=a;
		n/=2;
	}

	return res;
}

vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}
void debug_out(
	vector<string> __attribute__ ((unused)) args,
	__attribute__ ((unused)) int idx,
	__attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
	template <typename Head, typename... Tail>
	void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

int32_t main(){
	fast;

	int n;
	cin>>n;

	mi mpa;
	vi v;
	forr(i,0,n){
		string s;
		cin>>s;

		int sum=0;
		forr(j,0,s.size()){
			 if(s[j]=='(')
			sum++;

			else
			sum--;
		}

		mpa[sum]++;

		rev(s);
		int s1=0,e=0;

		forr(j,0,s.size()){
			if(s[j]==')')
			s1--;

			else
			s1++;

			if(s1>0){
				e=1;
				break;
			}
		}

		if(e==0)
		v.pb(-1*s1);
	}

	int ans=0;
	forr(i,0,v.size())
	ans+=mpa[v[i]];

	cout<<ans;
	re 0;
}


// Problem : C. Bracket Sequences Concatenation Problem
// Contest : Codeforces - Educational Codeforces Round 45 (Rated for Div. 2)
// URL : https://codeforces.com/contest/990/problem/C
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define XOX
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

#define int long long
#define re return
#define beg() begin()
#define cont continue
#define ldb long double
#define db double

#define br break
#define fr first
#define se second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define mkp make_pair

#define pi pair<int,int>
#define pll pair<ll,ll>
#define pdb pair<db,db>
#define pldb pair<ldb,ldb>

#define vi vector<int>
#define vll vector<ll>
#define vdb vector<db>
#define vldb vector<ldb>
#define vpi vector< pi >
#define vpll vector< pll >

#define mi map<int,int>
#define mdb map<db,db>
#define mldb map<ldb,ldb>

#define si set<int>
#define sdb set<db>
#define sldb set<ldb>

#define test int t; cin>>t; while(t--)
#define scan() int n; cin>>n; int a[n]; for(int i=0;i<n;i++) cin>>a[i]
#define scan2() int n,k; cin>>n>>k; int a[n]; for(int i=0;i<n;i++) cin>>a[i]
#define print(a,n) for(int i=0;i<n;i++) cout<<a[i]<<' '
#define mem(a,v) memset(a,v,sizeof(a))
#define srt(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define cn(x) cout<<x<<"\n"
#define cs(x) cout<<x<<" "
#define c(x) cout<<x
#define all(v) v.begin(),v.end()

#define forr(i,a,b) for (int i = (a); i < (b); ++i)
#define rrof(i,a,b) for (int i = (b)-1; i >= (a); --i)

const int MOD = 1e9+7;
const ldb PI = 4*atan((ldb)1);
const int INF = 1e18;
const int NINF = -1e18;

int get_hash(string s){
	int N=1000001;
	int base[N],A=11,MD=1110111110111;
	base[0]=1;

	forr(i,1,N)
	base[i]=(base[i-1]*A)%MD;

	int hs=0;
	forr(i,0,s.size()){
		hs+=(s[i]*base[i]);
		hs%=MD;
	}

	re hs;
}

int power(int a,int n){
	int res=1;

	while(n){
		if(n%2)
		res*=a;
		a*=a;
		n/=2;
	}

	return res;
}

vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}
void debug_out(
	vector<string> __attribute__ ((unused)) args,
	__attribute__ ((unused)) int idx,
	__attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
	template <typename Head, typename... Tail>
	void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

int32_t main(){
	fast;

	int n;
	cin>>n;

	string s[n];
	int cnt=0;
	mi mpa1,mpa2;

	forr(i,0,n){
		cin>>s[i];

		int sum=0;
		if(s[i][0]=='(' || (s[i][0]==')' && s[i][s[i].size()-1]==')')){
			forr(j,0,s[i].size()){
				if(s[i][j]=='(')
				sum++;

				else
				sum--;
			}

			if(sum>0)
			mpa1[sum]++;

			else if(sum<0)
			mpa2[sum]++;

			else
			cnt++;
		}
	}

	int ans=0;
	for(auto it=mpa1.begin();it!=mpa1.end();++it){
		int x=-1*(it->fr);
		auto it1=mpa2.lb(x);

		if(it1->fr==x)
		ans+=it1->se*it->se;
	}

	int v=cnt*cnt;
	ans+=v;
	cout<<ans;
	re 0;
}


#include <bits/stdc++.h>
#define XOX
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

#define int long long
#define re return
#define beg() begin()
#define cont continue
#define ldb long double
#define db double

#define br break
#define fr first
#define se second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define mkp make_pair

#define pi pair<int,int>
#define pll pair<ll,ll>
#define pdb pair<db,db>
#define pldb pair<ldb,ldb>

#define vi vector<int>
#define vll vector<ll>
#define vdb vector<db>
#define vldb vector<ldb>
#define vpi vector< pi >
#define vpll vector< pll >

#define mi map<int,int>
#define mdb map<db,db>
#define mldb map<ldb,ldb>

#define si set<int>
#define sdb set<db>
#define sldb set<ldb>

#define test int t; cin>>t; while(t--)
#define scan() int n; cin>>n; int a[n]; for(int i=0;i<n;i++) cin>>a[i]
#define scan2() int n,k; cin>>n>>k; int a[n]; for(int i=0;i<n;i++) cin>>a[i]
#define print(a,n) for(int i=0;i<n;i++) cout<<a[i]<<' '
#define mem(a,v) memset(a,v,sizeof(a))
#define srt(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define cn(x) cout<<x<<"\n"
#define cs(x) cout<<x<<" "
#define c(x) cout<<x
#define all(v) v.begin(),v.end()

#define forr(i,a,b) for (int i = (a); i < (b); ++i)
#define rrof(i,a,b) for (int i = (b)-1; i >= (a); --i)

const int MOD = 1e9+7;
const ldb PI = 4*atan((ldb)1);
const int INF = 1e18;
const int NINF = -1e18;

int get_hash(string s){
	int N=1000001;
	int base[N],A=11,MD=1110111110111;
	base[0]=1;

	forr(i,1,N)
	base[i]=(base[i-1]*A)%MD;

	int hs=0;
	forr(i,0,s.size()){
		hs+=(s[i]*base[i]);
		hs%=MD;
	}

	re hs;
}

int power(int a,int n){
	int res=1;

	while(n){
		if(n%2)
		res*=a;
		a*=a;
		n/=2;
	}

	return res;
}

vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}
void debug_out(
	vector<string> __attribute__ ((unused)) args,
	__attribute__ ((unused)) int idx,
	__attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
	template <typename Head, typename... Tail>
	void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

int32_t main(){
	fast;

	int n;
	cin>>n;

	mi mpa;
	vi v;
	forr(i,0,n){
		string s;
		cin>>s;

		int e=0;

		int sum=0;
		forr(j,0,s.size()){
			 if(s[j]=='(')
			sum++;

			else
			sum--;

			if(sum<0){
				e=1;
				break;
			}
		}

		if(e==0)
		mpa[sum]++;

		e=0;
		rev(s);
		int s1=0;

		forr(j,0,s.size()){
			if(s[j]==')')
			s1--;

			else
			s1++;

			if(s1>0){
				e=1;
				break;
			}
		}

		if(e==0)
		v.pb(-1*s1);
	}

	int ans=0;
	forr(i,0,v.size())
	ans+=mpa[v[i]];

	cout<<ans;
	re 0;
}


// Problem : C. Bracket Sequences Concatenation Problem
// Contest : Codeforces - Educational Codeforces Round 45 (Rated for Div. 2)
// URL : https://codeforces.com/contest/990/problem/C
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define XOX
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

#define int long long
#define re return
#define beg() begin()
#define cont continue
#define ldb long double
#define db double

#define br break
#define fr first
#define se second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define mkp make_pair

#define pi pair<int,int>
#define pll pair<ll,ll>
#define pdb pair<db,db>
#define pldb pair<ldb,ldb>

#define vi vector<int>
#define vll vector<ll>
#define vdb vector<db>
#define vldb vector<ldb>
#define vpi vector< pi >
#define vpll vector< pll >

#define mi map<int,int>
#define mdb map<db,db>
#define mldb map<ldb,ldb>

#define si set<int>
#define sdb set<db>
#define sldb set<ldb>

#define test int t; cin>>t; while(t--)
#define scan() int n; cin>>n; int a[n]; for(int i=0;i<n;i++) cin>>a[i]
#define scan2() int n,k; cin>>n>>k; int a[n]; for(int i=0;i<n;i++) cin>>a[i]
#define print(a,n) for(int i=0;i<n;i++) cout<<a[i]<<' '
#define mem(a,v) memset(a,v,sizeof(a))
#define srt(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define cn(x) cout<<x<<"\n"
#define cs(x) cout<<x<<" "
#define c(x) cout<<x
#define all(v) v.begin(),v.end()

#define forr(i,a,b) for (int i = (a); i < (b); ++i)
#define rrof(i,a,b) for (int i = (b)-1; i >= (a); --i)

const int MOD = 1e9+7;
const ldb PI = 4*atan((ldb)1);
const int INF = 1e18;
const int NINF = -1e18;

int get_hash(string s){
	int N=1000001;
	int base[N],A=11,MD=1110111110111;
	base[0]=1;

	forr(i,1,N)
	base[i]=(base[i-1]*A)%MD;

	int hs=0;
	forr(i,0,s.size()){
		hs+=(s[i]*base[i]);
		hs%=MD;
	}

	re hs;
}

int power(int a,int n){
	int res=1;

	while(n){
		if(n%2)
		res*=a;
		a*=a;
		n/=2;
	}

	return res;
}

vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}
void debug_out(
	vector<string> __attribute__ ((unused)) args,
	__attribute__ ((unused)) int idx,
	__attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
	template <typename Head, typename... Tail>
	void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

int32_t main(){
	fast;

	int n;
	cin>>n;

	string s[n];
	int cnt=0;
	mi mpa1,mpa2;

	forr(i,0,n){
		cin>>s[i];

		int sum=0,e=0;
		forr(j,0,s[i].size()){
			if(s[i][j]=='(')
			sum++;

			else
			sum--;

			if(j!=s[i].size()-1 && sum<0){
				e=1;
				br;
			}
		}

		if(e==1)
		continue;

		if(sum>0)
		mpa1[sum]++;

		else if(sum<0)
		mpa2[sum]++;

		else
		cnt++;
	}

	int ans=0;
	for(auto it=mpa1.begin();it!=mpa1.end();++it){
		int x=-1*(it->fr);
		auto it1=mpa2.lb(x);

		if(it1->fr==x)
		ans+=it1->se*it->se;
	}

	int v=cnt*cnt;
	ans+=v;
	cout<<ans;
	re 0;
}


// Problem : C. Bracket Sequences Concatenation Problem
// Contest : Codeforces - Educational Codeforces Round 45 (Rated for Div. 2)
// URL : https://codeforces.com/contest/990/problem/C
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define XOX
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

#define int long long
#define re return
#define beg() begin()
#define cont continue
#define ldb long double
#define db double

#define br break
#define fr first
#define se second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define mkp make_pair

#define pi pair<int,int>
#define pll pair<ll,ll>
#define pdb pair<db,db>
#define pldb pair<ldb,ldb>

#define vi vector<int>
#define vll vector<ll>
#define vdb vector<db>
#define vldb vector<ldb>
#define vpi vector< pi >
#define vpll vector< pll >

#define mi map<int,int>
#define mdb map<db,db>
#define mldb map<ldb,ldb>

#define si set<int>
#define sdb set<db>
#define sldb set<ldb>

#define test int t; cin>>t; while(t--)
#define scan() int n; cin>>n; int a[n]; for(int i=0;i<n;i++) cin>>a[i]
#define scan2() int n,k; cin>>n>>k; int a[n]; for(int i=0;i<n;i++) cin>>a[i]
#define print(a,n) for(int i=0;i<n;i++) cout<<a[i]<<' '
#define mem(a,v) memset(a,v,sizeof(a))
#define srt(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define cn(x) cout<<x<<"\n"
#define cs(x) cout<<x<<" "
#define c(x) cout<<x
#define all(v) v.begin(),v.end()

#define forr(i,a,b) for (int i = (a); i < (b); ++i)
#define rrof(i,a,b) for (int i = (b)-1; i >= (a); --i)

const int MOD = 1e9+7;
const ldb PI = 4*atan((ldb)1);
const int INF = 1e18;
const int NINF = -1e18;

int get_hash(string s){
	int N=1000001;
	int base[N],A=11,MD=1110111110111;
	base[0]=1;

	forr(i,1,N)
	base[i]=(base[i-1]*A)%MD;

	int hs=0;
	forr(i,0,s.size()){
		hs+=(s[i]*base[i]);
		hs%=MD;
	}

	re hs;
}

int power(int a,int n){
	int res=1;

	while(n){
		if(n%2)
		res*=a;
		a*=a;
		n/=2;
	}

	return res;
}

vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}
void debug_out(
	vector<string> __attribute__ ((unused)) args,
	__attribute__ ((unused)) int idx,
	__attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
	template <typename Head, typename... Tail>
	void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

int32_t main(){
	fast;

	int n;
	cin>>n;

	string s[n];
	int cnt=0;
	mi mpa1,mpa2;

	forr(i,0,n){
		cin>>s[i];

		int sum=0;
		forr(j,0,s[i].size()){
			if(s[i][j]=='(')
			sum++;

			else
			sum--;
		}

		if(sum>0)
		mpa1[sum]++;

		else if(sum<0)
		mpa2[sum]++;

		else
		cnt++;
	}

	int ans=0;
	for(auto it=mpa1.begin();it!=mpa1.end();++it){
		int x=-1*(it->fr);
		auto it1=mpa2.lb(x);

		if(it1->fr==x)
		ans+=it1->se*it->se;
	}

	int v=cnt*cnt;
	ans+=v;
	cout<<ans;
	re 0;
}


// Problem : C. Bracket Sequences Concatenation Problem
// Contest : Codeforces - Educational Codeforces Round 45 (Rated for Div. 2)
// URL : https://codeforces.com/contest/990/problem/C
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define XOX
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

#define int long long
#define re return
#define beg() begin()
#define cont continue
#define ldb long double
#define db double

#define br break
#define fr first
#define se second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define mkp make_pair

#define pi pair<int,int>
#define pll pair<ll,ll>
#define pdb pair<db,db>
#define pldb pair<ldb,ldb>

#define vi vector<int>
#define vll vector<ll>
#define vdb vector<db>
#define vldb vector<ldb>
#define vpi vector< pi >
#define vpll vector< pll >

#define mi map<int,int>
#define mdb map<db,db>
#define mldb map<ldb,ldb>

#define si set<int>
#define sdb set<db>
#define sldb set<ldb>

#define test int t; cin>>t; while(t--)
#define scan() int n; cin>>n; int a[n]; for(int i=0;i<n;i++) cin>>a[i]
#define scan2() int n,k; cin>>n>>k; int a[n]; for(int i=0;i<n;i++) cin>>a[i]
#define print(a,n) for(int i=0;i<n;i++) cout<<a[i]<<' '
#define mem(a,v) memset(a,v,sizeof(a))
#define srt(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define cn(x) cout<<x<<"\n"
#define cs(x) cout<<x<<" "
#define c(x) cout<<x
#define all(v) v.begin(),v.end()

#define forr(i,a,b) for (int i = (a); i < (b); ++i)
#define rrof(i,a,b) for (int i = (b)-1; i >= (a); --i)

const int MOD = 1e9+7;
const ldb PI = 4*atan((ldb)1);
const int INF = 1e18;
const int NINF = -1e18;

int get_hash(string s){
	int N=1000001;
	int base[N],A=11,MD=1110111110111;
	base[0]=1;

	forr(i,1,N)
	base[i]=(base[i-1]*A)%MD;

	int hs=0;
	forr(i,0,s.size()){
		hs+=(s[i]*base[i]);
		hs%=MD;
	}

	re hs;
}

int power(int a,int n){
	int res=1;

	while(n){
		if(n%2)
		res*=a;
		a*=a;
		n/=2;
	}

	return res;
}

vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}
void debug_out(
	vector<string> __attribute__ ((unused)) args,
	__attribute__ ((unused)) int idx,
	__attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
	template <typename Head, typename... Tail>
	void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

int32_t main(){
	fast;

	int n;
	cin>>n;

	string s[n];
	int cnt=0;
	mi mpa1,mpa2;

	forr(i,0,n){
		cin>>s[i];

		if(s[i][0]=='('){
			int sum=0;
			forr(j,0,s[i].size()){
				if(s[i][j]=='(')
				sum++;

				else
				sum--;
			}

			if(sum!=0)
			mpa1[sum]++;

			else
			cnt++;
		}

		else if(s[i][0]==')' && s[i][s[i].size()-1]==')'){
			int sum=0;
			forr(j,0,s[i].size()){
				if(s[i][j]=='(')
				sum++;

				else
				sum--;
			}

			mpa2[sum]++;
		}
	}

	int ans=0;
	for(auto it=mpa1.beg();it!=mpa1.end();++it){
		int x=-1*(it->fr);
		auto it1=mpa2.lb(x);

		if(it1->fr==x)
		ans+=it1->se*it->se;
	}

	for(auto it=mpa1.begin();it!=mpa1.end();++it){
		int x=-1*(it->fr);
		auto it1=mpa1.lb(x);

		if(it1->fr==x && x<0)
		ans+=it1->se*it->se;
	}

	// cout<<ans<<" "<<cnt<<"\n";
	int v=cnt*cnt;
	ans+=v;
	cout<<ans;
	re 0;
}


// Problem : C. Bracket Sequences Concatenation Problem
// Contest : Codeforces - Educational Codeforces Round 45 (Rated for Div. 2)
// URL : https://codeforces.com/contest/990/problem/C
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define XOX
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

#define int long long
#define re return
#define beg() begin()
#define cont continue
#define ldb long double
#define db double

#define br break
#define fr first
#define se second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define mkp make_pair

#define pi pair<int,int>
#define pll pair<ll,ll>
#define pdb pair<db,db>
#define pldb pair<ldb,ldb>

#define vi vector<int>
#define vll vector<ll>
#define vdb vector<db>
#define vldb vector<ldb>
#define vpi vector< pi >
#define vpll vector< pll >

#define mi map<int,int>
#define mdb map<db,db>
#define mldb map<ldb,ldb>

#define si set<int>
#define sdb set<db>
#define sldb set<ldb>

#define test int t; cin>>t; while(t--)
#define scan() int n; cin>>n; int a[n]; for(int i=0;i<n;i++) cin>>a[i]
#define scan2() int n,k; cin>>n>>k; int a[n]; for(int i=0;i<n;i++) cin>>a[i]
#define print(a,n) for(int i=0;i<n;i++) cout<<a[i]<<' '
#define mem(a,v) memset(a,v,sizeof(a))
#define srt(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define cn(x) cout<<x<<"\n"
#define cs(x) cout<<x<<" "
#define c(x) cout<<x
#define all(v) v.begin(),v.end()

#define forr(i,a,b) for (int i = (a); i < (b); ++i)
#define rrof(i,a,b) for (int i = (b)-1; i >= (a); --i)

const int MOD = 1e9+7;
const ldb PI = 4*atan((ldb)1);
const int INF = 1e18;
const int NINF = -1e18;

int get_hash(string s){
	int N=1000001;
	int base[N],A=11,MD=1110111110111;
	base[0]=1;

	forr(i,1,N)
	base[i]=(base[i-1]*A)%MD;

	int hs=0;
	forr(i,0,s.size()){
		hs+=(s[i]*base[i]);
		hs%=MD;
	}

	re hs;
}

int power(int a,int n){
	int res=1;

	while(n){
		if(n%2)
		res*=a;
		a*=a;
		n/=2;
	}

	return res;
}

vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}
void debug_out(
	vector<string> __attribute__ ((unused)) args,
	__attribute__ ((unused)) int idx,
	__attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
	template <typename Head, typename... Tail>
	void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

int32_t main(){
	fast;

	int n;
	cin>>n;

	string s[n];
	int cnt=0;
	mi mpa1,mpa2;

	forr(i,0,n){
		cin>>s[i];

		int sum=0;
		if(s[i][0]=='('){
			forr(j,0,s[i].size()){
				if(s[i][j]=='(')
				sum++;

				else
				sum--;
			}

			if(sum>0)
			mpa1[sum]++;

			else if(sum<0)
			mpa2[sum]++;

			else
			cnt++;
		}

		else if(s[i][0]==')' && s[i][s[i].size()-1]==')'){
			forr(j,0,s[i].size()){
				if(s[i][j]=='(')
				sum++;

				else
				sum--;
			}

			if(sum<0)
			mpa2[sum]++;
		}
	}

	int ans=0;
	for(auto it=mpa1.begin();it!=mpa1.end();++it){
		int x=-1*(it->fr);
		auto it1=mpa2.lb(x);

		if(it1->fr==x)
		ans+=it1->se*it->se;
	}

	int v=cnt*cnt;
	ans+=v;
	cout<<ans;
	re 0;
}


#pragma GCC optimize("O3")
#define first x
#define second y
#include <bits/stdc++.h>

using namespace std;

enum {MOD0 = 1000000000, MOD7 = 1000000007, MOD9 = 1000000009};
typedef unsigned short ushort;typedef unsigned int uint;typedef long long ll;typedef unsigned long long ull;
template <typename T> ostream &operator<<(ostream &cout, vector<T> &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << " "; return cout;}
template <typename T> ostream &operator<<(ostream &cout, vector<vector<T> > &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << endl; return cout;}
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif

constexpr size_t OFFSET = 300010;
vector<int> mns[2 * OFFSET + 1];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        int cur = 0;
        int mn = 0;
        for (size_t j = 0; j < s.size(); ++j) {
            if (s[j] == '(') {
                ++cur;
            } else {
                --cur;
            }
            mn = max(mn, -cur);
        }
        mns[cur + OFFSET].push_back(mn);
    }
    for (size_t i = 0; i < sizeof(mns) / sizeof(*mns); ++i) {
        sort(mns[i].begin(), mns[i].end());
    }

    ll ans = 0;
    for (size_t i = OFFSET; i < sizeof(mns) / sizeof(*mns); ++i) {
        int cur = i - OFFSET;
        int another = -cur + OFFSET;
        ll l = upper_bound(mns[another].begin(), mns[another].end(), cur) - mns[another].begin();
        ll k = upper_bound(mns[i].begin(), mns[i].end(), 0) - mns[i].begin();
        ans += k * l;
    }
    cout << ans << endl;
}


#pragma GCC optimize("O3")
#define first x
#define second y
#include <bits/stdc++.h>

using namespace std;

enum {MOD0 = 1000000000, MOD7 = 1000000007, MOD9 = 1000000009};
typedef unsigned short ushort;typedef unsigned int uint;typedef long long ll;typedef unsigned long long ull;
template <typename T> ostream &operator<<(ostream &cout, vector<T> &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << " "; return cout;}
template <typename T> ostream &operator<<(ostream &cout, vector<vector<T> > &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << endl; return cout;}
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif

constexpr int OFFSET = 300000;
vector<int> mns[2 * OFFSET + 1];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        int cur = 0;
        int mn = 0;
        for (int j = 0; j < s.size(); ++j) {
            if (s[j] == '(') {
                ++cur;
            } else {
                --cur;
            }
            mn = max(mn, -cur);
        }
        mns[cur + OFFSET].push_back(mn);
    }
    for (int i = 0; i < sizeof(mns) / sizeof(*mns); ++i) {
        sort(mns[i].begin(), mns[i].end());
    }

    int ans = 0;
    for (int i = OFFSET + 1; i < sizeof(mns) / sizeof(*mns); ++i) {
        int cur = i - OFFSET;
        int another = -cur + OFFSET;
        int l = upper_bound(mns[another].begin(), mns[another].end(), cur) - mns[another].begin();
        int k = upper_bound(mns[i].begin(), mns[i].end(), 0) - mns[i].begin();
        ans += k * l;
    }
    ll l = upper_bound(mns[OFFSET].begin(), mns[OFFSET].end(), 0) - mns[OFFSET].begin();
    ans += l * l;
    cout << ans << endl;
}


#pragma GCC optimize("O3")
#define first x
#define second y
#include <bits/stdc++.h>

using namespace std;

enum {MOD0 = 1000000000, MOD7 = 1000000007, MOD9 = 1000000009};
typedef unsigned short ushort;typedef unsigned int uint;typedef long long ll;typedef unsigned long long ull;
template <typename T> ostream &operator<<(ostream &cout, vector<T> &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << " "; return cout;}
template <typename T> ostream &operator<<(ostream &cout, vector<vector<T> > &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << endl; return cout;}
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif

struct Skobka {
    int mn = 0;
    int lopen = 0;
} sk[300000];

constexpr int OFFSET = 300000;
vector<int> mns[2 * OFFSET + 1];

bool check(int i, int j) {
    return sk[i].lopen == -sk[j].lopen && sk[i].lopen >= sk[j].mn;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        int cur = 0;
        int mn = 0;
        for (int j = 0; j < s.size(); ++j) {
            if (s[j] == '(') {
                ++cur;
            } else {
                --cur;
            }
            mn = max(mn, -cur);
        }
        sk[i] = {mn, cur};
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        ans += check(i, i);
        for (int j = i + 1; j < n; ++j) {
            ans += check(i, j);
            ans += check(j, i);
        }
    }
    cout << ans << endl;
}


#pragma GCC optimize("O3")
#define first x
#define second y
#include <bits/stdc++.h>

using namespace std;

enum {MOD0 = 1000000000, MOD7 = 1000000007, MOD9 = 1000000009};
typedef unsigned short ushort;typedef unsigned int uint;typedef long long ll;typedef unsigned long long ull;
template <typename T> ostream &operator<<(ostream &cout, vector<T> &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << " "; return cout;}
template <typename T> ostream &operator<<(ostream &cout, vector<vector<T> > &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << endl; return cout;}
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif

constexpr int OFFSET = 300000;
vector<int> mns[2 * OFFSET + 1];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        int cur = 0;
        int mn = 0;
        for (size_t j = 0; j < s.size(); ++j) {
            if (s[j] == '(') {
                ++cur;
            } else {
                --cur;
            }
            mn = max(mn, -cur);
        }
        mns[cur + OFFSET].push_back(mn);
    }
    for (size_t i = 0; i < sizeof(mns) / sizeof(*mns); ++i) {
        sort(mns[i].begin(), mns[i].end());
    }

    ll ans = 0;
    for (size_t i = OFFSET; i < sizeof(mns) / sizeof(*mns); ++i) {
        size_t cur = i - OFFSET;
        size_t another = -cur + OFFSET;
        size_t l = upper_bound(mns[another].begin(), mns[another].end(), cur) - mns[another].begin();
        size_t k = upper_bound(mns[i].begin(), mns[i].end(), 0) - mns[i].begin();
        ans += k * l;
    }
    cout << ans << endl;
}


#pragma GCC optimize("O3")
#define first x
#define second y
#include <bits/stdc++.h>

using namespace std;

enum {MOD0 = 1000000000, MOD7 = 1000000007, MOD9 = 1000000009};
typedef unsigned short ushort;typedef unsigned int uint;typedef long long ll;typedef unsigned long long ull;
template <typename T> ostream &operator<<(ostream &cout, vector<T> &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << " "; return cout;}
template <typename T> ostream &operator<<(ostream &cout, vector<vector<T> > &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << endl; return cout;}
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif

constexpr int OFFSET = 300000;
vector<int> mns[2 * OFFSET + 1];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        int cur = 0;
        int mn = 0;
        for (int j = 0; j < s.size(); ++j) {
            if (s[j] == '(') {
                ++cur;
            } else {
                --cur;
            }
            mn = max(mn, -cur);
        }
        mns[cur + OFFSET].push_back(mn);
    }
    for (int i = 0; i < sizeof(mns) / sizeof(*mns); ++i) {
        sort(mns[i].begin(), mns[i].end());
    }

    int ans = 0;
    for (int i = OFFSET + 1; i < sizeof(mns) / sizeof(*mns); ++i) {
        int cur = i - OFFSET;
        int another = -cur + OFFSET;
        int l = upper_bound(mns[another].begin(), mns[another].end(), cur) - mns[another].begin();
        ans += l;
    }
    ll l = upper_bound(mns[OFFSET].begin(), mns[OFFSET].end(), 0) - mns[OFFSET].begin();
    ans += l * l;
    cout << ans << endl;
}


#pragma GCC optimize("O3")
#define first x
#define second y
#include <bits/stdc++.h>

using namespace std;

enum {MOD0 = 1000000000, MOD7 = 1000000007, MOD9 = 1000000009};
typedef unsigned short ushort;typedef unsigned int uint;typedef long long ll;typedef unsigned long long ull;
template <typename T> ostream &operator<<(ostream &cout, vector<T> &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << " "; return cout;}
template <typename T> ostream &operator<<(ostream &cout, vector<vector<T> > &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << endl; return cout;}
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif

constexpr int OFFSET = 300000;
vector<int> mns[2 * OFFSET + 1];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        int cur = 0;
        int mn = 0;
        for (int j = 0; j < s.size(); ++j) {
            if (s[j] == '(') {
                ++cur;
            } else {
                --cur;
            }
            mn = max(mn, -cur);
        }
        mns[cur + OFFSET].push_back(mn);
    }
    for (int i = 0; i < sizeof(mns) / sizeof(*mns); ++i) {
        sort(mns[i].begin(), mns[i].end());
    }

    int ans = 0;
    for (int i = OFFSET + 1; i < sizeof(mns) / sizeof(*mns); ++i) {
        int cur = i - OFFSET;
        int another = -cur + OFFSET;
        ll l = upper_bound(mns[another].begin(), mns[another].end(), cur) - mns[another].begin();
        ll k = upper_bound(mns[i].begin(), mns[i].end(), 0) - mns[i].begin();
        ans += k * l;
    }
    ll l = upper_bound(mns[OFFSET].begin(), mns[OFFSET].end(), 0) - mns[OFFSET].begin();
    ans += l * l;
    cout << ans << endl;
}


#pragma GCC optimize("O3")
#define first x
#define second y
#include <bits/stdc++.h>

using namespace std;

enum {MOD0 = 1000000000, MOD7 = 1000000007, MOD9 = 1000000009};
typedef unsigned short ushort;typedef unsigned int uint;typedef long long ll;typedef unsigned long long ull;
template <typename T> ostream &operator<<(ostream &cout, vector<T> &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << " "; return cout;}
template <typename T> ostream &operator<<(ostream &cout, vector<vector<T> > &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << endl; return cout;}
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif

struct Skobka {
    int mn = 0;
    int lopen = 0;
} sk[300000];

constexpr int OFFSET = 300000;
vector<int> mns[2 * OFFSET + 1];

bool check(int i, int j) {
    return sk[i].lopen == -sk[j].lopen && sk[i].lopen >= sk[j].mn;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        int cur = 0;
        int mn = 0;
        for (int j = 0; j < s.size(); ++j) {
            if (s[j] == '(') {
                ++cur;
            } else {
                --cur;
            }
            mn = max(mn, -cur);
        }
        sk[i] = {mn, cur};
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            ans += check(i, j);
        }
    }
    cout << ans << endl;
}


#include <iostream>
#include <algorithm>

using namespace std;

#define MAX_BRACKETS 300000
//const int MAX_BRACKETS = 300000;
#define MAX_SEQ_COUNT 300000
int leftSeq[MAX_SEQ_COUNT]; // the sequences on the left side, which need concatenation to the right
int rightSeq[MAX_SEQ_COUNT]; // the sequences on the right side, which need concatenation to the left
// the indices for the above arrays signify the number of brackets to be balanced out

int main() {
	int n;
	cin >> n;
	int alreadyRegular = 0;
	for (int seq = 0; seq < n; seq++) {
		string si;
		cin >> si;
		int len = si.length();
		int difference = 0; // the signed current difference between the number of '(' and ')' - no'(' - no')'
		int minDifference = 0;
		for (int i = 0; i < len; i++) {
			if (si[i] == '(') {
				difference += 1;
			}
			else {
				difference -= 1;
				minDifference = min(minDifference, difference);
			}
		}
        // The whole string can be represented as a number of ')'s followed by a number of '('s, if all the '()'s are cancelled out - dayvanili
        // From the perspective of this problem these two sequences are equivalent

        int closeCount = -minDifference;
        int openCount = difference - minDifference;
        if (!openCount && !closeCount) { // if already a regular bracket sequence (ie 0 of both types of brackets in the simplified version of the sequence)
            alreadyRegular++;
        /*in the following conditions, we already know (as we are in the else section) that they are not both 0*/
        } else if (!openCount) { // if it only requires concatenation on left side (ie only has ')' brackets in the simplified version of the sequence)
            rightSeq[closeCount]++;
        } else if (!closeCount) { // if it only requires concatenation on right side (ie only has '(' brackets in the simplified version of the sequence)
            leftSeq[openCount]++;
        }
	}

	long long pairSum = alreadyRegular*1ll*alreadyRegular;
	for (int i = 0; i < MAX_SEQ_COUNT; i++) { // takes slightly more time to run all the way to MAX but easier than calculating a maximum
        pairSum += leftSeq[i]*rightSeq[i];
	}

	cout << pairSum << endl;
	return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

#define MAX_BRACKETS 300000
//const int MAX_BRACKETS = 300000;
#define MAX_SEQ_COUNT 300000
int leftSeq[MAX_SEQ_COUNT]; // the sequences on the left side, which need concatenation to the right
int rightSeq[MAX_SEQ_COUNT]; // the sequences on the right side, which need concatenation to the left
// the indices for the above arrays signify the number of brackets to be balanced out

int main() {
	int n;
	cin >> n;
	int alreadyRegular = 0;
	for (int seq = 0; seq < n; seq++) {
		string si;
		cin >> si;
		int len = si.length();
		int difference = 0; // the signed current difference between the number of '(' and ')' - no'(' - no')'
		int minDifference = 0;
		for (int i = 0; i < len; i++) {
			if (si[i] == '(') {
				difference += 1;
			}
			else {
				difference -= 1;
				minDifference = min(minDifference, difference);
			}
		}
        // The whole string can be represented as a number of ')'s followed by a number of '('s, if all the '()'s are cancelled out - dayvanili
        // From the perspective of this problem these two sequences are equivalent

        int closeCount = -minDifference;
        int openCount = difference - minDifference;
        if (!openCount && !closeCount) { // if already a regular bracket sequence (ie 0 of both types of brackets in the simplified version of the sequence)
            alreadyRegular++;
        /*in the following conditions, we already know (as we are in the else section) that they are not both 0*/
        } else if (!openCount) { // if it only requires concatenation on left side (ie only has ')' brackets in the simplified version of the sequence)
            rightSeq[closeCount]++;
        } else if (!closeCount) { // if it only requires concatenation on right side (ie only has '(' brackets in the simplified version of the sequence)
            leftSeq[openCount]++;
        }
	}

	long long pairSum = alreadyRegular * 1ll * alreadyRegular;
	for (int i = 0; i < MAX_SEQ_COUNT; i++) { // takes slightly more time to run all the way to MAX but easier than calculating a maximum
        pairSum += leftSeq[i] * 1ll * rightSeq[i];
	}

	cout << pairSum << endl;
	return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

#define MAX_BRACKETS 300000
//const int MAX_BRACKETS = 300000;
#define MAX_SEQ_COUNT 300000
int leftSeq[MAX_SEQ_COUNT]; // the sequences on the left side, which need concatenation to the right
int rightSeq[MAX_SEQ_COUNT]; // the sequences on the right side, which need concatenation to the left
// the indices for the above arrays signify the number of brackets to be balanced out

int main() {
	int n;
	cin >> n;
	int alreadyRegular = 0;
	for (int seq = 0; seq < n; seq++) {
		string si;
		cin >> si;
		int len = si.length();
		int difference = 0; // the signed current difference between the number of '(' and ')' - no'(' - no')'
		int minDifference = 0;
		for (int i = 0; i < len; i++) {
			if (si[i] == '(') {
				difference += 1;
			}
			else {
				difference -= 1;
				minDifference = min(minDifference, difference);
			}
		}
        // The whole string can be represented as a number of ')'s followed by a number of '('s, if all the '()'s are cancelled out - dayvanili
        // From the perspective of this problem these two sequences are equivalent

        int closeCount = -minDifference;
        int openCount = difference - minDifference;
        if (!openCount && !closeCount) { // if already a regular bracket sequence (ie 0 of both types of brackets in the simplified version of the sequence)
            alreadyRegular++;
        /*in the following conditions, we already know (as we are in the else section) that they are not both 0*/
        } else if (!openCount) { // if it only requires concatenation on left side (ie only has ')' brackets in the simplified version of the sequence)
            rightSeq[closeCount]++;
        } else if (!closeCount) { // if it only requires concatenation on right side (ie only has '(' brackets in the simplified version of the sequence)
            leftSeq[openCount]++;
        }
	}

	int pairSum = alreadyRegular*alreadyRegular;
	for (int i = 0; i < MAX_SEQ_COUNT; i++) { // takes slightly more time to run all the way to MAX but easier than calculating a maximum
        pairSum += leftSeq[i]*rightSeq[i];
	}

	cout << pairSum << endl;
	return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

#define MAX_BRACKETS 300000
//const int MAX_BRACKETS = 300000;
#define MAX_SEQ_COUNT 300000
int leftSeq[MAX_SEQ_COUNT]; // the sequences on the left side, which need concatenation to the right
int rightSeq[MAX_SEQ_COUNT]; // the sequences on the right side, which need concatenation to the left
// the indices for the above arrays signify the number of brackets to be balanced out

int main() {
	int n;
	cin >> n;
	int alreadyRegular = 0;
	for (int seq = 0; seq < n; seq++) {
		string si;
		cin >> si;
		int len = si.length();
		int difference = 0; // the signed current difference between the number of '(' and ')' - no'(' - no')'
		int minDifference = 0;
		for (int i = 0; i < len; i++) {
			if (si[i] == '(') {
				difference += 1;
			}
			else {
				difference -= 1;
				minDifference = min(minDifference, difference);
			}
		}
        // The whole string can be represented as a number of ')'s followed by a number of '('s, if all the '()'s are cancelled out - dayvanili
        // From the perspective of this problem these two sequences are equivalent

        int closeCount = -minDifference;
        int openCount = difference - minDifference;
        if (!openCount && !closeCount) { // if already a regular bracket sequence (ie 0 of both types of brackets in the simplified version of the sequence)
            alreadyRegular++;
        /*in the following conditions, we already know (as we are in the else section) that they are not both 0*/
        } else if (!openCount) { // if it only requires concatenation on left side (ie only has ')' brackets in the simplified version of the sequence)
            rightSeq[closeCount]++;
        } else if (!closeCount) { // if it only requires concatenation on right side (ie only has '(' brackets in the simplified version of the sequence)
            leftSeq[openCount]++;
        }
	}

	long long pairSum = alreadyRegular*alreadyRegular;
	for (int i = 0; i < MAX_SEQ_COUNT; i++) { // takes slightly more time to run all the way to MAX but easier than calculating a maximum
        pairSum += leftSeq[i]*rightSeq[i];
	}

	cout << pairSum << endl;
	return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

#define MAX_BRACKETS 300000
//const int MAX_BRACKETS = 300000;
#define MAX_SEQ_COUNT 300000
int leftSeq[MAX_SEQ_COUNT]; // the sequences on the left side, which need concatenation to the right
int rightSeq[MAX_SEQ_COUNT]; // the sequences on the right side, which need concatenation to the left
// the indices for the above arrays signify the number of brackets to be balanced out

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

	int n;
	cin >> n;
	int alreadyRegular = 0;
	for (int seq = 0; seq < n; seq++) {
		string si;
		cin >> si;
		int len = si.length();
		int difference = 0; // the signed current difference between the number of '(' and ')' - no'(' - no')'
		int minDifference = 0;
		for (int i = 0; i < len; i++) {
			if (si[i] == '(') {
				difference += 1;
			}
			else {
				difference -= 1;
				minDifference = min(minDifference, difference);
			}
		}
        // The whole string can be represented as a number of ')'s followed by a number of '('s, if all the '()'s are cancelled out - dayvanili
        // From the perspective of this problem these two sequences are equivalent

        int closeCount = -minDifference;
        int openCount = difference - minDifference;
        if (!openCount && !closeCount) { // if already a regular bracket sequence (ie 0 of both types of brackets in the simplified version of the sequence)
            alreadyRegular++;
        /*in the following conditions, we already know (as we are in the else section) that they are not both 0*/
        } else if (!openCount) { // if it only requires concatenation on left side (ie only has ')' brackets in the simplified version of the sequence)
            rightSeq[closeCount]++;
        } else if (!closeCount) { // if it only requires concatenation on right side (ie only has '(' brackets in the simplified version of the sequence)
            leftSeq[openCount]++;
        }
	}

	long long pairSum = alreadyRegular * 1ll * alreadyRegular;
	for (int i = 0; i < MAX_SEQ_COUNT; i++) { // takes slightly more time to run all the way to MAX but easier than calculating a maximum
        pairSum += leftSeq[i] * 1ll * rightSeq[i];
	}

	cout << pairSum << endl;
	return 0;
}


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

using namespace std;

const int MAX_STRINGS = 300000;

char brackets[MAX_STRINGS];
string sequence[MAX_STRINGS];

pair <int, int> sides[MAX_STRINGS];

int frequencyLeft[MAX_STRINGS];
int frequencyRight[MAX_STRINGS];

int main() {
	int n;
	scanf("%d\n", &n);
	//cin >> n;

	for (int i = 0; i < n; i++) {
		scanf("%s", &brackets);
		sequence[i] = string(brackets);
		//cin >> sequence[i];
	}

    int regularSequenceCount = 0;

    long long pairCount = 0;

	for (int i = 0; i < n; i++) {
        int openMore = 0;
        bool left = true, right = true;
        for (int j = 0; j < sequence[i].length(); j++) {
            openMore += ( sequence[i][j] == '(' ) ? 1 : -1;
            if (openMore < 0) {
                left = false;
                break;
            }
        }

        if (!openMore) {
            sides[i].first = sides[i].second = 0;
            regularSequenceCount++;
            continue;
        }
        if (left) {
            sides[i].first = openMore;
            sides[i].second = -1;
            frequencyLeft[openMore]++;
            pairCount += frequencyRight[openMore];
            continue;
        }

        sides[i].first = -1;

        int closeMore = 0;
        for (int j = sequence[i].length() - 1; j >= 0; j--) {
            closeMore += ( sequence[i][j] == ')' ) ? 1 : -1;
            if (closeMore < 0) {
                right = false;
                break;
            }
        }

        if (!right) {
            sides[i].second = -1;
        } else {
            sides[i].second = closeMore;
            frequencyRight[closeMore]++;
            pairCount += frequencyLeft[closeMore];
        }
	}

    pairCount += 1ll * regularSequenceCount * regularSequenceCount;

    cout << pairCount;
    return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

#define MAX_BRACKETS 300000
#define MAX_SEQ_COUNT 300000
int leftSeq[MAX_SEQ_COUNT];
int rightSeq[MAX_SEQ_COUNT];

int main() {
	int n;
	cin >> n;
	int alreadyRegular = 0;
	for (int seq = 0; seq < n; seq++) {
		string si;
		cin >> si;
		int len = si.length();
		int difference = 0;
		int minDifference = 0;
		for (int i = 0; i < len; i++) {
			if (si[i] == '(') {
				difference += 1;
			}
			else {
				difference -= 1;
				minDifference = min(minDifference, difference);
			}
		}

        int closeCount = -minDifference;
        int openCount = difference - minDifference;
        if (!openCount && !closeCount) {
            alreadyRegular++;
        } else if (!openCount) {
            rightSeq[closeCount]++;
        } else if (!closeCount) {
            leftSeq[openCount]++;
        }
	}

	long long pairSum = alreadyRegular*1ll*alreadyRegular;
	for (int i = 0; i < MAX_SEQ_COUNT; i++) {
        pairSum += leftSeq[i]*1ll*rightSeq[i];
	}

	cout << pairSum << endl;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <deque>
#include <bits/stdc++.h>
//#include "D:\C++\test_lib_projects\testlib.h"
using namespace std;
#define ll long long
#define pii pair<int,int>

bool debug=true;
/*
   Write In New Computer
    By XiaoGeNintendo
	     gwq2017
	Type:
*/

int n;
char c[300005];
map<int,int> l,r;
ll cc;
int main(int argc,char* argv[]){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%s",c);
		int sz=strlen(c);
		if(sz==1){
			if(c[0]=='('){
				l[1]++;
			}else{
				r[1]++;
			}
			continue;
		}

		if(c[0]==')' && c[sz-1]=='('){
			continue;
		}

		int cnt=0;
		bool fs=false;
		for(int j=0;j<sz;j++){
			if(cnt<0){
				fs=true;
			}
			if(c[j]=='('){
				cnt++;
			}else{
				cnt--;
			}
		}

		if(cnt==0 && !fs){
			cc++;
		}else{
			if(cnt>0){
				l[cnt]++;
			}else{
				r[-cnt]++;
			}
		}

	}

//	cout<<l[1]<<" "<<r[1]<<endl;

	ll ans=cc*cc;
	for(map<int,int>::iterator it=l.begin();it!=l.end();it++){
		ans+=1ll*l[it->first]*r[it->first];
	}

	cout<<ans;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <deque>
#include <bits/stdc++.h>
//#include "D:\C++\test_lib_projects\testlib.h"
using namespace std;
#define ll long long
#define pii pair<int,int>

bool debug=true;
/*
   Write In New Computer
    By XiaoGeNintendo
	     gwq2017
	Type:
*/

int n;
char tmp[300005];

map<int,int> mp;

int main(int argc,char* argv[]){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%s",tmp);
		int c=0;
		for(int j=0;j<strlen(tmp);j++){
			if(tmp[j]=='('){
				c++;
			}else{
				c--;
			}
		}

		mp[c]++;
	}

	ll ans=0;

	for(map<int,int>::iterator it=mp.begin();it!=mp.end();it++){
		if(it->first>0){
			break;
		}
		ans+=mp[it->first]*mp[0-it->first];
	}

	cout<<ans;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <deque>
#include <bits/stdc++.h>
//#include "D:\C++\test_lib_projects\testlib.h"
using namespace std;
#define ll long long
#define pii pair<int,int>

bool debug=true;
/*
   Write In New Computer
    By XiaoGeNintendo
	     gwq2017
	Type:
*/

ll n;
char c[300005];
map<ll,ll> l,r;
ll cc;
int main(int argc,char* argv[]){
	//freopen("out.txt","r",stdin);
	scanf("%lld",&n);
	for(int i=0;i<n;i++){
		scanf("%s",c);
		int sz=strlen(c);

		int cnt=0;
		bool fs=false;
		for(int j=0;j<sz;j++){
			if(cnt<0){
				fs=true;
			}
			if(c[j]=='('){
				cnt++;
			}else{
				cnt--;
			}
		}

		if(cnt<0){
			fs=true;
		}

		if(cnt==0 && !fs){
			cc++;
		}else{
			if(cnt==0){
				continue;
			}
			if(cnt>0){
				l[cnt]++;
			}else{
				r[-cnt]++;
			}
		}

	}

//	cout<<l[1]<<" "<<r[1]<<endl;

	ll ans=cc*cc;
	for(map<ll,ll>::iterator it=l.begin();it!=l.end();it++){
		ans+=l[it->first]*r[it->first];
	}

	cout<<ans;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <deque>
#include <bits/stdc++.h>
//#include "D:\C++\test_lib_projects\testlib.h"
using namespace std;
#define ll long long
#define pii pair<int,int>

bool debug=true;
/*
   Write In New Computer
    By XiaoGeNintendo
	     gwq2017
	Type:
*/

ll n,m,a,b;
int main(int argc,char* argv[]){
	cin>>n>>m>>a>>b;
	ll r=n%m;
	cout<<min(r*b,(m-r)*a);
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <deque>
#include <bits/stdc++.h>
//#include "D:\C++\test_lib_projects\testlib.h"
using namespace std;
#define ll long long
#define pii pair<int,int>

bool debug=true;
/*
   Write In New Computer
    By XiaoGeNintendo
	     gwq2017
	Type:
*/

ll n;
char c[300005];
map<ll,ll> l,r;
ll cc;
int main(int argc,char* argv[]){
	scanf("%lld",&n);
	for(int i=0;i<n;i++){
		scanf("%s",c);
		int sz=strlen(c);
		if(sz==1){
			if(c[0]=='('){
				l[1]++;
			}else{
				r[1]++;
			}
			continue;
		}

		if(c[0]==')' && c[sz-1]=='('){
			continue;
		}

		int cnt=0;
		bool fs=false;
		for(int j=0;j<sz;j++){
			if(cnt<0){
				fs=true;
			}
			if(c[j]=='('){
				cnt++;
			}else{
				cnt--;
			}
		}

		if(cnt<0){
			fs=true;
		}

		if(cnt==0 && !fs){
			cc++;
		}else{
			if(cnt==0){
				continue;
			}
			if(cnt>0){
				l[cnt]++;
			}else{
				r[-cnt]++;
			}
		}

	}

//	cout<<l[1]<<" "<<r[1]<<endl;

	ll ans=cc*cc;
	for(map<ll,ll>::iterator it=l.begin();it!=l.end();it++){
		ans+=l[it->first]*r[it->first];
	}

	cout<<ans;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <deque>
#include <bits/stdc++.h>
//#include "D:\C++\test_lib_projects\testlib.h"
using namespace std;
#define ll long long
#define pii pair<int,int>

bool debug=true;
/*
   Write In New Computer
    By XiaoGeNintendo
	     gwq2017
	Type:
*/

int n;
char c[300005];
map<int,int> l,r;
ll cc;
int main(int argc,char* argv[]){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%s",c);
		int sz=strlen(c);
		if(sz==1){
			if(c[0]=='('){
				l[1]++;
			}else{
				r[1]++;
			}
			continue;
		}

		if(c[0]==')' && c[sz-1]=='('){
			continue;
		}

		int cnt=0;
		bool fs=false;
		for(int j=0;j<sz;j++){
			if(cnt<0){
				fs=true;
			}
			if(c[j]=='('){
				cnt++;
			}else{
				cnt--;
			}
		}

		if(cnt==0 && !fs){
			cc++;
		}else{
			if(cnt>0){
				l[cnt]++;
			}else{
				r[-cnt]++;
			}
		}

	}

//	cout<<l[1]<<" "<<r[1]<<endl;

	ll ans=cc*cc;
	for(map<int,int>::iterator it=l.begin();it!=l.end();it++){
		ans+=l[it->first]*r[it->first];
	}

	cout<<ans;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <deque>
#include <bits/stdc++.h>
//#include "D:\C++\test_lib_projects\testlib.h"
using namespace std;
#define ll long long
#define pii pair<int,int>

bool debug=true;
/*
   Write In New Computer
    By XiaoGeNintendo
	     gwq2017
	Type:
*/

ll n;
char c[300005];
map<ll,ll> l,r;
ll cc;
int main(int argc,char* argv[]) {
	//freopen("out.txt","r",stdin);
	scanf("%lld",&n);
	for(int i=0; i<n; i++) {
		scanf("%s",c);
		int sz=strlen(c);

		int rr=0,lll=0;
		bool fe=false,fs=false;

		for (int j=0; j<sz; j++) {
			if (c[j]=='(') {
				rr++;
			} else {
				lll++;
				if (rr>0) rr--,lll--;
			}
		}

		if (rr) fe=true;
		if (lll) fs=true;

		if(fe&&fs){
			continue;
		}

		if(!fe && !fs){
			cc++;
		}

		if(fs){
			r[rr]++;
		}

		if(fe){
			l[lll]++;
		}
	}

//	cout<<l[1]<<" "<<r[1]<<endl;

	ll ans=cc*cc;
	for(map<ll,ll>::iterator it=l.begin(); it!=l.end(); it++) {
		ans+=l[it->first]*r[it->first];
	}

	cout<<ans;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <deque>
#include <bits/stdc++.h>
//#include "D:\C++\test_lib_projects\testlib.h"
using namespace std;
#define ll long long
#define pii pair<int,int>

bool debug=true;
/*
   Write In New Computer
    By XiaoGeNintendo
	     gwq2017
	Type:
*/

ll n;
char c[300005];
map<ll,ll> l,r;
ll cc;
int main(int argc,char* argv[]) {
	//freopen("out.txt","r",stdin);
	scanf("%lld",&n);
	for(int i=0; i<n; i++) {
		scanf("%s",c);
		int sz=strlen(c);

		int rr=0,lll=0;
		bool fe=false,fs=false;

		for (int j=0; j<sz; j++) {
			if (c[j]=='(') {
				rr++;
			} else {
				lll++;
				if (rr>0) rr--,lll--;
			}
		}

		if (rr) fe=true;
		if (lll) fs=true;

		if(fe&&fs){
			continue;
		}

		if(!fe && !fs){
			cc++;
		}

		if(fe){
			r[rr]++;
		}

		if(fs){
			l[lll]++;
		}
	}

//	cout<<l[1]<<" "<<r[1]<<endl;

	ll ans=cc*cc;
	for(map<ll,ll>::iterator it=l.begin(); it!=l.end(); it++) {
		ans+=l[it->first]*r[it->first];
	}

	cout<<ans;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <deque>
#include <bits/stdc++.h>
//#include "D:\C++\test_lib_projects\testlib.h"
using namespace std;
#define ll long long
#define pii pair<int,int>

bool debug=true;
/*
   Write In New Computer
    By XiaoGeNintendo
	     gwq2017
	Type:
*/

int n;
char c[300005];
map<int,int> l,r;
ll cc=0;
int main(int argc,char* argv[]){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%s",c);
		int sz=strlen(c);
		if(sz==1){
			if(c[0]=='('){
				l[1]++;
			}else{
				r[1]++;
			}
			continue;
		}

		if(c[0]==')' && c[sz-1]=='('){
			continue;
		}

		int cnt=0;
		for(int j=0;j<sz;j++){
			if(c[j]=='('){
				cnt++;
			}else{
				cnt--;
			}
		}

		if(cnt==0){
			cc++;
		}else{
			if(cnt>0){
				l[cnt]++;
			}else{
				r[-cnt]++;
			}
		}

	}

//	cout<<l[1]<<" "<<r[1]<<endl;

	ll ans=cc*cc;
	for(map<int,int>::iterator it=l.begin();it!=l.end();it++){
		ans+=l[it->first]*r[it->first];
	}

	cout<<ans;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <deque>
#include <bits/stdc++.h>
//#include "D:\C++\test_lib_projects\testlib.h"
using namespace std;
#define ll long long
#define pii pair<int,int>

bool debug=true;
/*
   Write In New Computer
    By XiaoGeNintendo
	     gwq2017
	Type:
*/

int n;
char c[300005];
map<int,int> l,r;
ll cc=0;
int main(int argc,char* argv[]){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%s",c);
		int sz=strlen(c);
		if(sz==1){
			if(c[0]=='('){
				l[1]++;
			}else{
				r[1]++;
			}
		}

		if(c[0]==')' && c[sz-1]=='('){
			continue;
		}

		int cnt=0;
		for(int j=0;j<sz;j++){
			if(c[j]=='('){
				cnt++;
			}else{
				cnt--;
			}
		}

		if(cnt==0){
			cc++;
		}else{
			if(cnt>0){
				l[cnt]++;
			}else{
				r[cnt]++;
			}
		}

	}

	ll ans=cc*cc;
	for(map<int,int>::iterator it=l.begin();it!=l.end();it++){
		ans+=l[it->first]*r[it->first];
	}

	cout<<ans;
	return 0;
}


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

#define DEBUG if(1)
#define MAXN 100
#define MAX INT_MAX
#define MAXLL INT_MAX
#define MAXU ULLONG_MAX
#define MIN -2000000
#define endl "\n"
#define INF 99999999
#define MOD 1000000007
#define s(n) scanf("%d", &n)
#define ss(a,b) scanf("%d %d",&a,&b)
#define pb push_back
#define mp make_pair
#define M_PI 3.14159265358979323846
#define sz(a) int(a.size())
#define lli long long int
#define rep(i,a,n) for (int i=a;i<n;i++)
#define ler(a,n,vec) for(int i=0;i<n;i++)s(a), vec.pb(a)
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<string, pair<int, char> > ps;
#define DEBUG if(1)
#define F first
#define S second
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int ddx[] = {1, 0};
int ddy[] = {1, 1};

int n;
vector<pair<string, ii>> vec;
map<lli, lli> qt;
int vis[300001];
int vis2[300001];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	for(int i=0;i<n;i++){
		string s;
		cin >> s;
		int a = 0, b = 0;
		for(int j=0;j<sz(s);j++){
			if(s[j] == '(') a++;
			else b++;
		}
		vis[i] = a - b;
		qt[vis[i]]++;
		vec.pb({s,{a,b}});
	}

	// lli ans = qt[0] + (check(qt[0]));
	lli ans = 0;
	for(int i=0;i<sz(vec);i++){
		if(vis[i] == 0){
			// continue;
			ans += qt[vis[i]];
			// qt[vis[i]]--;
		} else if(vis[i] < 0){
			// ans += qt[abs(vis[i])];
			// qt[vis[i]]--;
		} else {
			ans += qt[vis[i]*-1];
			// qt[vis[i]]--;
		}
	}

	cout << ans << endl;

	return 0;
}


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

#define DEBUG if(1)
#define MAXN 100
#define MAX INT_MAX
#define MAXLL INT_MAX
#define MAXU ULLONG_MAX
#define MIN -2000000
#define endl "\n"
#define INF 99999999
#define MOD 1000000007
#define s(n) scanf("%d", &n)
#define ss(a,b) scanf("%d %d",&a,&b)
#define pb push_back
#define mp make_pair
#define M_PI 3.14159265358979323846
#define sz(a) int(a.size())
#define lli long long int
#define rep(i,a,n) for (int i=a;i<n;i++)
#define ler(a,n,vec) for(int i=0;i<n;i++)s(a), vec.pb(a)
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<string, pair<int, char> > ps;
#define DEBUG if(1)
#define F first
#define S second
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int ddx[] = {1, 0};
int ddy[] = {1, 1};

int n;
vector<pair<string, ii>> vec;
map<lli, lli> qt;
int vis[300001];
int vis2[300001];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	for(int i=0;i<n;i++){
		string s;
		cin >> s;
		int a = 0, b = 0;
		for(int j=0;j<sz(s);j++){
			if(s[j] == '(') a++;
			else b++;
		}
		vis[i] = a - b;
		qt[vis[i]]++;
		vec.pb({s,{a,b}});
	}

	lli ans = 0;
	for(int i=0;i<sz(vec);i++){
		int a = vec[i].S.F, b = vec[i].S.S;
		if(vis[i] == 0 and vis2[vis[i]] == 0) ans += qt[vis[i]]*qt[vis[i]], vis2[vis[i]] = 1;
		else if(vis[i] < 0 and !vis2[abs(vis[i])] and !vis2[vis[i]]) ans += qt[abs(vis[i])], qt[vis[i]]--;
		else if(vis[i] > 0 and !vis2[vis[i]*-1] and !vis2[(vis[i])]) ans += qt[vis[i]*-1], qt[abs(vis[i])]--;
		// cout << vis[i] << " - " << qt[vis[i]] << endl;
	}

	cout << ans << endl;

	return 0;
}


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

#define DEBUG if(1)
#define MAXN 100
#define MAX INT_MAX
#define MAXLL INT_MAX
#define MAXU ULLONG_MAX
#define MIN -2000000
#define endl "\n"
#define INF 99999999
#define MOD 1000000007
#define s(n) scanf("%d", &n)
#define ss(a,b) scanf("%d %d",&a,&b)
#define pb push_back
#define mp make_pair
#define M_PI 3.14159265358979323846
#define sz(a) int(a.size())
#define lli long long int
#define rep(i,a,n) for (int i=a;i<n;i++)
#define ler(a,n,vec) for(int i=0;i<n;i++)s(a), vec.pb(a)
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<string, pair<int, char> > ps;
#define DEBUG if(1)
#define F first
#define S second
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int ddx[] = {1, 0};
int ddy[] = {1, 1};

int n;
vector<pair<string, ii>> vec;
map<lli, lli> qt;
int vis[300001];
int vis2[300001];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	for(int i=0;i<n;i++){
		string s;
		cin >> s;
		int a = 0, b = 0;
		bool at = false;
		for(int j=0;j<sz(s);j++){
			if(s[j] == '(') a++;
			else b++;
			if(a - b < 0) at = true;
		}
		vis[i] = a - b;
		qt[vis[i]]++;
		if(a - b >= 0 and at) vis2[i] = -1, qt[vis[i]]--;
		vec.pb({s,{a,b}});
	}

	lli ans = qt[0];
	for(int i=0;i<sz(vec);i++){
		// cout << vec[i].F << " - " << vis2[i] << endl;
		// cout << vis[i] << endl;
		if(vis2[i] == -1) continue;
		if(vis[i] == 0){
			// continue;
			ans += qt[vis[i]] - 1;
			// qt[vis[i]]--;
		} else if(vis[i] < 0){
			// ans += qt[abs(vis[i])];
			// qt[vis[i]]--;
		} else {
			ans += qt[vis[i]*-1];
			// qt[vis[i]]--;
		}
		// cout << vec[i].F << " - " << ans << endl;
	}

	cout << ans << endl;

	return 0;
}


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

#define DEBUG if(1)
#define MAXN 100
#define MAX INT_MAX
#define MAXLL INT_MAX
#define MAXU ULLONG_MAX
#define MIN -2000000
#define endl "\n"
#define INF 99999999
#define MOD 1000000007
#define s(n) scanf("%d", &n)
#define ss(a,b) scanf("%d %d",&a,&b)
#define pb push_back
#define mp make_pair
#define M_PI 3.14159265358979323846
#define sz(a) int(a.size())
#define lli long long int
#define rep(i,a,n) for (int i=a;i<n;i++)
#define ler(a,n,vec) for(int i=0;i<n;i++)s(a), vec.pb(a)
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<string, pair<int, char> > ps;
#define DEBUG if(1)
#define F first
#define S second
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int ddx[] = {1, 0};
int ddy[] = {1, 1};

int n;
vector<pair<string, ii>> vec;
map<lli, lli> qt;
int vis[300001];
int vis2[300001];

lli check(lli x){
	if(x == 2) return 1;
	else if(x == 1) return 0;
	lli a = 4;
	lli sum = 3;
	while(1){
		if(a == x+1) break;
		sum *= a;
		a++;
	}

	return sum/2;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	for(int i=0;i<n;i++){
		string s;
		cin >> s;
		int a = 0, b = 0;
		for(int j=0;j<sz(s);j++){
			if(s[j] == '(') a++;
			else b++;
		}
		vis[i] = a - b;
		qt[vis[i]]++;
		vec.pb({s,{a,b}});
	}

	// lli ans = qt[0] + (check(qt[0]));
	lli ans = 0;
	for(int i=0;i<sz(vec);i++){
		if(vis[i] == 0){
			// continue;
			ans += qt[vis[i]];
			// qt[vis[i]]--;
		} else if(vis[i] < 0){
			ans += qt[abs(vis[i])];
			// qt[vis[i]]--;
		} else {
			ans += qt[vis[i]*-1];
			// qt[vis[i]]--;
		}
	}

	cout << ans << endl;

	return 0;
}


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

#define DEBUG if(1)
#define MAXN 100
#define MAX INT_MAX
#define MAXLL INT_MAX
#define MAXU ULLONG_MAX
#define MIN -2000000
#define endl "\n"
#define INF 99999999
#define MOD 1000000007
#define s(n) scanf("%d", &n)
#define ss(a,b) scanf("%d %d",&a,&b)
#define pb push_back
#define mp make_pair
#define M_PI 3.14159265358979323846
#define sz(a) int(a.size())
#define lli long long int
#define rep(i,a,n) for (int i=a;i<n;i++)
#define ler(a,n,vec) for(int i=0;i<n;i++)s(a), vec.pb(a)
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<string, pair<int, char> > ps;
#define DEBUG if(1)
#define F first
#define S second
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int ddx[] = {1, 0};
int ddy[] = {1, 1};

int n;
vector<pair<string, ii>> vec;
map<lli, lli> qt;
int vis[300001];
int vis2[300001];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	for(int i=0;i<n;i++){
		string s;
		cin >> s;
		int a = 0, b = 0;
		bool at = false;
		bool at2 = false;

		for(int j=0;j<sz(s);j++){
			if(s[j] == '(') a++;
			else {
				if(a) a--;
				else b++;
			}
		}

		vis[i] = a - b;
		qt[vis[i]]++;
		if(a > 0 and b > 0) vis2[i] = -1, qt[vis[i]]--;

		vec.pb({s,{a,b}});
	}

	lli ans = qt[0];
	for(int i=0;i<sz(vec);i++){
		// cout << vec[i].F << " - " << vis2[i] << endl;
		// cout << vis[i] << endl;
		if(vis2[i] == -1) continue;
		if(vis[i] == 0){
			// continue;
			ans += qt[vis[i]] - 1;
			// qt[vis[i]]--;
		} else if(vis[i] < 0){
			// ans += qt[abs(vis[i])];
			// qt[vis[i]]--;
		} else {
			ans += qt[vis[i]*-1];
			// qt[vis[i]]--;
		}
		// cout << vec[i].F << " - " << ans << endl;
	}

	cout << ans << endl;

	return 0;
}


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

#define DEBUG if(1)
#define MAXN 100
#define MAX INT_MAX
#define MAXLL INT_MAX
#define MAXU ULLONG_MAX
#define MIN -2000000
#define endl "\n"
#define INF 99999999
#define MOD 1000000007
#define s(n) scanf("%d", &n)
#define ss(a,b) scanf("%d %d",&a,&b)
#define pb push_back
#define mp make_pair
#define M_PI 3.14159265358979323846
#define sz(a) int(a.size())
#define lli long long int
#define rep(i,a,n) for (int i=a;i<n;i++)
#define ler(a,n,vec) for(int i=0;i<n;i++)s(a), vec.pb(a)
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<string, pair<int, char> > ps;
#define DEBUG if(1)
#define F first
#define S second
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int ddx[] = {1, 0};
int ddy[] = {1, 1};

int n;
vector<pair<string, ii>> vec;
map<lli, lli> qt;
int vis[300001];
int vis2[300001];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	for(int i=0;i<n;i++){
		string s;
		cin >> s;
		int a = 0, b = 0;
		for(int j=0;j<sz(s);j++){
			if(s[j] == '(') a++;
			else b++;
		}
		vis[i] = a - b;
		qt[vis[i]]++;
		vec.pb({s,{a,b}});
	}

	lli ans = qt[0]*qt[0];
	for(int i=0;i<sz(vec);i++){
		if(vis[i] == 0){
			continue;
			ans += qt[vis[i]];
			qt[vis[i]]--;
		} else if(vis[i] < 0){
			ans += qt[abs(vis[i])];
			qt[vis[i]]--;
		} else {
			ans += qt[vis[i]*-1];
			qt[vis[i]]--;
		}
	}

	cout << ans << endl;

	return 0;
}


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

#define DEBUG if(1)
#define MAXN 100
#define MAX INT_MAX
#define MAXLL INT_MAX
#define MAXU ULLONG_MAX
#define MIN -2000000
#define endl "\n"
#define INF 99999999
#define MOD 1000000007
#define s(n) scanf("%d", &n)
#define ss(a,b) scanf("%d %d",&a,&b)
#define pb push_back
#define mp make_pair
#define M_PI 3.14159265358979323846
#define sz(a) int(a.size())
#define lli long long int
#define rep(i,a,n) for (int i=a;i<n;i++)
#define ler(a,n,vec) for(int i=0;i<n;i++)s(a), vec.pb(a)
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<string, pair<int, char> > ps;
#define DEBUG if(1)
#define F first
#define S second
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int ddx[] = {1, 0};
int ddy[] = {1, 1};

int n;
vector<pair<string, ii>> vec;
map<int, int> qt;
int vis[300001];
int vis2[300001];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	for(int i=0;i<n;i++){
		string s;
		cin >> s;
		int a = 0, b = 0;
		for(int j=0;j<sz(s);j++){
			if(s[j] == '(') a++;
			else b++;
		}
		vis[i] = a - b;
		qt[vis[i]]++;
		vec.pb({s,{a,b}});
	}

	lli ans = 0;
	for(int i=0;i<sz(vec);i++){
		int a = vec[i].S.F, b = vec[i].S.S;
		if(vis[i] == 0 and vis2[vis[i]] == 0) ans += qt[vis[i]]*qt[vis[i]], vis2[vis[i]] = 1;
		else if(vis[i] < 0 and !vis2[abs(vis[i])] and !vis2[vis[i]]) ans += qt[abs(vis[i])], vis2[abs(vis[i])] = 1;
		else if(vis[i] > 0 and !vis2[vis[i]*-1] and !vis2[(vis[i])]) ans += qt[vis[i]*-1], vis2[vis[i]*-1] = 1;
		// cout << vis[i] << " - " << qt[vis[i]] << endl;
	}

	cout << ans << endl;

	return 0;
}


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

#define DEBUG if(1)
#define MAXN 100
#define MAX INT_MAX
#define MAXLL INT_MAX
#define MAXU ULLONG_MAX
#define MIN -2000000
#define endl "\n"
#define INF 99999999
#define MOD 1000000007
#define s(n) scanf("%d", &n)
#define ss(a,b) scanf("%d %d",&a,&b)
#define pb push_back
#define mp make_pair
#define M_PI 3.14159265358979323846
#define sz(a) int(a.size())
#define lli long long int
#define rep(i,a,n) for (int i=a;i<n;i++)
#define ler(a,n,vec) for(int i=0;i<n;i++)s(a), vec.pb(a)
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<string, pair<int, char> > ps;
#define DEBUG if(1)
#define F first
#define S second
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int ddx[] = {1, 0};
int ddy[] = {1, 1};

int n;
vector<pair<string, ii>> vec;
map<lli, lli> qt;
int vis[300001];
int vis2[300001];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	for(int i=0;i<n;i++){
		string s;
		cin >> s;
		int a = 0, b = 0;
		for(int j=0;j<sz(s);j++){
			if(s[j] == '(') a++;
			else b++;
		}
		vis[i] = a - b;
		qt[vis[i]]++;
		vec.pb({s,{a,b}});
	}

	lli ans = qt[0];
	for(int i=0;i<sz(vec);i++){
		if(vis[i] == 0){
			// continue;
			ans += qt[vis[i]] - 1;
			// qt[vis[i]]--;
		} else if(vis[i] < 0){
			// ans += qt[abs(vis[i])];
			// qt[vis[i]]--;
		} else {
			ans += qt[vis[i]*-1];
			// qt[vis[i]]--;
		}
	}

	cout << ans << endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+100;
string str;
long long int cnt[maxn];
bool check()
{
    stack<char>stk;
    for(int i=0;i<str.size();++i)
    {
        if(str[i]=='(')
        {
            stk.push(str[i]);
        }
        else
        {
            if((!stk.empty())&&stk.top()=='(')
            {
                stk.pop();
            }
            else
                stk.push(str[i]);
        }
    }
    bool flag=true;
    int pre=')';
    while(!stk.empty())
    {
        if(flag)
        {
            flag=false;
            pre=stk.top();
        }
        else
        {
            if(stk.top()==')'&&pre=='(')
                return false;
            pre=stk.top();

        }
        stk.pop();
    }
    return true;
}
int main()
{
    int n;
    cin>>n;
    map<int,int>mp;
    long long int ans=0;
    long long int ac=0;
    for(int i=0;i<n;++i)
    {
        cin>>str;
        int temp=0;
        for(int j=0;j<str.size();++j)
        {
            if(str[j]=='(')
                ++temp;
            else
                --temp;
        }
        if(!check())
            continue;
        if(temp==0)
        {
            ++ac;
        }
        else if(temp>0)
        {
            cnt[temp]++;
        }
        else
        {
            mp[temp]++;
        }
    }
    for(int i=1;i<maxn;++i)
    {
        ans+=(cnt[i]*mp[-i]);
    }
    ans+=ac*ac;
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+100;
string str[maxn];
long long int cnt[maxn];
int main()
{
    int n;
    cin>>n;
    map<int,int>mp;
    for(int i=0;i<n;++i)
        cin>>str[i];
    long long int ans=0;
    int ac=0;
    for(int i=0;i<n;++i)
    {
        int temp=0;
        for(int j=0;j<str[i].size();++j)
        {
            if(str[i][j]=='(')
                ++temp;
            else
                --temp;
        }
        if(temp==0)
        {
            ++ac;
        }
        else if(temp>0)
        {
            cnt[temp]++;
        }
        else
        {
            mp[temp]++;
        }
    }
    for(int i=1;i<maxn;++i)
    {
        ans+=(cnt[i]*mp[-i]);
    }
    ans+=ac*ac;
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+100;
string str;
long long int cnt[maxn];
bool check()
{
    stack<char>stk;
    for(int i=0;i<str.size();++i)
    {
        if(str[i]=='(')
            stk.push(str[i]);
        else
        {
            if(stk.empty())
            {
                stk.push(str[i]);
            }
            else if(stk.top()=='(')
                stk.pop();
        }
    }
    if(stk.size()>1&&stk.top()=='(')
        return false;
    else
        return true;
}
int main()
{
    int n;
    cin>>n;
    map<int,int>mp;
    long long int ans=0;
    long long int ac=0;
    for(int i=0;i<n;++i)
    {
        cin>>str;
        int temp=0;
        for(int j=0;j<str.size();++j)
        {
            if(str[j]=='(')
                ++temp;
            else
                --temp;
        }
        if(!check())
            continue;
        if(temp==0)
        {
            ++ac;
        }
        else if(temp>0)
        {
            cnt[temp]++;
        }
        else
        {
            mp[temp]++;
        }
    }
    for(int i=1;i<maxn;++i)
    {
        ans+=(cnt[i]*mp[-i]);
    }
    ans+=ac*ac;
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+100;
string str;
long long int cnt[maxn];
bool check()
{
    stack<char>stk;
    for(int i=0;i<str.size();++i)
    {
        if(str[i]=='(')
        {
            if((!stk.empty())&&stk.top()==')')
                return false;
            stk.push(str[i]);
        }
        else
        {
            if(!stk.empty()&&stk.top()=='(')
            {
                stk.pop();
            }
            else
                stk.push(str[i]);
        }
    }
    return true;
}
int main()
{
    int n;
    cin>>n;
    map<int,int>mp;
    long long int ans=0;
    long long int ac=0;
    for(int i=0;i<n;++i)
    {
        cin>>str;
        int temp=0;
        for(int j=0;j<str.size();++j)
        {
            if(str[j]=='(')
                ++temp;
            else
                --temp;
        }
        if(!check())
            continue;
        if(temp==0)
        {
            ++ac;
        }
        else if(temp>0)
        {
            cnt[temp]++;
        }
        else
        {
            mp[temp]++;
        }
    }
    for(int i=1;i<maxn;++i)
    {
        ans+=(cnt[i]*mp[-i]);
    }
    ans+=ac*ac;
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+100;
string str;
long long int cnt[maxn];
bool check()
{
    stack<char>stk;
    for(int i=0;i<str.size();++i)
    {
        if(str[i]=='(')
        {
            if((!stk.empty())&&stk.top()==')')
                return false;
            stk.push(str[i]);
        }
        else
        {
            if((!stk.empty())&&stk.top()=='(')
            {
                stk.pop();
            }
            else
                stk.push(str[i]);
        }
    }
    return true;
}
int main()
{
    int n;
    cin>>n;
    map<int,int>mp;
    long long int ans=0;
    long long int ac=0;
    for(int i=0;i<n;++i)
    {
        cin>>str;
        int temp=0;
        for(int j=0;j<str.size();++j)
        {
            if(str[j]=='(')
                ++temp;
            else
                --temp;
        }
        if(!check())
            continue;
        if(temp==0)
        {
            ++ac;
        }
        else if(temp>0)
        {
            cnt[temp]++;
        }
        else
        {
            mp[temp]++;
        }
    }
    for(int i=1;i<maxn;++i)
    {
        ans+=(cnt[i]*mp[-i]);
    }
    ans+=ac*ac;
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+100;
string str;
long long int cnt[maxn];
bool check()
{
    stack<char>stk;
    for(int i=0;i<str.size();++i)
    {
        if(str[i]=='(')
        {
            if((!stk.empty())&&stk.top()==')')
                return false;
            stk.push(str[i]);
        }
        else
        {
            if(stk.empty())
            {
                stk.push(str[i]);
            }
            else if(stk.top()=='(')
                stk.pop();
        }
    }
    return true;
}
int main()
{
    int n;
    cin>>n;
    map<int,int>mp;
    long long int ans=0;
    long long int ac=0;
    for(int i=0;i<n;++i)
    {
        cin>>str;
        int temp=0;
        for(int j=0;j<str.size();++j)
        {
            if(str[j]=='(')
                ++temp;
            else
                --temp;
        }
        if(!check())
            continue;
        if(temp==0)
        {
            ++ac;
        }
        else if(temp>0)
        {
            cnt[temp]++;
        }
        else
        {
            mp[temp]++;
        }
    }
    for(int i=1;i<maxn;++i)
    {
        ans+=(cnt[i]*mp[-i]);
    }
    ans+=ac*ac;
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+100;
string str;
long long int cnt[maxn];
bool check()
{
    stack<char>stk;
    for(int i=0;i<str.size();++i)
    {
        if(str[i]=='(')
        {
            if(stk.top()==')')
                return false;
            stk.push(str[i]);
        }
        else
        {
            if(stk.empty())
            {
                stk.push(str[i]);
            }
            else if(stk.top()=='(')
                stk.pop();
        }
    }
    return true;
}
int main()
{
    int n;
    cin>>n;
    map<int,int>mp;
    long long int ans=0;
    long long int ac=0;
    for(int i=0;i<n;++i)
    {
        cin>>str;
        int temp=0;
        for(int j=0;j<str.size();++j)
        {
            if(str[j]=='(')
                ++temp;
            else
                --temp;
        }
        if(!check())
            continue;
        if(temp==0)
        {
            ++ac;
        }
        else if(temp>0)
        {
            cnt[temp]++;
        }
        else
        {
            mp[temp]++;
        }
    }
    for(int i=1;i<maxn;++i)
    {
        ans+=(cnt[i]*mp[-i]);
    }
    ans+=ac*ac;
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+100;
string str[maxn];
long long int cnt[maxn];
int main()
{
    int n;
    cin>>n;
    map<int,int>mp;
    for(int i=0;i<n;++i)
        cin>>str[i];
    long long int ans=0;
    long long int ac=0;
    for(int i=0;i<n;++i)
    {
        int temp=0;
        for(int j=0;j<str[i].size();++j)
        {
            if(str[i][j]=='(')
                ++temp;
            else
                --temp;
        }
        if(temp==0)
        {
            ++ac;
        }
        else if(temp>0)
        {
            cnt[temp]++;
        }
        else
        {
            mp[temp]++;
        }
    }
    for(int i=1;i<maxn;++i)
    {
        ans+=(cnt[i]*mp[-i]);
    }
    ans+=ac*ac;
    cout<<ans<<endl;
    return 0;
}


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

#define MOD 1000000007
#define N 2000100

#define scd(x) scanf("%d",&x);
#define prd(x) prllf("%d\n",x);
#define scl(x) scanf("%lld",&x);
#define prl(x) prllf("%lld",x);
#define forall(i,j) memset(i,j,sizeof(i));

#define FOR(i,k,e) for (ll i=e ; i<k ; i++)
#define RFOR(i,k,e) for (ll i=e ; i>=k ; i--)

typedef vector<ll> vi;
typedef vector<ll> vl;
typedef pair<ll,ll> pii;
typedef pair<ll,ll> pll;
typedef vector< pii > vpi;
typedef vector< pll > vpl;

// ll tree[4*N];
// ll lazy[4*N];

// void update(ll i, ll j , ll si , ll sj , ll index){
//  if(lazy[index]!=0){
//    if(lazy[index]%2==1){
//      tree[index] = (sj-si+1) - tree[index];
//    }
//    if(si!=sj){
//      lazy[2*index + 1] = lazy[2*index + 1] +  lazy[index];
//      lazy[2*index + 2] = lazy[2*index + 2] +  lazy[index];
//    }
//    lazy[index] = 0;
//  }
//  if(j<si || i > sj){
//   return ;
//    }
//  if(si>=i && sj<=j){
//    ll l = sj-si+1;
//    ll temp = tree[index];
//    tree[index] = l - tree[index];
//    if(si!=sj){
//      lazy[2*index + 1] = lazy[2*index+1] + 1;
//      lazy[2*index + 2] = lazy[2*index+2] + 1;

//    }
//    return;

//  }

//   update(i, j, si , (si + sj)/2 , 2*index + 1);
//   update( i, j, (si + sj)/2 +1 , sj , 2*index + 2);
//   tree[index] = tree[2*index+1] + tree[2*index+2];

// }
// ll query(ll i, ll j , ll si , ll sj , ll index){
//  if(lazy[index]!=0){
//    if(lazy[index]%2==1){
//      tree[index] = (sj-si+1) - tree[index];
//    }
//    if(si!=sj){
//      lazy[2*index + 1] = lazy[2*index + 1] +  lazy[index];
//      lazy[2*index + 2] = lazy[2*index + 2] +  lazy[index];
//    }
//    lazy[index] = 0;
//  }
//  if(j<si || i > sj){
//   return 0;
//    }
//  if(si>=i && sj<=j){
//    return tree[index];
//  }

//  return  query(i, j, si , (si + sj)/2 , 2*index + 1)
//      + query( i,  j, (si + sj)/2 +1 , sj , 2*index + 2);

// }
// ll make_tree(ll i,ll j,ll r){
//  if(i==j){
//    tree[r] = euler[i];
//    return tree[r];
//  }
//  tree[r] = make_tree(i,(i+j)/2,2*r+1) + make_tree(((i+j)/2)+1,j,2*r+2);
//  return tree[r];
// }
// void dfs(ll r){
//  vis[r] = 1;
//  FOR(i,adj[r].size(),0){
//    if(vis[adj[r][i]] == 0){
//      dfs(adj[r][i]);
//    }
//  }
// }{}
bool isOpen(char c)
{
    if(c == '(' || c == '{' || c == '[')
        return true;
    return false;
}

bool isBalanced(char popped, char now)
{
    if(popped == '(' && now ==')')
        return true;
    if(popped == '[' && now ==']')
        return true;
    if(popped == '{' && now =='}')
        return true;
    return false;
}
ll ch(string str){
        stack<char> s;

        ll no = 0;
        for(ll i = 0; i < str.length(); i++)
        {
            char now = str[i];
            if(isOpen(now))
                s.push(now);
            else
            {
                char popped;
                if(s.size() > 0)
                {
                    popped = s.top();
                    s.pop();
                }
                else
                {
                    no = 1;
                    break;
                }
                if(isBalanced(popped, now))
                    continue;
                else
                {
                    no = 1;
                    break;
                }
            }
        }
        if(s.size() != 0)
           { no = 1;}
        if(no)
            {
              return 0;
            }
        else
        {
            return 1;
        }

      }

string ch2(string s){
  stack<char>st;
  FOR(i,s.length(),0){
    if(st.size()>0){
      if(s[i]==')'&&st.top()=='('){
        st.pop();
      }
      else{
        st.push(s[i]);
      }
    }
    else{
      st.push(s[i]);
    }
  }
  // cout << s.size() << " ";
              string temp;
              while(!st.empty()){
                temp += st.top();
                st.pop();

              }
              FOR(i,temp.length(),0){
                if(temp[i]==')'){temp[i]='(';}
                else{temp[i]=')';}
              }

              return temp;
}
int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  ll n;
  cin >> n;
  vector<string>v;
  FOR(i,n,0){
    string s;
    cin >> s;
    v.push_back(s);
  }
  sort(v.begin(),v.end());
  ll c= 0;
  ll ans=0;
  map<string,ll>mp;
  FOR(i,n,0){

    if(ch(v[i])){
      c++;
    }
    else{
      string res = ch2(v[i]);
      // cout << res << " ";
      mp[res]++;
    }
  }
  FOR(i,n,0){
    if(mp[v[i]]){
      string res = ch2(v[i]);
      if(res[0]=='(')
      {ans += mp[v[i]];}
    }
  }

  ans += c*c ;
  cout << ans;
  return 0;
}


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

#define MOD 1000000007
#define N 2000100

#define scd(x) scanf("%d",&x);
#define prd(x) prllf("%d\n",x);
#define scl(x) scanf("%lld",&x);
#define prl(x) prllf("%lld",x);
#define forall(i,j) memset(i,j,sizeof(i));

#define FOR(i,k,e) for (ll i=e ; i<k ; i++)
#define RFOR(i,k,e) for (ll i=e ; i>=k ; i--)

typedef vector<ll> vi;
typedef vector<ll> vl;
typedef pair<ll,ll> pii;
typedef pair<ll,ll> pll;
typedef vector< pii > vpi;
typedef vector< pll > vpl;

// ll tree[4*N];
// ll lazy[4*N];

// void update(ll i, ll j , ll si , ll sj , ll index){
//  if(lazy[index]!=0){
//    if(lazy[index]%2==1){
//      tree[index] = (sj-si+1) - tree[index];
//    }
//    if(si!=sj){
//      lazy[2*index + 1] = lazy[2*index + 1] +  lazy[index];
//      lazy[2*index + 2] = lazy[2*index + 2] +  lazy[index];
//    }
//    lazy[index] = 0;
//  }
//  if(j<si || i > sj){
//   return ;
//    }
//  if(si>=i && sj<=j){
//    ll l = sj-si+1;
//    ll temp = tree[index];
//    tree[index] = l - tree[index];
//    if(si!=sj){
//      lazy[2*index + 1] = lazy[2*index+1] + 1;
//      lazy[2*index + 2] = lazy[2*index+2] + 1;

//    }
//    return;

//  }

//   update(i, j, si , (si + sj)/2 , 2*index + 1);
//   update( i, j, (si + sj)/2 +1 , sj , 2*index + 2);
//   tree[index] = tree[2*index+1] + tree[2*index+2];

// }
// ll query(ll i, ll j , ll si , ll sj , ll index){
//  if(lazy[index]!=0){
//    if(lazy[index]%2==1){
//      tree[index] = (sj-si+1) - tree[index];
//    }
//    if(si!=sj){
//      lazy[2*index + 1] = lazy[2*index + 1] +  lazy[index];
//      lazy[2*index + 2] = lazy[2*index + 2] +  lazy[index];
//    }
//    lazy[index] = 0;
//  }
//  if(j<si || i > sj){
//   return 0;
//    }
//  if(si>=i && sj<=j){
//    return tree[index];
//  }

//  return  query(i, j, si , (si + sj)/2 , 2*index + 1)
//      + query( i,  j, (si + sj)/2 +1 , sj , 2*index + 2);

// }
// ll make_tree(ll i,ll j,ll r){
//  if(i==j){
//    tree[r] = euler[i];
//    return tree[r];
//  }
//  tree[r] = make_tree(i,(i+j)/2,2*r+1) + make_tree(((i+j)/2)+1,j,2*r+2);
//  return tree[r];
// }
// void dfs(ll r){
//  vis[r] = 1;
//  FOR(i,adj[r].size(),0){
//    if(vis[adj[r][i]] == 0){
//      dfs(adj[r][i]);
//    }
//  }
// }{}
bool isOpen(char c)
{
    if(c == '(' || c == '{' || c == '[')
        return true;
    return false;
}

bool isBalanced(char popped, char now)
{
    if(popped == '(' && now ==')')
        return true;
    if(popped == '[' && now ==']')
        return true;
    if(popped == '{' && now =='}')
        return true;
    return false;
}
ll ch(string str){
        stack<char> s;

        ll no = 0;
        for(ll i = 0; i < str.length(); i++)
        {
            char now = str[i];
            if(isOpen(now))
                s.push(now);
            else
            {
                char popped;
                if(s.size() > 0)
                {
                    popped = s.top();
                    s.pop();
                }
                else
                {
                    no = 1;
                    break;
                }
                if(isBalanced(popped, now))
                    continue;
                else
                {
                    no = 1;
                    break;
                }
            }
        }
        if(s.size() != 0)
           { no = 1;}
        if(no)
            {
              return 0;
            }
        else
        {
            return 1;
        }

      }

string ch2(string s){
  stack<char>st;
  FOR(i,s.length(),0){
    if(st.size()>0){
      if(s[i]==')'&&st.top()=='('){
        st.pop();
      }
      else{
        st.push(s[i]);
      }
    }
    else{
      st.push(s[i]);
    }
  }
  // cout << s.size() << " ";
              string temp;
              while(!st.empty()){
                temp += st.top();
                st.pop();

              }
              FOR(i,temp.length(),0){
                if(temp[i]==')'){temp[i]='(';}
                else{temp[i]=')';}
              }

              return temp;
}
int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  ll n;
  cin >> n;
  vector<string>v;
  FOR(i,n,0){
    string s;
    cin >> s;
    v.push_back(s);
  }
  ll c= 0;
  ll ans=0;
  map<string,ll>mp;
  FOR(i,n,0){

    if(ch(v[i])){
      c++;
    }
    else{
      string res = ch2(v[i]);
      if(mp[v[i]]){
        ans++;
        mp[res] = 1;
      }
      else{
        mp[res] = 1;
      }
    }
  }
  if(c==1){
    ans++;
    cout << ans;return 0;
  }

  ans += c*c ;
  cout << ans;
  return 0;
}


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

#define MOD 1000000007
#define N 2000100

#define scd(x) scanf("%d",&x);
#define prd(x) prllf("%d\n",x);
#define scl(x) scanf("%lld",&x);
#define prl(x) prllf("%lld",x);
#define forall(i,j) memset(i,j,sizeof(i));

#define FOR(i,k,e) for (ll i=e ; i<k ; i++)
#define RFOR(i,k,e) for (ll i=e ; i>=k ; i--)

typedef vector<ll> vi;
typedef vector<ll> vl;
typedef pair<ll,ll> pii;
typedef pair<ll,ll> pll;
typedef vector< pii > vpi;
typedef vector< pll > vpl;

// ll tree[4*N];
// ll lazy[4*N];

// void update(ll i, ll j , ll si , ll sj , ll index){
//  if(lazy[index]!=0){
//    if(lazy[index]%2==1){
//      tree[index] = (sj-si+1) - tree[index];
//    }
//    if(si!=sj){
//      lazy[2*index + 1] = lazy[2*index + 1] +  lazy[index];
//      lazy[2*index + 2] = lazy[2*index + 2] +  lazy[index];
//    }
//    lazy[index] = 0;
//  }
//  if(j<si || i > sj){
//   return ;
//    }
//  if(si>=i && sj<=j){
//    ll l = sj-si+1;
//    ll temp = tree[index];
//    tree[index] = l - tree[index];
//    if(si!=sj){
//      lazy[2*index + 1] = lazy[2*index+1] + 1;
//      lazy[2*index + 2] = lazy[2*index+2] + 1;

//    }
//    return;

//  }

//   update(i, j, si , (si + sj)/2 , 2*index + 1);
//   update( i, j, (si + sj)/2 +1 , sj , 2*index + 2);
//   tree[index] = tree[2*index+1] + tree[2*index+2];

// }
// ll query(ll i, ll j , ll si , ll sj , ll index){
//  if(lazy[index]!=0){
//    if(lazy[index]%2==1){
//      tree[index] = (sj-si+1) - tree[index];
//    }
//    if(si!=sj){
//      lazy[2*index + 1] = lazy[2*index + 1] +  lazy[index];
//      lazy[2*index + 2] = lazy[2*index + 2] +  lazy[index];
//    }
//    lazy[index] = 0;
//  }
//  if(j<si || i > sj){
//   return 0;
//    }
//  if(si>=i && sj<=j){
//    return tree[index];
//  }

//  return  query(i, j, si , (si + sj)/2 , 2*index + 1)
//      + query( i,  j, (si + sj)/2 +1 , sj , 2*index + 2);

// }
// ll make_tree(ll i,ll j,ll r){
//  if(i==j){
//    tree[r] = euler[i];
//    return tree[r];
//  }
//  tree[r] = make_tree(i,(i+j)/2,2*r+1) + make_tree(((i+j)/2)+1,j,2*r+2);
//  return tree[r];
// }
// void dfs(ll r){
//  vis[r] = 1;
//  FOR(i,adj[r].size(),0){
//    if(vis[adj[r][i]] == 0){
//      dfs(adj[r][i]);
//    }
//  }
// }{}
bool isOpen(char c)
{
    if(c == '(' || c == '{' || c == '[')
        return true;
    return false;
}

bool isBalanced(char popped, char now)
{
    if(popped == '(' && now ==')')
        return true;
    if(popped == '[' && now ==']')
        return true;
    if(popped == '{' && now =='}')
        return true;
    return false;
}
ll ch(string str){
        stack<char> s;

        ll no = 0;
        for(ll i = 0; i < str.length(); i++)
        {
            char now = str[i];
            if(isOpen(now))
                s.push(now);
            else
            {
                char popped;
                if(s.size() > 0)
                {
                    popped = s.top();
                    s.pop();
                }
                else
                {
                    no = 1;
                    break;
                }
                if(isBalanced(popped, now))
                    continue;
                else
                {
                    no = 1;
                    break;
                }
            }
        }
        if(s.size() != 0)
           { no = 1;}
        if(no)
            {
              return 0;
            }
        else
        {
            return 1;
        }

      }

string ch2(string s){
  stack<char>st;
  FOR(i,s.length(),0){
    if(st.size()>0){
      if(s[i]==')'&&st.top()=='('){
        st.pop();
      }
      else{
        st.push(s[i]);
      }
    }
    else{
      st.push(s[i]);
    }
  }
  // cout << s.size() << " ";
              string temp;
              while(!st.empty()){
                temp += st.top();
                st.pop();

              }
              FOR(i,temp.length(),0){
                if(temp[i]==')'){temp[i]='(';}
                else{temp[i]=')';}
              }

              return temp;
}
int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  ll n;
  cin >> n;
  vector<string>v;
  FOR(i,n,0){
    string s;
    cin >> s;
    v.push_back(s);
  }
  ll c= 0;
  ll ans=0;
  map<string,ll>mp;
  FOR(i,n,0){

    if(ch(v[i])){
      c++;
    }
    else{
      string res = ch2(v[i]);
      mp[v[i]] = 1;
      if(mp[res]){
        ans++;
      }
    }
  }
  ans += c*c ;
  cout << ans;
  return 0;
}