#include <bits/stdc++.h>   using namespace std;   pair<int, int> cnt(string s) {     int bal = 0, minBal = 0;     for (char c : s) {       if (c ==  ( )         bal++;       else         bal--;       minBal = min(minBal, bal);     }     return {bal, minBal};   }   int k[400400];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     vector<int> bal(n), minBal(n);     for (int i = 0; i < n; i++) {       string s;       cin >> s;       auto p = cnt(s);       bal[i] = p.first;       minBal[i] = p.second;       if (bal[i] >= 0 && minBal[i] >= 0) k[bal[i]]++;     }     long long ans = 0;     for (int i = 0; i < n; i++) {       if (bal[i] > 0) continue;       if (minBal[i] - bal[i] >= 0) ans += (long long)k[-bal[i]];     }     cout << ans;     return 0;   }   