func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; long long dp[1000006][2]; long long pre[1000006][2]; void chkMinLog(long long& goal, long long t1, bool t2, bool curr) { if (dp[t1][t2] > goal) { dp[t1][t2] = goal; pre[t1][t2] = curr; } } void solve() { long long n; cin >> n; vec...
#include <bits/stdc++.h> using namespace std; const long long inf = 0x3f3f3f3f; const int N = 5e5 + 10; int a[8008]; int n, ans = 0; string s, ss, sss; map<string, int> mp; void str() { cin >> ss; int sum = 0; string x = ; for (int i = 0; i < ss.length(); i++) { if (ss[i] == & )...
#include <bits/stdc++.h> using namespace std; const int N = 200000; pair<int, bool> p[N * 2]; pair<int, int> t[N]; int main() { int n; scanf( %d , &n); int l, r; for (int i = 0; i < n; ++i) { scanf( %d%d , &l, &r); t[i] = make_pair(l, r); p[i * 2].first = l; p[i * 2].se...
#include <bits/stdc++.h> using namespace std; int n, L, a[1005], b[1005], ans[1005], cc; double dp[1005], dis[1005][1005]; int pre[1005]; inline bool check(double K) { dp[0] = 0; for (int i = 1; i <= n; ++i) { dp[i] = -1e9; for (int j = 0; j < i; ++j) { double v = dp[j] + K * b[i] ...
#include <bits/stdc++.h> using namespace std; vector<int> o, p, e; int n, i, j, x; int a[200000], b[200000]; struct T { int i; } t; bool operator<(T t1, T t2) { if ((t2.i - x - a[b[t2.i]] + 2 * n) % n != (t1.i - x - a[b[t1.i]] + 2 * n) % n) return (t2.i - x - a[b[t2.i]] + 2 * n) % n ...
#include <bits/stdc++.h> using namespace std; int main() { int l, r; cin >> l >> r; for (int i = l; i < r + 1; i++) { vector<int> cnts(10); int x = i; while (x > 0) { cnts[x % 10]++; x /= 10; } bool good = true; for (int j = 0; j < 10; j++) { i...
#include <bits/stdc++.h> using namespace std; void file() {} void fast() { std::ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); } long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); } long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; } int ...
#include <bits/stdc++.h> using namespace std; inline int read() { register int x = 0, f = 1; register char ch = getchar(); while (!isdigit(ch)) { if (ch == - ) f = 0; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + (ch ^ 0 ); ch = getchar(); } return f ? x ...
#include <bits/stdc++.h> using namespace std; const int NMAX = 100005; int A[NMAX]; int main() { ios::sync_with_stdio(false); int n; cin >> n; bool ok = true; if (n % 2 == 1) { if ((n - 1) % 4 == 0) { for (int i = 1; i <= n / 2; i += 2) { A[i] = i + 1; A[i +...
#include <bits/stdc++.h> using namespace std; template <class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); } template <class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return ...
#include <bits/stdc++.h> using namespace std; deque<int> d; string mot; int n; void f(int i) { if (i == n) return; else { f(i + 1); if (mot[i] == l ) { d.push_back(i + 1); } else { d.push_front(i + 1); } } } int main() { cin >> mot; n = mo...
#include <bits/stdc++.h> using namespace std; signed main() { printf( INTERCAL n ); return 0; }
#include <bits/stdc++.h> using namespace std; inline int read() { int neg = 1, num = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == - ) neg = -1; for (; isdigit(c); c = getchar()) num = (num << 1) + (num << 3) + c - 0 ; return neg * num; } int n, a, b; char s[30...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 10; const int MM = 1e9 + 7; void pts(int x, int y, int z) { printf( 3 %d %d %d n , x, y, z); } void pts(int w, int x, int y, int z) { printf( 4 %d %d %d %d n , w, x, y, z); } void gao(int n) { if (n == 3) { pts(1, 2, 3); pt...
#include <bits/stdc++.h> using namespace std; int num1 = 0; string s1, s2; int counter = 0; int ques = 0; int main() { cin >> s1 >> s2; int num2 = 0; for (int i = 0; i < s1.length(); i++) if (s1[i] == + ) num1++; else num1--; for (int i = 0; i < s2.length(); i++)...
#include <bits/stdc++.h> using namespace std; char s[111][3]; int main() { char t[3]; scanf( %s , t); int n; scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %s , s[i]); } for (int i = 0; i < n; i++) { if (t[0] == s[i][0] && t[1] == s[i][1]) { puts( YES ); ...
#include <bits/stdc++.h> using namespace std; struct hash { int head[8592637], next[8592637], t; unsigned long long lk[8592637]; double x[8592637]; double find(unsigned long long s) { for (int i = head[s % 8592637]; i; i = next[i]) if (lk[i] == s) return x[i]; return -1; } ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, k; int a[N]; void solve(int l, int r) { if (k <= 0) { return; } if (l == r - 1) { return; } int mid = (l + r) / 2; swap(a[mid - 1], a[mid]); --k; --k; solve(l, mid); solve(mid, r); ...
#include <bits/stdc++.h> using namespace std; long long int scs(long long int a) { long long int u = 0; while (a) { u++; a /= 10; } return u; } long long int mul(long long int a, long long int b, long long int m) { if (b == 1) return a % m; if (b == 0) return 1 % m; a %= ...
#include <bits/stdc++.h> using namespace std; bool isPowerOfTwo(long long n) { if (n == 0) return false; return (ceil(log2(n)) == floor(log2(n))); } long long power(long long x, unsigned long long y) { if (y == 0) return 1; else if (y % 2 == 0) return power(x, y / 2) * power(x, y / 2...
#include <bits/stdc++.h> using namespace std; const int maxx = 1000 + 50; long long DP[maxx]; int main() { int n, m; cin >> n >> m; int t = abs(n - m); DP[1] = 1; DP[2] = 3; for (int i = 3; i <= 1000; i++) DP[i] = DP[i - 1] + i; int ans = 0; ans = 2 * DP[(t / 2)]; if (t % 2 =...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f, maxn = 10; int Pow(int a, int b) { int ans = 1; while (b) { if (b & 1) ans = (long long)ans * a % 1000000007; a = (long long)a * a % 1000000007; b >>= 1; } return ans; } int main() { int n, k; w...
#include <bits/stdc++.h> using namespace std; long long powmod(long long p, long long n) { if (n == 0) return 1; if (n % 2 == 1) return (p * powmod(p, n - 1)) % 1000000007; long long z = powmod(p, n / 2); return (z * z) % 1000000007; } int main() { ios_base::sync_with_stdio(false); cin.t...
#include <bits/stdc++.h> using namespace std; int N, n, m; long long a[1 << 20], b[1 << 20]; int g[21][100001]; void FWT(long long *P, int opt) { for (int i = 2; i <= N; i <<= 1) for (int p = i >> 1, j = 0; j < N; j += i) for (int k = j; k < j + p; ++k) { long long x = P[k], y = P[...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); const double eps = 1e-6; inline long long lgput(long long a, long long b, long long mod) { long long ret = 1; while (b) { if (b & 1) ret = (ret * a) % mod; a = (a * a) % mod; b >>= 1; } return (ret % mod)...
#include <bits/stdc++.h> using namespace std; int n; pair<pair<int, int>, int> a[100100]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 1; i <= n; i++) { int x; cin >> x; a[i].first.first = x; } for (int i = 1; i <= n; i++) { int x;...
#include <bits/stdc++.h> using namespace std; int main() { int a; cin >> a; for (int i = 0; i < a; i++) { long long x = 0; long long a; long long b; long long k; cin >> a >> b >> k; if (k % 2 == 1) { x = (a - b) * (k / 2); x = x + a; } else { ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n; cin >> n; long long i, x; vector<long long> v; for (i = 0; i < n; i++) { cin >> x; v.push_back(x); } long long ans = 0; for...
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 5; const long long mod = 998244353; set<long long> pre, cur; string s, mn, mx; long long zmin[2 * N]; long long zmax[2 * N]; long long dmin[N]; long long dmax[N]; long long dp[N]; long long n; void init() { long long n, ...
#include <bits/stdc++.h> using namespace std; long long int modularPower(long long int x, unsigned long long int y, long long int mod) { long long int res = 1; x %= mod; while (y > 0) { if (y & 1) res = (res * x) % mod; y >>= 1; x = (x * x) % mod; } ...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const long long infLL = 0x3f3f3f3f3f3f3f3fLL; const int maxn = 5000 + 5; const int mod = 1000000007; int n, m; int s[maxn]; int f[maxn], h[maxn]; map<pair<int, int>, int> cows; int l[maxn], r[maxn]; int pre[maxn], suf[maxn];...
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long a[n + 1][3]; map<long long, long long> m; for (long long i = 1; i <= n; i++) { cin >> a[i][0] >> a[i][1] >> a[i][2]; } vector<pair<double, pair<long long, long long> > > v; for (long lon...
#include <bits/stdc++.h> const int maxn = 5e5 + 5; using namespace std; char s[maxn]; int main() { scanf( %s , s); int k = strlen(s); char y = s[0]; for (int i = 0; i < k; i++) { if (s[i] > y) { cout << Ann << endl; } else { y = s[i]; cout << Mike << endl;...
#include <bits/stdc++.h> using namespace std; int n; string s; bool es[100001]; string ans; void wk() { int i; cin >> n; cin >> s; for (i = 0; i <= n; i++) es[i] = false; int fstone = n; for (i = 0; i < n; i++) if (s[i] == 1 ) { fstone = i; break; } b...
#include <bits/stdc++.h> const char nl = n ; const int mod = (int)1e9 + 7; int main() { std::cin.tie(0)->std::ios::sync_with_stdio(0); std::cin.exceptions(std::cin.failbit); int t; std::cin >> t; while (t--) { int n; std::string s; std::cin >> n >> s; int l = -1, r = ...
#include <bits/stdc++.h> using namespace std; const bool DEBUG = false; int main() { ios::sync_with_stdio(0); cin.tie(0); bool puede = true; int N, M; cin >> N >> M; unordered_set<int> conj; vector<string> cad(N); vector<int> index(M); for (int i = 0; i < N; i++) { cin >>...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; vector<string> v(n); for (int i = 0; i < n; i++) { cin >> v[i]; } int a[26] = {0}; for (auto s : v) { for (auto i : s) { a[i - a...
#include <bits/stdc++.h> using namespace std; vector<long long> V[100005]; long long n; map<long long, long long> DP[100005]; long long concatHash(long long x, long long y) { return (x * 100005 + y) % 1000000007; } void answer(long long x) { cout << x; exit(0); } void fail() { cout << ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10; const double pi = acos(-1.0); const long long mod = 1e9 + 7; int n, k; int a[MAXN], b[MAXN], z[MAXN], f[MAXN]; void solve() { scanf( %d %d , &n, &k); int t = 0; for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); ...
#include <bits/stdc++.h> using namespace std; const long long INF = 1000000000 + 7; const double esp = 1e-13; struct node { int x, y; bool operator<(const node &op) const { return op.x > x || (op.x == x && op.y > y); } } a[2000 + 10]; int h, w, n; long long res[2000 + 10], gt[200000 + 10...
#include <bits/stdc++.h> using namespace std; int main() { pair<int, int> p[100000]; int n, ans = 0, a, k, c = 0, i; scanf( %d %d , &n, &k); for (i = 0; i < n; i++) scanf( %d , &a), p[i] = make_pair(a, i); sort(p, p + n); for (i = 0; i < n; i++) { if ((p[i].first + ans) <= k) c++, ans ...
#include <bits/stdc++.h> using namespace std; using Long = long long; constexpr Long MOD = 998244353; template <typename T> using V = vector<T>; template <typename T> using Vv = V<V<T>>; using Vb = V<bool>; using Vvb = V<Vb>; using Vi = V<int>; using Vvi = V<Vi>; using Vl = V<Long>; using Vvl ...
#include <bits/stdc++.h> using namespace std; const int N = (1 << 20) + 1000; const int INF = 1000000000; const int Mod = 1000000007; void update(int tree[], int k, int v) { while (k < N) { tree[k] += v; k += k & (-k); } } int get(int tree[], int k) { int ret = 0; while (k) { ...
#include <bits/stdc++.h> #pragma GCC target( avx2 ) #pragma GCC optimize( O3 ) #pragma GCC optimize( unroll-loops ) using namespace std; vector<long long int> edges[500010]; long long int c[500010], cc[500010], color[500010], bip[500010]; long long int dfs(long long int u, long long int co, long long int ...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 2, M = 6e5 + 2, O = 1.2e6 + 2; long long len1[M], len2[M], v[N], g[N][4], ans[M]; long long lx, ly; int lj[M], nxt[M], fir[N], f[N], qlj[O], qnxt[O], qfir[N], xw[O][3]; int flj[M], fnxt[M], ffir[N]; int n, q, i, x, y, c, bs, qs, fs; bool ...
#include <bits/stdc++.h> using namespace std; string winner; int score; int calc(int Suc, int Fal, int A, int B, int C, int D, int E) { int ret = A + B + C + D + E; ret += Suc * 100; ret -= Fal * 50; return ret; } int main() { int n; while (cin >> n) { score = -100000000; ...
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return a % b == 0 ? b : gcd(b, a % b); } int main() { int n; scanf( %d , &n); if (n % 2) printf( %d %d n , n / 2, n / 2 + 1); else { for (int a = n / 2 - 1; a; a--) { if (gcd(a, n - a) == 1) { print...
#include <bits/stdc++.h> int main() { int r, c; scanf( %d %d , &r, &c); bool banR[1000] = {false}; bool banC[1000] = {false}; char map[100][100]; for (int i = 0; i < r; i++) { scanf( %s , map[i]); } for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { if (map...
#include <bits/stdc++.h> using namespace std; vector<int> v[10]; int n, ans, m, tmp; vector<int> v2; void recur(int now) { if (now == n) { int vis[7][7]; memset(vis, 0, sizeof(vis)); int ans2 = 0; for (int e = 1; e <= n; e++) { for (int p = 0; p < v[e].size(); p++) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s1, s2; cin >> s1 >> s2; int ans = 0; int start = 0; int end = n - 1; while (s1[start] == s2[start]) start++; while (s1[end] == s2[end]) end--; if (s1.substr(start, end - start) == s2.substr(st...
#include <bits/stdc++.h> using namespace std; int main() { long long t1, t2, x1, x2, t0, y1, y2; cin >> t1 >> t2 >> x1 >> x2 >> t0; if (t1 == t2) cout << x1 << << x2 << endl; else if (t1 == t0) cout << x1 << << 0 << endl; else if (t2 == t0) cout << 0 << << x2 << end...
#include <bits/stdc++.h> using namespace std; void sortLU(long long a[], long long n, long long b[]) { long long i, j; for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { if (a[i] < a[j]) { swap(a[i], a[j]); swap(b[i], b[j]); } } } } int main() { l...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; inline void add(int &a, int b, int md = MOD) { a += b; if (a >= md) { a -= md; } } inline int mul(int a, int b, int md = MOD) { return (long long)a * b % md; } inline int power(int a, int b, int md = MOD) { int r...
#include <bits/stdc++.h> using namespace std; const int N = 1e7 + 10; const long long MOD = (long long)(1e9) + (long long)(7); const long double INF = 1e17; long long dp[505][505][12]; long long edge[505][505][4]; int main() { ios::sync_with_stdio(0); cin.tie(0); long long n; cin >> n; ...
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using vi = vector<int>; const int N = 3e5 + 3; const int mod = 1e9 + 7; int n; ll a[N]; template <class T> struct FT { vector<T> tree; int sz; FT(int n) { sz = n, tree.resize(n + 1); } T g...
#include <bits/stdc++.h> using namespace std; int main() { double a, v; cin >> a >> v; double l, d, w; cin >> l >> d >> w; w = min(w, v); double s = w / a; double t = a * s * s / 2; double thead = 0; double vhead = 0; if (t < d) { double t1 = v / a; double t2 = (v...
#include <bits/stdc++.h> using namespace std; bool debug = 1; long long MOD = 1e9 + 7; const int N = 2e5 + 10; map<int, vector<int>> mpe, mps; int nonred[N]; int n; set<int> st; int main() { cin >> n; for (int i = 0; i < n; i++) { int l, r; scanf( %d%d , &l, &r); mpe[l].push_...
#include <bits/stdc++.h> using namespace std; int main() { int n, t, a = 0, b = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> t; if (t == 25) a++; else if (t == 50) { b++; a--; if (a < 0 || b < 0) { cout << NO << endl; return 0;...
#include <bits/stdc++.h> using namespace std; const unsigned long long key = 31; const int MB = 1e5 + 5; int n, m; string s; unsigned long long p[100008]; unsigned long long h[100008]; vector<int> v[100005]; vector<int> vv[100005]; int a[100005]; map<unsigned long long, int> pos; string b[100005...
#include <bits/stdc++.h> long long dx[8] = {0, 1, 0, -1, 1, 1, -1, -1}; long long dy[8] = {1, 0, -1, 0, -1, 1, 1, -1}; using namespace std; class pa3 { public: long long x; long long y, z; pa3(long long x = 0, long long y = 0, long long z = 0) : x(x), y(y), z(z) {} bool operator<(const pa3 &p...
#include <bits/stdc++.h> using namespace std; #pragma warning(disable : 4996) #pragma comment(linker, /STACK:16777216 ) #pragma warning(disable : 4996) #pragma comment(linker, /STACK:16777216 ) #pragma GCC optimize( Ofast ) #pragma GCC target( avx,avx2,fma ) const int inf = 2e9; const long long linf...
#include <bits/stdc++.h> struct Data { std::vector<int> nums; std::string str; }; struct Interval { int start; int end; std::string* data; }; bool compareIntervals(const Interval& a, const Interval& b) { if (a.start < b.start) return true; if (a.start > b.start) return false; r...
#include <bits/stdc++.h> using namespace std; vector<bool> isprime(1005, true); vector<long long> spf(1005, 0); vector<long long> prime; void sieve() { isprime[0] = isprime[1] = false; for (long long i = 2; i < 1005; i++) { if (isprime[i]) { for (long long j = 2 * i; j < 1005; j += i) { ...
#include <bits/stdc++.h> const double pi = 3.1415926535897932384626433832795; int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } using namespace std; void ifd() {} void tme() {} int n, k, h; vector<pair<int, pair<int, int> > > l; vector<int> answer; bool can(double time) {...
#include <bits/stdc++.h> using namespace std; const int MAXN = 110; const int INF = 1e9; int _w; int n, a[MAXN], b[MAXN]; namespace MCMF { const int MAXV = 1000000; const int MAXE = 1000000; struct Edge { int u, v, c, f, w; Edge() {} Edge(int u, int v, int c, int f, int w) : u(u), v(v), c(...
#include <bits/stdc++.h> using namespace std; typedef int *arrint; const int maxn = 2e3 + 55; int main() { int h1, h2, a, b, i, j, k; scanf( %d , &h1), scanf( %d , &h2); scanf( %d , &a), scanf( %d , &b); k = 0; i = h1; j = 1; while (i < h2) { if (j == 1) { i = i + a * 8...
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); string s; cin >> s; long long n = s.length(); reverse(s.begin(), s.end()); set<string> ans; vector<bool> dp2(n + 1, 0), dp3(n + 1, 0); dp2[1] = 1; dp3[2] ...
#include <bits/stdc++.h> using namespace std; void solve() { int n, i; cin >> n; int ara[n]; for (int i = 0; i < n; ++i) { cin >> ara[i]; } for (i = 1; i < n; i++) { if (ara[i] != ara[i - 1]) { cout << 1 n ; return; } } cout << n << endl; } int ...
#include <bits/stdc++.h> using ll = long long; using namespace std; const int N = 1e6 + 10; const int Mod = 0; ll a[N], sum[N], p[N]; int n, m, T, q; int Read(); void update(ll x) { vector<ll> v; x--; int cnt = 0; if (n <= 14) { for (int i = 1; i <= 14; i++) v.push_back(i); } e...
#include <bits/stdc++.h> using namespace std; int main() { mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); long long n, k; cin >> n >> k; string s; long long lo = 1, hi = n; while (1) { long long mid = lo + hi >> 1; if (hi - lo <= 50) { long long gues...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 50; char s[N], t[N]; int n, a[N], b[N], c[N]; int main(void) { scanf( %d , &n); scanf( %s , s); scanf( %s , t); for (int i = 0; i < n; i++) { a[i] = s[i] - a ; b[i] = t[i] - a ; } for (int i = 0; i < n; i++...
#include <bits/stdc++.h> using namespace std; int main() { int i, j; int dif; int n, m; bool ans = true; char flag[100][101]; cin >> n >> m; for (i = 0; i < n; i++) cin >> flag[i]; for (i = 0; i < n; i++) { dif = flag[i][0]; for (j = 1; j < m; j++) if (flag[i][j] ...
#include <bits/stdc++.h> using namespace std; int n, m, k, e[111111], x, y, s, t, l, r, c, cc, yy[555555], pp[555555], xx[555555], f[111111], rr[111111], q1, q2, kk, p[111111], ll; int qx[444444], qc[444444], ql[444444]; int find(int x) { int y = x; while (x != p[x]) x = p[x]; while (x != y) {...
#include <bits/stdc++.h> using namespace std; const unsigned long long MOD = 1e9 + 7; const int INF = 1e9; const unsigned long long INF64 = 9e18; const long double EPS = 1e-9; const long double PI = 3.14159265358979310000; const unsigned long long MD = 535355424; const unsigned long long T = 25342; co...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[n]; for (int i = 0; i < n; i++) { int a; cin >> a; arr[i] = a; } sort(arr, arr + n); for (int j = 0; j < n; j++) { cout << arr[j] << ; } return 0; }
#include <bits/stdc++.h> using namespace std; int arr[100010]; vector<int> v; int main(void) { int n, k, i, j, totalcnt; scanf( %d %d , &n, &k); for (i = 1; i <= n; i++) { scanf( %d , &arr[i]); v.push_back(arr[i]); ; } if (k == 1) { sort(v.begin(), v.end()); pri...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int n; int k; map<int, int> mp; int S; long long res; struct linetree { map<int, int> rot; int s[22 * N][2]; int v[22 * N]; int ct; inline void ins(int p, int l, int r, int pos) { v[p]++; if (r - l == 1...
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 7; const int OO = INT_MAX, P = 10000; int xd[] = {1, 0, -1, 0, -1, 1, 1, -1}; int yd[] = {0, -1, 0, 1, 1, 1, -1, -1}; int main() { ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); long long int t; cin ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; vector<int> a(n + 1, 0), ans(n + 1, -1), visited(n + 1, 0); for (int i = 1; i <= n; i++) { cin >> a[i]; if (a[i] > a[i - 1]) { ans[i] = a[i - ...
#include <bits/stdc++.h> using namespace std; long long n, m, a[1005], b[1005], c[1005], d[1005], ans, tot; ; char s[1005]; long long calc() { long long cc = 0; for (long long i = 1; i <= n; i++) if (c[i]) { ans += (c[i] - 1) * (m - c[i]) * 4; for (long long j = i + 1; j <= n; j+...
#include <bits/stdc++.h> using namespace std; int sa[1007], n, t, x, d[1007], s; bool f[1007], c[1007]; int main() { scanf( %d%d , &n, &x); for (int i = 1; i <= n; ++i) { scanf( %d , &t), sa[t] = i; if (t == 0) c[i] = 1; } for (int i = 1; i <= n; ++i) { if (!c[i]) continue; ...
#include <bits/stdc++.h> using namespace std; int main() { vector<int> v; int n, i, j, k, value; cin >> n; int x = n; while (x--) { cin >> value; v.push_back(value); } for (i = 0; i < n; i++) for (j = 0; j < n; j++) { if (i == j) j++; for (k = j + 1; k <...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); string s; cin >> s; int ans = 0; int n = s.length(); for (int i = 0; i < n; i++) { if (s[i] != s[n - i - 1]) { ans = -1; break; } } ...
#include <bits/stdc++.h> using namespace std; string second, pre, suf; int main() { ios::sync_with_stdio(false); cin >> second; int n = (int)second.size(); int l = 0; int r = n - 1; while (l + 1 < r - 1) { if (second[l] == second[r]) { pre += second[l]; suf += second[...
#include <bits/stdc++.h> using namespace std; const int MX = 1e6 + 42; int k; int f[6]; long long dp[MX]; long long eval(int val) { long long ret = 0; for (int dig = 0; dig < 6; dig++) { int d = val % 10; if (d % 3 == 0) ret = ret + 1LL * d / 3 * f[dig]; val = val / 10; } r...
#include <bits/stdc++.h> using namespace std; const long long int logx = 30; const long long int N = 1e6 + 5; const long long int INF = 1e18 + 5; const long long int mod = 321555123; const double PI = 3.14159265358979323846; inline long long int mul(long long int a, long long int b) { return (a * 1ll ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 50100; int n, l[MAXN], p[MAXN], idx[MAXN]; double ev[MAXN], el[MAXN]; int idxCMP(int i, int j) { return p[i] * l[i] * (100 - p[j]) > p[j] * l[j] * (100 - p[i]); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >...
#include <bits/stdc++.h> using namespace std; struct segtree { vector<vector<int>> t; vector<int> d; int h, n, sz; inline void build_node(const int& x) { for (int j = 0; j < 26; ++j) { t[x][j] = t[x << 1][j] + t[x << 1 | 1][j]; } } inline void build(int x) { for (x ...
#include <bits/stdc++.h> using namespace std; struct Node { int id, k; }; const int N = 2e5 + 10; int a[N]; int C[N]; Node b[N]; int n; int lowbit(int x) { return (x & -x); } int sum(int x) { int ret = 0; while (x > 0) { ret += C[x]; x -= lowbit(x); } return ret; } ...
#include <bits/stdc++.h> using namespace std; pair<long long int, long long int> p[300002]; int see(long long int a, long long int b, long long int c) { for (long long int i = 0; i < c; i++) { if (p[i].first == a || p[i].first == b || p[i].second == a || p[i].second == b) continue; ...
#include <bits/stdc++.h> using namespace std; int n; int num = 0; int main() { cin >> n; int pre[n + 1]; pre[0] = 0; vector<int> all; for (int i = 0; i < n; i++) { int a; cin >> a; pre[i + 1] = pre[i] + a; } for (int i = 1; i <= n; i++) { for (int k = 0; k < i...
#include <bits/stdc++.h> int N, XL, XR, YL, YR, SX, SY, VX, VY; long long LN, LD = 1, RN = 1000000000000LL, RD = 1; inline bool cmp(long long a, long long b, long long c, long long d) { return a * d < b * c; } void LIM(int v, int s, int l, int r) { if (v == 0) { if (s <= l || s >= r) { p...
#include <bits/stdc++.h> using namespace std; long long f[200200], sum[200200]; long long n; void init() { f[0] = 1LL; for (int i = 1; i <= n; i++) f[i] = f[i - 1] * 10LL % 998244353; return; } void solve() { for (long long i = 1; i <= n; i++) { long long ans = 0; if (i == n) ...
#include <bits/stdc++.h> using namespace std; template <class T1> void deb(T1 e) { cout << e << endl; } template <class T1, class T2> void deb(T1 e1, T2 e2) { cout << e1 << << e2 << endl; } template <class T1, class T2, class T3> void deb(T1 e1, T2 e2, T3 e3) { cout << e1 << << e2 ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int t; cin >> t; while (t--) { long long int n, k; cin >> n >> k; long long int a[n * k], c = 0; for (long long int i = 0; i < n * k; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, x, i; cin >> n; x = n / 2; cout << x << endl; for (i = 1; i < x; i++) { cout << 2 ; } if (n % 2 == 0) cout << 2 n ; else cout << 3 n ; return 0; }
#include <bits/stdc++.h> using namespace std; namespace IO { inline bool read() { return true; } template <class T1, class... T2> bool read(T1 &a, T2 &...rest) { return (cin >> a) ? read(rest...) : 0; } template <class... T> bool read(char *a, T &...rest) { return (cin >> a) ? read(rest...) : 0;...
#include <bits/stdc++.h> using namespace std; long long l1, l2, r1, r2, q; long long p1, p2; int main() { scanf( %lld , &q); for (int i = 1; i <= q; i++) { scanf( %lld%lld%lld%lld , &l1, &r1, &l2, &r2); p1 = l1; p2 = l2; if (p1 == p2) p2 = r2; printf( %lld %lld n , p1, p2);...
#include <bits/stdc++.h> using namespace std; long long gcd(long long x, long long y) { return (!y ? x : gcd(y, x % y)); } long long lcm(long long x, long long y) { return x / gcd(x, y) * y; } void file() {} void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); file(); } int dx[] = {-...
#include <bits/stdc++.h> using namespace std; double x[111111]; double sX, sY; int n, K; double Solve(int l, int r) { if (l > r) return 0; return min(hypot(x[l] - sX, sY), hypot(x[r] - sX, sY)) + x[r] - x[l]; } int main() { scanf( %d%d , &n, &K); K--; for (int i = 0; i < n; ++i) scanf(...