func_code_string: #include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse4 )   using namespace std;   const int MOD = 1e9 + 7;   const int MX = 2e5 + 5;   const long long INF = 1e18;   const long double PI = acos((long double)-1);   const long double EPS = 1e-6;   const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};   const char nl =   n ;   template <typename T>   inline T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   template <typename T>   inline T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   template <class T>   void ckmin(T& a, T b) {     a = min(a, b);   }   template <class T>   void ckmax(T& a, T b) {     a = max(a, b);   }   int pct(int x) { return __builtin_popcount(x); }   int pct(long long x) { return __builtin_popcountll(x); }   void DBG() { cerr <<  ]  << endl; }   template <class H, class... T>   void DBG(H h, T... t) {     cerr << h;     if (sizeof...(t)) cerr <<  ,  ;     DBG(t...);   }   void setIn(string s) { freopen(s.c_str(),  r , stdin); }   void setOut(string s) { freopen(s.c_str(),  w , stdout); }   void unsyncIO() {     ios_base::sync_with_stdio(0);     cin.tie(0);   }   void setIO(string s =   ) {     unsyncIO();     if ((int)s.size()) {       setIn(s +  .in ), setOut(s +  .out );     }   }   long long pow(long long b, long long e, long long m = 0LL,                 long long ans = 1LL) {     while (e) {       if (e & 1LL) {         ans *= b;         if (m) ans %= m;       }       b *= b, e >>= 1LL;       if (m) b %= m;     }     return ans;   }   void solve(int tcn) {     int n, m;     cin >> n >> m;     vector<vector<int> > l(n + 1, vector<int>(m + 1)),         r(n + 1, vector<int>(m + 1));     for (int i = (0); i < (n); ++i) {       int k;       cin >> k;       for (int j = (0); j < (k); ++j) {         int lll, rrr;         cin >> lll >> rrr;         for (int x = (lll); x < (rrr + 1); ++x) {           l[i + 1][x] = lll;           r[i + 1][x] = rrr;         }       }     }     vector<vector<long long> > dp(m + 2, vector<long long>(m + 2, 0LL));     for (int lll = m; lll >= 1; --lll) {       for (int rrr = (lll); rrr < (m + 1); ++rrr) {         for (int x = (lll); x < (rrr + 1); ++x) {           long long cnt = 0LL;           for (int k = (1); k < (n + 1); ++k)             if (l[k][x] >= lll && r[k][x] <= rrr) ++cnt;           ckmax(dp[lll][rrr], dp[lll][x - 1] + cnt * cnt + dp[x + 1][rrr]);         }       }     }     cout << dp[1][m] << nl;   }   int main() {     setIO();     int t = 1;     for (int i = 1; i <= t; ++i) {       solve(i);     }     return 0;   }   