func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const int MAX = 1000011; bool hsh[MAX]; int fact[MAX]; void sieve(int n) { int i, a; for (i = 2; i <= n; i++) hsh[i] = true; for (i = 2; i <= n; i++) if (hsh[i]) { a = 2; fact[i] = i; while (a * i <= n) hsh[a * i] = false,...
#include <bits/stdc++.h> using namespace std; int main() { int i1[5], i2[5], i3[5], i4[5], i5[5]; int o = 0, j = 0, o1, j1; for (int i = 1; i < 6; i++) { cin >> i1[i] >> i2[i] >> i3[i] >> i4[i] >> i5[i]; if (i1[i] == 1) { o = i; j = 1; } if (i2[i] == 1) { ...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; const long long mod = 1e9 + 7; int n; vector<long long> arr; vector<pair<vector<long long>, vector<long long> > > segTree; vector<long long> source(4, 1); vector<long long> e(4); vector<long long> multVec(const vector<long long>& vec, ...
#include <bits/stdc++.h> using namespace std; template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { os << { ; string sep; for (const auto& x : v) os << sep << x, sep = , ; return os << } ; } template <typename T, size_t size> ostream& operator<<(ostream& os, const ...
#include <bits/stdc++.h> const int N = 1000001; int gcd(int a, int b) { int c; while (a) { c = a; a = b % a; b = c; } return b; } void cal(int a, int b, int &s1, int &s2) { int c; while (a > 1) { s1 += b / a; s2 += b / a - 1; c = a; a = b % a; ...
#include <bits/stdc++.h> using namespace std; long long n, m; bool judge(long long k) { if (n == 1) return 1; long long num = (long long)m * k, res = 1, C = 1; for (int i = 1; i <= k; i++) { if (num < i) return 0; if ((long long)(k - i + 1) * C >= (long long)n * i) C = n; els...
#include <bits/stdc++.h> using namespace std; int k, n, maxb, t; int b[100010], flag[100010]; int main() { ios::sync_with_stdio(false); cin >> k >> n >> maxb >> t; t = min(t, min(n, maxb)); for (int ti = 1; ti <= k; ti++) { for (int i = 1; i <= n; i++) cin >> b[i]; for (int i = 0; i ...
#include <bits/stdc++.h> const long long MOD1 = 998244353, MOD2 = 1000000007; long long POWER_MOD1[300001], POWER_MOD2[300001]; struct node { long long hash1_MOD1, hash1_MOD2, hash2_MOD1, hash2_MOD2; int len; } T[1048576], single[2] = {(node){0, 0, 0, 0, 1}, (node){1, 1, 1, 1, 1}}; inline node operato...
#include <bits/stdc++.h> int main(void) { long n; long sum = 0; int i; int call = 0; scanf( %li , &n); while (n != 1) { call = 0; for (i = 2; i <= (long)sqrt((double)n); i++) if (!(n % i)) { call = 1; break; } if (call) { sum += n; ...
#include <bits/stdc++.h> using namespace std; const int MAX = 2e5 + 5; int n, first[MAX], nextt[MAX * 2], u[MAX * 2], v[MAX * 2], cnt, white, black; int ans[MAX], father[MAX], tem[MAX]; bool col[MAX]; void add(int a, int b) { u[cnt] = a, v[cnt] = b; nextt[cnt] = first[u[cnt]]; first[u[cnt]] = cn...
#include <bits/stdc++.h> using namespace std; const int maxn = 300005; long long sum[3][maxn]; int pre[3][maxn]; map<pair<int, int>, int> vis, dp; int ans[maxn]; map<long long, int> pos; int dfs(int x, int y) { if (vis[make_pair((x), (y))]) return dp[make_pair((x), (y))]; else { vis[...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, cnt = 0, pz = 0, mx = 0; string s; cin >> a >> b; for (int i = 0; i < a; i++) { for (int j = 0; j < b; j++) { s += j + 97; } } for (int i = 0; i < a; i++) cout << s[i]; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int n, m; cin >> n >> m; char t[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> t[i][j]; } } bool check = true; int...
#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 MAXH = 200000; const int MAXW = 200000; const int MAXQ = 200000; int h, w, nq; ...
#include <bits/stdc++.h> using namespace std; long long INF = (1e15); int a[110]; int main() { int n, x, y; scanf( %d%d%d , &n, &x, &y); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); if (x > y) { printf( %d n , n); } else { int ans = 0; for (int i = 1; i <= n; i++) { ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; struct node { int x, y, id; void scan() { scanf( %d%d , &x, &y); if (x > y) swap(x, y); } } e[N * 5], q[N], tmp[N]; struct opt { int x, y, sz, f; long long ans; } op[N * 5]; int T; int ext; int cnt, n...
#include <bits/stdc++.h> using namespace std; typedef signed long long ll; #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define FORR2(x,y,arr) for(auto& [x,y]:arr) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,s...
#include <bits/stdc++.h> using namespace std; template <typename type> type input() { type var; cin >> var; return var; } template <typename type> void input(type &var) { cin >> var; return; } template <typename type> void output(type &var, const char *ch) { cout << var << ch; ...
#include <bits/stdc++.h> int main() { long long int n, b, c, i; float a, d; scanf( %I64d , &n); a = sqrt(n); b = floor(a); for (i = b; i > 0; i--) { d = n % i; if (d == 0) break; else continue; } c = n / i; printf( %I64d %I64d , i, c); }
#include <bits/stdc++.h> using namespace std; struct Edge { int v, u; long long cap, cost; Edge() : v(), u(), cap(), cost() {} Edge(int _v, int _u, long long _cap, long long _cost) : v(_v), u(_u), cap(_cap), cost(_cost) {} }; const long long INF1 = (long long)1e9; const long long INF2 ...
#include <bits/stdc++.h> using namespace std; inline long long read() { long long s = 0, w = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) w = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) s = s * 10 + ch - 0 , ch = getchar(); return s * w; } v...
#include <bits/stdc++.h> using namespace std; const long long int inf = (long long int)1e18 + 10; long long int dp[102][102] = {{0}}; map<char, long long int> m; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int n, k; string s; cin >> n >> k; ...
#include <bits/stdc++.h> using namespace std; int main() { string s, tem; cin >> s; int m = s.size(); for (int i = 0; i < m; i++) { if (s[i] != a ) tem += s[i]; } int n = tem.size() / 2; string sub1 = tem.substr(0, n); string sub2 = s.substr(m - n, m); if (sub1 == sub2 && ...
#include <bits/stdc++.h> bool m1; FILE *Input = stdin, *Output = stdout; const int maxn = 1e5 + 5; struct Edge { int to, next; Edge(){}; Edge(int ar1, int ar2) { to = ar1; next = ar2; } } Tree_List[maxn << 1], Tree2_List[maxn << 2]; int Numt[maxn], tott, deg[maxn], totn; int Nu...
#include <bits/stdc++.h> using namespace std; template <typename T> bool mmax(T &m, const T q) { if (m < q) { m = q; return true; } else return false; } template <typename T> bool mmin(T &m, const T q) { if (m > q) { m = q; return true; } else return false...
#include <bits/stdc++.h> using namespace std; bool mustnot[100005]; char opr[100005]; int sum[100005]; int apr[100005]; int sat[100005]; int res[100005]; int a[100005]; int n, m, rc; void work() { int i; memset(apr, -1, sizeof(apr)); for (i = 1; i <= m; ++i) if (opr[i] == + ) { ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); int Q; cin >> Q; while (Q--) { string s; cin >> s; vector<int> num, vec; int n = s.size(); for (int i = 4; i < n; i++) num.push_back(s[i] - 0 ); n = n...
#include <bits/stdc++.h> using namespace std; template <typename T> void chmax(T& a, const T& b) { if (a < b) a = b; } template <typename T> void chmin(T& a, const T& b) { if (a > b) a = b; } int N, M; long long dp[3001][3001]; const long long INF = 1e17; int main() { cin.tie(0); i...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n % 4 == 1 || n % 4 == 2) cout << 1; else cout << 0; }
#include <bits/stdc++.h> using namespace std; const long long maxn = 2000005; const long long mod = 998244353; long long n, ans, cn[maxn], pow3[maxn], pow1m[maxn]; void exgcd(long long a, long long b, long long &x, long long &y) { if (!b) { x = 1, y = 0; } else { exgcd(b, a % b, y, x); ...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; int main() { long long int n, m, i, j, x, y, l = INF, u = 0; cin >> n >> m; if (m == 0) cout << n - 1 << endl; else { for (i = 0; i < m; i++) { cin >> x >> y; if (y < x) swap(x, y); u = max(u, x)...
#include <bits/stdc++.h> using namespace std; ostream& operator<<(ostream& a, const vector<int>& b) { for (auto k : b) cout << k << ; return a; } istream& operator>>(istream& a, pair<int, int>& b) { cin >> b.first >> b.second; return a; } ostream& operator<<(ostream& a, const pair<int, in...
#include <bits/stdc++.h> using namespace std; const int inf = 0x7f7f7f7f; const int maxn = 1111; const int mod = 1000000007; const double eps = 1e-8; bool vis[maxn][maxn]; int n, k; vector<pair<int, int> > ans; bool solve() { for (int i = 1; i <= n; i++) { int cnt = 0; for (int j = 1; ...
#include <bits/stdc++.h> using namespace std; void solve() { int i, ar[3]; cin >> ar[0] >> ar[1] >> ar[2]; int person = 0; for (i = 0; i < 3; i++) if (ar[i] > 0) { ar[i]--; person++; } sort(ar, ar + 3); if (ar[0] > 0 && ar[2] > 0) { person++; ar[0]--; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; const int maxm = 1e5 + 5; const int INF = 0x3f3f3f3f; int main() { int l, p, q; scanf( %d%d%d , &l, &p, &q); printf( %.10lf n , l * 1.0 / (p + q) * 1.0 * p); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const int maxn = 1e6; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int n, m, k; cin >> n >> m >> k; vector<int> a(maxn, 0); for (int i = 0; i < n; i++) { int x; cin >> x; x--; a[x] =...
//manish kumar patel #include<bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define rep(i,a,b) for(ll i=a;i<b;i++) #define repb(i,a,b) for(ll i=a;i>=b;i--) #define err() cout<< -------------------------- <<endl; #define errA(A) for(auto i:A) cout<<i<< ;cou...
#include <bits/stdc++.h> using namespace std; int n, k, t[300010], u, v, a[300010], conf[300010], tc[300010], check[300010]; long long dp[300010][2]; vector<int> edge[300010]; const long long MOD = 998244353; long long add(long long a, long long b) { a += b; if (a >= MOD) a -= MOD; return a; }...
#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; bool comp(const pair<int, int> &a, const pair<int, int> &b) { return (a.first > b.first && a.second < b.second); } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int a[4], i; for (i = 0; i < 4; i++) { cin >> a[i]; ...
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; vector<pair<int, int> > dp(n); dp[n - 1].second = 0; dp[n - 1].first = 1; int mx = 0; for (int i = n - 2; i > -1; i--) { if (a[i + 1] > a...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:102400000,102400000 ) using namespace std; const long long MOD = 1e9 + 7; long long s, x; int a[50], n, ans0[1 << 21], ans1[1 << 21]; void work(int* ans, int s, int t) { int len = (t - s + 1); for (int i = 0; i < (1 << len); i++) { int t...
#include <bits/stdc++.h> using namespace std; int main() { long long n, x, y; cin >> n >> x >> y; if (y < n) { cout << -1 << endl; return 0; } long long a = y - n + 1; unsigned long long ans = 0; ans += n - 1 + a * a; if (ans < x) { cout << -1 << endl; ret...
#include <bits/stdc++.h> using namespace std; const int size = 50 + 10; int n, k, aim[size], num[size], ans = -1; int main() { cin >> n >> k; if (k > n) { cout << -1 << endl; return 0; } for (int i = 1; i <= n; i++) cin >> aim[i]; sort(aim + 1, aim + n + 1); num[1] = 0; f...
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); long long n, m; long long mn, mx; cin >> n >> m; mn = n; mn = max(0ll, n - 2 * m); cout << mn << ; long long cnt = 0; while (m > 0) { m -= cnt; ...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; void solve() { string s; cin >> s; vector<vector<ll>> cnt(2, vector<ll>(2, 0)); ll e = 0, o = 0; for (int i = 0; i < s.size(); i++) { o++; if (i % 2 == 0) { o += cnt[s[i] - a ][0]...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int tt = 0; tt < int(t); tt++) { int a, b, c, r; cin >> a >> b >> c >> r; int L = max(min(a, b), c - r); int R = min(max(a, b), c + r); cout << max(a, b) - min(a, b) - max(0, R - L) << endl; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e3 + 5; int a[maxn][maxn]; int col[maxn]; int deg[maxn]; bool vis[maxn]; int n; void recurse() { int piv = -1; for (int i = 1; i <= n; i++) { if (vis[i]) continue; if (deg[i] % 2 == 1) { piv = i; break; ...
#include <bits/stdc++.h> using namespace std; int main() { int q; cin >> q; while (q--) { int n, h; cin >> h >> n; int a[n]; for (int i = 0; i < n; ++i) cin >> a[i]; int cnt = 1; vector<int> v; for (int i = 1; i < n; ++i) { if (a[i] == a[i - 1] - 1) { ...
#include <bits/stdc++.h> using namespace std; string a, ans; int b; string c; int main() { while (cin >> a >> b) { for (int i = 0; i < a.size(); i++) if (a[i] >= A && a[i] <= Z ) a[i] = a[i] - A + a ; for (int i = 0; i < a.size(); i++) { if ((int)a[i] < b + 97) { ...
#include <bits/stdc++.h> using namespace std; const long double eps = 1e-9; const int inf = (1 << 30) - 1; const long long inf64 = ((long long)1 << 62) - 1; const long double pi = 3.1415926535897932384626433832795; template <class T> T sqr(T x) { return x * x; } template <class T> T abs(T x) { ...
#include <bits/stdc++.h> using namespace std; int n, a[1005]; long long int p[1005], f[1005], d; long long int power(long long int a, long long int b) { if (b == 0) return 1; if (b == 1) return a % 998244353; long long int c = power(a, b / 2); if (b & 1) return (((c * c) % 998244353) * a) ...
#include <bits/stdc++.h> using namespace std; int main() { long long int c, hr, hb, wr, wb; cin >> c >> hr >> hb >> wr >> wb; long long int ret = 0, ret1 = 0; int cnt = 0; for (long long int i = 0; i <= (c / wr); i++) { long long int r = i * wr; long long int l = c - r; long lo...
#include <bits/stdc++.h> int main() { int n; while (scanf( %d , &n) != EOF) { printf( %d n , n * 3 / 2); } return 0; }
#include <bits/stdc++.h> using namespace std; set<int> st; int n; long long w[4] = {1, 5, 10, 50}; bool vis[1280][105000]; void doit(int i, int s) { if (i == n) { st.insert(s); return; } if (vis[i][s]) return; vis[i][s] = 1; for (int j = 0; j < 4; j++) doit(i + 1, w[j] + s); ...
#include <bits/stdc++.h> using namespace std; long long mi, ma, n, d, k, l, r, mid, a[500007], b[500007], cnt[500007]; inline long long read() { long long s = 0, w = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == - ) w = -1; for (; isdigit(c); c = getchar()) s = (s << 3)...
#include <bits/stdc++.h> using namespace std; long long a[100005]; long long dp[100005]; int main() { int n; memset(a, 0, sizeof(a)); memset(dp, 0, sizeof(dp)); cin >> n; int x; for (int i = 0; i < n; i++) { cin >> x; a[x]++; } dp[1] = a[1]; dp[0] = 0LL; for (...
#include <bits/stdc++.h> using namespace std; long i, j, m, n, p, q, r, s, a, b; string aa, bb; int main() { cin >> n; scanf( %ld:%ld , &a, &b); if (n == 12) { if (a == 0) aa = 01 ; else if (a >= 13) { p = a % 10; if (p == 0) { aa = 10 ; } else...
#include <bits/stdc++.h> using namespace std; int solve(bool can_be_equal, const string &sa, vector<int> num_digits) { int received = 0; int given = 0; int offset = can_be_equal ? 0 : 1; for (char c : sa) { int d = c - 0 ; bool found = false; for (int search = d + offset; search <...
#include <bits/stdc++.h> using namespace std; long long bigmod(long long a, int p, long long int m) { if (p == 0) return 1; if (p & 1) { return ((a % m) * (bigmod(a, p - 1, m))) % m; } else { long long tmp = bigmod(a, p / 2, m); return (tmp * tmp) % m; } } int main() { ios_...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; int main() { int k; string s, st; cin >> k >> s; map<char, int> m; set<char> s1; if (s.length() % k) { cout << -1; return 0; } for (auto i = 0; i < s.length(); i++) { if (m.find(s[i]) == m...
#include <bits/stdc++.h> using namespace std; template <typename _T> inline void read(_T &f) { f = 0; _T fu = 1; char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) { fu = -1; } c = getchar(); } while (c >= 0 && c <= 9 ) { f = (f << 3) + (f << ...
#include <bits/stdc++.h> using namespace std; void solve(int test_number); int main() { cout.setf(ios::fixed); cout.precision(9); cerr.setf(ios::fixed); cerr.precision(3); int n = 1; for (int i = 0; i < n; i++) { solve(i + 1); } return 0; } const int MAXN = 200100; cons...
#include <bits/stdc++.h> using namespace std; mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count()); int main() { ios::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { int a, b, c; cin >> a >> b >> c; int ans = -1; for (int x = 0; x < a...
#include <bits/stdc++.h> using ll = long long; using ld = long double; using namespace std; void debugi(vector<int>& vec) { int n = (int)vec.size(); for (int i = 0; i < n; i++) { cout << vec[i] << ; } cout << endl; } void debugd(vector<long double>& vec) { int n = (int)vec.size(...
#include <bits/stdc++.h> using namespace std; int N, K; int A[300005]; int DP[300005]; bool chk(int d) { int mxp = 0; for (int i = K; i <= N; i++) { if (A[i] - A[DP[i - K] + 1] <= d) mxp = i; DP[i] = mxp; } return mxp == N; } int main() { cin >> N >> K; for (int i = 1; ...
#include <bits/stdc++.h> using namespace std; const int N = 119; int n, F[N], T[N]; long double D[N]; vector<pair<int, int> > Adj[N]; void DFS(int v, int p) { long double d = 2.0 / Adj[v].size(), t = 1.0; for (auto X : Adj[v]) if (X.first == p) t += D[X.second], t -= (t > 2.0) ? 2.0 : 0; f...
#include <bits/stdc++.h> using namespace std; int n, m; int a[200013]; int type[200013], len[200013]; int high[200013]; int res[200013]; multiset<int> has; int main() { scanf( %d%d , &n, &m); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); for (int i = 1; i <= m; i++) scanf( %d%d , &type[i]...
#include <bits/stdc++.h> int const maxl = 22; int const maxm = 2520; long long f[maxl][maxm + 4][50][2]; int a[maxl]; std::vector<int> alcm; long long plcm[maxm + 4][10]; long long kth[maxm + 4]; long long l, r; int gcd(int x, int y) { return !y ? x : gcd(y, x % y); } int lcm(int x, int y) { if ...
#include <bits/stdc++.h> using namespace std; const double PI = 3.14159265358979323846264338327950288419716939937510582097494459230; const long long MOD = 1e9 + 7; const long long INF = 1e14; long long mpow(long long a, long long b, long long p = MOD) { a = a % p; long long res = 1; while (b...
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; long long T = 1; cin >> T; while (T--) { long long n; cin >> n; char a[n][n]; for (long long i = 0; i < n; i++) for (long long j = 0;...
#include <bits/stdc++.h> using namespace std; inline int gcd(int a, int b) { while (b > 0) { int t = a; a = b; b = t % b; } return a; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; ++i)...
#include <bits/stdc++.h> using namespace std; int ansa, ansb; int mid[110], cnt; int yy; int cmp(int a, int b) { return a > b; } int main() { int n; scanf( %d , &n); for (int i = 0; i < n; ++i) { int s; scanf( %d , &s); int m = s / 2; int x; if (s & 1) { for...
#include <bits/stdc++.h> using namespace std; const int N_MAX = 1005, M_MAX = 100005; struct union_find { int rank[N_MAX], parent[N_MAX]; union_find() { for (int i = 0; i < N_MAX; i++) { rank[i] = 0; parent[i] = i; } } int find(int x) { return x == parent[x] ? x : paren...
#include <bits/stdc++.h> using namespace std; bool reach(int from[3], int to[3], vector<vector<string>> &works) { if (works[from[0]][from[1]][from[2]] == 0 ) return false; if (from[0] == to[0] && from[1] == to[1] && from[2] == to[2]) return true; for (int d = 0; d < 3; ++d) if (from[d] < to[d]) {...
#include <bits/stdc++.h> using namespace std; long long suml[100100], sumr[100100], l[100100], r[100100], A[100100], B[100100], total, ans[100100]; int main() { long long N; cin >> N; for (long long i = 1; i <= N; i++) { scanf( %lld , A + i); } for (long long i = N; i > 0; i--) { ...
#include <bits/stdc++.h> using namespace std; int n; char s[200010], t[200010]; double s1[200010][26], s2[200010][26]; double ans = 0.0; int main() { scanf( %d n , &n); memset(s1, 0, sizeof(s1)); memset(s2, 0, sizeof(s2)); for (int i = 1; i <= n; i++) { scanf( %c , &s[i]); for (i...
#include <bits/stdc++.h> const int MAXN = 1e5 + 10; int n, m, k, p; int h[MAXN], a[MAXN]; namespace solver1 { long long fin[MAXN]; bool check(long long x) { long long need = 0; static long long t[MAXN]; for (int i = 1; i <= n; i++) { need += (t[i] = std::max(0ll, (fin[i] - x + p - 1) / p))...
#include <bits/stdc++.h> using namespace std; struct Point { int x; int y; int z; int id; }; bool compY(Point a, Point b) { if (a.y != b.y) { return a.y < b.y; } return a.z < b.z; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullpt...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000; int a[MAXN]; int n; int main() { scanf( %d , &n); n *= 2; for (int i = 1; i <= n; ++i) scanf( %d , &a[i]); sort(a + 1, a + n + 1); int ans = 1e9; for (int j = 1; j <= n; ++j) for (int k = j + 1; k <= n; ++k) { ...
#include <bits/stdc++.h> using namespace std; long long dp[10][10000]; long long cnt[10]; long long w; int32_t main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> w; for (long long i = 0; i < 8; i++) { cin >> cnt[i]; } for (long long i = 0; i < 10; i++) f...
#include <bits/stdc++.h> using namespace std; int main() { int n; while (scanf( %d , &n) != EOF) { if (n % 2 != 0) printf( black n ); else { printf( white n1 2 n ); } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int w, m; cin >> w >> m; if (m == 1 || w == 2) { cout << YES << endl; return 0; } while (m) { if (m % w == 1) { --m; } else if (m % w == w - 1) { ++m; } if (m % w == 0) { m /=...
#include <bits/stdc++.h> using namespace std; const int N = 1.1e6; int ans; int n, m; vector<int> F; int S[N][7][7]; int s(int i, int a, int b) { if (i == m) return (F[i] - a) / 3; if (i + 1 == m) return (F[i] - a) / 3 + (F[i + 1] - b) / 3; int loc = S[i + 1][b][0]; for (int j = 0; j < 3; ...
#include <bits/stdc++.h> using namespace std; int T, n, k, l, a[300010], lst; bool flag = 0; int main() { scanf( %d , &T); while (T--) { flag = 0; lst = 0; scanf( %d%d%d , &n, &k, &l); for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); if (a[i] > l) flag...
#include <bits/stdc++.h> using namespace std; int main() { string s, t; cin >> s >> t; int flag = 0; vector<char> arr(26, . ); for (int i = 0; i < s.length(); i++) { int a = int(s[i]); int b = int(t[i]); if (arr[a - 97] == t[i] || arr[a - 97] == . ) { arr[a - 97] = t[...
#include <bits/stdc++.h> using namespace std; const int N = 1005; const int MOD = 1000000007; int t, k, dp[N][N][2]; char l[N], r[N], s[N]; void add(int &a, int b) { a += b; if (a >= MOD) a -= MOD; } int dfs(int l, int pos, int f, int limit) { if (l == -1) return f; if (!limit && dp[l][p...
#include <bits/stdc++.h> using namespace std; int a[101][101]; int main() { int n; cin >> n; int sum = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { cin >> a[i][j]; if ((i == j || i == (n - j + 1)) || (i == (n + 1) / 2 || j == (n + 1) / 2)) { ...
#include <bits/stdc++.h> using namespace std; const int M = 1e9 + 7; const int N = 2e5 + 1; const int oo = 1e9; const double pi = acos(-1); int main() { int t; cin >> t; while (t--) { int a, b, n; cin >> a >> b >> n; if (b < a) swap(a, b); int ans = 0; while (a <= n...
#include <bits/stdc++.h> using namespace std; const int INF = 2147483647; const int N = 300010; int n, m, ans, ansx, ansy, s1, s2, max1; struct aa { int x, y, w; } a[N], b[N << 1]; multiset<int> q1, q2; void Init(int &x) { char y; while ((y = getchar()) < 0 || y > 9 ) ; x = y - ...
#include <bits/stdc++.h> using namespace std; int main() { int n = 0; int nTemp = 0; cin >> n; nTemp = n; int sum = 0; int temp = 0; while (nTemp--) { cin >> temp; sum = sum + temp; } int ways = 0; for (int i = 1; i <= 5; i++) { if ((sum + i) % (n + 1) != 1)...
#include <bits/stdc++.h> using namespace std; const long long inf = (long long)5e18; const long long N = 120000; long long n, a[N], m, b[N]; long long pre[N], nxt[N]; long long q[N], top = 0; long long _abs(long long x) { return x < 0 ? -x : x; } void solve() { scanf( %lld%lld , &n, &m); for (lo...
#include <bits/stdc++.h> using namespace std; int n, q[10005]; long long W, B, X, f[10005], g[10005], cost[1005], c[1005]; int main() { int i, j; cin >> n >> W >> B >> X; for (i = 1; i <= n; ++i) cin >> c[i]; for (i = 1; i <= n; ++i) cin >> cost[i]; for (i = 0; i <= 10000; ++i) f[i] = -1; ...
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; const int MAXN = 1000006; char s[MAXN]; int qp(long long a, int b) { long long ans = 1; while (b) { if (b % 2) ans = ans * a % mod; b /= 2; a = a * a % mod; } return ans; } void solve() { int n,...
#include <bits/stdc++.h> using namespace std; long long bigmod(long long n, long long pow, long long m) { long long ret = 1; while (pow) { if (pow % 2) { ret *= n; ret %= m; } n *= n; n %= m; pow /= 2; } return ret; } long long arr[3 * 100009]; int...
#include <bits/stdc++.h> using namespace std; const int N = 1050; long double pr[N][N]; int n, m, P[N]; inline long double gp(int i, int j) { if (i < j) return pr[i][j]; else return 1 - pr[j][i]; } int main() { cin >> n >> m; for (int i = 1; i <= n; ++i) cin >> P[i]; for (i...
#include <bits/stdc++.h> using namespace std; int n; int m; vector<vector<char> > grid; vector<vector<int> > mindist; vector<int> first; vector<int> last; bool notpossible = false; int main() { scanf( %d %d n , &n, &m); grid.assign(n, vector<char>(m)); first.assign(n, -1); last.assign(...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; struct point { double x, y; point(double _x = 0, double _y = 0) : x(_x), y(_y) {} void read() { scanf( %lf%lf , &x, &y); } }; point polygon[30]; int sign(double x) { if (fabs(x) < eps) return 0; return (x > 0) ? 1 : -...
#include <bits/stdc++.h> int const MAXN = 300100; char a[MAXN]; int n, x, y; long long solve() { if (n == 1) return a[0] == 0 ? y : 0; long long cc = 1; for (int i = 1; i < n; ++i) { if (a[i - 1] != a[i]) ++cc; } if (a[0] == 1 ) --cc; if (a[n - 1] == 1 ) --cc; if (cc <= 0) ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; int hired = 0, untreated, counter = 0, counter2 = 0; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] != -1) { hired += a[i]; } else if (a[i] == -1 && hired != 0) { counter+...