func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; double const pi = 3.1415926535897932384626433832795; int const inf = (int)1e9; long long const inf64 = (long long)2e18; const string name = d ; vector<pair<int, int> > ans; int n, d[21]; void rec(int n, int x, int y, int z, bool rev) { if (n == 0) retur...
#include <bits/stdc++.h> using namespace std; int n, r; int main() { cin >> n >> r; int ans = 0, Max = -1, mark = false; for (int i = 1; i <= r; i++) { int t = i, b = r, num = 0, cnt = 0; while (t > 0 && b > 0) { bool flag = false; if (b > t) { int c = b / t - 1; ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e6; vector<int> g[MAXN], g1[MAXN]; int n, p, mp, m, all_n; void add(int t1, int t2) { g[t1 ^ 1].push_back(t2); g1[t2].push_back(t1 ^ 1); g[t2 ^ 1].push_back(t1); g1[t1].push_back(t2 ^ 1); } vector<int> order; bool vis[MAXN];...
#include <bits/stdc++.h> using namespace std; long long const M = 2e5 + 10, M2 = 1e7 + 10, mod = 1e9 + 7, inf = 1e9 + 10, sq = 450; long long a[M], cnt[M], t1, t2, t0, x1; pair<long long, long long> good, ans; bool check(long long ind, long long sum) { if (sum - ind > x1) return 0; l...
#include <bits/stdc++.h> int pct(int x) { return __builtin_popcount(x); } using namespace std; char grid[101][101]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int n, m; char c; cin >> n >> m >> c; int row; for (int i = 0; i < n; i++) { for (in...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 100; const long long INF = 1e12; int solve(long long x) { int res = 0; while (x) { res += (x % 10); x /= 10; } return res; } int main() { ios::sync_with_stdio(false); long long n; while (cin >> n) { ...
#include <bits/stdc++.h> using namespace std; string lower(string s) { for (int i = 0; i < s.size(); i++) s[i] = tolower(s[i]); return s; } vector<string> sep(string s, char c) { string temp; vector<string> res; for (int i = 0; i < s.size(); i++) { if (s[i] == c) { if (temp != ...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); bool F = 1; for (int i = 2; (long long)i * i <= n; i++) { if (n % i == 0) { F = 0; break; } } bool F2 = 1; for (int i = 2; (long long)i * i <= n - 2; i++) { if ((n - 2) % ...
#include <bits/stdc++.h> using namespace std; template <class T> ostream &operator<<(ostream &os, vector<T> V) { os << [ ; for (auto v : V) os << v << ; os << ] ; return os; } template <class T> ostream &operator<<(ostream &os, set<T> S) { os << { ; for (auto s : S) os << s <...
#include <bits/stdc++.h> int n; int a[15][15]; void dp() { for (int i = 1; i <= n; i++) a[i][1] = 1; for (int j = 1; j <= n; j++) a[1][j] = 1; for (int i = 2; i <= n; i++) { for (int j = 2; j <= n; j++) { a[i][j] = a[i - 1][j] + a[i][j - 1]; } } } int main() { scanf( %d...
#include <bits/stdc++.h> using namespace std; int main() { vector<pair<pair<long long, long long>, long long>> v; long long n, k; cin >> n >> k; long long p[n], c[n], ans[n]; for (int i = 0; i < n; i++) cin >> p[i]; for (int i = 0; i < n; i++) { cin >> c[i]; ans[i] = c[i]; } ...
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void debug_out(const char* name, Arg1&& arg1) { cout << name << = << arg1 << ] << n ; } template <typename Arg1, typename... Args> void debug_out(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strc...
#include <bits/stdc++.h> using namespace std; template <typename T> inline void ckmax(T& x, T y) { x = (y > x ? y : x); } template <typename T> inline void ckmin(T& x, T y) { x = (y < x ? y : x); } namespace Fread { const int SIZE = 1 << 21; char buf[SIZE], *S, *T; inline char getchar() { ...
#include <stdio.h> #include <sys/time.h> #define N 100000 #define Q 100000 #define A 100000 #define B 2154 /* B = floor(Q^(2/3)) = floor(N^(2/3)) */ #define INF 0x3f3f3f3f int min(int a, int b) { return a < b ? a : b; } unsigned int X; void srand_() { struct timeval tv; gettimeofd...
#include <bits/stdc++.h> using namespace std; long long c0, c1, n; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long lls[31]; long long comb(long long a, long long b) { long long s = 1, x, g; for (long long i = 0; ++i <= b; lls[i] = i) ; for (long long i = -...
#include <bits/stdc++.h> using namespace std; const int maxn = 100 + 5; int grid[maxn][maxn]; int main() { int n, ans = 0; scanf( %d , &n); for (int i = 0, x1, x2, y1, y2; i < n; i++) { scanf( %d%d%d%d , &x1, &y1, &x2, &y2); ans += (x2 - x1 + 1) * (y2 - y1 + 1); } printf( %d n , ...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const long long MAX = 2e9 + 7; const long long mod = 1e9 + 7; const long long maxn = 1e3 + 7; int n; string s[maxn]; set<string> ss; int jude(string s) { set<char> q; int a = s.size(); for (int i = 0; i < s.size();...
#include <bits/stdc++.h> using namespace std; std::mt19937 rnd( (int)std::chrono::steady_clock::now().time_since_epoch().count()); long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } const int MAXN = 300000; struct Res { int with, without, best; }; int n; vector<int>...
#include <bits/stdc++.h> using namespace std; map<int, int> mp; int main() { long long n; int k, cnt = 0; scanf( %lld %d , &n, &k); for (int i = 0; i < 63; i++) { if (n >> i & 1) { mp[i] = 1; ++cnt; } } if (cnt > k) return puts( No ), 0; puts( Yes ); int...
#include <bits/stdc++.h> using namespace std; int n, m; char s[1024][1024]; inline bool u(int i, int j) { return 0 <= i && i < n && 0 <= j && j <= m && s[i][j] == . ; } int p[1024 * 1024], c[1024 * 1024]; bool b[1024][1024]; int sid(int x) { int y, z = x; for (; (y = p[z]) != z; z = y) ...
#include <bits/stdc++.h> using namespace std; int t; long long x, b; void run(int a) { if (a < 10) x += a; else { x += a - a % 10; run(a / 10 + a % 10); } } int main() { cin >> t; int s[10005]; for (int i = 0; i < t; i++) cin >> s[i]; for (int i = 0; i < t; i++)...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:102400000,102400000 ) const int MOD = 1000000007; const int N = 1E5 + 15; const int maxn = 2e5 + 14; const int INF = (1 << 30) - 1; const int letter = 130; const double pi = acos(-1.0); const double eps = 1e-8; using namespace std; inline int ...
#include <bits/stdc++.h> using namespace std; int main() { int n = 0, m = 0, k = 0, arr[101], seg[100001][3]; long long sum = 0; cin >> n >> m >> k; for (int i = 0; i < m; i++) cin >> seg[i][0] >> seg[i][1] >> seg[i][2]; for (int i = 0; i < k; i++) cin >> arr[i]; for (int i = 0; i < k; i++) ...
#include <bits/stdc++.h> using namespace std; int32_t n, s, ans = -1, x, y; int main() { cin >> n >> s; while (n--) { cin >> x >> y; if (x < s || (x == s && !y)) ans = max(ans, !y ? 0 : 100 - y); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; struct node { long double x, y; node(long double X = 0.0, long double Y = 0.0) { x = X, y = Y; } } que[200005]; int n, k; int t[200005], head, tail; long double s[200005], a[200005], b[200005], f[2][200005]; long double K(node, node); int main() { ...
#include <bits/stdc++.h> using namespace std; const int fx[] = {+1, -1, +0, +0}, fy[] = {+0, +0, +1, -1}; const long long mod = 1e9 + 7, INF = 1e18, mx = 1e6; int Case = 1, cas = 0; long long n, A[mx], Sum; int main() { ios_base ::sync_with_stdio(0), cin.tie(0); ; cin >> n; for (int i = 1; i...
#include <bits/stdc++.h> using namespace std; int main() { int n, k, t, ma, sum = 0; std::string s[1000]; cin >> n >> k; for (int i = 0; i < n; i++) cin >> s[i]; for (int i = 0; i < k; i++) { cin >> t; ma = 1; map<char, int> m; for (int j = 0; j < n; j++) m[s[j][i]]++; ...
#include <bits/stdc++.h> #pragma optimise GCC(-O2) using namespace std; mt19937_64 rang( chrono::high_resolution_clock::now().time_since_epoch().count()); int rng(int lim) { uniform_int_distribution<int> uid(0, lim - 1); return uid(rang); } long long INF = LLONG_MAX; const long long M = 1000...
#include <bits/stdc++.h> using namespace std; using int64 = long long; using ld = double; const int MAXN = 1e5 + 1; vector<int> G[MAXN], comp[MAXN], suf_freq[MAXN]; vector<int64> suf_sum[MAXN]; int comp_cnt, comp_ind[MAXN], p[MAXN], dp1[MAXN], dp2[MAXN], dp[MAXN], diameter[MAXN]; void max_self(int...
#include <bits/stdc++.h> using namespace std; template <class T> inline void read(T& x) { bool fu = 0; char c; for (c = getchar(); c <= 32; c = getchar()) ; if (c == - ) fu = 1, c = getchar(); for (x = 0; c > 32; c = getchar()) x = x * 10 + c - 0 ; if (fu) x = -x; }; template <...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, x = 0, y = 0, p = 0, q = 0; cin >> n; bool ans = true; for (int i = 1; i <= n; i++) { cin >> p >> q; if (p < x || q < y) ans = false; else if (q - y ...
#include <bits/stdc++.h> using namespace std; long long int power(long long int x, long long int y, long long int p) { long long int res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } long long int modInverse(lon...
#include <bits/stdc++.h> const int SIZE_N = (1000 + 10); const int SIZE_M = (SIZE_N); const int SIZE_K = (500000 + 10); int n, m, k; int mat[SIZE_N][SIZE_M]; int mx[SIZE_M], my[SIZE_N]; int main(void) { scanf( %d%d%d , &n, &m, &k); for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) sc...
#include <bits/stdc++.h> using namespace std; using namespace std; vector<int> adj[100005]; vector<int>::iterator it; int con[100005]; bool visited[100005]; int bfs(int root) { int j, i, u, v, mn = 10000000, temp; queue<int> Q; Q.push(root); visited[root] = true; while (!Q.empty()) { ...
#include <bits/stdc++.h> using namespace std; int BIT[100005]; int v[100005], n, i, mayor, lol, cosaMenor = 1000005; int contMayor, numMenor; bool record[100005]; int buenos; void add(int pos) { while (pos > 0) { BIT[pos]++; pos -= pos & (-pos); } } int query(int pos) { int sum...
#include <bits/stdc++.h> using namespace std; int main() { int f[10]; for (int i = 0; i < 10; i++) { f[i] = 0; } for (int i = 0; i < 6; i++) { int tem; cin >> tem; f[tem]++; } int leg; int flag = 0; for (int i = 0; i < 10; i++) { if (f[i] >= 4) { ...
#include <bits/stdc++.h> using namespace std; template <typename T> inline T sqr(T a) { return a * a; }; template <typename T> void dprint(T begin, T end) { for (auto i = begin; i != end; i++) cerr << (*i) << ; cerr << n ; }; const int maxn = 500 + 5; int n, step[maxn * 2]; string a...
#include <bits/stdc++.h> using namespace std; int main() { int n, x, t, u, v; vector<long long> b; vector<pair<long long, long long> > a; scanf( %d , &n); for (int i = 0; i < n; ++i) { scanf( %d%d , &x, &t); a.push_back(make_pair(x, t)); } scanf( %d , &v); a.push_back(mak...
#include <bits/stdc++.h> const int MAXN = 1000000; int N; long long Ans; std::vector<int> G[MAXN + 5]; long long Val[MAXN + 5]; int Size[MAXN + 5]; int Fa[MAXN + 5], Dep[MAXN + 5]; void Dfs(int u, int fa, int dep) { Size[u] = 1; Fa[u] = fa; Dep[u] = dep; for (int i = 0; i < int(G[u].size...
#include <bits/stdc++.h> using namespace std; const int mo = 998244353; const double PI = acos(-1.0); template <typename _T> _T Fabs(_T x) { return x < 0 ? -x : x; } template <typename _T> void read(_T &x) { _T f = 1; x = 0; char s = getchar(); while (s > 9 || s < 0 ) { if (...
#include <bits/stdc++.h> using namespace std; template <class T> T abs(T x) { return x > 0 ? x : -x; } int n, m; int a[1 << 20]; int t[1 << 20]; void upd(int v, int val) { v += 1 << n; t[v] = val; v /= 2; bool cur = 0; while (v > 0) { if (cur == 0) t[v] = t[2 * v] |...
#include <bits/stdc++.h> using namespace std; int n; int a[200]; map<int, int> Map; int cnt[20]; int main() { for (int i = 0; i <= 11; i++) Map[1 << i] = i; int _; for (scanf( %d , &_); _; _--) { scanf( %d , &n); for (int i = 0; i < 12; i++) cnt[i] = 0; for (int i = 1; i <= n; ...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; long long prime[16] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53}; long long n, ans; void DFS(int x, int limit, long long num, long long cnt) { if (cnt > n) return; if (cnt == n && n...
#include<bits/stdc++.h> using namespace std; #define ios ios_base::sync_with_stdio(false);cin.tie(NULL); #define ll long long int #define max3(a,b,c) max(max((a),(b)),(c)) #define max4(a,b,c,d) max(max((a),(b)),max((c),(d))) #define min3(a,b,c) min(...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); long long n; cin >> n; long long k1 = 0, k2 = 1023; for (long long i = 0; i < n; i++) { long long k; char c; cin >> c >> k; if (c == | ) {...
#include <bits/stdc++.h> template <typename Arg1> void __f(const char* name, Arg1&& arg1) { std::cout << name << : << arg1 << n ; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, , ); std::cout.writ...
#include <bits/stdc++.h> using namespace std; template <typename base_type, base_type _MOD> struct IntMod { static const int INVERSE_CACHE_SIZE = (1 << 20); static base_type MOD; static void set_mod(base_type new_mod) { MOD = new_mod; } base_type n; IntMod(long long d = 0) { n = (d >= 0 ? d % ...
#include <bits/stdc++.h> bool pr[3001]; int prm[3001]; using namespace std; void primes() { int i, j; for (i = 0; i < 3001; i++) pr[i] = true; pr[0] = false; pr[1] = false; for (i = 2; i <= sqrt(3000); i++) { if (pr[i]) { for (j = i; i * j <= 3001; j += 1) { pr[i * j]...
#include <bits/stdc++.h> using namespace std; int chk[300004][3]; int visit[300004]; vector<int> vec[300004]; vector<pair<int, int>> vecp; void dfs(int x) { visit[x] = 1; for (int i = 0; i < vec[x].size(); i++) { if (visit[vec[x][i]] == 0) { dfs(vec[x][i]); chk[x][0] += chk[vec...
#include <bits/stdc++.h> using namespace std; const long long N = 1011; const long long INF = 5e16; namespace IO { inline long long read() { long long x = 0; bool f = 0; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) f ^= (ch == - ); for (; isdigit(ch); ch = getchar()) x = x * ...
#include <bits/stdc++.h> using namespace std; int main() { int q, l, k, n, m, a, b, c, sum = 0; cin >> l >> k; a = l * 2; b = l * 5; c = l * 8; sum = ((a / k) + (b / k) + (c / k)); if (a % k != 0) sum++; if (b % k != 0) sum++; if (c % k != 0) sum++; cout << sum << endl; r...
#include <bits/stdc++.h> using namespace std; int h, w; int get(int x, int y) { if (!y) return x; if (x == h) return h + y; if (y == w) return h + w + (h - x); return h + w + h + (w - y); } vector<pair<long long, long long> > get(int h, int w, int x, int a, int b) { vector<pair<long long, ...
#include <bits/stdc++.h> using namespace std; int sum[1000100]; int main() { string a, b; cin >> a >> b; int cnt = 0; for (int i = 0; i < b.size(); i++) { if (b[i] == 1 ) cnt++; } sum[0] = a[0] - 0 ; for (int i = 1; i < a.size(); i++) { sum[i] = sum[i - 1] + a[i] - 0 ; ...
#include <bits/stdc++.h> using namespace std; char a[1000][1001], s[] = DIMA ; bool b = 0, f[1000][1000]; int q, w, d[1000][1000]; void l(short int r, short int t, short int e) { int y = 0; if ((f[r][t]) || (b)) { b = 1; return; } f[r][t] = 1; e %= 4; if ((r) && (a[r - 1][...
#include <bits/stdc++.h> using namespace std; long long a[100010], b[100010]; int main(int argc, char *argv[]) { int n; long long t, Sum = 0; scanf( %d , &n); for (int i = 1; i <= n; ++i) { scanf( %lld , &t); Sum += t; } for (int i = 1; i <= n; ++i) scanf( %lld , &b[i]); so...
#include <bits/stdc++.h> using namespace std; const long long infl = 0x3f3f3f3f3f3f3f3fLL; const long long infi = 0x3f3f3f3f; const long long mod = infl; long long mygcd(long long a, long long b) { if (b == 0) { return a; } return mygcd(b, a % b); } long long mypow(long long a, long long...
#include <bits/stdc++.h> using namespace std; const double inf = 1.0 / 0.0; const double pi = 2 * acos(0.0); map<char, int> tab, tab1; char x; int main() { tab1[ Q ] = 9; tab[ q ] = 9; tab1[ R ] = 5; tab[ r ] = 5; tab1[ B ] = 3; tab[ b ] = 3; tab1[ P ] = 1; tab[ p ] = 1; ...
#include <bits/stdc++.h> using namespace std; const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342; const int MR = 1e5 + 10; const long long inf = 1e18; long long dp[21][MR]; int A[21][MR]; int a[MR]; int freq[MR], gp, gk; long long co...
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { x = (x * 10) + (ch - 0 ); ch = getchar(); } ...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<int, int>; using vi = vector<int>; const double PI = acos(-1); const double EPS = 1e-9; int main() { ios_base::sync_with_stdio(0); int n, m; cin >> n >> m; int mt[n][m]; int ans = 0; for (int i = 0;...
#include <bits/stdc++.h> using namespace std; vector<long long int> prm(1000010, 1); long long int P = 1e9 + 7; long long int M = 998244353; char adjlist[1001][1001]; bool visited[1000001] = {false}; long double pi = 3.14159265358979323846264338327950; map<int, int> visit; map<int, set<int>> g; int ...
#include <bits/stdc++.h> using namespace std; mt19937 rnd; const long long maxn = 2e6 + 5; const long long mod = 1e9 + 7; long long fac[maxn]; long long inv[maxn]; vector<char> prime(maxn, true); long long spf[maxn]; long long binpow(long long a, long long b) { if (b == 0) return 1; if (b == 1...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; string t = ; for (int i = 0; i < s.length(); i++) { if (s[i] != a && s[i] != e && s[i] != i && s[i] != o && s[i] != u && s[i] != y && s[i] != Y && s[i] != A && s[i] != E && s[...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); string s; for (int i = 1; i < 1000000 && s.size() < 1000; i++) { char val[20]; sprintf(val, %d , i); s += val; } int n; cin >> n; cout << s[n - 1]; return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5; const double EPS = 1e-8; int a[MAXN], b[MAXN]; int n, p; bool f(double T) { double have = p * T; for (int i = 0; i < n; ++i) { if (a[i] * T > b[i] + EPS) have += b[i] - a[i] * T; } return have > 0.0 + EPS; } int ma...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); long long mn, mx, n, m; cin >> n >> m; mx = n - m; mx++; mx = (mx * (mx - 1)) / 2; mn = n / m; long long temp = n / m; if (n % m != 0) { mn = (n % m) * ((mn * (mn + 1)) / 2); m -=...
#include <bits/stdc++.h> using namespace std; int main() { long long int i, n; cin >> n; for (i = 1;; ++i) { if ((i * (i + 1)) / 2 >= n) break; } cout << n - (i * (i - 1)) / 2; return 0; }
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; mt19937 rnd(chrono::steady_clock().now().time_since_epoch().count()); const int N = 765; const long long inf = (long long)4e18; long long dp[N][N]; long long f[N]; int main() { ios::sync_with_stdio(false); cin.tie(0); ...
#include <bits/stdc++.h> using namespace std; const int MAXN = (int)2e5 + 10, L = 4, INF = (int)1e9; struct State { int fa, len, tr[L], w[L]; } SAM[MAXN]; char t[MAXN]; vector<int> l[MAXN]; int m, tot; unsigned long long a[L], b[L][L], c[L][L]; unsigned long long n; int Build(int pre, int id) { ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 20; int a[MAXN]; int main() { int k; scanf( %d , &k); for (int i = 1; i <= 12; i++) { scanf( %d , &a[i]); } sort(a + 1, a + 13); int tot = 0, ans = 0; for (int i = 12; i >= 1; i--) { if (tot >= k) { br...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; switch (n) { case 1: cout << n * 2 << endl; break; case 2: cout << n + 1 << endl; break; case 3: cout << n - 2 << endl; break; case 4: cout << n / 2...
#include <bits/stdc++.h> using namespace std; const int MAX = 2e5; int main() { int n; cin >> n; int f = 0, z = 0; for (int i = 0; i < n; i++) { int val; scanf( %d , &val); if (val == 5) f++; else z++; } int mx = 0; for (int i = 0; i <= f; i++) ...
#include <bits/stdc++.h> using namespace std; const long long inf = 1 << 30; long long m, r; signed main() { double ans = 0; scanf( %d%d , &m, &r); for (long long i = 1; i <= m; i++) { double sum = 2 * r; if (i - 1 != 0) { sum += 2 * r + sqrt(2) * r; if (i - 1 >= 2) { ...
#include <bits/stdc++.h> using i64 = long long; int n; std::vector<std::vector<int>> g; std::vector<int> sz, d; int dfs(int v, int p) { return sz[v] = std::accumulate(g[v].begin(), g[v].end(), 1, [=](int s, int c) { return s + (d[c] >= 0 || c == p ? 0 : dfs(c, v)); ...
#include <bits/stdc++.h> using namespace std; int read() { int x = 0, f = 1; char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) f = -1; c = getchar(); } while ( 0 <= c && c <= 9 ) { x = x * 10 + c - 0 ; c = getchar(); } return x * f; } int n, m,...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 123; const int MINN = 1e3 + 123; const int mod = 1e9 + 7; const int INF = 1e9 + 1; pair<int, int> a[MINN]; bool cmp(pair<int, int> a, pair<int, int> b) { if (a.first < b.first) return 1; if (a.first == b.first) if (a.second...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 100; int m, n; long long sweets[MAXN]; vector<long long> sol; long long weightedSum; long long sums[MAXN]; int main() { cin >> n >> m; for (int i = 0; i < n; i++) { cin >> sweets[i]; } sort(sweets, sweets + n); ...
#include <bits/stdc++.h> using namespace std; struct MP { long long g[310][310]; } f[10], nil, tmp, c; int n, m, x, y, z1, z2, ans; void U(long long &x, long long y) { x = max(x, y); } MP CC(MP &f1, MP &f2) { MP res = nil; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) { ...
#include <bits/stdc++.h> const long long oo = 2 * 1000 * 1000 * 1000; const int _cnt = 1000 * 1000; const int _p = 1000 * 1000 * 1000 + 7; long long o(long long x) { return x % _p; } int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int lcm(int a, int b) { return a * b / gcd(a, b); } using namespace...
#include <bits/stdc++.h> const int N = 1e6 + 6, mod = 1e9 + 7; int n, sum[3]; inline int read() { int s = 0, f = 1; char ch; for (; ch < 0 || ch > 9 ; ch = getchar()) if (ch == - ) f = -1; for (; ch >= 0 && ch <= 9 ; ch = getchar()) s = (s << 1) + (s << 3) + ch - 0 ; return...
#include <bits/stdc++.h> using namespace std; const long long N = 200001; long long par[N], siz[N]; long long f(long long n) { if (n == par[n]) return n; else return par[n] = f(par[n]); } void u(long long a, long long b) { a = f(a); b = f(b); if (a != b) { if (siz[a] < ...
#include <bits/stdc++.h> using namespace std; void _print(long long t) { cerr << t; } void _print(int t) { cerr << t; } void _print(string t) { cerr << t; } void _print(char t) { cerr << t; } void _print(long double t) { cerr << t; } void _print(double t) { cerr << t; } void _print(unsigned long long t)...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const double pi = acos(-1.0); const long long INF = 0x3f3f3f3f3f3f3f3f; const int inf = 0x3f3f3f3f; const long long mod = 1e9 + 7; const int N = 1e5 + 10; struct zz { long long x, y; } a[N]; bool check(zz z1, zz z2, zz y1, zz...
#include <bits/stdc++.h> using namespace std; int main() { int k, r, shovel = 1; cin >> k >> r; while ((k % 10) * shovel % 10 != r && (k % 10) * shovel % 10) shovel++; cout << shovel; }
#include <bits/stdc++.h> const int INF = 1 << 29; int cmp(const void* a, const void* b); long long maxv(long long a, long long b); long long minv(long long a, long long b); long long gcd(long long u, long long v); int main() { char s[] = aeiou ; long long k, n, m; scanf( %lld , &k); if (k <...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const double eps = 1e-9; const int Mod = 1e9 + 7; const int MaxN = 2e5 + 5; char s[MaxN]; int a[MaxN]; int l[MaxN], r[MaxN]; bool cmp(int x, int y) { return x > y; } int main() { int n, k; scanf( %d %d , &n, &k); f...
#include<bits/stdc++.h> #define pb push_back #define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0) #define ll long long #define pii pair<int,int> #define pll pair<ll,ll> #define f first #define s second #define int long long #define sz(x) (ll)(x.size()) using namespace std; ...
#include <bits/stdc++.h> using namespace std; int fastio() { ios_base::sync_with_stdio(false); cout << fixed << setprecision(10); cin.tie(nullptr); return 0; } int __fastio = fastio(); void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr <...
#include <bits/stdc++.h> using namespace std; vector<int> vt; int n; inline bool judge(int i) { int ans = i; while (i) { ans += i % 10; i /= 10; } return ans == n; } int main(void) { std::ios::sync_with_stdio(false); cin.tie(0); while (cin >> n) { vt.clear(); ...
#include <bits/stdc++.h> using namespace std; void read(long long &x) { scanf( %lld , &x); } const long long N = 1000005; struct city { long long cnt, id; bool operator<(const city b) const { return cnt < b.cnt; } } a[N]; struct que { long long x, id; bool operator<(const que b) const { retu...
#include <bits/stdc++.h> #pragma GCC target( avx2 ) #pragma GCC optimization( O3 ) #pragma GCC optimization( unroll-loops ) using namespace std; template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << { << p.first << , << p.second << } ; return os; } co...
#include <bits/stdc++.h> using namespace std; const long long inf = 1LL << 61; const long long mod = 1000000007; const int maxn = 404; bitset<maxn> cb[30][maxn]; bitset<maxn> ans[maxn]; bitset<maxn> shift(bitset<maxn> b, int len, int sh); int main() { std::ios::sync_with_stdio(false); int i = 0,...
#include <bits/stdc++.h> using namespace std; const int maxn = (int)3e5 + 10; struct node { int nxt, to; } edg[maxn * 2]; int head[maxn], num; int f[maxn], n, a[maxn]; void add(int a, int b) { edg[++num].to = b; edg[num].nxt = head[a]; head[a] = num; } int k = 0; void dfs(int root) {...
#include <bits/stdc++.h> using namespace std; int n, a, b, k, tt; int tree1[800000], tree2[800000]; void updata1(int L, int R, int ro, int x, int v) { if (x < L || x > R) return; if (L == R && L == x) { tree1[ro] = min(v + tree1[ro], b); return; } int Mid = (L + R) / 2; updata1(L...
#include <bits/stdc++.h> using namespace std; long long fa2[200007], fb2[200007]; bool f(int i, int j, long long y) { long long x1, x2; if ((y - fb2[i]) % fa2[i] == 0) { x1 = (y - fb2[i]) / fa2[i]; } else x1 = (y - fb2[i]) / fa2[i] + 1; if ((y - fb2[j]) % fa2[j] == 0) { x2 = (y -...
#include <bits/stdc++.h> using namespace std; long long n, m, a, b, x, y, z, ans, g[3010 * 3010], h[3010][3010], f[3010][3010]; deque<long long> q, zr; int main() { scanf( %lld%lld%lld%lld%lld%lld%lld%lld , &n, &m, &a, &b, g, &x, &y, &z); for (int i = 1; i <= n * m; i++) g[i] = (g[i - 1] * x + y) ...
#include <bits/stdc++.h> using namespace std; const double pie = 3.14159265358979323846; int32_t main() { ios::sync_with_stdio(false); cin.tie(NULL); double d, h, v, e, t = 0; cin >> d >> h >> v >> e; if (v <= (pie * (d / 2) * (d / 2) * e)) { cout << NO n ; } else { t = (pie *...
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 35; const int N = 2e5; const long long mod = 1e7; const double eps = 1e-6; int a[MAX]; long long n; long long ans; pair<long long, long long> ch(long long x) { long long x2 = n - x; long long s = x; s += (x2 * (x2 - 1)) / ...
#include <bits/stdc++.h> using namespace std; inline int read() { static int r, sign; static char c; r = 0, sign = 1; do c = getchar(); while (c != - && (c < 0 || c > 9 )); if (c == - ) sign = -1, c = getchar(); while (c >= 0 && c <= 9 ) r = r * 10 + (int)(c - 0 ), c = getchar(...
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; const int dy[] = {-1, 1, 0, 0}; const int dx[] = {0, 0, -1, 1}; int n, m; string s[1010]; int L[1010][1010]; int R[1010][1010]; int U[1010][1010]; int D[1010][1010]; int usedX[1010][1010], usedY[1010]...