#include <bits/stdc++.h>   using namespace std;   int test() {     long long n;     cin >> n;     long long cL = 0, cR = 0;     long long si = 3 * 100001;     long long *right = new long long[si], *left = new long long[si];     for (long long i = 0; i < si; i++) {       right[i] = 0;       left[i] = 0;     }     long long prop = 0, l = 0, r = 0;     string temp;     for (long long i = 0; i < n; i++) {       cin >> temp;       long long tempS = temp.size();       for (long long i = 0; i < tempS; i++) {         if (temp[i] ==  ( ) {           cL++;           l++;         } else {           cR++;           if (l != 0)             l--;           else             r++;         }       }       if (r != 0 && l != 0) {       } else if (cR == cL)         prop++;       else if (cR > cL)         right[cR - cL]++;       else         left[cL - cR]++;       l = 0;       r = 0;       cL = 0;       cR = 0;     }     long long S = 0;     for (long long i = 0; i < si; i++) {       if (right[i] != 0 && left[i] != 0) {         S += right[i] * left[i];       }     }     S += prop * prop;     cout << S;     return 0;   }   int hacker() { return 0; }   int main() {     while (true) {       return test();       cout <<   n n-- ;       hacker();       cout <<   n n n----------------------------- n n n ;     }     return 0;   }   