func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 100; int n, sl, res; int c[maxn][27]; int d[maxn][2], trace[maxn]; vector<int> a[maxn]; vector<string> q; void init() { q.clear(); for (int i = 1; i <= sl; i++) { for (int j = 0; j < 26; j++) { c[i][j] = 0; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, x, y, z, xsum(0), ysum(0), zsum(0); cin >> n; while (n--) { cin >> x >> y >> z; xsum += x; ysum += y; zsum += z; } if (xsum == 0 && ysum == 0 && zsum == 0) { cout << YES << endl; } else { ...
#include <bits/stdc++.h> using namespace std; string to_string(string s) { return + s + ; } string to_string(char s) { return string(1, s); } string to_string(const char *s) { return to_string((string)s); } string to_string(bool b) { return (b ? true : false ); } template <typename A> string to_...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, k, d; cin >> n >> k >> d; long long int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } map<int, int> p; long long int l = 0, size = 0, m = 99999999; ...
#include <bits/stdc++.h> using namespace std; int flash_drives[100001]; int main() { int n, m; scanf( %d%d , &n, &m); for (int i = 0; i < n; i++) { scanf( %d , &flash_drives[i]); } sort(flash_drives, flash_drives + n, greater<int>()); int l = 0; int sum = 0; for (int i = 0; i...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, k; cin >> n >> k; long long minNumNod = k * (1 + k) / 2; if (minNumNod > n || k > 1e6) { cout << -1 << endl; return 0; } long long nod = 1; ...
#include <bits/stdc++.h> using namespace std; long long a[1000000]; int main() { long long n, s; cin >> n >> s; for (long long i = 0; i < n; i++) { long long k, m; cin >> k >> m; a[k] = max(a[k], m); } long long ans = 0, last = s; for (long long i = s; i > 0; i--) { ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int inf = 1 << 30; int n, t; int main() { cin >> n; int v; set<int> s; for (int i = 0; i < n; i++) { cin >> v; if (v != 0) s.insert(v); } int a = s.size(); if (a != 0) cout << a << end...
#include <bits/stdc++.h> inline int getint() { register char ch; register bool neg = false; while (!isdigit(ch = getchar())) if (ch == - ) neg = true; register int x = ch ^ 0 ; while (isdigit(ch = getchar())) x = (((x << 2) + x) << 1) + (ch ^ 0 ); return neg ? -x : x; } const int ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:102400000,102400000 ) const int inf = 0x3f3f3f3f; const long double PI = acos(-1); using namespace std; const int N = 1e5 + 10; int t, n, ans; char s[N]; int solve() { for (char c = a ; c <= z ; c++) { int temp = 0, i = 0, j = n - 1; ...
#include <bits/stdc++.h> using namespace std; int N, M, C, a[100009]; int res(int p1, int p2, int p3) { int s = 0; if (p1 > p2) s += (p2 - p1); if (p2 > p3) s += (p3 - p2); return s; } void solve(int s) { int G; cin >> G; if (G <= C / 2) { for (int i = 1; i <= N; i++) { ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { string s; cin >> s; int n = s.length(); int m; cin >> m; int b[m + 2]; for (int i = 1; i <= m; i++) { cin >> b[i]; } char ans[m + 2]; sort(s.begin...
#include <bits/stdc++.h> using namespace std; int heliqi; int main() { long long N, M, K; cin >> N >> M >> K; long long ans = -1; if (N + M < K + 2) { cout << -1 << endl; return 0; } long long t = 2; while (t--) { if (K < N) ans = max((N / (K + 1)) * M, ans)...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, k, p, i, j, max = 0; cin >> n >> k >> p; long long a[n + 1]; long long b[k + 1]; for (i = 1; i <= n; i++) cin >> a[i]; for (i = 1; i <= k; i++)...
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(NULL); cin.sync_with_stdio(false); int n; cin >> n; for (int i = 0; i < n; i++) { int a, b, x, y; cin >> a >> b >> x >> y; cout << max(max(((a - 1) - x) * b, ((b - 1) - y) * a), max((x)*b, (y)*a)) << ...
#include <bits/stdc++.h> using namespace std; struct node { int x, in; } arr[210000], qu[210000]; int n, m, k, ans, len; int head, tail; int cmp(node a, node b) { if (a.x == b.x) return a.in < b.in; else return a.x < b.x; } int main() { int i, j, tp; while (scanf( %d%d%d ...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<int, int>; const int MAXN = 5 + 300000; const int MAXB = 21; int n, arr[MAXN], nxt[MAXN][MAXB], memo[MAXN][MAXB]; int dp(int i, int k) { if (i == n) return n; int& ans = memo[i][k]; if (ans == -1) { if (n...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); vector<int> v(n); for (auto &x : v) { scanf( %d , &x); } sort(v.begin(), v.end()); int pos = 0, cnt = 0; for (int x : v) { while (pos < n) { if (v[pos] > x) { pos++; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, v; scanf( %d%d , &n, &v); if (n - v <= 1) { printf( %d , n - 1); } else { printf( %d , (n - v + 1) * (n - v) / 2 + v - 1); } return 0; }
#include <bits/stdc++.h> using namespace std; int n, m, i, j; char cad[1000][1000]; bool marcas[10]; int main() { bool ok = 1; scanf( %d%d , &n, &m); for (i = 0; i < n && ok; i++) { scanf( %s , cad[i]); for (j = 1; j < m && ok; j++) ok = cad[i][j] == cad[i][0]; } for (i = 1; i ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int ara[n + 5], ar[n + 5]; ar[0] = INT_MAX; int j = 1, i, a = 0, b = 1; for (i = 1; i <= n; ++i) { cin >> ara[i]; if (ara[i] == 0) ar[j++] = i; } ar[j] = INT_MAX; for (i = 1; i <= n; ++i) { ...
#include <bits/stdc++.h> using namespace std; const long long p = 1e9 + 7; long long dp[40][40][2], n, ans; int lim[45], len; int calc(int x, int sgn) { if (x == 0) return sgn ^ 1; return 1 << x >> 1; } int main() { cin >> n; if (n == 0) return puts( 1 ), 0; while (n) { lim[++len...
#include<iostream> #include<cstring> #include<cmath> #include<string> #include<algorithm> #include<cstdio> #include<set> #include<vector> #include<map> #include<stack> using namespace std; const int N = 110; const int inf = 0x3f3f3f3f; typedef long long ll; #define reg register const int m...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n, k; cin >> n >> k; vector<long long int> a(n); for (long long int i = 0; i < a.size(); i++) cin >> a[i]; long long int ans(0); for (long long int i = 0; i < n; ...
#include <bits/stdc++.h> using namespace std; void solve() { string s; cin >> s; set<char> st; for (int i = 0; i < s.size(); i++) { if (s[i] == s[i + 1]) { i++; } else { st.insert(s[i]); } } for (auto it : st) { cout << it; } cout << n ; } ...
#include <bits/stdc++.h> using namespace std; template <class c> struct rge { c b, e; }; template <class c> rge<c> range(c i, c j) { return rge<c>{i, j}; } template <class c> auto dud(c *x) -> decltype(cerr << *x, 0); template <class c> char dud(...); struct debug { ~debug() { cerr <...
#include <bits/stdc++.h> using namespace std; long long dp[3][111111]; vector<int> graph[111111]; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; for (int i = 0; i < n - 1; i++) { int a, b; cin >> a >> b; a--; b--; graph[a].push_back(b); graph[...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const int MAXN = 1e3 + 10; inline long long in() { long long x = 0, flag = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) flag = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false), cin.tie(NULL); int a[100][100]; int b[100][100]; int m, n; cin >> m >> n; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { b[i][j] = 1; } } for (int i = 0; i < m; i+...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int a = min(m, n); if (a % 2 == 0) { cout << Malvika ; } else { cout << Akshat ; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { bool f1 = true, f2 = false; int arrS[26] = {0}; int arrT[26] = {0}; string s, t; getline(cin, s); getline(cin, t); for (int i = 0; i < s.size(); i++) arrS[s[i] - a ]++; for (int i = 0; i < t.size(); i++) arrT[t[i] - a ]++; ...
#include <bits/stdc++.h> using namespace std; const int maxn = (int)1e6; const int inf = (int)2e9; const double eps = 1e-9; const int mod = (int)1e9 + 7; int n, l, x, y, a[maxn], ok1, ok2; map<int, int> was; bool check(int v) { if (v >= 0 && v <= l && (was.count(v - x) || was.count(v + x) || ok1) &&...
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 7; int a[N], h[N], f[N << 2], lazy[N << 2]; vector<int> p[N], g[N]; struct node { int fi, id, se; } b[N]; void dfs(int x, int fa) { b[x] = b[fa]; if (h[x] <= b[x].fi) { b[x].se = b[x].fi; b[x].fi = h[x]; b[x].i...
#include <bits/stdc++.h> const long long SZ = 401010; const long long INF = 1e18; const long long MOD = 1000000007; const long long mod = 998244353; long long opnmbr = 1; using namespace std; void solve() {} long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); ...
#include <bits/stdc++.h> using namespace std; struct mydata { int id; int x; int num; bool operator<(const mydata &r) const { if (x == r.x) return id < r.id; else return x < r.x; } } data[50]; int ret[2000]; int main() { int n, m; scanf( %d%d , &n, &m); ...
#include <bits/stdc++.h> using namespace std; void c_p_c() { ios_base::sync_with_stdio(0); cin.tie(0); cin.tie(0); } int main() { c_p_c(); int Q; cin >> Q; while (Q--) { int n, h = 0, j = 0, b[2]; cin >> n; for (int i = 1; i <= n; i++) { int a; cin >...
#include <bits/stdc++.h> using namespace std; long long int fact(long long int n) { long long int ans = 1; for (long long int i = 2; i <= n; i++) ans = (ans % 1000000007 * i % 1000000007) % 1000000007; return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout...
#include <bits/stdc++.h> using namespace std; int main() { int T, cas = 0; scanf( %d , &T); while (cas++ < T) { int sum = 0, s[251], maxi = 0; for (int i = 1; i <= 250; i++) { scanf( %d , s + i); sum += s[i]; maxi = max(s[i], maxi); } double aver = sum / 2...
#include <bits/stdc++.h> using namespace std; string to_string(bool b) { return (b ? true : false ); } template <size_t N> string to_string(bitset<N> v) { string res = ; for (size_t i = 0; i < N; i++) { res += static_cast<char>( 0 + v[i]); } return res; } template <typename A> ...
#include <bits/stdc++.h> const int MAXN = 2000 + 10; int n; char s[MAXN]; struct Bitset { static const int SIZE = 2048 / 64; unsigned long long a[SIZE]; int cnt; int high; Bitset() { memset(a, 0, sizeof a); cnt = 0; high = 0; } inline bool at(int x) { return (a[x >>...
#include <bits/stdc++.h> using namespace std; int N; string get_block(const string &str) { string res; if (str.length() < 4) res.append(4 - str.length(), 0 ); res.append(str); return res; } string process(const string &addr) { string res; int all = count(addr.begin(), addr.end(), : )...
#include <bits/stdc++.h> int inp() { char c = getchar(); int neg = 1; while (c < 0 || c > 9 ) { if (c == - ) neg = -1; c = getchar(); } int sum = 0; while (c >= 0 && c <= 9 ) { sum = sum * 10 + c - 0 ; c = getchar(); } return sum * neg; } int idx = 0...
#include <bits/stdc++.h> using namespace std; inline int read() { int ret = 0, f = 1; char ch = getchar(); while (ch > 9 || ch < 0 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { ret = (ret << 1) + (ret << 3) + ch - 0 ; ch = getchar(); ...
#include <bits/stdc++.h> using namespace std; long double jd[1100000], x[1100000], y[1100000]; long double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647; int n, m; bool b; long double qq; void cty(int k, int l, int r, ...
#include <bits/stdc++.h> using namespace std; unsigned long long a, b; int main() { cin >> a >> b; if ((a + b) % 2 == 0) cout << (a - b) / 2 << << (a + b) / 2 << endl; else cout << -1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 100; int n, x[maxn], y[maxn], r; void write(int x) { if (x <= 50) printf( %d , x); else { printf( (50+ ); write(x - 50); printf( ) ); } } void work() { for (int i = 1; i < n; i++) printf( ( ); for (int...
#include <bits/stdc++.h> using namespace std; long long C[2333][2333]; int d, MOD, p = 0; long long co[23333]; vector<int> operator-(vector<int> a, vector<int> b) { vector<int> s; int u = max(a.size(), b.size()); a.resize(u); b.resize(u); for (int i = 0; i < u; ++i) s.push_back((a[i] - b[i...
#include <bits/stdc++.h> using namespace std; int n; double A[1010], B[1010]; double p[1010][1010]; double dis(int u) { return (B[u] + 1) / (1 - A[u]); } int mark[1010]; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) { scanf( %lf , &p[i][j]); ...
#include <bits/stdc++.h> using namespace std; void solve(const int &test_id) { int n, p, k; cin >> n >> p >> k; vector<pair<long long, int> > aud(n); for (int i = 0; i < n; i++) cin >> aud[i].first, aud[i].second = i; sort(aud.rbegin(), aud.rend()); vector<int> twos(p + 1); for (int i = ...
#include <iostream> #include <cmath> #include <algorithm> #include <vector> #include <set> #include <unordered_set> #include <queue> #include <deque> #include <string> #include <sstream> #include <iomanip> #include <map> #include <unordered_map> #include <stack> #include <cstdio> #include ...
#include <bits/stdc++.h> using namespace std; int maps[501][501]; char str[501]; int dx[11] = {-1, 0, 1, 0, -1, -1, 1, 1, -1, -1}; int dy[11] = {0, 1, 0, -1, 0, 1, 1, -1, -1, 1}; int dp[550][550][10]; int n, m; int pan(int x, int y) { if (x < 1 || x > n || y < 1 || y > m) return 1; if (maps[x][y...
#include <bits/stdc++.h> using namespace std; const char nl = n ; const int MAX_N = 100011; const long long INF = (1 << 29) + 123; const long long MOD = 998244353; const long double PI = 4 * atan((long double)1); template <typename T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, k; cin >> n >> k; long long ar[n]; for (long long i = 0; i < n; i++) { cin >> ar[i]; } map<long long, long long> mp1, mp2; for (long long i...
#include <bits/stdc++.h> using namespace std; inline int read() { char c = getchar(); int tot = 1; while ((c < 0 || c > 9 ) && c != - ) c = getchar(); if (c == - ) { tot = -1; c = getchar(); } int sum = 0; while (c >= 0 && c <= 9 ) { sum = sum * 10 + c - 0 ; ...
#include <bits/stdc++.h> using namespace std; long long N, f[3001][3001]; struct Node { long long x, val; } P[3001]; inline bool cmp(const Node &a, const Node &b) { return a.x < b.x; } int main() { scanf( %I64d , &N); for (long long i = 1; i <= N; i++) scanf( %I64d%I64d , &P[i].x, &P[i].val); ...
#include <bits/stdc++.h> using namespace std; int ax[4], ay[4], bx[4], by[4]; int xmin = 1000, xmax = -1000, ymin = 1000, ymax = -1000; bool f() { for (int i = 0; i < 4; i++) { if (bx[i] >= xmin && bx[i] <= xmax && by[i] >= ymin && by[i] <= ymax) { return 1; } } double X = ((doub...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int N, M; cin >> N >> M; vector<int> ceff(N * 2); for (int i = 0; i < N; ++i) { cin >> ceff[i * 2]; } cin >> ceff[N * 2 - 1]; for (int i = 1; i < N; ++i) { cin >> ceff...
#include <bits/stdc++.h> using namespace std; const int inf(1010101010); struct uf { int par[5005], rank[5005]; int ff(int x) { return par[x] == x ? x : par[x] = ff(par[x]); } void uu(int x, int y) { x = ff(x), y = ff(y); if (x == y) return; if (rank[x] > rank[y]) par[y] = x;...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; const int ZERO = 2e5 + 5000; int n, w, h; struct node { int id, x, t; node() {} node(int _id, int _x, int _t) : id(_id), x(_x), t(_t) {} bool operator<(const node &a) const { return x < a.x; } } X[MAXN]; vector<node> Y...
#include <bits/stdc++.h> using namespace std; char ans[1000005], tmp[1000005]; int wa; int n, x; void go(int x, int y) { int len = 0; while (x != y) { if (x < y) { y -= x; tmp[len++] = B ; } else { x -= y; tmp[len++] = T ; } if (len >= n) retur...
#include <bits/stdc++.h> const int N = 5e5 + 10, M = 1e7 + 10; const long long mod = 1e9 + 7; using namespace std; map<pair<int, int>, set<int>> mp; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int x[N], y[N]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) scanf( %d%d , ...
#include <bits/stdc++.h> using namespace std; int aa[105][105]; pair<int, int> pos[105][105]; int main() { int n, m, q; scanf( %d %d %d , &n, &m, &q); for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { pos[i][j] = {i, j}; aa[i][j] = INT_MAX; } } for (in...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); int n; cin >> n; int A[12]; int B[12]; for (int i = 0; i < 10; i++) A[i] = true; for (int i = 0; i < 10; i++) B[i] = false; for (int i = 0; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; const int mxN = 500, M = 1e9 + 7; int n, a[mxN]; long long dp[mxN][mxN]; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 0; i < n; ++i) cin >> a[i], --a[i]; dp[0][0] = 1; for (int i = 1; i < n; ++i) dp[i][i] = dp[i ...
#include <bits/stdc++.h> using namespace std; constexpr int inf = 1e9; int main() { int n, m; cin >> n >> m; vector<int> d(m), h(m); for (int i = 0; i < m; ++i) { cin >> d[i] >> h[i]; } int ans = max(h[0] + d[0] - 1, h.back() + (n - d.back())); for (int i = 0; i + 1 < m; ++i) { ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const int mod = 1e9 + 7; void show2d(const vector<vector<int>>& adj) { for (auto x : adj) { for (auto y : x) { cout << y << ; } cout << n ; } } long long int modexp(long long int a, long long int b, l...
#include <bits/stdc++.h> using namespace std; template <typename T> void print(T a) { for (auto i = a.begin(); i != a.end(); i++) cout << *i << ; cout << endl; } bool isVowel(char c) { if (c == a || c == e || c == i || c == o || c == u ) return true; return false; } void sync()...
#include <bits/stdc++.h> using namespace std; const int N = 10000; const int M = 1000000; const int inf = 1e9; struct Edge { int v, w, cost, next; } g[M]; int head[N], st, ed, flow, cost, cnt; void init() { memset(head, -1, sizeof(head)); flow = cost = cnt = 0; } void addEdge(int u, int ...
#include <bits/stdc++.h> using namespace std; long double pi = 3.141592653589793238; set<long long>::iterator it; multiset<long long>::iterator itr; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; long long t; t = 1; while (t--) { long long n; cin >> n; ...
#include <bits/stdc++.h> using ll = long long; using namespace std; const int MOD = 1e9 + 7; map<int, vector<int>> nodecolor; map<int, vector<int>> tree; void dfs(vector<int>& vis, int node, vector<int>& color) { int blue = 0, c = 0, red = 0; if (color[node - 1] == 0) { c += 1; } if (c...
#include <bits/stdc++.h> using namespace std; inline long long in() { int32_t x; scanf( %d , &x); return x; } const long long maxn = 1e6 + 10; const long long mod = 1e9 + 7; const long long inf = 1e9 + 10; long long dp[maxn]; long long ans[maxn]; int32_t main() { dp[1] = 1; for (lo...
#include <bits/stdc++.h> using namespace std; int main() { long long n, t, ans = 0, i, a, b, m, x, y; cin >> t; while (t > 0) { cin >> n; vector<int> res; long long es = 0, os = 0; if ((n / 2) % 2 == 0) { cout << YES << endl; for (i = 0; i < n / 2; i++) { ...
#include <bits/stdc++.h> const int INF = 0x3f3f3f3f; const int kN = 100 + 5; const int MOD = (int)1e9 + 7; int n, limit; int graph[kN][kN]; std::vector<int> edges[kN]; int dp[kN][kN]; void dfs(int u, int fa) { for (int w = 0; w < n; ++w) if (graph[u][w] <= limit) dp[u][w] = 1; for (int v :...
#include <bits/stdc++.h> using namespace std; const int N = 1001; int a[N][N], LR[N][N], RR[N][N], LC[N][N], RC[N][N]; int main() { int n, m; cin >> n >> m; for (int i = 1; i <= n; ++i) { vector<int> v; for (int j = 1; j <= m; ++j) { cin >> a[i][j]; v.push_back(a[i][j]); ...
#include <bits/stdc++.h> using namespace std; namespace fast_IO { inline int read_int() { register int ret = 0, f = 1; register char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) f = -1; c = getchar(); } while (c >= 0 && c <= 9 ) { ret = (ret << 1) + (ret << 3)...
#include <bits/stdc++.h> using namespace std; const int maxx = 500 + 7; const int maxn = 100 + 7; const long long mod = 1E9 + 7; const int maxs = 2 * (1E7) + 5; const int maxm = 100 + 3; const long long maxk = 1e13; long double dp[maxn][maxn]; int last[1000]; char seq[maxn]; long long n, k; void...
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T& x) { static char c; static int f; for (c = getchar(), f = 1; c < 0 || c > 9 ; c = getchar()) if (c == - ) f = -f; for (x = 0; c >= 0 && c <= 9 ; c = getchar()) x = x * 10 + (c & 15); x *= f; } tem...
#include <bits/stdc++.h> using namespace std; int Set(int N, int pos) { return N = N | (1 << pos); } int reset(int N, int pos) { return N = N & ~(1 << pos); } bool check(int N, int pos) { return (bool)(N & (1 << pos)); } string st, st2, st3, st4, ans; int main() { ios_base::sync_with_stdio(0), cin.tie(N...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { string s; cin >> s; int ans = -1; for (int i = 0; i < s.size(); i++) { if (s[i] == R ) { ans = i + 1; break; } } if (ans == -1) { cou...
#include <bits/stdc++.h> using namespace std; const int maxk = 15; const int maxn = 1e5 + 10; long long D[maxk][maxn]; long long queryBIT(int k, int x) { long long ret = 0; while (x > 0) { ret += D[k][x]; x -= x & -x; } return ret; } void addBIT(int k, int x, long long d) { ...
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; vector<int> g[maxn]; int src[maxn], dest[maxn]; bool vis[maxn]; int main() { int n, m; int a, b; scanf( %d %d , &n, &m); for (int i = 0; i < m; i++) { scanf( %d %d , &a, &b); a--, b--; g[a].push_back(b);...
#include <bits/stdc++.h> using namespace std; int ls, cc; char s[1111111], a[1111111]; int main() { gets(s), ls = strlen(s), cc = 0, a[0] = # ; for (int i = 0; i < ls; ++i) { a[++cc] = s[i]; while (cc > 1 && a[cc - 1] != a[cc]) cc -= 2; } for (int i = 1; i <= cc; ++i) putchar(a[i]);...
#include <bits/stdc++.h> using namespace std; const int sz = 100005; int a[sz], b[sz], sum[sz]; int main() { int n, m, c; cin >> n >> m >> c; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= m; i++) { cin >> b[i]; sum[i] = (sum[i - 1] + b[i]) % c; } for (int i =...
#include <bits/stdc++.h> using namespace std; const int N = 105; int n, res = 1e9, a[5][N][N]; void calc(int a[N][N], int b[N][N], int c[N][N], int d[N][N]) { int tmp = 0, tmp2 = 0; for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) { if (a[i][j] != (i + j) % 2) ++tmp; ...
#include <bits/stdc++.h> using namespace std; string name[101]; vector<string> seen; bool see = false; int m, n, i, j; int main() { cin >> n; m = n; i = 1; int k = 0; while (n > 0) { cin >> name[i]; i++; n--; } for (i = 1; i <= m; i++) { see = false; ...
//Jai Shree Ram #include<bits/stdc++.h> using namespace std; #define f(a,b,n) for(ll a=b;a<n;a++) #define readarr(arr,n) f(i,0,n) cin>>arr[i]; #define ll long long #define pb push_back #define fastio ios_base::sync_with_stdio(false),cin.tie(NULL),cout...
#include <bits/stdc++.h> using namespace std; bool flag = 0, flag1 = 0, flag2 = 0; string t = abacaba ; int check(string s) { long long int x = 0; for (long long int i = 0; i < s.size(); i++) { if (s.substr(i, 7) == t) { x++; } } return x; } int main() { ios::sync_wi...
#include <bits/stdc++.h> using namespace std; struct rua { long double x, y; } m; set<pair<long double, long double> > p; vector<pair<long double, long double> > del; vector<long double> d; set<long double> mm; int n, ans; long double x, y; bool tt; bool check(rua T) { d.clear(); rua M...
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(0); long long n; cin >> n; long long num = 1e5 + 3; long long pos[num]; for (int i = 0; i < n; ++i) { long long a; cin >> a; pos[a] = i + 1; } long long m; cin >> m; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; const long long inf = 1e9 + 7; long long mod = 998244353; vector<int> a; int solve(vector<int> &b, int bit) { vector<int> l, r; if (b.size() == 0 || bit < 0) return 0; for (int i = 0; i < b.size(); i++) { if ((b[i] >>...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int n, m, u, v, w, answer, capital, intree, l, dis[N]; vector<pair<int, int> > nei[N]; vector<pair<int, pair<int, int> > > edge; bool done[N]; priority_queue<pair<int, int> > pq; int main() { cin >> n >> m >> capital; capital-...
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; vector<long long> v(n + 1); long long xr = 0; for (long long i = 1; i <= n; i++) { cin >> v[i]; xr ^= v[i]; } if (xr == 0) { cout << DRAW << n ; return; } lo...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ul = unsigned long long; using ld = long double; const int N = 101; int a[N][N]; vector<vector<int>> ans; void q(int ax, int ay, int bx, int by, int cx, int cy) { a[ax][ay] ^= 1; a[bx][by] ^= 1; a[cx][cy] ^= 1; ans...
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_str...
#include <bits/stdc++.h> using namespace std; int Read() { char c; while (c = getchar(), (c != - ) && (c < 0 || c > 9 )) ; bool neg = (c == - ); int ret = (neg ? 0 : c - 48); while (c = getchar(), c >= 0 && c <= 9 ) ret = ret * 10 + c - 48; return neg ? -ret : ret; } const ...
#include <bits/stdc++.h> using namespace std; int n; long long int cvp = 3; int main() { scanf( %d , &n); for (int i = 3; i <= n; i++) { cvp = cvp * 3; if (i % 2 == 1) cvp -= 3; else cvp += 3; cvp = cvp % (long long int)1000000007; } if (n == 1) { pr...
#include <bits/stdc++.h> using namespace std; inline long long read() { long long ret = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) ret = ret * 10 + ch - 0 , ch = getchar(); return ret * f;...
#include <bits/stdc++.h> using namespace std; inline void read(int &x) { char c; int flag = 1; while ((c = getchar()) < 0 || c > 9 ) if (c == - ) flag *= -1; x = c - 0 ; while ((c = getchar()) >= 0 && c <= 9 ) x = x * 10 + c - 0 ; x *= flag; return; } inline void read(...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; int add(int a, int b) { return (a + b) % MOD; } int sub(int a, int b) { return add(a, MOD - b); } int mul(int a, int b) { return ((long long)a * b) % MOD; } int inv(int a) { int b = 1; for (int i = 0; (1 << i) <= MOD - 2; i++) { ...
#include <bits/stdc++.h> #pragma hdrstop using namespace std; void solve(); int main() { int t = 1; while (t--) solve(); return 0; } long long n, k; long long dp[5000][5000]; vector<pair<long long, long long> > a; long long b[5000]; void solve() { cin >> n >> k; a.push_back(make_...