malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long n, m, q;   long long b[100000 + 1];   long long suma;   long long sums;   long long sum[100000 + 1];   long long sign(long long i) { return ((i & 1) ? 1 : (-1)); }   inline long long poz(long long a) { return (a > 0 ? a : (-a)); }   void readFile() {     scanf( %lld%lld%lld , &n, &m, &q);     long long i, nr;     for (i = 1; i <= n; i++) {       scanf( %lld , &nr);       suma += nr * sign(i);     }     long long sumb = 0;     long long cr = 1;     for (i = 1; i <= m; i++) {       scanf( %lld , &b[i]);       if (i > n) {         sumb -= (-b[i - n]);         sumb = (-sumb);       }       if (i <= n) cr = (-cr);       sumb += cr * b[i];       if (i >= n) sum[++sums] = sumb;     }   }   long long elem(long long i) {     if (i >= 1 && i <= sums) return sum[i];     return sum[1];   }   void printRez() {     long long i = 0;     long long pas = (1 << 16);     long long caut = -suma;     while (pas != 0) {       if (i + pas <= sums && sum[i + pas] <= caut) i += pas;       pas >>= 1;     }     printf( %lld n , min(min(poz(suma + elem(i)), poz(suma + elem(i + 1))),                          poz(suma + elem(i - 1))));   }   void ansQues() {     sort(sum + 1, sum + sums + 1);     printRez();     while (q > 0) {       q--;       long long st, dr, nr;       scanf( %lld%lld%lld , &st, &dr, &nr);       long long mns = (dr >> 1) - ((st - 1) >> 1);       long long pls = (dr - st + 1) - mns;       suma += 1LL * pls * nr;       suma -= 1LL * mns * nr;       printRez();     }   }   int main() {     readFile();     ansQues();     return 0;   }
#include <bits/stdc++.h>   int dr[] = {2, 2, -2, -2, 1, -1, 1, -1};   int dc[] = {1, -1, 1, -1, 2, 2, -2, -2};   int dr1[] = {0, 0, 1, 1, 1, -1, -1, -1};   int dc1[] = {1, -1, 1, 0, -1, 0, 1, -1};   int dr2[] = {0, 0, 1, -1};   int dc2[] = {1, -1, 0, 0};   using namespace std;   long long a[100005];   long long bigmod(long long n, long long p) {     if (p == 0) return 1;     long long x = bigmod(n, p / 2);     x = (x * x) % 1000000007;     if (p % 2 == 1) x = (x * n) % 1000000007;     return x;   }   int main() {     long long n, i, j;     while (cin >> n) {       bool f = 0;       for (i = 1; i <= n; i++) {         cin >> a[i];         if (a[i] % 2 == 0) f = 1;       }       if (f == 1) {         long long m = 2;         for (i = 1; i <= n; i++) {           m = bigmod(m, a[i]);         }         m = m * bigmod(2LL, 1000000007 - 2);         m %= 1000000007;         long long m1 = m;         m1 = (m1 + 1) % 1000000007;         m1 = m1 * bigmod(3LL, 1000000007 - 2);         m1 %= 1000000007;         cout << m1 <<  /  << m << endl;       } else {         long long m = 2;         for (i = 1; i <= n; i++) {           m = bigmod(m, a[i]);         }         m = m * bigmod(2LL, 1000000007 - 2);         m %= 1000000007;         long long m1 = m;         m1 = (m1 - 1 + 1000000007) % 1000000007;         m1 = m1 * bigmod(3LL, 1000000007 - 2);         m1 %= 1000000007;         cout << m1 <<  /  << m << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int kMod = 1e9 + 7;   const int kNmax = 2e5 + 10;   int n, v[kNmax], sub[kNmax], up[kNmax][2], down[kNmax][2], res, res_even;   vector<int> g[kNmax];   void dfs(int node, int father = 0) {     sub[node] = 1;     down[node][0] = 1;     int ways = (1LL * n * n) % kMod;     for (int vec : g[node]) {       if (vec == father) continue;       dfs(vec, node);       ways = (ways - 1LL * sub[vec] * sub[vec]) % kMod;       if (ways < 0) ways += kMod;       sub[node] += sub[vec];       down[node][0] += down[vec][1];       down[node][1] += down[vec][0];     }     ways = (ways - 1LL * (n - sub[node]) * (n - sub[node])) % kMod;     if (ways < 0) ways += kMod;     res = (res + 1LL * ways * v[node]) % kMod;     if (res < 0) res += kMod;   }   void dfs_bad(int node, int father = 0) {     int s0 = 0, s1 = 0;     int ways = (1LL * down[node][1] * (n - sub[node])) % kMod;     ways = (ways + 1LL * up[node][1] * sub[node]) % kMod;     for (int vec : g[node]) {       if (vec == father) continue;       ways = (ways + 1LL * down[vec][0] * (sub[node] - sub[vec])) % kMod;       s0 += down[vec][0];       s1 += down[vec][1];     }     res_even = (res_even + 1LL * ways * v[node]) % kMod;     if (res_even < 0) res_even += kMod;     for (int vec : g[node]) {       if (vec == father) continue;       up[vec][0] = up[node][1] + s0 - down[vec][0];       up[vec][1] = n - sub[vec] - up[vec][0];       dfs_bad(vec, node);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n;     for (int i = 1; i <= n; i++) cin >> v[i];     for (int i = 1, a, b; i < n; i++) {       cin >> a >> b;       g[a].push_back(b);       g[b].push_back(a);     }     dfs(1);     up[1][0] = 1;     dfs_bad(1);     res = (res - 2LL * res_even) % kMod;     if (res < 0) res += kMod;     cout << res;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> bariers;     int n, m, s, d, temp;     scanf( %d%d%d%d , &n, &m, &s, &d);     for (int i = 0; i < n; i++) {       scanf( %d , &temp);       bariers.push_back(temp);     }     sort(bariers.begin(), bariers.end());     int sing_dist, temp_dist = 0;     if (bariers[0] <= s || d == 1) {       printf( IMPOSSIBLE );       return 0;     }     for (int i = 0; i < bariers.size() - 1; i++) {       sing_dist = bariers[i + 1] - bariers[i];       if (sing_dist <= s + 1) {         bariers.erase(bariers.begin() + i);         temp_dist += sing_dist;         i--;       } else {         temp_dist = 0;       }       if (temp_dist + 1 >= d) {         printf( IMPOSSIBLE );         return 0;       }     }     int cur_pos = 0;     for (int i = 0; i < bariers.size(); i++) {       temp_dist = bariers[i] - d - s + 1;       if (cur_pos < temp_dist) {         printf( RUN %d n , temp_dist + s - cur_pos);         printf( JUMP %d n , d);       } else {         printf( RUN %d n , s);         printf( JUMP %d n , bariers[i] + 1 - cur_pos - s);       }       cur_pos = bariers[i] + 1;     }     if (cur_pos != m) {       printf( RUN %d n , m - cur_pos);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   double r, v;   double a, b;   bool check(double l) {     double arfa = l / r;     double A = r * (1 - cos(arfa));     double B = r * sin(arfa);     return l + sqrt(A * A + B * B) >= b - a;   }   int main() {     cin >> n >> r >> v;     while (n--) {       scanf( %lf%lf , &a, &b);       double l = 0, r = b - a, ans;       for (int i = 1; i <= 100; i++) {         double mid = (l + r) / 2.0;         if (check(mid))           ans = mid, r = mid;         else           l = mid;       }       printf( %.10f n , ans / v);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using namespace std;   const int maxn = 3e5 + 7;   int n, f[maxn][20], dep[maxn];   set<int> s1, s2;   int mx = 0;   long long ans = 0;   int path(int o, int p) {     if (dep[o] < dep[p]) swap(o, p);     int dis = dep[o] - dep[p];     for (int i = 19; i >= 0; --i) {       if (dep[f[o][i]] >= dep[p]) {         o = f[o][i];       }     }     if (o == p) return dis;     for (int i = 19; i >= 0; --i) {       if (f[o][i] != f[p][i]) {         dis += 2 * (dep[o] - dep[f[o][i]]);         o = f[o][i];         p = f[p][i];       }     }     return dis + 2;   }   void solve(int v) {     int u;     scanf( %d , &u);     f[v][0] = u;     dep[v] = dep[u] + 1;     for (int i = 1; i < 20; ++i) {       f[v][i] = f[f[v][i - 1]][i - 1];     }     int dis1 = s1.empty() ? 0 : path(v, *s1.begin());     int dis2 = s2.empty() ? 0 : path(v, *s2.begin());     if (max(dis1, dis2) < mx) return;     if (max(dis1, dis2) > mx) {       mx = max(dis1, dis2);       if (dis1 >= dis2) {         for (auto &i : s2) {           if (path(i, v) == mx) {             s1.insert(i);           }         }         s2.clear();         s2.insert(v);       } else {         for (auto &i : s1) {           if (path(i, v) == mx) {             s2.insert(i);           }         }         s1.clear();         s1.insert(v);       }     } else {       if (dis1 >= dis2) {         s2.insert(v);       } else {         s1.insert(v);       }     }     ans = s1.size() + s2.size();   }   int main() {     scanf( %d , &n);     for (int i = 0; i < 20; ++i) {       f[1][i] = 1;       f[2][i] = 1;     }     s1.insert(1);     mx = 1;     for (int i = 2; i <= n + 1; ++i) {       solve(i);       printf( %lld n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, max = 0, max2 = 0, indexm, indexm2;     cin >> n;     for (int i = 0; i < n; i++) {       int temp;       cin >> temp;       if (temp >= max) {         max2 = max;         indexm2 = indexm;         max = temp;         indexm = i + 1;       } else if (temp > max2) {         max2 = temp;         indexm2 = i + 1;       }     }     cout << indexm <<     << max2 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void maxtt(T& t1, T t2) {     t1 = max(t1, t2);   }   template <typename T>   void mintt(T& t1, T t2) {     t1 = min(t1, t2);   }   bool debug = 0;   int n, m, k;   int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};   string direc =  RDLU ;   long long ln, lk, lm;   void etp(bool f = 0) {     puts(f ?  YES  :  NO );     exit(0);   }   void addmod(int& x, int y, int mod = 998244353) {     assert(y >= 0);     x += y;     if (x >= mod) x -= mod;     assert(x >= 0 && x < mod);   }   void et(int x = -1) {     printf( %d n , x);     exit(0);   }   long long fastPow(long long x, long long y, int mod = 998244353) {     long long ans = 1;     while (y > 0) {       if (y & 1) ans = (x * ans) % mod;       x = x * x % mod;       y >>= 1;     }     return ans;   }   long long gcd1(long long x, long long y) { return y ? gcd1(y, x % y) : x; }   int t;   long long a[205], b[205], c[205];   long long sa[205], sb[205];   long long f[205][205][2], g[205][205][2];   void fmain(int ID) {     scanf( %d%d%d , &n, &t, &k);     for (int(i) = 1; (i) <= (int)(n); (i)++) {       scanf( %lld%lld%lld , a + i, b + i, c + i);     }     n++;     a[n] = (1 << 30);     b[n] = (1 << 30);     c[n] = (1LL << 60);     for (int(i) = 1; (i) <= (int)(n); (i)++) {       sa[i] = sa[i - 1] + a[i];       sb[i] = sb[i - 1] + b[i];     }     for (int(i) = 0; (i) < (int)(205); (i)++)       for (int(j) = 0; (j) < (int)(205); (j)++)         for (int(z) = 0; (z) < (int)(2); (z)++) {           f[i][j][z] = g[i][j][z] = (1LL << 60);         }     for (int(j) = 0; (j) < (int)(205); (j)++)       for (int(z) = 0; (z) < (int)(2); (z)++) f[0][j][z] = g[0][j][z] = 0;     for (int(i) = 1; (i) <= (int)(n); (i)++) {       for (int j = 0; j <= t; j++)         for (int(z) = 0; (z) < (int)(2); (z)++) {           if (a[i] * z + b[i] * j <= c[i] && f[i - 1][j][z] < (1LL << 60)) {             mintt(f[i][j][z], f[i - 1][j][z]);             long long cnt = (sa[i - 1] * z + sb[i - 1] * j + k - 1) / k;             if (cnt * k <= sa[i] * z + sb[i] * j) mintt(g[i][j][z], cnt);           }           for (int r = 0; r < j; r++) {             long long cnt = g[i][r][z];             if (cnt == (1LL << 60)) continue;             long long rem = sa[i] * z + sb[i] * r - cnt * k;             assert(0 <= rem);             long long need = (max(0LL, rem + b[i] * (j - r) - c[i]) + k - 1) / k;             if (need * k <= rem && f[i - 1][j - r][0] < (1LL << 60)) {               mintt(f[i][j][z], cnt + need + f[i - 1][j - r][0]);               long long n2 = (sb[i - 1] * (j - r) + k - 1) / k;               if (n2 * k <= sb[i] * (j - r) + rem - need * k) {                 mintt(g[i][j][z], cnt + need + n2);               }             }           }         }     }     printf( %lld n , f[n][t][1]);   }   int main() {     int t = 1;     for (int(i) = 1; (i) <= (int)(t); (i)++) {       fmain(i);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int k, l, m, n, d;     int cont = 0;     cin >> k >> l >> m >> n >> d;     cont = d;     if (k == 1 || l == 1 || m == 1 || n == 1) {       cout << d << endl;     } else {       for (int i = 1; i <= d; i++) {         if ((i % k != 0) && (i % l != 0) && (i % m != 0) && (i % n != 0)) cont--;       }       cout << cont << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long ans = 0;   int main(int argc, char const *argv[]) {     int t;     cin >> t;     while (t--) {       int a, b, ans = 0;       cin >> a >> b;       if (a == b)         cout << (a * 2) / 3 << endl;       else {         if (a > b) swap(a, b);         if (b >= 2 * a)           cout << a << endl;         else {           ans = b - a;           a = 2 * a - b;           ans += (a * 2) / 3;           cout << ans << endl;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long ans = 0;       while (n % 2 == 0) {         n /= 2;         ans++;       }       while (n % 3 == 0) {         n /= 3;         ans += 2;       }       while (n % 5 == 0) {         n /= 5;         ans += 3;       }       while (n % 2 == 0) {         n /= 2;         ans++;       }       if (n == 1)         cout << ans << endl;       else         cout <<  -1  << endl;     }   }
/**    *  created: 06/03/2021, 16:16:13   **/      #include <bits/stdc++.h>      using namespace std;      const int max_n = 100111, inf = 1000111222;   const int max_c = 26;      int t, n, k, cnt[max_c], need[max_c];   char s[max_n];      bool check(int mx) {       int tot = 0;       for (int i = 0; i < max_c; ++i) {           need[i] = 0;           if (cnt[i] % k) {               need[i] = k - (cnt[i] % k);           }           tot += need[i];       }       return tot <= mx;   }      void solve() {       for (int i = n - 1; i >= 0; --i) {           --cnt[s[i] -  a ];           for (int c = s[i] + 1; c <=  z ; ++c) {               ++cnt[c -  a ];               bool res = check(n - i - 1);               --cnt[c -  a ];               if (res) {                   for (int j = 0; j < i; ++j) {                       printf( %c , s[j]);                   }                   printf( %c , c);                   int tot = accumulate(need, need + max_c, 0), all = n - i - 1;                   for (int j = tot; j < all; ++j) {                       printf( a );                   }                   for (int c2 = 0; c2 < max_c; ++c2) {                       for (int j = 0; j < need[c2]; ++j) {                           printf( %c , c2 +  a );                       }                   }                   puts(  );                   return;               }           }       }   }      int main() {       //freopen( input.txt ,  r , stdin);       //freopen( output.txt ,  w , stdout);       scanf( %d , &t);       while (t--) {           scanf( %d%d%s , &n, &k, s);           if (n % k) {               puts( -1 );               continue;           }           memset(cnt, 0, sizeof(cnt));           for (int i = 0; i < n; ++i) {               ++cnt[s[i] -  a ];           }           bool ok = 1;           for (int i = 0; i < max_c; ++i) {               if (cnt[i] % k) {                   ok = 0;                   break;               }           }           if (ok) {               puts(s);               continue;           }           solve();       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct point {     double x, y;   };   point operator+(point a, point b) { return (point){a.x + b.x, a.y + b.y}; }   point operator*(point a, double b) { return (point){a.x * b, a.y * b}; }   double len(point x) { return sqrt(x.x * x.x + x.y * x.y); }   void print(point x) { printf( %.10lf %.10lf n , x.x, x.y); }   int main() {     ios::sync_with_stdio(false);     point p, v;     cin >> p.x >> p.y >> v.x >> v.y;     double a, b, c, d;     cin >> a >> b >> c >> d;     print(p + v * (b / len(v)));     point u = v * (-1);     point l = (point){-v.y, v.x};     point r = l * (-1);     point tmp = p;     print(tmp = tmp + l * (a / 2 / len(l)));     print(tmp = tmp + r * ((a - c) / 2 / len(r)));     print(tmp = tmp + u * (d / len(u)));     print(tmp = tmp + r * (c / len(r)));     print(tmp = tmp + v * (d / len(v)));     print(tmp = tmp + r * ((a - c) / 2 / len(r)));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n, k;     cin >> n >> k;     if (k == 1) {       long long int ans = n * (n - 1) / 2;       cout << ans <<     << ans << endl;     } else {       long long int ans = (n - k + 1) * (n - k) / 2;       long long int x = n / k;       long long int y = n % k;       long long int ans2 = x * (x - 1) / 2;       long long int ans3 = (x + 1) * x / 2;       cout << ans3 * y + ans2 * (k - y) <<     << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int Mod = (int)1e9 + 7;   const int MX = 1073741822;   const long long MXLL = 4e18;   const int Sz = 1110111;   inline void Read_rap() {     ios_base ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   inline void randomizer3000() {     unsigned int seed;     asm( rdtsc  :  =A (seed));     srand(seed);   }   void files(string problem) {     if (fopen((problem +  .in ).c_str(),  r )) {       freopen((problem +  .in ).c_str(),  r , stdin);       freopen((problem +  .out ).c_str(),  w , stdout);     }   }   int n;   long long d[Sz], m[Sz], r[Sz], p[Sz];   bool used[Sz];   struct fenwick {     int n;     vector<vector<pair<int, int> > > t;     fenwick(int n) : n(n), t(n + 1) {}     void add(int x, int y, int id) {       for (int i = x; i <= n; i |= (i + 1)) t[i].push_back(make_pair(y, id));     }     void preSort() {       for (int i = 0; i <= n; i++)         sort(t[i].begin(), t[i].end(),              [](pair<int, int> a, pair<int, int> b) { return a > b; });     }     void expand(int x, int y, queue<int> &q) {       for (int i = x; i >= 0; i = (i & (i + 1)) - 1) {         while ((int)(t[i].size()) && t[i].back().first <= y) {           int id = t[i].back().second;           if (!used[id]) {             used[id] = 1;             q.push(id);           }           t[i].pop_back();         }       }     }   };   int Bfs(int st) {     fenwick T(2 * (n + 1));     for (int i = 1; i <= n; i++) T.add(m[i], d[i], i);     T.preSort();     queue<int> q;     q.push(st);     int cnt = 0;     while (!q.empty()) {       int i = q.front();       q.pop();       int p = ::p[i];       int r = ::r[i];       T.expand(p, r, q);       cnt++;     }     return cnt - 1;   }   void compress(long long a[], long long b[]) {     static vector<long long> c;     c.clear();     for (int i = 0; i <= n; i++) {       c.push_back(a[i]);       c.push_back(b[i]);     }     sort(c.begin(), c.end());     for (int i = 0; i <= n; i++)       a[i] = lower_bound(c.begin(), c.end(), a[i]) - c.begin();     for (int i = 0; i <= n; i++)       b[i] = lower_bound(c.begin(), c.end(), b[i]) - c.begin();   }   long long dist(int x, int y) { return x * 1ll * x + y * 1ll * y; }   int main() {     int sx, sy;     scanf( %d %d %d %d %d , &sx, &sy, p + 0, r + 0, &n);     for (int i = 1; i <= n; i++) {       int x, y;       scanf( %d %d %d %d %d , &x, &y, m + i, p + i, r + i);       d[i] = dist(x - sx, y - sy);     }     for (int i = 0; i <= n; i++) r[i] *= r[i];     compress(r, d);     compress(p, m);     cout << Bfs(0);     return 0;   }
#include <bits/stdc++.h>   const int N = 41;   long long bin_p(long long a, long long b) {     if (!b) return 1;     if (b % 2 == 0) {       long long cur = bin_p(a, b / 2);       return cur * cur;     }     return a * bin_p(a, b - 1);   }   long long color[N];   std::vector<long long> g[N];   long long g1[N], cmpSz = 0;   bool fl = false;   void dfs(int v, int clr = 1) {     color[v] = clr;     for (auto e : g[v]) {       if (color[e] == 0) {         color[e] = (3 - clr);         dfs(e, 3 - clr);       }       if (color[e] == clr) {         fl = true;       }     }   }   const long long LEFT = 22;   const long long MASK_LEFT = (1LL << LEFT) - 1,                   MASK_RIGHT = ((1LL << 40) - 1) ^ MASK_LEFT;   long long dp1[1LL << 21], dp2[1LL << 21];   int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(0);     int n, m;     std::cin >> n >> m;     for (int i = 0; i < m; ++i) {       int a, b;       std::cin >> a >> b;       --a;       --b;       g[a].push_back(b);       g[b].push_back(a);       g1[a] |= (1LL << b);       g1[b] |= (1LL << a);     }     long long isolated = 0;     for (int i = 0; i < n; ++i) {       if (!color[i]) {         dfs(i);         cmpSz++;       }       if (g[i].size() == 0) isolated++;     }     long long answ = (1LL << n);     if (m == 0) {       answ -= (1LL << n);     }     if (!fl) {       answ += (1LL << cmpSz);     }     answ += 2LL * (1LL << isolated);     answ -= (1LL << cmpSz);     for (long long mask = 0; mask < (1 << std::max(0LL, (n - LEFT))); ++mask) {       long long realMask = (mask << LEFT), adMask = 0;       for (long long j = 0; j < n; ++j) {         if ((realMask >> j) & 1) {           adMask |= g1[j];         }       }       if ((adMask & realMask) == 0) {         dp2[mask]++;       }     }     for (long long j = 0; j < std::max(0LL, n - LEFT); ++j) {       for (long long msk = 0; msk < (1LL << std::max(0LL, (n - LEFT))); ++msk) {         if (((msk >> j) & 1)) {           dp2[msk] += dp2[msk ^ (1LL << j)];         }       }     }     for (long long mask = 0; mask < (1 << std::min((long long)n, LEFT)); ++mask) {       long long adMask = 0;       for (long long j = 0; j < n; ++j) {         if ((mask >> j) & 1) {           adMask |= g1[j];         }       }       if ((adMask & mask) == 0) {         answ -= 2 * dp2[(adMask ^ ((1LL << n) - 1)) >> LEFT];       }     }     std::cout << answ;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100010;   int ans = -1, ansd, a[MAXN], b[MAXN], n, m;   inline int Pow(int x, int y, int mod) {     int s = 1;     for (; y; y >>= 1, x = 1ll * x * x % mod)       if (y & 1) s = 1ll * s * x % mod;     return s;   }   inline bool find(int *a, int n, int x) {     int t = lower_bound(a + 1, a + n + 1, x) - a;     return a[t] == x;   }   inline void solve(int *a, int n) {     if (n == 1) {       ans = a[1], ansd = 1;       return;     }     int tmp = a[2] - a[1], cnt = 0;     for (int i = 1; i <= n; i++)       if (find(a, n, (a[i] + tmp) % m)) cnt++;     ansd = 1ll * tmp * Pow(n - cnt, m - 2, m) % m;     int d = (m - ansd) % m;     for (int i = 1; i <= n; i++)       if (!find(a, n, (a[i] + d) % m)) {         if (ans == -1)           ans = a[i];         else {           ans = -1;           return;         }       }   }   int main() {     scanf( %d%d , &m, &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     sort(a + 1, a + n + 1);     if (n == 1 || n == m) return printf( %d 1 n , a[1], 1), 0;     if (2 * n - 4 < m)       solve(a, n);     else {       int t = 0;       for (int i = 0; i < m; i++)         if (!find(a, n, i)) b[++t] = i;       solve(b, t);       if (ans != -1) (ans += 1ll * ansd * t % m) %= m;     }     if (ans == -1) return printf( -1 n ), 0;     return printf( %d %d n , ans, ansd), 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, k, i;     while (scanf( %lld %lld , &n, &k) != EOF) {       vector<long long int> v;       for (i = 1; i * i <= n; i++) {         if (n % i == 0) {           v.push_back(i);           if ((n / i) != i) v.push_back(n / i);         }       }       sort(v.begin(), v.end());       if (v.size() < k) {         cout <<  -1  << endl;       } else {         printf( %lld n , v[k - 1]);       }     }     return 0;   }