func_code_string: #include <bits/stdc++.h>   using namespace std;   pair<pair<long long, long long>, pair<long long, long long> > st1[4000000];   pair<pair<long long, long long>, pair<long long, long long> > st2[4000000];   long long arrL[600010];   long long arrR[600010];   long long dist[600010];   long long height[600010];   pair<pair<long long, long long>, pair<long long, long long> > maximize(       pair<pair<long long, long long>, pair<long long, long long> > p,       pair<pair<long long, long long>, pair<long long, long long> > q) {     pair<long long, long long> a[4];     a[0] = p.first;     a[1] = p.second;     a[2] = q.first;     a[3] = q.second;     sort(a, a + 4);     return make_pair(a[2], a[3]);   }   void build(pair<pair<long long, long long>, pair<long long, long long> > st[],              long long arr[], int node, int L, int R) {     if (L == R)       st[node] = make_pair(make_pair(arr[L], L), make_pair(-1LL << 60, -1));     else {       int mid = (R + L) / 2;       build(st, arr, node * 2, L, mid);       build(st, arr, node * 2 + 1, mid + 1, R);       st[node] = maximize(st[node * 2], st[node * 2 + 1]);     }   }   pair<pair<long long, long long>, pair<long long, long long> > query(       pair<pair<long long, long long>, pair<long long, long long> > st[],       int node, int L, int R, int i, int j) {     if (i > R || j < L)       return make_pair(make_pair(-1LL << 60, -1), make_pair(-1LL << 60, -1));     if (L >= i && R <= j) return st[node];     int mid = (L + R) / 2;     pair<pair<long long, long long>, pair<long long, long long> > qL =         query(st, node * 2, L, mid, i, j);     pair<pair<long long, long long>, pair<long long, long long> > qR =         query(st, node * 2 + 1, mid + 1, R, i, j);     return maximize(qL, qR);   }   int main() {     int N, M;     cin >> N >> M;     for (int i = 0; i < N; i++) {       cin >> dist[i];       dist[i + N] = dist[i];     }     for (int i = 1; i < 2 * N - 1; i++) dist[i] += dist[i - 1];     for (int i = 0; i < N; i++) {       cin >> height[i];       height[i + N] = height[i];     }     for (int i = 0; i < 2 * N - 1; i++) {       arrL[i] = arrR[i] = 2 * height[i];       if (i) {         arrL[i] -= dist[i - 1];         arrR[i] += dist[i - 1];       }     }     build(st1, arrL, 1, 0, 2 * N - 1);     build(st2, arrR, 1, 0, 2 * N - 1);     for (int i = 0; i < M; i++) {       int a, b;       cin >> a >> b;       a--, b--;       int x, y;       if (a <= b) {         x = b + 1;         y = a + N - 1;       } else {         x = b + 1;         y = a - 1;       }       pair<pair<long long, long long>, pair<long long, long long> > p =           query(st1, 1, 0, 2 * N - 1, x, y);       pair<pair<long long, long long>, pair<long long, long long> > q =           query(st2, 1, 0, 2 * N - 1, x, y);       vector<pair<long long, long long> > v1;       v1.push_back(p.first);       v1.push_back(p.second);       vector<pair<long long, long long> > v2;       v2.push_back(q.first);       v2.push_back(q.second);       vector<long long> ret;       for (int i = 0; i < int((v1).size()); i++)         for (int j = 0; j < int((v2).size()); j++)           if (v1[i].second == v2[j].second)             continue;           else             ret.push_back(v1[i].first + v2[j].first);       sort((ret).begin(), (ret).end());       cout << ret.back() << endl;     }   }   