malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1000000007;   const long long int inf = 0x3f3f3f3f3f3f3f3fLL;   const double eps = 1e-9;   const double PI = acos(-1);   long long int i, j, k;   void solve(void);   inline bool equal(double a, double b) { return fabs(a - b) < eps; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout << fixed << setprecision(10);     int t = 1;     while (t--) solve();     return 0;   }   long long int m;   unordered_map<long long int, long long int> f;   long long int fib(long long int n) {     if (n == 0) return 0;     if (n == 1 || n == 2) return (f[n] = 1) % m;     if (f[n]) return f[n];     long long int k = (n & 1) ? (n + 1) / 2 : n / 2;     f[n] = (n & 1) ? ((fib(k) * fib(k)) % m + (fib(k - 1) * fib(k - 1)) % m) % m                    : (((2 * fib(k - 1)) % m + fib(k)) % m * fib(k)) % m;     return f[n];   }   void solve() {     long long int l, r, k;     cin >> m >> l >> r >> k;     long long int d = (r - l) / (k - 1);     while (d > 1) {       if (1 + r / d - (l + d - 1) / d >= k) break;       long long int N = 1 + r / d;       d -= ((N * d - r) + (N - 1)) / N;     }     cout << fib(d) <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   char str[100010];   long long n, l[100010], r[100010], ofs, stk[100010], sa[100010], rk[100010],       tmp[100010], hei[100010];   vector<long long> ll[100010], rr[100010];   void build_sa(char *str, long long sa[]);   void build_hei(char *str, long long sa[], long long hei[]);   int main() {     scanf( %s , str);     n = strlen(str);     build_sa(str, sa);     build_hei(str, sa, hei);     long long i, k;     for (k = 0, i = 1; i <= n - 1; i++) {       while (k && hei[stk[k]] >= hei[i]) k--;       l[i] = (k ? stk[k] + 1 : 1);       stk[++k] = i;     }     for (k = 0, i = n - 1; i >= 1; i--) {       while (k && hei[stk[k]] >= hei[i]) k--;       r[i] = (k ? stk[k] - 1 : n - 1);       stk[++k] = i;     }     for (i = 1; i <= n - 1; i++)       if (hei[i] && (ll[hei[i]].empty() || l[i] != ll[hei[i]].back())) {         ll[hei[i]].push_back(l[i]);         rr[hei[i]].push_back(r[i]);       }     long long ans = 0, p, q;     for (hei[0] = hei[n] = 0, i = 1; i <= n - 1; i++)       while (!ll[i].empty()) {         p = ll[i].back();         q = rr[i].back();         ans += (q - p + 2) * (q - p + 3) / 2 * (i - max(hei[p - 1], hei[q + 1]));         ll[i].pop_back();         rr[i].pop_back();       }     for (i = 1; i <= n; i++) ans += n - sa[i] + 1 - max(hei[i], hei[i - 1]);     printf( %I64d n , ans);     return 0;   }   bool cmp(long long i, long long j) {     if (rk[i] != rk[j]) return rk[i] < rk[j];     long long ri = (i + ofs <= n ? rk[i + ofs] : -1),               rj = (j + ofs <= n ? rk[j + ofs] : -1);     return ri < rj;   }   void build_sa(char *str, long long sa[]) {     long long i;     for (i = 1; i <= n; i++) {       sa[i] = i;       rk[i] = str[i - 1];     }     for (ofs = 1; ofs <= n; ofs *= 2) {       sort(sa + 1, sa + n + 1, cmp);       for (tmp[sa[1]] = 1, i = 2; i <= n; i++)         tmp[sa[i]] = tmp[sa[i - 1]] + (cmp(sa[i - 1], sa[i]) ? 1 : 0);       for (i = 1; i <= n; i++) rk[i] = tmp[i];     }   }   void build_hei(char *str, long long sa[], long long hei[]) {     long long h = 0, i, j;     for (i = 1; i <= n; i++) {       if (rk[i] == n) continue;       j = sa[rk[i] + 1];       if (h) h--;       for (; j + h <= n && i + h <= n; h++)         if (str[j + h - 1] != str[i + h - 1]) break;       hei[rk[i]] = h;     }   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7, A = 5e5 + 5;   vector<vector<long long>> v;   long long n, m, val;   long long ans[A];   bool vis[A], vis2[A];   void DFS(long long node) {     if (vis[node]) return;     vis[node] = 1;     for (auto child : v[node]) {       if (vis[child]) continue;       val++;       DFS(child);     }   }   void DFSmemo(long long node) {     if (vis2[node]) return;     vis2[node] = 1;     for (auto child : v[node]) {       if (vis2[child]) continue;       ans[child] = val;       DFSmemo(child);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     v.resize(n + 2);     for (int i = 0; i < m; i++) {       long long g, x, y;       cin >> g;       if (g != 0) cin >> x;       for (int j = 1; j < g; j++) {         cin >> y;         v[x].push_back(y), v[y].push_back(x);       }     }     for (int i = 1; i <= n; i++) {       if (ans[i] == 0) {         val = 1;         DFS(i);         DFSmemo(i);       } else         val = ans[i];       cout << val <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     vector<set<int> > v(n);     vector<set<int> > w(n);     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       a--;       b--;       if (a > b)         v[a].insert(b);       else         v[b].insert(a);       if (a > b)         w[b].insert(a);       else         w[a].insert(b);     }     vector<int> pairs(n), pairs2(n);     pairs[0] = v[0].size();     for (int i = 1; i < n; i++) pairs[i] = pairs[i - 1] + v[i].size();     pairs2[n - 1] = 0;     for (int i = n - 2; i >= 0; i--) pairs2[i] = pairs2[i + 1] + w[i].size();     long long ans = 0;     for (int i = 0; i < n - 1; i++)       if (pairs[i] == 0 && pairs2[i + 1] == 0) ans++;     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long cnt(long long a, long long b, long long c) {     if (a > b || b > c) return 0LL;     if (a == b && b == c) return 1LL;     if (a == b && b < c) return 3LL;     if (a < b && b == c) return 3LL;     if (a < b && b < c) return 6LL;   }   int main() {     long long n;     scanf( %lld , &n);     if (n % 3LL)       printf( 0 n );     else {       long long ans = 0LL;       n /= 3LL;       for (long long sab = 1LL; sab * sab * sab <= n; sab++)         if (n % sab == 0LL) {           for (long long a = 1LL; a <= sab - a; a++) {             long long b = sab - a;             long long det = sab * sab - 4LL * a * b + 4LL * n / sab;             if (det < 0LL) continue;             long long sqdet = 0LL, dd = 1LL << 30LL;             while (dd) {               long long nsqdet = sqdet + dd;               if (nsqdet * nsqdet <= det) sqdet = nsqdet;               dd >>= 1LL;             }             if (sqdet * sqdet == det) {               long long c = sqdet - sab;               if (c % 2LL == 0) {                 c /= 2LL;                 ans += cnt(a, b, c);               }             }           }         }       printf( %lld n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6;   const int md = 1000000009;   int n;   long long two[maxn + 5], f[maxn + 5], ans;   int main() {     two[0] = 1;     for (int i = 1; i <= maxn; ++i) two[i] = two[i - 1] * 2 % md;     scanf( %d , &n);     f[n] = 2;     for (int i = n - 1; i >= 2; --i) {       if (i & 1)         f[i] = (f[i + 1] + 2) % md;       else {         int k = i >> 1;         f[i] = (2 + ((two[k - 1] - 1 + md) % md * 4 + 1) * f[i + 1]) % md;       }     }     f[1] = (1 + f[2] * f[2]) % md;     ans = f[1] * 2 % md;     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd1(long long a, long long b) {     if (a == 0) return b;     return gcd1(b % a, a);   }   long long modx(long long base, long long ex) {     long long ans = 1LL, val = base;     while (ex > 0LL) {       if (ex & 1LL) ans = (ans * val) % 998244353LL;       val = (val * val) % 998244353LL;       ex = ex >> 1LL;     }     return ans;   }   const int maxn = 5e5 + 10;   int a[maxn], n, c;   int pre[maxn], suff[maxn];   int cnt[maxn], ans;   vector<int> v[maxn];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> c;     for (int i = 1; i <= n; i++) {       cin >> a[i];       v[a[i]].push_back(i);       if (a[i] == c)         cnt[i] = cnt[i - 1] + 1;       else         cnt[i] = cnt[i - 1];     }     ans = cnt[n];     for (int i = 1; i < maxn; i++) {       if (i == c) continue;       if (v[i].size() == 0) continue;       for (int j = 0; j < v[i].size(); j++) {         pre[j] = cnt[v[i][j]];         pre[j]++;         if (j > 0) pre[j] = max(pre[j], pre[j - 1] + 1);       }       for (int j = v[i].size() - 1; j >= 0; j--) {         suff[j] = cnt[n] - cnt[v[i][j]];         suff[j]++;         if (j + 1 < v[i].size()) suff[j] = max(suff[j], suff[j + 1] + 1);       }       for (int j = 0; j < v[i].size(); j++) {         ans = max(ans, pre[j] + suff[j] - 1);       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     int base = sqrt(n);     if (base * base == n) {       cout << base <<     << 1 << endl;       return;     }     n = n - base * base;     if (n <= base + 1) {       cout << n <<     << base + 1 << endl;     } else       cout << base + 1 <<     << (2 * (base + 1) - n) << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string a, s;     cin >> a >> s;     sort(s.begin(), s.end());     reverse(s.begin(), s.end());     int k = 0;     for (int i = 0; i < a.size() && i < s.size(); i++) {       bool found = false;       for (int j = k; j < a.size(); j++) {         if (s[i] > a[j]) {           a[j] = s[i];           found = true;           k = j;           break;         }       }       if (!found) break;     }     cout << a << endl;   }
#include <bits/stdc++.h>   using namespace std;   bool sort_d(long long x, long long y) { return x > y; }   int gcd(long long x, long long y) {     if (!y)       return x;     else       return gcd(y, x % y);   }   int lcm(long long x, long long y) { return (x * y) / gcd(x, y); }   int main() {     int n, m, a, b;     std::vector<int> Cs, Ce, Ps, Pe;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a >> b;       Cs.push_back(a);       Ce.push_back(b);     }     cin >> m;     for (int i = 0; i < m; i++) {       cin >> a >> b;       Ps.push_back(a);       Pe.push_back(b);     }     sort(Cs.begin(), Cs.end());     sort(Ce.begin(), Ce.end());     sort(Ps.begin(), Ps.end());     sort(Pe.begin(), Pe.end());     a = max(Ps[Ps.size() - 1] - Ce[0], 0);     b = max(Cs[Cs.size() - 1] - Pe[0], 0);     cout << max(a, b) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int ni() {     int a;     scanf( %d , &a);     return a;   }   inline double nf() {     double a;     scanf( %lf , &a);     return a;   }   template <class T>   void out(T a, T b) {     bool first = true;     for (T i = a; i != b; i++) {       if (!first) printf(   );       first = false;       cout << *i;     }     puts(  );   }   template <class T>   void outl(T a, T b) {     for (T i = a; i != b; i++) cout << *i <<   n ;   }   int n, m;   vector<pair<int, int> > v;   map<int, vector<int> > p;   set<pair<int, int> > s;   vector<pair<int, int> > cur;   vector<pair<int, int> > w;   int mx;   int main() {     n = ni();     m = ni();     v.resize(m);     for (int i = 0; i < (int)(m); i++) {       v[i].first = ni();       v[i].second = ni();       p[v[i].first].push_back(v[i].second);       mx = max(mx, v[i].first);     }     for (map<int, vector<int> >::iterator it = p.begin(); it != p.end(); it++)       sort((it->second).begin(), (it->second).end());     s.insert(make_pair(1, 1));     int last = 0;     for (map<int, vector<int> >::iterator it = p.begin(); it != p.end();) {       if (s.empty()) break;       cur.clear();       if (last + 1 < it->first) {         cur.push_back(make_pair(1, n));         last = it->first - 1;       } else {         int f = 1, lst = n;         for (int i = 0; i < (int)(((int)(it->second).size())); i++) {           if (f < it->second[i]) {             cur.push_back(make_pair(f, it->second[i] - 1));           }           f = it->second[i] + 1;         }         if (f <= lst) cur.push_back(make_pair(f, lst));         last = it->first;         it++;       }       int d = 0;       w.clear();       for (set<pair<int, int> >::iterator sit = s.begin();            sit != s.end() && d < ((int)(cur).size());) {         while (d < ((int)(cur).size()) && cur[d].second < sit->first) d++;         if (d < ((int)(cur).size()) && cur[d].first <= sit->second) {           w.push_back(make_pair(max(cur[d].first, sit->first), cur[d].second));           d++;         } else {           sit++;         }       }       s.clear();       for (int i = 0; i < (int)(((int)(w).size())); i++) s.insert(w[i]);     }     if (!s.empty()) {       if (last == n) {         if (s.rbegin()->second == n)           cout << 2 * (n - 1) << endl;         else           puts( -1 );       } else {         cout << 2 * (n - 1) << endl;       }     } else {       cout << -1 << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   int solve();   void precomp();   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int t = 1;     if (0) cin >> t;     precomp();     for (int tc = 1; tc <= t; tc++) {       if (0 && 0) cout <<  Case #  << tc <<  :  ;       solve();     }   }   void precomp() { return; }   int cnt[26][26], ans[26], tmp[26];   string s;   int solve() {     cin >> s;     for (int i = 1; i <= s.size(); i++) {       memset(cnt, 0, sizeof(cnt));       memset(tmp, 0, sizeof(tmp));       for (int j = 0; j < s.size(); j++)         cnt[s[j] -  a ][s[(j + i) % s.size()] -  a ]++;       for (int j = 0; j < s.size(); j++)         if (cnt[s[j] -  a ][s[(i + j) % s.size()] -  a ] == 1) tmp[s[j] -  a ]++;       for (int j = 0; j < 26; j++) ans[j] = max(ans[j], tmp[j]);     }     int tot = 0;     for (int i = 0; i < 26; i++) tot += ans[i];     long double ans = (long double)tot / (long double)s.size();     cout << fixed << setprecision(10);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   const int MOD = 1e9 + 7;   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long l, r;     long long ans = -1;     cin >> l >> r;     for (int i = 0; l > 0 || r > 0; ++i) {       if ((l & 1) != (r & 1)) ans = i;       l >>= 1;       r >>= 1;     }     cout << (1LL << (ans + 1)) - 1 <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a, n, d, t, v;   double ans[100001];   double gets_ans() {     double t1 = v * 1.0 / a;     if (0.5 * a * t1 * t1 <= d) return t + t1 + (d - 0.5 * a * t1 * t1) / v;     return sqrt(2.0 * d / a) + t;   }   int main() {     cin >> n >> a >> d;     for (int i = 0; i < n; i++) {       cin >> t >> v;       ans[i] = gets_ans();       if (i != 0 && ans[i] < ans[i - 1]) ans[i] = ans[i - 1];       printf( %.10lf n , ans[i]);     }   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:100000000000000 )   using namespace std;   long long n, cnt[5], fct[1000001];   pair<long long, long long> dp[1000001];   string st;   map<char, int> mp;   long long pw(long long a, long long b) {     if (b == 0) return 1;     if (b == 1) return a;     long long ret = pw(a, b / 2);     (ret *= ret) %= 1000000007;     if (b & 1) (ret *= a) % 1000000007;     return ret;   }   pair<long long, long long> rec(int lef) {     if (lef == 0) return make_pair(0, 1);     if (~dp[lef].first) return dp[lef];     pair<long long, long long> ret = make_pair(0, 0);     for (int i = 0; i < 4; i++) {       pair<long long, long long> tmp = rec(lef - 1);       tmp.first += cnt[i];       if (tmp.first == ret.first)         (ret.second += tmp.second) %= 1000000007;       else if (tmp.first > ret.first)         ret = tmp;     }     return dp[lef] = ret;   }   int main() {     cin >> n >> st;     mp[ A ] = 0;     mp[ C ] = 1;     mp[ G ] = 2;     mp[ T ] = 3;     fct[0] = fct[1] = 1;     for (int i = 0; i < st.size(); i++) cnt[mp[st[i]]]++;     for (int i = 2; i < 1000001; i++) fct[i] = (fct[i - 1] * i) % 1000000007;     memset((dp), (-1), sizeof(dp));     pair<long long, long long> x = rec(n);     cout << x.second << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int Nmax = 2005;   int n, k;   pair<double, double> mij[Nmax * Nmax];   pair<int, int> a[Nmax];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i].first >> a[i].second;     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++)         mij[++k] = {(double)(a[i].first + a[j].first) / 2,                     (double)(a[i].second + a[j].second) / 2};     sort(mij + 1, mij + k + 1);     int cnt;     long long sol = 0;     cnt = 1;     for (int i = 2; i <= k;) {       while (i <= k && mij[i].first == mij[i - 1].first &&              mij[i].second == mij[i - 1].second) {         i++;         cnt++;       }       sol += (cnt * (cnt - 1)) / 2;       cnt = 1;       i++;     }     cout << sol <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool vis[500005];   int low[500005], d[500005], par[500005], rnk[500005], lev[500005], timer;   vector<int> adj[500005], tree[500005];   vector<pair<int, int>> edges;   map<int, map<int, int>> ed, br;   int get(int x) { return (par[x] == x ? x : par[x] = get(par[x])); }   void link(int x, int y) {     x = get(x);     y = get(y);     if (x == y) return;     par[x] = y;   }   void bridge_find(int u, int par) {     timer++;     d[u] = low[u] = timer;     for (auto x : adj[u]) {       if (x == par) continue;       if (d[x] > 0) {         low[u] = min(low[u], d[x]);         if (ed[x][u] == 0) ed[u][x] = 1;       } else {         bridge_find(x, u);         low[u] = min(low[u], low[x]);         if (d[u] < low[x])           br[u][x] = 1, br[x][u] = 1;         else {           ed[u][x] = 1;           link(u, x);         }       }     }   }   void dfs(int child, int par) {     vis[child] = 1;     for (auto x : adj[child]) {       if (x == par) continue;       if (br[x][child]) ed[x][child] = 1;       if (!vis[x]) dfs(x, child);     }   }   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++) rnk[i] = 1, par[i] = i;     for (int i = 0; i < m; i++) {       int x, y;       scanf( %d %d , &x, &y);       edges.push_back({x, y});       adj[x].push_back(y);       adj[y].push_back(x);     }     bridge_find(1, -1);     int mx = 0, cur;     for (int i = 1; i <= n; i++) {       int x;       x = get(i);       lev[x]++;       if (mx < lev[x]) {         mx = lev[x], cur = x;       }     }     dfs(cur, -1);     cout << mx << endl;     for (int i = 0; i < m; i++) {       if (ed[edges[i].first][edges[i].second])         cout << edges[i].first <<     << edges[i].second << endl;       else if (ed[edges[i].second][edges[i].first])         cout << edges[i].second <<     << edges[i].first << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, m, i;   int main() {     scanf( %d , &n);     n -= 10;     int a[20];     a[0] = 0;     a[1] = 4;     a[2] = 4;     a[3] = 4;     a[4] = 4;     a[5] = 4;     a[6] = 4;     a[7] = 4;     a[8] = 4;     a[9] = 4;     a[10] = 15;     a[11] = 4;     printf( %d n , (n <= 0 || n > 11 ? 0 : a[n]));   }
#include <bits/stdc++.h>   const long double eps = 1e-9;   const long double pi = fabsl(atan2(0.0, -1.0));   const int INF = 0x7f7f7f7f;   const long long LINF = 1ll << 60;   const long double LDINF = 1e42;   using namespace std;   int n, k;   string s;   int a[110];   int res[110];   int p[110];   void Load() {     cin >> n >> k;     cin >> s;     p[1] = 0;     int i, k = 0;     for (i = 2; i <= s.size(); i++) {       while (k > 0 && s[k] != s[i - 1]) k = p[k];       if (s[k] == s[i - 1]) k++;       p[i] = k;     }     {       int c = 0;       while ((c = getchar()) != 10 && c != EOF)         ;     };     for (int i = 0; i < n - s.size() + 1; i++) {       a[i] = getchar() -  0 ;     }   }   void Solve() {     int k = 0, i, j, t;     for (i = 0; i < n; i++) {       if (a[i] == 1) {         if (res[i] != 0) {           for (j = 0; j < s.size(); j++) {             if (res[i + j] != 0 && res[i + j] != s[j]) {               cout <<  No solution ;               return;             } else {               res[i + j] = s[j];             }           }         } else {           for (j = 0; j < s.size(); j++) {             res[i + j] = s[j];           }         }       }       if (res[i] == 0) {         int rr = 110, rch;         for (j =  a ; j <=  a  + ::k - 1; j++) {           t = k;           while (t > 0 && s[t] != j) t = p[t];           if (s[t] == j) t++;           if (rr > t) {             rr = t, rch = j;           }         }         cerr << rr <<     << (char)rch;         res[i] = rch;         k = rr;         if (k == s.size() && a[i - s.size() + 1] == 0) {           cout <<  No solution ;           return;         }       } else {         t = k;         while (t > 0 && s[t] != res[i]) t = p[t];         if (s[t] == res[i]) t++;         if (t == s.size() && a[i - s.size() + 1] == 0) {           cout <<  No solution ;           return;         }         k = t;       }     }     for (i = 0; i < n; i++) {       putchar(res[i]);     }   }   int main() {     Load();     Solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxN = 2 * 300000 + 1000;   int block[maxN], start[maxN], fin[maxN];   int main() {     ios::sync_with_stdio(0);     ;     int n, m;     cin >> n >> m;     string s;     cin >> s;     set<int> st;     st.insert(-1);     st.insert(n);     for (int i = 0; i < n; i++) {       if (s[i] !=  . ) st.insert(i);     }     int f = 0;     int cur = 0;     for (int i = 0; i < n; i++) {       if (s[i] ==  . )         cur++;       else {         if (cur) f += cur - 1;         cur = 0;       }     }     if (cur) f += cur - 1;     while (m--) {       int pos;       char c;       cin >> pos >> c;       pos--;       if (c ==  . ) {         auto left = st.lower_bound(pos);         if (*left != pos) {           cout << f <<   n ;           continue;         }         left--;         int l = *left;         int r = *st.upper_bound(pos);         int sub = r - pos - 2;         if (sub > 0) f -= sub;         sub = pos - l - 2;         if (sub > 0) f -= sub;         st.erase(pos);         sub = r - l - 2;         if (sub > 0) f += sub;       } else {         auto left = st.lower_bound(pos);         if (*left == pos) {           cout << f <<   n ;           continue;         }         left--;         int l = *left;         int r = *st.lower_bound(pos);         int sub = r - l - 2;         f -= sub;         sub = pos - l - 2;         if (sub > 0) f += sub;         sub = r - pos - 2;         if (sub > 0) f += sub;         st.insert(pos);       }       cout << f <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int n;   struct pt {     int ai;     int wz;   };   int cmp(pt a, pt b) { return a.ai > b.ai; }   pt cun[1005];   int ans;   int ans1[1005];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &cun[i].ai);       cun[i].wz = i;     }     sort(cun + 1, cun + 1 + n, cmp);     for (int i = 1; i <= n; i++) {       ans += cun[i].ai * (i - 1) + 1;     }     printf( %d n , ans);     for (int i = 1; i <= n; i++) {       printf( %d  , cun[i].wz);     }     printf(  n );     return 0;   }