func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; const int N = 1e5 + 2; const int M = 1 << 19; const int inf = 2e9; const long long linf = 1e18; long long n, m, k; int ok(long long mid) { long long ans = 0; for (int i = 1; i <= n; i++) { ans += min(m, mid / i)...
#include <bits/stdc++.h> using namespace std; double pi = M_PI; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { long long n; cin >> n; n = n * 2; double angle = ((n - 2) * M_PI) / (2 * n); cout << fixed << set...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int tc; cin >> tc; while (tc--) { int n; cin >> n; priority_queue<pair<int, int> > pq; for (int i = 0; i < n; i++) { int ai; cin >> ai; pq.push(pair...
#include <bits/stdc++.h> using namespace std; const long long int N = 2e5 + 5; void solve() { long long int n; cin >> n; long long int k = sqrt(n); long long int sum = 0; if (n == k * k) { cout << 4 * k << n ; return; } sum = sum + k * 4; n = n - (k * k); if (n > ...
#include <bits/stdc++.h> using namespace std; const int N = 100005; vector<int> g[N], ans; bool vis[N]; int x[N]; void Set(int u) { x[u] ^= 1; ans.push_back(u); } void dfs(int u) { Set(u); vis[u] = 1; for (int i = 0; i < g[u].size(); ++i) { int v = g[u][i]; if (vis[v]) co...
#include <bits/stdc++.h> const int T_DATA = 100000; const int N = 100000; int T; int a, b; char mp[N + 10]; int n, m; int l[N + 10], r[N + 10]; int dis[N + 10]; int main() { scanf( %d , &T); while (T--) { scanf( %d %d , &a, &b); scanf( %s , mp + 1); n = strlen(mp + 1); ...
#include <bits/stdc++.h> using namespace std; template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << ( << p.first << , << p.second << ) ; } template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container...
#include <bits/stdc++.h> using namespace std; int NumberOfJus; double n; double sum; int main() { cin >> NumberOfJus; for (int i = 0; i < NumberOfJus; i++) { cin >> n; sum += n / NumberOfJus; } cout << sum; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxbuff = 1 << 17; char ibuff[maxbuff], obuff[maxbuff]; inline char Getchar() { static char *p1 = ibuff, *p2 = ibuff; if (p1 == p2) { p1 = ibuff; p2 = ibuff + fread(ibuff, 1, maxbuff, stdin); if (p1 == p2) return -1; } ret...
#include <bits/stdc++.h> using namespace std; pair<long long, long long> a[1000000]; long long ans = 0; bool check(long long k, pair<long long, long long> l, pair<long long, long long> r) { long long cur = abs(k - l.second) + abs(k - r.second); if (cur <= r.first - l.first) { return t...
#include <bits/stdc++.h> using namespace std; long long int key[300005], dia[300005], m1[300005], m2[300005], dp1[300005], dp2[300005]; vector<long long int> kv[300005], adj[300005]; bool mrk[300005]; inline void dfs(long long int x, long long int pr, long long int root) { if (mrk[x]) return; mr...
#include <bits/stdc++.h> using namespace std; const int maxn = 1010, maxm = 1 << 16, INF = 1e9; int n, dp[2][maxm], a[5], cMask[maxn]; vector<int> optionalMasks[5]; string s[4]; int addColumn(int column, int mask) { return (mask >> 4) | (cMask[column] << 12); } int main() { scanf( %d , &n); ...
#include <bits/stdc++.h> using namespace std; int const N = 100000; vector<pair<int, int> > g[N + 1]; vector<int> imp; long long cl[42][N + 1]; int dp[N + 1], n; pair<int, long long> pa[N + 1][17]; bool vis[N + 1]; void pl(int v = 1, int p = 0, int w = 0) { dp[v] = dp[p] + 1; vis[v] = true; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; int n, m; int low[maxn], dfn[maxn], v[maxn << 1], A[maxn]; int nxt[maxn << 1], head[maxn], belong[maxn], a[maxn], vis[maxn << 1]; stack<int> s; int indexs = 0, cnt = 0; int ans = 0; void add_edge(int x, int y) { static int N = ...
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; if (a == b) { cout << infinity ; return 0; } if (a < b) { cout << 0; return 0; } a -= b; int s = 0; for (int i = 1; i * i <= a; i++) if (a % i == 0) { s += (...
#include <bits/stdc++.h> using namespace std; const long long int inf = INT_MAX; const long long int mod = 1000000007; long long int gcd(long long int a, long long int b) { if (b == 0) return a; return gcd(b, a % b); } long long int lcm(long long int a, long long int b) { return (a / gcd(a, b)) ...
#include <bits/stdc++.h> using namespace std; long long b = 0, s = 0, c = 0; long long nb, ns, nc; long long pb, ps, pc; long long r; bool isPoss(long long m) { long long rnb = b * m - nb < 0 ? 0 : b * m - nb; long long rns = s * m - ns < 0 ? 0 : s * m - ns; long long rnc = c * m - nc < 0 ? 0 : ...
#include <bits/stdc++.h> using namespace std; const int N = 23, M = 2e4 + 1e3 + 7, P = 998244353; int n; int cnt[N][26], pw[M]; char s[M]; int f[1 << N]; int mn[26]; int main() { pw[0] = 1; for (int i = 1; i < M; i++) pw[i] = pw[i - 1] * 2 % P; scanf( %d , &n); for (int i = 0; i < n; i++...
#include <bits/stdc++.h> using namespace std; string S; int ans; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); for (int i = 1; i <= 3; i++) { getline(cin, S); ans = 0; for (int j = 0; j < S.length(); j++) { if (S[j] == a || S[j] == i || S[j] ==...
#include <bits/stdc++.h> using namespace std; long long int a[200000]; long long int left1[200000][2]; long long int right1[200000][2]; long long int ans[200000]; int main() { long long int n; cin >> n; left1[1][0] = 0; right1[n][0] = 0; for (long long int i = 1; i <= n; i++) cin >> a[i]...
#include <bits/stdc++.h> using namespace std; vector<int> poz[100]; int main() { string s; cin >> s; for (int i(0); i <= 26; i++) poz[i].push_back(-1); for (int i(0); i < s.size(); i++) poz[s[i] - a ].push_back(i); for (int i(0); i <= 26; i++) poz[i].push_back(s.size()); int kmin = s.size...
#include <bits/stdc++.h> using namespace std; using ll = int64_t; using vll = vector<ll>; using vvll = vector<vll>; using pll = pair<ll, ll>; using vpll = vector<pll>; using vvpll = vector<vpll>; bool sorted(int arr[], int n) { bool f1 = 1, f2 = 1; for (int i = 0; i < n - 1; i++) { if (arr...
#include <bits/stdc++.h> using namespace std; int main() { string s; long long int n; cin >> n; getline(cin, s); getline(cin, s); long long int l = s.length(); long long int a = 0, ii = 0, f = 0; for (long long int i = 0; i < l; i++) { if (s[i] == A ) { a++; } el...
#include <bits/stdc++.h> using namespace std; const long long MOD = 998244353; long long mul(long long a, long long b) { return (a * b) % MOD; } long long bin_pow(long long a, long long p) { if (p == 0) return 1; long long ans = bin_pow(mul(a, a), p / 2); if (p % 2) ans = mul(ans, a); return ans...
#include <bits/stdc++.h> using namespace std; int main() { int n, x[101] = {0}, i, a, m = 0; cin >> n; for (i = 0; i < n; i++) { cin >> a; x[a]++; } for (i = 0; i <= 100; i++) { if (x[i] > m) m = x[i]; } cout << m; }
#include <bits/stdc++.h> using namespace std; int a[100 + 10]; int main() { int n; while (~scanf( %d , &n)) { int p1, p2, p3, t1, t2; scanf( %d%d%d%d%d , &p1, &p2, &p3, &t1, &t2); int ans = 0; int temp, len = 0; for (int i = 1; i <= n; i++) { int x, y; scanf( ...
#include <bits/stdc++.h> const int MAX_L = 2005; const int INF_INT = 0x3f3f3f3f; const long long INF_LL = 0x7fffffff; const int MOD = 1e9 + 7; const double eps = 1e-9; const double pi = acos(-1); using namespace std; int n; int a[26], b[26][26]; int main() { while (cin >> n) { string s; ...
#include <bits/stdc++.h> using namespace std; void task(); int main() { srand(time(0)); ios_base::sync_with_stdio(0); task(); return 0; } const int INF = 0x3f3f3f3f; const int N = 1e6 + 10; const int M = 1e5 + 10; struct SufAutomaton { struct State { int len; int link; ...
#include <bits/stdc++.h> using namespace std; struct node { int a, v, c, next; node() {} node(int a, int v, int c, int next) : a(a), v(v), c(c), next(next) {} } edge[200010]; struct pp { int v, d1, d2; }; queue<int> q; int n, m, tot; int dis[100010], d[100010], pre[100010], ans[100010], ...
#include <bits/stdc++.h> using namespace std; long long pow1(long long a, long long b) { if (b == 0) return 1; if (b == 1) return a; long long ab = pow1(a, b / 2) % 1000000007; if (b % 2 == 0) return (ab * ab) % 1000000007; else return ((ab * ab) % 1000000007 * a) % 1000000007; } ...
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n; cin >> n; vector<long long> arr(n, 0); vector<long long> pref(n, 0); vector<long long> suff(n, 0); map<long long, long long> pre; map<lo...
#include <bits/stdc++.h> namespace FASTIO { char buf[1 << 21]; char *p1, *p2; template <typename T> inline void wt(T x, char c = n ) { if (x < 0) { x = -x; putchar( - ); } static char sta[sizeof(T) * 8]; T top = 0; do { sta[top++] = x % 10; x /= 10; } while (x...
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 10; int n, pre[maxn], son[maxn], dep[maxn], Ans[maxn], cnt, lis[maxn]; vector<int> g[maxn]; int main() { scanf( %d , &n); dep[1] = 1; for (int i = 1; i < n; i++) { scanf( %d , &pre[i + 1]); pre[i + 1]++; g[pr...
#include <bits/stdc++.h> using namespace std; int n, m; char s[110][110]; void work1() { if (n % 3) { puts( NO ); return; } int k = n / 3; if (s[0][0] == s[k][0] || s[0][0] == s[k * 2][0] || s[k][0] == s[k * 2][0]) { puts( NO ); return; } for (int h = 0; h < 3; h+...
#include <bits/stdc++.h> unsigned *G[222222], Ga[222222], Gi[222222]; void add(unsigned i, unsigned j) { if (Ga[i] == Gi[i]) { if (!Ga[i]) G[i] = (unsigned *)calloc(Ga[i] = 1, sizeof(unsigned)); else G[i] = (unsigned *)realloc(G[i], (Ga[i] <<= 1) * sizeof(unsigned)); } G[i][G...
#include <bits/stdc++.h> using namespace std; int const MAXN = 2e5 + 10; int n; int a[MAXN], L[MAXN * 30], R[MAXN * 30]; struct Trie { int tot = 1; int trie[MAXN * 30][2]; void insert(int pos) { int x = 1; for (int i = 30;; i--) { int dir = (a[pos] >> i) & 1; L[x] = min...
#include <bits/stdc++.h> #pragma GCC optimize( O3 , unroll-all-loops ) #pragma GCC target( sse4.2 ) using namespace std; ifstream in; ofstream out; const long long kk = 1000; const long long ml = kk * kk; const long long mod = 998244353; const long long inf = ml * ml * ml + 7; const int C = 5; mt...
#include <bits/stdc++.h> using namespace std; int main() { int a1, a2, a3, a4; scanf( %d %d %d %d , &a1, &a2, &a3, &a4); int n = min(min(a1, a4), a3); long long ans = 0; ans += n * 256; a1 -= n; a3 -= n; a4 -= n; int m = min(a1, a2); ans += m * 32; printf( %lld n , ans); ...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const long long inf = 1e14; long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, ans = 0; c...
#include <bits/stdc++.h> using namespace std; int rem = 1000000007; vector<long long> v; vector<long long> d(21); vector<long long> down(21); long long n, s; long long binpow(long long a, long long n) { if (n == 0) return 1; long long tmp = binpow(a, n / 2); if (n & 1) return tmp * tmp % rem *...
#include<bits/stdc++.h> using namespace std; int a[305]; int main() { int t; cin>>t; while(t--) { int n,x; cin>>n; string s; cin>>s; bool flag=false; if(s== 2020 ) flag=true; else { ...
#include <bits/stdc++.h> using namespace std; vector<int> adj[100005]; bitset<100005> vis; int nodes = 0, edges = 0; void dfs(int v) { nodes++; vis[v] = true; for (auto nv : adj[v]) { if (!vis[nv]) dfs(nv); edges++; } } int main() { int n, k; scanf( %d%d , &n, &k); ...
#include <bits/stdc++.h> using namespace std; long long power(long long a, long long b) { long long ans = 1; while (b > 0) { if (b % 2 != 0) { ans = (ans * a) % 1000000007; } a = (a * a) % 1000000007; b >>= 1; } return ans; } int main() { std::ios::sync_with_s...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7; void read(long long &x) { x = 0; char ch = getchar(); long long pd = 1; while (ch < 0 || ch > 9 ) { if (ch == - ) { pd = -pd; } ch = getchar(); } while (ch >= 0 && ch <= 9 ) { x = x ...
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; const long long nax = 1e5 + 100; long long n, m; signed main() { cin >> n >> m; long long dp[n][m], a[n][m]; for (long long i = 0; i < n; i++) for (long long j = 0; j < m; j++) { cin >> a[i][j]; dp...
#include <bits/stdc++.h> using namespace std; long long rdtsc() { long long tmp; asm( rdtsc : =A (tmp)); return tmp; } inline int myrand() { return abs((rand() << 15) ^ rand()); } inline int rnd(int x) { return myrand() % x; } const int maxn = (int)1e5; char s[maxn + 1]; long long hs[maxn ...
#include <bits/stdc++.h> using namespace std; int dp[105][105][12]; int main() { int n, C, q; scanf( %d%d%d , &n, &q, &C); for (int i = 1; i <= n; i++) { int a, b, c; scanf( %d%d%d , &a, &b, &c); dp[a][b][c]++; } for (int i = 1; i <= 100; i++) for (int j = 1; j <= 100; ...
#include <bits/stdc++.h> using namespace std; map<string, int> fr; int main() { ios_base::sync_with_stdio(false); string s; cin >> s; for (int k = 0; k <= 9; k++) { string a; cin >> a; fr[a] = k; } int id = 0; string act = ; for (int k = 0; k < 80; k++) { ...
#include <bits/stdc++.h> using namespace std; const int mxn = 1e5 + 10; int n, m; bool jest[410][410]; bool vis_sam[mxn], vis_poc[mxn]; int sam[mxn], poc[mxn]; void wczytaj() { scanf( %d%d , &n, &m); for (int i = 1; i <= m; i++) { int a, b; scanf( %d%d , &a, &b); jest[a][b] = tru...
#include <bits/stdc++.h> using namespace std; const int N = 5050, b = 53, mod = 1073676287; int n, q, pre[N], suf[N], ans[N], binv[N], dp[N][N]; int mul(int x, int y) { return (x * 1ll * y) % mod; } int add(int x, int y) { return ((x + y) % mod + mod) % mod; } int pw(int b, int p) { if (!p) return 1; ...
#include <bits/stdc++.h> using namespace std; int n, m; int a[20]; int main() { cin >> n >> m; for (int t, i = 1; i <= n; i++) { cin >> t; a[t]++; } int ans = 0; for (int i = 1; i <= m; i++) for (int j = i + 1; j <= m; j++) ans += a[i] * a[j]; cout << ans; }
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > ke[105]; int d[105], x[105], y[105], a[105]; int n, m, s, t, module; void dijkstra() { set<pair<int, int> > q; for (int u = 1; u <= n; ++u) d[u] = 1000000007; d[1] = 0; q.insert(make_pair(d[1], 1)); while (!q.empty()) { ...
#include <bits/stdc++.h> const long long MOD = 1e9 + 7; const long long MAXN = 1e6 + 1; using namespace std; long long readInt() { bool minus1 = false; long long result = 0; char ch; ch = getchar(); while (true) { if (ch == - ) break; if (ch >= 0 && ch <= 9 ) break; ch ...
#include <bits/stdc++.h> using namespace std; long long int mod = 1000000007; long long int max(long long int a, long long int b) { if (a > b) return a; else return b; } long long int min(long long int a, long long int b) { if (a < b) return a; else return b; } long...
#include <bits/stdc++.h> using namespace std; long long n; int main() { ios_base::sync_with_stdio(false); cin >> n; cout << (n - 3) * (n - 1) + 1; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; long long l = s.size(); for (long long i = 1; i < l - 1; i++) { if (s[i] == s[i - 1]) { if (s[i - 1] != a && s[i + 1] != a ) s[i] = a ; else if (s[i - 1] != b && s[i + 1] != b ) ...
#include <bits/stdc++.h> using namespace std; int main() { unsigned long long int ops = 0; long long int x, y, m; cin >> x >> y >> m; if (x >= m || y >= m) { cout << 0 << endl; return 0; } if (x <= 0 && y <= 0) { cout << -1 << endl; return 0; } long long int m...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int mod2 = 1e9 + 9; const int maxN = 5e5 + 100; const int INF = 1e9 + 7; const int maxedge = 1e6 + 100; const long long LL_INF = 1e18 + 11; using namespace std; long long n, ans; map<long long, long long> ma; void file() ...
#include <bits/stdc++.h> using namespace std; char s[1010][3][50]; bool p[1010]; int main() { int n, i, j, c; cin >> n; for (i = 1; i <= n; i++) cin >> s[i][1] >> s[i][2]; memset(p, true, sizeof(p)); for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) { if (i != j) { ...
#include <bits/stdc++.h> using namespace std; const int N = 1.5e3 + 5; const int T = 1e5 + 5; const int mod = 1e9 + 7; int n, m, a, b, p, t; int fac[T], inv[T], res; int P[N], F[N], SP[N], SPL[N], S[N][N], L[N][N]; namespace _ { inline int mul(int x, int y) { return 1ll * x * y % mod; } inline int d...
#include <bits/stdc++.h> using namespace std; int matrix[105][105]; int vis[105][105]; int main() { int n, k; while (scanf( %d%d , &n, &k) != EOF) { memset(matrix, 0, sizeof(matrix)); memset(vis, 0, sizeof(vis)); if (k > n * n) { printf( -1 n ); continue; } ...
#include <bits/stdc++.h> using namespace std; const int N = 1e4 + 5; long long int dp[N][102]; int main() { int n, k, m; scanf( %d%d%d , &n, &k, &m); for (int i = 1; i <= 9; i++) dp[1][i % k]++; long long int wynik = 0, p = 1; for (int x = 1; x <= n - 1; x++) { p = (p * 10) % k; ...
#include <bits/stdc++.h> using namespace std; const int N = 1000006, B = 1000001969; int n, k, m, L[N], R[N]; char a[N], b[N]; long long a1[N], M[N]; set<int> Set; int actual(int x) { auto it = Set.lower_bound(x); return it == Set.end() ? n + 1 : *it; } void hash_build(char a[], int n, long lo...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n; cin >> n; long long int arr[n], i, c = 0; for (i = 0; i < n; i++) { cin >> arr[i]; if (arr[i] == 1) c++; } if (c == n) { for (i = 0; i < n - ...
#include <bits/stdc++.h> using namespace std; unsigned N, M; vector<unsigned> V; double dens(const unsigned idxV1, const unsigned idxV2, const unsigned eW) { if (eW == 0) { return 0; } return (double)(V[idxV1] + V[idxV2]) / (double)eW; } int main() { unsigned v1, v2, w, n, m; doubl...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int N = 2e6 + 10; const long long mod = 1000000007; const double eps = 1e-9; const double PI = acos(-1); template <typename T> inline void read(T &a) { char c = getchar(); T x = 0, f = 1; while (!isdigit(c)) { ...
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); ; int T; cin >> T; while (T--) { int n; string s; cin >> n; cin >> s; int arr[200002]; int cnt = 1; int idx = 1; char x = s[0]...
#include <bits/stdc++.h> using namespace std; int main() { int n, i; cin >> n; cout << (n / 2) + 1 << endl; for (i = 1; i <= (n / 2) + 1; i++) cout << i << 1 << endl; ; if (n % 2 != 0) for (i = 2; i <= (n / 2) + 1; i++) cout << (n / 2) + 1 << << i << endl; else for (i ...
#include <bits/stdc++.h> using namespace std; const long long int inf = 1000000000; const long long int mod = 1000000000 + 7; inline void IO() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } inline int dcmp(long double x) { return x < -1e-12 ? -1 : (x > 1e-12); } template <class T> ...
#include <bits/stdc++.h> using namespace std; void dbg_out() { cerr << b b] n ; } template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << H << , ; dbg_out(T...); } void solve() { long double n; cin >> n; cout << fixed << setprecision(10); if (n == 2) ...
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; vector<long long int> a(n); for (auto &it : a) cin >> it; long long o = (n + 1) / 2, e = n / 2; for (auto it : a) { if (!it) continue; if (it % 2) o--; else e--; } lo...
#include <bits/stdc++.h> using namespace std; void read() { return; } void wrt() { cout << (string) n ; } void wrt(long long t) { cout << t; } void wrt(int t) { cout << t; } void wrt(char t) { cout << t; } void wrt(string t) { cout << t; } void wrt(double t) { cout << t; } template <class T> void ...
#include <bits/stdc++.h> using namespace std; int dp[100006][2]; int main(void) { string s; cin >> s; int len = s.size(); memset(dp, -1, sizeof(dp)); dp[0][0] = 0; dp[0][1] = 0; for (int i = 1; i <= len; ++i) { dp[i][1] = dp[i - 1][1] + (bool)islower(s[i - 1]); dp[i][0] = m...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 100, mod = 998244353; int n, c[N], s[N]; int qpow(int x, int y) { int res = 1; while (y) { if (y & 1) res = 1ll * res * x % mod; x = 1ll * x * x % mod, y >>= 1; } return res; } int main() { scanf( %d , &n); ...
#include <bits/stdc++.h> using namespace std; int a[100007], b[100007]; vector<int> v, ans; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m, x; cin >> n >> m; for (int i = 0; i < n; i++) cin >> x, a[x]++; for (int i = 0; i < n; i++) cin >> x, b[m - x - 1]++; for (int ...
#include <bits/stdc++.h> using namespace std; int popc(long long int x) { int cnt = 0; for (int i = 0; i < 50; i++) { if ((1ll << i) & x) cnt++; } return cnt; } int main() { ios_base::sync_with_stdio(0); long long int s, x; cin >> s >> x; if (s < x) { cout << 0 n ; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int p = 1; int diagjump = n + 1; for (int i = 1; i <= n; i++) { p = i; for (int j = 1; j <= n; j++) { cout << p << ; if (p == n * j) p++; else p += diagjump; ...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } bool checkprime(long long n) { long long i = 2; while (i * i <= n) { if (n % i == 0) return 0; i++; } return 1; } long long fact(long long...
#include <bits/stdc++.h> using namespace std; bool flag; int n, k, vis[10][105]; char s[10][105]; int judge(int x, int y) { if ((s[x][y] == . || s[x][y] == s ) && (x >= 1 && x <= 3)) return 1; else return 0; } void dfs(int x, int y) { vis[x][y] = 1; if (y >= n - 1) { f...
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long t; cin >> t; while (t--) { long long n; cin >> n; long long a, b, c; cin >> a >> b >> c; string s; cin >> s; long...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; const ll INF = 1e18; const ll MOD = 1e9 + 7; const ld EPS = 1e-10; const ld PI = acos(-1); vector<ll> po[2]; ll n, k; pair<ll, ll> CountHash(ll x, ll ind, ll q) { ll h1 =...
#include <bits/stdc++.h> using namespace std; const int maxN = 2000 + 5; int s, n, m, a[maxN]; vector<int> p[maxN]; vector<int> f[maxN], g[maxN]; void initialize() { ios::sync_with_stdio(false); cin >> n >> s; s--; for (int i = 0; i < n; ++i) cin >> a[i]; vector<int> t(a, a + n); sor...
#include <bits/stdc++.h> using namespace std; long long n, num, m; map<long long, bool> isInsert; priority_queue<long long, vector<long long>, greater<long long> > pq; vector<string> vs; vector<long long> vi; int main() { m = 0; cin >> n; while (n--) { string s; cin >> s; if ...
#include <bits/stdc++.h> int team[1000010][2], ans[1010], n, x; bool used[1010]; int main() { scanf( %d , &n); n *= 2; for (int i = 1; i <= n; i++) for (int j = 1; j < i; j++) { scanf( %d , &x); team[x][0] = i; team[x][1] = j; } used[0] = 1; for (int i = 100...
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> inline void chkmin(T1& a, T2 b) { if (a > b) a = b; } template <typename T1, typename T2> inline void chkmax(T1& a, T2 b) { if (a < b) a = b; } using ll = long long; using d = double; using ld = long double; ...
#include <bits/stdc++.h> using namespace std; const long long LL_INF = (long long)2e18 + 5; struct point { long long x, y; point() : x(0), y(0) {} point(long long _x, long long _y) : x(_x), y(_y) {} }; struct reverse_monotonic_dp_hull { vector<point> points; int size() const { return (int)...
#include <bits/stdc++.h> using namespace std; int judge(int n) { int flag = 0; for (int i = 2; i <= n / 2; i++) { if (n % i == 0) { flag = 1; break; } } if (flag) return 0; else return 1; } int main() { int n; cin >> n; for (int i = 1; i <=...
#include <bits/stdc++.h> using namespace std; const long long int inf = 1e18; const int N = 1e5 + 5; void solve() { int n; cin >> n; set<int> st; for (int i = 0; i < n; i++) { int x; cin >> x; if (x % 2 == 0) st.insert(x); } int ans = 0; while (!st.empty()) { ...
#include <bits/stdc++.h> using namespace std; void read(int &n) { n = 0; int s = 1; char c; for (; (c = getchar()) > 9 || c < 0 ;) if (c == - ) s = -1; for (; c >= 0 && c <= 9 ; c = getchar()) n = (n << 1) + (n << 3) + c - 48; n *= s; } void write(int n) { if (!n) putcha...
#include <bits/stdc++.h> using namespace std; const long long maxN = 1e5 + 13; long long root, sz[maxN], h[maxN], ans, val[maxN], m, n, pw[maxN], pre[maxN]; map<long long, long long> mp; vector<long long> vec; vector<pair<long long, long long>> adj[maxN]; bool mark[maxN], fl; void dfs(long long v, long ...
#include <bits/stdc++.h> using namespace std; void solve() { int n, M; cin >> n >> M; vector<char> s(n); int m = M; vector<int> p(m), b(n), yes(n, 0), cnt(26, 0); for (int i = 0; i < n; i++) { cin >> s[i]; cnt[s[i] - a ]++; } for (int i = 0; i < m; i++) { cin >> p[...
#include <bits/stdc++.h> using namespace std; struct tree { tree() : par(NULL), val(0) { next.clear(); }; map<int, tree *> next; tree *par; int val; void setParent(tree *p) { par = p; } }; tree *moveDown(tree *root, int n) { tree *ret = NULL; if (root->next.count(n)) { ret = ro...
#include <bits/stdc++.h> using namespace std; long long inv(long long a, long long mod) { long long b = mod, p = 1, q = 0; while (b) { long long c = a / b, d = a; a = b; b = d % b; d = p; p = q; q = d - c * q; } return (p + mod) % mod; } map<tuple<long long, l...
#include <bits/stdc++.h> using namespace std; double ans = 1111111111; int ap[111111], bp[111111], bt[111111], n, m, a, b, l, r, m1, m2, minap, minbp; double dist(double ax, double ay, double bx, double by) { return sqrt((bx - ax) * (bx - ax) + (by - ay) * (by - ay)); } double f(int i, int j) { retu...
#include <bits/stdc++.h> using namespace std; int main() { int n, i, sum, sum1, count = 1; cin >> n; int arr[4 * n + 1]; arr[0] = 0; for (i = 1; i <= 4 * n - 3; i = i + 4) { cin >> arr[i] >> arr[i + 1] >> arr[i + 2] >> arr[i + 3]; if (i == 1) sum = arr[1] + arr[2] + arr[3] + ...
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-10; const double PI = acos(-1.0); template <class T> T gcd(T a, T b) { for (T c; b; c = a, a = b, b = c % b) ; return a; } template <class T> void out(const vector<T> &a) { for (int i = 0; i < ((int)(a).size()); ++i) c...
#include <bits/stdc++.h> using namespace std; inline void read(int &x) { int v = 0, f = 1; char c = getchar(); while (!isdigit(c) && c != - ) c = getchar(); if (c == - ) f = -1; else v = v * 10 + c - 0 ; while (isdigit(c = getchar())) v = v * 10 + c - 0 ; x = v * f; } ...
#include <bits/stdc++.h> using namespace std; const long long N = 2 * 1e5 + 100; long long n, m, k, w, a[N], d[N], p[N], fa[N], vi[N]; long long tot, first[N], nxt[N * 2], point[N * 2], len[N * 2]; priority_queue<pair<long long, long long>, vector<pair<long long, long long> >, greater<pair<lo...
#include <bits/stdc++.h> char input[5001]; int data[1000]; using namespace std; int main() { int r = 0; stack<int> s; char temp[10]; int b = 0, p, count; while (scanf( %s , input) != EOF) { for (int i = 0; i < strlen(input); i++) { if (input[i] == < ) { count = 0; ...
#include <bits/stdc++.h> using namespace std; void solve() {} int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; long long k = 1; vector<long long> v; while (1) { long long tmp = ((1 << k) - 1) * (1 << (k - 1)); if (tmp > 100001) break; v.p...