malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     vector<int> s(n, 0);     s[n - 1] = a[n - 1];     for (int i = n - 2; i >= 0; i--) s[i] = max(a[i], s[i + 1]);     for (int i = 0; i < n - 1; i++) cout << max(0, s[i + 1] - a[i] + 1) <<    ;     cout << 0;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct pr {     int a, b, n, x;     pr(int a, int b, int n) : a(a), b(b), n(n) {}     pr() : a(0), b(0), n(-1) {}   };   int n, m;   vector<pr> a, b;   void connect(int x1, int& x2, int& y2) {     if ((x2 != -1 && x2 != x1) || (y2 != -1 && y2 != x1)) {       cout << -1;       exit(0);     }     x2 = y2 = x1;   }   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       int x, y;       cin >> x >> y;       a.push_back(pr(x, y, -1));     }     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       b.push_back(pr(x, y, -1));     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (a[i].a == b[j].a && a[i].b != b[j].b)           connect(a[i].a, a[i].n, b[j].n);         else if (a[i].b == b[j].b && a[i].a != b[j].a)           connect(a[i].b, a[i].n, b[j].n);         else if (a[i].a == b[j].b && a[i].b != b[j].a)           connect(a[i].a, a[i].n, b[j].n);         else if (a[i].b == b[j].a && a[i].a != b[j].b)           connect(a[i].b, a[i].n, b[j].n);       }     }     int ans = -1;     for (int i = 0; i < n; i++) {       if (a[i].n != -1) {         if (ans == -1 || ans == a[i].n)           ans = a[i].n;         else {           cout << 0;           return 0;         }       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 70, MAXM = 100, MOD = 1e9 + 7, INF = 1e9;   char c[] = { c ,  o ,  d ,  e ,  f ,  o ,  r ,  c ,  e ,  s };   void solve() {     long long n;     cin >> n;     long long x = 0, x1 = 0;     while (pow(x + 1, 10) <= n) x++;     while (pow(x, 10 - x1) * pow(x + 1, x1) < n) x1++;     for (int i = 0; i < 10; i++) {       if (i < x1)         for (int j = 0; j <= x; j++) cout << c[i];       else         for (int j = 0; j < x; j++) cout << c[i];     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     solve();   }
#include <bits/stdc++.h>   using namespace std;   const double SUCK = 999999999999999999.99;   const int MX = 51 * 101;   int n;   int r;   int f[55];   int s[55];   int p[55];   double cp[55];   double dp[55][MX];   bool isOk(double det) {     for (int i = 0; i <= r; i++) {       dp[n][i] = 0;     }     for (int i = n - 1; i >= 0; i--) {       for (int j = 0; j <= r; j++) {         dp[i][j] = det;         double togo = 0;         if (j + f[i] > r) {           togo = det;         } else {           togo += cp[i] * (f[i] + dp[i + 1][j + f[i]]);           if (j + s[i] > r)             togo += (1 - cp[i]) * (s[i] + det);           else             togo += (1 - cp[i]) * (s[i] + dp[i + 1][j + s[i]]);         }         dp[i][j] = min(det, togo);       }     }     if (dp[0][0] >= det) return false;     return true;   }   const double eps = 0.000000001;   time_t bg;   double getTime() {     time_t en = clock();     double ret = (double)(en - bg) / CLOCKS_PER_SEC;     return ret;   }   double bsearch(double l, double r) {     double m = (l + r) / 2;     if (r - l < eps) return m;     if (getTime() >= 1.95) return m;     if (isOk(m))       return bsearch(l, m);     else       return bsearch(m, r);   }   int main() {     bg = clock();     scanf( %d%d , &n, &r);     for (int i = 0; i < n; i++) scanf( %d%d%d , &f[i], &s[i], &p[i]);     for (int i = 0; i < n; i++) cp[i] = 0.010000 * p[i];     double ans = bsearch(n, 50000000);     printf( %.12f , ans);     return 0;   }
#include <bits/stdc++.h>   const int INF = 0x3f3f3f3f;   const std::string str =  ATGC ;   int main() {     int n, m;     std::vector<std::string> s;     std::vector<std::string> tmp;     std::vector<std::string> ans;     int min_ans = INF, pos;     std::cin >> n >> m;     for (int i = 0; i < n; ++i) {       std::string st;       std::cin >> st;       s.push_back(st);     }     for (int c1 = 0; c1 < 4; ++c1)       for (int c2 = c1 + 1; c2 < 4; ++c2) {         std::string stri;         std::set<int> st;         for (int i = 0; i < 4; ++i) st.insert(i);         st.erase(c1);         st.erase(c2);         auto it = st.begin();         stri.push_back(str[c1]);         stri.push_back(str[c2]);         stri.push_back(str[*(it++)]);         stri.push_back(str[*it]);         pos = 0;         tmp.clear();         for (int i = 0; i < n; ++i) {           tmp.push_back(  );           int bit = (i & 1) << 1;           int cnt1 = 0, cnt2 = 0;           for (int j = 0; j < m; ++j) {             if (s[i][j] != stri[bit + (j & 1)]) ++cnt1;             if (s[i][j] != stri[bit + ((j & 1) ^ 1)]) ++cnt2;           }           if (cnt1 < cnt2)             for (int j = 0; j < m; ++j) tmp[i].push_back(stri[bit + (j & 1)]);           else             for (int j = 0; j < m; ++j)               tmp[i].push_back(stri[bit + ((j & 1) ^ 1)]);           pos += std::min(cnt1, cnt2);         }         if (pos < min_ans) {           ans = tmp;           min_ans = pos;         }         pos = 0;         tmp.clear();         for (int i = 0; i < n; ++i) tmp.push_back(  );         for (int j = 0; j < m; ++j) {           int bit = (j & 1) << 1;           int cnt1 = 0, cnt2 = 0;           for (int i = 0; i < n; ++i) {             if (s[i][j] != stri[bit + (i & 1)]) ++cnt1;             if (s[i][j] != stri[bit + ((i & 1) ^ 1)]) ++cnt2;           }           if (cnt1 < cnt2)             for (int i = 0; i < n; ++i) tmp[i].push_back(stri[bit + (i & 1)]);           else             for (int i = 0; i < n; ++i)               tmp[i].push_back(stri[bit + ((i & 1) ^ 1)]);           pos += std::min(cnt1, cnt2);         }         if (pos < min_ans) {           ans = tmp;           min_ans = pos;         }       }     for (int i = 0; i < n; ++i) std::cout << ans[i] << std::endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long base = 233;   const long long ff = 4e5 + 1;   const long long mod = 1e9 + 7;   const long long inf = 1e17 + 1;   long long read() {     long long x;     scanf( %lld , &x);     return x;   }   inline long long Read() {     long long x = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = (x << 3) + (x << 1) + ch -  0 ;       ch = getchar();     }     return x * f;   }   long long a, b, c, d;   long long my_max(long long x, long long y) { return (x > y) ? x : y; }   void init() {     long long ans = 0;     a = Read(), b = Read(), c = Read(), d = Read();     for (long long i = a; i <= b; ++i) {       long long st = my_max(min(i + b - c, d), 0LL);       long long ed = my_max(min(i + c - 1, d) - c + 1, 0LL);       long long q = max(ed - st + 1, 0LL);       ans += (st + ed) * q / 2;       if (i + c - 1 > d)         ans += my_max(min((i + c - 1) - d, c - b + 1), 0LL) * (d - c + 1);     }     cout << ans;   }   signed main() { init(); }
#include <bits/stdc++.h>   int main() {     int n, m;     scanf( %d%d , &n, &m);     if (n % 2 != 0) {       printf( %d , n);     } else {       int a[n][m];       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           scanf( %d , &a[i][j]);         }       }       bool isSymmetric = true;       while (isSymmetric == true && n % 2 == 0) {         for (int i = 0; i < n / 2; i++) {           for (int j = 0; j < m; j++) {             if (a[i][j] != a[n - 1 - i][j]) {               isSymmetric = false;               break;             }           }         }         if (isSymmetric) {           n = n / 2;         }       }       printf( %d , n);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     vector<int> questions(k);     vector<int> previsited(n + 1, 0);     vector<int> posvisited(n + 1, 0);     vector<int> vis;     int tot_non = n;     for (int i = 0; i < k; i++) {       cin >> questions[i];       if (!previsited[questions[i]]) {         tot_non--;         vis.push_back(questions[i]);         previsited[questions[i]] = i + 1;       }       posvisited[questions[i]] = i + 1;     }     int ans = tot_non * 3;     if (previsited[1] == 0) ans--;     if (previsited[n] == 0) ans--;     for (int i = 0; i < vis.size(); i++) {       if (vis[i] <= n - 1 && previsited[vis[i]] > posvisited[vis[i] + 1]) {         ans++;       }       if (vis[i] >= 2 && previsited[vis[i]] > posvisited[vis[i] - 1]) {         ans++;       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, m;     cin >> n >> m;     int a[n + 1];     for (int i = 1; i <= n; ++i) cin >> a[i];     int ans = 0;     for (int i = 0; i < m; ++i) {       int u, v;       cin >> u >> v;       ans += min(a[u], a[v]);     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a[101], b[101] = {0}, c[101] = {0}, n, m, i, j, k;     scanf( %d%d , &n, &m);     for (i = 1; i <= m; i++) {       for (j = 1; j <= n; j++) {         scanf( %d , &a[j]);         c[j] += a[j];       }       k = 0;       for (j = 1; j <= n; j++)         if (k < a[j]) k = a[j];       for (j = 1; j <= n; j++)         if (a[j] == k) {           b[j]++;           break;         }     }     j = 1;     k = b[1];     for (i = 2; i <= n; i++)       if (k < b[i]) {         k = b[i];         j = i;       }     printf( %d n , j);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = (int)1e9;   const double INF = 1e12, EPS = 1e-9;   int n;   pair<int, int> p[5000];   int main() {     cin >> n;     for (int i = 0; i < (int)n; i++) {       int a, b;       cin >> a >> b;       p[i] = pair<int, int>(a, b);     }     sort(p, p + n);     int mn = 0;     for (int i = 0; i < (int)n; i++) {       if (p[i].second >= mn)         mn = p[i].second;       else         mn = p[i].first;     }     cout << mn << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string str;     cin >> str;     stack<char> s;     map<char, char> type = {{ ( ,  ) }, { { ,  } }, { < ,  > }, { [ ,  ] }};     int ans = 0;     for (auto it : str) {       if (it ==  {  || it ==  (  || it ==  <  || it ==  [ ) {         s.push(it);       } else {         if (s.empty()) {           cout <<  Impossible n ;           return 0;         } else {           if (type[s.top()] != it) {             ans += 1;           }           s.pop();         }       }     }     if (s.empty()) {       cout << ans <<   n ;       return 0;     }     cout <<  Impossible n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = (int)1e5 + 10;   bool isp[maxn];   int _prime[maxn], lp = 0;   int _minCost[maxn];   void InitPrime() {     isp[0] = isp[1] = true;     for (int i = 4; i < maxn; i += 2) isp[i] = true;     for (int i = 3; i * i < maxn; i += 2)       if (!isp[i])         for (int j = i * i; j < maxn; j += i) isp[j] = true;     _prime[lp++] = 2;     for (int i = 3; i < maxn; i += 2)       if (!isp[i]) _prime[lp++] = i;   }   bool IsPrime(long long n) {     if (n < maxn) return !isp[n];     for (int i = 0; i < lp && (long long)_prime[i] * _prime[i] <= n; ++i) {       if (n % _prime[i] == 0) return false;     }     return true;   }   int minCost(long long n) {     if (IsPrime(n)) return 1;     for (int i = 0; i < lp && _prime[i] + 2 <= n; ++i) {       if (n - _prime[i] >= 2 && IsPrime(n - _prime[i])) return 2;     }     return 3;   }   int main() {     InitPrime();     long long n;     cin >> n;     cout << minCost(n) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = INT_MAX;   const long long INFL = LLONG_MAX;   const long double pi = acos(-1);   int N;   int A[300100];   long long S[300100];   int shouldCut[300100];   map<int, vector<int> > mymap;   vector<int> v;   int main() {     ios_base::sync_with_stdio(0);     cout.precision(15);     cout << fixed;     cout.tie(0);     cin.tie(0);     cin >> N;     for (int(i) = 1, j123 = N; (i) <= j123; (i)++) {       cin >> A[i];       S[i] = max(0, A[i]);       S[i] += S[i - 1];       mymap[A[i]].push_back(i);       v.push_back(A[i]);     }     sort(v.begin(), v.end());     v.erase(unique(v.begin(), v.end()), v.end());     int mx = -2e9;     long long bestTot = -2e10;     int bestFirst = -1;     int bestLast = -1;     for (int(i) = 0, j123 = int(v.size()); (i) < j123; (i)++) {       if (int(mymap[v[i]].size()) > 1) {         sort(mymap[v[i]].begin(), mymap[v[i]].end());         int curfirst = mymap[v[i]].front();         int curlast = mymap[v[i]].back();         long long score = S[curlast - 1] - S[curfirst];         score += A[curfirst];         score += A[curlast];         if (score > bestTot) {           bestTot = score;           bestFirst = curfirst;           bestLast = curlast;         }       }     }     for (int i = 1; i < bestFirst; i++) shouldCut[i] = 1;     for (int i = N; i > bestLast; i--) shouldCut[i] = 1;     for (int i = bestFirst + 1; i <= bestLast - 1; i++)       if (A[i] < 0) shouldCut[i] = 1;     long long toteth = 0;     vector<int> vec;     for (int(i) = 1, j123 = N; (i) <= j123; (i)++) {       if (shouldCut[i])         vec.push_back(i);       else         toteth += A[i];     }     cout << toteth <<     << int(vec.size()) <<   n ;     for (int(i) = 0, j123 = int(vec.size()); (i) < j123; (i)++)       cout << vec[i] << (i + 1 < int(vec.size()) ?     :   n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1999999999;   const double pi = acos(-1.0);   const double eps = 1e-9;   char gc() {     char c;     while (isspace(c = getchar()))       ;     return c;   }   int gs(char* s) {     if (!fgets(s, 9999999, stdin)) return -1;     int l = strlen(s);     while (l && isspace(s[l - 1])) s[--l] = 0;     return l;   }   int main() {     ios::sync_with_stdio(false);     cout << fixed << setprecision(15);     int n;     cin >> n;     vector<int> v;     for (int i = 0, _i = (n); i < (_i); i++) {       int t;       cin >> t;       v.push_back(t);     }     sort((v).begin(), (v).end());     v.erase(unique((v).begin(), (v).end()), v.end());     for (int i = 0, _i = (((int)(v).size()) - 1); i < (_i); i++) {       if (v[i] * 2 > v[i + 1]) {         cout <<  YES ;         return 0;       }     }     cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 24;   int n, m, a[N][N], f[1 << 20];   char str[N][N];   void work() {     int i, j, k, x;     scanf( %d%d , &n, &m);     for (i = 0; i < n; ++i) scanf( %s , str[i]);     for (i = 0; i < n; ++i)       for (j = 0; j < m; ++j) scanf( %d , &a[i][j]);     for (i = 1; i < 1 << n; ++i) {       x = __builtin_ctz(i & -i);       f[i] = 1 << 30;       for (j = 0; j < m; ++j) {         f[i] = min(f[i], f[i ^ (1 << x)] + a[x][j]);         int sum = 0, mx = 0, mask = 0;         for (k = 0; k < n; ++k) {           if (str[k][j] == str[x][j]) {             sum += a[k][j];             mx = max(mx, a[k][j]);             mask |= 1 << k;           }         }         f[i] = min(f[i], f[i & (i ^ mask)] + sum - mx);       }     }     cout << f[(1 << n) - 1] << endl;   }   int main() {     work();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int pw(long long int a, long long int b, long long int mod) {     if (!b) return 1;     if (b & 1) return a * pw(a * a % mod, b / 2, mod) % mod;     return pw(a * a % mod, b / 2, mod) % mod;   }   const long long int MAXN = 1e5 + 10;   const long long int MAXK = 1e4 + 10;   const long long int INF = 8e18;   const long long int MOD = 1e9 + 7;   long long int h, n, m, k, dist[MAXK], mark[MAXK], seen[MAXN];   pair<long long int, long long int> A[MAXN];   vector<pair<long long int, long long int>> adj[MAXK];   set<pair<long long int, long long int>> st;   priority_queue<pair<long long int, long long int>,                  vector<pair<long long int, long long int>>,                  greater<pair<long long int, long long int>>>       pq;   void Dijk() {     fill(dist, dist + MAXK, INF);     fill(mark, mark + MAXK, 0);     dist[0] = 0;     pq.push({0, 0});     while (!pq.empty()) {       long long int u = pq.top().second;       pq.pop();       if (mark[u]) continue;       mark[u] = 1;       for (pair<long long int, long long int>& e : adj[u]) {         if (dist[e.first] <= dist[u] + e.second) continue;         dist[e.first] = dist[u] + e.second;         pq.push({dist[e.first], e.first});       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cin >> h >> n >> m >> k;     for (long long int i = 1; i <= n; i++) {       cin >> A[i].first >> A[i].second;       A[i].first--;       if (A[i].first % k == 0) {         st.insert({A[i].second, -i});         seen[i] = 1;       }     }     Dijk();     while (m--) {       long long int type;       cin >> type;       if (type == 1) {         long long int x;         cin >> x;         for (long long int i = 0; i < k; i++) {           adj[i].push_back({(i + x) % k, x});         }         Dijk();         for (long long int i = 1; i <= n; i++) {           if (!seen[i] && dist[A[i].first % k] <= A[i].first) {             seen[i] = 1;             st.insert({A[i].second, -i});           }         }       }       if (type == 2) {         long long int x, val;         cin >> x >> val;         if (seen[x]) st.erase({A[x].second, -x});         A[x].second -= val;         if (seen[x]) st.insert({A[x].second, -x});       }       if (type == 3) {         if (st.empty()) {           cout << 0 <<   n ;           continue;         }         auto it = st.end();         it--;         cout << (*it).first <<   n ;         st.erase(it);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void read(T &x) {     cin >> x;   }   template <typename T, typename T0>   void read(T &x, T0 &y) {     cin >> x >> y;   }   template <typename T, typename T0, typename T1>   void read(T &x, T0 &y, T1 &z) {     cin >> x >> y >> z;   }   bool isPowerOfTwo(int x) { return x && (!(x & (x - 1))); }   int digits(int n) {     int x = floor(log10(n)) + 1;     return x;   }   long long int fact(long long int n) {     if (n == 0) return 1;     return n * fact(n - 1);   }   bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {     return (a.second < b.second);   }   vector<bool> sieve(1000000, true);   void sieve_er() {     sieve[0] = false;     sieve[1] = false;     for (long long int i = 2; i * i <= 1000000; i++) {       if (sieve[i] == true) {         for (long long int j = i * i; j < 1000000; j += i) sieve[j] = false;       }     }   }   vector<long long int> vec;   void divisors(long long int n) {     for (long long int i = 1; i <= sqrt(n); i++) {       if (n % i == 0) {         if (n / i == i)           vec.push_back(i);         else {           vec.push_back(i);           vec.push_back(n / i);         }       }     }   }   long long int total_divisors(long long int n) {     long long int c = 0;     for (long long int i = 1; i <= sqrt(n); i++) {       if (n % i == 0) {         if (n / i == i)           c = c + 1;         else           c = c + 2;       }     }     return c;   }   long long int nCr(long long int n, long long int r) {     long long int ans = 1;     for (long long int i = 0; i < r; i++) {       ans *= n - i;       ans /= i + 1;     }     return ans;   }   long long int power_m(long long int a, long long int b,                         long long int m = 1000000007) {     a %= m;     long long int res = 1;     while (b > 0) {       if (b & 1) res = res * a % m;       a = a * a % m;       b >>= 1;     }     return res;   }   long long int power(long long int a, long long int b) {     long long int res = 1;     while (b > 0) {       if (b & 1) res = res * a;       a = a * a;       b >>= 1;     }     return res;   }   long long int strTo(string s) {     stringstream tmp(s);     long long int x = 0;     tmp >> x;     return x;   }   string NoTo(long long int n) {     ostringstream str1;     str1 << n;     string ans = str1.str();     return ans;   }   void start() {}   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     cin >> t;     while (t--) {       long long int x1, y1, x2, y2;       cin >> x1 >> y1 >> x2 >> y2;       int ans = 0;       if (x1 == x2)         ans = abs(y1 - y2);       else if (y1 == y2)         ans = abs(x1 - x2);       else {         ans += abs(x1 - x2);         ans += 2;         ans += abs(y1 - y2);       }       cout << ans << endl;     }     cerr <<  Time :   << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC          <<  ms n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, p, k;     long long a, ans = 0;     map<long long, long long> mp;     scanf( %d %d %d , &n, &p, &k);     for (int i = 0; i < n; i++) {       scanf( %lld , &a);       ans += mp[((((a * a) % p) * ((a * a) % p)) % p - (k * a) % p + p) % p]++;     }     printf( %lld , ans);   }
#include <bits/stdc++.h>   int abss(int a);   int main() {     int size;     scanf( %d , &size);     int colunm[size + 10][2];     int i;     int left = 0, right = 0;     for (i = 1; i <= size; i++) {       scanf( %d %d , &colunm[i][0], &colunm[i][1]);       left += colunm[i][0];       right += colunm[i][1];     }     int abs = abss(left - right);     int max = 0, temp, flag = 0;     for (i = 1; i <= size; i++) {       int tLeft = left;       int tRight = right;       tLeft = tLeft - colunm[i][0] + colunm[i][1];       tRight = tRight - colunm[i][1] + colunm[i][0];       int tAbs = abss(tLeft - tRight);       temp = tAbs - abs;       if (temp > max) {         max = temp;         flag = i;       }     }     printf( %d , flag);     return 0;   }   int abss(int a) {     if (a > 0)       return a;     else       return -a;   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   int num[500005];   long long dp[500005];   int cnt[500005];   bool ok(int cost) {     dp[0] = dp[1] = cnt[0] = cnt[1] = 0;     for (int i = (2); i <= (n); i += (1)) {       dp[i] = dp[i - 1];       cnt[i] = cnt[i - 1];       long long v = dp[i - 2] + num[i] - num[i - 1] - cost;       int c = cnt[i - 2] + 1;       if (v < dp[i] || v == dp[i] && c > cnt[i]) dp[i] = v, cnt[i] = c;     }     return (cnt[n] >= k);   }   int main() {     scanf( %d %d , &k, &n);     for (int i = (1); i <= (n); i += (1)) scanf( %d , &num[i]);     sort(num + 1, num + n + 1);     int l = 0, r = 1000000000;     while (l <= r) {       int m = (l + r) >> 1;       if (ok(m))         r = m - 1;       else         l = m + 1;     }     ok(l);     printf( %lld n , dp[n] + 1LL * l * k);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 8;   const int dx[9] = {-1, -1, -1, 0, 0, 0, 1, 1, 1};   const int dy[9] = {-1, 0, 1, -1, 0, 1, -1, 0, 1};   string a[N];   int v[105][N][N], f[105][N][N];   int main() {     for (int i = 0; i < N; ++i) cin >> a[i];     memset(v, 0, sizeof(v));     for (int i = 0; i < N; ++i)       for (int j = 0; j < N; ++j)         if (a[i][j] ==  S )           for (int k = i + 1; k <= N; ++k)             v[k - i][k][j] = v[k - i][k - 1][j] = 1;     memset(f, 0, sizeof(f));     f[0][7][0] = 1;     for (int t = 1; t <= 100; ++t)       for (int x = 0; x < N; ++x)         for (int y = 0; y < N; ++y)           if (f[t - 1][x][y])             for (int dire = 0; dire < 9; ++dire) {               int xx = x + dx[dire];               int yy = y + dy[dire];               if (xx < 0 || xx >= N) continue;               if (yy < 0 || yy >= N) continue;               if (v[t][xx][yy]) continue;               f[t][xx][yy] = 1;             }     bool flag = 0;     for (int t = 1; t <= 100; ++t) flag |= f[t][0][7];     if (flag)       cout <<  WIN ;     else       cout <<  LOSE ;     cout << endl;     return 0;   }