func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; void printprecise(double l, long long int precision) { std::cout << std::fixed; std::cout << std::setprecision(precision); std::cout << l; } long long int ncr(long long int n, long long int k) { long long int C[n + 1][k + 1]; long long int i, j; ...
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, i, j, n, t, m; cin >> t; while (t--) { string s; cin >> s; n = s.size(); vector<long long> ans; long long count = 0; for (i = 0; i < n; i++) { if (s[i] == 1 ) count++; ...
#include <bits/stdc++.h> int main() { long long n, m; scanf( %lld %lld , &n, &m); long long res = 1, p = 2; while (m != 0) { if (m % 2 != 0) res = res * p % 1000000007; p = p * p % 1000000007; m >>= 1; } res--; p = res; res = 1; while (n != 0) { if (n % 2 !=...
#include <bits/stdc++.h> using namespace std; int n, k, a, lev[16], loy[16], suf; double ret; double dp[16][(2 << 8)]; double calc(int pos, int mask) { if (pos == n) { int need = suf - __builtin_popcount(mask); if (need <= 0) return 1.0; else { int b = 0; for (int...
#include <bits/stdc++.h> using namespace std; const long long P = 998244353LL; const int N_MAX = 1e5 + 15; int A[N_MAX]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> A[i]; long long ans = 0LL; bool rem = 1; long long q = 1LL; while (rem) { long long t = 0L...
#include <bits/stdc++.h> using namespace std; long long int i, j; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int k, n; cin >> k; long long int maxi = -1; for (i = 0; i < k; i++) { cin >> n; maxi = max(maxi, n); } if (maxi > 25) cout <<...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; const long long INF = 1e9; long long b[N]; long long ans[N]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; for (int i = 1; i <= ...
#include <bits/stdc++.h> using namespace std; const int maxn = 5000 + 10; const int MOD = 998244353; long long f[maxn]; int lim[maxn]; long long frac[maxn], ifrac[maxn]; int arr[maxn], b[maxn]; int n; long long fpow(long long a, long long b) { long long ret = 1; while (b) { if (b & 1) re...
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18; priority_queue<pair<int, int> > p; int n; const int maxn = 1 << 19; int vis[maxn]; long long dp[maxn][19]; int a[maxn], pos, L, sum; long long ans; int main() { scanf( %d , &n); memset(dp, -1, sizeof(dp)); for (int...
#include <bits/stdc++.h> using namespace std; int sx, sy, dx, dy, n, dis[100004]; map<pair<int, int>, int> mp; int main() { cin >> sx >> sy >> dx >> dy; cin >> n; int i, j, cnt = 1; for (i = 0; i < n; i++) { int r, c1, c2; cin >> r >> c1 >> c2; for (j = c1; j <= c2; j++) { ...
/// Down with The Sickness #pragma GCC optimize( O3 ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx ) #pragma GCC optimization ( unroll-loops ) #include bits/stdc++.h using namespace std; using ll = long long; using ii = pair<int, int>; #define pb push_back #define F first...
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; int qmul(int a, int b) { a = (a % mod + mod) % mod; b = (b % mod + mod) % mod; int ans = 0; while (b) { if (b & 1) ans = (ans + a) % mod; a = (a << 1) % mod; b >>= 1; } return ans; } int qpow(int...
#include <bits/stdc++.h> using namespace std; const int N = 111; const long double Eps = 1e-6; int sgn(long double a, long double b = 0) { a -= b; return (a > Eps) - (a < -Eps); } const long double Pi = 4 * atan(1); struct Point { long double x, y; Point operator-(Point p) { return {x - p....
#include <bits/stdc++.h> using namespace std; void mf() { freopen( input.in , r , stdin); } int a[1007]; int n, k; map<int, int> mm; queue<int> q; bool f(map<int, int>& _mm, int x) { return _mm.find(x) != _mm.end(); } void solve() { int m; n = 0; cin >> k >> m; int x; for (int i = 1...
#include <bits/stdc++.h> using namespace std; vector<pair<pair<int, int>, int> > g[100010]; long long dist[100010]; bool mark[100010]; int req[100010]; void dijkstra(int n) { memset(mark, 0, sizeof(mark)); priority_queue<pair<long long, long long>, vector<pair<long long, long long...
#include <bits/stdc++.h> using namespace std; const int INF = 987654321; double f[107][107][107]; int main() { ios::sync_with_stdio(false); cout.precision(10); cout << fixed; int R, S, P; cin >> R >> S >> P; memset(f, 0, sizeof(f)); f[R][S][P] = 1.0; for (int r = R; r >= 0; --r) ...
#include <bits/stdc++.h> using namespace std; int c1, c2, c3, c4; int a[1111], b[1111]; int n, m; int main() { while (cin >> c1 >> c2 >> c3 >> c4) { cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) cin >> b[i]; int mi = min(c4, 2 * c3); int ...
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int n, k1, k2, m1 = INT_MIN, m2 = INT_MIN, tmp; cin >> n >> k1 >> k2; for (long long int i = 0; i < k1; i++) { cin >> tmp; m1 = max(m1, tmp); } for ...
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007; long long power(long long x, int y) { long long res = 1; x = x % mod; if (x == 0) return 0; while (y > 0) { if (y & 1) res = (res * x) % mod; y = y >> 1; x = (x * x) % mod; } return res; } int m...
#include <bits/stdc++.h> using namespace std; void err(istream_iterator<string> it) { cout << endl; } template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << = << a << ; err(++it, args...); } template <typename T> inline void read(T&...
#include <bits/stdc++.h> const long long MOD = 1e9 + 7; using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n; cin >> n; while (n--) { long long ci, sum; cin >> ci >> sum; long long n = sum / ci; long long...
#include <bits/stdc++.h> using namespace std; struct data { int id, a; data() {} data(int id, int a) : id(id), a(a) {} bool operator<(const data &r) const { return a < r.a; } } da[100010]; int n, h; int main() { scanf( %d%d , &n, &h); for (int i = 0; i < n; i++) scanf( %d , &da[i].a), ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1605; int n, m, tot; int a[MAXN][MAXN]; int sz[MAXN * MAXN]; int ans[MAXN * MAXN]; int cnt[MAXN * MAXN]; int fa1[MAXN * MAXN]; int fa2[MAXN * MAXN]; double v[MAXN][MAXN]; double t[MAXN][MAXN]; int getroot(int *fa, int u) { return...
#include <bits/stdc++.h> using namespace std; const int N = 5555; const long long INF = 1e9 + 19; int n; int a[N][3]; bool can[N][3]; int sumH[3]; int cando[3]; void read() { scanf( %d , &n); vector<vector<int> > tmp; tmp.resize(n); for (int i = 0; i < n; i++) { for (int j = 0; j...
#include <bits/stdc++.h> using namespace std; int main() { int n, x; cin >> n; x = (n + 1) / 2; string s, even, odd; cin >> s; for (int i = 0; i < n; i++) { if (i % 2 == 0) odd.push_back(s[i]); else even.push_back(s[i]); } if (n <= 2) { cout << s << ...
#include <bits/stdc++.h> using namespace std; const long long modl = 1000000007; int farr[1000000]; int pre[1000000]; int cum[1000000]; unsigned long long poow(int base, int po); void swaap(int *a, int *b); long long gcd(long long a, long long b); void mul_big_int(string s1, string s2); int cnt_prim...
#include <bits/stdc++.h> const long long int INF = 1e15; using namespace std; const long long int MAX = 1e7 + 5; const long long int mod = 1e9 + 7; long long int gcd(long long int a, long long int b) { while (b > 0) { a = a % b; swap(a, b); } return a; } long long int binpow(long l...
#include <bits/stdc++.h> using namespace std; const int N = 81; const int M = 2001; int n, k, m, ans = 1e9; int cache[N][2][N][N]; vector<pair<int, int> > g[N]; int dp(int idx, int dir, int dist, int taken) { if (taken == k) return 0; int &ans = cache[idx][dir][dist][taken]; if (ans != -1) ret...
#include <bits/stdc++.h> using namespace std; int n; bool next_n(vector<int> &a) { int i = n - 1; for (; i >= 0 && a[i] == 5; --i) { a[i] = 0; } if (i == -1) { return false; } ++a[i]; return true; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); ...
#include <bits/stdc++.h> using namespace std; template <typename Value> class feque { protected: vector<Value> data; public: feque() {} feque(const feque &f) { data = f.data; } feque(feque &&f) { this->data = move(f.data); } feque(initializer_list<Value> list) { data = list; } feq...
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { string input; cin >> input; int i = 0; if (input[0] == 9 ) ++i; for (; i < input.length(); ++i) { if (input[i] >= 5 ) { input[i] = 0 + 9 - input[i]; } } for (int j = 0; j < in...
#include <bits/stdc++.h> using namespace std; char arr[21]; char brr[21]; int player1[100]; int player2[100]; int main() { char z; cin >> arr; cin >> brr; memset(player1, 0, sizeof(player1)); memset(player2, 0, sizeof(player2)); int n, t, d, i, f, m; char p, s; cin >> n; ...
#include <bits/stdc++.h> using namespace std; template <class T, class S> ostream& operator<<(ostream& os, const pair<T, S>& v) { return os << ( << v.first << , << v.second << ) ; } template <class T> ostream& operator<<(ostream& os, const vector<T>& v) { os << [ ; for (int i = int(0); i ...
#include <bits/stdc++.h> using namespace std; int a[100000]; char t[1000]; int main() { string s, sa; stack<int> sta; int i, j; while (cin >> sa) { s += sa; } int cnt = 0; for (i = 0; i < s.length(); i++) { if (s[i] != < ) continue; i++; for (j = 0; i < s.len...
#include <bits/stdc++.h> using namespace std; vector<vector<double> > M, I; vector<vector<double> > M2[15]; int X[203], Y[203]; int sz = 0; map<pair<int, int>, int> mp; map<pair<pair<int, int>, int>, int> conv; vector<int> vec[40003]; int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); } ve...
#include <bits/stdc++.h> using namespace std; template <typename T> inline T sqr(const T& a) { return a * a; } template <typename T> inline int sign(const T& a) { return a < 0 ? -1 : a > 0; } void task(); int main() { ios_base::sync_with_stdio(0); task(); return 0; } int h, q; ...
#include <bits/stdc++.h> using namespace std; map<int, int> mp[11]; const int N = 2e5 + 5; int ws(int u) { return (int)log10(u) + 1; } int n, k, a[N], mo[11][N]; long long ans; int main() { scanf( %d%d , &n, &k); for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); mo[0][i] = a[i] % k; ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int gl, bl, br, gr; cin >> gl >> gr >> bl >> br; if (br <= (gl + 1) * 2 && br >= gl - 1) { cout << YES ; return 0; } if (bl <= (gr + 1) * 2 && bl >...
#include <bits/stdc++.h> using namespace std; long long a[345678], b[456111], c, n, i, l, s = 0, k = 0, m, j, t, x, y; string p, q, r, rr; int main() { cin >> n >> m; for (i = 0; i < m; i++) { a[i] = n / m; } for (i = 1; i <= n % m; i++) a[i]++; for (i = 0; i < m; i++) { for (j =...
#include <bits/stdc++.h> using namespace std; int main() { string str; int flag = 1; cin >> str; int len = str.size(); str[len] = 1 ; str[len + 1] = 1 ; for (int i = 0; i < str.size();) { string temp = ; if (str[i] == 1 ) { temp = str[i + 1]; if (temp == ...
#include <bits/stdc++.h> using namespace std; const int maxm = 1e6 + 5; double q[maxm]; int buf[maxm], len[maxm]; void run_case() { int n; cin >> n; int top = 0; for (int i = 1; i <= n; ++i) cin >> buf[i]; q[++top] = buf[1], len[1] = 1; for (int i = 2; i <= n; ++i) { double now =...
#include <bits/stdc++.h> using namespace std; int m = 10000000; int n; int a[1000005]; int p[10000005]; long long gcd(long long a, long long b) { if (!b) return a; return gcd(b, a % b); } int get(int x) { return p[x] == x ? x : p[x] = get(p[x]); } int main() { cin >> n; for (int i = 0;...
#include <bits/stdc++.h> using namespace std; const int maxn = 1100010; const double pai = acos(-1.0); char s[maxn], t[maxn]; int n, m, a[maxn], b[maxn], ans[maxn], fa[maxn][6], rev[maxn], bin[1100010]; struct node { double a, b; node(double t0 = 0.0, double t1 = 0.0) { a = t0; b = t1; ...
#include <bits/stdc++.h> using namespace std; void fast() { std::ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); } void file() {} int main() { fast(); file(); int n, idx = 0; cin >> n; vector<vector<int>> v(n, vector<int>(n)); vector<bool> ans(n, 1); for (i...
#include <bits/stdc++.h> using namespace std; template <typename T> void sc(T &x) { char r; bool start = false, neg = false; T ret = 0; while (true) { r = getchar(); if ((r - 0 < 0 || r - 0 > 9) && r != - && !start) continue; if ((r - 0 < 0 || r - 0 > 9) && r != - && ...
#include <bits/stdc++.h> using namespace std; void code() { int n; cin>>n; string s; cin>>s; set<char> used; char last= - ; bool possible=true; for(char& c:s) { if(c!=last) { if(used.find(c)!=used.end()) { possible=false; break; } } ...
#include <bits/stdc++.h> using namespace std; const int N = 1 << 20; int n; int part[N][2]; bool vis[N]; vector<int> ans; vector<pair<int, int> > G[N]; void dfs(int u) { vis[u] = true; for (auto v : G[u]) if (!vis[v.first]) dfs(v.first); } bool check(int Mask) { for (int i = 0; i <...
#include <bits/stdc++.h> int main() { float d, l, v1, v2, y, z, p, q, i, j; scanf( %f %f %f %f , &d, &l, &v1, &v2); float x = (l - d) / (v1 + v2); printf( %f n , x); }
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1, c = getchar(); while (c < 48) c == - && (f = -1), c = getchar(); while (c > 47) x = x * 10 + c - 0 , c = getchar(); return x * f; } const int MAXN = 100005; struct Node { int l, r, mx; double p; } ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> v(n); for (int i = 0; i < n; ++i) { cin >> v[i]; } sort(v.begin(), v.end()); cout << min(v[n - 1] - v[1], v[n - 2] - v[0]); }
#include <bits/stdc++.h> using namespace std; const int MaxN = 1e3 + 100; const int LogN = 20; long long Inf = 1e9 + 100; const int dx[4] = {0, 1, 0, -1}; const int dy[4] = {1, 0, -1, 0}; const double eps = 1e-9; int md = 2520; struct el { int v, u, c; }; vector<el> Ans; vector<int> Gr[MaxN]...
#include <bits/stdc++.h> using namespace std; const int mod = int(1e9) + 7, INF = 0x3fffffff, maxn = 1e5 + 12; int n, sum, a[maxn]; int main(void) { cin >> n; for (int i = 0; i < n; i++) scanf( %d , &(a[i])), sum += a[i]; sort(a, a + n); int ans = 0; int l = sum / n, r; r = l + 1; in...
#include <bits/stdc++.h> using namespace std; int arr[3500]; int main(void) { int c; scanf( %d n , &c); for (int t = 0; t < c; t++) { int n, m, k; scanf( %d %d %d n , &n, &m, &k); for (int i = 0; i < n; i++) { scanf( %d , &arr[i]); } scanf( n ); vector<int...
#include <bits/stdc++.h> using namespace std; int n, sl, fh; struct node { int s, m, r, t; } a[100010]; struct seg { vector<long long> tim, pre, suf; vector<node> a; int lt; void resize(int l) { pre.resize(l); suf.resize(l); } long long getans(int T) { if (!lt) { ...
#include <bits/stdc++.h> #pragma GCC optimize(3) using namespace std; int n, x, y, final, a[100500], dep[100500], maxn, root, f[100500]; std::vector<int> G[100500]; priority_queue<int> Que; void DFS1(int now, int fa) { for (int i = 0; i < (int)G[now].size(); i++) { if (G[now][i] == fa) continue; ...
#include <bits/stdc++.h> int m, n = 0, num[(20)]; long long f[(20)][(20)], cnt[(20)], ans = 0; void CountBit(int m); long long dfs(int bit, int value, bool limit); void solve(int p, int s, int q, long long tot); int main() { scanf( %d , &m); CountBit(m); memset(f, 0xff, sizeof(f)); for (int ...
#include <bits/stdc++.h> using namespace std; long long x, a[] = {3, 15, 81, 6723, 50625, 2562991875LL}; int sg[] = {0, 1, 2, 0, 3, 1, 2}, n, ans = 0; int main() { cin >> n; while (n--) { cin >> x; ans ^= sg[lower_bound(a, a + 6, x) - a]; } cout << (ans ? Furlo : Rublo ) << endl; ...
#include <bits/stdc++.h> using namespace std; int main() { int q; scanf( %d , &q); map<long long, long long> road; for (int i = 0; i < q; i++) { int s; scanf( %d , &s); if (s == 1) { long long u, v, w; scanf( %I64d %I64d %I64d , &u, &v, &w); while (u != v) {...
#include <bits/stdc++.h> using namespace std; const int maxn = 501; long long matrix[maxn][maxn]; long long sum_col[maxn]; long long sum_row[maxn]; long long sum_d1 = 0; long long sum_d2 = 0; int pos_col = 0; int pos_row = 0; int main() { int n, sum = 0; cin >> n; for (int i = 0; i < n; ...
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize( Ofast ) long long int n, remm[200010], actual_pos[200010]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); clock_t clk = clock(); int q; cin >> n; for (int i = 1; i <= n; i++) cin >> remm[i], actua...
#include <bits/stdc++.h> using namespace std; vector<int> t[100000]; int n; int h[100000]; int arr[100000]; double fac[100001]; bool cmp(int a, int b) { return h[a] < h[b]; } void dfs(int cur, int he, int par = -1) { h[cur] = he; for (int i = 0; i < t[cur].size(); i++) { if (t[cur][i] == p...
#include <bits/stdc++.h> using namespace std; inline void FAST_IO() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } template <class F, class S> ostream& operator<<(ostream& os, pair<F, S>& p) { os << ( << p.first << , << p.second << ) ; return os; } template <class T, class ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<long long> m(n); for (int i = 0; i < n; i++) cin >> m[i]; long long sum = 0; for (int i = 0; i < n; i++) sum += m[i]; sum += n; vector<long long> a(n + ...
#include <bits/stdc++.h> using namespace std; template <class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } struct Edge { int ...
#include <bits/stdc++.h> using namespace std; class R { public: int l; int r; int t; int b; R(int l, int r, int t, int b) { this->l = l; this->r = r; this->b = b; this->t = t; } }; int ask(int x1, int x2, int y1, int y2) { cout << ? << x1 << << y1 <<...
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007; int lca[400100][20]; int len[400100]; long long s[400100][20]; int w[400100]; int main() { ios::sync_with_stdio(false); int Q; cin >> Q; int cnt = 0; int last = 0; len[0] = 1; for (long long q = 0; q < (l...
#include <bits/stdc++.h> using namespace std; vector<long long> val(100000 + 5); struct Gaussian { long long no_of_bits = 20; vector<long long> v; long long set, origsize = 0, redsize = 0; void push(long long val) { origsize++; if (val) v.push_back(val); } void clear() { ...
#include <bits/stdc++.h> using namespace std; const long long mod1 = 19260817; const long long mod2 = 19660813; int n; int m; char s[200005]; char opt[5]; struct { int tree[200005]; int lowbit(int x) { return x & -x; } void ins(int pos, int val) { for (; pos <= n; pos += lowbit(pos)) t...
#include <bits/stdc++.h> using namespace std; int a, b, k, m, maxa, minb, tem; int main() { cin >> a >> b >> k >> m; for (int i = 0; i < a; i++) { cin >> tem; if (i == k - 1) maxa = tem; } for (int i = 0; i < b; i++) { cin >> tem; if (i == b - m) minb = tem; } cout ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long w, h, u1, d1, u2, d2; cin >> w >> h >> u1 >> d1 >> u2 >> d2; for (int i = h; i >= 0; i--) { w += i; if (i == d1) w -= u1; if (i == d2) w -= u2; w = max(w,...
#include <bits/stdc++.h> using namespace std; unordered_set<int> S; int main() { int n; cin >> n; int A[n], dp[n + 1]; dp[0] = 0; S.clear(); for (int _n{n}, i{0}; i < _n; ++i) { cin >> A[i]; dp[i + 1] = dp[i]; if (!S.count(A[i])) { S.insert(A[i]); dp[i + 1...
#include <bits/stdc++.h> using namespace std; bool comp(long long a, long long b) { return a > b; } std::vector<long long> fac(500000); void pre() { fac[0] = 1; for (int i = 1; i < 500000; i++) { fac[i] = i * fac[i - 1]; fac[i] %= 998244353; } } long long power(long long x, long long...
#include <bits/stdc++.h> using namespace std; const long long int mx = 2e3 + 1, Mod = 1e9 + 7; long long int k, Pa, Pb; int pw(long long int a, int b) { long long int ans = 1; while (b) { if (b % 2) ans = (ans * a) % Mod; a = (a * a) % Mod; b /= 2; } return ans; } long long...
#include <bits/stdc++.h> using namespace std; char str[2000 + 5][2000 + 5]; int v, res, n, m, k, cnt; int main() { scanf( %d%d%d , &n, &m, &k); bool flag = 0; if (k == 1) flag = 1; for (int i = 1; i <= n; i++) scanf( %s , str[i]); for (int i = 1; i <= n; i++) { for (int j = 0; j < m; j...
#include <bits/stdc++.h> using namespace std; #define ll long long int #define mp make_pair #define pb push_back #define pf push_front #define F first #define S second #define MOD 1000000007 #define MAXN 1000001 #define MODA 998244353 #define all(a) (a).begin(),(a).end() #define allr(a...
#include <bits/stdc++.h> using namespace std; int main() { long long int arr[101], ans = 0, temp = 0; int i, j, n; scanf( %d , &n); for (i = 0; i < n; i++) scanf( %I64d , &arr[i]); for (i = 0; i < n; i++) { for (j = i; j < n; j++) { temp = temp ^ arr[j]; ans = max(ans, temp...
#include <bits/stdc++.h> using namespace std; const int N = 2020; int n, m, i, j, cnt[N]; char grid[N][N]; bool check(int s) { for (int i = 0; i < m; ++i) if (grid[s][i] == 1 && cnt[i] <= 1) return 0; return 1; } int main() { cin >> n >> m; for (i = 0; i < n; ++i) { scanf( %s...
#include<string.h> #include<bits/stdc++.h> using namespace std; int main() { int t; cin>>t; //string a,b; while(t--) { string a,b; cin>>a; int n,m,g,maxx; cin>>b; string l,k; int len=a.size(),len1=b.size(); for(int i=1;i<=len;i++) { int r=0; for(int j=0;j...
#include <bits/stdc++.h> using namespace std; const int MaxN = 100 * 1000; int ok[MaxN]; int bad[MaxN]; char TYPE[MaxN]; int QUERY[MaxN]; bool crime[MaxN]; int main() { int n, m; scanf( %d%d n , &n, &m); int sumWrong = 0; for (int i = 0; i < n; i++) { char type; int x; ...
#include <bits/stdc++.h> using namespace std; int main(void) { cin.sync_with_stdio(false); long long k[3]; int t[3]; int n, i, j; for (i = 0; i < 3; i++) cin >> k[i]; for (i = 0; i < 3; i++) cin >> t[i]; cin >> n; vector<long long> a(n); vector<long long> b(n); for (i = 0; i ...
#include<bits/stdc++.h> using namespace std; #define pb push_back #define reg register #define int long long #define For(i,a,b) for(reg int i=a;i<=b;++i) #define Down(i,a,b) for(reg int i=a;i>=b;--i) #define ull unsigned long long #define rep(i,a,b) for(reg int i=a;i<=b;++i) #define ll long long in...
#include <bits/stdc++.h> using namespace std; int main() { int i, j, n, m, q, p; cin >> q; while (q--) { cin >> n; string s; cin >> s; p = 0; if (s.length() > 2) { cout << YES n2 n ; cout << s[0] << ; for (i = 1; i < n; i++) cout << s[i]; ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 4000; long long p[MAXN + 10], v[MAXN + 10], d[MAXN + 10]; bool lft[MAXN + 10]; int n; void print(int n) { for (int i = 0; i < n; i++) cout << p[i] << ; cout << endl; for (int i = 0; i < n; i++) cout << lft[i] << ; cout << e...
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 2; const long long N1 = 1e2 + 2; const long long mod = 1e9 + 7; const int MASK = 1 << 17 + 1; const int who = 6 * N * log2(N); long long power(long long a, long long b, long long c) { long long ret = 1; while (b) { if (b...
#include <bits/stdc++.h> using namespace std; int dr[4][2] = {{1, 1}, {-1, 1}, {-1, -1}, {1, -1}}; bool eq(double d1, double d2) { return fabs(d1 - d2) < 1e-7; } int getState(double dx, double dy) { for (int i = 0; i < 4; i++) if (!eq(dx, 0) && !eq(dy, 0)) if (dx * dr[i][0] > 0 && dy * dr[i][1...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long int n; cin >> n; int fl = 0; long long int ans = 0; if (n == 2) { cout << 2 << endl; continue; } ans = pow(2, n); for (int i = 1; i < n; i++...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int ans = 0; int a, b; cin >> a >> b; if (a < b) swap(a, b); cout << b << << (a - b) / 2 << endl; return 0; }
#include <bits/stdc++.h> #define ll long long #define db long double #define x first #define y second #define mp make_pair #define pb push_back #define all(a) a.begin(), a.end() using namespace std; const int MAGIC = 300; const int BLOCKS = 160000/MAGIC; vector<int> tree; vector<int> le...
#include <bits/stdc++.h> using namespace std; int n, t; int s[100013]; int g[17][100013]; int lg[100013]; vector<pair<int, int> > sorted; int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); } int find_l(int gcf, int ind) { int left = 0, right = sorted.size() - 1; while (left < right) { ...
#include <bits/stdc++.h> using namespace std; using uint = unsigned int; using ll = long long; using ld = long double; using ull = unsigned long long; using pii = pair<int, int>; using pll = pair<ll, ll>; void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(He...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; using pii = pair<long long, long long>; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); long long q; cin >> q; while (q--) { long long n, m; cin >> n >> m; vector<pair<long long, p...
#include <bits/stdc++.h> using namespace std; int main() { int n, x; cin >> n >> x; int s = 0; for (int i = 0; i < n; ++i) { int a; cin >> a; s += a; } s += n - 1; if (s == x) { cout << YES << endl; } else { cout << NO << endl; } return 0; ...
#include <bits/stdc++.h> using namespace std; int main() { vector<int> b1, b2; int n; cin >> n; int a[n]; long long s1 = 0, s2 = 0; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] > 0) { s1 += a[i]; b1.push_back(a[i]); } else { s2 -= a[i]; ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000 * 1000 + 100; int d[MAXN]; int main() { ios::sync_with_stdio(false); long long n, m; cin >> n >> m; long long ans = n * (n - 1) * (n - 2) / 6; ans -= m * (n - 2); for (int i = 0; i < m; i++) { int u, v; cin >...
#include <bits/stdc++.h> using namespace std; struct point{ public: int x, y; }; bool cmpx(point a, point b){ return a.x<b.x; } bool cmpy(point a, point b){ return a.y<b.y; } int main(){ int t, i, j, x1, x2, y1, y2, d; point ptsx[4], ptsy[4]; cin>>t; ...
#include <bits/stdc++.h> using namespace std; template <class T> inline void amin(T &a, T b) { if (a > b) a = b; } template <class T> inline void amax(T &a, T b) { if (a < b) a = b; } int gcd(int x, int y) { while (y) { x %= y; swap(x, y); } return x; } int GCD[111][1...
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 10; int n, m; struct bian { int from, to; }; struct tree { bian eg[N << 2]; int num, front[N << 1]; int zong; int fa[N << 1], siz[N << 1]; void add(int x, int y) { eg[++num].to = y; eg[num].from = front[x];...
#include <bits/stdc++.h> using namespace std; int n, k, i; int oma = 0, omi = 0, ma, mi; int a[101]; string s; int main() { cin >> n >> k; for (i = 1; i <= n; i++) { cin >> s; a[s.size()]++; } cin >> s; for (i = 1; i < s.size(); i++) omi = omi + a[i]; mi = omi; ma = o...
#include <bits/stdc++.h> using namespace std; int n, k; string s; void solve() {} int main() { std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long test = 1; cin >> test; while (test--) { cin >> n >> k; cin >> s; int ans = 0; int cnt = 0; ...
#include<cmath> #include<cstdio> #include<vector> #include<algorithm> #include<map> using namespace std; int main() { int n, M=1000000007, tmp, maxc=100; vector<int> c; scanf( %d , &n); int sumc=0; for(int i=0;i<n;++i) { scanf( %d , &tmp); c.push_back(...