func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } const char opname[4][5] = { and , nand , or , nor }; const int inputmapping[3][4] = {{0, 1, 0, 1}, {0, 1, 0, 2}, {0, 1, 2, 3}}; int parseop(char *s) { for (int i = (0); i < (4); ...
#include <bits/stdc++.h> using namespace std; const int N = (int)2e5 + 5; int n, m; vector<vector<int>> adj; int Set[N]; bool vis[N]; bool isBipartite(int node) { for (int& x : adj[node]) { if (!vis[x]) { vis[x] = 1; Set[x] = 3 - Set[node]; if (!isBipartite(x)) return fal...
#include <bits/stdc++.h> using namespace std; using namespace std; long long n, dvyg, a[3000000]; long long pointer; int main() { cin >> n; dvyg = 1; for (int i = 1; i <= n; ++i) a[i] = i; for (int i = 2; i <= n; ++i) { pointer = n / i * i + dvyg; for (int j = pointer; j >= dvyg; j...
#include <bits/stdc++.h> using namespace std; void getint(int &v) { char ch, fu = 0; for (ch = * ; (ch < 0 || ch > 9 ) && ch != - ; ch = getchar()) ; if (ch == - ) fu = 1, ch = getchar(); for (v = 0; ch >= 0 && ch <= 9 ; ch = getchar()) v = v * 10 + ch - 0 ; if (fu) v = -v; } ...
#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) { cout << [ << *it << : << a << ] t ; err(++it, args...); } const long long nax = 1e3 + 5; long long n; lo...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 77; long long a[N], f[N], l, r; int n, k; bool check(int mid) { for (int i = 1; i <= n; i++) f[i] = 0; f[0] = 1; int pl = 1, pr; for (int i = 1; i <= n; i++) { while (a[i] - a[pl] > mid) pl++; pr = i - k + 1; f...
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 30, Mod = 1e9 + 7; const long long SQ = 330; long long a[N], b[N]; int main() { ios::sync_with_stdio(0), cin.tie(0); long long n; cin >> n; long long s = 0; for (int i = 0; i < n; i++) cin >> a[i], s += a[i]; for (...
#include <bits/stdc++.h> using namespace std; int cases(1), t; template <typename T> void binary(T n) { stack<int> st; while (n > 0) { st.push(n % 2); n /= 2; } while (!st.empty()) { cout << st.top(); st.pop(); } cout << n ; } vector<long long> factorize(lon...
#include <bits/stdc++.h> using namespace std; const int INF = (int)1e+9 + 9; const long double EPS = 1e-9; const long double PI = 3.1415926535897932384626433832795; const int N = 1000500; int n, k, ans[N]; int main() { scanf( %d%d , &n, &k); if (k * 3 > n) { printf( -1 ); return 0; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 200050; int len; char a[maxn]; int main() { while (scanf( %d , &len) != EOF) { scanf( %s , a); int ans = 0; for (int i = 0; i < len; i++) if (a[i] == < ) ans++; else break; for (int ...
#include <bits/stdc++.h> #pragma optimizitaion_level 3 #pragma GCC optimize( unroll-loops ) #pragma GCC optimize( fast-math ) using namespace std; int n, h; vector<int> b; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> h; b.resize(n); for (auto &...
#include <bits/stdc++.h> using namespace std; template <typename T> bool GetMin(T &a, T b) { return ((a <= b) ? false : (a = b, true)); } template <typename T> bool GetMax(T &a, T b) { return ((a >= b) ? false : (a = b, true)); } const int N = 2333; const long double eps = 1e-8; int n, m; ...
#include <bits/stdc++.h> using namespace std; const long long MAX = 2e6 + 99; const long long INF = 1e12; const long long mod = 1e9 + 7; set<pair<long long, long long>> dif; set<pair<long long, long long>>::iterator it; long long N, M, row[1000], col[1000], mark[500][500], imp[500][500], arr[500][50...
#include <bits/stdc++.h> using namespace std; long long a[100005]; set<int> b; set<int>::iterator it; int main() { long long n, i, s, x, y, z, d, st; scanf( %lld , &n); for (i = 0; i < n; i++) { scanf( %lld , &x); b.insert(x); } n = 0; for (it = b.begin(); it != b.end(); it...
#include <bits/stdc++.h> #pragma GCC_OPTIMIZE( ofast ) using namespace std; void solve() { long long n, k; cin >> n >> k; string s; cin >> s; string need; for (long long i = 0; i < k - 1; i++) { need.push_back( ( ); need.push_back( ) ); } for (long long i = 0; i < n / 2...
#include <bits/stdc++.h> using namespace std; struct edge { int index; int disc, exit; int val; int depth; }; int n, m; edge e[200010]; vector<int> V[200010]; int disc = 1; void calc_disc(int curr, int par, int depth) { e[curr].disc = disc++; e[curr].depth = depth; for (int i...
#include <bits/stdc++.h> using namespace std; int tab[100][100]; int seed = 1304104130; int abs(int x) { if (x < 0) return -x; else return x; } int rand() { return seed = abs(seed * 12493LL + 142412 % 1000000009); } int best(int a) { int last = -1; for (int i = 1; i * i < a; ++...
#include <bits/stdc++.h> using namespace std; map<long long, int> mp; int a[100001], b[100001]; int main() { int n, i; cin >> n; for (i = 1; i <= n; i++) cin >> a[i]; for (i = 1; i <= n; i++) cin >> b[i]; if (a[1] != b[1] || a[n] != b[n]) { cout << No ; return 0; } for (...
#include <bits/stdc++.h> using namespace std; int main() { int n; string t, s; cin >> n >> s; t = s; sort(s.begin(), s.end()); int ret = (1 << 21); for (int i = 0; i < s.length() + 1; i++) { int dif = 0; for (int i = 0; i < s.length(); i++) { if (t[i] != s[i]) dif++; ...
#include <bits/stdc++.h> using namespace std; void solve() { string s; cin >> s; vector<string> s1; for (int i = 0; i < int((s).size()); i++) { string s2(int((s).size()) - i, 0 ); if (s[i] != 0 ) { s2[0] = s[i]; s1.push_back(s2); } } cout << s1.size() << ...
#include <bits/stdc++.h> using namespace std; int dis(int x, int y) { return (x * x + y * y); } int main() { int d, n, i, x, y, r, cnt = 0, R1, R2; cin >> r >> d; R1 = r; R2 = r - d; cin >> n; while (n--) { cin >> x >> y >> r; d = dis(x, y); if (d <= ((R1 - r) * (R1 - r))...
#include <bits/stdc++.h> using namespace std; struct Position { int r, c, t; Position(int r, int c, int t) { this->r = r; this->c = c; this->t = t; } }; int main() { vector<string> board; vector<pair<int, int> > s; for (int r = 0; r < 8; r++) { string line; ...
#include <bits/stdc++.h> using namespace std; int main() { string s; int sz, ans = 0, cnt = 0; cin >> s; sz = s.size(); ans = sz; for (int i = 0; i < sz; i++) if (s[i] == a ) cnt++; while (cnt < ((ans / 2) + 1)) ans--; cout << ans; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, q; cin >> n >> m >> q; vector<long long> a(n, 0); for (int i = 0; i < n; ++i) cin >> a[i]; vector<int> weights(m, 0); vector<int> heavyListsIds; vector<vector<int> > lists(m, vector<int>()); int heavyBorder = ...
#include <bits/stdc++.h> using namespace std; template <typename T> T expo(T e, T n) { T x = 1, p = e; while (n) { if (n & 1) x = x * p; p = p * p; n >>= 1; } return x; } template <typename T> T power(T e, T n, T m) { T x = 1, p = e; while (n) { if (n & 1) x =...
#include <bits/stdc++.h> int n, i; char s[100005]; long long a[270], r; int main() { scanf( %s , s); n = strlen(s); for (i = 0; i < n; i++) a[s[i]]++; for (i = 0; i < 270; i++) r += a[i] * a[i]; printf( %I64d n , r); }
#include <bits/stdc++.h> using namespace std; template <class T> T mceil(T a, T b) { if (a % b == 0) return a / b; else return a / b + 1; } const long long int M = 1e9 + 7; const long long int N = 2e5 + 5; const long long int inf = 9e18; int main() { ios_base ::sync_with_stdio(fa...
#include <bits/stdc++.h> using namespace std; const int INF = 0x7fffffff; int a[2010]; int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); } int main() { int n, count = 0; scanf( %d , &n); for (int i = 1; i <= n; ++i) { scanf( %d , &a[i]); if (a[i] == 1) ++count; } if ...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; int n; pair<int, int> a[N]; void rec(int l, int r) { if (l >= r) { return; } int mid = (r + l) >> 1; rec(l, mid); rec(mid + 1, r); for (int i = l; i <= r; i++) { n++; a[n] = make_pair(a[mid].first, a...
#include <bits/stdc++.h> using namespace std; int higherR(int candies[], int index, int n, int c) { int counter = 0; for (int i = index + 1; i < n; i++) { if (candies[i] > candies[index] && candies[i] != c) { counter++; } } return counter; } int higherL(int candies[], int ind...
#include <bits/stdc++.h> using namespace std; int T; double n; int main() { cin >> T; while (T-- > 0) { cin >> n; printf( %.9lf n , (1.0 / (2.0 * sin(acos(-1.0) / (2.0 * n)))) * cos(acos(-1.0) / 2 / n) * 2); } }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int t, n, i, j; string second; cin >> t; while (t--) { cin >> second; vector<int> v1, v2; n = second.length(); for (i = 0; i < n; i++) { if ((second[i] - 0 ) %...
#include <bits/stdc++.h> using namespace std; char question[4][100]; int len[4]; int main() { for (int i = 0; i < 4; i++) { cin >> question[i]; string s = question[i]; len[i] = s.size() - 2; } int count_ = 0; int index = -1; for (int i = 0; i < 4; i++) { int n; ...
#include <bits/stdc++.h> using namespace std; int x[1005], y[1005], r[1005], level[1005]; long long sum[1005]; vector<pair<int, int> > X[1005]; void dfs(int node, int l) { level[node] = l; int i; for (i = 0; i < X[node].size(); i++) { if (level[X[node][i].second] <= level[node]) dfs(X[node][...
#include <bits/stdc++.h> using namespace std; bool comp(const int a, const int b) { return a > b; } long long binpow(long long a, long long n, int mod) { long long res = 1; while (n) if (n & 1) { res *= a; res %= mod; --n; } else { a *= a; a %= mod; ...
#include <bits/stdc++.h> using namespace std; struct l { int index; int depth; int color; }; int a[100001]; struct BFSearch { vector<pair<l, vector<int> > > adj; queue<l> k; void clear1() { for (int i = 0; i < adj.size(); i++) { adj[i].first.color = 0; adj[i].firs...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5; char s[N]; int main(void) { int n; while (cin >> n) { int cntl = 0; int cntr = 0; int cntq = 0; getchar(); n = abs(n); scanf( %s , s); if (s[0] == ) || s[n - 1] == ( ) { puts( :( ); ...
#include <bits/stdc++.h> using namespace std; FILE* in = stdin; FILE* out = stdout; const int MAX = 100001; int n, k; int a[MAX]; int color[256]; void solve() { memset(color, -1, sizeof(color)); color[0] = 0; for (int i = 0; i < n; i++) { if (color[a[i]] != -1) continue; int left...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; set<char> s; char ch; int rep = 0; for (int i = 0; i < n; i++) { cin >> ch; if (s.find(ch) != s.end()) rep++; s.insert(ch); } if (26 - s.size() >= rep) cout << rep; else cout...
#include <bits/stdc++.h> using namespace std; int main() { vector<int> p; vector<int> n; vector<int> z; int t; cin >> t; int x; for (int i = 0; i < t; i++) { cin >> x; if (x > 0) p.push_back(x); else if (x < 0) n.push_back(x); else z.push_b...
#include <bits/stdc++.h> using namespace std; int t; void solve() { while (t--) { long long int n, k, res = 0; cin >> n >> k; if (n < k) res = k - n; else if ((n - k) % 2 == 0 && n >= k) { res = 0; } else res = 1; cout << res << n ; } } int...
#include <bits/stdc++.h> using namespace std; int a[100005], n, k; bool cmp(int x, int y) { return x % 10 > y % 10; } int main() { cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n, cmp); for (int i = 0; i < n; i++) { if (a[i] % 10 == 0 || k < 10 - a[i] % 10) break; ...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1); const int N = 1e5 + 5; int a[N]; int b[N]; int main() { ios_base::sync_with_stdio(false); int T; cin >> T; while (T--) { int n; cin >> n; vector<int> ve1, ve2; for (int i = 0; i < n; i++) cin >>...
#include <bits/stdc++.h> using namespace std; long long int modexp(long long int a, long long int b) { long long int ret = 1; while (b) { if ((b & 1)) { ret *= a; ret %= 1000000007; } a *= a; a %= 1000000007; b >>= 1; } return ret; } long long int fa...
#include <bits/stdc++.h> long long m; long long from, to; long long x, y; int visit[2][1000010]; int main() { std::cin >> m; int i, time; int cs[2], ci[2], targ[2]; for (i = 0; i < 2; ++i) { std::cin >> from >> to >> x >> y; time = 1; int cur = from; while (true) { ...
#include <bits/stdc++.h> using namespace std; const int N = 150001; int a[N], vis[N]; int main() { int n; while (cin >> n) { for (int i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + n + 1); memset(vis, 0, sizeof(vis)); int ans = 0; for (int i = 1; i <= n; i++) { if...
#include <bits/stdc++.h> using namespace std; const string kStart = What are you doing at the end of the world? Are you busy? Will you save us? ; const string kPrefix = What are you doing while sending ; const string kCenter = ? Are you busy? Will you send ; const string kTail = ? ; ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:1000000000,1000000000 ) using namespace std; const long long inf = 1e18 + 7; const long long mod = 1e9 + 7; const double eps = 1e-9; const double PI = 2 * acos(0.0); const double E = 2.71828; int f[1 << 24], sum[1 << 24], n, k, a[24], b[2]; int ...
#include <bits/stdc++.h> using namespace std; int read() { int x = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar(); } return...
#include <bits/stdc++.h> int main(void) { int n, k, p = 0, t, i, j, c = 0; scanf( %d%d , &n, &k); int x[n], y[n], z[k * 2]; for (i = 0; i < n; i++) { scanf( %d , &x[i]); y[i] = i + 1; } for (i = 0; i < n; i++) { for (j = 0; j < n - 1; j++) { if (x[j] < x[j + 1]) { ...
#include <bits/stdc++.h> using namespace std; int arr[30001]; int main() { int t; cin >> t; while (t--) { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> arr[i]; } int dp1 = arr[1]; int dp2 = 0; bool fail = 0; for (int i = 2; i < n; i++) {...
#include <bits/stdc++.h> using namespace std; int k; long long s[16], sum; map<long long, int> id; vector<long long> v; bool vis[16]; bool dp[1 << 15]; vector<pair<int, int> > way[1 << 15]; int pre[1 << 15]; pair<int, int> ans[16]; int main() { scanf( %d , &k); for (int i = 0; i < k; i++) ...
#include <bits/stdc++.h> using namespace std; bool mark[100007] = {0}; vector<pair<long long int, long long int> > adj[100007]; vector<long long int> ans; long long int d[100007]; long long int par[100007]; void dijkstra(long long int v) { d[v] = 0; long long int u; priority_queue<pair<long lo...
#include <bits/stdc++.h> using namespace std; const int mxn = 1e5 + 5; const int inf = 1e9; vector<int> adj[mxn]; bool f1[mxn], f2[mxn]; bool done; int ask(char x, int y) { cout << x << << y << endl; int r; cin >> r; return r; } int dfs(int cur, int prev) { if (done) return -1;...
#include <bits/stdc++.h> using namespace std; int main() { char s[3]; cin >> s; int a; char b; b = s[0]; a = s[1]; if ((b == a || b == h ) && (a == 1 || a == 8 )) cout << 3; else if ((b == a || b == h ) && (a > 1 && a < 8 )) cout << 5; else if ((a == 1 |...
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_str...
#include <bits/stdc++.h> using namespace std; int a[1 << 18]; long long sum[1 << 18]; int p[1 << 18]; int n, T, m; double c; void Calc() { double mean = 0.0; for (int i = 0, j = 0; i < n && j < m; i++) { mean = (mean + (a[i] + .0) / T) / c; if (i == p[j] - 1) { double real = (....
#include <bits/stdc++.h> using namespace std; long long n, x, res = -1000000000; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; for (int i = 1; i <= n; i++) { cin >> x; if (floor(sqrt(x)) != ceil(sqrt(x))) { res = max(res, x); } } cout << ...
#include <bits/stdc++.h> using namespace std; int main() { int n, pay = 0, kd; int U = 0, R = 0; char c; cin >> n; cin >> c; if (c == U ) { kd = 1; U++; } else { kd = 0; R++; } for (int i = 1; i < n; i++) { cin >> c; if (c == U ) U++;...
#include <bits/stdc++.h> using namespace std; const int N = 20500; int A[N]; int n; int B[N]; int get(int k) { if (n / k < 3) return -1e9; for (int i = 0; i < k; i++) B[i] = 0; for (int i = 0; i < n; i++) B[i % k] += A[i]; int ans = -1e9; for (int i = 0; i < k; i++) ans = max(ans, B[i]);...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int i = 0; i < t; i++) { int a = 0, b = 0, c = 0; string line; cin >> line; for (char d : line) { if (d == B ) b++; if (d == A ) a++; if (d == C ) c++; } if (b ...
#include <bits/stdc++.h> using namespace std; long long int MOD = 1000000007; long long int power(long long int x, long long int y, long long int p) { long long int res = 1; x = x % p; if (x == 0) return 0; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) %...
#include <bits/stdc++.h> using namespace std; long long solve(int N, const vector<int>& A) { long long res = 0; vector<int> freq(32); for (int x : A) { int hsb = (sizeof(int) * 8 - 1 - __builtin_clz((x))); res += freq[hsb]; ++freq[hsb]; } return res; } int main(int argc, ch...
#include <bits/stdc++.h> using namespace std; template <class T> void read(vector<T>& a) { for (auto& e : a) { cin >> e; } } template <class T> void print(vector<T>& a) { for (auto& e : a) { cout << e << ; } cout << n ; } void solve() { long long n, h; cin >>...
#include <bits/stdc++.h> using namespace std; inline void read(int &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; } const int N = ...
#include <bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int main() { fast; int t; cin >> t; while (t--) { int n; cin >> n; vector<int> a(n + 1); a[0] = 0; for (int i = 1;...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 3, Mod = 1e9 + 7; const int maxN = 1e5 + 3; void solve() { long long n; cin >> n; long long ans = 6; long long bin = 4; for (int i = 1; i < n; i++) { bin *= bin; bin %= Mod; ans *= bin; ans %= Mod; ...
#include <bits/stdc++.h> using namespace std; int x[102], pile[102]; int MN(int a, int b) { return (a < b) ? a : b; } int main() { int n, i, sz, j, flag; while (scanf( %d , &n) != EOF) { for (i = 1; i <= n; i++) { scanf( %d , &x[i]); } sort(x + 1, x + n + 1); sz = 1; ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 10; int n; int inDegree[MAXN]; long long A[MAXN], _A[MAXN], B[MAXN]; vector<int> adj[MAXN]; void build() { for (int i = 0; i < n; i++) { if (B[i] == -1) continue; adj[i].push_back(B[i]); inDegree[B[i]]++; } } ...
#include <bits/stdc++.h> using namespace std; int n, t; int ask(int r) { cout << ? << 1 << << r << endl; int ans; cin >> ans; return ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); srand(time(0)); cin >> n >> t; vector<int> a(1, t); int inv = 0, rep...
//a.9 #include<bits/stdc++.h> #define ll long long #define all(x) x.begin(),x.end() #define CASE(t) cout<< Case # <<(t)<< : ; #define endll endl #define endl n #define INF 1e18 #define deb(x) cout << [ << (#x) << = << x << ] << n #define deb2(x,y) cout << [ << (#x) << = << x << ] [ ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; int b[n]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> b[i]; int c = 0, r = 0; for (int i = 0; i < n; i++) { if (a[i] == 0 and b[i] == 1) c++; if (a[i] == ...
#include <bits/stdc++.h> using namespace std; char s[90]; void error() { cout << -1 << endl; exit(0); } int main() { int n, m, l = 1, r; scanf( %d%d n , &n, &m); r = n; while (m--) { int v; scanf( To the %s of %d n , s, &v); if (!strcmp(s, left )) { if (l >= ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 10000005; int sum[MAXN]; bool ok[MAXN]; int n; char a[200005]; bool grp[200005]; void submit(int s) { vector<string> ret; for (int i = 0; i < n; i++) { if (grp[i]) { string str; str.push_back(a[i]); str....
#include <bits/stdc++.h> using namespace std; const int N = 200000; int H[N]; vector<int> g[N], b[N]; int ans[N]; int n, q; map<int, set<pair<int, int> > > m; void dfs(int v, int h = 0, int p = -1) { ans[v] = -1; H[v] = h; for (auto i : b[v]) { if (!m[i].empty()) { auto t = *m[...
#include <bits/stdc++.h> using namespace std; const double pie = acos(-1); int n, m, i, N, f[1100000], t, s, j, k, chz[266], ans, a[4][1100000], b[4][1100000], gs[4], use[1100000]; char s1[1100000], s2[1100000]; struct fs { double x, y; } w[1100000], A[1100000], B[1100000], C[1100000], v, ww; fs...
#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); } long long t, a[200010]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> t; while (t--) { long long n; set<long long> s; ...
#include <bits/stdc++.h> using namespace std; int main(int argc, char **argv) { ios_base::sync_with_stdio(false); string s; cin >> s; int n = s.size(); long long maxDiff = 0; long long ans = 0; int x; if (n == 1) { cout << s << endl; return 0; } vector<pair<char, ...
#include <bits/stdc++.h> using namespace std; struct TPoint { double x, y; TPoint(){}; TPoint(double _x, double _y) { x = _x; y = _y; } }; struct TVector { double x, y; TVector() {} TVector(TPoint p) { x = p.x; y = p.y; } TVector(TPoint p1, TPoint p2) ...
#include <bits/stdc++.h> using namespace std; const long long N = 400010; inline long long read() { long long s = 0, w = 1; register char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) w = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) s = (s << 3) + (s <...
#include <bits/stdc++.h> using namespace std; template <class T> bool chkmin(T& a, T b) { return a > b ? a = b, true : false; } template <class T> bool chkmax(T& a, T b) { return a < b ? a = b, true : false; } template <class T> void read(T& a) { char c = getchar_unlocked(); T f = 1; ...
#include <bits/stdc++.h> using namespace std; long long read() { long long x = 0, f = 0; char ch = getchar(); while (!isdigit(ch)) f = ch == - , ch = getchar(); while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar(); return f ? -x : x; } const int N = 1005; int n, k, b; ...
#include <bits/stdc++.h> using namespace std; int n, is, it; vector<int> res; string s, t; int getis() { for (int i = it; i < t.size(); ++i) { if (s[i] == t[it]) return i; } return -1; } int main() { cin >> n >> s >> t; while (s != t) { is = getis(); if (is == -1) { ...
#include <bits/stdc++.h> using namespace std; int main() { string s; bool flag = 1; int c = 0, a[] = {5, 7, 5}, k = 0; map<char, bool> m{{ a , 1}, { e , 1}, { o , 1}, { u , 1}, { i , 1}}; while (getline(cin, s)) { c = 0; for (int i = 0; i < s.size(); i++) c += m[s[i]]; if (c !=...
#include <bits/stdc++.h> using namespace std; int main() { long long int a, b; cin >> a >> b; stringstream ss; ss << b; string str; str = ss.str(); reverse((str).begin(), (str).end()); stringstream ss1; ss1 << str; ss1 >> b; cout << a + b << endl; }
#include <bits/stdc++.h> using namespace std; template <class T> T big(T a, T b) { return a > b ? a : b; } long long gcd(long long a, long long b) { if (a == 0) return b; return gcd(b % a, a); } long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); } bool mod(long double a, l...
#include <bits/stdc++.h> using std::cin; using std::cout; struct Item { int parent; int count; }; int Find(int x, std::vector<Item>* items) { if (items->at(x).parent == x) { return x; } return items->at(x).parent = Find(items->at(x).parent, items); } void Unite(int x, int y, std:...
#include <bits/stdc++.h> using namespace std; long long a, b, i, c, x, y, z, k, h; int main() { cin >> x >> y; for (a = 0; a <= 1000; a++) { for (b = 0; b <= 1000; b++) if (a * a + b == x && a + b * b == y) h++; } cout << h; }
#include <bits/stdc++.h> using namespace std; const int MAX = 999999; const double Eps = 1e-12; const double PI = acos(-1.0); int gcd(int x, int y) { return x % y == 0 ? y : gcd(y, x % y); } long long pe[2222], key[2222]; char a[100], b[100]; int p[11111]; using namespace std; int num[200004], ans[2...
#include <bits/stdc++.h> using namespace std; int main() { string in = 111 ; cin >> in; vector<vector<int>> result; set<int> last1, last0; for (int i = 0; i < in.size(); i++) { if (in[i] == 0 ) { if (last1.empty()) { result.push_back({i}); last0.insert(result....
#include <bits/stdc++.h> using namespace std; struct abcd { int to, next; } table[300300 << 1]; int head[300300], tot; int n, m; char ans[300300]; void Add(int x, int y) { table[++tot].to = y; table[tot].next = head[x]; head[x] = tot; } void DFS(int x) { int i, cnt = 0; for (i ...
#include <bits/stdc++.h> using namespace std; using ll = long long; const int INF = 2e9; vector<string> v; int n, m; int diff(string a, string b) { int i, cc = 0; for (i = 0; i < m; ++i) cc += (a[i] != b[i]); return cc; } string solve() { string s = v[0], t; int i, j, cc; char c;...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000010; int a[MAXN], parent[MAXN], rnk[MAXN]; vector<int> arr[MAXN]; vector<int> ans; void make_set(int v) { parent[v] = v; rnk[v] = 0; } int find_set(int v) { if (v == parent[v]) return v; return parent[v] = find_set(parent...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 9; long long c[4005][4005]; void getc() { memset(c, 0, sizeof(c)); c[0][0] = 1; for (int i = 1; i < 4001; i++) { c[i][0] = 1; for (int j = 1; j <= i; j++) { c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod; ...
#include <bits/stdc++.h> using namespace std; const long long MOD = (long long)1e9 + 7; long long dp[12][65][1024], dp0[12][65][1024]; void upd(long long &a, long long b) { a = (a + b); } int get_next(int a, int b) { if ((a & (1 << b)) == 0) { a += (1 << b); } else { a -= (1 << b); } ...
#include <bits/stdc++.h> using namespace std; const int N = 3610, mod = 998244353; template <typename T> void read(T &x) { int ch = getchar(); x = 0; for (; ch < 0 || ch > 9 ; ch = getchar()) ; for (; ch >= 0 && ch <= 9 ; ch = getchar()) x = x * 10 + ch - 0 ; } void qmo(int &x) ...
#include <bits/stdc++.h> using namespace std; template <class T> void chmin(T &t, const T &f) { if (t > f) t = f; } template <class T> void chmax(T &t, const T &f) { if (t < f) t = f; } int main() { long long int n, a, c1, c2, m, len = 0, prev = 0, ans = 0, rlow, rlen, rind, ...
#include <bits/stdc++.h> using namespace std; int max_of_num; int n, test_Q, point_num[100005], f_delp[100005][2]; vector<int> vc[100005]; bool flag = false; void search1(int u, int fa) { for (int i = 0; i < vc[u].size(); i++) { int v = vc[u][i]; if (v != fa) { if (point_num[v] == 1)...
#include <bits/stdc++.h> using namespace std; int const MAX_CH = 110; char st1[MAX_CH], st2[MAX_CH], st3[MAX_CH]; int dp[MAX_CH][MAX_CH][MAX_CH]; int new_pref_len[MAX_CH][30]; struct { int i, j, k; char ad_ch; } from[MAX_CH][MAX_CH][MAX_CH]; int main() { gets(st1); int len_1 = (int)strle...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; long long int invmod(long long int x, long long int n, long long int mod) { if (n == 0) return 1 % mod; long long int half = invmod(x, n / 2, mod); half = (half * half) % mod; if (n % 2 == 1) half = (half * (x % mod)) % mo...