malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int inf = 987654321;   const long long int INF = 123456789987654321;   int N;   vector<int> arr, chk, chk2;   bool f(int l, int r) {     for (int i = 0; i < min(l, N - r - 1); i++) {       if (arr[i] != arr[N - i - 1]) return false;     }     chk = vector<int>(N, 0);     for (int i = min(l, N - r - 1); i <= max(r, N - l - 1); i++) {       chk[arr[i]]++;     }     chk2 = vector<int>(N, 0);     int len = max(r, N - l - 1) - min(l, N - r - 1) + 1;     if (len < 2 * (r - l + 1)) {       for (int i = min(l, N - r - 1); i <= max(r, N - l - 1); i++) {         if (i < l || r < i) {           chk2[arr[i]]++;           if (chk2[arr[i]] > chk[arr[i]] / 2) return false;         }       }     } else {       for (int i = min(l, N - r - 1); i < min(l, N - r - 1) + (r - l + 1); i++) {         chk2[arr[i]]++;       }       for (int i = min(l, N - r - 1); i < min(l, N - r - 1) + (r - l + 1); i++) {         chk2[arr[N - 1 - i]]--;       }       for (int i = 0; i < N; i++) {         if (chk2[i]) return false;       }       for (int i = min(l, N - r - 1) + (r - l + 1);            i <= max(r, N - l - 1) - (r - l + 1); i++) {         if (arr[i] != arr[N - 1 - i]) return false;       }     }     return true;   }   long long int ans = 0;   int main() {     scanf( %d , &N);     arr.resize(N);     chk = vector<int>(N, 0);     for (int i = 0; i < N; i++) {       scanf( %d , &arr[i]);       chk[--arr[i]]++;     }     if (N == 1) {       printf( 1 );       return 0;     }     int oddcnt = 0;     for (int i = 0; i < N; i++) {       if (chk[i] % 2) oddcnt++;     }     if (oddcnt > 1) {       printf( 0 );       return 0;     }     int s = 0, e = N - 1;     int idx;     while (s <= e) {       int m = (s + e) >> 1;       if (f(0, m)) {         idx = m;         e = m - 1;       } else         s = m + 1;     }     s = 0, e = N - 1;     int idx2;     while (s <= e) {       int m = (s + e) >> 1;       if (f(m, N - 1)) {         idx2 = m;         s = m + 1;       } else         e = m - 1;     }     int len = 0;     for (int i = 0; i < N / 2; i++) {       if (arr[i] != arr[N - 1 - i]) break;       len++;     }     if (len == N / 2) {       printf( %I64d , (long long int)N * (N + 1) / 2);       return 0;     }     long long int ans = len * len;     if (idx < N - len) ans += (len + 1) * (N - len - idx);     if (len <= idx2) ans += (len + 1) * (idx2 - len + 1);     if (idx < N - len && len <= idx2) ans--;     printf( %I64d , ans);   }
#include <bits/stdc++.h>   using namespace std;   char s[200010];   int g[200010][30];   int main() {     int i, j, k;     int n, t, m;     cin >> t;     while (t--) {       cin >> n >> m;       cin >> s + 1;       int ans[30] = {0};       for (i = 1; i <= n; i++) {         for (j = 0; j < 26; j++) {           g[i][j] = g[i - 1][j];         }         g[i][s[i] -  a ]++;       }       for (i = 1; i <= m; i++) {         int x;         cin >> x;         for (j = 0; j < 26; j++) {           ans[j] += g[x][j];         }       }       for (i = 0; i < 26; i++) ans[i] += g[n][i];       for (i = 0; i < 26; i++) {         if (i) printf(   );         printf( %d , ans[i]);       }       puts(  );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int arr;     int a = 0, b = 0, i, j, k;     for (i = 0; i < n; i++) {       cin >> arr;       if (arr >= 0) {         a += arr;       } else {         b += arr;       }     }     cout << a - b << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, d;   long long x;   int a[100005], b[100005];   int a_index[100005], q[100005];   long long getNextX() {     x = (x * 37 + 10007) % 1000000007;     return x;   }   void initAB() {     for (int i = 0; i < n; i = i + 1) {       a[i] = i + 1;     }     for (int i = 0; i < n; i = i + 1) {       swap(a[i], a[getNextX() % (i + 1)]);     }     for (int i = 0; i < n; i = i + 1) {       if (i < d)         b[i] = 1;       else         b[i] = 0;     }     for (int i = 0; i < n; i = i + 1) {       swap(b[i], b[getNextX() % (i + 1)]);     }   }   int main() {     cin >> n >> d >> x;     initAB();     for (int i = 0; i < n; i++) {       a_index[a[i]] = i;     }     int s = 30;     for (int i = 0; i < n; i++)       if (b[i]) q[++q[0]] = i;     for (int i = 0; i < n; i++) {       int j;       for (j = n; j >= n - s; j--)         if (j > 0 && i >= a_index[j] && b[i - a_index[j]]) {           printf( %d n , j);           break;         }       if (j < n - s) {         int ma = 0;         for (j = 1; j <= q[0] && q[j] <= i; j++) ma = max(ma, a[i - q[j]]);         printf( %d n , ma);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, t, p[105], ans, x = 1, c;   pair<long long, long long> a[105];   int cmp(pair<long long, long long> a, pair<long long, long long> b) {     return a.first * a.second < b.first * b.second;   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i].second >> a[i].first;     cin >> t;     for (int i = 1; i <= t; i++) cin >> p[i];     for (int i = t; i >= 1; i--) p[i] -= p[i - 1];     sort(a + 1, a + 1 + n);     p[t + 1] = 1000000000000000009;     for (int i = 1; i <= n; i++)       while (a[i].second) {         ans += min(a[i].second, p[x]) * x * a[i].first;         long long r = min(a[i].second, p[x]);         a[i].second -= r;         p[x] -= r;         if (!p[x]) x++;       }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool solve() {     char s[500];     if (scanf( %s , s) == EOF) return false;     int in = 0, out = 0;     for (int i = 0; s[i]; ++i) {       if (s[i] ==  + ) {         if (out) {           out--;           in++;         } else {           in++;         }       } else {         if (in) {           in--;           out++;         } else {           out++;         }       }     }     printf( %d n , in + out);     return true;   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>      using namespace std;      typedef long long ll;   typedef long double ld;   #define mems(p) memset(p,-1,sizeof(p))   #define pb push_back   #define eb emplace_back   #define nl   n    #define sz(x) (int)(x).size()   #define all(x) x.begin(), x.end()   #define allr(x) x.rbegin(), x.rend()      using pi = pair<int,int>;   using pl = pair<ll,ll>;   using vi = vector<int>;   using vl = vector<ll>;   using vb = vector<bool>;   using vd = vector<double>;   using vc = vector<char>;   using vpi = vector<pi>;   using vpl = vector<pl>;   using vvi = vector<vector<int>>;   using vvl = vector<vector<ll>>;   using vvb = vector<vector<bool>>;   using vvd = vector<vector<double>>;   using vvc = vector<vector<char>>;   using vvpi = vector<vector<pi>>;   using vvpl = vector<vector<pl>>;   using vvvi = vector<vector<vector<int>>>;   using vvvl = vector<vector<vector<ll>>>;   using vvvb = vector<vector<vector<bool>>>;   using vvvd = vector<vector<vector<double>>>;   using vvvc = vector<vector<vector<char>>>;   using vvvpi = vector<vector<vector<pi>>>;   using vvvpl = vector<vector<vector<pl>>>;      const int mxN = 8e5 + 100;   const ll MOD = 1e9 + 7;      void fast()   {ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}      ll gcd(ll a, ll b) {       return b ? gcd(b, a%b) : a;   }      vl factorial;      ll expo(ll x, ll exp, ll mod = MOD) {       if (exp <= 0) return 1;       ll tmp = (x*x) % mod;       if (exp%2) {           return (expo(tmp, exp/2, mod) * x) % mod;       }       return (expo(tmp, exp/2, mod)) % mod;   }      ll choice(ll n, ll r, ll mod = MOD) {       if (n < r) return 0;       ll numer = factorial[n];       ll denom = (factorial[r] * factorial[n-r]) % mod;       return numer * expo(denom, mod - 2, mod) % mod;   }      ll phi(ll n) {       ll result = n;       for (ll i = 2; i * i <= n; i++) {           if (n % i == 0) {               while (n % i == 0)                   n /= i;               result -= result / i;           }       }       if (n > 1)           result -= result / n;       return result;   }      ll store[5001][5001];   ll a[5001];   int n;      ll dp(int x, int k) {       if (k == 0) return 1;       if (store[x][k] != -1) return store[x][k];       ll res = 0;       if (x > 0) res += dp(x-1,k-1);       if (x < n - 1) res += dp(x+1,k-1);       if (res >= MOD) res -= MOD;       return store[x][k] = res;   }      int main() {       fast();       int k, q;       cin >> n >> k >> q;       for (int i = 0; i < n; ++i)       {           cin >> a[i];       }       mems(store);       ll ans = 0;       vl sum(n, 0);       for (int i = 0; i < n; ++i)       {           for (int j = 0; j <= k; ++j)           {               sum[i] += dp(i,j)*dp(i,k-j);               sum[i] %= MOD;           }           ans += sum[i]*a[i];           ans %= MOD;       }       //cout <<  init   << ans << nl;          int idx;       ll x;       for (int i = 0; i < q; ++i)       {           cin >> idx >> x;           --idx;           ll chng = x - a[idx];           if (chng < 0) chng += MOD;           ans += chng*sum[idx];           ans %= MOD;           cout << ans << nl;           a[idx] = x;       }   }
#include <bits/stdc++.h>   using namespace std;   int dp[1010][1010][11][2];   int main() {     ios_base::sync_with_stdio(0);     int n, m, k;     cin >> n >> m >> k;     int kk = k;     string a, b;     cin >> a >> b;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         if (a[i - 1] == b[j - 1]) {           for (int k = 1; k <= kk; ++k) {             dp[i][j][k][0] =                 max(dp[i - 1][j - 1][k][0], dp[i - 1][j - 1][k - 1][1]) + 1;           }         }         for (int k = 1; k <= kk; ++k) {           dp[i][j][k][1] = max(max(dp[i - 1][j - 1][k][1], dp[i - 1][j][k][1]),                                max(dp[i][j - 1][k][1], dp[i][j][k][0]));         }       }     }     int ans = 0;     for (int i = 1; i <= k; ++i) {       ans = max(ans, dp[n][m][i][1]);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int a[300], ans[500][2], tot, v[300];   void sl(int p, int x) {     if (p == x || x == 0) return;     if (a[x] == 0 || a[x] == x) {       ans[tot][0] = p, ans[tot][1] = x;       a[x] = x;       a[p] = 0;       tot++;       return;     }     if (v[x]) {       ans[tot][0] = p, ans[tot][1] = n;       a[p] = 0;       a[n] = x;       tot++;       return;     }     v[p] = 1;     sl(x, a[x]);     ans[tot][0] = p, ans[tot][1] = x;     a[x] = x;     a[p] = 0;     tot++;     v[p] = 0;   }   int main() {     scanf( %d%d , &n, &m);     int p = 0, t, sum = 0;     for (int i = 0; i < m; i++) {       scanf( %d , &t);       sum += t;       while (t--) {         int x;         scanf( %d , &x);         a[x] = ++p;       }     }     for (int i = n; i > 0; i--) {       sl(i, a[i]);       sl(n, a[n]);     }     printf( %d n , tot);     for (int i = 0; i < tot; i++) {       printf( %d %d n , ans[i][0], ans[i][1]);     }   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 5;   const int MOD = 1e9 + 7;   void solve() {     int n, m;     cin >> n >> m;     cout << (n % m ?  NO n  :  YES n );   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int t = 1;     cin >> t;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     int n, m, f = 0;     cin >> n >> m;     cin >> s;     for (int i = 0; i < n; i++) {       if (s[i] ==  # )         f++;       else         f = 0;       if (f >= m) {         cout <<  NO ;         return 0;       }     }     cout <<  YES ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve();   void YN(bool b) {     if (b) {       cout <<  YES             <<   n ;       ;     } else {       cout <<  NO             <<   n ;       ;     }   };   void yn(bool b) {     if (b) {       cout <<  Yes             <<   n ;       ;     } else {       cout <<  No             <<   n ;       ;     }   };   void queries() {     int n;     cin >> n;     while (n--) solve();   }   const int maxn = 200200;   void solve() {     int n;     cin >> n;     vector<int> a(n);     vector<int> b;     map<int, int> m;     for (int i = 0; i < n; i++) {       cin >> a[i];       m[a[i]]++;     }     for (auto i : m) {       b.push_back(i.second);     }     map<int, bool> taken;     long long sum = 0;     sort(b.begin(), b.end());     for (int i = b.size() - 1; i >= 0; i--) {       if (!taken[b[i]]) {         sum += b[i];         taken[b[i]] = 1;       } else {         for (int j = b[i]; j > 0; j--) {           if (!taken[j]) {             sum += j;             taken[j] = 1;             break;           }         }       }     }     cout << sum <<   n ;     ;     return;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     queries();     ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int i, j, k, n, m, a[110001], ans;   bool cmp(int a, int b) { return a > b; }   int main() {     scanf( %d%d , &n, &m);     for (i = 1; i <= m; i++) scanf( %d%d , &j, &a[i]);     sort(a + 1, a + 1 + m, cmp);     for (i = 1;; i++) {       if (i == 1)         k = 1;       else if (i == 2)         k = 2;       else {         k = min((i - 2) * (i / 2) + 2 * (1 + (i - 1) / 2),                 (i - 1) * (i / 2) + (2 + (i - 2) / 2));       }       if (k > n) break;     }     k = i - 1;     for (ans = 0, i = 1; i <= k; i++) ans += a[i];     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, q;     string a;     cin >> n;     map<string, int> m;     map<string, string> ma;     for (int i = 1; i <= n; i++) {       cin >> a;       int len = a.length();       for (int i = 0; i <= len; i++) {         for (int j = 0; j + i <= len; j++) {           string s1 = a.substr(i, j);           if (ma[s1] != a) {             m[s1]++;             ma[s1] = a;           }         }       }     }     cin >> q;     for (int i = 1; i <= q; i++) {       cin >> a;       if (m[a] != 0) {         cout << m[a] <<     << ma[a] << endl;       } else         printf( 0 - n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct LinearBase {     const int n = 30;     vector<int> pivot = vector<int>(n);     void Insert(int curr) {       for (int bit = n - 1; bit >= 0 && curr != 0; --bit) {         if ((curr & (1 << bit)) != 0) {           curr ^= pivot[bit];         }       }       if (curr == 0) return;       int msb = 31 - __builtin_clz(curr);       assert(pivot[msb] == 0);       pivot[msb] = curr;       for (int bit = n - 1; bit > msb; --bit) {         if ((pivot[bit] & (1 << bit)) != 0) {           pivot[bit] ^= curr;         }       }     }     int Query(int ans) {       for (int bit = n - 1; bit >= 0; --bit) {         if ((ans & (1 << bit)) != 0) {           ans ^= pivot[bit];         }       }       return ans;     }   };   struct Graph {     int n;     LinearBase base;     vector<int> dist;     vector<vector<pair<int, int>>> adj;     Graph(int n_) : n(n_), dist(n, -1), adj(n) {}     void AddEdge(int a, int b, int w) {       adj[a].emplace_back(b, w);       adj[b].emplace_back(a, w);     }     void DFS(int node) {       for (auto &e : adj[node]) {         int x, w;         tie(x, w) = e;         if (dist[x] == -1) {           dist[x] = dist[node] ^ w;           DFS(x);         } else {           base.Insert(dist[node] ^ dist[x] ^ w);         }       }     }     int Solve() {       dist[0] = 0;       DFS(0);       return base.Query(dist[n - 1]);     }   };   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     Graph g(n);     for (int i = 0; i < m; ++i) {       int a, b, w;       cin >> a >> b >> w;       g.AddEdge(a - 1, b - 1, w);     }     cout << g.Solve() << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long n, dp[30][30];   string s;   long long ten[30];   string ans[30][30];   int main() {     cin >> n >> s;     reverse(s.begin(), s.end());     ten[0] = 1;     for (int i = 1; i <= 20; i++) ten[i] = ten[i - 1] * 10;     dp[0][0] = 0;     dp[1][0] = s[0] -  0 ;     ans[1][0] =  M ;     dp[0][1] = s[0] -  0 ;     ans[0][1] =  H ;     for (int i = 2; i <= n; i++) {       long long q = (int)s[i - 1] -  0 ;       dp[i][0] = dp[i - 1][0] + q * ten[i - 1];       ans[i][0] = ans[i - 1][0];       ans[i][0] +=  M ;       dp[0][i] = dp[0][i - 1] + q * ten[i - 1];       ans[0][i] = ans[0][i - 1];       ans[0][i] +=  H ;     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) {         long long q = (int)s[i + j - 1] -  0 ;         long long m = dp[i - 1][j] + q * ten[i - 1];         long long h = dp[i][j - 1] + q * ten[j - 1];         if (m <= h) {           dp[i][j] = h;           ans[i][j] = ans[i][j - 1];           ans[i][j] +=  H ;         } else {           dp[i][j] = m;           ans[i][j] = ans[i - 1][j];           ans[i][j] +=  M ;         }       }     s = ans[n][n];     reverse(s.begin(), s.end());     cout << s << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 7;   const int maxm = 1e9 + 7;   int n;   int a[maxn], b[maxn], c[maxn], ans[maxn];   map<int, int> mp;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       b[i] = a[i];     }     queue<int> q;     q.push(n);     mp[a[n]] = n;     for (int i = n; i >= 1; i--) {       if (a[i] < a[q.back()]) {         q.push(i);         mp[a[q.back()]] = i;       }     }     sort(b + 1, b + 1 + n);     int num = unique(b + 1, b + n + 1) - b;     int p = 0;     for (int i = 1; i <= num - 1; i++) {       int j = b[i];       if (!mp[j])         mp[j] = p;       else {         swap(mp[j], p);       }     }     for (int i = 1; i <= n; i++) {       if (i >= mp[a[i]])         printf( -1  );       else         printf( %d  , mp[a[i]] - i - 1);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     cin.sync_with_stdio(false);     cin.tie(0);     long int n;     cin >> n;     const long int N = n;     char s[N];     int cnt0 = 0, cnt1 = 0;     for (int i = 0; i < n; i++) {       cin >> s[i];       if (s[i] ==  z ) {         cnt0++;       }       if (s[i] ==  n ) {         cnt1++;       }     }     for (int i = 0; i < cnt1; i++) cout <<  1  ;     for (int i = 0; i < cnt0; i++) cout <<  0  ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 10005, M = 105;   int n;   char s[N];   int p, m;   int lim;   int dp[2][N][M];   int ch[N][2], tot = 1;   int fa[N];   void dfs(int u) {     if (!ch[u][0]) return;     dfs(ch[u][0]);     dfs(ch[u][1]);     for (int i = 0; i <= lim; i++)       for (int j = 0; i + j <= lim; j++) {         dp[0][u][i + j + (p < m)] = max(dp[0][u][i + j + (p < m)],                                         dp[0][ch[u][0]][i] + dp[0][ch[u][1]][j]);         dp[0][u][i + j + (p >= m)] = max(dp[0][u][i + j + (p >= m)],                                          dp[0][ch[u][0]][i] - dp[1][ch[u][1]][j]);         dp[1][u][i + j + (p < m)] = min(dp[1][u][i + j + (p < m)],                                         dp[1][ch[u][0]][i] + dp[1][ch[u][1]][j]);         dp[1][u][i + j + (p >= m)] = min(dp[1][u][i + j + (p >= m)],                                          dp[1][ch[u][0]][i] - dp[0][ch[u][1]][j]);       }     return;   }   int main() {     scanf( %s , s + 1);     scanf( %d%d , &p, &m);     n = strlen(s + 1);     lim = min(p, m);     memset(dp[0], -63, sizeof(dp[0]));     memset(dp[1], 63, sizeof(dp[1]));     tot = 1;     int pre = tot;     for (int i = 1; i <= n; i++) {       if (s[i] ==  (  || s[i] ==  ? ) {         ch[pre][ch[pre][0] ? 1 : 0] = ++tot;         fa[tot] = pre;         pre = tot;       } else if (s[i] ==  ) )         pre = fa[pre];       else         dp[0][tot][0] = dp[1][tot][0] = s[i] -  0 , pre = fa[pre];     }     dfs(1);     printf( %d , dp[0][1][lim]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e3 + 3;   const int mod = 1e9 + 7;   const int inf = 1e9 + 7;   bool dp[N][N];   bool ok[N][10];   int cnt[N][10];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     string t[10];     t[0] =  1110111 ;     t[1] =  0010010 ;     t[2] =  1011101 ;     t[3] =  1011011 ;     t[4] =  0111010 ;     t[5] =  1101011 ;     t[6] =  1101111 ;     t[7] =  1010010 ;     t[8] =  1111111 ;     t[9] =  1111011 ;     int n, k;     cin >> n >> k;     string s[n + 4];     for (int i = 1; i <= n; ++i) cin >> s[i];     for (int i = 1; i <= n; ++i) {       for (int l = 0; l <= 9; ++l) {         ok[i][l] = 1;         for (int p = 0; p <= 6; ++p) {           if (t[l][p] ==  0  && s[i][p] ==  1 ) ok[i][l] = 0;           if (t[l][p] ==  1  && s[i][p] ==  0 ) ++cnt[i][l];         }       }     }     dp[n + 1][0] = 1;     for (int i = n; i >= 1; --i) {       for (int l = 0; l <= 9; ++l) {         if (!ok[i][l]) continue;         for (int j = cnt[i][l]; j <= k; ++j)           dp[i][j] = max(dp[i][j], dp[i + 1][j - cnt[i][l]]);       }     }     if (!dp[1][k]) return cout << -1, 0;     string ans =   ;     for (int i = 1; i <= n; ++i) {       for (int l = 9; l >= 0; --l) {         if (ok[i][l] && k >= cnt[i][l] && dp[i + 1][k - cnt[i][l]]) {           ans += char(l +  0 );           k -= cnt[i][l];           break;         }       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int NMAX = 100007;   int v[NMAX];   int n;   int main() {     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> v[i];     }     sort(v + 1, v + n + 1);     for (int i = 3; i <= n; ++i) {       if (v[i - 2] + v[i - 1] > v[i]) {         cout <<  YES ;         return 0;       }     }     cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   char s[100005];   vector<int> p, star;   void input() {     scanf( %s , s);     p.clear(), star.clear();     int l = strlen(s);     for (int i = 0; i < l; i++) {       if (s[i] ==  P ) p.push_back(i);       if (s[i] ==  * ) star.push_back(i);     }     n = p.size(), m = star.size();   }   bool can(int step) {     int now = 0;     for (int i = 0; i < n; i++) {       if (now == m) return 1;       if (p[i] - star[now] > step) return 0;       int j = now;       while (j < m) {         int MIN = min(abs(p[i] - star[now]), abs(p[i] - star[j]));         MIN += star[j] - star[now];         if (MIN <= step)           j++;         else           break;       }       now = j;       if (now == m) return 1;     }     return 0;   }   int binary(int l, int r) {     if (l == r) return l;     int m = (l + r) >> 1;     if (can(m)) return binary(l, m);     return binary(m + 1, r);   }   int main() {     int l;     while (cin >> l) {       input();       cout << binary(0, 2 * l) << endl;     }     return 0;   }