func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int n, a, d, t, v; double tim[200000]; double jisuan(double a, double vmax, double s) { double t = (vmax) / a; if (0.5 * a * t * t > s) return sqrt(s * 2 / a); else return t + (s - 0.5 * a * t * t) / vmax; } int main() { scanf( %d%d%d...
#include <bits/stdc++.h> using namespace std; const int MAXN = (int)2e5 + 7; vector<int> G[MAXN]; int pic[1007][1007], vis[MAXN], siz[MAXN]; unordered_map<int, int> mp; int tot, val[MAXN]; int fa[MAXN], sz; int findfa(int x) { if (x == fa[x]) return x; return fa[x] = findfa(fa[x]); } void un...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k; cin >> n >> k; long long int i, a[n]; for (i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); if (a[0] == a[n - 1] && a[0] == 0) { while (k--) cout << 0 << endl; } long long int b[n], ct = 0; for (i...
#include <bits/stdc++.h> using namespace std; const int N = 55; int r[N][N], c[N][N], s[N][N], f[N][N][N][N], n; int sol(int x1, int y1, int x2, int y2) { if (x1 <= 0 || x2 <= 0 || y1 <= 0 || y2 <= 0 || x1 > n || x2 > n || y1 > n || y2 > n || x1 > x2 || y1 > y2) return 0; if (f[x1][y1][x2]...
#include <bits/stdc++.h> using namespace std; class C_ {}; template <typename T> C_& operator<<(C_& __m, const T& __s) { if (!1) cerr << E[91m << __s << E[0m ; return __m; } C_ merr; struct __s { __s() { if (1) { ios_base::Init i; cin.sync_with_stdio(0); cin....
#include <bits/stdc++.h> using namespace std; const int N = 500005; int n, m, h[N], mn[N], par[N], t, num, op, uo, ra; vector<int> adj[N]; set<int> answer, qtr; bool finish, q[N], vis[N]; struct edge { int u, v; } ed[N]; void output() { if ((int)answer.size() == n) { cout << NO << n ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { int n, k; cin >> n >> k; int arr[n], brr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } sort(arr, arr + n, gr...
#include <bits/stdc++.h> using namespace std; void solve() { int n, c0, c1, h; cin >> n >> c0 >> c1 >> h; string s; cin >> s; int ans = 0; for (char ch : s) { if (ch == 0 ) { ans += min(c0, c1 + h); } else { ans += min(c1, c0 + h); } } cout << ans <...
#include <bits/stdc++.h> using namespace std; vector<int> AL[100005]; int main() { int n; scanf( %d , &n); for (int i = 0; i < n - 1; i++) { int u, v; scanf( %d , &u); scanf( %d , &v); AL[u].push_back(v); AL[v].push_back(u); } long long int l = 0; int fl = 0; ...
#include<bits/stdc++.h> #define ll long long #define ull unsigned long long #define in(ar,n) for(int i=0;i<n;i++)cin>>ar[i]; #define invec(ar,n)for(int i =0 ; i<n;i++){int temp;cin>>temp;ar.push_back(temp);} #define in2d(ar,n,m) for(int i=0;i<n;i++)for(int i=0;i<m;i++)cin>>ar[i] #define out(ar,n) f...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, d, h, i, p, q, s; cin >> n >> d >> h; if (d > (2 * h)) { cout << -1 ; } else if ((d == 1) && (h == 1)) { if (n == 2) { cout << 1 2 ; } else { cout << -1 ; } } else if ((d == h))...
#include <bits/stdc++.h> using namespace std; const int N = 25; const int mo = 1000000007; const int inf = (int)1e9; inline int IN() { char ch; (ch = getchar()); int f = 0, x = 0; for (; ((ch) == n || (ch) == r || (ch) == t || (ch) == ); (ch = getchar())) ; if (c...
#include <bits/stdc++.h> using namespace std; const long long N = 2e3 + 10, big = 1e18, mod = 1e9 + 7; vector<long long> a[N], now, ans; long long n, x, y, m, maxi; bool vis[N], mp[N][N]; void dfs(long long i) { vis[i] = 1, now.push_back(i); for (int j = 0; j < a[i].size(); j++) if (!vis[a[i][...
#include <bits/stdc++.h> using namespace std; vector<int> V; void initSet(int _size) { V.resize(_size); for (int i = int(0); i <= int(_size - 1); i++) V[i] = i; } int findSet(int i) { return (V[i] == i) ? i : (V[i] = findSet(V[i])); } void unionSet(int i, int j) { V[findSet(i)] = findSet(j); } boo...
#include <bits/stdc++.h> using namespace std; const long long N = 3e5 + 5; const long long INF = 1e18; const long long mod = 1e9 + 7; void solve() { long long n, m, k; string s; cin >> n; map<int, int> F; while (true) { F[n] = 1; n = n + 1; while (n % 10 == 0) n /= 10; ...
#include <bits/stdc++.h> using namespace std; set<int> s; int a[200005]; int b[200005], u[200005]; int n, k; int main() { int T; scanf( %d , &T); for (; T--;) { scanf( %d%d , &n, &k); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); for (int i = 1; i <= k; i++) scanf( %d , &b[i...
#include <bits/stdc++.h> using namespace std; const string alf = abcdefghijklmnopqrstuvwxyz ; const int hashP = 239017; const int N = 1e5 + 10; const int MOD = 1e9 + 7; const int MOD2 = 998244353; const int INF = 1e9; const long long oo = 9e18; template <typename T> bool umn(T &a, T b) { return...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long ans = 0; long long n; cin >> n; vector<long long> a(n), b(n), c(n); string s1, s2; cin >> s1 >> s2; for (long long i = 0; i < n; i++) { a[i] = (s1[i] =...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; while (n <= 70000) { ++n; int x = n; int a[10] = {0}; for (int i = 0; i < 4; i++) { int m = x % 10; ++a[m]; x = x / 10; } int count = 0; for (int i = 0; i < 10; i...
#include <bits/stdc++.h> using namespace std; inline void read(int &x) { char ch; bool flag = false; for (ch = getchar(); !isdigit(ch); ch = getchar()) if (ch == - ) flag = true; for (x = 0; isdigit(ch); x = x * 10 + ch - 0 , ch = getchar()) ; x = flag ? -x : x; } const int INF...
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 10, maxk = 1e6 + 10; int n, k, A[maxn], cnt[maxk], sum[maxk]; int32_t main() { scanf( %d%d , &n, &k); for (int i = int(0); i < int(n); i++) { scanf( %d , A + i); cnt[A[i]]++; } sort(A, A + n); for (int i = int(1...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, f = 0, d = 0; cin >> a >> b; for (int i = 1; i <= 6; i++) { int d1 = abs(a - i), d2 = abs(b - i); if (d1 < d2) f++; else if (d1 == d2) d++; } cout << f << << d << << 6 - f - d << endl; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; long long maxi; maxi = -9999999999; cin >> n >> k; for (int i = 1; i <= n; i++) { int a, b; long long tmp; cin >> a >> b; if (b > k) { tmp = a - (b - k); } else { tmp = a; } ...
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 5, maxlen = 5e5 + 5; const int inf = 3e6 + 5; int n, x[maxn], y[maxn]; char s[maxlen]; int ansb, ansn; bool check(int mid, int ty) { int xmin = 0, xmax = inf, ymin = 0, ymax = inf, dmin = -inf, dmax = inf; for (int i = 1; i <= n;...
#include <bits/stdc++.h> using namespace std; int n, k; string s; long long md = 1000000007; int a[2100]; long long dp[2100][2100]; long long sdp[2100][2100]; int main() { cin >> n >> k >> s; for (int i = 0; i < n; i++) a[i] = s[i] - a ; dp[n][0] = 1; sdp[n][0] = 1; for (int i = n -...
#include <bits/stdc++.h> using namespace std; vector<vector<int>> g; vector<int> c; int root, n; vector<int> dfs(int u) { vector<int> combine; for (int v : g[u]) { vector<int> child = dfs(v); for (int z : child) combine.emplace_back(z); } if (c[u] > combine.size()) { cout << ...
#include <bits/stdc++.h> using namespace std; long long solve() { long long n; cin >> n; vector<long long> arr(n); map<long long, long long> counts; map<long long, long long> checks; for (auto &x : arr) { cin >> x; counts[x]++; } for (auto x : counts) { checks[x.sec...
#include <bits/stdc++.h> using namespace std; long long int n, a[100008], cnt = 0; int main() { ios_base::sync_with_stdio(0); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) { if (a[i] == 1) { if (!cnt) cnt++; int j = i + 1; while (a[j...
#include <bits/stdc++.h> using namespace std; inline void fast_and_furious() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); } int n; long long a[1005], b[1005], u, l, ans; int main() { fast_and_furious(); cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int...
#include <bits/stdc++.h> using namespace std; const long long MAX_I = 1000; long long a[MAX_I + 1]; long long b[MAX_I + 1]; int main() { long long n, m; long long c[5]; long long tmp; long long asum = 0; long long bsum = 0; cin >> c[1] >> c[2] >> c[3] >> c[4]; cin >> n >> m; fo...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; int pos[n + 1]; for (int i = 0; i < n; i++) { int x; cin >> x; pos[x] = i; } int curIndex = 0; for (int i = 0; i < n; i++) { int x; cin >...
#include <bits/stdc++.h> using namespace std; void go() { ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed; cout << setprecision(6); } void solve() { string s; cin >> s; long long n = s.size(); vector<long long> arr(n); long long cur = 0; for (long long i = 0; i < ...
#include <bits/stdc++.h> using namespace std; const int N = 2e3 + 10; int T, n, m, a[N], b[N], l, r, ins[N], las[N]; vector<int> to[N]; struct node { int u; long long k; bool f; }; node q[N]; inline bool check(long long now) { vector<int> s; for (int i = 1; i <= n; ++i) ins[i] = las[...
#include <bits/stdc++.h> using namespace std; const int NMAX = 50; int n; int a[5][NMAX + 5]; int b[NMAX + 5]; vector<int> ans; int main() { cin >> n; for (int i = 1; i <= 2; i++) for (int j = 1; j < n; j++) { cin >> a[i][j]; a[i][j] += a[i][j - 1]; } a[1][n] = a[1]...
#include <bits/stdc++.h> using namespace std; const int NM = 1e5 + 10; int color[NM]; vector<pair<int, char> > adj[NM]; bool dfs(int u, bool c, char type, vector<int> &all) { if (color[u] != -1) return (color[u] == c); all.push_back(u); color[u] = c; for (int i = 0; i < adj[u].size(); i++) { ...
#include <bits/stdc++.h> int main() { long long b; scanf( %lld , &b); long long flag = 0; for (long long i = 1; i < sqrt(b); i++) if (b % i == 0) flag = flag + 1; flag = 2 * flag; long long a = sqrt(b); if (a * a == b) flag = flag + 1; printf( %lld , flag); }
#include <bits/stdc++.h> using namespace std; long long int n; vector<long long int> BIT((int)1e6 + 5, 0); void _update(int x) { while (x <= n) { BIT[x]++; x += x & -x; } } int query(int x) { long long int sum = 0; while (x > 0) { sum += BIT[x]; x -= x & -x; } ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2 * 1000 + 17; int n, init[MAXN][MAXN], hope[MAXN][MAXN], c[MAXN][MAXN], r[MAXN], cnt = 1, comp[MAXN << 2]; vector<int> out[MAXN << 2], in[MAXN << 2], order, trash; vector<pair<string, int>> ans; void add(int i, bool f1, int j, bool f2) { ...
#include <bits/stdc++.h> using namespace std; const int INF = 2e9; long long int n, h; bool check(long long int maxh) { long long int k = min(maxh, h); long long int count = maxh * maxh - k * (k - 1) / 2; return (n >= count); } long long int get(long long int maxh) { long long int k = min(h,...
#include <bits/stdc++.h> using namespace std; int it[200041], n, io; int down(int x) { int s = 0, rs = x; while (x <= n * 2) { s = max(it[x], s); x += x & (-x); } return s; } void up(int x, int u) { while (x > 0) { it[x] = max(it[x], u); x -= x & (-x); } } i...
#include <bits/stdc++.h> int count[5001] = {0}, i = 0, n, a, c = 0; int main() { scanf( %d , &n); for (i = 0; i < n; i++) { scanf( %d , &a); count[a - 1]++; } for (i = 0; i < n; i++) if (count[i] == 0) c++; printf( %d n , c); return 0; }
#include <bits/stdc++.h> using namespace std; inline 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 * 10 + ch - 0 ; ch = getchar(); } return x * f;...
#include <bits/stdc++.h> using namespace std; int m1[502][502], m2[502][502]; int num[502], lie[502]; vector<int> v; const int INF = 0x3f3f3f3f; int main(void) { int a, b, i, j, flag = 1, sum = 0; scanf( %d %d , &a, &b); for (i = 0; i < a; i++) { for (j = 0; j < b; j++) { scanf( %d...
#include <bits/stdc++.h> using namespace std; int main() { int n, c = 0, se = 0, so = 0, soo = 0, see = 0; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; if (i % 2 == 0) so += a[i]; else se += a[i]; } for (int i = 0; i < n; i++) { if (i...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, n, i, t, r = 0; while (cin >> t) { for (i = 0; i < t; i++) { cin >> a >> b >> n; if (n % 3 == 1) cout << b << endl; else if (n % 3 == 0) cout << a << endl; else { r = a ^ ...
#include <bits/stdc++.h> using namespace std; const int N = 500009; const int mod = 1000000007; int n, m, x, y; vector<int> v[N]; vector<bool> vis; bool is; void pre() { vis.assign(N, 0); } void dfs(int ver, int par) { vis[ver] = 1; for (auto &it : v[ver]) { if (it == par) continue; ...
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 7; double pi = 3.1415926535; long long int gcd(long long int a, long long int b) { if (b == 0) { return a; } return gcd(b, a % b); } long long int power(long long int a, long long int n) { long long int res =...
#include <bits/stdc++.h> using namespace std; template <typename T> inline T read() { char c = getchar(); T x = 0, f = 1; while (!isdigit(c)) { if (c == - ) f = -1; c = getchar(); } while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar(); return x * f; } templ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 310; map<int, int> Map; int l[MAXN], c[MAXN], n; int gcd(int x, int y) { return !y ? x : gcd(y, x % y); } int main() { scanf( %d , &n); for (int i = 1; i <= n; ++i) scanf( %d , &l[i]); for (int i = 1; i <= n; ++i) scanf( %d , &c[i]);...
#include <bits/stdc++.h> using namespace std; const int MN = 1000 * 100 + 10; const int inf = (1 << 29); string s, t, ans, tmp; int cnt[30], curr[30]; int main() { cin >> s >> t; sort(s.rbegin(), s.rend()); for (int i = 0; i < s.size(); i++) cnt[s[i] - a ]++; if (s <= t) cout << -1 n...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; scanf( %d %d , &n, &m); map<unsigned long long, vector<int>> pow; vector<int> a(m + 1), s(m + 1), u(m + 1), b(n + 1); for (int i = 1; i <= n; ++i) { unsigned long long p; scanf( %llu , &p); pow[p].push_back(i)...
#include <bits/stdc++.h> using namespace std; struct Point { double x, y; Point(double x = 0, double y = 0) : x(x), y(y) {} Point operator+(Point b) { return Point(x + b.x, y + b.y); } Point operator-(Point b) { return Point(x - b.x, y - b.y); } double operator^(Point b) { return x * b.y - y * b...
#include <bits/stdc++.h> using namespace std; int const N = 400400; int const mod = 1000000007; void add(int &a, int b) { if ((a += b) >= mod) a -= mod; } int prod(int a, int b) { auto x = (unsigned long long)a * b; unsigned int xh = x >> 32, xl = x, q, r; asm( divl %4; n t : =a (q), =d ...
#include <bits/stdc++.h> using namespace std; int x[2010], y[2010]; long long nc2(long long n) { return (n * n - n) / 2LL; } int main() { int T, n, caseNo = 0; map<pair<int, int>, long long> cnt; scanf( %d , &n); for (int i = 0; i <= n - 1; i++) { scanf( %d %d , &x[i], &y[i]); x[i] *...
#include <bits/stdc++.h> using namespace std; class Node { set<int> adj; public: bool isLeave() const { return adj.size() == 1; } void add(int v) { adj.insert(v); } void remove(int v) { adj.erase(v); } int front() const { return *adj.begin(); } }; const int N = 100001; Node neighbors...
#include <bits/stdc++.h> using namespace std; const int N = 111; const int LIMIT = 10000; const double eps = 1e-6; int a[N], b[N]; int n, m; int isSq(long long t) { long long tt = (long long)sqrt(t + eps); return tt * tt == t; } void gen(int n, int a[]) { bool flag = false; while (!fla...
#include <bits/stdc++.h> using namespace std; bool cycle[3001]; int vis[3001]; vector<vector<int> > adj; bool f; int node; bool getC(int ind, int prev) { if (cycle[ind]) { node = ind; return 1; } cycle[ind] = 1; for (int i = 0; i < (int)adj[ind].size(); i++) if (prev != a...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } long long perf[100]; struct BalancedBinaryForest { int n; vector<bool> isblack; vector<int> blackheight; vector<int> lft, rgt, par; void init(int _n) { n = _n; ...
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; long long a, b; cin >> a >> b; if (b < a || (b - a) % 2) cout << -1 << endl; else if (b == a && a == 0) cout << 0 << endl; else if (b == a) ...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const double PI = acos(-1.0); const double eps = 1e-6; const int MAX = 1e5 + 10; const long long mod = 1e9 + 7; struct node { long long l, r, mid, sum, tag; node() {} node(long long a, long long b) { l = a; r...
#include <bits/stdc++.h> using namespace std; const int MOD = (int)1e9 + 7; const int MOD2 = 1007681537; const int INF = (int)1e9; const long long LINF = (long long)1e18; const long double PI = acos((long double)-1); const long double EPS = 1e-9; inline long long gcd(long long a, long long b) { long...
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; ll n, m; cin >> n >> m; std::vector<int> a(n + 2); n = n + 2; a[0] = 0; a[n - 1] = m; for (int i = 1; i <= n; i++) cin >> a[i]; ll v[...
#include <bits/stdc++.h> using namespace std; long long t[3000000]; long long t1[3000000]; long long dp[10 * 10 + 5][10 + 5]; vector<long long> v; long long n, m, k, l, r, nb, q, p; map<long long, int> mapp; void debug(long long* tab, int len) { cout << debug :::: n ; for (int i = 0; i < len; ...
#include <bits/stdc++.h> #pragma warning(disable : 4996) template <typename T> T min(T x, T y) { return x < y ? x : y; } template <typename T> T max(T x, T y) { return x > y ? x : y; }; const int INF = 2000000005; const long long mod = 1000000007; const long long MAXN = 1000005; const doub...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using D = double; using uint = unsigned int; const int maxn = 1005; int n; int a[maxn]; int cnt[maxn]; int have[maxn]; int was[maxn]; int ct = 0; inline bool canset(int x) { int wh = lower_bound(a, ...
#include <bits/stdc++.h> using namespace std; string s[1005]; long long a[1005]; long long ans; long long b[1005][5]; long long ma; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; for (long long i = 1; i <= n; i++) { cin >> s[i...
#include <bits/stdc++.h> int Q; int A; int Ans[33]; int main() { Ans[2] = 1; Ans[3] = 1; Ans[4] = 5; Ans[5] = 1; Ans[6] = 21; Ans[7] = 1; Ans[8] = 85; Ans[9] = 73; Ans[10] = 341; Ans[11] = 89; Ans[12] = 1365; Ans[13] = 1; Ans[14] = 5461; Ans[15] = 4681; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; unsigned long long sum{}; int cur{1}; for (int i{}; i < m; i++) { int x; cin >> x; if (cur < x) { sum += x - cur; cur = x; } else if (cur > x) { sum += n - cur + x;...
#include <bits/stdc++.h> using namespace std; int n; long long ab[11], y[11]; long long val(string abv) { long long res = 0; for (int i = 0; i < (int)abv.size(); i++) res = 10 * res + ((long long)(abv[i] - 0 )); return res; } int main() { cin.sync_with_stdio(false); long long p10 ...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const int N = 100010; int a[N]; vector<int> f[N]; void go() { long long n; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 2; i < N; i++) { for (int j = i; j < N; j += i) f[j].push_back(i); ...
#include <bits/stdc++.h> using namespace std; int l1, r1, l2, r2, ans; int min(int a, int b) { return a < b ? a : b; } int max(int a, int b) { return a > b ? a : b; } int check(int a) { if (a > ans) ans = a; return a; } int solve(int l1, int r1, int l2, int r2, int k) { if (l1 == l2 && r1 == r...
#include <bits/stdc++.h> using namespace std; int main() { char temp[11]; int n, m, k; cin >> n >> m >> k; int a[10][100], b[10][100], c[10][100]; for (int i = 0; i < n; i++) { cin >> temp; for (int j = 0; j < m; j++) cin >> a[i][j] >> b[i][j] >> c[i][j]; } int maxi = 0; ...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int maxn = 100010; int x0[maxn], x1[maxn], d[maxn], c[maxn]; int main() { int n, m, y0, y1; cin >> n >> m >> y0 >> y1; for (int i = 0; i < n; ++i) { cin >> x0[i]; } memset(d, -1, sizeof(d)); for (int ...
#include <bits/stdc++.h> using namespace std; void solve(); void precalc(); clock_t start; bool doing = true; int main() { int t = 1; cout.sync_with_stdio(0); cin.tie(0); precalc(); cout.precision(10); cout << fixed; start = clock(); int testNum = 1; while (t--) { s...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); double x = 0, ans = 0, p[100005] = {0}; int n; cin >> n; for (int i = 1; i <= n; i++) cin >> p[i]; for (int i = 1; i <= n; i++) { x = x * p[i] + p[i]; ans += 2 * x; ans -= p[i]; ...
#include <bits/stdc++.h> using namespace std; string char_to_str(char c) { string tem(1, c); return tem; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; long long n, k; cin >> n >> k; string s; cin >> s; string ans = s; for (long long i = 0; i < n...
#include <bits/stdc++.h> using namespace std; int dx[8] = {0, 0, 1, -1, -1, -1, 1, 1}; int dy[8] = {1, -1, 0, 0, 1, -1, 1, -1}; char s[111][111]; int main() { int n, m; scanf( %d%d , &n, &m); for (int i = 1; i <= n; i++) scanf( %s , s[i] + 1); for (int i = 1; i <= n; i++) for (int j = 1;...
#include <bits/stdc++.h> using namespace std; int dp[105][105][205][2]; string s1; int main() { int n; int ans = 0; memset(dp, 0, sizeof(dp)); cin >> s1; cin >> n; dp[0][0][100][0] = 1; for (int i = 1; i <= s1.size(); i++) { for (int j = 0; j <= 100; j++) { for (int k =...
#include <bits/stdc++.h> using namespace std; const int bigp = 1000000007; int main() { int x[103], y[103], z[103]; x[1] = 1; y[1] = 2; z[1] = 0; x[2] = 3; y[2] = 3; z[2] = 1; x[3] = 4; y[3] = 4; z[3] = 2; x[4] = 5; y[4] = 6; z[4] = 1; x[5] = 7; y[5] = 8...
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 5; long long n, u, v, w, res = 0, par[N]; vector<pair<long long, long long> > a[N]; long long root(long long x) { if (par[x] < 0) return x; return (par[x] = root(par[x])); } void Merge(long long u, long long v) { long long...
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int n; cin >> n; long long int i, j, s = 0, p = 0, u = 0; for (i = 1; i <= n / 2; i++) { s = s + i * i; } cout << s * 8 << endl; } return 0; ...
#include <bits/stdc++.h> using namespace std; long long M1 = 998244353; long long M2 = 1000000007; long long fact[100005]; long long prime[169] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, ...
#include <bits/stdc++.h> using namespace std; constexpr int inf32 = 0x3f3f3f3f; constexpr long long inf64 = 0x3f3f3f3f3f3f3f3f; int main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); int n, m; cin >> n >> m; vector<long long> a(n); for (int u = 0; u < (n); ++u) cin >> a[u]; ...
#include <bits/stdc++.h> using namespace std; long long a[100005], b; int n, k; pair<long long, int> pvec[100005]; int solve() { for (int i = 0; i < n - 1; i++) pvec[i] = make_pair(a[i], i + 1); sort(pvec, pvec + n); reverse(pvec, pvec + n); long long total = 0; int ans = n; for (int i...
#include <bits/stdc++.h> const int B = 500; using namespace std; const long long inf = 1e9 + 12; long long mod = 1e9 + 7; const long long mxn = 4e5 + 5; const int N = 10000005; const double pi = 3.14159; int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}; int dy[] = {1, 0, -1, 0, -1, 1, 1, -1}; long long m, n, ...
#include <bits/stdc++.h> using namespace std; int n, m; char block[][3][4] = {{ ..# , ### , ..# }, { .#. , .#. , ### }, { #.. , ### , #.. }, { ### , .#. , .#. }}; int cell[10][10], anscell[10][10]; int bcnt, ans; bool isPlacable...
#include <bits/stdc++.h> using namespace std; using uint = unsigned int; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; using pll = pair<ll, ll>; template <typename T1, typename T2> ostream &operator<<(ostream &out, const pair<T1, T2> &item) { out << ( << item.fi...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { string a, b, c; cin >> a >> b >> c; int n = a.length(); int count = 0; for (int i = 0; i < n; i++) { if (c[i] == a[i] || c[i] == b[i]) continue; else { ...
#include <bits/stdc++.h> using namespace std; int main() { int k, n[3], t[3]; while (scanf( %d , &k) == 1) { for (int i = 0; i < 3; i++) scanf( %d , &n[i]); for (int i = 0; i < 3; i++) scanf( %d , &t[i]); deque<int> q[3]; for (int i = 0; i < 3; i++) q[i].clear(); int p = 0; ...
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef long double ld; #define F first #define S second const int MOD = 998244353;// XXX const int C = 26;// XXX void add(int &x, int y){ x += y; while (x >= MOD) x -= MOD; whil...
#include <bits/stdc++.h> using namespace std; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); mt19937 rnf(2106); const int N = 100005; int n, m, k; vector<int> a[N]; vector<int> v[2]; void dfs0(int x, int p, int z) { v[z].push_back(x); for (int i = 0; i < a[x].size(); ++i) {...
#include <bits/stdc++.h> using namespace std; const long long MAX = 2e5 + 9, LG = 35; long long sum, b[MAX], c[MAX], a[MAX], n, k[LG]; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> b[i], sum += b[i]; for (int i = 0; i < n; i++) cin >> c[i], sum += c[i]; if (sum % (2 * n) != 0) return...
#include <bits/stdc++.h> using namespace std; int mx1, my1, mx2, my2; string in; int main() { ios::sync_with_stdio(0); cin >> in; mx1 = in[0] - a + 1; my1 = in[1] - 0 ; cin >> in; mx2 = in[0] - a + 1; my2 = in[1] - 0 ; cout << max(abs(mx1 - mx2), abs(my1 - my2)) << endl; ...
#include <bits/stdc++.h> using namespace std; void load() {} const int N = 5e5 + 123; const int inf = 1e9; int a[N], v[N]; int dp[200][200]; void trungtt() { int n, k, p; scanf( %d%d%d , &n, &k, &p); for (int i = 1; i <= n; ++i) scanf( %d , &a[i]), a[i] += a[i - 1], a[i] %= p; if (k * p > ...
#include <bits/stdc++.h> const int G[8][2] = {{0, 4}, {1, 5}, {2, 6}, {3, 7}, {0, 2}, {1, 6}, {3, 4}, {5, 7}}; int f[(1 << 8)], g[1111]; int max(int a, int b) { return a > b ? a : b; } int min(int a, int b) { return a < b ? a : b; } int main() { int n; int i, j, k, _; f[0] =...
#include <bits/stdc++.h> using namespace std; const int MOD = (int)1e9 + 7; const int MAX = 1e6; int len1, len2, pre[MAX], suf[MAX]; bool can_skip(int skip) { for (int i = 1; i + skip - 1 < len1; i++) if (pre[i - 1] + suf[i + skip] >= len2) return 1; return 0; } int main() { string x, y,...
#include <bits/stdc++.h> using namespace std; int main() { ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; for (int i = 0; i < t; i++) { int n; cin >> n; string x; cin >> x; string a(n, 0 ); string b(n, 0 ); for (...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 100; struct node { int u, v, w, f, nxt; node() {} node(int u, int v, int w, int f, int nxt) : u(u), v(v), w(w), f(f), nxt(nxt) {} } e[N << 2]; int h[N], idx = 1; void link(int x, int y, int w) { e[++idx] = node(x, y, w...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullptr); int n, i, j, tmp, tmp2; cin >> n >> tmp; for (i = 1; i < n; i++) { cin >> tmp2; if (tmp == tmp2) { for (i = i + 1; i < ...
#include <bits/stdc++.h> using namespace std; const int N = 5e4 + 5; const int LOG = 16; struct trie { int go[N][2], NFI = 1; trie() { memset(go, -1, sizeof(go)); } void reset() { for (int i = 0; i <= NFI; i++) go[i][0] = go[i][1] = -1; NFI = 1; } void add(int x) { for (int...