func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const int N = 1e6 + 6; struct segt { vector<int> t; int d; segt(vector<int> &a) { int n = a.size(); for (d = 2; d < n; d <<= 1) ; t.assign(d * 2, 0); for (int i = 0; i < n; +...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; long long l; cin >> a >> b >> c >> l; long long ans = (l + 1) * (l + 3) * (l + 2) / 6; for (long long k = 0; k <= l; k++) { if (a + k >= b + c) { long long j = min(k, (a - b - c + k) / 2); ans = ans - (...
#include <bits/stdc++.h> using namespace std; long long int spf[100000 + 1]; long long int const MAXN = 100001; long long int modex(long long int x, long long int y, long long int p); void getZarr(string str, long long int Z[]); void sieve(); vector<long long int> getFactorization(long long int x); int ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<int> starts(m), ends(m), results; for (int i = 0; i < n; i++) { int l, r; cin >> l >> r; starts[l - 1]++; ends[r - 1]++; } int open = 0; for (int i = 0; i < m; i++) { ...
#include <bits/stdc++.h> using namespace std; int n, a; stack<int> q; vector<int> d; void insert(int x) { if (q.empty()) { q.push(x); return; } if (q.top() != x) { q.push(x); return; } q.pop(); insert(x + 1); } int main() { scanf( %d , &n); for (int ...
#include <bits/stdc++.h> using namespace std; void _exit(string message) { if (message != ) cout << message << endl; exit(0); } template <typename T> ostream &operator<<(ostream &out, const vector<T> &V) { if (!V.empty()) { out << [ ; for (auto v : V) out << v << , ; out << ...
#include <bits/stdc++.h> using namespace std; int n, m; int dp[303030][30]; int u, v; int in[303030]; vector<int> adj[303030]; char s[303030]; int main() { scanf( %d %d , &n, &m); scanf( %s , s); for (int i = 0; i < m; ++i) { scanf( %d %d , &u, &v); --u; --v; adj[u].p...
#include <bits/stdc++.h> using namespace std; using namespace std; const int N = 3e6 + 5; int a[55][55], b[55][55], aa[55][55], bb[55][55]; int row(int x, int y) { for (int i = 1; i <= x; i++) { int k = 1; for (int j = 2; j <= y; j++) { if (a[i][j] > a[i][k]) { k = j; ...
#include <bits/stdc++.h> using namespace std; multiset<long long> dd; long long su; long long revsum[100001]; struct tab { long long l; long long d; } arr[100001]; long long findsumoftop(long long k) { long long ans = 0; multiset<long long>::iterator it = dd.begin(); while (k--) { ...
#include <bits/stdc++.h> using namespace std; const long long N = 550005; const long long mod = 998244353; int n, u, v; vector<int> g[N]; long long dp[N][2][2]; inline long long bin(long long x, long long k) { long long res = 1; while (k) { if (k & 1) res = res * x % mod; x = x * x % m...
#include <bits/stdc++.h> using namespace std; int main() { int t; long long n; cin >> t; for (int i = 0; i < t; i++) { cin >> n; if (n < 6) { cout << 15 << endl; } else if (n % 2 == 0) { cout << n / 2 * 5 << endl; } else { n++; cout << n / 2 * ...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int n = s.length(); string a[n]; a[0] = s; for (int i = 1; i < n; i++) { a[i] = a[i - 1][n - 1] + a[i - 1].substr(0, n - 1); } int dem = 0; for (int i = 0; i < n; i++) { if (a[i] != . ) { ...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int maxn = 1e4 + 5; int n, k; int a[maxn], b[maxn], c[maxn], dp1[maxn], dp2[maxn]; int main() { scanf( %d%d , &n, &k); memset(dp1, -0x3f, sizeof(dp1)); memset(dp2, -0x3f, sizeof(dp2)); for (int i = 1; i <= n; i++...
#include <bits/stdc++.h> using namespace std; const int M = 1e9 + 7; long long powmod(long long a, long long b, long long mod) { long long res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res % mod; } const in...
#include <bits/stdc++.h> int dis[1048576]; std::vector<int> node[1048576], rnode[1048576]; int main() { int n, m, s, t; scanf( %d%d , &n, &m); while (m--) { int u, v; scanf( %d%d , &u, &v); node[u].push_back(v); rnode[v].push_back(u); } scanf( %d%d , &s, &t); memset...
#include <bits/stdc++.h> using namespace std; const int N = 5005; const long long p = 1e9 + 7; long long dp[N], dp1[N]; long long modexp(long long a, long long b, long long p) { long long ans = 1LL; a %= p; while (b) { if (b & 1) ans = ans * a % p; b >>= 1; a = a * a % p; } ...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } struct KMP { int n, at; string s; vector<int> nxt; vector<int> nxtdiff; void init(int _n) { n = _n, at = 0, s = string(n, ? ), nxt = nxtdiff = vector<int>(n + 1, ...
#include <bits/stdc++.h> using namespace std; const int C = 20, A = 40; int n, liq; int dp[1 << C]; long long k[A]; int main() { scanf( %d %d , &n, &liq); for (int i = 0; i < n; i++) for (int j = 0, first; j < n; j++) cin >> first, k[i] |= (long long)(first || i == j) << j; for (i...
#include <bits/stdc++.h> using namespace std; int main() { vector<int64_t> A(8, 8); vector<int64_t> A_high(8, 0); vector<int64_t> B(8, 8); vector<int64_t> B_high(8, 8); int64_t amax = 8; int64_t bmax = 8; char k; for (int64_t i = 0; i < 8; i++) { for (int64_t j = 0; j < 8; j++)...
#include <bits/stdc++.h> using namespace std; int main() { map<string, int> mp; int n, m; cin >> n >> m; int same = 0; for (int i = 0; i < n; i++) { string s; cin >> s; mp[s] = 1; } for (int i = 0; i < m; i++) { string s; cin >> s; if (mp[s]) same++; ...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; long long fpow(long long b, long long x) { long long res = 1; while (x) { if (x & 1) res = (res * b) % MOD; b = (b * b) % MOD; x >>= 1; } return res; } long long c(long long k, long long r) { if ...
#include <bits/stdc++.h> using namespace std; template <class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } template <typename T> ...
#include <bits/stdc++.h> using namespace std; vector<string> vec_splitter(string s) { for (char& c : s) c = c == , ? : c; stringstream ss; ss << s; vector<string> res; for (string z; ss >> z; res.push_back(z)) ; return res; } void debug_out(vector<string> args, int idx) { cer...
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize( Ofast,unroll-loops ) const long long int MAXN = 4e3 + 20, md = 1e9 + 7, inf = 5e18; int dp[MAXN][100][100], a[MAXN], ps[MAXN], sp[MAXN]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); memset(dp, -63, sizeo...
#include <bits/stdc++.h> using namespace std; const long double PI = 3.1415926535897932384626433832795; const long double EPS = 1e-11; pair<int, int> c1, c2, r1, r2; int ans = 0; long double dst(pair<int, int> a, pair<int, int> b) { return (a.first - b.first) * (a.first - b.first) + (a.second...
#include <bits/stdc++.h> using namespace std; int mx = 0; string a, b; string ba, bb; int sum[123] = {}; void solve(int last) { int cursum1[123]; int cursum2[123]; memcpy(cursum1, sum, sizeof sum); memcpy(cursum2, sum, sizeof sum); if (cursum1[last] == 0 || cursum2[(10 - last) % 10] == 0...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int l, r, k; cin >> l >> r >> k; if (k < l) { cout << k << endl; } else { cout << (r / k + 1) * k << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 500010; int n, m; char a[maxn], b[maxn]; char s[maxn * 2], c[maxn * 3]; int z[maxn * 3]; int lcp[maxn]; int lcs[maxn]; void z_init(int len) { int l = 1, r = 1; z[1] = len; for (int i = 2; i <= len; i++) { if (i > r) { ...
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int t; cin >> t; int n, k; string s; while (t--) { cin >> n >> k >> s; vector<int> A(n + 1); for (int i = 0; i < (int)(n); i++) { if (s[i] == 1 ) { A[m...
#include <bits/stdc++.h> using namespace std; double PI = 3.141592653589793238462643383279; const double EPS = 1e-9; const long long MOD = 1000000007; const int inf = 1 << 30; const long long linf = 1LL << 60; int n; int a[100]; vector<pair<vector<int>, int> > v1, v2; int main() { scanf( %d , &n...
#include <bits/stdc++.h> using namespace std; int main() { int k, l, m, n, d, x = 0; cin >> k; cin >> l; cin >> m; cin >> n; cin >> d; int arr[] = {k, l, m, n}; for (int i = 1; i <= d; i++) { for (int j = 0; j < 4; j++) { if (i % arr[j] == 0) { x++; ...
#include <bits/stdc++.h> int main() { int n, input; int count = 1; int s = 3; scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d , &input); if (input == 10) { if (s == 1) { count++; } s = 0; } else if (input == 1) { if (s == 0) { ...
#include <bits/stdc++.h> using namespace std; int main() { int T; T = 1; while (T--) { string t, s, s1, s2; cin >> t; s = t; int i, j, x, l, a = 0; for (i = 0; i < t.length(); i++) { if (t[i] == a ) a = i; } for (i = 0; i < t.length(); i++) { if...
#include <bits/stdc++.h> using namespace std; int main() { int p, x, y; cin >> p >> x >> y; for (int i = x; i >= y; i -= 50) { int t = ((i / 50) % 475); set<int> tr; for (int j = 0; j < 25; j++) { t = (t * 96 + 42) % 475; tr.insert(26 + t); } if (tr.find(p) ...
#include <bits/stdc++.h> using namespace std; int main() { int n, i = 2, c = 0, v = 1; cin >> n; int x = 5; while (n - x > 0) { n = n - x; x = x * 2; v = v * 2; } while (n - v >= 1) { n = n - v; c++; } if (c + 1 == 1) { cout << Sheldon ; } ...
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 520; long long A[N]; long long dp[N]; long long maxl[N]; long long n, m; long long get(long long x, long long y) { if (x == 0) return N - 1; return (x - 1) * m + y; } int main() { cin >> n >> m; A[N - 1] = 0; f...
#include <bits/stdc++.h> using namespace std; ifstream F( p.in ); const int M = 1000000007; const int K = 110; const int N = 100100; int dp[K][N], b[N], c[N][K]; int n, m; void add(int &x, int y) { x = ((x + y) % M + M) % M; } int main() { ios::sync_with_stdio(0); for (int n = 0; n < N; ++n) {...
#include <bits/stdc++.h> using namespace std; int n, m, a[100100], b[100100]; long long ans; int main() { scanf( %d%d , &n, &m); for (int i = 0; i < n; i++) scanf( %d , &a[i]); for (int i = 0; i < m; i++) scanf( %d , &b[i]); sort(a, a + n); sort(b, b + m, greater<int>()); n = min(n, m); ...
#include <bits/stdc++.h> using namespace std; long long n, k; long long c2(long long n) { return n * (n - 1) / 2; } void solve(long long x, long long y) { if (x == 0) return; if (y + 1 >= x) { cout << ( ; solve(x - 1, y - x + 1); cout << ) ; return; } else { cout << ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 150100; long long n, m, l, r; long long P; vector<int> p; long long sum; long long _dfs(long long d, long long x, long long y) { if (d == p.size()) { long long n = abs(y / x); sum += n * (n + 1) / 2 * x; return y / x; ...
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double lf; typedef unsigned long long ull; typedef pair<ll,int>P; const int inf = 0x7f7f7f7f; const ll INF = 1e16; const int N = 2e5+10; const ull base = 131; const ll mod = 1e9+7; const double PI = acos(-1.0); cons...
#include <bits/stdc++.h> using namespace std; map<int, int> mm; int mv[100000] = {0}; int bfs(int n, int m) { queue<int> mq; mq.push(n); mv[n] = 0; while (!mq.empty()) { int r = mq.front(); if (r == m) return mv[r]; mq.pop(); int x, y; x = r - 1; y = r * 2; ...
#include <bits/stdc++.h> using namespace std; using ll = long long; using pll = pair<ll, ll>; using dd = long double; namespace { static bool constexpr dbg = 0; ll constexpr N = -999; ll n, k; bool ok(string const &s1, string const &s2) { do { if (dbg) { bool b = (s1.size() == s2.siz...
#include <bits/stdc++.h> using namespace std; long long n, x, sum; vector<long long> my, temp; int main() { ios::sync_with_stdio(0); cin.tie(); cout.tie(); cin >> n; for (long long i = 0; i < n; i++) { cin >> x; my.push_back(x); temp.push_back(x); } for (long long i...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n <= 4) cout << No solution << endl; else { double alpha = 2 * M_PI / n; cout << fixed << setprecision(6); double x = 0, y = 0; for (int i = 1; i <= n - 2; i++) { cout << x << ...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<int> ans; if (k == 1) { printf( %d n , n); return 0; } for (int i = 2; i * i <= n; i++) { while (n % i == 0) { n /= i; ans.push_back(i); if (((int)ans.size()) ...
#include <bits/stdc++.h> using namespace std; void Debug(vector<int> v) { for (int i : v) { cerr << i << ; } } void Debug(int a[]) { for (int i = 0; i < 5; i++) { cerr << a[i] << ; } } void Debug(int a) { cerr << a; } void Debug(string a) { cerr << a; } void Debug(long ...
#include <bits/stdc++.h> using namespace std; long long MOD = 1e9 + 7; long long MAX = 1e17; bool b[1000]; int main() { ios_base::sync_with_stdio(0); ; int m, t, r, ans = 0; cin >> m >> t >> r; int w[m]; for (int i = 0; i < m; i++) cin >> w[i]; if (r > t) { cout << -1 << endl...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 1; vector<int> e[N]; int s[N], seg[N << 2], num[N << 2], chg[N << 2], dfn[N][2], dfsns[N], sgn[N] = {-1}, stamp; void dfs(int now, int pre) { dfn[now][0] = ++stamp; dfsns[stamp] = now; sgn[dfn[now][0]] = sgn[dfn[pre][0]] == 1 ...
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, i, j, k, sum = 0; scanf( %d%d%d , &n, &a, &b); int arr[n]; for (i = 0; i < n; i++) scanf( %d , &arr[i]); for (i = 0, j = n - 1; i <= j; i++, j--) { if (i != j && arr[i] != arr[j] && arr[i] != 2 && arr[j] != 2) { ...
#include <bits/stdc++.h> const long double eps = 0.00000001; const long long MOD = 1e9 + 7; const double PI = 3.141592653589793238463; using namespace std; long long ans; int was[1010][1010]; int main() { fflush(stdin); cout << fixed, cout.precision(18); ios_base::sync_with_stdio(false); i...
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 5; int n, k, a[maxn], b[maxn]; void work(long long g); long long as, ct; int main() { scanf( %d%d , &n, &k); for (int i = 1; i <= n; i++) scanf( %d , a + i); for (int i = 1; i <= n; i++) scanf( %d , b + i); long long l = 0,...
#include <bits/stdc++.h> using namespace std; template <class T> inline void IO(T &x) { char c = getchar(); T sgn = 1; while (c < 0 || c > 9 ) { if (c == - ) sgn = -1; c = getchar(); } x = 0; while (c >= 0 && c <= 9 ) { x = (T)(x << 1) + (x << 3) + c - 0 ; c...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; pair<int, int> A[N]; int factorial[N]; int twos[N]; int main() { ios::sync_with_stdio(false); int n; cin >> n; for (int i = (int)0; i < (int)2 * n; i++) { cin >> A[i].first; A[i].second = i % n; } sort(...
#include <bits/stdc++.h> using namespace std; long long int power(long long int a, long long int b) { if (b == 0) return 1; long long int p = power(a, b / 2); if (b % 2 == 0) return p * p; else return a * p * p; } long int gcd(long int a, long int b) { if (b == 0) return a; r...
#include <bits/stdc++.h> int N, M, A, B; char table[60][60]; int rows[60]; int cols[60]; int solve() { scanf( %d%d%d%d , &N, &M, &A, &B); if (A * N != B * M) { puts( NO ); return 0; } memset(table, 0, sizeof(table)); memset(rows, 0, sizeof(rows)); memset(cols, 0, sizeof(col...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; int main(int argc, char const *argv[]) { string a; cin >> a; long long n = a.length(); char p[n]; p[0] = a[0]; long long i; for (i = 1; i < n; i++) p[i] = (p[i - 1] > a[i]) ? a[i] : p[i - 1]; for (int i = ...
#include <bits/stdc++.h> const double pi = acos(-1.0); const int maxn = (5e2 + 10); const int inf = 0x3f3f3f3f; const long long mod = 1e9 + 7; using namespace std; map<long long, long long> ys; long long a[200010]; int main() { cin.tie(0); ios::sync_with_stdio(false); long long n; long d...
#include <bits/stdc++.h> using namespace std; struct query { int id, n; }; vector<query> ql[101000]; query now; int m, len, n, ans[101000], sum[101000], qm, fac[201000], inv[201000], ex[110000]; char str[101000]; const int mod = 1e9 + 7; int power(int a, int n) { if (n == 0) return 1; ...
#include <bits/stdc++.h> using namespace std; int INF = 1000000007; string s; int n, k, c, v, ans; int fat[1000100], siz[1000100]; vector<int> edge[1000100]; struct node { int l, r, xo; node(int _l = 0, int _r = 0, int _xo = 0) : l(_l), r(_r), xo(_xo) {} int get() { return min(l, r); } voi...
#include <bits/stdc++.h> using namespace std; void solve() { long long n, m; cin >> n >> m; string a, b; cin >> a >> b; reverse(a.begin(), a.end()); reverse(b.begin(), b.end()); vector<long long> v(n, 0), u(m, 0); for (long long i = 0; i < n; i++) { if (a[i] == 1 ) { v...
#include <bits/stdc++.h> using namespace std; int n; int s[4040][4040]; bool u[4040][4040], r[4040][4040]; int su[4040][4040], sr[4040][4040]; bool b[4040][4040]; int get(int x1, int y1, int x2, int y2) { return s[x2][y2] + s[x1 - 1][y1 - 1] - s[x1 - 1][y2] - s[x2][y1 - 1]; } struct Point { in...
#include <bits/stdc++.h> int main() { long long n; int i = 0; scanf( %lld , &n); while (n - i > 0) { n = n - i; i++; } printf( %lld , n); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, m, s1 = 0, s2 = 0; cin >> n; vector<int> v1(n); for (int i = 0; i < n; i++) cin >> v1[i]; cin >> m; vector<int> v2(m); for (int i = 0; i < m; i++) cin >> v2[i]; sort(v1.begin(), v1.end()); sort(v2.begin(), v2.end()...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC optimize( unroll-loops ) #pragma GCC target( avx,avx2,fma ) using namespace std; const int N = 1500 + 5, lg = 27, mod = 5e4 + 7; bool check(int a, int b, int c, int d) { double k = 1.0 * (a + b + c + d) / 4; double k1 = 1.0 * (b + c)...
#include <bits/stdc++.h> const int Maxn = 100000; const int Maxv = 100000; int n; struct Node { int x, y; Node(int _x = 0, int _y = 0) { x = _x, y = _y; } friend Node operator+(Node a, Node b) { return Node(a.x + b.x, a.y + b.y); } friend Node operator-(Node a, Node b) { return Node(a.x - b.x, a...
#include <bits/stdc++.h> using namespace std; void setIO(const string &name = ) { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); if (name.length()) { freopen((name + .in ).c_str(), r , stdin); freopen((name + .out ).c_str(), w , stdout); } } template <typ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; if (n > 6 + 10 + 14) { if (n - (6 + 10 + 14) != 6 && n - (6 + 10 + 14) != 10 && n - (6 + 10 + 14) != 14) { cout << YES << endl; cout << 6...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int n, m; cin >> n >> m; vector<vector<int>> a(n, vector<int>(m)); map<int, vector<int>> raws; for (int i = 0; i ...
#include <bits/stdc++.h> using namespace std; const int inf = 1000000007; const long long linf = 1LL << 62; const unsigned long long ulinf = 1ULL << 63; const double eps = 0.000001; const double pi = 3.14159265358979323846; template <class T> T abs(T a) { return a >= 0 ? a : -a; } template <clas...
#include <bits/stdc++.h> using namespace std; using ll = long long; template <class t, class u> void chmax(t& first, u second) { if (first < second) first = second; } template <class t, class u> void chmin(t& first, u second) { if (second < first) first = second; } template <class t> using v...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, c = 0, ans; cin >> n; while (n) { if (n % 2) c++; n /= 2; } cout << c << endl; }
#include <bits/stdc++.h> using namespace std; void fre() { freopen( c://test//input.in , r , stdin); freopen( c://test//output.out , w , stdout); } template <class T1, class T2> inline void gmax(T1 &a, T2 b) { if (b > a) a = b; } template <class T1, class T2> inline void gmin(T1 &a, T2 b) ...
#include <bits/stdc++.h> using namespace std; void swap(int* a, int* b) { int t = *a; *a = *b; *b = t; } int partition(int arr[], int arr2[], int arr3[], int arr4[], int arr5[], int low, int high) { int pivot = arr[high]; int i = (low - 1); for (int j = low; j <= high - 1...
#include <bits/stdc++.h> using namespace std; vector<long long> x; vector<vector<long long> > y; vector<long long> bfs(long long k) { vector<long long> p((long long)y.size() + 1, 0); vector<bool> vis((long long)y.size() + 1, false); vis[k] = true; queue<long long> q; q.push(k); while (!q...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9; const long long MAXN = 2e5 + 1; void faster() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } int prs[1000]; void solve() { int n, k; cin >> n >> k; unsigned long long a[n]; set<int> m...
#include <bits/stdc++.h> using namespace std; template <class T> struct range_leq { int N; vector<vector<T> > fen; range_leq(int *A, int n) : N(n + 1), fen(N) { for (int i = 1; i < N; ++i) { int p = 1; for (; !(p & i); p <<= 1) ; for (; p; --p) fen[i].push_back(...
#include <bits/stdc++.h> using namespace std; int main() { int s; cin >> s; int *a = new int[s]; for (int i = 0; i < s; i++) cin >> a[i]; for (int i = s - 2; i < s; i--) { if (a[i] != a[i + 1]) { cout << i + 1 << endl; break; } } return 0; }
#include <bits/stdc++.h> using namespace std; template <typename T> inline void checkmin(T &a, T b) { if (a > b) a = b; } const int N = 1001; char buf[N][N], bf[N][N] = {0}; int n, m, cnt = 0; short mx[N * N], my[N * N]; int msz = 0; bool isab(int a, int b) { if (a == n - 1 || b == m - 1) re...
#include <bits/stdc++.h> using namespace std; template <typename T> bool vmin(T& a, T b) { return (a > b) ? (a = b, true) : (false); } template <typename T> bool vmax(T& a, T b) { return (a < b) ? (a = b, true) : (false); } template <typename T> T smax(T x) { return x; } template <type...
#include <bits/stdc++.h> using namespace std; int main() { string a, b; cin >> a >> b; reverse(b.begin(), b.end()); cout << atoi(a.c_str()) + atoi(b.c_str()) << endl; }
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; long long powmod(long long a, long long b) { long long res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; } const int N = 55; ...
#include <bits/stdc++.h> const int N = 1e5 + 7; long long n, m, A[N], sum[N], suf[N]; inline int read() { int now = 0; register char c = getchar(); for (; !isdigit(c); c = getchar()) ; for (; isdigit(c); now = now * 10 + c - 0 , c = getchar()) ; return now; } int main() { ...
#include <bits/stdc++.h> using namespace std; const long long oo = 1e18; vector<int> dinh; int nn; long long n, m, k, kc[801][801]; vector<pair<long long, pair<long long, long long>>> e; void compress() { sort(dinh.begin(), dinh.end()); dinh.resize(unique(dinh.begin(), dinh.end()) - dinh.begin());...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 15; struct Node { int l, r; bool operator<(const Node& b) const { return r != b.r ? r < b.r : l < b.l; } }; unordered_map<int, vector<Node> > mp; int sum[N]; int main() { int n; while (~scanf( %d , &n)) { mp.clear(); ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); string s; cin >> s; int sz = s.size(); s = X + s; int k; cin >> k; int ans = 0; for (int i = 1; i <= sz; i++) { for (int len = 1; len <= 400; len++) { ...
#include <bits/stdc++.h> using namespace std; #define ll long long int void solve() { ll p,a,b,c; cin >> p >> a >> b >> c; ll ans = 1e18 + 1; if(p%a != 0) ans = min(a - p%a, ans); else ans = 0; if(p%b != 0) ans = min(b - p%b, ans); else ans = 0; if(p%c...
#include <bits/stdc++.h> using namespace std; const int maxn = 300 + 66; const long long mod = 1e9 + 7; int N, M, Q; int a[maxn][maxn]; int main() { scanf( %d , &N); for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { scanf( %d , &a[i][j]); } } scanf( %d , &Q); ...
#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> second) { os << { ; for (auto s : second)...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; char s[N]; int a[N], b[N], n; int f[N][2][2]; pair<int, int> g1[N][2][2], g2[N][2][2]; void solve() { for (int l = 0, r = n + 1; l <= r; l++, r--) { if (l + 1 == r || l == r) break; int i = l; for (int j = 0; j < 2;...
#include <bits/stdc++.h> using namespace std; long long H; int N, M, K; long long A[100002], C[100002]; long long add[100002]; bool can[100002]; long long minget[10002]; set<pair<long long, int> > Q; set<pair<int, int>, greater<pair<int, int> > > S; int main() { cin.sync_with_stdio(false); c...
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int main() { int n; cin >> n; vector<int> m(n), r(n); unsigned long long lcm = 1; for (int i = 0; i < n; ++i) { cin >> m[i]; lcm *= m[i] / gcd(m[i], lcm); } for (int i = 0;...
#include <bits/stdc++.h> using namespace std; const int INF = 2147483647; const double PI = 3.141592653589793; const int N = 40005; map<pair<int, int>, int> mapa; int n, m, k, t, a, b, c, pocz[N], waste[N], r, i; int main() { scanf( %d %d %d %d , &n, &m, &k, &t); for (i = 0; i < n; i++) waste[i] =...
#include <bits/stdc++.h> using namespace std; long long md = 1e9 + 7; const int N = 100005; long long power(long long x, long long y, long long p) { long long res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } ...
#include <bits/stdc++.h> using namespace std; char str[100020]; int len[3] = {0}; int num[100020]; void zhuanhuan(int x) { if (x >= 3) { len[2]++; } else if (x == 2) { len[1]++; } else { len[0]++; } } int main() { int n, kuan = 1; scanf( %d , &n); scanf( %*c )...
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (b == 0) { return a; } return gcd(b, a % b); } int main() { int x, y; long long int a, b; cin >> x >> y >> a >> b; int lcm = (x * y) / (gcd(x, y)); int ans = (b / lcm) - ((a - 1) / lcm); cout << an...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; string s[n + 1]; for (int i = 0; i < n; i++) { cin >> s[i]; } long long ans = 1; for (int i = 0; i < m; i++) { unordered_set<char> b; for (int j = 0; j < n; j++) { b.insert(s[j][...
#include <bits/stdc++.h> using namespace std; int t; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> t; while (t--) { int a[3]; int b[3]; cin >> a[0] >> a[1] >> a[2]; cin >> b[0] >> b[1] >> b[2]; long long sum = 0; int au...
#include <bits/stdc++.h> using namespace std; long long pw(long long b, long long p) { if (!p) return 1; long long sq = pw(b, p / 2); sq *= sq; if (p % 2) sq *= b; return sq; } long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); } long long sd(long long x) { retu...
#include <bits/stdc++.h> using namespace std; int N, M; vector<int> edge[100001]; int val[100001]; vector<int> ans[2]; void dfs(int i, int fi) { if (val[i] != 0 && fi != val[i]) { cout << -1 n ; exit(0); } if (val[i] != 0 && fi == val[i]) { return; } val[i] = fi; a...