func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; bool iss(int d) { for (int i = 2; i * i <= d; ++i) if (d % i == 0) return false; return true; } int main() { int a, b, c; scanf( %d%d%d , &a, &b, &c); vector<int> simple; for (int i = 2; i < 100; ++i) if (iss(i)) simple.push_back(...
#include <bits/stdc++.h> using namespace std; char s[60][30]; long long id[1 << 20]; int num[1 << 20]; double f[1 << 20]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { scanf( %s , &s[i]); } int m = strlen(s[1]); for (int i = 1; i <= n; i++) { for (int j = ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int l, r, res = 0; cin >> l >> r; vector<unsigned long long> two, three, temp; for (int i = 0; i < 31; ++i) { two.push_back(1LL << i); if (i > 19)...
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> std::istream& operator>>(std::istream& i, pair<T, U>& p) { i >> p.first >> p.second; return i; } template <typename T> std::istream& operator>>(std::istream& i, vector<T>& t) { for (auto& v : t) { i >> v; }...
#include <bits/stdc++.h> using namespace std; int T, arr[100005], a, b, ans; int cal(int v) { int vv = v * (v - 1); return (vv >> 1); } int main() { cin >> T; for (int i = 1; i < T; i++) { cin >> a >> b; arr[a]++; arr[b]++; } for (int i = 1; i <= T; i++) { if (a...
#include <bits/stdc++.h> using namespace std; const int maxn = 200010; struct node { int x, y; } a[maxn]; int ans[maxn]; int f[maxn]; bool cmp(int c, int d) { return c < d; } int main() { int n, m; scanf( %d%d , &n, &m); for (int i = 1; i <= n; i++) { scanf( %d , &f[i]); } ...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000000; long long powmod(long long a, long long b) { long long res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; } const int N = 201000; struct node { ...
#include <bits/stdc++.h> #pragma warning(disable : 4786) using namespace std; int a[200000]; int main() { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); } a[n + 1] = a[1]; int y = 0; for (int i = 2; i <= n + 1; i++) { if (a[i] < a[i - 1]) { ...
#include <bits/stdc++.h> using namespace std; const int maxN = 11111; pair<int, int> a[maxN]; short dp[maxN][maxN]; int s[maxN]; bool mycmp(pair<int, int> a, pair<int, int> b) { if (a.second != b.second) return (a.second < b.second); return (a.first > b.first); } int main() { ios_base::sync_...
#include <bits/stdc++.h> using namespace std; pair<int, pair<int, int> > a[200020]; int f[200020]; int v[200020]; int n, m; int F(int x) { if (f[x] == x) { return x; } f[x] = F(f[x]); v[f[x]] |= v[x]; return f[x]; } int main() { scanf( %d%d , &n, &m); for (int i = 1; i ...
#include <bits/stdc++.h> using namespace std; vector<int> g1[30000 + 100], g2[30000 + 100]; set<int> st; int Next[30000 + 100], Prev[30000 + 100]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m, start; cin >> n >> m; for (int i = 1; i <= m; i++) { int u, v; ...
#include <bits/stdc++.h> using namespace std; const int N = (int)1e6 + 7; int n; string s; vector<int> p; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> s; n = (int)s.size(); for (int i = 0; i < n; i++) { if (s[i] != s[(i + 1) % n]) { p.push_back(i); } }...
#include <bits/stdc++.h> using namespace std; int n; bool isp(int a) { for (int i = 2; i * i <= a; i++) if (a % i == 0) return false; return true; } int power[100001]; long long pow(long long a, long long b, long long MOD = n) { long long ret = 1, c = a; while (b) { if (b & 1) re...
#include <bits/stdc++.h> using namespace std; const int N = (int)1e5 + 17; const int MX = (int)1e6 + 17; const int MOD = (int)1e9 + 7; const long long oo = LLONG_MAX; const int INF = INT_MAX; const long double Pi = 3.14159265358979323846264338327950288419716939937510; const int di[4] = {-1, 0, 1, 0}; ...
#include <bits/stdc++.h> using namespace std; const long long INFL = 1LL << 60; const int INF = 1 << 30; const long long MOD = 998244353; double EPS = 1e-10; vector<long long> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0}; vector<long long> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0}; void pres(double A) { printf( %.12lf...
#include <bits/stdc++.h> using namespace std; const int MAXN = 305; struct sss { int a, b, c; bool operator<(const sss& a) const { return c < a.c; } }; vector<sss> v[MAXN * MAXN]; int cost(int a, int b, int c, int d) { return abs(a - c) + abs(b - d); } int main() { int m, n, i, j, k, p; ci...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 11; int s[N]; int main() { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , &s[i]); sort(s + 1, s + 1 + n); for (int i = 1, j = 1; i <= n; i++) { if (s[i] % s[j] != 0) { printf( %d , -1); ...
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2, typename T3> struct pair3 { T1 first; T2 second; T3 third; }; template <typename T1, typename T2, typename T3, typename T4> struct pair4 { T1 first; T2 second; T3 third; T4 fourth; }; const long...
#include <bits/stdc++.h> using namespace std; int n, m; char s[1008][1008], last[1008][1008]; int a[58][58]; int flag[58], x[58], y[58]; int ans, tot; bool in[8][8]; struct Tprogram { void open() { freopen( 1.in , r , stdin); freopen( 1.out , w , stdout); } void close() {} ...
#include <bits/stdc++.h> using namespace std; int main() { int a; cin >> a; double x, y, s = 0; for (int i = 0; i < a; i++) { cin >> x >> y; s += y; } s /= a; printf( %.3lf n , s + 5); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; while (t--) { int sum, limit; cin >> sum >> limit; vector<pair<int, int>> v; for (int i = 1; i <= limit; i++) { v.push_back({1 << __builtin_ctz(...
#include <bits/stdc++.h> using namespace std; int GEN_SIZE = 6; vector<int> v, adj[50005]; int match[50005], match2[50005], vis[50005], ans[50005]; int V, Vleft; int conv(vector<int> v, int s) { int ans = 0; for (int i = 0; i < v.size(); i++) { ans *= s; ans += v[i]; } return ans...
#include <bits/stdc++.h> using namespace std; int a[1000][1000]; int w, h; int fastMax(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ y; } int fastMin(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ x; } int main() { scanf( %d%d , &h, &w); for (int y = 0; y < h; y++) for...
#include <bits/stdc++.h> using namespace std; int main() { int n, sum = 0, inp; cin >> n; for (int i = 0; i < n; i++) { cin >> inp; sum += inp; } cout << (float)sum / (float)n; return 0; }
#include <bits/stdc++.h> using namespace std; int n, d, ff = 1, bb = 1; long long mx; pair<long long, long long> f[100005]; int main() { scanf( %d%d , &n, &d); for (int i = 1; i <= n; i++) scanf( %d%d , &f[i].first, &f[i].second); sort(f + 1, f + n + 1); for (int i = 2; i <= n; i++) f[i].secon...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, a, b, sum = 0; cin >> n >> m; for (int i = 0; i < n * m; i++) { cin >> a >> b; if (a == 1 || b == 1) sum++; } cout << sum; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 7; const int SS = 4 * N; long long n, q, k, a, b; long long seg[SS][2]; void modif(int ind, int val, int s = 0, int e = n, int v = 1) { if (ind < s || ind >= e) return; if (e - s == 1) { seg[v][0] += val, seg[v][0] = min(seg[v][...
#include<bits/stdc++.h> using namespace std; #define ll long long #define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), , , ); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); } void err(istream_iterator<string> it) {} template<typename T, typename... Args> ...
#include <bits/stdc++.h> using namespace std; const int INF = (int)1e9; const int maxN = 1.1e4; vector<int> g[maxN]; map<string, int> m[maxN]; int len = 1; void add(int v, string s) { if (m[v][s] == 0) { m[v][s] = len; g[v].push_back(len); len++; } } void parse(string s) { ...
#include <bits/stdc++.h> using namespace std; #define pb push_back #define f first #define s second #define ll long long ll MOD = 1000000007; int main(){ ll t; cin>>t; while(t--){ ll n; cin>>n; int c =1; if(n==1)cout<<1<<endl; if(n==2)cout<<-1<<endl; if(n>=3){ ...
#include <bits/stdc++.h> using namespace std; int n; vector<pair<int, int> > A; int F(int i, int j) { return (A[i].first - A[j].first) * (A[i].first - A[j].first) + (A[i].second - A[j].second) * (A[i].second - A[j].second); } bool F1(vector<int> I) { for (int(i) = (0); (i) < (4); ++(i)) ...
#include <bits/stdc++.h> using namespace std; const int N = 100010; int n, a[N] = {}, tot = 0; bool v[N] = {}; void dfs(int s) { v[s] = true; if (!v[s * 2 % n]) dfs(s * 2 % n); if (!v[s * 2 % n + 1]) dfs(s * 2 % n + 1); a[++tot] = s; } int main() { cin >> n; if (n % 2) puts( ...
#include <bits/stdc++.h> using namespace std; template <class T> void chkmin(T &x, T y) { if (y < x) x = y; } template <class T> void chkmax(T &x, T y) { if (y > x) x = y; } const int N = 105; int a[N], n, x, ans1, ans2[N][N], len; int main() { scanf( %d , &n); for (int i = 1; i <= (...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3fffffff; const int maxn = 100000 + 5, maxh = 800; int n, k; int f[maxh], g[maxh]; vector<int> P[maxn]; int main() { scanf( %d%d , &n, &k); for (int i = 1, iend = k; i <= iend; ++i) { int x, y; scanf( %d%d , &x, &y); ...
#include <bits/stdc++.h> using namespace std; long long a[27]; bool h[27]; bool valid[1005][1005]; long long dp[1005]; int main() { for (int i = 0; i < 1005; i++) { for (int j = 0; j < 1005; j++) valid[i][j] = false; } for (int i = 0; i < 26; i++) h[i] = false; int n, lsub = 1; cin...
#include <bits/stdc++.h> int dp[2][1005]; int main() { char start[2 * 1005], end[1005]; int i, j, k, K; while (scanf( %s %s %d , start, end, &K) != EOF) { memset(dp, 0, sizeof(dp)); int n = strlen(start); for (i = n; i < 2 * n; i++) start[i] = start[i - n]; dp[0][0] = 1; in...
#include <bits/stdc++.h> using namespace std; char ans[1010][1010]; int len[1010]; void upd(int n, int c) { ans[n][len[n]++] = c; } char all[1 << 21]; int main() { int n, k, l; scanf( %d%d%d , &n, &l, &k); scanf( %s , all); sort(all, all + strlen(all)); int cur = 0; int beg = 1; ...
#include<bits/stdc++.h> using namespace std; #define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() #define MEM(a,x) memset(a,x,sizeof(a)) #define pi acos(-1.0) #define ll long long #define...
#include <bits/stdc++.h> using namespace std; using ll = long long; int n, m, chk[100100], a[100100], b[100100]; vector<int> v[100100]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for (int i = 1; i <= m; i++) { int a, b; cin >> a >> b; v[a].push_back...
#include <bits/stdc++.h> using namespace std; int main() { string org; cin >> org; int n; cin >> n; map<string, int> mp; for (int i = 0; i < n; i++) { string s, t; cin >> s >> t; string name; string trash; if (t[0] == p || t[0] == c ) { string trash; ...
#include <bits/stdc++.h> using namespace std; int main() { long long n, mid; bool flag; string str; char ans[3000]; cin >> n; cin >> str; if (n % 2 == 0) { mid = (n / 2) - 1; flag = true; } else { mid = (n - 1) / 2; flag = false; } long long k = 1, cnt...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; int N, dp[5000][5001], cumlcp[5000][5000]; vector<int> sa, ra, rsa, lcp; string s; void saInit() { int l = (int)s.size(); sa.resize(l); iota(sa.begin(), sa.end(), 0); ra.assign(s.begin(), s.end()); for (int k = 1; ...
#include <bits/stdc++.h> using namespace std; char str[2010][2010]; void go(int x, int y) { int l, r, u, d; d = (int)(str[x + 1][y] == . ); u = (int)(str[x - 1][y] == . ); r = (int)(str[x][y + 1] == . ); l = (int)(str[x][y - 1] == . ); if (!d && !u && !r && !l) { cout << Not uni...
#include <bits/stdc++.h> using namespace std; unsigned long long int n, m; int main() { cin >> n; m = (((n - 3) * 3) + ((n - 3) * (n - 4))) + 1; cout << m << endl; }
#include <bits/stdc++.h> using namespace std; const int N = 8e5 + 5; struct trie { int a[26]; vector<int> val[2]; } a[N]; int vis[N][2]; char ch[800005]; int cnt, n; void insert(char ch[], int op, int k) { int u = 0; int len = strlen(ch + 1); a[u].val[op].push_back(k); for (int i...
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e6 + 50; const long long inf = 0x3f3f3f3f3f3f3f3f; const long long mod = 1e9 + 7; const long double eps = 1e-20; const long long HASH = 131; using namespace std; long long a[maxn]; signed main() { std::ios::sync_with_stdio(false...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; using ii = pair<long long, long long>; using ll = long long; using ull = unsigned long long; using ld = long double; using vec = vector<long long>; using vecc = vector<vector<long long> >; namespace royyaha { template <typen...
#include <bits/stdc++.h> using namespace std; void AWAD() { std::ios::sync_with_stdio(false); cin.tie(0); } bool cmp(long long int a, long long int b) { if (a > b) return true; return false; } int a[1000001], b[1000001]; int main() { AWAD(); string input; long long int c4 = 0, ...
#include <bits/stdc++.h> using namespace std; char c; int mo = 1000003; int main() { int pre = 0; while (scanf( %c , &c) != EOF) { if (c < 32 || c > 126) break; int w = c; int tmp = 0; for (int j = 0; j < 8; j++) { tmp = tmp * 2 + w % 2; w /= 2; } w = ...
#include <bits/stdc++.h> using namespace std; const int mo = 10007; char S[205]; int n, m, M, f[205][205][205], ans; struct O { long long a[330][330]; void clear() { memset(a, 0, sizeof a); } } A, B, C; O operator*(const O &A, const O &B) { for (int i = 0; i <= M; ++i) for (int j = i; j ...
#include <bits/stdc++.h> int A, B, M = 6, N; int main() { scanf( %d%d%d , &N, &A, &B); int nda = N / A; for (int i = 1; (i <= 2) && (B * i <= N); ++i) M = std::min((i ^ 3) + (4 - ((N - B * i) / A) * (i ^ 3) + nda - 1) / nda, M); printf( %d n , M); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1000009; const int SGZ = 26; const int M = 10009; int n, m, nxt[N][SGZ], crt[N][SGZ], q[M], ans[M]; vector<int> val; char s[N], qy[SGZ]; inline int read() { char c = getchar(); int ret = 0, f = 1; while (c < 0 || c > 9 ) { ...
#include <bits/stdc++.h> int main() { long n; long m; std::cin >> n >> m; long a = 0, b = 0, c = 0, d = 0; while (!(n % 2)) { n = n / 2; a++; } while (!(n % 3)) { n = n / 3; b++; } while (!(m % 2)) { m = m / 2; c++; } while (!(m % 3)) { ...
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, k, x, s = 0; cin >> n >> k; map<long long, long long> m; queue<long long> q; for (long long i = 0; 0 < n ? i < n : i > n; 0 < n ? i += 1 : i -= 1) { ...
#include <bits/stdc++.h> using namespace std; char s[2000006]; char t[1000006]; int len[100005], pos[100005]; vector<pair<int, int>> e; int main() { int n; scanf( %d , &n); int tp = 0; for (int i = 0; i < n; i++) { scanf( %s , t + tp); len[i] = strlen(t + tp); pos[i] = tp; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 5e3 + 5; const int mod = 998244353; inline long long fpm(long long a, long long p) { long long r = 1; while (p) { if (p & 1) r = r * a % mod; a = a * a % mod; p /= 2; } return r; } int k, n, m; int s[maxn][max...
#include <bits/stdc++.h> using namespace std; char S[5000005], T[5000005]; int n, l = 1, tot = 0, R[5000005], st[5000005], ed[5000005]; void modify() { T[0] = $ , T[1] = # ; for (int i = 0; i < n; ++i) T[++l] = S[i], T[++l] = # ; T[++l] = 0 ; } void Manacher() { int p = 0, mx = 0; f...
#include <bits/stdc++.h> using namespace std; using vint = vector<long long>; using pint = pair<long long, long long>; using vpint = vector<pint>; template <typename A, typename B> inline void chmin(A& a, B b) { if (a > b) a = b; } template <typename A, typename B> inline void chmax(A& a, B b) { ...
#include <bits/stdc++.h> using namespace std; int n; int a[100002]; int mini[100002][21]; vector<pair<int, int> > vp; int f(int l, int r, int m) { if (l == r) { for (int i = 0; i < a[l] - m; i++) { vp.push_back(make_pair(l, r)); } return a[l] - m; } int i = 0; for (...
#include <bits/stdc++.h> using namespace std; struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n; for (int k = 0; k < n; k++) { cin >> m; for (int i = 0; i < m / 2; i++) { int fir, sec; cin >> fir >> sec; if (fir > 0 && sec > 0) { cout << sec << << -fir << ; } e...
#include <bits/stdc++.h> using namespace std; const int N = 100010; int n; char s[N], t[N]; bitset<N> c[30], ans; int main() { scanf( %s%d , s + 1, &n); for (int i = 1, _ = strlen(s + 1); i <= _; i++) c[s[i] - a ][i] = 1; int op, x, y; while (n--) { scanf( %d , &op); if (op == 1...
#include <bits/stdc++.h> using namespace std; const long long MAXN = 1000005; long long pw(long long b, long long r, long long md) { long long ans = 1; while (r) { if (r & 1) ans = (ans * b) % md; b = (b * b) % md; r >>= 1; } return ans; } bool cmp(pair<long long, long long> ...
#include <bits/stdc++.h> using namespace std; int x[200005], y[200005], z[200005]; long long a[200005], b[200005]; int main() { long long n, t; cin >> n >> t; x[0] = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; y[i] = 0; } for (int i = 1; i <= n; i++) { cin >> x[i]; ...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; using pll = pair<ll, ll>; template <class T> inline bool Min(T &a, T b) { return a > b ? (a = b, true) : false; } template <class T> inline bool Max(T &a, T b) { re...
#include <bits/stdc++.h> using namespace std; int powm[100005]; int fact[100005]; int sum[100005]; string s; void powers_of_10(int m) { powm[0] = 1; for (int i = 1; i <= m; i++) powm[i] = 1LL * powm[i - 1] * 10 % 1000000007; } void factorials(int m) { fact[0] = 1; for (int i = 1; i <= m;...
#include <bits/stdc++.h> using namespace std; inline char gc() { static char buf[100000], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++; } inline long long read() { long long x = 0; char ch = getcha...
#include <bits/stdc++.h> using namespace std; static inline void WRITE(int a) { printf( %d n , a); } static inline void WRITE2(int a, int b) { printf( %d %d n , a, b); } const int S9 = 1000000007, S6 = 1000007, S5 = 100007, S4 = 10007, S3 = 1007, S2 = 107; const double E2 = 0.01, E4 = 0.0001, E6 =...
#include <bits/stdc++.h> using namespace std; const int MAXN = (int)1010; set<int> ans; int n, m; char a[MAXN][MAXN]; int posk[MAXN]; int posG[MAXN]; int main() { cin >> n >> m; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> a[i][j]; if (a[i][j] == S ) ...
#include <bits/stdc++.h> using namespace std; struct node { bool flag = 0; long long sum1 = 0, sum2 = 0; void operator+=(const node& rhs) { flag |= rhs.flag; sum1 += rhs.sum1; sum2 = max(sum2, rhs.sum2); } }; const int N = 200200; int n, m, s, T; int par[N], siz[N]; int t...
#include <bits/stdc++.h> using namespace std; int main() { long double n; cin >> n; if (n <= 127) { cout << byte ; } else if (n <= 32767) { cout << short ; } else if (n <= 2147483647) { cout << int ; } else if (n <= 9223372036854775807LL) { cout << long ; } el...
#include <bits/stdc++.h> using namespace std; int main() { std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int t; cin >> t; while (t--) { long long int n; cin >> n; if (n <= 6) cout << 15 << endl; else { long long int r = n % ...
#include <bits/stdc++.h> using namespace std; char a[1005]; char b[1005]; int t[1005]; int sum[1005]; int main() { memset(t, 0, sizeof(t)); int p, n, m; cin >> n >> m >> p; cin >> a >> b; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (a[i + j] != b[j]) ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 200006; int a[MAXN], b[MAXN]; int N; int main() { while (scanf( %d , &N) != EOF) { int i, j; int x; int n = 0, m = 0; long long suma = 0, sumb = 0; int win = 0; int last; for (i = 1; i <= N; i++) { ...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const double eps = 1e-6; const int MAXN = 1e5 + 10; const int MAXM = 1e6 + 10; const long long mod = 1e9 + 7; int a[1010]; int main() { int n; scanf( %d , &n); for (int i = 0; i < n; i++) scanf( %d , &a[i]); int an...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const double eps = 1e-20; int main() { int n, a, d; cin >> n >> a >> d; int *t = new int[n]; int *v = new int[n]; double ans = -1.0; for (int i = 0; i < n; i++) cin >> t[i] >> v[i]; for (int i = 0; i < n; i++...
#include <bits/stdc++.h> using namespace std; const int N = 110; const int M = 1010; double f[N][M * N], sum[N * M]; int a[N], n, m, s; int main() { scanf( %d%d , &n, &m); for (int i = 1; i <= n; i++) { scanf( %d , a + i); s += a[i]; } f[0][0] = 1; sum[0] = 1.0; for (int ...
#include <bits/stdc++.h> using namespace std; int n, m, a[111], x[111], saven; long double f[2][100111], sum[2][100111]; int main() { ios ::sync_with_stdio(0); cin.tie(0); cout << (fixed) << setprecision(12); while (cin >> n >> m) { int sumA = 0; for (int i = (1), _b = (n); i <= _b; ...
#include <bits/stdc++.h> using namespace std; int n, k; void solve(){ cin >> n >> k; int cnt = 1; int query = 0; for(int i = 0; i < n; i++){ if(i) query = i ^ (i - 1); cout << query << endl; int r; cin >> r; if(r == 1) return...
#include <bits/stdc++.h> using namespace std; int n, m, i, x, y, k, a, q, h, l, r, j, p, s[400]; vector<int> ve[51][51]; bool ok1, ok2, Find, ok[51][51]; void get(int x, int y, int z) { q = 105; h = 104; for (int i = 1; i < ve[x][y].size(); i++) { s[++h] = ve[x][y][i]; if (i == z) l = ...
#include <bits/stdc++.h> using namespace std; const long double PI = 3.141592653589793238462643383; int w; int visit[37] = {0}; int Ceil(int a, int b) { if (a % b == 0) return a / b; else return (a / b) + 1; } struct TrieNode { struct TrieNode *children[37]; bool isEndofWord; ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:64000000 ) using namespace std; int main() { long long n; cin >> n; vector<long long> v; long long mx = -1, mn = -1; for (long long i = 1; i * i <= n; i++) if (n % i == 0) { v.push_back(i); v.push_back(n / i); ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10, inf = 1e9 + 10, P = 53, MOD = 1e9 + 7; int n, a, b, k, q, seg1[4 * maxn], seg2[4 * maxn]; inline void update(int ind) { seg1[ind] = seg1[((ind) * (2))] + seg1[(((ind) * (2)) + 1)]; seg2[ind] = seg2[((ind) * (2))] + seg2[(((ind) * (...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 100; struct node { int x, y; } point[maxn]; bool check(node a, node b, node c, node d) { if (a.x - b.x == c.x - d.x && a.y - b.y == c.y - d.y) return true; return false; } int main() { int n; cin >> n; for (int i ...
#include <bits/stdc++.h> using namespace std; const long long N = 1e3 + 10; const long long M = 1e9 + 7; long long Max(long long a, long long b) { if (a > b) return a; return b; } long long Min(long long a, long long b) { if (a > b) return b; return a; } long long big_mul(long long a, lo...
#include <bits/stdc++.h> using namespace std; long long a[100010]; bool b[100010]; long long gcd(long long a, long long b) { return a % b ? gcd(b, a % b) : b; } int main() { long long n, t; scanf( %lld , &n); for (int i = 1; i <= n; i++) { scanf( %lld , &a[i]); b[i] = a[i] % 2; } ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const long long INF = 1000000007; const long long INF2 = 1000000007LL * 1000000007LL; const long double EPS = 1e-9; const int SIZE = 1001000; int n, a, b; string fn[SIZE]; int val[SIZE], ans[SIZE]; int z[SIZE]; vector<int> g...
#include <bits/stdc++.h> using namespace std; const int MAXN = 202; const int MAXM = 50005; struct edge { int a, b; long long int g, s; edge(int a_ = 0, int b_ = 0, long long int g_ = 0LL, long long int s_ = 0LL) { a = a_, b = b_, g = g_, s = s_; } }; int N, M, cnt; int dad[MAXN]; ...
#include <bits/stdc++.h> using namespace std; int n, id, nxt[100005], num[100005], mark[100005]; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d , &nxt[i]); if (nxt[i] == i) { puts( YES ); for (int j = 1; j <= n; j++) if (j != i) printf( %d %d n...
#include <bits/stdc++.h> int main() { int n; scanf( %d , &n); int ara[n]; int temp, j; int i = 0; while (i < n) { scanf( %d , &ara[i]); i++; } i = 0; while (i < (n - 1)) { j = 0; while (j < (n - 1)) { if (ara[j] > ara[j + 1]) { temp = ara[j...
#include <bits/stdc++.h> #define MP make_pair using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); ++ i) #define rep1(i, n) for (int i = 1; i <= (int)(n); ++ i) #define foreach(itr, c) for (__typeof((c).begin()) itr = (c).begin(); itr != (c).end(); ++ itr) typedef long long LL; typed...
#include <iostream> #include <cmath> #include <map> #include <string> #include <vector> #include <algorithm> #define int long long using namespace std; string s; int a, b, c; int n, m, k; vector<int>vec, vec2; int arr[4000000], mark[4000000]; signed main() { ios_base::sync_with_stdio(false)...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 15; const int inf = 1e9; const int md = 1e9 + 7; const int shift = 1 << 17; int n, m; vector<vector<int> > g; set<pair<int, int> > br; int timer; int tin[maxn], fup[maxn]; int used[maxn]; void dfs(int v, int p = -1) { used[...
#include <bits/stdc++.h> using namespace std; int n, siz[500010]; vector<int> v[500010]; class DS { public: long long dat[2][2]; DS() { memset(dat, 0, sizeof(dat)); } DS(long long a00, long long a01, long long a10, long long a11) { dat[0][0] = a00; dat[0][1] = a01; dat[1][0] = a...
#include <bits/stdc++.h> using namespace std; long long int n, u, a[300001], x, y; long double ans = -1.0; int main() { cin >> n >> u; for (int i = 0; i < n; ++i) cin >> a[i]; y = 1; while (x < n - 2) { while (y < n - 1 && a[y + 1] - a[x] <= u) ++y; if (y - x >= 2 && a[y] - a[x] <= u...
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 5; int n, m, cnt, belong[N]; vector<int> g[N], ans[N]; int get(int x) { return belong[x] ? belong[x] = get(belong[x]) : x; } void dfs(int i) { ans[cnt].push_back(i); belong[i] = i + 1; for (int j = get(1), k = 0; j <= n; j = get(j...
#include <bits/stdc++.h> using namespace std; int q, n; int a[100010], b[100010]; int main() { scanf( %d , &q); while (q--) { scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); for (int i = 1; i <= n; i++) scanf( %d , &b[i]); int pos = 0, dis = 0, flag1 = 0, flag2 ...
#include <bits/stdc++.h> using namespace std; const int OO = (int)2e9; const double eps = 1e-9; int x[3], y[3]; int main() { int i; vector<pair<int, int> > V(8); set<int> X; set<int> Y; for (i = 0; i < 8; i++) { cin >> V[i].first >> V[i].second; X.insert(V[i].first); Y.in...
#include <bits/stdc++.h> using namespace std; int n; int a[4000]; int ans[4000][4000]; int main() { cin >> n; map<int, int> r; for (int i = 0; i < n; i++) { cin >> a[i]; if (r.find(a[i]) == r.end()) { int k = r.size(); r[a[i]] = k; } a[i] = r[a[i]]; } ...
#include <bits/stdc++.h> using namespace std; long long int a[100001], b[100001]; vector<long long int> v; map<long long int, long long int> assign; pair<long long int, long long int> dp[1001][7001]; inline long long int gcd(long long int a, long long int b) { long long int tmp; while (b) { tm...