malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long ans, n, m, a, r, c, sum, sums[1000002], sumsR[1000002],       sumsC[1000002], sumsR2[1000002], sumsC2[1000002];   const long long p = 998244353;   struct el {     long long x, r, c;   };   bool operator<(el x, el y) { return x.x < y.x; }   el arr[1000002];   long long modu(long long am, long long bm) {     long long ansm = am, p2 = p - 2, h = bm;     while (p2 > 0) {       if ((p2 & 1) != 0) ansm = (ansm * h) % p;       h = (h * h) % p;       p2 /= 2;     }     return ansm;   }   int main() {     cin >> n >> m;     for (long long i = 1; i <= n * m; i++) {       cin >> a;       arr[i].x = a;       arr[i].r = (i - 1) / m + 1;       arr[i].c = (i - 1) % m + 1;     }     cin >> r >> c;     sort(arr + 1, arr + n * m + 1);     sums[1] = 0;     sumsR[1] = arr[1].r % p;     sumsC[1] = arr[1].c % p;     sumsR2[1] = (arr[1].r * arr[1].r) % p;     sumsC2[1] = (arr[1].c * arr[1].c) % p;     a = 0;     for (int i = 2; i <= n * m; i++) {       if (arr[i].x != arr[i - 1].x) a = i - 1;       sum = 0;       sum += sums[a] % p;       sum %= p;       sum += (a * arr[i].r * arr[i].r) % p;       sum %= p;       sum += (a * arr[i].c * arr[i].c) % p;       sum %= p;       sum += (sumsR2[a]) % p;       sum %= p;       sum += (sumsC2[a]) % p;       sum %= p;       sum -= (2 * arr[i].r * sumsR[a]) % p;       sum %= p;       if (sum < 0) sum += p;       sum -= (2 * arr[i].c * sumsC[a]) % p;       sum %= p;       if (sum < 0) sum += p;       sum = modu(sum, a);       if (arr[i].r == r && arr[i].c == c) {         ans = sum;         break;       }       sumsR[i] = (sumsR[i - 1] + arr[i].r) % p;       sumsC[i] = (sumsC[i - 1] + arr[i].c) % p;       sumsR2[i] = (sumsR2[i - 1] + arr[i].r * arr[i].r) % p;       sumsC2[i] = (sumsC2[i - 1] + arr[i].c * arr[i].c) % p;       sums[i] = (sums[i - 1] + sum);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long cnt, n, pre, i, j, k, l, x, y, z, a[310][310];     cin >> n;     pre = 0;     for (i = 1; i <= n; i++) {       for (j = 1; j <= n; j++) {         cin >> a[i][j];         pre += a[i][j];       }     }     cin >> k;     while (k--) {       cin >> x >> y >> z;       if (a[x][y] <= z)         cout << pre / 2 <<    ;       else {         cnt = 0;         a[x][y] = z;         a[y][x] = z;         for (i = 1; i <= n; i++) {           a[x][i] = min(a[x][i], a[x][y] + a[y][i]);           a[i][x] = a[x][i];         }         for (i = 1; i <= n; i++) {           a[y][i] = min(a[y][i], a[y][x] + a[x][i]);           a[i][y] = a[y][i];         }         for (i = 1; i <= n; i++)           for (j = 1; j <= n; j++)             a[i][j] = min(min(a[i][j], a[i][x] + a[x][j]), a[i][y] + a[y][j]);         for (i = 1; i <= n; i++)           for (j = 1; j <= n; j++) cnt += a[i][j];         pre = cnt;         cout << pre / 2 <<    ;       }     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int NM = 1000005;   const int Mod = 1000000007;   int N, m, n, p26 = 0, pi[NM], i, x, y, b[NM];   char a[NM];   bool kmp[NM];   long long put(long long a, int b) {     if (!b) return 1;     if (b & 1) return a * put(a * a % Mod, b >> 1) % Mod;     return put(a * a % Mod, b >> 1);   }   void KMP() {     int i, k = 0;     pi[1] = 0;     for (i = 2; i <= n; ++i) {       while (k && a[i] != a[k + 1]) k = pi[k];       if (a[i] == a[k + 1]) ++k;       pi[i] = k;     }     while (k) {       kmp[k] = 1;       k = pi[k];     }   }   int main() {     scanf( %d %d n , &N, &m);     gets(a + 1);     n = strlen(a + 1);     KMP();     if (!m) {       printf( %I64d n , put(26LL, N));       return 0;     }     for (i = 1; i <= m; ++i) scanf( %d , &b[i]);     p26 += b[1] - 1;     for (i = 1; i < m; ++i) {       x = b[i] + n - 1;       y = b[i + 1];       if (x < y)         p26 += y - x - 1;       else if (!kmp[x - y + 1]) {         printf( 0 n );         return 0;       }     }     p26 += N;     p26 -= b[i] + n - 1;     printf( %I64d n , put(26LL, p26));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 100;   char s[N];   int cost(char a, char b) { return min(abs(b - a), 26 - abs(b - a)); }   int main() {     int ans = 1e9;     int n;     cin >> n;     scanf( %s , s + 1);     for (int i = 1; i <= n; i++) {       int j = i + 1, k = j + 1, t = k + 1;       if (t > n) continue;       ans = min(ans, cost(s[i],  A ) + cost(s[j],  C ) + cost(s[k],  T ) +                          cost(s[t],  G ));     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   using namespace std;   int m, h, t, n, i, j, k;   int a[200000], q[200000];   long long sum[200000], ans;   long long pas[200000];   long long get(int i, int j) { return sum[j] - sum[i] + a[i]; }   int main() {     cin >> n;     for (i = 0; i < n; i++) cin >> a[i];     cin >> m;     for (i = 0; i < m; i++) cin >> q[i];     sort(a, a + n);     sum[0] = a[0];     for (i = 1; i < n; i++) {       sum[i] = sum[i - 1];       sum[i] += a[i];     }     for (i = 1; i <= 100000; i++) {       ans = 0;       long long num = 0;       long long freespace = i;       for (j = n - 2; j >= 0;) {         if (freespace > n * 10) freespace = n * 10;         num++;         long long l = j - freespace + 1;         if (l < 0) l = 0;         ans += num * get(l, j);         j = j - freespace;         freespace = freespace * i;       }       pas[i] = ans;     }     for (i = 0; i < m; i++) cout << pas[q[i]] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string st;   long n, k, ans, calc;   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> k;     cin >> st;     for (int i = 0; i < st.size(); i++) {       if (st[i] ==  # )         ++calc;       else {         ans = max(ans, calc);         calc = 0;       }     }     if (ans >= k)       cout <<  NO  << endl;     else       cout <<  YES  << endl;     cin.get();     cin.get();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 5005;   struct Point {     double x, y, z;   };   double dist(Point a, Point b) {     return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) +                 (a.z - b.z) * (a.z - b.z));   }   Point p[MAXN];   double dis[MAXN];   int main() {     int n;     while (scanf( %d , &n) != EOF) {       for (int i = 0; i < n; i++) scanf( %lf%lf%lf , &p[i].x, &p[i].y, &p[i].z);       for (int i = 1; i < n; i++) dis[i] = dist(p[0], p[i]);       double ta = 100000.0;       for (int i = 1; i < n - 1; i++) {         for (int j = i + 1; j < n; j++) {           double tmp = dist(p[j], p[i]);           double td;           if (dis[i] > dis[j])             td = (tmp - dis[i] + dis[j]) / 2 + dis[i];           else             td = (tmp - dis[j] + dis[i]) / 2 + dis[j];           if (ta > td) ta = td;         }       }       printf( %.6lf n , ta);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 510;   bool dp[N][N];   int n, k;   int a[N], b[N];   int main() {     cin >> n >> k;     long long sum1 = 0, sum2 = 0;     long long ans = 0;     for (int i = 1; i <= n; i++) {       scanf( %d%d , &a[i], &b[i]);       sum1 += a[i];       sum2 += b[i];     }     ans = sum1 / k + sum2 / k;     if (sum1 % k + sum2 % k < k) {       printf( %lld n , ans);       return 0;     } else {       bool flag = false;       dp[0][0] = true;       for (int i = 1; i <= n; i++)         for (int j = 0; j < k; j++)           if (dp[i - 1][j]) {             dp[i][j] = true;             for (int x = 1; x < k; x++) {               if (a[i] >= x && b[i] >= k - x) dp[i][(j + x) % k] = true;             }           }       for (int i = 0; i <= sum1 % k; i++)         if (dp[n][i] && sum2 % k + i >= k) {           flag = true;           break;         }       if (flag)         printf( %lld n , ans + 1);       else         printf( %lld n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s, t;     getline(cin, s);     getline(cin, t);     int x = -1, y = -1;     for (int i = 0, j = 0; j < t.length(); j++) {       i += s[i] == t[j];       if (i == s.length()) {         x = j;         break;       }     }     for (int i = s.length() - 1, j = t.length() - 1; j >= 0; j--) {       i -= s[i] == t[j];       if (i == -1) {         y = j;         break;       }     }     if (x != -1 && y != -1 && x < y) {       printf( %d , y - x);     } else {       printf( 0 );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const double eps = 1e-9;   char mapp[110][110];   int main() {     cin.sync_with_stdio(false);     int n, m;     int ans, cnt;     int x1, x2, y1, y2;     while (cin >> n >> m) {       ans = 0;       x1 = 0x3f3f3f3f, x2 = -1, y1 = 0x3f3f3f3f, y2 = -1;       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           cin >> mapp[i][j];           if (mapp[i][j] ==  B ) {             x1 = min(x1, i);             y1 = min(y1, j);             x2 = max(x2, i);             y2 = max(y2, j);             ans++;           }         }       }       if (x1 == 0x3f3f3f3f) {         cout << 1 << endl;       } else {         cnt = max(x2 - x1, y2 - y1) + 1;         if (cnt > n || cnt > m) {           cout << -1 << endl;           continue;         }         cout << cnt * cnt - ans << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int maxN = -1;   vector<string> str;   bool ok = false;   int main() {     string s;     while (getline(cin, s)) {       maxN = max(maxN, (int)s.size());       str.push_back(s);     }     for (int i = 0; i < maxN + 2; i++) cout <<  * ;     cout << endl;     int n = str.size();     for (int i = 0; i < n; i++) {       cout <<  * ;       int ni = str[i].size();       int align = maxN - ni;       int space = align / 2;       if (align % 2 != 0) {         if (ok == false) {         } else           space++;       }       for (int j = 0; j < space; j++) cout <<    ;       cout << str[i];       if (align % 2 != 0) {         if (ok == true)           space--;         else if (ok == false)           space++;       }       for (int j = 0; j < space; j++) cout <<    ;       cout <<  * ;       cout << endl;       if (align % 2) ok = !ok;     }     for (int i = 0; i < maxN + 2; i++) cout <<  * ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long read() {     char c = getchar();     long long x = 0;     bool f = 0;     for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45);     for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);     if (f) x = -x;     return x;   }   long long n, a[300005], l[300005], r[300005];   bool vis[300005];   void work() {     n = read();     for (register long long i = (1); i <= (n); ++i) a[i] = read(), vis[i] = 0;     long long all = 0, now = 0, mx = 0;     for (register long long i = (1); i <= (n); ++i) {       if (!vis[a[i]]) vis[a[i]] = 1, l[a[i]] = i, ++all;       r[a[i]] = i;     }     long long lst = -1;     for (register long long i = (1); i <= (n); ++i)       if (vis[i]) {         if (!now)           now = mx = 1, lst = i;         else {           if (l[i] > r[lst])             now++;           else             now = 1;           lst = i;           mx = max(mx, now);         }       }     cout << all - mx << endl;   }   signed main() {     long long T = read();     while (T--) work();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   T sqr(T x) {     return x * x;   }   long double pi = 3.1415926535897932384626433832795;   long long mod = 1e9 + 7;   const int N = 1e6 + 10;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   vector<vector<long long> > e(int n) {     vector<vector<long long> > res;     for (int i = 0; i < n; i++) {       vector<long long> v;       for (int j = 0; j < n; j++) {         if (i == j)           v.push_back(1);         else           v.push_back(0);       }       res.push_back(v);     }     return res;   }   vector<vector<long long> > zero(int n, int m) {     vector<vector<long long> > res;     for (int i = 0; i < n; i++) {       vector<long long> v;       for (int j = 0; j < m; j++) {         v.push_back(0);       }       res.push_back(v);     }     return res;   }   vector<vector<long long> > operator^(vector<vector<long long> > b,                                        vector<vector<long long> > a) {     int n = b.size(), m = a[0].size(), K = a.size();     vector<vector<long long> > c = zero(n, m);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         for (int k = 0; k < K; k++) {           c[i][j] += b[i][k] * a[k][j];           c[i][j] %= mod;         }       }     }     return c;   }   vector<vector<long long> > bin_pow(vector<vector<long long> > a, long long pw) {     int n = a.size();     vector<vector<long long> > res = e(n);     while (pw) {       if (pw & 1ll) res = res ^ a;       a = a ^ a;       pw >>= 1;     }     return res;   }   long long n, k;   int main() {     cin >> n >> k;     vector<vector<long long> > ans = zero(1, 16);     ans[0][0] = 1;     for (int i = 0; i < n; i++) {       long long a, b, c;       cin >> a >> b >> c;       b = min(b, k);       long long pw = b - a;       vector<vector<long long> > m = zero(c + 1, c + 1);       ans[0].resize(c + 1);       for (int i = 0; i <= c; i++) {         for (int j = -1; j <= +1; j++) {           int ni = i + j;           if (ni < 0 || ni > c) continue;           m[i][ni] = 1;         }       }       m = bin_pow(m, pw);       ans = ans ^ m;     }     cout << ans[0][0];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int n;     cin >> n;     vector<int> scores;     for (int i = 0; i < n; i++) {       int temp;       cin >> temp;       scores.push_back(temp);     }     int max = scores[0];     int min = scores[0];     int count = 0;     for (int s : scores) {       if (s > max) {         max = s;         count++;       }       if (s < min) {         min = s;         count++;       }     }     cout << count <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int inf = 1e9 + 7;   const long long int inf2 = inf * inf;   priority_queue<long long int, vector<long long int>, greater<long long int>>       mnheap;   long long int gcd(long long int x, long long int y) {     if (x == 0) return y;     return gcd(y % x, x);   }   int is_prime(long long int x) {     if (x < 2) return 0;     for (long long int i = 2; i * i <= x; i++) {       if (x % i == 0) return 0;     }     return 1;   }   inline long long int modpw(long long int x, long long int y, long long int z) {     long long int res = 1;     x = x % z;     while (y) {       if (y & 1) res = (res * x) % z;       x = (x * x) % z;       y /= 2;     }     return res;   }   inline long long int modinv(long long int x, long long int z) {     return modpw(x, z - 2, z);   }   long long int lcm(long long int x, long long int y) {     return (x * y) / gcd(x, y);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     t = 1;     while (t--) {       int n;       cin >> n;       long long int x;       vector<long long int> vv;       for (int i = 0; i < n; i++) {         cin >> x;         vv.push_back(x);       }       if (n == 1) {         cout << 1 <<     << 1 << endl;         cout << -vv[0] << endl;         cout << 1 <<     << 1 << endl;         cout << 0 << endl;         cout << 1 <<     << 1 << endl;         cout << 0 << endl;         return 0;       }       cout << 1 <<     << n - 1 << endl;       for (int i = 0; i < n - 1; i++) {         cout << vv[i] * (n - 1) <<    ;       }       cout << endl;       cout << n <<     << n << endl;       cout << vv[n - 1] * (n - 1) << endl;       cout << 1 <<     << n << endl;       for (int i = 0; i < n; i++) {         cout << -1 * vv[i] * n <<    ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 100000 + 10;   int pos[MAX], s[MAX];   int main() {     int n, a;     while (cin >> n) {       memset(pos, 0, sizeof pos);       memset(s, -1, sizeof s);       for (int i = 1; i <= n; ++i) {         cin >> a;         if (s[a] == -1)           s[a] = 0;         else if (s[a] == 0)           s[a] = i - pos[a];         else if (s[a] > 0 && i - pos[a] != s[a])           s[a] = -2;         pos[a] = i;       }       int sum = 0;       for (int i = 1; i < MAX; ++i)         if (s[i] >= 0) ++sum;       cout << sum << endl;       for (int i = 1; i < MAX; ++i) {         if (s[i] >= 0) cout << i <<     << s[i] << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = -1;   int n;   int main() {     int t;     scanf( %d , &t);     for (int cs = (0); cs < (int)(t); cs++) {       scanf( %d , &n);       printf( %d %d n , n - 1, 1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct DirectedEulerPath {     int n;     vector<vector<int> > g;     vector<int> path;     void init(int _n) {       n = _n;       g = vector<vector<int> >(n + 1, vector<int>());       path.clear();     }     void add_edge(int u, int v) { g[u].push_back(v); }     void dfs(int u) {       while (g[u].size()) {         int v = g[u].back();         g[u].pop_back();         dfs(v);       }       path.push_back(u);     }     bool getPath() {       int ctEdges = 0;       vector<int> outDeg, inDeg;       outDeg = inDeg = vector<int>(n + 1, 0);       for (int i = 1; i <= n; i++) {         ctEdges += g[i].size();         outDeg[i] += g[i].size();         for (auto &u : g[i]) inDeg[u]++;       }       int ctMiddle = 0, src = 1;       for (int i = 1; i <= n; i++) {         if (abs(inDeg[i] - outDeg[i]) > 1) return 0;         if (inDeg[i] == outDeg[i]) ctMiddle++;         if (outDeg[i] > inDeg[i]) src = i;       }       if (ctMiddle != n && ctMiddle + 2 != n) return 0;       dfs(src);       reverse(path.begin(), path.end());       return (path.size() == ctEdges + 1);     }   } ep;   string arr[(int)5e5], rev[(int)5e5];   map<string, int> comp;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int n;     cin >> n;     for (int x = 0; x < n; x++) {       cin >> arr[x];       comp[arr[x].substr(0, 2)];       comp[arr[x].substr(1, 2)];     }     int cnt = 1;     for (auto x : comp) {       comp[x.first] = cnt;       rev[cnt++] = x.first;     }     ep.init(cnt);     for (int x = 0; x < n; x++)       ep.add_edge(comp[arr[x].substr(0, 2)], comp[arr[x].substr(1, 2)]);     bool ok = ep.getPath();     if (!ok) return 0 * printf( NO n );     cout <<  YES n ;     string ans = rev[ep.path[0]];     for (int x = 1; x < (int)ep.path.size(); x++) ans += rev[ep.path[x]].back();     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const long long maxn = 1e5 + 7;   long long n, k, a;   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> k;     a = n / (2 * (k + 1));     cout << a <<     << a * k <<     << n - a * (k + 1);   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   #pragma GCC optimization( unroll-loops )   using namespace std;   int n;   pair<int, int> e[200005];   int deg[200005];   vector<int> Adj[200005];   void solve();   int main() { solve(); }   void solve() {     cin >> n;     for (int i = 1; i <= n - 1; i++) {       int u, v;       cin >> u >> v;       e[i] = {u, v};       Adj[u].push_back(v);       Adj[v].push_back(u);     }     for (int i = 1; i <= n - 1; i++) {       int u = e[i].first, v = e[i].second;       int c = 0, d = 0;       if (Adj[u].size() - 1 == 1) {         cout <<  NO ;         return;       }       if (Adj[v].size() - 1 == 1) {         cout <<  NO ;         return;       }     }     cout <<  YES ;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10;   int n, m;   int long long dp[maxn];   vector<pair<int long long, int long long>> veci[maxn];   set<pair<int long long, int long long>> st;   bool mark[maxn];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     fill_n(dp, maxn, 1e18);     while (m--) {       int long long a, b, c;       cin >> a >> b >> c;       veci[a].push_back({b, c});       veci[b].push_back({a, c});     }     for (int i = 1; i <= n; i++) {       int long long a;       cin >> a;       st.insert({a, i});     }     while (st.size() > 0) {       auto x = *st.begin();       st.erase(x);       if (mark[x.second]) continue;       dp[x.second] = x.first;       mark[x.second] = 1;       for (auto y : veci[x.second])         st.insert({dp[x.second] + (2 * y.second), y.first});     }     for (int i = 1; i <= n; i++) cout << dp[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   inline int in() {     int x;     scanf( %d , &x);     return x;   }   const int N = 2 * 1e5 + 10;   const long long MOD = 1e9;   const long double eps = 1e-12;   int n, m;   long long fib[N], fib_sum[N], g0[4 * N], g1[4 * N], lazy[4 * N];   void precalc() {     fib[0] = fib[1] = 1;     for (int i = 2; i < N; i++) fib[i] = (fib[i - 1] + fib[i - 2]) % MOD;     for (int i = 0; i < N; i++) fib_sum[i + 1] = (fib_sum[i] + fib[i]) % MOD;   }   long long get_gib(int i, int x) {     if (x == 0) return g0[i];     if (x == 1) return g1[i];     long long res = 0;     res = g0[i] * fib[x - 2] + g1[i] * fib[x - 1];     res %= MOD;     return res;   }   void pull(int i, int l, int r) {     int m = (l + r) / 2, cl = i * 2 + 0, cr = i * 2 + 1;     g0[i] = g0[cl] + get_gib(cr, m - l);     g0[i] %= MOD;     g1[i] = g1[cl] + get_gib(cr, m - l + 1);     g1[i] %= MOD;   }   void upd(int id, int len, int add) {     g0[id] += add * fib_sum[len];     g0[id] %= MOD;     g1[id] += add * fib_sum[len + 1] - add;     g1[id] %= MOD;   }   void push(int idx, int l, int r) {     if (lazy[idx] <= 0) return;     int a = lazy[idx], cl = idx * 2 + 0, cr = idx * 2 + 1, m = (l + r) / 2;     upd(cl, m - l, a);     upd(cr, r - m, a);     lazy[cl] += a;     lazy[cr] += a;   }   void turn(int pos, int val, int l = 0, int r = n, int idx = 1) {     if (pos < l || r <= pos) return;     if (r - l < 2) {       g0[idx] = val, g1[idx] = val;       return;     }     push(idx, l, r);     int m = (l + r) / 2;     turn(pos, val, l, m, idx * 2 + 0);     turn(pos, val, m, r, idx * 2 + 1);     pull(idx, l, r);   }   void inc(int ql, int qr, int val, int l = 0, int r = n, int idx = 1) {     if (qr <= l || r <= ql) return;     if (ql <= l && r <= qr) {       upd(idx, r - l, val);       lazy[idx] += val;       return;     }     push(idx, l, r);     int m = (l + r) / 2;     inc(ql, qr, l, m, idx * 2 + 0);     inc(ql, qr, m, r, idx * 2 + 1);     pull(idx, l, r);   }   long long get(int ql, int qr, int l = 0, int r = n, int idx = 1) {     if (qr <= l || r <= ql) return 0;     if (ql <= l && r <= qr) {       return get_gib(idx, l - ql);     }     push(idx, l, r);     long long res = 0;     int m = (l + r) / 2;     res += get(ql, qr, l, m, idx * 2 + 0);     res += get(ql, qr, m, r, idx * 2 + 1);     return res % MOD;   }   int main() {     precalc();     n = in();     m = in();     for (int i = 0; i < n; i++) {       int a = in();       turn(i, a);     }     for (int i = 0; i < m; i++) {       int t = in();       if (t == 1) {         int x = in(), v = in();         x--;         turn(x, v);       } else if (t == 2) {         int l = in(), r = in();         l--;         long long res = (get(l, r) + MOD) % MOD;         printf( %I64d n , res);       } else {         int l = in(), r = in(), d = in();         l--;         inc(l, r, d);       }     }     return 0;   }