func_code_string: #include <bits/stdc++.h>   using namespace std;   inline int qpow(int b, int e, int m = 998244353) {     int a = 1;     for (; e; e >>= 1, b = (long long)b * b % m)       if (e & 1) a = (long long)a * b % m;     return a;   }   struct node {     long long sum;     long long pre;     long long suf;     long long ans;   };   node segt[1000000];   node combine(node &a, node &b) {     node c;     c.sum = a.sum + b.sum;     c.pre = max(a.pre, a.sum + b.pre);     c.suf = max(b.suf, b.sum + a.suf);     c.ans = max(max(a.ans, b.ans), a.suf + b.pre);     return c;   }   void build(long long i, long long tl, long long tr, vector<long long> &d,              vector<long long> &h) {     if (tl == tr) {       node t;       t.ans = 0;       t.sum = d[tl];       t.pre = 2 * h[tl];       t.suf = 2 * h[tl] + d[tl];       segt[i] = t;       return;     }     long long tm = (tl + tr) / 2;     build(i * 2, tl, tm, d, h);     build(i * 2 + 1, tm + 1, tr, d, h);     node c = combine(segt[i * 2], segt[i * 2 + 1]);     segt[i] = c;   }   node getans(long long i, long long tl, long long tr, long long l, long long r) {     if (l > r) {       node t;       t.sum = t.pre = t.suf = t.ans = INT_MIN;       return t;     }     if (tl == l && tr == r) return segt[i];     long long tm = (tl + tr) / 2;     node a = getans(i * 2, tl, tm, l, min(tm, r));     node b = getans(i * 2 + 1, tm + 1, tr, max(tm + 1, l), r);     node c = combine(a, b);     ;     return c;   }   void pn(node a) {     cout <<  ans :   << a.ans <<   pre:   << a.pre <<   suf :  << a.suf          <<   sum :   << a.sum << endl;   }   void solve() {     long long n, m;     cin >> n >> m;     vector<long long> d(2 * n + 1);     vector<long long> h(2 * n + 1);     for (int i = 1; i <= n; i++) {       cin >> d[i];       d[i + n] = d[i];     }     for (int i = 1; i <= n; i++) {       cin >> h[i];       h[i + n] = h[i];     }     build(1, 1, 2 * n, d, h);     while (m--) {       long long a, b;       cin >> a >> b;       long long l, r;       l = b + 1;       if (a <= b) {         r = n + a - 1;       } else {         r = a - 1;       }       auto ans = getans(1, 1, 2 * n, l, r);       cout << ans.ans << endl;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     t = 1;     while (t--) solve();     return 0;   }   