malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   vector<int> v[3 * 100005];   int n, m, nr, h[3 * 100005], f[3 * 100005], a[3 * 100005], b[3 * 100005],       t[3 * 100005], q;   void dfs(int x) {     for (auto it : v[x])       if (h[it] == 0) {         t[it] = x;         h[it] = h[x] + 1;         dfs(it);       }   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> m;     for (int i = 1; i <= m; i++) {       int x, y;       cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);     }     cin >> q;     for (int i = 1; i <= q; i++) {       cin >> a[i] >> b[i];       f[a[i]]++;       f[b[i]]++;     }     for (int i = 1; i <= n; i++)       if (f[i] % 2) nr++;     if (nr) {       cout <<  NO n  << nr / 2;       return 0;     }     cout <<  YES n ;     h[1] = 1;     dfs(1);     for (int i = 1; i <= q; i++) {       vector<int> unu;       vector<int> doi;       while (h[a[i]] > h[b[i]]) {         unu.push_back(a[i]);         a[i] = t[a[i]];       }       while (h[a[i]] < h[b[i]]) {         doi.push_back(b[i]);         b[i] = t[b[i]];       }       while (a[i] != b[i]) {         unu.push_back(a[i]);         doi.push_back(b[i]);         a[i] = t[a[i]];         b[i] = t[b[i]];       }       cout << unu.size() + doi.size() + 1 <<   n ;       for (auto it : unu) cout << it <<    ;       cout << a[i] <<    ;       for (int j = doi.size() - 1; j >= 0; j--) cout << doi[j] <<    ;       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char str[100005];   int main() {     cin.getline(str, 100005);     int y = 0;     int l = strlen(str);     int has = 0;     for (int i = 0; i < l; i++) {       if (y == 1 && str[i] !=    ) {         cout << str[i];         continue;       }       if (str[i] ==    ) {         if (y == 0) {           y = 1;           if (has) {             cout <<  >  << endl;             has = 0;           }           cout <<  < ;         } else if (y == 1) {           cout <<  >  << endl;           y = 0;         }         continue;       }       if (str[i] ==    ) {         if (has) {           cout <<  >  << endl;           has = 0;         }         continue;       }       if (has)         cout << str[i];       else {         has = 1;         cout <<  <  << str[i];       }     }     if (str[l - 1] !=     && str[l - 1] !=    ) cout <<  >  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, k, p, total = 0;     cin >> n;     k = (n - 11) / 2;     for (int i = 1; i <= n; i++) {       char temp;       cin >> temp;       if (temp ==  8 ) {         total++;         if (total == k + 1) p = i;       }     }     if (total <= k)       cout <<  NO ;     else {       p -= k;       if ((p - 1) <= k)         cout <<  YES ;       else         cout <<  NO ;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e15;   void Tez() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int main() {     Tez();     long long n, k;     cin >> n >> k;     long long cap[k];     for (int i = 0; i < k; i++) cin >> cap[i];     long long tp = 1, no = 0, maxam = 0;     for (int i = 0; i < k; i++) {       long long x = n / cap[i];       long long am = x * cap[i];       if (am > maxam) {         no = x;         maxam = am;         tp = i + 1;       }     }     cout << tp <<     << no;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int vis[2000007];   string s;   int main() {     int n, k, i, j, l, x, len = 0, pos;     string in;     cin >> n;     for (i = 0; i < 2000007; i++) s +=  a ;     for (i = 0; i < n; i++) {       cin >> in >> k;       pos = -(int)in.length();       for (j = 1; j <= k; j++) {         cin >> x;         len = max(len, x + (int)in.length());         for (l = max(0, pos + (int)in.length() - x); l < in.length(); l++)           s[l + x] = in[l];         pos = x;       }     }     for (i = 1; i < len; i++) cout << s[i];     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int maxn = 502;   int a[maxn][maxn];   int izq[maxn][maxn], arr[maxn][maxn];   void solve() {     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         char c;         cin >> c;         if (c ==  . ) a[i][j] = 1;       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         izq[i][j] = izq[i][j - 1];         if (a[i][j] && a[i][j - 1]) {           izq[i][j]++;         }       }     }     for (int j = 1; j <= m; j++) {       for (int i = 1; i <= n; i++) {         arr[i][j] = arr[i - 1][j];         if (a[i][j] && a[i - 1][j]) {           arr[i][j]++;         }       }     }     int q;     cin >> q;     while (q--) {       int r1, c1, r2, c2;       cin >> r1 >> c1 >> r2 >> c2;       long long int ans = 0;       for (int f = r1; f <= r2; f++) {         long long int res = izq[f][c2] - izq[f][c1 - 1];         if (a[f][c1] && a[f][c1 - 1]) res--;         ans += res;       }       for (int c = c1; c <= c2; c++) {         long long int res = arr[r2][c] - arr[r1 - 1][c];         if (a[r1][c] && a[r1 - 1][c]) res--;         ans += res;       }       cout << ans <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[5][5];   pair<int, int> cost[5];   int n;   int main() {     cin >> n;     for (int i = 1; i <= 4; i++)       for (int j = 1; j <= 4; j++) cin >> a[i][j];     for (int i = 1; i <= 4; i++) {       cost[i].first =           min(a[i][1] + a[i][3],               min(a[i][1] + a[i][4], min(a[i][2] + a[i][3], a[i][2] + a[i][4])));       cost[i].second = i;     }     sort(cost + 1, cost + 5);     if (cost[1].first > n)       cout << -1;     else {       cout << cost[1].second <<    ;       int u = cost[1].second;       if (cost[1].first == a[u][1] + a[u][3])         cout << a[u][1] <<     << n - a[u][1];       else if (cost[1].first == a[u][1] + a[u][4])         cout << a[u][1] <<     << n - a[u][1];       else if (cost[1].first == a[u][2] + a[u][3])         cout << a[u][2] <<     << n - a[u][2];       else         cout << a[u][2] <<     << n - a[u][2];     }   }
#include <bits/stdc++.h>   const int dx[] = {1, -1, 0, 0};   const int dy[] = {0, 0, -1, 1};   using namespace std;   long long tests;   long long n, m, b, MOD, dp[5256][5256], a[5256], ans;   void solve() {     scanf( %I64d%I64d%I64d%I64d , &n, &m, &b, &MOD);     for (int i = 1; i <= n; i += 1) {       scanf( %I64d , &a[i]);     }     dp[0][0] = 1;     for (int i = 1; i <= n; i += 1)       for (int j = 0; j <= m; j += 1)         for (int k = 0; k <= b; k += 1)           if (k + a[i] <= b) {             dp[j + 1][k + a[i]] += dp[j][k];             dp[j + 1][k + a[i]] %= MOD;           }     for (int i = 0; i <= b; i += 1) {       ans += dp[m][i];       ans %= MOD;     }     printf( %I64d , ans);   }   int main() { solve(); }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }   long long min(long long a, long long b) { return a < b ? a : b; }   long long max(long long a, long long b) { return a > b ? a : b; }   long long max3(long long a, long long b, long long c) {     return max(max(a, b), c);   }   long long max4(long long a, long long b, long long c, long long d) {     return max(max(a, b), max(c, d));   }   long long min3(long long a, long long b, long long c) {     return min(min(a, b), c);   }   long long min4(long long a, long long b, long long c, long long d) {     return min(min(a, b), min(c, d));   }   long long po(long long x, long long n, long long mod = 1000000007) {     if (n == 0) {       return 1;     }     long long m = po(x, n / 2, mod);     m *= m;     m %= mod;     if (n % 2) {       m *= x;       m %= mod;     }     return m;   }   long long n, k;   vector<string> v(2005);   vector<string> num{ 1110111 ,  0010010 ,  1011101 ,  1011011 ,  0111010 ,                       1101011 ,  1101111 ,  1010010 ,  1111111 ,  1111011 };   long long check(string a, string b) {     long long count = 0;     for (long long i = 0; i < 7; i++) {       if (a[i] ==  1  && b[i] ==  0 ) {         return -1;       } else if (a[i] ==  0  && b[i] ==  1 ) {         count++;       }     }     return count;   }   bool comp(char a, char b) {     if (b ==  - ) {       return 1;     } else if (a ==  - ) {       return 0;     }     return a >= b;   }   vector<long long> ans;   long long dp[2005][2005];   bool stored[2005][2005];   long long solve(long long rem, long long index) {     if (rem < 0) {       return -1;     }     if (stored[rem][index]) {       return dp[rem][index];     }     if (index == n - 1) {       for (long long j = 9; j >= 0; j--) {         if (check(v[index], num[j]) == rem) {           stored[rem][index] = 1;           ans.push_back(j);           return dp[rem][index] = 1;         }       }       stored[rem][index] = 1;       return dp[rem][index] = -1;     }     stored[rem][index] = 1;     for (long long j = 9; j >= 0; j--) {       if (check(v[index], num[j]) == -1) {         continue;       }       if (solve(rem - check(v[index], num[j]), index + 1) != -1) {         ans.push_back(j);         return dp[rem][index] = 1;       }     }     return dp[rem][index] = -1;   }   int32_t main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(false);     cin.tie(NULL);     clock_t startTime = clock();     cout << fixed << setprecision(12);     cin >> n >> k;     for (long long i = 0; i < n; i++) cin >> v[i];     if (solve(k, 0) == -1) {       cout << -1;     } else {       reverse((ans).begin(), (ans).end());       for (long long i = 0; i < n; i++) {         cout << ans[i];       }     }   }
#include <bits/stdc++.h>   using namespace std;   string s;   char a;   int b, c, d, i, k, n;   int main() {     cin >> s;     k = s.size();     if (k < 2) d = 1;     while (n < 100 && d == 0) {       while (i < k - 2 && d == 0) {         if (s[i] > s[i + 2]) {           a = s[i + 2];           s[i + 2] = s[i];           s[i] = a;         }         i += 2;       }       n++;       i = 0;     }     cout << s;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k;   struct Edge {     int u;     int v;   } e[1000000];   int dp[3000][3000];   bool Judge1(int x, int y) {     for (int i = 0; i < n; i++)       if (!(x & (1 << i)) && (y & (1 << i))) return false;     return true;   }   bool Judge2(int u, int v, int x, int y) {     if ((1 << (u - 1)) & x && !((1 << (v - 1)) & x)) return true;     return false;   }   int Count(int x) {     int ret = 0;     for (int i = 0; i < n; i++)       if ((1 << i) & x) ret++;     return ret;   }   void PUT(int x) {     for (int i = 0; i < n; i++)       if (x & (1 << i))         cout << 1;       else         cout << 0;   }   int ans;   int main() {     cin >> n >> m >> k;     for (int i = 1; i <= m; i++) {       cin >> e[i].u >> e[i].v;       int temp = 0;       temp |= (1 << (e[i].u - 1));       temp |= (1 << (e[i].v - 1));       dp[temp][temp] = 1;     }     for (int i = 0; i <= (1 << n) - 1; i++)       for (int j = 0; j <= (1 << n) - 1; j++)         if (Judge1(i, j))           for (int g = 1; g <= m; g++) {             if (Judge2(e[g].u, e[g].v, i, j)) {               int temp = j;               temp |= (1 << (e[g].v - 1));               if (temp & (1 << (e[g].u - 1))) temp ^= (1 << (e[g].u - 1));               bool pd = false;               for (int q = e[g].v + 1; q <= n; q++)                 if ((1 << (q - 1)) & temp) {                   pd = true;                   break;                 }               int st = i;               st |= 1 << (e[g].v - 1);               if (!pd) dp[st][temp] += dp[i][j];             } else if (Judge2(e[g].v, e[g].u, i, j)) {               swap(e[g].v, e[g].u);               int temp = j;               temp |= (1 << (e[g].v - 1));               if (temp & (1 << (e[g].u - 1))) temp ^= (1 << (e[g].u - 1));               bool pd = false;               for (int q = e[g].v + 1; q <= n; q++)                 if ((1 << (q - 1)) & temp) {                   pd = true;                   break;                 }               int st = i;               st |= 1 << (e[g].v - 1);               if (!pd) dp[st][temp] += dp[i][j];             }           }     for (int i = 0; i <= (1 << n) - 1; i++)       for (int j = 0; j <= (1 << n) - 1; j++) {         if (Count(j) == k && (i == ((1 << n) - 1))) ans += dp[i][j];       }     cout << ans << endl;     return 0;   }
#include<bits/stdc++.h>   using namespace std;   int main()   {       int t;       cin>>t;       while(t--)       {           int a,b,c;           cin>>a>>b>>c;           int sum=a+b+c;           if(sum<7)               cout<< No <<endl;           else           {               if(sum%9==0)               {                   sum=sum/9;                   if(a>=sum && b>=sum && c>=sum)                       cout<< Yes <<endl;                   else                       cout<< No <<endl;               }               else                   cout<< No <<endl;           }       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int x, d;     cin >> x >> d;     long long start = 1;     vector<long long> arr;     while (x > 0) {       int toPrint = 1;       while ((1LL << toPrint) - 1 <= x) toPrint++;       toPrint--;       for (long long i = start; i < start + toPrint; i++) arr.push_back(start);       start += toPrint + d + 1;       x -= ((1LL << toPrint) - 1);     }     if (arr.size() > 1e4 || start >= 1e18) {       cout <<  -1 ;       return 0;     }     cout << arr.size() << endl;     for (int i = 0; i < arr.size(); i++) cout << arr[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int T, n, m;   int t1, t2;   bool w;   map<pair<int, long long>, int> mex;   int solve(int rem = 60, long long msk = (1 << 60) - 1) {     if (mex.count({rem, msk})) {       return mex[{rem, msk}];     }     mex[{rem, msk}] = 0;     int x = 0;     set<int> s;     for (int i = 1; i <= rem; ++i) {       if ((msk >> i) & 1)         s.insert(             solve(rem - i, ((1ll << (rem - i + 1)) - 1) & (msk & ~(1ll << i))));     }     while (s.count(x)) ++x;     return mex[{rem, msk}] = x;   }   int main() {     scanf( %d , &n);     scanf( %d , &t1);     T = solve(t1, (1ll << t1 + 1) - 1);     for (int i = 1; i < n; ++i) {       scanf( %d , &t1);       T ^= solve(t1, (1ll << t1 + 1) - 1);     }     if (T) {       printf( NO );     } else {       printf( YES );     }     printf(  n );   }
#include <bits/stdc++.h>   using namespace std;   void fre() {     freopen( c://test//input.in ,  r , stdin);     freopen( c://test//output.out ,  w , stdout);   }   template <class T1, class T2>   inline void gmax(T1 &a, T2 b) {     if (b > a) a = b;   }   template <class T1, class T2>   inline void gmin(T1 &a, T2 b) {     if (b < a) a = b;   }   const int N = 0, M = 0, Z = 1e9 + 7, ms63 = 0x3f3f3f3f;   int casenum, casei;   long long n;   void solve1e6(long long n) {     int step = 0;     while (n) {       int x = n;       int mx = 0;       while (x) gmax(mx, x % 10), x /= 10;       n -= mx;       ++step;     }     printf( %d n , step);   }   struct A {     long long x;     int y;     void add(const A &b) {       x += b.x;       y = b.y;     }   };   int a[20];   A f[20][10][10];   A dp(int p, int mx, int tim, int tp) {     if (p == -1) {       if (mx == 0) return {0, 0};       if (tim) return {0, tim - 1};       return {1, mx - 1};     }     if (!tp && ~f[p][mx][tim].x) return f[p][mx][tim];     A ret = {0, tim};     int top = tp ? a[p] : 9;     for (int i = top; i >= 0; --i) {       ret.add(dp(p - 1, max(mx, i), ret.y, tp && i == top));     }     if (!tp) f[p][mx][tim] = ret;     return ret;   }   void solve1e18(long long n) {     int p = -1;     while (n) a[++p] = n % 10, n /= 10;     if (p == -1) a[++p] = 0;     for (int i = 0; i <= p; ++i) {       for (int j = 0; j < 10; ++j) {         for (int k = 0; k < 10; ++k) f[i][j][k].x = -1;       }     }     printf( %lld n , dp(p, 0, 0, 1).x);   }   int main() {     while (~scanf( %lld , &n)) {       solve1e18(n);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct xy {     int x, y;   };   int a[1212121], par[1212121], depth[1212121];   vector<int> C[1212121];   void dfs(int w, int dep) {     depth[w] = dep;     for (int nxt : C[w]) dfs(nxt, dep + 1);   }   int Hn = 0, myH[1212121], sz[1212121], root[1212121], ppar[1212121];   int find(int x) {     if (ppar[x] == x) return x;     return ppar[x] = find(ppar[x]);   }   multiset<int> S[1212121], ansS;   void push(int x) {     sz[x] = 1;     int mx = 0, mxw;     for (int child : C[x]) {       sz[x] += sz[child];       if (mx < sz[child] && S[myH[child]].size() > 0) mx = sz[child], mxw = child;     }     if (mx == 0) {       int hIdx = ++Hn;       myH[x] = hIdx;       root[hIdx] = x;       S[hIdx].insert(depth[x]);       ppar[hIdx] = hIdx;       ansS.insert(0);     } else {       int hIdx = myH[x] = myH[mxw];       root[hIdx] = x;       int dep = (*S[hIdx].rbegin()) - depth[mxw];       ansS.erase(ansS.find(dep));       S[hIdx].insert(depth[x]);       for (int child : C[x])         if (child != mxw) {           if (!S[myH[child]].empty()) {             for (auto &v : S[myH[child]]) S[hIdx].insert(v);             ppar[myH[child]] = hIdx;             int dep = (*S[myH[child]].rbegin()) - depth[child];             ansS.erase(ansS.find(dep));           }           S[myH[child]].clear();         }       dep = (*S[hIdx].rbegin()) - depth[x];       ansS.insert(dep);     }   }   void pop(int x) {     int hIdx = find(myH[x]);     int dep = (*S[hIdx].rbegin()) - depth[root[hIdx]];     ansS.erase(ansS.find(dep));     S[hIdx].erase(S[hIdx].find(depth[x]));     if (S[hIdx].empty()) return;     dep = (*S[hIdx].rbegin()) - depth[root[hIdx]];     ansS.insert(dep);   }   int main() {     int n, k, i, j;     scanf( %d%d , &n, &k);     for (i = 1; i <= n; i++) scanf( %d , &a[i]);     vector<xy> ST;     ST.push_back({n + 1, n + 1});     for (i = n; i >= 1; i--) {       while (ST.back().x <= a[i]) ST.pop_back();       par[i] = ST.back().y;       C[par[i]].push_back(i);       ST.push_back({a[i], i});     }     dfs(n + 1, 0);     for (i = 1; i <= n; i++) {       push(i);       if (k <= i) {         printf( %d  , *ansS.rbegin() + 1);         if (i != n) pop(i - k + 1);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[210][210], b[210][210];   int n, m;   int main() {     while (cin >> n >> m) {       int ra = 1, rb = 1, ca = 1, cb = 1;       for (int i = 1; i <= m; i++)         if (i % 2) {           a[ra++][ca] = i;           if (ra > n) ra = 1, ca++;         } else {           b[rb++][cb] = i;           if (rb > n) rb = 1, cb++;         }       for (int i = 1; i <= n; i++) {         for (int j = ca; j >= 1; j--) {           if (!a[i][j]) continue;           cout << a[i][j] <<    ;         }         for (int j = cb; j >= 1; j--) {           if (!b[i][j]) continue;           cout << b[i][j] <<    ;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, bear, ans, a, aux, votes[128];   priority_queue<int> q;   int Solution() {     int ans = 0;     while (bear <= q.top()) {       aux = q.top();       if (bear <= aux) {         bear++;         aux--;         q.pop();         q.push(aux);         ans++;       }     }     return ans;   }   int main() {     scanf( %d , &n);     scanf( %d , &bear);     for (int i = 0; i < n - 1; ++i) {       scanf( %d , &a);       q.push(a);     }     ans = Solution();     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long fpm(long long b, long long e, long long m) {     long long t = 1;     for (; e; e >>= 1, b = b * b % m) e & 1 ? t = t * b % m : 0;     return t;   }   template <class T>   inline bool chkmin(T &a, T b) {     return a > b ? a = b, true : false;   }   template <class T>   inline bool chkmax(T &a, T b) {     return a < b ? a = b, true : false;   }   template <class T>   inline T sqr(T x) {     return x * x;   }   template <class edge>   struct Graph {     vector<vector<edge> > adj;     Graph(int n) {       adj.clear();       adj.resize(n + 5);     }     void adde(int s, edge e) { adj[s].push_back(e); }     typename vector<edge>::iterator operator[](int t) { return adj[t].begin(); }   };   const int maxn = 1100;   typedef int arr32[maxn];   arr32 col, row, vrow, vcol;   int noans, mod;   int main() {     ios_base::sync_with_stdio(false);     int n, m, K;     cin >> n >> m >> K;     for (int i = 1; i <= n; ++i) row[i] = m, vrow[i] = 1;     for (int j = 1; j <= m; ++j) col[j] = n, vcol[j] = 1;     for (int i = 1, a, b, c; i <= K; ++i)       cin >> a >> b >> c, --row[a], --col[b], vrow[a] *= c, vcol[b] *= c;     int unx = 0;     if (K < n) {       for (int i = 1; i <= n; ++i)         if (row[i])           unx += row[i] - 1;         else if (vrow[i] != -1)           noans = 1;       unx -= m - 1;     } else {       for (int j = 1; j <= m; ++j)         if (col[j])           unx += col[j] - 1;         else if (vcol[j] != -1)           noans = 1;       unx -= n - 1;     }     cin >> mod;     if (noans || (n & 1) != (m & 1))       cout << 0 << endl;     else       cout << fpm(2, unx, mod) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 3;   map<int, vector<int>> sign;   int a[MAX];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     multiset<int> st;     for (int i = 1; i <= n; i++) {       cin >> a[i];       st.insert(a[i]);     }     vector<pair<int, int>> v;     for (int i = 0; i < n - 1; i++) {       int x = *st.rbegin();       st.erase(st.find(x));       int y = *st.rbegin();       st.erase(st.find(y));       st.insert(x - y);       v.push_back({x, y});     }     int S = *st.rbegin();     sign[S].push_back(1);     for (int i = n - 2; i >= 0; i--) {       int x = v[i].first, y = v[i].second;       int p = sign[x - y].back();       sign[x - y].pop_back();       sign[x].push_back(p), sign[y].push_back(p ^ 1);     }     for (int i = 1; i <= n; i++) {       if (sign[a[i]].back())         cout <<  + ;       else         cout <<  - ;       sign[a[i]].pop_back();     }   }
#include <bits/stdc++.h>   using namespace std;   int num[105];   double cal(int w, int e, int s) {     if (e < s) return 1.0;     double res = 1, dw = (double)w, de = (double)e;     for (int i = 0; i < s; i++) {       res = res * de / dw;       dw--;       de--;     }     return 1.0 - res;   }   int main() {     int n, m, h;     int s;     while (~scanf( %d%d%d , &n, &m, &h)) {       s = 0;       for (int i = 1; i <= m; i++) {         scanf( %d , &num[i]);         s += num[i];       }       if (s < n)         printf( -1.0 n );       else {         printf( %.7lf n , cal(s - 1, s - num[h], n - 1));       }     }     return 0;   }