malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 20, MAX2 = 1e7 + 10;   int an[MAX], n, x;   bool primes[MAX2];   void seive(long long n) {     for (long long i = 2; i <= n; i++) primes[i] = 1;     for (long long i = 2; i <= n; i++) {       if (primes[i] == 1) {         for (long long j = i * i; j <= n; j += i) primes[j] = 0;       }     }   }   set<int> mm;   int main() {     scanf( %d%d , &n, &x);     for (int i = 0; i < n; i++) scanf( %d , &an[i]), mm.insert(an[i]);     int k = 1299721;     seive(k);     if (x == 2)       printf( %d n , 0);     else if (*mm.begin() == 1)       printf( %d n , 1);     else {       if (x - 1 > 1299721)         printf( %d n , -1);       else {         vector<int> pp;         for (int i = 2; i <= x - 1; i++) {           if (primes[i] == 1) pp.push_back(i);         }         bool ok = 1;         for (int i = 0; i < pp.size(); i++) {           auto ite = mm.find(pp[i]);           if (ite == mm.end()) ok = 0;         }         if (!ok)           printf( %d n , -1);         else           printf( %d n , pp.size());       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   long long read_ll() {     char c = getchar();     while ((c <  0  || c >  9 ) && c !=  - ) c = getchar();     long long ret = 0;     int neg = 0;     if (c ==  - ) neg = 1, c = getchar();     while (c >=  0  && c <=  9 ) {       ret = 10 * ret + c - 48;       c = getchar();     }     return neg ? -ret : ret;   }   int main() {     long long n, i;     n = read_ll();     long long a[n + 2], mini = INT_MAX, maxi = INT_MIN;     a[0] = INT_MIN;     a[n + 1] = INT_MIN;     for (i = 1; i <= n; i++) {       a[i] = read_ll();       mini = min(a[i], mini);       maxi = max(a[i], maxi);     }     long long leftmin[n + 1], rightmin[n + 1], leftmax[n + 1], rightmax[n + 1];     memset(leftmax, 0, sizeof(leftmax));     memset(rightmin, 0, sizeof(rightmin));     memset(rightmax, 0, sizeof(rightmax));     memset(leftmin, 0, sizeof(leftmin));     stack<long long> st;     st.push(0);     for (i = 1; i <= n; i++) {       while (a[st.top()] >= a[i]) st.pop();       leftmin[i] = st.top();       st.push(i);     }     while (!st.empty()) st.pop();     st.push(n + 1);     for (i = n; i >= 1; i--) {       while (a[st.top()] > a[i]) st.pop();       rightmin[i] = st.top();       st.push(i);     }     while (!st.empty()) st.pop();     a[0] = INT_MAX, a[n + 1] = INT_MAX;     st.push(0);     for (i = 1; i <= n; i++) {       while (a[st.top()] <= a[i]) st.pop();       leftmax[i] = st.top();       st.push(i);     }     while (!st.empty()) st.pop();     st.push(n + 1);     for (i = n; i >= 1; i--) {       while (a[st.top()] < a[i]) st.pop();       rightmax[i] = st.top();       st.push(i);     }     long long minsum = mini, maxsum = maxi, res = 0;     for (i = 1; i <= n; i++) {       long long cnt = (rightmax[i] - i) * (i - leftmax[i]) -                       (rightmin[i] - i) * (i - leftmin[i]);       res += cnt * a[i];     }     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2010;   int n, a[N], p[N], pos[N];   vector<int> c[26], ans;   string s, t;   void add(int x) {     if (0 < x) {       ans.push_back(x);     }     vector<int> nw;     for (int i = n - 1; i >= n - x; --i) {       nw.push_back(p[i]);     }     for (int i = n - 1; i >= x; --i) {       p[i] = p[i - x];     }     for (int i = 0; i < x; ++i) {       p[i] = nw[i];     }     for (int i = 0; i < n; ++i) {       pos[p[i]] = i;     }   }   int main() {     cin >> n >> s >> t;     for (int i = 0; i < n; ++i) {       c[t[i] -  a ].push_back(i);     }     for (int i = 0; i < n; ++i) {       int ind = s[i] -  a ;       if (c[ind].size() == 0) {         puts( -1 );         return 0;       }       p[i] = c[ind].back();       c[ind].pop_back();       pos[p[i]] = i;     }     for (int i = 0; i < n; ++i) {       add(n - pos[i] - 1);       add(1);       add(n);     }     cout << ans.size() <<   n ;     for (int i : ans) cout << i <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000000;   int main() {     int n, m;     cin >> n >> m;     vector<int> session(n);     vector<vector<int> > s2d(m);     for (int i = 0; i < n; i++) {       cin >> session[i];       if (session[i]) s2d[session[i] - 1].push_back(i);     }     vector<int> price(m);     for (int i = 0; i < m; i++) {       cin >> price[i];     }     int l = 0, r = n, mid, cnt, doned;     vector<int> pos(m);     bool res, ares = false;     while (r - l > 1) {       mid = (l + r) / 2;       for (int i = 0; i < m; i++) {         pos[i] = (int)(upper_bound(s2d[i].begin(), s2d[i].end(), mid) -                        s2d[i].begin()) -                  1;         pos[i] = (pos[i] >= 0 ? s2d[i][pos[i]] : -1);       }       cnt = 0, doned = 0;       res = true;       for (int i = 0; i <= mid && res; i++) {         if (session[i] && pos[session[i] - 1] == i) {           cnt -= price[session[i] - 1];           doned++;         } else           cnt++;         if (cnt < 0) res = false;       }       if (!res || doned < m) {         l = mid;       } else {         r = mid;         ares = true;       }     }     if (ares)       cout << r + 1;     else       cout << -1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int f[500000], g[500000], a[500000];   map<long long, int> mp;   struct bit1 {     int s[500000];     int num;     void add(int x, int z) {       for (int i = x; i <= num; i += (i & -i)) s[i] = max(s[i], z);     }     int ask(int x) {       int tmp = 0;       for (int i = x; i >= 1; i -= (i & -i)) tmp = max(tmp, s[i]);       return tmp;     }     void clear() { memset(s, 0, sizeof(s)); }   } s;   struct bit2 {     int s[500000];     int num;     void add(int x, int z) {       for (int i = x; i >= 1; i -= (i & -i)) s[i] = max(s[i], z);     }     int ask(int x) {       int tmp = 0;       for (int i = x; i <= num; i += (i & -i)) tmp = max(tmp, s[i]);       return tmp;     }     void clear() { memset(s, 0, sizeof(s)); }   } t;   int main() {     scanf( %d , &n);     int mx = 0, lis = 0;     for (int i = 1; i <= n; i++) scanf( %d , &a[i]), mx = max(mx, a[i]);     s.clear();     s.num = mx + 1;     for (int i = 1; i <= n; i++) {       f[i] = s.ask(a[i] - 1) + 1;       s.add(a[i], f[i]);       lis = max(lis, f[i]);     }     t.clear();     t.num = mx + 1;     for (int i = n; i >= 1; i--) {       g[i] = t.ask(a[i] + 1) + 1;       t.add(a[i], g[i]);     }     for (int i = 1; i <= n; i++) {       long long tmp = f[i] * (n + 1) + g[i];       if (mp.find(tmp) == mp.end())         mp[tmp] = 1;       else         mp[tmp]++;     }     for (int i = 1; i <= n; i++) {       long long tmp = f[i] * (n + 1) + g[i];       if (f[i] + g[i] - 1 < lis)         printf( 1 );       else if (mp[tmp] > 1)         printf( 2 );       else         printf( 3 );     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 256;   const char nxt =   n ;   inline void in(string Q) {     Q +=  .in ;     freopen(Q.c_str(),  r , stdin);   }   inline void out(string Q) {     Q +=  .out ;     freopen(Q.c_str(),  w , stdout);   }   inline void open_file(string Q) {     in(Q);     out(Q);   }   int n, a[111][111];   int main() {     if (0) open_file(  );     scanf( %d , &n);     while (n--) {       int x, y, X, Y;       scanf( %d , &x);       scanf( %d , &y);       scanf( %d , &X);       scanf( %d , &Y);       for (int i = x; i <= X; ++i) {         for (int j = y; j <= Y; ++j) {           a[i][j]++;         }       }     }     int ans = 0;     for (int i = 1; i <= 100; ++i) {       for (int j = 1; j <= 100; ++j) {         ans += a[i][j];       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     long long n;     cin >> n;     vector<long long> a(n), b(n);     for (long long i = 0; i < n; ++i) cin >> a[i];     for (long long i = 0; i < n; ++i) cin >> b[i];     if (n == 1) {       if (a[0] == b[0])         cout <<  SMALL n  << 0;       else         cout <<  IMPOSSIBLE ;       return 0;     }     if (n == 2) {       vector<pair<long long, bool>> res;       long long kol = 0;       while (true) {         if (b[0] == 0 || b[1] == 0) {           cout <<  IMPOSSIBLE ;           return 0;         }         if (a == b) break;         if (a[0] == b[1] && a[1] == b[0]) {           res.emplace_back(1, false);           break;         }         if (b[0] == b[1]) {           cout <<  IMPOSSIBLE ;           return 0;         }         if (b[0] > b[1]) {           res.emplace_back(1, false);           swap(b[0], b[1]);         }         if (a[0] == b[0] && a[1] < b[1] && a[1] % b[0] == b[1] % b[0]) {           res.emplace_back((b[1] - a[1]) / b[0], true);           kol += res.back().first;           break;         }         if (a[1] == b[0] && a[0] < b[1] && a[0] % b[0] == b[1] % b[0]) {           res.emplace_back((b[1] - a[0]) / b[0], true);           kol += res.back().first;           res.emplace_back(1, false);           break;         }         kol += b[1] / b[0];         res.emplace_back(b[1] / b[0], true);         b[1] %= b[0];       }       if (kol > 2e5) {         cout <<  BIG n ;         cout << kol;       } else {         cout <<  SMALL n ;         long long flex = 0;         for (auto i : res) flex += i.first;         cout << flex <<   n ;         for (long long i = res.size() - 1; i >= 0; --i) {           for (long long j = 0; j < res[i].first; ++j) {             if (res[i].second)               cout <<  P ;             else               cout <<  R ;           }         }       }       return 0;     }     vector<bool> ans;     long long kol = 0;     while (true) {       if (a == b) break;       reverse(b.begin(), b.end());       if (a == b) {         ans.push_back(false);         break;       }       reverse(b.begin(), b.end());       bool vozr = false, ub = false, r = false;       for (long long i = 1; i < n; ++i) {         if (b[i] > b[i - 1])           vozr = true;         else if (b[i] < b[i - 1])           ub = true;         else           r = true;       }       if (r || (vozr && ub)) {         cout <<  IMPOSSIBLE ;         return 0;       }       vector<long long> c(n);       if (ub) {         ans.push_back(false);         reverse(b.begin(), b.end());       }       c[0] = b[0];       for (long long i = 1; i < n; ++i) {         c[i] = b[i] - b[i - 1];       }       ans.push_back(true);       b = c;       ++kol;     }     if (kol > 2e5) {       cout <<  BIG n  << kol;     } else {       cout <<  SMALL n  << ans.size() <<   n ;       for (long long i = ans.size() - 1; i >= 0; --i) {         if (ans[i])           cout <<  P ;         else           cout <<  R ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int n, p[200009], b[200009], ans, u[200009], sum;   void dfs(int v) {     if (u[v] == 1) {       ans++;       return;     }     u[v] = 1;     dfs(p[v]);   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> p[i];     for (int i = 1; i <= n; i++) cin >> b[i];     for (int i = 1; i <= n; i++) {       if (!u[p[i]]) {         dfs(p[i]);       }     }     if (ans == 1) ans = 0;     for (int i = 1; i <= n; i++) sum += b[i];     if (sum % 2 == 0) ans++;     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int main(int argc, char const *argv[]) {     int h1, a1, c1;     int h2, a2;     cin >> h1 >> a1 >> c1;     cin >> h2 >> a2;     int th1 = h1;     int th2 = h2;     int count = 0;     while (th2 > 0) {       if (th1 > a2 || th2 - a1 <= 0) {         count++;         th2 = th2 - a1;         th1 = th1 - a2;       } else {         count++;         th1 = th1 + c1;         th1 = th1 - a2;       }     }     cout << count <<   n ;     while (h2 > 0) {       if (h1 > a2 || h2 - a1 <= 0) {         h2 = h2 - a1;         h1 = h1 - a2;         cout <<  STRIKE n ;       } else {         h1 = h1 + c1;         h1 = h1 - a2;         cout <<  HEAL n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t, i, j, curr, n;     cin >> curr >> n;     int arr[curr + 1];     int temp;     arr[0] = 1;     int count = curr - 1;     for (i = 1; i <= curr; i++) arr[i] = 0;     for (i = 0; i < n; i++) {       cin >> temp;       if (temp == 1) {         int a, b;         cin >> a >> b;         arr[a] = 1;         arr[b] = 1;         count = count - 2;       } else {         int a;         cin >> a;         arr[a] = 1;         count = count - 1;       }     }     arr[curr] = 1;     int min = 0;     for (i = 1; i < curr; i++) {       if (arr[i] == 0 && arr[i + 1] == 0) {         min += 1;         i++;         continue;       } else if (arr[i] == 0) {         min += 1;       }     }     cout << min <<     << count << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[10001];   int best = 100000000;   int main() {     int n, m, d;     scanf( %d %d %d , &n, &m, &d);     scanf( %d , &a[0]);     int c = a[0] % d;     int lll = n * m;     for (int i = 1; i < lll; i++) {       scanf( %d , &a[i]);       if (a[i] % d != c) {         cout << -1 << endl;         return 0;       }     }     for (int i = 0; i < lll; i++) {       int ans = 0;       int lo = a[i];       for (int j = 0; j < lll; j++) {         ans += abs(a[j] - lo) / d;       }       best = min(ans, best);     }     cout << best << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     pair<int, int> s[n + 1];     for (int a = 0; a < n; a++) {       int x, y;       cin >> x >> y;       s[a] = make_pair(max(x - y, 1), min(x + y, m));     }     sort(s, s + n);     int dp[m + 1];     dp[m] = 0;     for (int a = m - 1; a >= 0; a--) {       bool cover = 0;       int minima = m - a;       for (int b = 0; b < n; b++) {         if (s[b].first <= (a + 1) && s[b].second >= (a + 1)) {           cover = 1;           break;         } else if (s[b].first > (a + 1)) {           minima = min(minima, dp[min(m, s[b].second + s[b].first - (a + 1))] +                                    s[b].first - (a + 1));         }       }       if (cover) {         dp[a] = dp[a + 1];       } else         dp[a] = minima;     }     cout << dp[0];   }
#include <bits/stdc++.h>   using namespace std;   mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());   const int N = 3e5;   int n, a[N + 1], b[N + 1], c[N + 1];   int dp[N + 1];   vector<int> g1[N + 1], g2[N + 1];   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> a[i];     }     vector<pair<int, int> > st;     for (int i = 1; i <= n; ++i) {       while (!st.empty() && st.back().first < a[i]) {         st.pop_back();       }       if (!st.empty()) {         b[i] = st.back().second;       }       st.emplace_back(a[i], i);     }     st.clear();     for (int i = 1; i <= n; ++i) {       while (!st.empty() && st.back().first > a[i]) {         st.pop_back();       }       if (!st.empty()) {         c[i] = st.back().second;       }       st.emplace_back(a[i], i);     }     st.clear();     for (int i = n; i >= 1; --i) {       while (!st.empty() && st.back().first < a[i]) {         st.pop_back();       }       if (!st.empty()) {         g1[st.back().second].emplace_back(i);       }       st.emplace_back(a[i], i);     }     st.clear();     for (int i = n; i >= 1; --i) {       while (!st.empty() && st.back().first > a[i]) {         st.pop_back();       }       if (!st.empty()) {         g2[st.back().second].emplace_back(i);       }       st.emplace_back(a[i], i);     }     dp[1] = 0;     for (int i = 2; i <= n; ++i) {       dp[i] = dp[i - 1] + 1;       if (b[i]) dp[i] = min(dp[i], dp[b[i]] + 1);       if (c[i]) dp[i] = min(dp[i], dp[c[i]] + 1);       for (int x : g1[i]) {         if (x >= b[i]) {           dp[i] = min(dp[i], dp[x] + 1);         }       }       for (int x : g2[i]) {         if (x >= c[i]) {           dp[i] = min(dp[i], dp[x] + 1);         }       }     }     cout << dp[n] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dx[] = {-1, 0, 0, 1};   int dy[] = {0, -1, 1, 0};   int dx1[] = {-1, -1, -1, 0, 0, 0, 1, 1, 1};   int dy1[] = {-1, 0, 1, -1, 0, 1, -1, 0, 1};   const double eps = 1e-9;   const int inf = 2000000000;   const long long int infLL = 9000000000000000000;   const long long int MOD = 1e+7;   const double PI = 3.141592653589793238462643383279;   int main() {     ios_base ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     int ans = 2 * n - m + 1;     for (long long int i = 0; i < m; i++) {       int k;       cin >> k;       for (long long int j = 0; j < k; j++) {         int a;         cin >> a;         if (a == j + 1) ans -= 2;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void __print(int x) { cout << x; }   void __print(long x) { cout << x; }   void __print(long long x) { cout << x; }   void __print(unsigned x) { cout << x; }   void __print(unsigned long x) { cout << x; }   void __print(unsigned long long x) { cout << x; }   void __print(float x) { cout << x; }   void __print(double x) { cout << x; }   void __print(long double x) { cout << x; }   void __print(char x) { cout <<      << x <<     ; }   void __print(const char *x) { cout <<     << x <<    ; }   void __print(const string &x) { cout <<     << x <<    ; }   void __print(bool x) { cout << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     __print(x.first);     cout <<  , ;     __print(x.second);   }   template <typename T>   void __print(const T &x) {     int f = 0;     for (auto &i : x) cout << (f++ ?  ,  :   ), __print(i);   }   void _print() { cout <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cout <<  ,  ;     _print(v...);   }   const int N = 2e5 + 7;   const int MOD = 1e9 + 7;   long long fastpow(long long b, long long p) {     long long temp;     if (p == 0) return 1;     if (p == 1) return b;     temp = fastpow(b, p / 2);     temp = temp * temp % MOD;     if (p & 1) {       temp = temp * b % MOD;     }     return temp;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n, k;     cin >> n >> k;     string s;     cin >> s;     vector<char> v(k);     for (int i = 0; i < k; i++) cin >> v[i];     vector<int> temp(n);     for (int i = 0; i < n; i++) {       if (count(v.begin(), v.end(), s[i]))         temp[i] = 1;       else         temp[i] = 0;     }     long long ans = 0;     for (int i = 0; i < n; i++) {       if (temp[i] == 1) {         long long j = i;         while (j < n && temp[j] == 1) j++;         ans += ((j - i) * (j - i + 1)) / 2;         i = j;       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[101];   int main() {     bool f = false;     int n, counter = 1;     long long ans = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] == 0 && f) counter++;       if (a[i] == 1 && !f)         f = true, ans = 1;       else if (a[i] == 1 && f)         ans *= counter, counter = 1;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int tt;     cin >> tt;     while (tt--) {       int n;       cin >> n;       vector<int> a(n + 1);       for (int i = 1; i <= n; i++) {         cin >> a[i];       }       int lo = 1, hi = n;       while (a[lo] == lo && lo <= n) lo++;       while (a[hi] == hi && hi >= 0) hi--;       if (lo == n + 1 || hi == -1) {         cout << 0 <<   n ;         continue;       }       int ans = 1;       for (int i = lo; i <= hi; i++) {         if (a[i] == i) {           ans++;           break;         }       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 4e5 + 9;   vector<int> ans[N];   vector<char> arr;   int k, n, q, a, hash[N][50], ar[N], s;   char c;   string str;   bool flag;   int main() {     cin >> k;     cin >> str;     int n = str.size();     for (int i = 1; i <= k; i++)       for (int j = 0; j < n; j++) arr.push_back(str[j]);     for (int i = 0; i < arr.size(); i++) ans[arr[i]].push_back(i);     cin >> q;     for (int i = 1; i <= q; i++) {       cin >> a >> c;       arr[ans[c][a - 1]] =  0 ;       ans[c].erase(ans[c].begin() + a - 1);     }     for (int i = 0; i < arr.size(); i++)       if (arr[i] !=  0 ) cout << arr[i];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = (int)1e5 + 7;   const long long INF = (long long)1e18;   int n;   int m;   vector<pair<int, int>> g[N];   long long dist[N];   int par[N];   int t[N];   int root(int x) {     if (t[x] == x) {       return x;     } else {       return t[x] = root(t[x]);     }   }   void unite(int x, int y) { t[root(x)] = root(y); }   struct T {     int x;     long long d;   };   bool operator<(T a, T b) { return a.d > b.d; }   struct edge {     int x;     int y;     long long d;   };   bool operator<(edge a, edge b) { return a.d < b.d; }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = 1; i <= m; i++) {       int x, y, z;       cin >> x >> y >> z;       g[x].push_back({y, z});       g[y].push_back({x, z});     }     for (int i = 1; i <= n; i++) {       t[i] = i;       dist[i] = INF;     }     priority_queue<T> pq;     int cnt;     cin >> cnt;     for (int i = 1; i <= cnt; i++) {       int portal;       cin >> portal;       dist[portal] = 0;       par[portal] = portal;       pq.push({portal, 0});     }     while (!pq.empty()) {       int x = pq.top().x;       long long d = pq.top().d;       pq.pop();       if (d != dist[x]) {         continue;       }       for (auto &it : g[x]) {         int y = it.first;         long long dy = dist[x] + it.second;         if (dy < dist[y]) {           dist[y] = dy;           par[y] = par[x];           pq.push({y, dy});         }       }     }     vector<edge> e;     for (int i = 1; i <= n; i++) {       for (auto &it : g[i]) {         int j = it.first;         int c = it.second;         if (par[i] != par[j]) {           e.push_back({par[i], par[j], c + dist[i] + dist[j]});         }       }     }     long long sol = dist[1];     sort(e.begin(), e.end());     for (auto &it : e) {       if (root(it.x) != root(it.y)) {         unite(it.x, it.y);         sol += it.d;       }     }     cout << sol <<   n ;     return 0;   }
#include <bits/stdc++.h>   const long long mod = 1e9 + 9;   using namespace std;   const long long N = 105;   long long vis[N], l[N], who[N], n, m;   void fail() {     cout <<  -1 n ;     exit(0);   }   int32_t main() {     cin >> n >> m;     for (long long i = 1; i <= m; i++) cin >> l[i];     long long cur = l[1];     for (long long i = 2; i <= m; i++) {       long long dif = (l[i] - cur);       if (dif <= 0) dif += n;       if (vis[dif] && vis[dif] != cur) fail();       who[cur] = dif;       vis[dif] = cur;       cur = l[i];     }     long long cnt = 0;     set<long long> st;     for (long long i = 1; i <= n; i++) {       if (!vis[i]) {         st.insert(i);       }       if (!who[i]) cnt++;     }     auto it = st.begin();     if (cnt > st.size()) fail();     for (long long i = 1; i <= n; i++) {       if (who[i])         cout << who[i];       else {         cout << *it;         it++;       }       cout <<    ;     }     return 0;   }