func_code_string: #include <bits/stdc++.h>   struct Seg {     int l;     int r;     int y;   };   struct Event {     int x;     enum { BEG, END } type;     Seg seg;     static Event beginOf(Seg seg) { return Event{seg.l, BEG, seg}; }     static Event endOf(Seg seg) { return Event{seg.r, END, seg}; }     friend bool operator<(const Event& a, const Event& b) {       return std::tie(a.x, a.type, a.seg.y) < std::tie(b.x, b.type, b.seg.y);     }   };   int main() {     int sx, sy;     std::cin >> sy >> sx;     std::vector<Event> events;     events.reserve(sy * sx);     for (int y = 0; y < sy; y++) {       int intervals;       std::cin >> intervals;       for (int i = 0; i < intervals; i++) {         int l, r;         std::cin >> l >> r;         Seg seg{l - 1, r, y};         events.push_back(Event::beginOf(seg));         events.push_back(Event::endOf(seg));       }     }     std::sort(events.begin(), events.end());     std::vector<std::vector<int>> dp(sx + 1, std::vector<int>(sx + 1, 0));     for (int len = 1; len <= sx; len++) {       for (int l = 0, r = len; r <= sx; l++, r++) {         int currHeight = 0;         auto currEv = events.begin();         for (int x = l; x < r; x++) {           for (; currEv != events.end() && currEv->x <= x; ++currEv) {             if (l <= currEv->seg.l && currEv->seg.r <= r) {               if (currEv->type == Event::BEG)                 currHeight++;               else                 currHeight--;             }           }           dp[l][r] = std::max(dp[l][r],                               dp[l][x] + dp[x + 1][r] + currHeight * currHeight);         }       }     }     std::cout << dp[0][sx] << std::endl;   }   