func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, r; cin >> n >> r; vector<double> a(1 << n); double sum = 0, div = (double)(1 << n); for (int i = 0; i < (1 << n); i++) { int x; cin >> x; a[i] = (double)x; s...
#include <bits/stdc++.h> using namespace std; 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; } long long modInverse(long long...
#include <bits/stdc++.h> using namespace std; const int M = 111111; int Tit[M]; int ra[M]; int k[M]; int r, j, rslt = 0; vector<int> vec[M]; void dfs(int u, int v) { ra[u] = ra[v] + 1; k[ra[u]] ^= 1; int j = vec[u].size(); int z; while (j--) { z = vec[u][j]; if (z != v) d...
#include <bits/stdc++.h> typedef long long ll; #define endl n #define pq priority_queue <pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> #define graph1 vector<vector<pair<ll,ll>>> #define graph vector<vector<ll>> #define pq1 priority_queue<pair<ll, pair<ll, ll>>, vector<pair<ll, pair<ll,ll>>>,...
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; using vvi = vector<vi>; using ll = long long; using vll = vector<ll>; using vvll = vector<vll>; using pii = pair<int, int>; using pll = pair<ll, ll>; ll power[40]; void dfs(int id, vi& v, vi& s) { if (id < v.size()) { s....
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; struct Point { double x, y; Point(double x = 0, double y = 0) : x(x), y(y) {} }; double Dot(Point A, Point B) { return A.x * B.x + A.y * B.y; } double Length(Point A) { return sqrt(Dot(A, A)); } double Angle(Point A, Point B) {...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, m, a[N], type, l, r; set<int> q[N]; inline int myrand() { return rand() ^ (rand() << 16); } struct item { item *l, *r; int key, prior, val; long long sum; item() {} item(int _key, int _val) { val = sum = _v...
#include <bits/stdc++.h> using namespace std; #define ll long long int #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define scan(a,n) for(long long int index=0;index<n;index++) cin>>a[index]; #define print(a,n) for(long long int index=0;index<n;index++) cout<<a[index]<< ;co...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[n]; long long sum = 0; for (int i = 0; i < n; i++) cin >> arr[i]; vector<int> odd, even; for (int i = 0; i < n; i++) { if (arr[i] & 1) odd.push_back(arr[i]); else even.push_bac...
#include <bits/stdc++.h> using namespace std; using vi = vector<long long int>; using vvi = vector<vi>; using vb = vector<bool>; using vc = vector<char>; using vs = vector<string>; using vld = vector<long double>; using pii = pair<long long int, long long int>; using psi = pair<string, long long int>;...
#include <bits/stdc++.h> using namespace std; const int mx[8] = {-1, 1, -1, 1, -2, 2, -2, 2}; const int my[8] = {-2, -2, 2, 2, -1, -1, 1, 1}; const int MAXN = 1100; const int MAXM = 1100; int N, M; const int MAXV = MAXN * MAXM; int V; int source[2]; int target[2]; int dist[2][MAXV]; int nxt[2][M...
#include <bits/stdc++.h> using namespace std; const int maxn = 5000 + 7; int n, a[maxn], ans[maxn], b[maxn], id; map<int, int> mp; int t0 = 0, t1 = 0, t2 = 0; int cnt[maxn]; void work(int id) { for (int i = 2;; ++i) { int t = i * i; if (a[id] >= 0 && t > a[id]) return; if (a[id] < 0 ...
#include <bits/stdc++.h> using namespace std; int main() { int n, a = 0, k = 2000000000; cin >> n; for (int i = 0; i < n; i++) { int x; cin >> x; if (x % n <= i) x = x / n; else x = x / n + 1; if (x < k) { a = i; k = x; } } cout...
#include <bits/stdc++.h> using namespace std; long long fact[100001], inv[100001], ifact[100001]; template <typename T, typename T1> T mod(T x, T1 p) { x %= p; if (x < 0) x += p; return x; } template <typename T> T inverse(T x, T p) { x = mod(x, p); if (x == 1) return x; return mod...
#include <bits/stdc++.h> using namespace std; const int INF = 0x7fffffff; long long n, m, k, x, s; const int maxn = 2e5 + 10; long long a[maxn], b[maxn], c[maxn], d[maxn]; int main(void) { cin.sync_with_stdio(false); cin >> n >> m >> k >> x >> s; for (int i = (0); i < (m); i++) { cin >> a[...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 500; const int INF = 1e7 + 500; const int MOD = 1e9 + 7; const int LOG = 18; const double EPS = 1e-9; const double PI = 3.1415926535; vector<pair<int, int> > P; long double L = INF, R = -INF, M1, M2; long double dist(long double x0...
#include <bits/stdc++.h> using namespace std; const int N = 5005; vector<string> A[N]; vector<int> pq[N]; int n, m; bool val[N]; inline int fnc(int i, int x) { int ans = 0; for (__typeof((n)) j = (1); j <= (n); j++) { if (A[j].size() == 3) { if (!pq[j].empty()) val[j] = val...
#include <bits/stdc++.h> inline void in(int &MAGNUS) { scanf( %d , &MAGNUS); } inline void out(int MAGNUS) { printf( %d n , MAGNUS); } inline void in(int &MAGNUS, int &CLAR) { scanf( %d%d , &MAGNUS, &CLAR); } inline void out(int MAGNUS, int CLAR) { printf( %d %d n , MAGNUS, CLAR); } inline void inl(long long ...
#include <bits/stdc++.h> using namespace std; bool sBs(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); } long long SUMD(long long n); long long BS(vector<pair<long long, long long> > &PS, long long s, long long e, long long ser); long long MI(long long a,...
#include <bits/stdc++.h> using namespace std; int n, m, k; struct point { int x, y, ind; }; vector<point> fd[200200]; vector<point> bd[200200]; long long out[100100]; int main() { scanf( %d%d%d , &n, &m, &k); memset(out, -1, sizeof out); for (int i = 0, x, y; i < k; ++i) { scanf( %...
#include <bits/stdc++.h> using namespace std; const long long inf = 1000000001; const long long maxg = 4444444444LL; vector<long long> g; void recurs(int d, int len, long long z) { if (d == len) g.push_back(z); else { recurs(d + 1, len, z * 10 + 4); recurs(d + 1, len, z * 10 + 7); ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e3 + 5; int main() { int x1, y1, x2, y2; while (~scanf( %d%d%d%d , &x1, &y1, &x2, &y2)) { long long x = x2 - x1 + 1; long long y = y2 - y1 + 2; long long s = x * y / 2 - x / 2; printf( %lld n , s); } }
#include <bits/stdc++.h> using namespace std; vector<long long int> facts; vector<long long int> inv_facts; long long int c(long long int n, long long int p) { if (p < 0 || n < p) return 0; return (facts[n] * inv_facts[p]) % 1000000007 * inv_facts[n - p] % 1000000007; } long long int pow_mod(long lo...
#include <bits/stdc++.h> using namespace std; const int N = 1000005, md = 998244353; int n, i, j, k, e, p[N], lmt, len, rt[N], ome[N], rome[N], g[N], h[N], w1[N], w2[N], inv[N]; long long a[N], b[N], w, xxj[65]; inline void Read(long long &x) { char c; while ((c = getchar()) < 0 || c > 9 ) ...
#include <bits/stdc++.h> using namespace std; int dp[5005][15], oo = 1e5; char str[5005]; int solve(int i, int s) { if (str[i] == 0 and s == 2) { return 0; } else if (str[i] == 0 and s != 2) { return oo; } else if (~dp[i][s]) { return dp[i][s]; } else { int ans = 0; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; int cnt[maxn][26]; int dif[26]; int getAns() { int cc = 0; for (int i = 0; i < 26; ++i) if (dif[i]) { ++cc; } return cc; } int main() { string s; cin >> s; int len = s.length(); for (int...
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; inline int add(int a, int b) { a += b; if (a >= mod) a -= mod; return a; } inline int mult(int a, int b) { long long t = 1ll * a * b; if (t >= mod) t %= mod; return t; } int k, dp[1010][1010]; int main() { ...
#include <bits/stdc++.h> using namespace std; const int M = 3e5 + 5; int a[M], b[M], c, lst[M], sl[M], ans[M]; struct D { int p1, p, s; }; queue<D> q; int read() { int s = 0, t = 1; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == - ) t = -1; for (; isdigit(ch...
#include <bits/stdc++.h> using namespace std; const int E4 = 1e4 + 2; const int E5 = 1e5 + 2; const int E6 = 1e6 + 2; const int MOD = 1e9 + 7; const int INF = 1e9 + 8; const double eps = 1e-12; const double pi = 3.14159265359; const long long INFL = 1ll * INF * INF; void getTime(double sub = 0.0) { ...
#include <bits/stdc++.h> using namespace std; map<int, int> dp; int l[305], c[305]; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> l[i]; for (int i = 0; i < n; i++) cin >> c[i]; dp[0] = 0; for (int i = 0; i < n; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, c, b, ans = 0; cin >> n; int a[n + 1]; for (int i = 1; i <= n - 1; i++) cin >> a[i]; cin >> c >> b; for (int i = c; i <= b - 1; i++) ans += a[i]; cout << ans; }
#include <bits/stdc++.h> using namespace std; int C[155][155]; int ans[155][2][155], cnt = 0; bool vis[150] = {0}; void DFS(int x, int c) { int i; if (x > 150) return; C[x][0] = C[x - 2][0]; for (i = 1; i < x; i++) { C[x][i] = c * C[x - 1][i - 1] + C[x - 2][i]; if (C[x][i] < -1 || ...
#include <bits/stdc++.h> using namespace std; using uint = unsigned int; using ll = long long; using ull = unsigned long long; constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); } int bsr(int x) { return 31 - __builtin_clz(x); } template <class T> using V = vector<T>; template <class T> ...
#include <bits/stdc++.h> using namespace std; int cross(const complex<int>& a, const complex<int>& b) { return a.real() * b.imag() - a.imag() * b.real(); } int hypot2(const complex<int>& a) { return a.real() * a.real() + a.imag() * a.imag(); } int N; vector<complex<int> > pt; vector<complex<int>...
#include<bits/stdc++.h> #define rb(a,b,c) for(int a=b;a<=c;++a) #define rl(a,b,c) for(int a=b;a>=c;--a) #define LL long long #define IT iterator #define PB push_back #define II(a,b) make_pair(a,b) #define FIR first #define SEC second #define FREO freopen( check.out , w ,stdout) #define rep(a,b) for(...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; long long int a[n]; long long int b[n]; int pos = 1; for (int i = 0; i < n; ++i) { cin >> a[i]; b[i] = a[i]; } sort(b, b + n); ...
#include <bits/stdc++.h> using namespace std; int N, K; int a[2210], b[2210]; int cnt[2210]; long long func(void) { int i, j = N; int aans = -1, bans = -1, bid = -1; long long best = (1ll << 60); for (i = N - 1; i >= 0; i--) { while (j > i || (j > 0 && cnt[j - 1] > 0)) { j--; ...
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 2; const int mod = 998244353; void inc(int& x, const int& y) { (x += y) >= mod ? x -= mod : 0; } void dec(int& x, const int& y) { x < y ? x += mod - y : x -= y; } void cmax(int& x, const int& y) { x = x > y ? x : y; } int n, k, m; int l[N...
#include <bits/stdc++.h> using namespace std; void Solution() { int n, k; cin >> n >> k; int a[n]; vector<int> v; for (int i = 0; i < n; i++) { cin >> a[i]; if (5 - a[i] >= k) { v.push_back(a[i]); } } cout << v.size() / 3 << endl; } int main() { ios_base...
#include <bits/stdc++.h> using namespace std; long long a, b, x, y; long long r; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long binsearch(long long i, long long j, long long w, long long m) { if (i == j) { if (i * w <= a && i * m <= b) return i; return -1; ...
#include <bits/stdc++.h> using namespace std; struct point { int x, y; }; int n, k, l[1000002], r[1000002]; point a[1000002]; bool cmp(point a, point b) { return a.x < b.x; } void nhap() { cin >> n >> k; for (int i = 1; i <= n; ++i) { cin >> a[i].x; l[i] = 0; r[i] = 0; } ...
#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; const int N = 1e5; int n, k, a[N]; long long seg[4 * N + 4], dp[N + 1][12]; void update(int p, int l, int r, int indx, long long val) { if (l == r) { seg[p] = val; return; } int mid = l + (r - l) / 2; if (indx <= mid) update(p * 2...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) const long long INF = 0x3f3f3f3f3f3f3f3f; const long long llinf = (1LL << 61); const int inf = (1 << 30); const int nmax = 1e3 + 50; const int mod = 1e9 + 7; using namespace std; int n, m, i, j, a[nmax][nmax], aa[nmax][nmax], b[nmax][nmax], bb[nmax][nm...
#include <bits/stdc++.h> using namespace std; class trio { public: long long first, second, third; }; long long gcdExtended(long long a, long long b, long long *x, long long *y) { if (a == 0) { *x = 0, *y = 1; return b; } long long x1, y1; long long gcd = gcdExtended(b % a, a,...
#include <bits/stdc++.h> using namespace std; template <class T> inline void checkmin(T &a, T b) { if (b < a) a = b; } template <class T> inline void checkmax(T &a, T b) { if (b > a) a = b; } int cond = (long long)1; void _main() { int n, w, m; scanf( %d%d%d , &n, &w, &m); int gues...
#include <bits/stdc++.h> using namespace std; int n, k, x; int a[255]; long long dp[255][255][255]; int main() { cin >> n >> k >> x; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i <= n; i++) for (int j = 0; j <= k; j++) { for (int p = 0; p <= x; p++) { ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 11, mod = 998244353; int ans, n, k, blo, bel[N], f[N], g[N], a[N], L[N], R[N], las[N], bef[N], lim[N], sum[411][N], Sum[411]; inline void inc(int &x, int y) { x += y; if (x >= mod) x -= mod; } inline void deal(int l, int r, int ...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; const int N = 1000 + 20; int n, m, q, part[N][N]; string s[N]; inline int get(int x) { return (__builtin_popcount(x) & 1 ? -1 : +1); } inline int get(int x, int y) { return get(x) * ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); long long a, b, m; long long vx, vy, vz; cin >> a >> b >> m >> vx >> vy >> vz; double time = -((double)(m) / (double)(vy)); double xc = (double)(a) / 2.0 + time * vx; if ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 7; long long a[MAXN]; int n, k, x; void print() { for (int i = 1; i <= n; ++i) cout << a[i] << ; exit(0); } int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n >> k >> x; vector<int> zeros;...
#include <bits/stdc++.h> using namespace std; const int MAX = 2e6 + 10; int n, k, count1; int a[MAX]; int res = 1e19 + 10; int binary_search1(int x, int l, int r) { int res = 0; while (l <= r) { int mid = (l + r) >> 1; if (a[mid] <= x) { res = mid; l = mid + 1; } el...
#include <bits/stdc++.h> using namespace std; const int inf = 0x7fffffff; const int Size = 1000 * 1000 + 1; char buffer[Size]; int solution(int nTest) { int n, m, K; scanf( %d%d%d , &n, &m, &K); vector<string> name; vector<vector<int> > a, b, c; for (int i = 0; i < n; i++) { scanf( %...
#include <bits/stdc++.h> const int N = 1e5, V = 5; const unsigned long long MOD = 1ull << 58, INV5 = 14757395258967641293ull; struct Com { unsigned long long a[V]; inline void clear() { a[0] = a[1] = a[2] = a[3] = a[4] = 0; } inline Com() { clear(); } inline unsigned long long &operator[](int x) {...
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; const int maxn = 2e5; const int INF = 0x7fffffff; const int mod = 1e9 + 7; const double eps = 1e-7; const double Pi = acos(-1.0); inline int read_int() { char c; int ret = 0, sgn = 1; do { c = getchar(); } while ...
#include <bits/stdc++.h> using namespace std; const int maxn = 505, maxmax = 1000000; int n, javab[maxn][maxn]; vector<int> v; int dp(int l, int r) { int x = maxmax; if (l == r) { javab[l][r] = 1; return 1; } if (l == r - 1) { if (v[r] == v[l]) { javab[l][r] = 1; ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC optimize( no-stack-protector ) #pragma GCC optimize( unroll-loops ) #pragma GCC optimize( fast-math ) #pragma GCC target( sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native ) using namespace std; template <typename T> void uin(T &a, T b) { ...
#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 int MAXLEN = 15; long long dp[MAXLEN + 1][2]; long long dpleq[MAXLEN + 1][2]; inline int conv(char c) { if (isdigit(c)) return c - 0 ; if (islower(c)) return c - a + ...
#include <bits/stdc++.h> int main() { int n; scanf( %d , &n); int ans = 0; int score = -1; for (int i = 0; i < n; i++) { int sub, subsc = 0; scanf( %d , &sub); subsc += sub; scanf( %d , &sub); subsc += sub; scanf( %d , &sub); subsc += sub; scanf( %d ...
#include <bits/stdc++.h> using namespace std; const int N = 450, inf = 1e8; int n1, n2, m, r, b, node, s, t, S, T, a[N], id[N]; char col1[N], col2[N]; int head[N], ce = 1, inq[N], dis[N], maxflow, mincost, need; struct edge { int to, nxt, cap, flow, w; } e[5000]; void lnk(int a, int b, int c, int w)...
#include <bits/stdc++.h> using namespace std; int search_factor(int n) { if (n % 2 == 0) { return n / 2; } else { for (int i = (n - 1) / 2; i >= 1; i -= 1) { if (n % i == 0) return i; } } } int main() { int n; cin >> n; long long int sum = n; while (n != 1) ...
#include <bits/stdc++.h> using namespace std; struct sTree { int L, R; int pl, pr; long long sum_m; long long sum_r; } tree[2000000]; int treeSize; int s[100009]; int r[100009]; int m[100009]; int BuildTree(int L, int R) { int cur = treeSize++; tree[cur].L = L; tree[cur].R = ...
#include <bits/stdc++.h> using namespace std; void rd(long long &x) { scanf( %lld , &x); } void rd(long long &x, long long &y) { scanf( %lld%lld , &x, &y); } void rd(long long &x, long long &y, long long &z) { scanf( %lld%lld%lld , &x, &y, &z); } void rd(long long &x, long long &y, long long &z, long lo...
#include <bits/stdc++.h> using namespace std; int tc = 0; long long a, b, c, d; inline long long sum(long long i) { return -a * i + b * (d - 1) * i + i * (i - 1) / 2 * b * d; } inline long long calc(long long i) { if (i < 0) return 0; long long ans = 0; if (i < (c + 1) / d) { ans = min...
#include <bits/stdc++.h> using namespace std; int m, n; int a[110][110], b[110][110]; template <typename T> inline void chkmax(T &x, T y) { x = max(x, y); } template <typename T> inline void chkmin(T &x, T y) { x = min(x, y); } template <typename T> inline void read(T &x) { T f = 1; ...
#include <bits/stdc++.h> using namespace std; struct DT { int l, r, x; }; DT qr[300005]; int n, m, ans[300005], tree[4 * 300005]; void update(int nd, int b, int e, int l, int r, int v) { if (r < l || l < 1 || r > n) return; if (b > r || e < l) return; if (tree[nd] != 0 && b != e) { tre...
#include <bits/stdc++.h> using namespace std; int n, cnt = 0; int main() { ios::sync_with_stdio(false); cin >> n; if (n <= 3) { cout << NO ; return 0; } cout << YES << n ; if (n % 2) { cout << 5 - 3 = 2 << n ; cout << 2 + 1 = 3 << n ; cout << 3 *...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; const int INF = 1000000009; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); int a, b; cin >> a >> b; if ((a || b) && max(a, b) - min(a, b) < 2) { cout << YES ; } else { cout << ...
#include <bits/stdc++.h> using namespace std; vector<pair<pair<int, int>, int> > v; int a[(int)(1e5 + 50)]; string s; void solve() { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) { int x; scanf( %d , &x); s += (char)(x + 0 ); } for (int i = 0; i < s.size();) { ...
#include <bits/stdc++.h> using namespace std; const int NMAX = 755; const long long INF = 1LL << 62; long long dp[NMAX][NMAX]; int main() { cin.sync_with_stdio(false); int n, m; cin >> n >> m; vector<int> v(n); for (int i = 0; i < n; i++) { cin >> v[i]; } for (int i = n - 1; ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n; cin >> n; long long int k; cin >> k; vector<long long int> arr(n, 0); long long int cnt = 0; for (int i = 0; i < n; ++i) { cin >> arr[i]; long ...
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> bool Max(T1& a, T2 b) { return a < b ? a = b, 1 : 0; } template <typename T1, typename T2> bool Min(T1& a, T2 b) { return a > b ? a = b, 1 : 0; } const int N = 1000001; bool prime[N]; vector<long long> pri; v...
#include <bits/stdc++.h> using namespace std; void test_case() { int n; long long k; cin >> n >> k; int l, r[2] = {-1, -1}; long long curr[2] = {k, k}, ans[2] = {0, 0}, monsters; for (int i = 0; i < n; i++) { int old_r[2] = {r[0], r[1]}, tmp_r; long long old_curr[2] = {curr[0], c...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; int vis[maxn]; vector<int> e[maxn]; vector<int> w[maxn]; int a[maxn]; int ans; void add_edge(int u, int v, int ww) { e[u].push_back(v); e[v].push_back(u); w[u].push_back(ww); w[v].push_back(ww); } void dfs(int n...
#include <bits/stdc++.h> using namespace std; #define ll int #define vl vector<long long> #define fr(i,a,n) for(ll i=a; i<n; i++) #define all(x) x.begin(), x.end() int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll t; cin>>t; while(t--){ ll n, x=0, z...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; bool et[N]; int n; int mob[N]; vector<int> d[N]; int cnt[N]; bool get(int x) { int coprime = 0; for (auto p : d[x]) coprime += cnt[p] * mob[p]; return coprime > 0; } void update(int x, int val) { for (auto p : d[x])...
#include <bits/stdc++.h> using namespace std; int main() { int N, X, Y; cin >> N >> X >> Y; int p = ceil(Y / 100.0 * N); cout << max(p - X, 0) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s; int i, j, count_star, diff, res = 0, n; cin >> s; n = s.size(); for (i = 0; i < n; i++) { diff = count_star = 0; for (j = i; j < n; j++) { if (s[j] == ( ) diff++; else if (s[j] == ) ) ...
#include <bits/stdc++.h> using namespace std; int P; int g1() { double p = rand() / 32767.0, s = 0, g = 1; for (int k = 0;; k++) { if (k) g *= k; double c = pow(P, k) * exp(-P) / g; s += c; if (p <= s) return k; } } int g2() { double p = rand() / 32767.0, s = 0; for...
#include <bits/stdc++.h> using namespace std; unsigned gcd(unsigned a, unsigned b) { unsigned r; do { r = a % b; a = b; b = r; } while (r > 0); return a; } unsigned arr[705]; bool dp[705][705][2]; bool en[705][705][2]; unsigned g[705][705]; bool f(int l, int r, int rm) ...
#include <bits/stdc++.h> using namespace std; void __dbg() { cout << endl; } template <typename Arg, typename... Args> void __dbg(Arg A, Args... B) { cout << << A; __dbg(B...); } const int inf = INT_MAX; const int ninf = INT_MIN; const int mod = 1e9 + 7; const int maxN = 1e6 + 2; int mai...
#include <bits/stdc++.h> using namespace std; int p[111]; int main() { int n, a = 0, b = 0, c = 0; cin >> n; for (int i = 1; i <= n; i++) { cin >> p[i]; if (i < 3 && i == 1 || i % 3 == 1) { a = a + p[i]; } else if (i < 3 && i == 2 || i % 3 == 2) { b = b + p[i]; ...
#include <bits/stdc++.h> using namespace std; int main() { long long int t, n, l, r; cin >> t; while (t--) { cin >> n; r = n; l = (-1) * (n - 1); cout << l << << r << n ; } return 0; }
#include <bits/stdc++.h> using namespace std; int main(void) { int n, m, v[100][100], x, y, cnt, ans = 0, dcnt = 1; vector<int> del; memset(v, 0, sizeof(v)); cin >> n >> m; for (int i = 0; i < m; i++) { cin >> x >> y; v[x - 1][y - 1] = 1; v[y - 1][x - 1] = 1; } while (d...
#include <bits/stdc++.h> using namespace std; int N; long long dp[2 * 100000 + 10][2], arr[2 * 100000 + 10]; long long Solve(int, bool); int main() { scanf( %d , &N); dp[0][0] = dp[0][1] = dp[1][0] = dp[1][1] = -2; for (int i = 2; i <= N; i++) { scanf( %I64d , &arr[i]); dp[i][0] = dp[i...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, i, j; cin >> n; map<long long, long long> mp, cp; vector<long long> v(n); for (i = 0; i < n; i++) { cin >> v[i]; mp[v[i]]++; } ...
#include <bits/stdc++.h> using namespace std; int a[10][10], b[5010], c[51]; string s[110][110]; int main() { int maxx = 0; int summ = 0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { cin >> a[i][j]; summ = summ + a[i][j]; } } a[1][1] = summ / 6; ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1E9 + 9; int n, m, ans, cntNode(1), root(1), f[200], dp[1005][105][13], vis[1005][105][13]; string s; struct Trie { int son[4], fail, len; Trie() { for (int i = 0; i < 4; i++) son[i] = 0; fail = len = 0; } } tr[105];...
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> T pow_mod(T a, U b, int mod) { T r = 1; for (; b > 0; b >>= 1) { if (b & 1) r = (long long)r * a % mod; a = (long long)a * a % mod; } return r; } namespace combinatorics { const int mod = 1e9 + 7, N =...
#include <bits/stdc++.h> using namespace std; char opt; long long a, b, c, ansa, ansb, ansc, anslen = 15; void dfs(long long a, long long b, long long c, long long nowa, long long nowb, int pre, long long len, long long step) { if (len >= anslen) return; if (!a && !b && !c && !pre) { an...
#include <bits/stdc++.h> using namespace std; constexpr int mod = 998244353; int x[5], y[5]; int px[32], nx[32], py[32], ny[32]; int dp[32][20][20][20][20][2][2]; void add(int& x, const int& y) { x += y; if (x >= mod) x -= mod; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr)...
#include <bits/stdc++.h> using namespace std; bool qo(bool x) { return (x ? 0 : qo(!x)); } const int mnx = 1e5 + 9; const int mod = 1e9 + 7; long long n, sum; long long a[mnx]; int main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); cin >> n; for (int i = 0; i < n; i++) { ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:256000000 ) using namespace std; const int INF = 1000001000; const int mod = 1000 * 1000 * 1000 + 7; const int mod9 = 1000 * 1000 * 1000 + 9; const double PI = 3.1415926535897932; double sqr(double first) { return first * first; }; long double sqr...
#include <bits/stdc++.h> const double EPS = 1e-10; const double PI = acos(-1.0); using namespace std; int main(void) { int n; cin >> n; vector<pair<int, int> > e; for (int i = (0); i < (n); ++i) { int a, b; cin >> a >> b; e.push_back(make_pair(a, b)); } sort((e).begin()...
#include <bits/stdc++.h> using namespace std; char field[50][50]; bool used[50][50]; int n, m, k; int counts[26]; int cur_set; set<string> min_ways; int min_len = INT_MAX; int start_x, start_y, end_x, end_y; vector<char> alpha(0); bool comp(pair<int, int> a, pair<int, int> b) { if (field[a.fir...
#include <bits/stdc++.h> using namespace std; vector<long long> AE[1000005]; long long par[1000005]; enum LG { AND = 1, OR = 2, XOR = 3, NOT = 4, IN = 5 }; long long type[1000005], inp[1000005]; inline void nedge(long long a, long long b) { AE[a].push_back(b), par[b] = a; } bool oans[1000005]; bool dfs(...
#include <bits/stdc++.h> using namespace std; struct osoba { string ime, prezime; }; int main() { int n; cin >> n; vector<osoba> osobe(n); vector<int> redoslijed(n); vector<string> minori(n); bool trigger = true; for (int i = 0; i < n; i++) cin >> osobe[i].ime >> osobe[i].prezime...
#include <bits/stdc++.h> using namespace std; void CyBerForCe() { long long n, k, x; cin >> n >> k >> x; vector<long long> v, u1, u2; long long f[1024] = {0}, temp[1024]; for (long long i = 0; i < n; i++) { long long a; cin >> a; v.push_back(a); f[a]++; } for (lon...
#include <bits/stdc++.h> using namespace std; const int N = 2e3 + 2; bitset<N> equa[N], value[N]; int ans[N], hehe[N]; signed main() { ios::sync_with_stdio(0); cin.tie(0); int n, m, i, j, k, l, num = 0; cin >> n >> m; for (i = 0; i < n; i++) { value[2 * i][2 * i] = 1; value[2 *...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fLL; const double EPS = 1e-8; const int MOD = 998244353; const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1}; struct IOSetup { IOSetup() { cin.tie(nullptr); ios_base::sync_wit...