func_code_string: #include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, m, x;     cin >> n >> m;     vector<long long> vPref(n), vSuf(n), vTot(n), vCen(n);     for (int i(0), ThkMk(n); i < ThkMk; ++i) {       cin >> x;       vector<long long> v(x);       vector<long long> prefix(x);       vector<long long> suffix(x);       vector<long long> dp(x);       long long curMx, curSuf, curPref;       for (int i(0), ThkMk(x); i < ThkMk; ++i) {         cin >> v[i];         dp[i] = prefix[i] = v[i];         if (i > 0) {           prefix[i] += prefix[i - 1];           dp[i] += max(0LL, dp[i - 1]);           curMx = max(curMx, dp[i]);         } else           curMx = v[0];       }       suffix[x - 1] = v[x - 1];       curSuf = suffix[0];       curPref = prefix[0];       for (int i = x - 2; i >= 0; --i) suffix[i] += suffix[i + 1] + v[i];       for (int i(0), ThkMk(x); i < ThkMk; ++i) {         curSuf = max(curSuf, suffix[i]);         curPref = max(curPref, prefix[i]);       }       vPref[i] = curPref;       vSuf[i] = curSuf;       vTot[i] = suffix[0];       vCen[i] = curMx;     }     long long ans = -1e18;     long long prev = 0;     for (int i(0), ThkMk(m); i < ThkMk; ++i) {       cin >> x;       --x;       ans = max(ans, vCen[x]);       ans = max(ans, prev + vPref[x]);       prev = max({0LL, prev + vTot[x], vSuf[x]});     }     cout << ans <<   n ;     return 0;   }   