func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int a, b, c; int main() { cin >> a >> b >> c; int ans = 0; for (int i = 0; i <= c; i += a) { if ((c - i) % b == 0) ans++; } if (ans == 0) cout << No ; else cout << Yes ; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxint = -1u >> 2; const double eps = 1e-6; const int MAX = 100001; int CA[MAX]; int CB[MAX]; int main() { int N; cin >> N; int ans = N + 1; if (N == 1 || N == 2) { cout << 0 << endl; return 0; } vector<int> A(N); ...
#include <bits/stdc++.h> using namespace std; const int N = 100000 + 7; int n, m, comp[N], y, spre[N]; bool vis[N]; vector<int> g[N], ig[N], ord, rep[N]; set<int> sgn[N]; void dfs1(int a) { vis[a] = 1; for (auto &b : g[a]) { if (!vis[b]) { dfs1(b); } } ord.push_back(a);...
#include <bits/stdc++.h> using namespace std; bool func(int x) { int cnt = 0; while (x != 0) { x = x / 10; cnt++; } if (cnt == 1) return true; else if (cnt == 2) return false; else if (cnt == 0) return true; } int main() { int h1, h2, m1, m2; int h, ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:40000000 ) using namespace std; const double EPS = 1e-10; const double PI = acos(-1.0); const int mod = 1000000007; const int MAXN = 200 * 200; int a[111]; int n; int main() { cin >> n; bool p = 1; for (int(i) = (0); (i) < (n); ++(i)...
#include <bits/stdc++.h> using namespace std; void Append(const string& w, string& a) { a += w; a += , ; } bool IsNumber(const string& w) { for (char c : w) { if (!isdigit(c)) return false; } return !w.empty() && (w == 0 || w[0] != 0 ); } void Process(const string& s, int start...
#include <bits/stdc++.h> using namespace std; long long f(long long x) { int num = 0; for (int i = 1; 1ll * i * i <= x; i++) { if (x % i) continue; num++; if (1ll * i * i != x) num++; } return num; } long long solve(vector<int> v) { int n = v.size(); long long num = 1ll...
#include <bits/stdc++.h> const int N = 1000005; using namespace std; long long n, k, sum, q, res, m, val, ans; long long x, y; double p; long long xx[] = {1, 0, -1, 0}; long long yy[] = {0, 1, 0, -1}; void solve(long long no) { cin >> n; long long res = 0; vector<long long> v[64]; for (i...
#include <bits/stdc++.h> using namespace std; void solve() { int n, m; cin >> n >> m; int sz = n + m - 2; int mid = sz / 2; int x; vector<pair<int, int>> a(mid + 1, {0, 0}); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> x; int id = i + j; ...
#include <bits/stdc++.h> using namespace std; int n, t, last; int f[6005][6005]; inline void dfs(int x, int y, int o) { f[x][y] += o; int O = f[x][y]; f[x][y] %= 4; if (O < 4) return; dfs(x, y + 1, O / 4); dfs(x, y - 1, O / 4); dfs(x + 1, y, O / 4); dfs(x - 1, y, O / 4); } in...
#include <bits/stdc++.h> using namespace std; template <typename T> void chkmax(T &x, T y) { x = x > y ? x : y; } template <typename T> void chkmin(T &x, T y) { x = x > y ? y : x; } template <typename T> void update(T &x, T y, T mod) { x = x + y > mod ? x + y - mod : x + y; } template ...
#include <bits/stdc++.h> using namespace std; int n, a, b, h[15], side = 0, dsh[15], cent = 52; vector<int> sshot, cshot; void recur(int now, int tot) { if (now == n - 1) { int ok = 1; for (int i = 1; i < n - 1; i++) if (dsh[i] * a + dsh[i - 1] * b + dsh[i + 1] * b <= h[i]) { o...
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; vector<int> v(n); for (long long i = 0; i < n; i++) cin >> v[i]; ; vector<int> u(n); for (long long i = 0; i < n; i++) cin >> u[i]; ; sort((v).begin(), (v).end()); sort((u).begin(), (u).end()); ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; scanf( %d%d , &n, &m); int l = (n - 1) / m; if ((n - 1) % m == 0) printf( %d n , 2 * l); else printf( %d n , 2 * l + 1 + ((n - 1) % m >= 2)); int need = (n - 1) % m; for (int i = 2; i <= n;) { int maxn...
#include <bits/stdc++.h> using namespace std; int Int() { int x; scanf( %d , &x); return x; } long long Long() { long long x; scanf( %lld , &x); return x; } void err(istream_iterator<string> it) { cout << endl; } template <typename T, typename... Args> void err(istream_iterator<s...
#include <bits/stdc++.h> using namespace std; int t; char a[9][9]; int dx[4] = {2, 2, -2, -2}, dy[4] = {2, -2, 2, -2}; int b[9][9]; int c[9][9]; int dem1, dem2; int kt; void ktrak1(int x, int y) { int h, k; dem1++; for (int i = 0; i <= 3; i++) { h = x + dx[i]; k = y + dy[i]; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 50; const int inf = 0x3f3f3f3f; int A[maxn]; int n, k; void solve(int l, int r) { if (l + 1 == r || !k) return; int mid = (l + r) >> 1; k -= 2; swap(A[mid], A[mid - 1]); solve(l, mid); solve(mid, r); } int main(...
#include <bits/stdc++.h> using namespace std; const int Imx = 2147483647; const long long Lbig = 2e18; const int mod = 1e9 + 7; struct fastio { char s[100000]; int it, len; fastio() { it = len = 0; } inline char get() { if (it < len) return s[it++]; it = 0; len = fread(s, 1, ...
#include <bits/stdc++.h> using namespace std; const int N = 2e6 + 5; const long long M = 1e9 + 7; const long long inf = 1e18 + 5; vector<int> prefix_function(string &s) { int n = s.size(); vector<int> pre(n); int pos = 0; pre[0] = 0; for (int i = 1; i < n; i++) { while (pos and s[pos...
#include <bits/stdc++.h> using namespace std; int test, n; long long f[2000001][2]; const int P = 1000000007; int main() { memset(f, 0, sizeof(f)); f[3][0] = 0; f[3][1] = 4; for (int i = 4; i <= 2000000; i++) f[i][0] = max(f[i - 1][0], f[i - 1][1]) + max(f[i - 2][0], f[i - 2][1]) * 2, ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:256000000 ) using namespace std; const int INF = 1000001000; const long long INFLL = INF * 1LL * INF; const int mod = 1000 * 1000 * 1000 + 7; const int mod9 = 1000 * 1000 * 1000 + 9; const int modr = 99990001; const long double PI = 3.141592653589...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int N = 1e5 + 10; string a; int main() { int n; while (~scanf( %d , &n)) { map<string, int> q; q.clear(); int num = 0; for (int i = 0; i < n; i++) { cin >> a; q[a]++; num = m...
#include <bits/stdc++.h> using namespace std; int main() { long long n, i; cin >> n; if (n == 1 || n == 2) { cout << No ; } else { cout << Yes << n ; cout << 1 << ; cout << n << n ; cout << n - 1 << ; for (i = 0; i < n - 1; i++) { c...
#include <bits/stdc++.h> using namespace std; int m, n; string bs[50]; long long component[1000]; long long combo[1001][1001]; long long pseudopart[1001]; bool visited[1000]; int main() { cin >> m >> n; for (int i = 0; i < n; i++) cin >> bs[i]; for (int i = 0; i < m; i++) for (int j = ...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; const int maxn = 1e5 + 5; const int MAX = 314000000; int n, m; int dis[maxn], tot[maxn], sum[maxn], dp[maxn]; vector<int> have[maxn]; queue<int> q; priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pa...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int SIZE = 1e6 + 10; using namespace std; struct E { int k, c; E() {} E(int _k, int _c) : k(_k), c(_c) {} } es[4200010]; struct Flow { int n, m, dis[500010]; int qq[500010], qr, ql; vector<int> e[500010]; ...
#include <bits/stdc++.h> using namespace std; template <typename T> istream& operator>>(istream& is, vector<T>& v) { for (T& x : v) is >> x; return is; } template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { for (int i = 0; i < (int)v.size(); i++) { os << v[i] << (i ...
#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define fi first #define se second #define pii pair<int,int> void solve() { int n, m; cin>>n>>m; vector<int> a(n), b(n), c(m), vis(n, 1); int cnt = 0; for(int i=0;i<n;i++) cin>>a[i]; ...
#include <bits/stdc++.h> using namespace std; int main() { int x0, y0, x[3], y[3], x1[3], y1[3]; for (int i = 0; i < 3; i++) cin >> x[i] >> y[i]; x0 = x[0] - x[1], y0 = y[0] - y[1]; x1[0] = x[2] - x0, y1[0] = y[2] - y0; x1[1] = x[2] + x0, y1[1] = y[2] + y0; x0 = x[1] - x[2], y0 = y[1] - y[2]...
#include list #include <iostream> #include <utility> #include <vector> #include fstream #include <fstream> #include <map> #include algorithm #include <iomanip> #include cmath #include set #include <climits> #include queue #include complex #define all(x) (x).begin(), (x).end(...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1e6 + 200, RANGE = 1e6 + 20; const long long INF = 0x3f3f3f3f3f3f3f3f; int n, m, p; long long pre_min[MAX_N], nodes[MAX_N << 2], tag[MAX_N << 2]; pair<int, int> ai[MAX_N], bi[MAX_N]; struct tup { int x, y, z; bool operator<(const tup ...
#include <bits/stdc++.h> #include <unordered_map> #include <cctype> #include <string.h> #define PB push_back #define EB emplace_back #define MP make_pair #define endl n #define ll long long #define ull unsigned long long #define STR string #define VEC vector<int> #define IOS {ios_base::sy...
#include <bits/stdc++.h> int main() { long long n; scanf( %lld , &n); if (n <= 1) { printf( -1 ); } else { printf( %lld %lld %lld , n, n + 1, n * (n + 1)); } return 0; }
#include <bits/stdc++.h> using namespace std; class T { private: long node[262145]; long low[262145]; long high[262145]; void update(long n); long amount(long a, long b, long n, long n_a, long n_b); long firstUp(long k, long n, long n_a, long n_b); long firstDown(long k, long n, long ...
#include <bits/stdc++.h> using namespace std; template <typename T> inline T abs(T a) { return ((a < 0) ? -a : a); } template <typename T> inline T sqr(T a) { return a * a; } const int INF = (int)1E9 + 7; const long double EPS = 1E-10; const long double PI = 3.1415926535897932384626433832795...
#include <bits/stdc++.h> using namespace std; void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << = << a << n ; err(++it, args...); } const double PI = acos(-1); const double eps = (1e-9); ...
#include <bits/stdc++.h> using namespace std; vector<string> str; const string di = .. ; char ss[500]; int main() { int ti; scanf( %d , &ti); for (int i = 0; i < ti; i++) { scanf( %s , ss); if (ss[0] == p ) { printf( / ); for (int i = 0; i < str.size(); i++) printf( %...
#include <bits/stdc++.h> using namespace std; const long long MOD = 100000000; const long long MAXN = 2e6 + 20; struct edge { long long from, to, cost; }; int main() { long long i, j, k, t1, t2, t3, n, m, t; std::ios::sync_with_stdio(0); cin >> n >> k; cout << (k + n - 1) / n << n ; ...
#include <bits/stdc++.h> using namespace std; int main() { int i, j, n, a[5002], b, c, d; cin >> n; cout << ? << << 1 << << 2 << endl; fflush(stdout); cin >> b; cout << ? << << 2 << << 3 << endl; fflush(stdout); cin >> c; cout << ? << << 1 << << 3 <<...
#include <bits/stdc++.h> using namespace std; const int maxn = 200000 + 10; const int hashnum = 3; long long base[] = {233, 23, 97}; long long mod[] = {122420729, 1000000007, 1000000009}; int sum[maxn]; char s[maxn]; long long power[hashnum][maxn]; int n; struct node { long long hv[hashnum]; ...
#include <bits/stdc++.h> using namespace std; bool Notlucky(int x) { for (int i = x; i != 0; i /= 10) { if (i % 10 == 8 || i % 10 == -8) return false; } return true; } int main() { int a, b; cin >> a; b = a + 1; while (Notlucky(b)) { b++; } cout << b - a; retu...
#include <bits/stdc++.h> using namespace std; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __prin...
#include <bits/stdc++.h> using namespace std; const int MAX_N = (int)1e5 + 20; long long a[MAX_N]; long long dp[2][MAX_N][2]; int n; long long ans; void Solve(int p) { dp[p][0][0] = 0, dp[p][0][1] = -1; for (int i = 1; i < n; i++) { int bri = i - 1; long long m = a[bri]; if (m <=...
#include <bits/stdc++.h> using namespace std; int main() { long long n, k, ans; cin >> n >> k; if (n % 2 == 0) { if (k <= n / 2) { ans = 2 * k - 1; } else { ans = 2 * k - n; } } else { if (k <= (n / 2) + 1) { ans = 2 * k - 1; } else { ans...
#include <bits/stdc++.h> #pragma GCC target( avx,avx2 ) using namespace std; using LF = double; using LL = long long; using basis = complex<LF>; const LF PI = acos(-1.0l); const int N = 125005; vector<int> rev; vector<basis> omega; inline void calc_rev(int n, int log_n) { omega.assign(n, 0); ...
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > a[60]; int c[60], d[60], e[60]; int main() { int i, j, k, m, n; double w; while (scanf( %d%lf%d , &n, &w, &m) != EOF) { for (i = 0; i < n; i++) d[i] = m; memset(c, 0, sizeof(c)); k = 0; int f = 0; for...
#include <bits/stdc++.h> using namespace std; long long N, i, j, k, a, b; long long gcd(long long a, long long b) { long long t; while (b > 0) { t = b; b = a % b; a = t; } return a; } long long lcm(long long a, long long b, long long c) { long long d = a * b / gcd(a, b); ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; const int INF = 0x3f3f3f3f; int vis[105]; int main() { string s; cin >> s; int len = s.size(); int ans = 0; for (int i = 0; i < len - 1; i++) { if (s[i] == V && s[i + 1] == K ) ans++; } for (int i = 0;...
#include <bits/stdc++.h> using namespace std; int m, n, q, a[13][110005], id; bitset<4100> s[110005]; inline int read() { int ret = 0, ff = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == - ) ff = -1; ch = getchar(); } while (isdigit(ch)) { ret = (ret << 3) + (ret...
#include <bits/stdc++.h> using namespace std; void read(vector<long long int> &a, int n) { a.resize(n); for (int i = 0; i < n; i++) cin >> a[i]; } bool fine = 0; void solve() { int x, y, z; cin >> x >> y >> z; vector<int> a(x), b(y), c(z); for (int i = 0; i < x; i++) cin >> a[i]; f...
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 2e5 + 10; struct node { int l, r, id; friend bool operator<(node A, node B) { return A.r == B.r ? A.l < B.l : A.r < B.r; } }; node a[N]; bool add[N]; int main() { ios::sync_with_stdio(0); cin.tie(...
#include <bits/stdc++.h> using namespace std; const long long maxn = 3e3 + 100; const long long inf = 0x3f3f3f3f; const long long iinf = 1 << 30; const long long linf = 2e18; const long long mod = 998244353; const double eps = 1e-7; template <class T = long long> T chmin(T &a, T b) { return a = mi...
#include <bits/stdc++.h> #pragma GCC optimize( no-stack-protector ) #pragma GCC optimize( -funroll-loops ) #pragma GCC target( avx,sse4 ) using namespace std; const int P = 1e9 + 7, i2 = P / 2 + 1, i6 = P / 6 + 1, N = 1e6 + 5; long long n, m; int r, f1[N], f2[N], f3[N]; int main() { scanf( %lld , &n...
#include <bits/stdc++.h> using namespace std; int n, co[200010], to[200010]; int cnt = 0; int dfn[200010], low[200010]; int scc_cnt; int sccno[200010]; int nt[200010], va[200010]; stack<int> S; void dfs(int u) { dfn[u] = low[u] = ++cnt; S.push(u); int v = to[u]; if (dfn[v] == 0) { ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; char s[N], t[N]; int n, m; int ch[N][26]; int lps[N]; void calcLps() { memset(lps, 0, sizeof(lps)); int i = 1; int len = 0; lps[0] = 0; while (i < m) { if (t[i + 1] == t[len + 1]) { len++; lps[i...
#include <bits/stdc++.h> using namespace std; const int N = 107; int n, k; int f[N][N]; int main() { int i, j, tmp; bool ok = 0; cin >> k; f[1][2] = f[2][1] = 1; tmp = 0; for (i = 3; i <= 100; i++) { f[1][i] = f[i][1] = 1; for (j = 2; j < i; j++) { if (tmp + j - 1 >...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100500; int n, m; int a[30]; string s, t; char ans[5500]; void po_poryadky(int x) { for (int i = x; i < n; i++) { for (int j = 0; j < 30; j++) if (a[j]) { ans[i] = (char)( a + j); a[j]--; break;...
#include <bits/stdc++.h> const int MAXN = 2e5 + 5; int n, a[MAXN]; long long sm[MAXN]; int ans = 0; int pc[MAXN]; inline bool check(int l, int r) { return (a[l] ^ a[r]) == sm[r - 1] - sm[l]; } int main() { scanf( %d , &n); for (int i = 1; i <= n; ++i) scanf( %d , a + i), sm[i] = sm[i - 1] + a[i]; ...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 2e5 + 10; int n, m, l, r, x, a[MAX_N], left_ancestor[MAX_N]; int main() { scanf( %d %d , &n, &m); for (int i = 1; i <= n; i++) scanf( %d , a + i); for (int i = 2; i <= n; i++) if (a[i] == a[i - 1]) left_ancestor[i] = left_...
#include <bits/stdc++.h> using namespace std; const int maxn = 5 * 1e5; long long s[maxn], del[maxn], mark[maxn]; void build(int u, int l, int r) { if (l < r) { int mid = (l + r) / 2; build(u * 2, l, mid), build(u * 2 + 1, mid + 1, r); } else mark[u] = l; } long long query(int u, i...
#include <bits/stdc++.h> using namespace std; const int N = 100001; int n, m, ind[N], dpth[N], s[N], e[N], t, seg[4 * N], lazy[4 * N], a[N]; vector<vector<int> > g, gift; vector<pair<int, int> > anc; vector<int> ans, root; void dfs(int u) { s[u] = t++; for (int i = 0; i < g[u].size(); i++) { ...
#include <bits/stdc++.h> using namespace std; void matches(vector<int> arr) { int i; for (i = 0; i < arr.size(); i++) { if (arr[i] == 2) cout << 2 << endl; else if (arr[i] % 2 == 0 && arr[i] != 2) cout << 0 << endl; else cout << 1 << endl; } } int main() { ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int INF = 1000000001; const long long LINF = 1000000000000000001LL; struct ConvexHullTrick { struct line { int a; long long b; long long eval(int x) { return (long long)a * x + b; } }; bool incrSlope,...
#include <bits/stdc++.h> using namespace std; int N, M; long long tblX[1001001]; int minp[1001001]; long long gs[1001001]; long long bsum[1001001]; long long bsums0[1001001]; long long bsums1[1001001]; long long bsums2[1001001]; long long linsum(long long K) { long long P = K, Q = K + 1; if ...
#include <bits/stdc++.h> using namespace std; int n1; int i, j; int main() { int a[10] = {4, 7, 47, 74, 447, 474, 477, 774, 747, 744}; string n; cin >> n; int z = n.length(); stringstream stoi(n); stoi >> n1; for (i = 0; i < 10; i++) { if (n1 % a[i] == 0) { cout << YES...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-6; const double pi = acos(-1); int sign(double k) { if (k > eps) return 1; else if (k < -eps) return -1; return 0; } int cmp(double k1, double k2) { return sign(k1 - k2); } int inmid(double k1, double k2, double k3...
#include <bits/stdc++.h> std::mt19937 rng( (int)std::chrono::steady_clock::now().time_since_epoch().count()); const int MOD = 1e9 + 7; const int ms = 220; int c = 1; int to[ms][20]; int fail[ms]; int cost[ms]; int addString(const std::vector<int> &str) { int on = 0; for (auto ch : str) { ...
#include <bits/stdc++.h> using namespace std; long long i, j, k, l, n, m, s, sum, K; double an; const long long N = 1020; long long f[N][N], lu[N][N], ld[N][N], ru[N][N], rd[N][N]; long long Lu[N][N], Ld[N][N], Ru[N][N], Rd[N][N]; int hang[N], lie[N]; char a[N][N]; void work(long long x, long long y) ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 610; int N; vector<int> edge[MAXN]; bool seen[MAXN]; int mtype[MAXN]; int par[MAXN]; int get_count(vector<int> v) { if (v.size() <= 1) return 0; cout << ? << v.size() << n ; for (int i = 0; i < v.size(); i++) { if (i) ...
#include <bits/stdc++.h> using namespace std; int main() { char c; char prev; vector<int> A; int i = 0, count = 1; scanf( %c , &prev); A.push_back(1); while (scanf( %c , &c) != EOF) { if (c != + && c != - ) continue; if (c == prev) { A[i]++; } else { ...
#include <bits/stdc++.h> using namespace std; const int N = 505; vector<int> g[N]; int used[N], cant, pep[N][N]; void dfs(int u, int col) { if (g[u].size() == 0) return; used[u] = col; int ncol = ((col == 1) ? 2 : 1); for (int v : g[u]) if (!used[v]) { dfs(v, ncol); } else ...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 2; bool vis[N]; int trie[N * 20][2], sz; void inser(int n) { int curr = 0; for (int i = 19; i >= 0; i--) { int dir = (n >> i) & 1; if (trie[curr][dir] == -1) trie[curr][dir] = ++sz; curr = trie[curr][dir]; } } ...
#include <bits/stdc++.h> using namespace std; const int N = 55; const long long M = 1000003; struct ban { long long x; ban() { x = 0; } ban(long long x) { this->x = x % M; } }; bool operator<(const ban& a, const ban& b) { return a.x < b.x; } bool operator>(const ban& a, const ban& b) { return ...
#include <bits/stdc++.h> int pprime[1010] = {0}; int prime[1010]; int total; void Getprime() { int i, j; for (i = 2; i * i <= 1010; i++) { if (!pprime[i]) { for (j = i; j * i <= 1010; j++) pprime[j * i] = 1; } } total = 0; for (i = 2; i <= 1010; i++) if (!pprime[i])...
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math ) const int maxn = 1e6 + 50; int seg[2 * maxn], ans[maxn], last_pos[maxn], next_pos[maxn]; int n, m; vector<int> v, get_val, partial_xor; vector<pair<pair<int, int>, int> > ques; void upda...
#include <bits/stdc++.h> const long long mod = 1e9 + 7; const int N = 1e5 + 20; using namespace std; int main() { int n, s[N], m; s[0] = 0; cin >> n; for (int i = (1); i <= (n); i++) { cin >> m; s[i] = s[i - 1] + m; } cin >> m; for (int i = (1); i <= (m); i++) { int...
#include <bits/stdc++.h> using namespace std; int main() { int m, n; int out; cin >> m >> n; if (m >= n && m >= 2) { out = (m / 2) * n; if (m % 2 && n / 2) { out += (n / 2); } } else if (n > m && n >= 2) { out = (n / 2) * m; if (n % 2 && m / 2) { out...
#include <bits/stdc++.h> using namespace std; int n, m, p, l, r, cnt[600000], lg[600000], sum[600000], pre[600000][30], f[600000], g[600000]; bool cov[600000 << 6]; char s[600000]; struct Hash { const long long B1 = 233, mod1 = 998244353, B2 = 377, mod2 = 1000000007; long long h1[600000], pw1[60...
#include <bits/stdc++.h> using namespace std; const int N = (int)1e6 + 7; const int MOD = (int)1e9 + 7; const long long INF = (long long)1e18 + 7; vector<vector<long long>> a; long long col[N], row[N], trow[N], tcol[N]; long long res; int m, n; long long getrow() { long long ma = trow[1]; long...
#include <bits/stdc++.h> using namespace std; long long dp[10001]; const long long INF = 1e60 + 7; long long binpow(long long a, long long b) { if (a == 0) { return 0; } if (b == 0) return 1; long long temp = binpow(a, b / 2); if (b & 1) { return temp * temp * a; } else ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; int fx[] = {+1, -1, +0, +0, +1, +1, -1, -1, +0}; int fy[] = {+0, +0, +1, -1, +1, -1, +1, -1, +0}; template <typename T> inline T GCD(T a, T b) { a = abs(a); b = abs(b); while (b) { a = a % b; swap(a, b); } ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100010; bool vis[MAXN]; char str[MAXN]; int main() { gets(str); int len = strlen(str); char maxch = 0; memset(vis, false, sizeof(vis)); for (int i = len - 1; i >= 0; i--) { if (str[i] >= maxch) vis[i] = true; maxch ...
#include <bits/stdc++.h> using namespace std; template <class T> inline void read(T &x) { x = 0; char c = getchar(); int f = 1; while (!isdigit(c)) { if (c == - ) f = -1; c = getchar(); } while (isdigit(c)) { x = x * 10 + c - 0 ; c = getchar(); } x *= f; ...
#include <bits/stdc++.h> unsigned long long int factorial(unsigned long long int n) { unsigned long long int facto; if (n == 0) return 1; return facto = n * factorial(n - 1); } int main() { long long int a, b, GCD; unsigned long long int fa, fb; scanf( %I64d %I64d , &a, &b); if (a > b)...
#include <bits/stdc++.h> using namespace std; int x[101010], v[101010], t[101010]; int n, s; int l[1010101], r[1010101]; bool check(double m) { memset(l, 0, sizeof(l)); memset(r, 0, sizeof(r)); for (int i = 1; i <= n; i++) { if (t[i] == 1) { if (1.0 * x[i] / v[i] < m) l[0]+...
#include <bits/stdc++.h> using namespace std; int n, a, b, ans; int main() { scanf( %d %d %d , &n, &a, &b); if (b < 0) { for (int i = b; i < 0; i++) { a--; if (a == 0) { a = n; } } ans = a; } else { for (int i = 0; i < b; i++) { a++; ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 40; const int MAXM = 210; int n, m, A[MAXN]; double p[MAXM][MAXN][MAXN]; void lucky() { scanf( %d %d , &n, &m); for (int i = 1; i <= n; i++) scanf( %d , &A[i]); } int main() { lucky(); for (int i = 1; i <= n; i++) for (...
#include<bits/stdc++.h> using namespace std; typedef unsigned long long int ull; typedef long long int ll; typedef long double ld; #define PB push_back #define MP make_pair #define F first #define S second #define Pair vector<pair<ll,ll>> #define vec vector <ll> #define all(a) a.begin...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int z = 0; for (int i = 0; i < n; ++i) { int t; cin >> t; if ((5 - t) >= k) ++z; } cout << z / 3; return 0; }
#include <bits/stdc++.h> using namespace std; void getre() { int x = 0; printf( %d n , 1 / x); } void gettle() { int res = 1; while (1) res <<= 1; printf( %d n , res); } template <typename T, typename S> inline bool upmin(T &a, const S &b) { return a > b ? a = b, 1 : 0; } templ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC optimize( inline ) using namespace std; const int N = 101010, mod = 1e9 + 7; namespace { inline int add(int x, int y) { return (x += y) >= mod ? x - mod : x; } inline int sub(int x, int y) { return (x -= y) < 0 ? x + mod : x; } inline in...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false), cin.tie(NULL); long long k = 0; cin >> k; if (k == 1) { cout << 4 ; return 0; } string s = ; unsigned long long a = 1000000000000000000; unsigned long long num = 0; long lo...
#include <bits/stdc++.h> using namespace std; int N; vector<int> Q[100010]; long long F[100010][2]; bool vis[100010]; void dfs(int u) { if (vis[u]) return; vis[u] = true, F[u][1] = 1LL, F[u][0] = 0LL; if (!Q[u].size()) return; long long d0, d1; for (int i = 0; i < Q[u].size(); i++) { ...
#include <bits/stdc++.h> using namespace std; int h[36020]; int main() { char sir[4005]; int a, n, i, j, suma, v[4005]; cin >> a; cin.get(); cin.get(sir + 1, 4005); n = strlen(sir + 1); v[0] = 0; for (i = 1; i <= n; i++) v[i] = v[i - 1] + (sir[i] - 0 ); for (i = 1; i <= n; i++...
#include <bits/stdc++.h> using namespace std; int n, m, k; unordered_map<int, vector<int> > g; map<pair<int, int>, int> weights; map<pair<int, int>, int> idx; unordered_map<int, bool> used; struct elem { int prev; int u; long long dist; elem(int prev, int u, long long dist) : prev(prev), u...
#include <bits/stdc++.h> using namespace std; int arr[100005]; long long ans = 0; int main() { int n; cin >> n; vector<int> a; for (int i = 0; i < n; i++) { cin >> arr[i]; if (arr[i] % 2) a.push_back(arr[i]); else ans += arr[i]; } int i; if ((int)a.s...
#include <bits/stdc++.h> using namespace std; const int INF = 2e9; const long long INFL = 1e18; const int N = 3e5; int n, m, R; vector<int> adj[N + 5]; pair<int, int> E[2 * N + 5]; long long d[N + 5]; struct cmp { bool operator()(pair<int, long long> x, pair<int, long long> y) { return (x.se...
#include <bits/stdc++.h> using namespace std; const long long MAXN = 2e5 + 10, MOD = 1e9 + 7; long long n, T, ni[MAXN], jie[MAXN], jie_ni[MAXN], A[MAXN], ans, sum; long long sum_N, sum_K; void Init() { ni[1] = 1; for (long long i = 2; i <= MAXN - 10; i++) { ni[i] = ((MOD - (MOD / i)) * ni[MOD % ...
#include <bits/stdc++.h> using namespace std; char a[2000][2000]; const int dx[4] = {-1, 0, 1, 0}; const int dy[4] = {0, -1, 0, 1}; queue<pair<int, int> > que; int main() { int n, m; while (~scanf( %d %d , &n, &m)) { for (int i = 0; i < n; i++) { getchar(); for (int j = 0; j < ...
#include <bits/stdc++.h> #pragma GCC optimize trapv const int inf1 = 1e9; const long long int inf2 = 1e18; const int N = 100000; using namespace std; int dirs[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; vector<int> z_function(string s) { int n = s.length(); vector<int> z(n); for (int i = 1, ...