func_code_string: #include <bits/stdc++.h>   using namespace std;   template <typename T>   void maxE(T& a, const T& b) {     a = max(a, b);   }   template <typename T>   void minE(T& a, const T& b) {     a = min(a, b);   }   template <typename T>   ostream& operator<<(ostream& out, const vector<T>& t_) {     out <<  [ ;     for (auto i : t_) out << i <<  ,  ;     out <<  ] ;     return out;   }   template <typename S, typename T>   ostream& operator<<(ostream& out, const pair<S, T>& rhs) {     out <<  (  << rhs.first <<  ,  << rhs.second <<  ) ;     return out;   }   const long long INF = 1000LL * 1000 * 1000 * 1000 * 1000 * 1000LL;   struct Val {     long long maxPref, maxSuf, sum, maxInf;   };   Val neutral() {     Val r;     r.maxPref = r.maxSuf = r.maxInf = 0;     r.sum = 0;     return r;   }   Val single(long long a) {     Val r;     r.maxPref = r.maxSuf = r.maxInf = max(0LL, a);     r.sum = a;     return r;   }   Val join(const Val& a, const Val& b) {     Val r;     r.maxPref = max(a.maxPref, a.sum + b.maxPref);     r.maxSuf = max(a.maxSuf + b.sum, b.maxSuf);     r.sum = a.sum + b.sum;     r.maxInf = max(max(a.maxInf, b.maxInf), a.maxSuf + b.maxPref);     return r;   }   struct Tree {     int s;     vector<Val> t;     void init(int s_) {       s = 1;       while (s <= s_) s *= 2;       t.assign(2 * s, neutral());     }     Val tget(int a, int b) {       if (a > b)         return neutral();       else if (a == b)         return t[a];       Val r = neutral();       int na = a;       int nb = b;       if (a % 2) na++;       if (nb % 2 == 0) nb--;       if (a % 2) r = join(r, t[a]);       r = join(r, tget(na / 2, nb / 2));       if (b % 2 == 0) r = join(r, t[b]);       return r;     }     long long get(int a, int b) { return tget(s + a, s + b).maxInf; }   };   int n;   vector<long long> t;   Tree tree;   int main() {     int m;     assert(scanf( %d%d , &n, &m) == 2);     vector<int> d, h;     for (int i = 0; i < int(n); ++i) {       int a;       assert(scanf( %d , &a) == 1);       d.push_back(a);     }     for (int i = 0; i < int(n); ++i) {       int a;       assert(scanf( %d , &a) == 1);       h.push_back(a);     }     for (int j = 0; j < int(2); ++j)       for (int i = 0; i < int(n); ++i) {         t.push_back(h[i] * 2LL);         t.push_back(-4LL * h[i]);         t.push_back(h[i] * 2LL);         t.push_back(d[i]);       }     tree.init(((int)((t).size())));     for (int i = 0; i < int(((int)((t).size()))); ++i)       tree.t[tree.s + i] = single(t[i]);     for (int i = tree.s - 1; i >= 1; i--)       tree.t[i] = join(tree.t[i * 2], tree.t[i * 2 + 1]);     if (0) cout <<  tree ready   << endl;     if (0)       cout <<  SIZE(t)             <<     << ((int)((t).size())) <<     << endl;     for (int i = 0; i < int(m); ++i) {       int a, b;       assert(scanf( %d%d , &a, &b) == 2);       a--;       b--;       int x, y;       if (a <= b) {         x = b + 1;         y = a + n - 1;       } else {         x = b + 1;         y = a - 1;       }       assert(x < y);       if (0)         cout <<  a               <<     << a <<                  <<  b               <<     << b <<                  <<  x               <<     << x <<                  <<  y               <<     << y <<     << endl;       x = 4 * x;       y = 4 * y;       int s = ((int)((t).size()));       assert(x >= 0 && x < s && y >= 0 && y < s);       cout << tree.get(x, y) << endl;     }     return 0;   }   