func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const int maxs = 405; const int inf = 1e9 + 7; int dp[maxs][maxs]; string s, t, x, y; int slen, tlen; int nxt[maxs][26]; int g(int x) { return x + 1; } int f(int a, int b) { if (a == -1 && b == -1) return 0; if (a < -1 || b < -1) return inf; in...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:100000000000,100000000000 ) using namespace std; const double eps = 1E-9; const double Exp = 2.718281828459045; const double Pi = 3.1415926535897932; const int NMAX = 100 + 5; const int MMAX = 100000 + 5; const int INF = 1000000000; const int BS...
#include <bits/stdc++.h> using namespace std; int n, m; int c[1010100], cc[1010100]; int lowbit(int x) { return x & (-x); } void upd(int v, int idx, int a[]) { while (idx <= n) { a[idx] += v; idx += lowbit(idx); } } int qu(int idx, int a[]) { int sum = 0; if (idx == 0) return 0...
#include <bits/stdc++.h> using namespace std; const int N = 10200; const int mod = 1e9 + 7; int dp[N]; int len[N]; inline int get_len(int x) { if (x == 0) return 1; int res = 0; while (x) res++, x /= 10; return res; } vector<int> del[N]; vector<int> calc_prefix(string s) { int n = ...
#include <bits/stdc++.h> using namespace std; const long long INF = 8e+1000; int n, k, x, c[1000]; int main() { ios_base::sync_with_stdio(false); cin >> n >> k >> x; for (int i = 0; i < n; i++) cin >> c[i]; int res = 0; for (int i = 0; i < n - 1; i++) { if (c[i] == c[i + 1] && c[i] == ...
#include <bits/stdc++.h> #define endl n #define IOS ios::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr) using namespace std; typedef long long LL; typedef pair<int, int> PII; const int maxn = 1e3 + 5; string input; int cnt[maxn], mx; double a, b; inline double randrand(){ ...
#include <bits/stdc++.h> using namespace std; pair<int, int> afis[1503]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, cnt = 0, i, x = 1; cin >> n; afis[++cnt] = {0, 0}; while (x <= n + 1) { afis[++cnt] = {x, x}; afis[++cnt] = {x, x - ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, m, k, a[N]; long long rem, cnt, sum; double ans; int main() { cin >> n >> k >> m; for (int i = 1; i <= n; ++i) { scanf( %d , a + i); sum += a[i]; } sort(a + 1, a + n + 1); for (int i = 1; i <= n; ++i)...
#include <bits/stdc++.h> #include <string> using namespace std; bool susp() { int n; cin >> n; string days; cin >> days; for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { if (days[j] == days[i] && days[j - 1] != days[i]) ...
#include <bits/stdc++.h> using namespace std; int main() { set<string> s; int n; cin >> n; for (int i = 0; i < n; ++i) { string ss; cin >> ss; s.insert(ss); } cout << 6 - n << n ; if (s.find( purple ) == s.end()) { cout << Power n ; } if (s.find( green ...
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 5, mod = 1e9 + 7, lg = 22; int n, suf[maxn], lcp[maxn], Rank[lg][maxn], pw2[30], rmq[lg][maxn], lst, seg[maxn * 4], klg[maxn], dp[maxn]; string s; vector<pair<pair<int, int>, int>> V2; void raDix_Sort() { vector<vector<pair<pair<...
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 7; const long long inf = 1e9 + 7; const long long mod = 1e9 + 7; int n; int m; int x; int y; vector<int> g[N]; int main() { ios_base::sync_with_stdio(false); cin >> n >> m; for (int i = 1; i <= m; i++) { cin >>...
#include <bits/stdc++.h> using namespace std; inline int in() { int32_t x; scanf( %d , &x); return x; } inline string get() { char ch[1000010]; scanf( %s , ch); return ch; } const int MAX_LG = 21; const int maxn = 2e5 + 100; const int base = 29; const int mod = 1e9 + 7; const...
#include <bits/stdc++.h> using namespace std; int n, c0, c1, C[70][50010]; const int N = 60, M = 40000; struct atom { long long w; int num; } A[50]; int len; int check(long long lim) { int now = min(1ll * n, lim / c1); for (int i = 1; i <= N; i++) { int j = 0; while (1ll * i * ...
#include <bits/stdc++.h> using namespace std; class input { private: bool fail; istream* stream; public: input(istream& stream_ = cin) { stream = &stream_; } istream& getStream() { return *stream; } template <typename T = int> T read() { T value; if (*stream >> value) { ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:64000000 ) using namespace std; const int INF = (int)1E9; const long long INF64 = (long long)1E18; const long double EPS = 1E-9; const long double PI = 3.1415926535897932384626433832795; const int MAXN = 100100; map<int, vector<pair<int, int> > > ...
#include <bits/stdc++.h> using namespace std; long long l, r, u, d; long long n, x, y, c; long long sqr(long long x) { return x * x; } long long tri(long long x) { return (x + 1) * x / 2; } bool solve(long long t) { long long sum = t * t + (t + 1) * (t + 1); if (t > l) sum -= sqr(t - l); if (t >...
#include <bits/stdc++.h> using namespace std; bool check(pair<int, int> a, pair<int, int> b) { if (a.first > b.first) return true; else if (a.first == b.first) return a.second < b.second; else return false; } int main() { int n, k; cin >> n >> k; pair<int, int> a[n]; ...
#include <bits/stdc++.h> using namespace std; const int N = 15; const char inf = z ; bool g[N][N]; vector<string> gen_cand_strings(int n); void rec_gen(vector<string>& ans, string& cur, char c, int n); vector<string> get_good_strings(vector<string>& cand, int n); vector<string> gen_cand2_strings(int n)...
#include <bits/stdc++.h> #pragma optimize( O3 ) using namespace std; const int up = 1e5 + 5; int la, ra, ta, lb, rb, tb; int gcd(int x, int y) { if (x == 0 || y == 0) { return x + y; } int r = x % y; while (r) { x = y; y = r; r = x % y; } return y; } int mai...
#include <bits/stdc++.h> using namespace std; const long long INF = 2e18; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n; cin >> n; vector<long long> a(n); map<long long, long long> dp; for (long long i = 0; i < n; ++i) { cin >> a[i]; ...
#include <bits/stdc++.h> using namespace std; set<long long> sset; void add(int n) { set<long long>::iterator it = sset.find(n); if (it == sset.end()) { sset.insert(n); } else { sset.erase(it); add(n + 1); } } int main() { cin.sync_with_stdio(false); int n; cin >>...
#include <bits/stdc++.h> using namespace std; const int mx = 1e3 + 10; int a[mx], b[mx]; int main() { int n, k; scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d%d , a + i, b + i); scanf( %d , &k); for (int i = 1; i <= n; i++) if (k <= b[i]) return 0 * printf( %d n , n - i + 1); ...
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; a = abs(a - b); b = a / 2; a = a / 2 + (a & 1); cout << (a * a + a) / 2 + (b * b + b) / 2 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int n; int ask(int l) { cout << ? ; for (int i = 0; i < n - 1; i++) cout << 1 << ; cout << l << endl; cout.flush(); int k; cin >> k; if (k == 0) return 1; else return 0; } int ask1(int l, int x) { cout << ? ; ...
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { int n; cin >> n; vector<int> a; for (int i = 0; i < n; ++i) { int x; cin >> x; a.push_back(x); } int b = 0, c = n - 1; while (a[b + 1] > a[b] && b < n - 1) { b++; } whil...
#include <bits/stdc++.h> using namespace std; long long int a[100001]; vector<long long int> adj[100001]; long long int ans[21] = {}; long long int dp[100001][21][2]; void dfs(long long int i, long long int par) { long long int u = 0; for (long long int j = 0; j < adj[i].size(); j++) { long lo...
#include <bits/stdc++.h> using namespace std; int main() { int T; cin >> T; while (T--) { int n; cin >> n; n *= 2; vector<int> a, b, x; for (int i = 0; i < n; i++) { int tn; cin >> tn; x.push_back(tn); } sort(x.begin(), x.end()); co...
#include<bits/stdc++.h> #define rep(i, a, n) for(int i = a; i <= n; i++) #define _rep(i, n, a) for(int i = n; i >= a; i--) typedef long long LL; using namespace std; const int maxn = 2e5 + 10; const int mod = 1004535809; inline LL read(){ LL x = 0, fl = 1; char c = getchar(); while (c < 0 || c > ...
#include <bits/stdc++.h> const int maxnm = 9 + 2; int n, m; char map[maxnm][maxnm], best[maxnm][maxnm]; bool shape[4][3][3] = {{{1, 1, 1}, {0, 1, 0}, {0, 1, 0}}, {{0, 1, 0}, {0, 1, 0}, {1, 1, 1}}, {{1, 0, 0}, {1, 1, 1}, {1, 0, 0}}, {{0, ...
#include <bits/stdc++.h> using namespace std; template <class T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf( %d , &x); } void _R(long long &x) { scanf( %lld , &x); } void _R(double &x) { scanf( %lf , &x); } void _R(char &x) { scanf( %c , &x); } void _R(char *x) { scanf( %s , x); } void...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 10; long long spf[MAXN]; long long min1[MAXN]; long long min2[MAXN]; void sieve() { spf[1] = 1; for (int i = 2; i < MAXN; i++) spf[i] = i; for (int i = 4; i < MAXN; i += 2) spf[i] = 2; for (int i = 3; i * i < MAXN; i++) { ...
#include <bits/stdc++.h> using namespace std; vector<long long> v; bool vis[10005]; long long n, m, k; int main() { cin >> n >> m >> k; if ((n * m * 2) % k != 0) puts( NO ); else { puts( YES ); puts( 0 0 ); if ((n * 2) % k == 0) { printf( %lld 0 n , n * 2 / k); ...
#include <bits/stdc++.h> using namespace std; const long double EPS = 1e-11; int n, d; const int M = 30001; int f[M][250 * 2]; int v[M]; int solve(int i, int j) { if (i >= M) return 0; int jj = j - (d - 250); if (f[i][jj] != -1) return f[i][jj]; f[i][jj] = 0; int res = 0; if (j == ...
#include <bits/stdc++.h> using namespace std; const int N = 1000100, M = 100100, K = 1000100, mod = 1000000007; int n, m, k, l = N, r = 0, tot = 0, p[K] = {1}; int main() { scanf( %d%d%d , &n, &m, &k); for (int i = 1, u, v; i <= m; ++i) { scanf( %d%d , &u, &v); if (v - u > 1) { if (v...
#include <bits/stdc++.h> using namespace std; long long int power(long long int a, long long int b) { long long int x = (a) % 1000000007, y = 1; while (b) { if (b % 2 != 0) y = (y * x) % 1000000007; x = (x * x) % 1000000007; b /= 2; } return y; } long long cnt[200003] = {0}, l[...
#include <bits/stdc++.h> using namespace std; const long long UNDEF = -1; const int INF = 1 << 25; template <typename T> inline bool chkmax(T& aa, T bb) { return aa < bb ? aa = bb, true : false; } template <typename T> inline bool chkmin(T& aa, T bb) { return aa > bb ? aa = bb, true : false; }...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int i = 0; i < t; i++) { int n; cin >> n; int maxi = 0, mini = 1000000000; vector<long long int> a(n, 0); long long int xor1 = 0; long long int sum1 = 0; for (int i = 0; i < n; i++)...
#include <bits/stdc++.h> using namespace std; char S[111111]; long long cnt1[26], cnt2[26 * 26]; int main() { scanf( %s , S); int len = strlen(S); for (int i = 0; i < len; i++) { for (int j = 0; j < 26; j++) cnt2[26 * j + S[i] - a ] += cnt1[j]; cnt1[S[i] - a ]++; } long long an...
#include <bits/stdc++.h> using namespace std; int n, d = 2; bool P[100100]; int A[100100]; vector<pair<int, int> > R; void criba() { for (int i = 0; i < 100100; i++) P[i] = 1; P[0] = 0; P[1] = 0; for (int i = 2; i < 100100; i++) { if (P[i]) { for (int j = 2 * i; j < 100100; j +...
#include <bits/stdc++.h> using namespace std; const int N = 100100; inline long long int gcd(long long int ga, long long int gb) { if (!gb) return ga; return gcd(gb, ga % gb); } inline long long int lcm(long long int a, long long int b, long long int c) { long long int ans = a * b / gcd(a, b); ...
#include <bits/stdc++.h> using namespace std; int main() { int n, i, a, b, s = 0; cin >> n; map<int, int> m1, m2; for (i = 1; i < n + 1; ++i) { int a, b; cin >> a >> b; s += m1[a + b]++; s += m2[a - b]++; } cout << s; }
#include <bits/stdc++.h> using namespace std; int main() { double n, m; scanf( %lf %lf , &n, &m); printf( %.6lf , pow(1.000000011, m) * n); }
#include <bits/stdc++.h> using namespace std; int main() { int b, x; double a, c; cin >> a >> b >> c; a = ceil(a * (c / 100)); x = a; x -= b; if (x < 1) x = 0; cout << x << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; int a[1200]; while (~scanf( %d , &n)) { for (int i = 1; i <= 2 * n; i++) scanf( %d , &a[i]); sort(a + 1, a + 2 * n + 1); if (a[n] == a[n + 1]) printf( NO n ); else printf( YES n ); } return ...
#include <bits/stdc++.h> using namespace std; const int N = 30; class Solution; class LinearBasis { public: friend class Solution; LinearBasis() : size(0) { fill(begin(bs), end(bs), 0); } LinearBasis& operator=(const LinearBasis& other) { copy(begin(other.bs), end(other.bs), begin(bs)); ...
#include <bits/stdc++.h> using namespace std; int main(void) { int n; scanf( %d , &n); for (int i = 30; i >= 0; i--) { if (n >> i & 1) printf( %d , i + 1); } puts( ); return 0; }
#include <bits/stdc++.h> using namespace std; int n; int a[100], b[100]; int res[100][3001][101] = {0}; bool us[100][3001][101] = {0}; const int mod = 1000000007; int work(int ll, int pr = -1, int lpred = -1) { if (ll < 0) return 0; if (ll == 0) return 1; if (pr != -1 && us[pr][ll][lpred] != 0...
#include <bits/stdc++.h> using namespace std; const long long maxn = 2e6 + 10; long long n, a[maxn], Begin[maxn], Next[maxn], To[maxn], e, sum; bool vis[maxn], use[maxn]; inline void add(long long u, long long v) { To[++e] = v; Next[e] = Begin[u]; Begin[u] = e; } inline void DFS(long long u, l...
#include <bits/stdc++.h> using namespace std; mt19937 gen(chrono::system_clock::now().time_since_epoch().count()); const int M = 3e5 + 7; const int N = 1e6 + 7; int n, q, l, r, t[N * 4], ans[N], k, x, tn = 1; map<int, vector<int> > p; map<int, vector<pair<int, int> > > otr; map<int, vector<pair<int, int...
#include <bits/stdc++.h> using namespace std; std::vector<int> res; std::vector<int> adj[200005]; std::vector<int> DEPTH(200005); std::vector<int> NODENUM(200005); std::vector<int> funct(200005); vector<bool> taken(200005); vector<bool> visited(200005); int dfs(int v, int depth) { int nodeNum = 0;...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, dig = 0, rem; cin >> n; while (n != 0) { rem = n % 10; if (rem == 4 || rem == 7) { dig++; } n = n / 10; } if (dig == 4 || dig == 7) cout << YES ; else cout << NO ; }
#include <bits/stdc++.h> using namespace std; int place_to_score[] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1}; int t, n; map<string, int> ids; int next_id = 1; char names[50][64]; char tmp[64]; int score[50]; int places[50][50]; int main() { scanf( %d , &t); for (int i = 0; i < t; i++) { sc...
#include <bits/stdc++.h> using namespace std; string dst__; stringstream dss__; void debug(stringstream& ds) { cerr << endl; return; } template <typename F, typename... R> void debug(stringstream& ds, const F& f, const R&... r) { string n; ds >> n; cerr << n << = << f << ; deb...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int cnt[26] = {0}; for (int i = 0; i < s.size(); i++) { cnt[s[i] - a ]++; } int ans[26] = {0}; vector<int> v; for (int i = 0; i < 26; i++) { ans[i] = cnt[i] / 2; cnt[i] = cnt[i] % 2; ...
#include <bits/stdc++.h> const double pi = acos(-1); const int MOD = 1e9 + 7; const int INF = 1e9 + 7; const int MAXN = 1e6 + 5; const double eps = 1e-9; using namespace std; double xp, yp, vp, x, y, v, r, R; double P, len, L; pair<double, double> pos[2]; double f(double dphi) { if (dphi > pi) d...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:667772160 ) using namespace std; struct __isoff { __isoff() { if (0) freopen( input.txt , r , stdin), freopen( output.txt , w , stdout); srand( C + T + A + C + Y + M + B + A ); } ~__isoff() {} } __osafwf; const un...
#include <bits/stdc++.h> using namespace std; const int modulo = 1e9 + 7; template <class __Ty> bool mini(__Ty& a, __Ty b) { return a > b ? ((a = b) | 1) : (0); } template <class __Ty> bool maxi(__Ty& a, __Ty b) { return a < b ? ((a = b) | 1) : (0); } template <class __Ty> __Ty add(__Ty a, _...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d, e, f; cin >> a >> b >> c >> d >> e >> f; cout << (a + b + c) * (a + b + c) - (a * a + c * c + e * e); }
#include <bits/stdc++.h> using namespace std; const long long MXN = 2e5 + 10; long long n, m, sum, maxi; long long A[MXN], Ans[MXN], Max[MXN]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i = 1; i <= m; i++) cin >> A[i], sum += A[i]; if (sum < ...
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; const int MOD = 1e9 + 7; vector<pair<int, int> > G[maxn]; int vis[maxn]; int dp[maxn]; int dfs(int x, int v) { vis[x] = 1; dp[x] = v; for (pair<int, int> e : G[x]) { int a = e.first; int b = 1 - e.second; ...
#include <bits/stdc++.h> using namespace std; string t; int ct, z; vector<int> vi; int gcd(int a, int b) { if (!b) return a; if (a % b == 0) return b; return gcd(b, a % b); } int main() { int a, b, k; cin >> a >> b >> k; if (a + k < b) { printf( 0.0000000 n ); exit(0); ...
#include <bits/stdc++.h> using namespace std; const int N = 505; int a[N]; int dp[N][N]; int deal(int L, int R) { if (L >= R) return 1; if (dp[L][R] != N) return dp[L][R]; if (a[L] == a[R]) dp[L][R] = min(dp[L][R], deal(L + 1, R - 1)); for (int i = L; i < R; ++i) { dp[L][R] = min(dp[L][R...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const int MAX = (int)(2e5) + 7; const int MOD = (int)(1e9) + 7; const int INF_I = (int)(1e9) + 7; const ll INF_LL = (ll)(1e18); template <typename T> void info(T& v) { for (const auto& i : v) cout << i << ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); long long n; long long t1(0), t2(0); long long mn = 0, mx = 0; cin >> n; vector<long> vec(n, 0); for (long i = 0; i < n; i++) { cin >> vec[i]; } sort(vec.begin(), vec.end()); mn = ve...
#include <bits/stdc++.h> using namespace std; const int NMAX = 1000000 + 5; int N; int p[2 * NMAX]; int main() { cin >> N; iota(p + 1, p + N + 1, 1); int st = 1, dr = N; for (int phase = 2; phase <= N; ++phase, ++st) { int old = 0; for (int i = st; i <= dr; i += phase) { in...
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 7; int n; long long a[maxn]; long long work(long long m) { long long res = 0; while (m) { if (m & 1) res++; m >>= 1; } return res; } long long dp[maxn][2]; int main() { scanf( %d , &n); for (int i = ...
#include <bits/stdc++.h> using namespace std; struct node { unsigned long int val; long int index; unsigned long int other; }; bool cmp(node& a, node& b) { if (a.val != b.val) return a.val < b.val; else return a.other > b.other; } struct node2 { bool operator()(const node...
#include <bits/stdc++.h> using namespace std; template <class T> void printvec(vector<T>& x, int a, int b) { for (int i = (a); i <= (b); i++) cout << x[i] << ; cout << n ; } const double PI = acos((double)-1); const double EPSILON = 1e-7; const int N = 1e6 + 1; const int NN = 1e3 + 1; con...
#include <bits/stdc++.h> using namespace std; int n, k; string s; int cnt; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> k; cin >> s; for (int i = 0; i < n; i++) { if (s[i] == # ) { cnt++; } else { if (cnt >= k) { ...
#include <bits/stdc++.h> using namespace std; int N, A[100], i, j; bool w; string S; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N; for (i = 0; i < N; i++) { cin >> A[i]; } getline(cin, S); for (j = 0; j < N; j++) { getline(cin, S); ...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; int n, k; vector<int> g[N]; int fa[N]; int dep[N]; bool vis[N]; int anc[N][35]; void dfs(int u, int f) { fa[u] = f; anc[u][0] = fa[u]; for (int i = 0; i < g[u].size(); i++) { int v = g[u][i]; if (v != f) { ...
#include <bits/stdc++.h> using namespace std; inline long long read() { char ch = getchar(); long long x = 0; int op = 1; for (; !isdigit(ch); ch = getchar()) if (ch == - ) op = -1; for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - 0 ; return x * op; } inline void write(long ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } int sum = 2 * n - 1 + a[0]; if (n > 1) { if (a[0] > a[1]) sum += a[0] - a[1]; for (int i = 1; i < n - 1; i++) { if (a[i] > a[i - 1]...
#include <bits/stdc++.h> using namespace std; const int oo = (int)1e9; const double PI = 2 * acos(0); const double eps = 1e-9; inline int comp(const double &a, const double &b) { if (fabs(a - b) < eps) return 0; return a > b ? 1 : -1; } int di[] = {1, -1, 0, 0, 1, -1, 1, -1}; int dj[] = {0, 0, 1...
#include <bits/stdc++.h> using namespace std; string a; int n; int main() { cin >> a; scanf( %d , &n); int i; for (i = 0; i < a.size(); i++) if (a[i] >= A && a[i] <= Z ) a[i] = a + a[i] - A ; for (i = 0; i < a.size(); i++) if (a[i] - a + 1 <= n) a[i] = A + a[i] - a ; ...
#include <bits/stdc++.h> using namespace std; int dx[4] = {1, -1, 0, 0}; int dy[4] = {0, 0, 1, -1}; void fast() { ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0); } void online_judge() { freopen( input.txt , r , stdin); freopen( output.txt , w , stdout); } const int flag_m...
#include <bits/stdc++.h> using namespace std; int counter = 0; int ans = -1; int n, m; char a[15][15]; char z[15][15]; inline int ok(int x, int y) { return (x >= 0 && y >= 0 && x < n && y < m && a[x][y] == . ); } void rec(int x, int y) { if (counter + (n * m - x * m - y) / 5 <= ans) return; ...
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007; long long BASE = 101; bool is_enough(int h, int n, int m) { int n1 = h / 2; int m1 = h / 3; int mn1 = h / 6; if (n1 - mn1 >= n && m1 - mn1 >= m) { return true; } int need_n = max(0, n - (n1 - mn1)); int n...
#include <bits/stdc++.h> using namespace std; const int maxn = 200500; const int inf = 2e9; const double eps = 1e-8; const int base = 1073676287; long long a[maxn]; int b[maxn]; int c[maxn]; int bit[64]; int bits2[64]; void check(int n) { long long sum = 0LL; for (int j = 0; j < n; j++) { ...
#include <bits/stdc++.h> using namespace std; struct wor { int x, y; bool start; }; struct node { int maxN; int plus; }; vector<node> t(16 * 1000000 + 1000, {0, 0}); int m = 4 * 1000000 + 5; bool operator<(wor a, wor b) { return a.y < b.y or a.y == b.y and a.x < b.x; } void update(int ...
#include <bits/stdc++.h> using namespace std; int t; typedef long long LL; set<LL>a; int main(){ for(LL i = 1;i <= 10000;i++)a.insert(i*i*i); scanf( %d ,&t); while(t--){ LL x; cin >> x; int flag = 0; for(LL i = 1;i <= 10000;i++) if(a.count(x-i*i*i)){ puts( YES ); flag...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[100 + 10][100 + 10]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> a[i][j]; } } int sum = 0; for (int i = 0; i < n; i++) { sum += a[i][i]; } for (int i...
#include <bits/stdc++.h> using namespace std; int pp(int x, int y) { int i = 0; int min = 1; for (i = 0; i < y; i++) { min = min * x; } return min; } int main() { int n; int a[100001]; int i, k, t, flag; long long int min; while (scanf( %d , &n) != EOF) { for ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long t, i, j; cin >> t; while (t--) { long long n; cin >> n; set<long long> s; s.insert(0); s.insert(1); for (i = sqrt(n); i > 0; i--...
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; const int inf = 50000000; const int maxn = 100010; int check(vector<int> &v) { int i, first, cur, j; for (i = 0; i < v.size(); i++) { first = j = 0; cur = v[i]; while (j < 8) { if (cur == 1) { ...
#include <bits/stdc++.h> using namespace std; int nBox, testC, iBox, nBird, A[109]; int main() { scanf( %d , &nBox); for (int i = 0; i < nBox; ++i) scanf( %d , &A[i]); scanf( %d , &testC); for (int i = 0; i < testC; ++i) { scanf( %d%d , &iBox, &nBird); --iBox; if (iBox != 0) A[iB...
#include <bits/stdc++.h> using namespace std; int a[100005]; int calc(int x, int k) { int SG; if (k % 2 == 0) { if (x >= 3) SG = !(x % 2); else SG = x; } else { if (x >= 6) { if (x % 2) SG = 0; else { if (calc(x / 2, k) == 1) ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); ; cout.tie(0); int n, i; cin >> n; int a[n], f[105] = {0}; int m = 0; for (i = 1; i <= n; i++) { cin >> a[i]; f[a[i]]++; if (f[a[i]] > m) m = f[a[i]]; } ...
#include <bits/stdc++.h> using namespace std; signed main() { int q; cin >> q; while (q--) { int n; cin >> n; string a, b; cin >> a; cin >> b; if (n == 1) { if (a[0] == 1 || a[0] == 2 ) cout << NO n ; else if (b[0] == 1 || b[0] == 2 ) ...
#include <bits/stdc++.h> using namespace std; const long long int MOD = 1000000007; const long double PI = 2 * acos(0.0); const vector<long long int> dx = {1, -1, 0, 0}; const vector<long long int> dy = {0, 0, 1, -1}; vector<long long int> ga(long long int n, bool oneIndexed = false) { vector<long long ...
#include <bits/stdc++.h> using namespace std; long long n; vector<long long> G[500005]; long long t1, d1, t2, d2; long long dis1[500005], dis2[500005]; long long inp[500005], in[500005]; stringstream ss; void dfs1(long long u, long long fa, long long d) { if (d > d1) { d1 = d; t1 = u; ...
#include <bits/stdc++.h> using namespace std; struct segtree { int size = 1; vector<pair<int, int>> v; vector<pair<int, int>> lazy; void init(int n) { while (n > size) { size *= 2; } v.assign(size * 2, {0, -1}); lazy.assign(size * 2, {0, -1}); } void prop(int ...
#include <bits/stdc++.h> using namespace std; const int SIZE = 9000; const int mod = 1e9 + 7; const int maxv = 9000; bool vis[maxv + 1][maxv + 1], in[maxv + 1][maxv + 1]; vector<int> v[maxv + 1]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; int n; cin >> n; ...
#include <bits/stdc++.h> using namespace std; int main() { long long i, j, k, l, m, n, cnt = 0, ans = 0; char a[8][8]; for (i = 0; i < 8; i++) for (j = 0; j < 8; j++) cin >> a[i][j]; for (i = 0; i < 8; i++) { for (j = 0; j < 8; j++) { if (a[i][j] == B ) cnt++; } if (...
#include <bits/stdc++.h> int main() { int n, l, v1, v2, k; while (~scanf( %d%d%d%d%d , &n, &l, &v1, &v2, &k)) { if (k >= n) { printf( %.10lf n , l * 1.0 / v2); continue; } int t = (n - 1) / k; double s = v2 * 1.0 / v1; double kk = (1 + s) / (3 + s); double t...
#include <bits/stdc++.h> using namespace std; const int MAXN = 55; int n, m; int a[MAXN][MAXN]; int main() { int t; cin >> t; while (t--) { cin >> n >> m; set<int> rows, columns; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cin >> a[i][j]; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, i, j, k, cnt1, cnt2; scanf( %d %d , &n, &m); string str1, str2; cin >> str1 >> str2; if (str1 == str2) { return !printf( YES n ); } cnt1 = cnt2 = 0; int l2; for (i = 0; i < n && i < m; i++) { if (str...
#include <bits/stdc++.h> using namespace std; int t; int main() { scanf( %d , &t); while (t--) { int a, b; scanf( %d%d , &a, &b); int k = min(max(2 * a, b), max(a, 2 * b)); printf( %d n , k * k); } }
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 7; const int L = 30; int n; int a[N]; struct Trie { Trie *l, *r; Trie(Trie *l_, Trie *r_) { l = l_; r = r_; } }; struct Ans { Trie *t; long long ans; }; int get(Trie *l, Trie *r, int i) { if (i == -...