func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int x[200000], y[200000]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, s[2]; cin >> n >> s[0] >> s[1]; for (int i = 0; i < n; i++) cin >> x[i] >> y[i]; int quadrant[5] = { 0, }; int line[5] = { 0, }; ...
#include <bits/stdc++.h> using namespace std; int n; vector<int> Left; vector<int> Right; map<pair<int, int>, int> excep; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(); cin >> n; for (int i = 0; i < n; i++) { int l, r; cin >> l >> r; Left.push_back(l); ...
#include <bits/stdc++.h> using namespace std; long long int n, k; vector<long long int> od, ev; long long int dps[200005], dpd[200005]; void buildDp() { dps[0] = 0LL; dps[1] = k - 1; dpd[0] = 1LL; dpd[1] = k - 2; for (int i = 2; i < 200005; i++) { dps[i] = ((dps[i - 2] * (k - 1)) % 9...
#include <bits/stdc++.h> using namespace std; #pragma GCC diagnostic ignored -Wmissing-declarations inline int safe_mul(const int x, const int y) __attribute__((warn_unused_result)); int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector<int> a(n);...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2 * 200000; const int MAXM = 199999 * 2 * 2 + 200000 * 2; int n, m, a, b; string s[2]; int dsu[MAXN]; int to[MAXM], head[MAXN], nxt[MAXM], E; int p[MAXN][19]; int d[MAXN]; int tin[MAXN], tout[MAXN], timer; inline int root(int x) { retu...
#include <bits/stdc++.h> using namespace std; template <typename T> inline void Read(T &x) { char c = getchar(); bool f = false; for (x = 0; !isdigit(c); c = getchar()) { if (c == - ) { f = true; } } for (; isdigit(c); c = getchar()) { x = x * 10 + c - 0 ; } ...
#include <bits/stdc++.h> using namespace std; int main() { int g[5][5] = {0}, tes; for (int x = 1; x < 4; x++) for (int y = 1; y < 4; y++) { cin >> tes; if (tes % 2 == 0) continue; else { g[x][y + 1]++; g[x][y - 1]++; g[x + 1][y]++; ...
#include <bits/stdc++.h> using namespace std; int const xn = 1e4 + 105, xm = 105; int n, m, cnt, hd[xn], ct, to[xn], nxt[xn], w[xn], s1, s2, f; long long dis[2][xn], inf = 1e17; bool vis[xn]; struct E { int u, v, bh, l, r, w; } ed[xm]; struct N { long long d; int id; N(long long d = 0, i...
#include <bits/stdc++.h> using namespace std; struct edg { int cost, id, parity; bool operator<(edg other) const { return cost > other.cost; } }; vector<int> g[1000011 >> 1][2]; int from[1000011], to[1000011], l[1000011], r[1000011]; int N, M; bool cmp(int &a, int &b) { return l[a] > l[b]; } int...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long n, a, b, t; string str; cin >> n >> a >> b >> t >> str; str += str; long long len = 1, l = n, r, remain = t - 1 - (str[n] == w ) * b, ans = 1; if (remain < 0) { cout ...
#include <bits/stdc++.h> using namespace std; const int MOD = (int)1e9 + 7; const int INF = (int)1e9; const long long LINF = (long long)1e18; const long double PI = 2 * acos((long double)0); long long gcd(long long a, long long b) { long long r; while (b) { r = a % b; a = b; b = r;...
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (a == 0) return b; if (b == 0) return a; if (a == b) return a; if (a > b) return gcd(a - b, b); return gcd(a, b - a); } int main() { long long int n, m; cin >> n >> m; long long int a[n + 1], b[m + 1]; f...
#include <bits/stdc++.h> using namespace std; struct heap { int v, x; } h[1000010]; int n, m, a[500010]; int tmp, sz, ans, tot; int v[500010], cnt; int nxt[500010], pre[500010], pos[500010]; inline int read() { char ch = getchar(); int f = 1, x = 0; while (!(ch >= 0 && ch <= 9 )) { ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7, N = 2e5 + 5; int par[N], over[N]; int getpar(int u) { if (par[par[u]] == par[u]) return par[u]; return par[u] = getpar(par[u]); } bool unite(int a, int b) { a = getpar(a); b = getpar(b); if (a == b) { if (over[a...
#include <bits/stdc++.h> using namespace std; class Solution { int max_free; vector<bool> visited; vector<int> parent; vector<set<int>> children; void dfs(int i) { visited[i] = true; for (int j : children[i]) { if (!visited[j]) { if (i != 0) cout << i << << j <<...
#include <bits/stdc++.h> using namespace std; int n, m, ha1[50][50], ha2[50][50], ans1[50][50], ans2[50][50], x = 0, flag = 0; int main() { memset(ha1, 0, sizeof(ha1)); memset(ha2, 0, sizeof(ha2)); memset(ans1, 0, sizeof(ans1)); memset(ans2, 0, sizeof(ans2)); cin >> n >> m; for (int i = 1,...
#include <bits/stdc++.h> using namespace std; int parent[100000], Size[100000]; void init(int n) { for (int i = 0; i < n; i++) { parent[i] = i; Size[i] = 1; } } int Find(int u) { if (u != parent[u]) parent[u] = Find(parent[u]); return parent[u]; } void Union(int u, int v) { ...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const ll OO = 1e18, oo = 1e12 + 21; int di[8] = {0, 0, 1, -1, -1, 1, -1, 1}; int dj[8] = {1, -1, 0, 0, 1, 1, -1, -1}; string ys = YES , no = NO ; const long double dgr = acos(-1) / 180, rad = 180 / acos(-1); ...
#include <bits/stdc++.h> using namespace std; const int N = 1e6; int lp[N + 1]; vector<int> pr; int i, j, p1, p2, x0, x1, x2, ans; int main() { for (i = 2; i <= N; i++) { if (lp[i] == 0) { lp[i] = i; pr.push_back(i); } for (j = 0; j < pr.size() && pr[j] <= lp[i] && i * ...
#include <bits/stdc++.h> using namespace std; const long long M = 2100000; const long long N = 210000; struct node { long long inx; long long a, b; long long m; long long lt, rt; }; vector<node> odd_nodes[M]; vector<node> even_nodes[M]; bool cmp(node a, node b) { if (a.lt == b.lt) ...
#include <bits/stdc++.h> using namespace std; int n, a[1000005], r[3], cnt; bool up, down; set<int> s; int main() { srand(75435); scanf( %d , &n); for (int i = 0; i < n; i++) scanf( %d , &a[i]); if (n <= 2) { cout << -1; return 0; } for (int i = 0; i < n; i++) { if (s...
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; vector<string> N(a), M(b); for (auto& i : N) cin >> i; for (auto& i : M) cin >> i; int q; cin >> q; while (q--) { int n; cin >> n; cout << N[(n - 1) % a] << M[(n - 1) % b] << n ; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; set<int> s; for (int i = 0; i < n; i++) { int t; cin >> t; s.insert(t); } int a, b; cin >> a >> b; int res = 0; while (a > b) { int mx = 1; set<int> toerase; for (set<i...
#include <bits/stdc++.h> using namespace std; const int N = 2020, mod = 1000000007; int n, m, t = 0, a[N] = {}, vis[N] = {}; int *f[N] = {}, *g, *h, arr[N][N << 2] = {}; vector<int> e[N]; long long ans = 0; int main() { cin >> n >> m; for (int i = 1, u, v; i <= m; ++i) { cin >> u >> v; ...
#include <bits/stdc++.h> using namespace std; const int INF = 2e9; const long long LINF = 1LL << 60; const double inf = 1e15; long long mod = 1e9 + 7; char READ_DATA; int SIGNAL_INPUT; template <typename Type> inline Type ru(Type &v) { SIGNAL_INPUT = 1; while ((READ_DATA = getchar()) < 0 || ...
#include <bits/stdc++.h> using namespace std; void change(char &x) { if (x == B ) x = W ; else x = B ; } int main() { string s; int n; cin >> n; cin >> s; int w = 0, b = 0; for (int i = 0; i < n; i++) { if (s[i] == B ) b++; else w++; ...
#include <bits/stdc++.h> using namespace std; template <class T, class T2> inline int chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; } template <class T, class T2> inline int chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; } const int MAXN = (1 << 20); int n, m; int64_t g[...
#include <bits/stdc++.h> using namespace std; int main() { int n, i; long long sum = 0, z = 0, s = 0, m = 0, mm = 0; cin >> n; vector<long long> a(n); for (i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < (n - 1); i++) { if (i % 2 == 0) sum = sum + abs(a[i + 1] - a[i]); el...
#include <bits/stdc++.h> using namespace std; int main() { int n, a[100]; cin >> n; int i, loce, loco, even = 0, odd = 0; for (i = 0; i < n; i++) { cin >> a[i]; if (a[i] % 2 == 0) { even++; loce = i; } if (a[i] % 2 == 1) { odd++; loco = i; ...
#include <bits/stdc++.h> using namespace std; long long mInv[41]; long long fact[41]; long long factInv[41]; map<long, long> mymap; long long heights[5]; long long segTree[3]; long nums[5005]; long g[5005]; vector<long> primes; vector<long> badPrimes; long funcVal[1000006]; long long N; set<...
#include <bits/stdc++.h> using namespace std; int n, m; int an[333333]; int bit[333333]; void upd(int x, int v) { for (int i = x; i <= n; i += (i & -i)) { bit[i] += v; } } int get(int x) { int an = 0; for (int i = x; i > 0; i -= (i & -i)) an += bit[i]; return an; } int main()...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e4 + 5; const int mod = 1e9 + 7; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; int a[n + 5], mx = 0; long long sum = 0; for (int i = 0; i < n; i++) cin >> a[i], sum += a[i]...
#include <bits/stdc++.h> using namespace std; int main() { int n; long long k; cin >> n >> k; int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; sort(arr, arr + n); int prev = arr[0], best = -1, num, left = 0; for (int i = 0; i < n; i++) { k -= (0LL + i - left) * (arr[i] - ...
#include <bits/stdc++.h> int g[1010][1010]; int main() { int n, k, ans, i, j; while (~scanf( %d%d , &n, &k)) { ans = 0; memset(g, 0, sizeof(g)); for (i = 0; i < n; i++) for (j = i + 1; j <= i + k; j++) g[i][j % n] = 1, ans++; int flag = 1; for (i = 0; i < n; i++) ...
#include <bits/stdc++.h> struct node { int a, b, w; } p[200005]; int fa[200005]; bool d[200005]; bool cmp(node x, node y) { return x.w > y.w; } int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); } int main() { int n, m, ans = 0; scanf( %d%d , &n, &m); for (int i = 1; i <= m; i+...
#include<bits/stdc++.h> #define ll long long int using namespace std; int t; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; int sum=0; int odd=-1; vector<int> a(n); for (int q=0;q<n;q++){ int x; cin>>x; ...
#include <bits/stdc++.h> using namespace std; int pre[100010]; char f[100010]; int a[100010]; int ans[100010]; int main() { int n, m, i, c, cnt = 0; scanf( %d , &n); scanf( %d , &m); for (i = 0; i < n; ++i) { scanf( %c , &f[i]); scanf( %c , &f[i]); scanf( %d , &a[i]); ...
#include <bits/stdc++.h> using namespace std; int vis[500500]; int a[500500]; int b[500500]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int j = 0; j < n; j++) cin >> b[j]; int ans = 0; int j ...
#include <bits/stdc++.h> using namespace std; long long n, u, r; long long ans = -1e18; long long a[35], b[35], k[35], p[35]; void calc(long long aa[]) { long long mx = 0; for (int i = 1; i <= n; i++) mx += aa[i] * k[i]; ans = (ans > mx ? ans : mx); } void dfs(long long depth, long long aa[]) ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, q; cin >> n >> q; vector<int> res(n + 1, 0); vector<vector<int>> adjacenyList(n + 1); for (int i = 1; i < n; i++) { int u, v; cin >> u >> v; ...
#include <bits/stdc++.h> using namespace std; int N, K; int arr[205]; int u[100005], v[100005], f[100005]; int lvl[205], ptr[205]; bool vis[205]; vector<int> graph[205]; vector<int> cgraph[205]; vector<vector<int>> vec; void addedge(int a, int b, int k) { u[K] = a; v[K] = b; u[K ^ 1] = b...
#include <bits/stdc++.h> using namespace std; int n, k; int main() { scanf( %d%d , &n, &k); if (k >= (n * (n - 1)) / 2) puts( no solution ); else { for (int i = 0, t = 1; t <= n; t++) printf( %d %d n , i, t); } return 0; }
#include <bits/stdc++.h> using namespace std; vector<vector<int> > a; vector<int> color; int n, m; long long ans = 0; void brut(int v) { if (v == n) { set<pair<int, int> > q; vector<bool> find(n, false); for (int i = 0; i < n; ++i) { for (int j : a[i]) { if (j < i) co...
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 5; long long n, x, y, z, ans; long long a[N], b[N], par[N], sz[N]; long long get(long long x) { if (par[x] == x) return x; return par[x] = get(par[x]); } void merge(long long x, long long y) { long long root_a = get(x); ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native ) using namespace std; template <typename Tp> inline void read(Tp &x) { static char c; static bool neg; x = 0, ...
#include <bits/stdc++.h> using namespace std; inline int in() { int x; scanf( %d , &x); return x; } inline void priv(vector<int> a) { for (int i = 0; i < ((int)(a).size()); ++i) printf( %d%c , a[i], i == (int)(a).size() - 1 ? n : ); } template <typename T> istream& operator>>(i...
#include <bits/stdc++.h> using namespace std; int main() { long long q; cin >> q; while (q--) { long long n, count = 0; cin >> n; long long a[100005]; for (int i = 0; i < n; i++) cin >> a[i]; if (n == 1) cout << 1 << endl; else { for (int i = 0; i < ...
#include <bits/stdc++.h> using namespace std; int n, i, j, k, s, a[50], b[50], c[50]; long long x; int main() { scanf( %d , &n); for (i = 1; i <= n; i++) { scanf( %I64d , &x); for (j = 0; (1ll << j) < x; j++) ; if ((1ll << j) == x) a[j]++; else b[j - 1]++;...
#include <bits/stdc++.h> using namespace std; int a, b, n; int main() { cin >> a >> b >> n; for (int i = 0; i < n - 1; ++i) { b = a + b; a = b - a; } cout << b << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define pll pair<ll, ll> #define vl vector<ll> #define pb push_back #define pp pop_back #define f(i, a, b) for (ll i = a; i < b; ++i) #define rev(i, a, b) for (ll i = a; i >= b; --i) #define print(x) cout << x << endl #define ...
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > v; int N, M; long long f(int a, int b) { long long res = 1; for (int i = 1; i <= a; i++) { int ii = i; while (b > 0 && ii % 2 == 0) { ii /= 2; b--; } res = (res * ii) % M; } return res; ...
#include <bits/stdc++.h> int main() { int a, b; scanf( %d %d , &a, &b); int diff, same, total; total = a + b; if (a > b) { diff = b; } else { diff = a; } same = (total - (2 * diff)) / 2; printf( %d %d n , diff, same); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 40005; const int M = 1005; const int Q = 1000000007; const int P = 10000019; int n, m, q, tot; int v[N], w[N], Ask[N], f[N], id[N]; int g[M], dp[N * 4]; vector<int> T[N * 4]; void Build(int s, int x, int y, int l, int r, int k) { if (l ...
#include <bits/stdc++.h> class Scanner { private: static const int BUFFER_SIZE = 1 << 18; char buff[BUFFER_SIZE]; char *buffPos, *buffLim; FILE* file; public: Scanner(FILE* file) { this->file = file; buffLim = buff + fread(buff, 1, BUFFER_SIZE, file); buffPos = buff; ...
#include <bits/stdc++.h> using namespace std; int d, n, x, ans; int main() { cin >> d; cin >> n; for (int i = 0; i < n - 1; i++) { cin >> x; ans += d - x; } cin >> x; cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-9; signed main() { ios::sync_with_stdio(false); cin.tie(0); long long n; cin >> n; using T = tuple<long long, long long, long long, long long>; vector<long long> x(n), y(n), z(n); for (long long i = (0); i < ((n)); ++i...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int cnt = 0; set <int> s; while(n) { s.insert(n % m); cnt++; n /= m; } if(s.size() == cnt) cout << YES n ; else cout << NO n ; return 0; }
#include <bits/stdc++.h> using namespace std; const int INF = 1E9 + 7; template <class C> void mini(C& a4, C b4) { a4 = min(a4, b4); } template <class C> void maxi(C& a4, C b4) { a4 = max(a4, b4); } int n, k; int il[2]; const long long mod = 1E9 + 7; int best[2][55][55]; int ile[2][55]...
#include <bits/stdc++.h> using namespace std; const int N = 1007; int c[N], t[N]; bool cmp(int i, int j) { return c[i] > c[j]; } int main() { int n, k; cin >> n >> k; vector<int> v[3]; for (int i = 0; i < n; ++i) { cin >> c[i] >> t[i]; v[t[i]].push_back(i); } sort((v[1]).be...
#include <bits/stdc++.h> using namespace std; bool is_vowel(const char c) { for (const char vowel : { a , e , i , o , u }) if (c == vowel) return true; return false; } bool is_block_ok(const array<char, 3> cs) { for (const char c : cs) if (is_vowel(c)) return true; return cs[0] =...
#include <bits/stdc++.h> using namespace std; void solve() { int n; long long int k; cin >> n >> k; vector<pair<int, int> > a(n); for (int i = 0; i < n; i++) { cin >> a[i].first >> a[i].second; } sort(a.begin(), a.end()); int ans = -1; long long int l = 0, r = 2e9; for ...
#include <bits/stdc++.h> using namespace std; inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; } int n, m, c; int A[1111]; int pref = 0, post = 0; bool end() { bool ans = true; for (int(i) = 0; (i) < (n); (i)++) if (A[i] == -1 || (i < n - 1 && A[i + 1] < A[i])) ans = false; ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int a[N]; int main() { ios::sync_with_stdio(0); int tt; cin >> tt; while (tt--) { int n; cin >> n; if (n % 2 == 0) { cout << n / 2 << << n / 2 << endl; } else { int lim = sqrt(n + 0.5...
#include <bits/stdc++.h> using namespace std; int main(int argc, char *argv[]) { string a; cin >> a; int n = 0, m = 0, first = 0, last = 0; bool b = true; for (int i = 0; i < a.size(); i++) { if (a[i] == H ) n++; if (a[i] == Q ) m++; } int sm = int(sqrt(m)); int i = 0; ...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1000, MAX_M = 1000; int N, M; int a[MAX_N][MAX_M], mxx[MAX_N], mxy[MAX_M], cmpx[MAX_N][MAX_M], cmpy[MAX_N][MAX_M]; vector<int> cmp; int main() { scanf( %d %d , &N, &M); for (int i = (0); i < (N); i++) for (int j = (0); j < (...
#include <bits/stdc++.h> using namespace std; const int N = 100010; int n, howMany[N]; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cin >> n; vector<pair<int, int> > beacons; for (int i = 0; i < n; i++) { int x, p; cin >> x >> p; beacons.push_back({x, p}); }...
#include <bits/stdc++.h> using namespace std; int main() { unsigned n, m; cin >> n >> m; if (n % 2 != 0 && m % 2 != 0) cout << ((m * n) - 1) / 2; else cout << (m * n) / 2; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 6; int n, k, h[N]; long long p, m, t, a[N], b[N]; struct xd { int z, i; bool operator<(const xd &d) const { return z > d.z; } } tmp, nw; inline int read() { int T = 0, F = 1; char ch = getchar(); while (ch < 0 || ch > ...
#include <bits/stdc++.h> int t1, t2, t3; int g[88][88]; int n, k; int m; int dp[88][88][88]; int ans = 0x3f3f3f3f; int main() { scanf( %d%d , &n, &k); scanf( %d , &m); for (int i = 0; i <= n + 1; i++) { for (int j = 0; j <= n + 1; j++) { g[i][j] = 0x3f3f3f3f; for (int kk ...
#include <bits/stdc++.h> using namespace std; int n, a[300010], s[300010], x[2]; long long p; int main() { int i, j; long long k; scanf( %d , &n); for (i = 1; i <= n; i++) { scanf( %lld , &k); for (j = 0; j <= 60; j++) if (k & (1ll << j)) a[i]++; s[i] = s[i - 1] + a[i];...
#include <bits/stdc++.h> int compare(const void *a, const void *b) { return *(int *)a - *(int *)b; } int main() { int n, k; scanf( %d%d , &n, &k); int i; if ((n == 1 && k == 1)) { printf( -1 n ); return 0; } if (n == k) { printf( -1 n ); return 0; } if ((n - k...
#include <bits/stdc++.h> using namespace std; int print1() { cout << -1 << endl; return 0; } int main() { int n, m; cin >> n >> m; vector<vector<int> > e(n); int a, b; for (int i = 0; i < m; ++i) { cin >> a >> b; a--; b--; e[a].push_back(b); e[b].push_ba...
#include <bits/stdc++.h> using namespace std; const int maxn = 55; char a[maxn][maxn]; int vis[maxn][maxn]; int n, m; inline void go(int x, int y) { if (vis[x][y] == 1) return; if (a[x][y] != # ) return; vis[x][y] = 1; go(x - 1, y); go(x + 1, y); go(x, y - 1); go(x, y + 1); } ...
#include <bits/stdc++.h> using namespace std; const int max_dp = 2e5 + 1; int dp[101][max_dp]; int n, k; int a[101], b[101]; int solve(int num, int bal) { if (dp[num][bal] != -1) { return dp[num][bal]; } if (num == 0) { if (bal == 1e5) { return 0; } else { retur...
#include <bits/stdc++.h> using namespace std; int n, m, v[1005], xi, yi; int main() { scanf( %d %d , &n, &m); for (int i = 0; i < n; i++) scanf( %d , &v[i]); int res = 0; while (m--) { scanf( %d %d , &xi, &yi); xi--, yi--; res += min(v[xi], v[yi]); } printf( %d n , res); ...
#include <bits/stdc++.h> using namespace std; int A[100][10000]; int d[100][10000]; int main() { int n, m; cin >> n >> m; string str; getline(cin, str); for (int i = 0; i < n; i++) { getline(cin, str); for (int j = 0; j < str.size(); j++) if (str[j] == 1 ) A[i]...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, tt; cin >> n >> tt; vector<int> a(1 << n); long long sum = 0; for (int i = 0; i < (1 << n); i++) { cin >> a[i]; sum += (long long)a[i]; } cout << fixed << s...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n >= 1 && n <= 10 || n >= 22 && n <= 25) cout << 0 ; else if (n == 11) cout << 4 ; else if (n == 20) cout << 15 ; else cout << 4 ; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s; int l = 0, u = 0; cin >> s; for (int i = 0; i < s.size(); i++) { if (s[i] > 90) l++; else u++; } if (l >= u) { transform(s.begin(), s.end(), s.begin(), ::tolower); cout << s << endl; ...
#include <bits/stdc++.h> const int MN = 1e5 + 4; int N, Q, ecnt, ch[MN], depth[MN], len[MN]; long long rt, bit1[MN], *bit2[MN]; std::vector<int> adj[MN]; inline void upd(long long *bit, int ind, int cap, long long val) { for (; ind < cap; ind += ind & -ind) bit[ind] += val; } inline long long qry(long...
#include <bits/stdc++.h> using namespace std; int main() { long long int l, r; cin >> l >> r; long long int res = 0; for (long long int i = 1; i <= r; i *= 2) { for (long long int j = 1; j <= r; j *= 3) { if (i * j <= r && i * j >= l) { res++; } } } cout...
#include <bits/stdc++.h> using namespace std; int main() { int n, pos, l, r; cin >> n >> pos >> l >> r; int result; if (l == 1 && r == n) { result = 0; } else if (l == 1) { result = abs(pos - r) + 1; } else if (r == n) { result = abs(pos - l) + 1; } else { result ...
#include <bits/stdc++.h> using namespace std; vector<int> graph[3123]; vector<vector<int> > vCiclos; int dist[3123]; int vis[3123]; vector<int> v; int ciclo[3123]; int tamanhoCiclo[3123]; int cnt = 1; int n; bool cycle[3123]; void dfs(int x, int pai) { vis[x] = 1; v.push_back(x); for...
#include <bits/stdc++.h> using namespace std; const int mod = 998244353, N = 200200, G = 3, Gi = 332748118; long long power(long long base, long long b) { long long ret = 1; while (b) { if (b & 1) ret = ret * base % mod; base = base * base % mod; b >>= 1; } return ret; } int ...
#include <bits/stdc++.h> using namespace std; int main() { string months[] = { January , February , March , April , May , June , July , August , September , October , November , December }; string s; int n, a; cin >> s >> n...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int INF = 2e9 + 5; const int MAXN = 100010; int n; long long a, r, m, h[MAXN]; int main() { cin.sync_with_stdio(0); cin.tie(0); cin >> n >> a >> r >> m; for (int i = 0; i < n; i++) { cin >> h[i]; } m...
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; const int N = 2e5 + 10; const int MX = 1e9; int n, t; int ar[N], mn[N]; unordered_map<int, int> bit; void upd(int x, int val) { x++; while (x <= t) { bit[x] += val; x += (x & (-x)); ...
#include <bits/stdc++.h> using namespace std; int gets(string s) { int sum = 0; while ((s[0] == 0 ) and (s.size() != 1)) s = s.substr(1, s.size() - 1); for (int i = 0; i < s.size(); i++) sum += s[i] - 48; return sum; } int main() { string s, s1, m; int kol; cin >> s; m = s; ...
#include <bits/stdc++.h> using namespace std; template <typename T> istream& operator>>(istream& is, vector<T>& a) { for (T& ai : a) is >> ai; return is; } template <typename T> ostream& operator<<(ostream& os, vector<T> const& a) { os << [ ; for (const T& ai : a) os << ai << ; retu...
#include <bits/stdc++.h> using namespace std; int main() { long long t, a, b; cin >> t; while (t--) { cin >> a >> b; int f = 0; long long area = a * a - b * b; if ((a - b) != 1) cout << NO ; else { area = a + b; for (int i = 2; i <= sqrt(a + b); i++...
#include <bits/stdc++.h> using namespace std; long long s(0), p, k; int main() { cin >> k >> p; for (long long cz(1), i(0); i < k; ++i, ++cz) { string str = to_string(cz); string res(str); reverse(begin(str), end(str)); res += str; s += stoll(res) % p; } cout << s % p...
#include <bits/stdc++.h> using namespace std; long long xl, xr, yu, yd; long long x, y; int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); long long n; cin >> n; for (int i = 0; i < n; i++) { cin >> x >> y; if (i == 0) { xl = x; xr = x; yu = y;...
#include <bits/stdc++.h> using namespace std; int o, e, oC, eC, n, en; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> en; if (en % 2 == 0) { e = i; eC++; } else { o = i; oC++; } } if (oC == 1) cout << o; else cou...
#include <bits/stdc++.h> using namespace std; double px[1005], py[1005]; double tx, ty; int sum; int pnpoly(int nvert, double *vertx, double *verty, double testx, double testy) { int i, j, c = 0; for (i = 0, j = nvert - 1; i < nvert; j = i++) { if (((verty[i] > testy) != (verty[j] >...
#include <bits/stdc++.h> using namespace std; const int N = 1e5; int w[N], ne[N], la[N], len[N], cst[N], t = 1; void alink(int x, int y, int z, int c) { w[++t] = y; ne[t] = la[x]; la[x] = t; len[t] = z; cst[t] = c; } void link(int x, int y, int z, int c) { alink(x, y, z, c); alin...
#include <bits/stdc++.h> using namespace std; int IN() { int c, x; while (!isdigit(c = getchar())) ; x = c - 0 ; while (isdigit(c = getchar())) x = (x << 1) + (x << 3) + c - 0 ; return x; } const int N = 1000 + 19, P = 1e9 + 7; int A[N][N], s[N][N], f[N], c[N], b[N]; int n, m, k,...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 10, Mod = 1e9 + 7; int t, n, k; long long Pow(long long a, long long b) { a %= Mod; long long ans = 1; while (b) { if (b & 1) ans *= a, ans %= Mod; a *= a, a %= Mod; b >>= 1; } return ans; } long long ...
#include <bits/stdc++.h> using namespace std; int n, l = 1; string s; int main() { cin >> n >> s; for (int i = 1; i <= n; i++) if (s.substr(0, i) == s.substr(i, i)) l = i; cout << n - l + 1; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 543; const long long INF = (long long)(1e18); struct Matching { int n1, n2; vector<set<int>> g; vector<int> mt, used; void init() { mt = vector<int>(n2, -1); } int kuhn(int x) { if(used[...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 100; int a[maxn], ans[2 * maxn]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m, c; cin >> n >> m >> c; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) { ...