malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n, m, k;   string A[505];   bool a[505][505];   int star[505][505];   int col[505][505];   int main() {     cin >> n >> m >> k;     for (int i = 0; i < n; i++) cin >> A[i];     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) a[i][j] = A[i][j] ==  1 ;     for (int i = 1; i < n - 1; i++)       for (int j = 1; j < m - 1; j++) {         if (a[i][j] && a[i - 1][j] && a[i + 1][j] && a[i][j - 1] && a[i][j + 1])           star[i][j] = 1;       }     for (int j = 0; j < m; j++) {       col[j][0] = 0;       for (int i = 0; i < n; i++) col[j][i + 1] = col[j][i] + int(star[i][j]);     }     long long res = 0;     for (int i1 = 0; i1 < n; i1++)       for (int i2 = i1 + 3; i2 < n + 1; i2++) {         int z[m];         for (int j = 1; j < m - 1; j++) z[j] = col[j][i2 - 1] - col[j][i1 + 1];         int s = 0, j2 = 1;         for (int j1 = 1; j1 < m - 1; j1++) {           while (s < k) s += z[j2++];           res += m - j2;           s -= z[j1];         }       }     cout << res << endl;   }
#include <bits/stdc++.h>   using namespace std;   bool comp(int a[2], int b[2]) {     if (a[0] != b[0])       return a[0] > b[0];     else       return a[1] > b[1];   }   int main() {     int n;     cin >> n;     int ob[n][2], cl[n][2];     for (int i = 0; i < n; i++) {       cin >> ob[i][0] >> ob[i][1];     }     for (int i = 0; i < n; i++) {       cin >> cl[i][0] >> cl[i][1];     }     for (int i = 0; i < n - 1; i++) {       for (int j = 0; j < n - 1; j++) {         if (comp(ob[j], ob[j + 1])) {           int temp[2];           temp[0] = ob[j][0];           temp[1] = ob[j][1];           ob[j][0] = ob[j + 1][0];           ob[j][1] = ob[j + 1][1];           ob[j + 1][0] = temp[0];           ob[j + 1][1] = temp[1];         }       }     }     for (int i = 0; i < n - 1; i++) {       for (int j = 0; j < n - 1; j++) {         if (!comp(cl[j], cl[j + 1])) {           int temp[2];           temp[0] = cl[j][0];           temp[1] = cl[j][1];           cl[j][0] = cl[j + 1][0];           cl[j][1] = cl[j + 1][1];           cl[j + 1][0] = temp[0];           cl[j + 1][1] = temp[1];         }       }     }     cout << ob[0][0] + cl[0][0] <<     << ob[0][1] + cl[0][1];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long A = 100000000000000LL, N = 300228;   long long t[N * 4], i, j, n, m, a[N], p[N], o, b, l, r;   void modi(long long v, long long l, long long r, long long p, long long g) {     if (p < l || p > r) return;     if (l == r) {       t[v] = g;       return;     }     long long mid = (l + r) / 2;     if (p <= mid)       modi(v * 2, l, mid, p, g);     else       modi(v * 2 + 1, mid + 1, r, p, g);     t[v] = t[v * 2] + t[v * 2 + 1];   }   long long get(long long v, long long l, long long r, long long _l,                 long long _r) {     if (_l > _r) return 0;     if (l == _l && r == _r) return t[v];     long long mid = (l + r) / 2;     return get(v * 2, l, mid, _l, min(_r, mid)) +            get(v * 2 + 1, mid + 1, r, max(mid + 1, _l), _r);   }   int main() {     cin >> n;     for (i = 1; i <= n; i++) scanf( %d , &a[i]), p[a[i]] = i;     for (i = 1; i < n; i++)       if (p[i] > p[i + 1]) modi(1, 1, n, i + 1, 1);     cin >> m;     while (m--) {       scanf( %d%d%d , &b, &l, &r);       if (b == 1)         printf( %d n , get(1, 1, n, l + 1, r) + 1);       else {         swap(p[a[l]], p[a[r]]), swap(a[l], a[r]);         if (p[a[l]] > p[a[l] + 1])           modi(1, 1, n, a[l] + 1, 1);         else           modi(1, 1, n, a[l] + 1, 0);         if (p[a[r]] > p[a[r] + 1])           modi(1, 1, n, a[r] + 1, 1);         else           modi(1, 1, n, a[r] + 1, 0);         if (p[a[l] - 1] > p[a[l]])           modi(1, 1, n, a[l], 1);         else           modi(1, 1, n, a[l], 0);         if (p[a[r] - 1] > p[a[r]])           modi(1, 1, n, a[r], 1);         else           modi(1, 1, n, a[r], 0);       }     }   }
#include <bits/stdc++.h>   using namespace std;   bool desc(pair<long long, long long> a, pair<long long, long long> b) {     return a.first > b.first;   }   long long counter = 0, countedge = 0;   void addEdge(vector<long long> adj[], long long u, long long v) {     adj[u].push_back(v);     adj[v].push_back(u);   }   long long fact(long long x) {     long long z = 1;     while (x > 0) {       z *= x;       x--;     }     return z;   }   long long power(long long x, long long y) {     long long z = 1;     while (y-- > 0) {       z *= 2;     }     return z;   }   void dfs(vector<long long> adj[], long long u, bool vis[]) {     int i, j;     vis[u] = true;     counter++;     countedge += adj[u].size();     for (i = 0; i < adj[u].size(); i++) {       if (!vis[adj[u][i]]) dfs(adj, adj[u][i], vis);     }   }   pair<pair<long long, long long>, pair<long long, long long> > Intersect(       pair<long long, long long> a, pair<long long, long long> b,       pair<long long, long long> c, pair<long long, long long> d) {     int i, j, z, lf, rg, up, dwn;     pair<long long, long long> p1, p2;     lf = max(a.first, c.first);     rg = min(b.first, d.first);     dwn = max(a.second, c.second);     up = min(b.second, d.second);     p1 = make_pair(lf, dwn);     p2 = make_pair(rg, up);     if (rg <= lf || up <= dwn) return {{0, 0}, {0, 0}};     return make_pair(p1, p2);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int i, j, n, m, cont = 0, p, d, mn, sum = 0, k, a, b, z, w,                               sum2 = 0, c = 0, first, val, ans, nx, ny, o = 0, mx,                               s1, s2, l, r;     string s, t;     long long flag = 0;     vector<pair<long long, long long> > pt(7);     for (i = 1; i <= 6; i++) {       cin >> pt[i].first >> pt[i].second;     }     pair<pair<long long, long long>, pair<long long, long long> > wb1, wb2, inter;     wb1 = Intersect(pt[1], pt[2], pt[3], pt[4]);     wb2 = Intersect(pt[1], pt[2], pt[5], pt[6]);     inter = Intersect(wb1.first, wb1.second, wb2.first, wb2.second);     long long a1, a2;     a1 = (abs(wb1.first.first - wb1.second.first) *           abs(wb1.first.second - wb1.second.second));     a2 = (abs(wb2.first.first - wb2.second.first) *           abs(wb2.first.second - wb2.second.second));     c = (abs(inter.first.first - inter.second.first) *          abs(inter.first.second - inter.second.second));     long long area = (pt[1].first - pt[2].first) * (pt[1].second - pt[2].second);     if (area > (a1 + a2 - c))       cout <<  YES ;     else {       cout <<  NO ;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, q, a[2000000], f[2000000], fst[2000000], nx[2000000];   int main() {     srand(time(0));     scanf( %d %d , &n, &q);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (; q--;) {       long long b;       cin >> b;       int answer = 2e9, j = 1;       long long sum = 0;       for (int i = 1; i <= n; i++) {         sum += a[i];         while (sum > b) {           sum -= a[j];           j++;         }         nx[i] = j - 1;       }       f[0] = 0;       for (int i = 1; i <= n; i++) f[i] = f[nx[i]] + 1;       for (int i = 1; i <= n; i++)         if (f[i] == 1)           fst[i] = i;         else           fst[i] = fst[nx[i]];       sum = a[1];       if (sum > b) {         printf( %d n , answer);         continue;       }       int it = 1;       long long rightpart = a[1];       for (int i = 2; i < n; i++) {         if (sum + a[i] > b) break;         sum += a[i];         rightpart += a[i];         it = i;       }       for (int i = n; i >= 2; i--) {         sum += a[i];         while (it > 0 && sum > b) {           sum -= a[it];           rightpart -= a[it];           it--;         }         if (sum > b) break;         if (fst[i - 1] <= it)           answer = min(answer, f[i - 1]);         else           answer = min(answer, f[i - 1] + 1);       }       printf( %d n , answer);     };     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100000 + 10;   int n;   int a[N], indexes[N], parent[N], rrank[N], ccount[N];   bool used[N];   int get_set(int v) {     if (v == parent[v]) return v;     return parent[v] = get_set(parent[v]);   }   void create_set(int v) {     parent[v] = v;     rrank[v] = 0;     ccount[v] = 1;   }   void merge_sets(int v, int u) {     v = get_set(v);     u = get_set(u);     if (v != u) {       if (rrank[v] > rrank[u]) swap(v, u);       parent[v] = u;       if (rrank[v] == rrank[u]) rrank[u]++;       ccount[u] += ccount[v];     }   }   bool comp(int i, int j) { return a[i] < a[j]; }   int solve() {     int maxSize = 0, maxSets, sets = 0;     int res = 0, resSets = -1;     for (int i = 0; i < n; i++) {       bool isMerged = false;       int ind = indexes[i];       used[ind] = true;       sets++;       if (ind > 0 && used[ind - 1]) {         isMerged = true;         merge_sets(ind - 1, ind);         sets--;       }       if (ind < n - 1 && used[ind + 1]) {         isMerged = true;         merge_sets(ind + 1, ind);         sets--;       }       int sst = get_set(ind);       if (ccount[sst] > maxSize) {         maxSize = ccount[sst];         maxSets = 1;       } else if (ccount[sst] == maxSize) {         maxSets++;       }       if (i < n - 1 && a[indexes[i]] == a[indexes[i + 1]]) {         continue;       }       if (maxSets == sets && sets > resSets) {         resSets = sets;         res = a[ind] + 1;       }     }     return res;   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       indexes[i] = i;       create_set(i);       used[i] = false;     }     sort(indexes, indexes + n, comp);     cout << solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int m;   long long int power(long long int x, long long int y) {     long long int res = 1;     while (y > 0) {       if (y & 1) res = res * x;       res %= m;       y = y >> 1;       x = x * x;       x %= m;     }     return res;   }   long long int inv(long long int x) { return power(x, m - 2); }   long long int prime[100009];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> m;     for (long long int i = 2; i <= 100000; i++) {       if (prime[i] == 0) {         for (long long int j = (2 * i); j <= 100000; j += i) {           prime[j] = 1;         }       }     }     if (m == 1) {       cout <<  YES  <<   n  << 1;     } else if (m == 4) {       cout <<  YES  <<   n ;       cout << 1 <<   n  << 3 <<   n  << 2 <<   n  << 4;     } else if (prime[m] == 0) {       cout <<  YES  <<   n ;       cout << 1 <<   n ;       long long int x = 1;       for (long long int j = 2; j < m; j++) {         x = inv((j - 1));         x *= j;         x %= m;         cout << x <<   n ;       }       cout << m;     } else {       cout <<  NO ;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   long long u;   long long a[1000];   long long d[1000];   long long minn = -1e17;   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) {       scanf( %lld , &a[i]);       d[i] = minn;     }     for (int i = n; i >= 0; --i) {       for (int j = n; j >= 0; --j) {         if (j == 0) {           u = minn;         } else           u = d[j - 1];         d[j] = max(min(d[j] + a[i], 0LL), u);       }     }     while (m--) {       scanf( %lld , &u);       int k = lower_bound(d, d + n + 1, -u) - d;       cout << k << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long double EPS = 1E-9;   const int INF = (int)1E9;   const long long INF64 = (long long)1E18;   const long double PI = 2 * acos(.0);   int main() {     bool cumple[1005];     for (int i = 0; i < (int)(1005); i++) cumple[i] = false;     string word;     cin >> word;     int n = (word).size();     for (int i = 2; i <= n / 2; i++) {       cumple[i] = 1;       for (int j = 2; i * j <= n; j++) {         cumple[i * j] = 1;       }     }     int cont1 = 0;     for (int i = 1; i < (int)(n + 1); i++) {       if (cumple[i] == 1) cont1++;     }     int numWord[50];     memset(numWord, 0, sizeof(numWord));     for (int i = 0; i < (int)(n); i++) numWord[word[i] -  a ]++;     int maxPos = -1, maxi = -1;     for (int i = 0; i < (int)(50); i++) {       if (maxi < numWord[i]) {         maxi = numWord[i];         maxPos = i;       }     }     if (maxi < cont1)       cout <<  NO  << endl;     else {       string rege;       rege.append(n,  ? );       for (int i = 1; i < (int)(n + 1); i++)         if (cumple[i] == 1) rege[i - 1] =  a  + maxPos;       numWord[maxPos] -= cont1;       int cont = 0, wpos = 0;       while (wpos < n) {         if (rege[wpos] ==  ? ) {           if (numWord[cont] > 0) {             rege[wpos] = ( a  + cont);             numWord[cont]--;           } else             cont++;         } else           wpos++;       }       cout <<  YES  << endl;       cout << rege << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, a[100][100], f[2000000], p;   char s[30][30];   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) scanf( %s , s[i]);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) scanf( %d , &a[i][j]);     memset(f, 0x3f, sizeof(f));     f[0] = 0;     for (int i = 0; i <= (1 << n) - 2; i++) {       for (int j = 0; j < n; j++)         if (!(i & (1 << j))) {           p = j;           break;         }       for (int j = 0; j < m; j++) {         int sum = 0, l = 0, mx = 0;         f[i | (1 << p)] = min(f[i | (1 << p)], f[i] + a[p][j]);         for (int k = 0; k < n; k++)           if (s[k][j] == s[p][j]) {             sum = sum + a[k][j];             mx = max(mx, a[k][j]);             l = l | (1 << k);           }         f[i | l] = min(f[i | l], f[i] + sum - mx);       }     }     return printf( %d , f[(1 << n) - 1]), 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {       ios::sync_with_stdio(false);       cin.tie(nullptr);       int t;       cin >> t;       while (t--) {           int n, k;           cin >> n >> k;           string s;           cin >> s;           vector<int> pos;           vector<int> v;           for (int i = 0; i < n; i++) {               if (s[i] ==  * ) {                   pos.push_back(i);               }           }           if (pos.size()) {               v.push_back(pos[0]);           }           while (v.size() and v.back() + k < n) {               int i = upper_bound(pos.begin(), pos.end(), v.back() + k) - pos.begin();               if (pos[i - 1] == v.back()) {                   break;               }               v.push_back(pos[i - 1]);           }           if (pos.back() != v.back()) {               v.push_back(pos.back());           }           cout << v.size() <<   n ;       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int a[300005], w[300005];   long long ksm(long long a, long long b) {     if (!b) return 1;     long long ns = ksm(a, b >> 1);     ns = ns * ns % 998244353;     if (b & 1) ns = ns * a % 998244353;     return ns;   }   long long dp[3005][3005];   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     long long S[2] = {0, 0};     for (int i = 1; i <= n; i++)       scanf( %d , &w[i]), S[a[i]] += w[i], S[a[i]] %= 998244353;     long long f[2] = {S[0], S[1]};     dp[1][0] = 1;     for (int i = 1; i <= m; i++)       for (int j = 0; j <= i; j++) {         long long n1 = S[1] + j, n2 = S[0] - (i - 1 - j);         if (!dp[i][j]) continue;         long long bk = ksm((n1 + n2) % 998244353, 998244353 - 2);         n1 = n1 * bk % 998244353, n2 = n2 * bk % 998244353;         dp[i + 1][j] += n2 * dp[i][j], dp[i + 1][j] %= 998244353;         dp[i + 1][j + 1] += n1 * dp[i][j], dp[i + 1][j + 1] %= 998244353;       }     for (int j = 0; j <= m + 1; j++)       f[1] += dp[m + 1][j] * j, f[1] %= 998244353, f[0] -= dp[m + 1][j] * (m - j),           f[0] %= 998244353;     S[0] = ksm(S[0], 998244353 - 2);     S[1] = ksm(S[1], 998244353 - 2);     for (int i = 1; i <= n; i++) {       long long ns = f[a[i]] * S[a[i]] % 998244353 * w[i] % 998244353;       if (ns < 0) ns += 998244353;       printf( %lld n , ns);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int ToInt(string& s, int len) {     int r = 0;     for (int i = 0, max_ = (len); i < max_; ++i) {       r *= 10;       r += s[i] -  0 ;     }     return r;   }   int GCD(int a, int b) { return b != 0 ? GCD(b, a % b) : a; }   int LCM(int a, int b) { return a * (b / GCD(a, b)); }   long long Pow(long long n, long long e) {     if (e == 0) return 1;     if (e == 1)       return n;     else if (e & 1) {       long long t = Pow(n, e / 2);       return n * t * t;     } else {       long long t = Pow(n, e / 2);       return t * t;     }   }   int SolvePile(long long n) {     if (n < 4)       return 0;     else if (n < 16)       return 1;     else if (n < 82)       return 2;     else if (n < 6724)       return 0;     else if (n < 50626)       return 3;     else if (n < 2562991876LL)       return 1;     else       return 2;   }   int main() {     long long n;     int N, res = 0;     scanf( %d , &N);     for (int i = 0, max_ = (N); i < max_; ++i) {       scanf( %I64d , &n);       res ^= SolvePile(n);     }     if (res > 0)       printf( Furlo n );     else       printf( Rublo n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     bool flag = true;     int n, m;     cin >> n;     cin >> m;     char prev;     for (int i = 0; i < n; i++) {       string row;       cin >> row;       if (i != 0 && row[0] == prev) {         flag = false;       }       for (int j = 1; j < m; j++) {         if (row[j] != row[0]) {           flag = false;           break;         }       }       prev = row[0];     }     if (flag) {       cout <<  Yes  << endl;     } else {       cout <<  No  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> v[100010], ans;   int idx = 1;   void dfs(int cur, int prev) {     if ((int)v[cur].size() == 1 && cur != idx)       ans.push_back(cur);     else {       for (int i = 0; i < (int)v[cur].size(); i++) {         int j = v[cur][i];         if (j != prev) dfs(j, cur);       }     }     return;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d %d , &x, &y);       v[x].push_back(y);       v[y].push_back(x);     }     int cnt = 0;     for (int i = 1; i <= n; i++)       if ((int)v[i].size() > 2) cnt++, idx = i;     if (cnt > 1) {       printf( No n );       return 0;     }     printf( Yes n );     dfs(idx, -1);     printf( %d n , (int)ans.size());     for (int i = 0; i < (int)ans.size(); i++) printf( %d %d n , idx, ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f, mod = 1000000007;   const double pi = 3.1415926535897932, eps = 1e-6;   void chmax(int &x, int y) {     if (x < y) x = y;   }   void chmin(int &x, int y) {     if (x > y) x = y;   }   int B = 333;   int n, top = 101000, cnt;   string s[100005];   int val[300005], ex[300005];   long long sum[444][5];   int num[444], rea[100005];   map<int, int> mp;   void calc(int x) {     int lb = x * B, rb = (x + 1) * B;     int now_cnt = 0;     for (int(i) = (0); (i) <= (4); (i)++) sum[x][i] = 0;     num[x] = 0;     for (int(i) = (lb); (i) < (rb); (i)++) {       if (ex[i]) {         sum[x][now_cnt % 5] += rea[i];         now_cnt++;       }     }     num[x] = now_cnt;   }   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int(i) = (1); (i) <= (n); (i)++) {       cin >> s[i];       if (s[i] !=  sum ) {         cin >> val[i];         mp[val[i]] = 0;       }     }     for (map<int, int>::iterator it = mp.begin(); it != mp.end(); it++) {       rea[cnt] = it->first;       it->second = cnt++;     }     for (int(i) = (1); (i) <= (n); (i)++) {       if (s[i] ==  sum ) {         int Top = top / B + 1;         int now_cnt = 0;         long long ans = 0;         for (int(i) = (0); (i) <= (Top); (i)++) {           ans += sum[i][(2 - now_cnt + 555555555) % 5];           now_cnt += num[i];         }         cout << ans <<   n ;       } else {         val[i] = mp[val[i]];         if (s[i] ==  add ) {           int v = val[i];           ex[v] = 1;           int at = v / B;           calc(at);         } else {           int v = val[i];           ex[v] = 0;           int at = v / B;           calc(at);         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAXn = 100 + 13;   int n, k, t[MAXn];   int main() {     cin >> n;     for (int i = 0; i < n; i++) cin >> t[i];     cin >> k;     sort(t, t + n);     int i = 0, j = 0, d = 0, num = 0, ans = 0;     while (j < n) {       d = t[j++] - t[i];       while (d > k) d -= t[i++];       num = j - i;       ans = max(ans, num);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int ans[200010];   int main() {     int n;     cin >> n;     if (n & 1) {       puts( YES );       bool f = true;       for (int i = 0; i < n; i++) {         if (f)           ans[i + n] = (i + 1) * 2, ans[i] = (i + 1) * 2 - 1;         else           ans[i] = (i + 1) * 2, ans[i + n] = (i + 1) * 2 - 1;         f = !f;       }       for (int i = 0; i < (n * 2); i++) {         cout << ans[i] <<    ;       }     } else       puts( NO );   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long q;     cin >> q;     while (q--) {       long long a, b, m;       cin >> a >> b >> m;       if (a == b) {         cout << 1 <<     << a <<   n ;         continue;       }       bool ok = 0;       long long dif = 0;       long long p = a, i = 1ll;       while (p <= b) {         if (b - p <= ((1ll << (i - 1ll)) * m) && b - p >= (1ll << (i - 1ll))) {           ok = 1;           dif = b - p - (1ll << (i - 1ll));           break;         }         i++;         p = (p * 2ll);       }       if (!ok) {         cout << (-1) <<   n ;         continue;       }       long long s1 = min(dif, m - 1);       dif -= s1;       cout << i + 1 <<    ;       long long res[55];       res[0] = a;       for (long long j = 1ll; j < i; j++) {         long long sss = 0;         for (long long u = 0; u < j; u++) sss += res[u];         sss += min((dif / (1ll << (i - j - 1ll))), m - 1ll);         dif -= min((dif / (1ll << (i - j - 1ll))), m - 1ll) *                (long long)((1ll << (i - j - 1ll)));         sss++;         res[j] = sss;       }       long long sss = 0;       for (long long u = 0; u < i; u++) sss += res[u];       sss += s1;       sss++;       res[i] = sss;       for (long long j = 0; j <= i; j++) cout << res[j] <<    ;       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, p, d[100005], sum[100005], f[105][100005], s[100005], a[100005],       q[100005], head, tail, g[100005];   inline long long getint() {     long long x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     return x * f;   }   void work() {     n = getint(), m = getint(), p = getint();     for (int i = 2; i <= n; ++i) d[i] = getint(), sum[i] = sum[i - 1] + d[i];     for (int i = 1; i <= m; ++i) {       int x, y;       x = getint(), y = getint();       a[i] = y - sum[x];     }     sort(a + 1, a + 1 + m);     for (int i = 1; i <= m; ++i) s[i] = s[i - 1] + a[i];     memset(f, 0x3f, sizeof(f));     f[0][0] = 0;     for (int i = 1; i <= p; ++i) {       for (int j = 1; j <= m; ++j) g[j] = f[i - 1][j] + s[j];       head = 1, tail = 1;       q[1] = 0;       for (int j = 1; j <= m; ++j) {         while (head < tail &&                g[q[head + 1]] - g[q[head]] <= a[j] * (q[head + 1] - q[head]))           ++head;         f[i][j] = min(f[i - 1][j], g[q[head]] + a[j] * (j - q[head]) - s[j]);         if (g[j] >= 0x3f3f3f3f3f3f3f3fll) continue;         while (head < tail && (g[j] - g[q[tail]]) * (q[tail] - q[tail - 1]) <=                                   (g[q[tail]] - g[q[tail - 1]]) * (j - q[tail]))           --tail;         q[++tail] = j;       }     }     cout << f[p][m] << endl;   }   int main() {     work();     return 0;   }