func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const int mx = 1e5 + 5; int f[mx]; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<pair<int, int>> v; for (int i = 3; 2 * i <= n; i += 2) { if (f[i] == 0) { int c = 0; for (int j = i; j...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; int n, act; int t[MAXN]; int last[MAXN], len[MAXN]; int main() { scanf( %d , &n); for (int i = 1; i < MAXN; ++i) len[i] = -1; for (int i = 1; i <= n; ++i) { scanf( %d , &t[i]); act = t[i]; if (len[act] == -1...
#include <bits/stdc++.h> using namespace std; const long long int MaxN = 300005; const long long int mod = 1e9 + 7; const float pi = 3.1415926535897932384626433832795028; long long int mcd(long long int a, long long int b) { if (a == 0) return b; return mcd(b % a, a); } int arr[MaxN]; void solve...
#include <bits/stdc++.h> using namespace std; inline int read() { int out = 0, fh = 1; char jp = getchar(); while ((jp > 9 || jp < 0 ) && jp != - ) jp = getchar(); if (jp == - ) fh = -1, jp = getchar(); while (jp >= 0 && jp <= 9 ) out = out * 10 + jp - 0 , jp = getchar(); return out...
#include <bits/stdc++.h> using namespace std; int t[101000], n, h[101000], p[101000]; pair<int, int> w[101000]; int main() { scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d , &t[i]); w[i].first = t[i]; w[i].second = i; } sort(w, w + n); for (int i = n - 1; i >= 0; ...
#include <bits/stdc++.h> using namespace std; const int N = 1e6; const int inf = 1e9; const int mod = 1e9 + 7; const long long INF = 1e18; long long a00, a01, a10, a11, cnt0, cnt1, cnt01, cnt10, ins = 0, t = -1; long long p[N]; void get() { for (int i = 1; i <= ins; ++i) { cout << 1; } ...
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 10; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long lcm(long long a, long long b) { return a * b / gcd(a, b); } long long a[maxn], suf[maxn]; int main() { long long n, ans = 0; cin >> n; for ...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; const int MAXN = 5 * 1e5 + 1, MODM = 1e9 + 7; int n; vector<int> g[MAXN]; int sz[MAXN]; int pr[MAXN]; int ans[MAXN]; int m1, m2; int now; int root = -1; void dfs(int v, int p = -1) { sz[v] = 1; pr[v] = p; for (...
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5; const long double PI = acos(-1.0); char d[MAX]; int l[MAX]; int w[MAX]; int pos; int main() { long long n; ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; long long i; for (i = 0; i < n; i++) cin >> d[i]; ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; for (int i = 0; i < k; i++) { if (n % 10 > 0) { n--; } else n /= 10; } cout << n; return 0; }
#include <bits/stdc++.h> using namespace std; char s[100100]; int main() { int n, m; scanf( %d %d %s , &n, &m, s); long long ans = 0, cnt = 1, num = 0; for (int i = 1; s[i]; i++) { cnt += s[i] != s[i - 1]; } ans += cnt * n * (m - 1); cnt = 1; for (int i = 1; s[i]; i++) { ...
#include <bits/stdc++.h> #pragma comment(linker, /stack:200000000 ) #pragma GCC optimize( Ofast ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) #pragma GCC optimize( unroll-loops ) using namespace std; template <class A, class B> ostream& operator<<(ostream& out, const pai...
#include <bits/stdc++.h> using namespace std; int n, s, e; long long x[5001]; long long a[5001]; long long b[5001]; long long c[5001]; long long d[5001]; long long pd[5001][5001]; long long func(int at, int comp, int left, int right) { if (comp <= 0 && at != 0) return 0x3f3f3f3f3f3f3f3fll; if ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; if (m % 2 != 0) { cout << (m + 1) / 2; } else { cout << (n - m + 2) / 2; } return 0; }
#include <bits/stdc++.h> const int MAXN = 1005; int a[MAXN]; int cnt[MAXN]; int main() { int n, k; while (scanf( %d%d , &n, &k) + 1) { memset(cnt, 0, sizeof(cnt)); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int a, b; cin >> a >> b; cout << a << << a * 2 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; map<long long, pair<long long, long long>> ChthollyTree; map<long long, pair<long long, long long>>::iterator split( long long p, map<long long, pair<long long, long long>>::iterator *pre) { map<long long, pair<long long, long long>>::iterator pos = ...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); int ans = 6; for (int i = 4; i <= n; i++) { ans += (i - 1) * i; } printf( %d n , ans); return 0; }
#include <bits/stdc++.h> using namespace std; int kbo[1001]; int main() { int s, k, i; scanf( %d%d , &s, &k); kbo[0] = 0; kbo[1] = 1; kbo[2] = 1; for (i = 3;; i++) { if (i - k - 1 > 0) kbo[i] = 2 * kbo[i - 1] - kbo[i - k - 1]; else kbo[i] = 2 * kbo[i - 1]; ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10, K = 105, MOD = 998244353; int p[N][K], dp[N][K], a[N], ans[N] = {1}; int n, k, len; int sum(int l, int r, int x) { l = max(l, 1); r = min(r, n); return p[r][x] - p[l - 1][x]; } int main() { cin >> n >> k >> len; for ...
#include <bits/stdc++.h> using namespace std; const long long MAXN = 200011; long long a[MAXN], v[MAXN]; int main() { long long ii, tt, i, j, k, m, n, d, md, maxt, mx, t, ct, oct, res1, res2, sum, osum, L, R, M; cin >> tt; for (ii = 0; ii < tt; ii++) { cin >> n >> m >> maxt; for ...
#include <bits/stdc++.h> using namespace std; long long int max(long long int a, long long int b) { if (a > b) return a; else return b; } long long int gcd(long long int a, long long int b) { if (a == 0) return b; return gcd(b % a, a); } long long int lcm(long long int a, long lo...
#include <bits/stdc++.h> using namespace std; const int INF = INT_MAX; const int NINF = INT_MIN; const long long INF_LL = LLONG_MAX; const long long NINF_LL = LLONG_MIN; const double PI = acos(-1.0); const int MOD = 1e9 + 7; int main() { long long n, m; cin >> n >> m; long long ans = n * n; ...
#include <bits/stdc++.h> using namespace std; template <class T> T abs(T x) { return x > 0 ? x : -x; } int n; int m; int l[100], v[100][100], t[100][100], q[200]; int main() { scanf( %d%d , &n, &m); for (int i = 0; i < n; i++) { scanf( %d , &l[i]); for (int j = 0; j < l[i]; j++) ...
#include <bits/stdc++.h> using namespace std; template <typename _Tp> inline _Tp read(_Tp& x) { char c11 = getchar(), ob = 0; x = 0; while (c11 ^ - && !isdigit(c11)) c11 = getchar(); if (c11 == - ) ob = 1, c11 = getchar(); while (isdigit(c11)) x = x * 10 + c11 - 0 , c11 = getchar(); if...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, x, a, b; cin >> n >> x >> a >> b; if (abs(a - b) + x >= n) cout << n - 1 << endl; else { cout << abs(a - b) + x << endl; } } }
#include <bits/stdc++.h> using namespace std; int read() { int x = 0, f = 1; char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) f = -1; c = getchar(); } while (c >= 0 && c <= 9 ) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); return x * f; } int n, a[...
#include <bits/stdc++.h> using namespace std; const int maxn = 2 * 1e5 + 5; double sum; int i, j, l, o, n, k, a[maxn]; int main() { scanf( %d %d , &n, &k); for (int j = 1; j <= n; j++) scanf( %d , &a[j]); for (i = 1; i <= n; i++) { if (i <= k) { if (n - k + 1 >= i) sum += 1...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << n % 2 << n ; return 0; }
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long int LINF = 0x3f3f3f3f3f3f3f3fll; const long double pi = acos(-1); const int MOD = 1e9 + 7; const int N = 310; int l[N], c[N]; map<long long int, int> mapa; int mdc(int a, int b) { if (b == 0) return a; re...
#include <bits/stdc++.h> using namespace std; int n, m; struct node { int u, v, w; friend bool operator<(node a, node b) { return a.w > b.w; } } itm[200005]; int fa[200005]; int gf(int x) { if (x != fa[x]) return fa[x] = gf(fa[x]); return fa[x]; } int main() { while (~scanf( %d%d , &...
#include <bits/stdc++.h> using namespace std; const int M = 2e5 + 100; int a[M], b[M]; int n, x, y; int di[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; bool check(int xx, int yy) { if (xx < 1 || xx > x || yy < 1 || yy > y) return 0; return 1; } bool bfs() { queue<int> q; int l = 0; q....
#include <bits/stdc++.h> using namespace std; long long n, i, j, ans, sum1, sum2; long long x[100000], y[100000]; int main() { scanf( %I64d , &n); sum1 = 0; sum2 = 0; ans = 0; for (i = 0; i < n; i++) { scanf( %I64d %I64d , &x[i], &y[i]); ans += (n * (x[i] * x[i] + y[i] * y[i])); ...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); int arr[n][n]; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) scanf( %d , &arr[i][j]); int q; scanf( %d , &q); int res = 0; for (int k = 0; k < n; k++) { res += arr[k][k]; re...
#include <bits/stdc++.h> using namespace std; int main() { std::ios_base::sync_with_stdio(false); cin.tie(0); long long int n, i, j, x, in = 0; string s; vector<pair<string, long long int>> v; priority_queue<long long int, vector<long long int>, greater<long long int>> pq; cin >>...
#include <bits/stdc++.h> const int MOD = 1e9 + 7; const int MAXN = 2e5 + 17; const int magic = (1 << 7); using namespace std; struct p { long double x, y; p(long double x, long double y) : x(x), y(y) {} p() {} long double len() const { return sqrt(x * x + y * y); } }; p operator-(const p &...
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0, f = 1; char ch = getchar(); while (ch > 9 || ch < 0 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { x = x * 10 + ch - 0 ; ch = getchar(); } r...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const int INF = 1e6; namespace IO { const int MAXSIZE = 1 << 20; char buf[MAXSIZE], *p1, *p2; inline int gc() { return (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2) ...
#include <bits/stdc++.h> using namespace std; long long n, m, ans, a[2000010], a0[2000010]; struct Node { long long MaxL, MaxR, Max; }; Node tree[2000010]; long long Sign(long long x) { if (x > 0) { return 1; } if (x == 0) { return 0; } return -1; } void Merge(long lo...
#include <bits/stdc++.h> using namespace std; const int mm = 1e6 + 1; const int mx = 1 << 20; const int N = 3e5 + 10; int a[N], b[N]; int seg_t[mx * 2 + 10], tag[mx * 2 + 10]; void up(int o) { seg_t[o] = max(seg_t[o << 1], seg_t[o << 1 | 1]); } void down(int o) { if (tag[o] == 0) { return; ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); long long int x1, y1; cin >> x1 >> y1; long long int x2, y2; cin >> x2 >> y2; int n; cin >> n; int ans = 0; for (int i = 0; n > i; i++) { long long int a, b, c; cin >> a >> b >> c;...
#include <bits/stdc++.h> using namespace std; long long N; long long F[20][10][10] = {{{0}}}; int to[20][10][10] = {{{0}}}; long long Ans[20][10] = {{0}}; void done() { for (int i = 0; i <= 9; i++) { for (int j = 0; j <= 9; j++) { int x = max(i, j); if (i == 0 || i < x) { ...
#include <bits/stdc++.h> using namespace std; int main() { std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int testcases; cin >> testcases; while (testcases--) { long long int n, m; cin >> n >> m; char a[n][m]; for (long long int(i) = 0; (i) ...
#include <bits/stdc++.h> using namespace std; int dx[] = {-1, 1, 0, 0, 1, -1, 1, -1}; int dy[] = {0, -0, -1, 1, 1, -1, -1, 1}; void run() {} int fixMod(int a, int b) { return ((a % b) + b) % b; } long long gcd(long long a, long long b) { return (b == 0 ? abs(a) : gcd(b, a % b)); } void fast() { ...
#include <bits/stdc++.h> using namespace std; struct node { double x, y, r; }; double dis(node a, node b) { double dx = a.x - b.x, dy = a.y - b.y; return sqrt(dx * dx + dy * dy); } double R, d; node origin = {0, 0}; bool check(node a) { double distance = dis(a, origin); if (distance ...
#include <bits/stdc++.h> using namespace std; int n, m, a[200200], w[200200], dp[3030][3030], ep[3030][3030], X, Y, Z, ans[200200], Inv[2 * 3030 + 5]; const int mod = 998244353; int expmod(int x, int n) { int rlt = 1; while (n) { if (n & 1) rlt = 1ll * rlt * x % mod; x = 1ll * x * x % ...
#include <bits/stdc++.h> using namespace std; const int N = 300050; const int M = 2 * N; char s[M]; int tot, sa[M], id[M], fwid[N], bwid[N]; vector<pair<pair<int, int>, int> > tmp; void BuildSuffixArray() { int i, j, cnt; s[++tot] = a + 26; for (i = 1; i <= tot; i++) id[i] = s[i] - a ; ...
#include <bits/stdc++.h> using namespace std; const int nMAX = 100000 + 5; const int NMAX = 2 * nMAX; int n, m; string S, T; int Q; int N; string str; const int MOD[] = {1000000000 + 7, 1000000000 + 9}; struct Hash { int h[sizeof(MOD) / sizeof(int)]; Hash() { for (int i = 0; i < sizeof...
#include <bits/stdc++.h> using namespace std; int n, x, s; int a[105]; double f[105][10005]; int main() { cin >> n >> x; for (int i = 1; i <= n; i++) cin >> a[i], s += a[i]; f[0][0] = 1; for (int i = 1; i <= n; i++) for (int j = i; j >= 1; j--) for (int k = s; k >= a[i]; k--) ...
#include <bits/stdc++.h> const int INF = 1e6; using namespace std; const int maxn = 1e5 + 5; const int N = 1e6; const int big = 1e9; long long int get(long long int a, long long int b, long long int x, long long int y) { x--; y--; long long int temp = (y * (y - 1) - x * (x - ...
#include <bits/stdc++.h> using namespace std; int n; queue<pair<int, int> > q; vector<pair<int, int> > v; vector<vector<int> > g; set<pair<int, int> > out; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; for (int i = 0; i < n; i++) { int x, y; cin >> x >...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m, x, y, i, s = 0, k = 0; vector<pair<long long int, long long int> > v; cin >> n >> m; for (i = 0; i < m; i++) { cin >> x >> y; v.push_back(make_pair(y, x)); } sort(v.begin(), v.end()); for (i = v.si...
#include <bits/stdc++.h> using namespace std; int v[100010]; int main() { int n, k; scanf( %d %d , &n, &k); int low = 1000000001; for (int i = 0; i < n; i++) { scanf( %d , &v[i]); low = min(low, v[i]); } long long ans = 0; for (int i = 0; i < n && ans != -1; i++) { if...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; stack<char> a; int count = 0, flag = 0; for (int i = 0; i < s.length(); i++) { if (s[i] == { || s[i] == [ || s[i] == < || s[i] == ( ) a.push(s[i]); else { if (a.size() == 0) { ...
#include <bits/stdc++.h> using namespace std; using ll = long long; #ifdef LOCAL #define debug(...) { std::cout << [ << __FUNCTION__ << : << __LINE__ << ] << #__VA_ARGS__ << << __VA_ARGS__ << std::endl; } #else #define debug(...) #endif const long long mod = 1000000007; ...
#include <bits/stdc++.h> using namespace std; int const maxn = int(2 * 1e5 + 5); int dp1[maxn], dp2[maxn], dp3[maxn], n, k, t; string second; char chuyen(char c) { if (c == R ) return G ; if (c == G ) return B ; if (c == B ) return R ; } int main() { ios_base::sync_with_stdio(false);...
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; int main() { int h, w, k, count = 0; scanf( %d %d %d , &h, &w, &k); for (size_t i = 0; i < k; i++) { if (h == 1 && w == 1) { count++; } else if (h == 1) { count += w; } else if (w == 1) { ...
#include <bits/stdc++.h> using namespace std; int N; int x[2001], y[2001]; bool sameLine(int i, int j, int k) { return (y[i] - y[j]) * (x[k] - x[j]) == (y[k] - y[j]) * (x[i] - x[j]); } int main() { scanf( %d , &N); for (int i = 0; i < N; i++) scanf( %d %d , &x[i], &y[i]); long long ans = 0; ...
#include <bits/stdc++.h> using namespace std; int f(long long p) { int ans = 0; while (p) { ans += p % 10; p /= 10; } return ans; } long long g(long long a) { if (a == 0) return 0; int digit = 0; long long b = a; while (b >= 10) { digit++; b /= 10; } ...
#include <bits/stdc++.h> using namespace std; template <class T> T euclideanistance(T x1, T x2, T y1, T y2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); } template <class T> T digitSum(T n) { T sum = 0; while (n > 0) sum += n % 10, n /= 10; return sum; } const double INF...
#include <bits/stdc++.h> using namespace std; long long lcis(long long a[], long long n) { unordered_map<long long, long long> make_pair; long long dp[n], lastIndex; memset(dp, 0, sizeof(dp)); ; long long mx = INT_MIN; for (long long i = 0; i < n; i++) { if (make_pair.find(a[i] - 1) !=...
#include <bits/stdc++.h> using namespace std; const long long inf = 1e16 + 3; const int mod = 1e9 + 7; const int lim = 2e5 + 2; int q, ni; string str; void solve() { cin >> q; while (q--) { cin >> ni >> str; if (ni > 2) { cout << YES << n ; cout << 2 <<...
#include <bits/stdc++.h> using namespace std; const int INF = 2e9; const long long LINF = 2e18; void inv(bool e); template <typename T> void die(T& a); bool brute, alter; int cnt_tests = 1; const int N = (1 << 17) + 1; int degree[N], xr[N]; int n; void inp() { cin >> n; for (int i = 0; i...
#include <bits/stdc++.h> using namespace std; void ga(int N, int *A) { for (int i(0); i < N; i++) scanf( %d , A + i); } char s[64][64]; int N, M, x = int(1e9 + 1), X, y = int(1e9 + 1), Y; int main(void) { scanf( %d%d , &N, &M); for (int i(0); i < N; i++) scanf( %s , s[i]); for (int i(0); i <...
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 10; int mapp[110][110]; int b[110][110]; int main() { int Cas = 1; scanf( %d , &Cas); while (Cas--) { int n, m; scanf( %d%d , &n, &m); memset(mapp, 0, sizeof(mapp)); for (int i = 1; i <= n; i++) for...
#include <bits/stdc++.h> using namespace std; const long long int mxn = 1e5 + 1; string s, s1, s2, s3; char ch[10000][10000]; int main() { long long int n, m, i, z, j, a = 0, ans = 0, k = 0, cnt = 0, b; long long int c = 0, x, y, d = 0, sum = 0, mn = INT_MAX, mx = 0; string ss, strn; char ch; ...
#include <bits/stdc++.h> using namespace std; const int T = 1000; const long long MAX = 1000000000000007; const long long MOD = 100000000; long long n, m, k; vector<long long> A[T]; vector<pair<char, int> > ans; long long K[T]; long long N[T]; int main() { cin >> n; for (int i = (int)0; i <=...
#include <bits/stdc++.h> int n, i, j, k, t, len; char st[200]; int main() { scanf( %d , &n); while (n--) { scanf( %s , st); len = strlen(st); t = 8; for (i = 0; i < len; i++) if (st[i] != : ) { t--; while (i < len && st[i] != : ) i++; } j...
#include <bits/stdc++.h> using namespace std; const int Z = (int)1e5 + 111; const int inf = (int)1e9 + 111; const long long llinf = (long long)1e18 + 5; const int MOD = (int)1e9 + 7; vector<int> ans[Z]; int a[Z]; pair<int, int> b[Z]; int main() { ios_base::sync_with_stdio(false); int n; ci...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const long long INF = 1e9; const long long LINF = INF * INF; const int MAX = 1 << 10; void go(pair<int, int> s, pair<int, int> f, vector<pair<int, int> >& a) { a.push_back(s); while (s.first > f.first) { s.first--; ...
#include <bits/stdc++.h> using namespace std; int i, h, j, w; string s, t, v; pair<string, int> k; stack<int> p; vector<pair<string, int>> a; int main() { cin >> s; v = s; t = s; for (i = 0; i < s.size(); i++) if (s[i] == ( || s[i] == [ ) p.push(i); while (!p.empty()) { ...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k, p, x, y; cin >> n >> k >> p >> x >> y; long long int sum = 0; long long int cov = 0; for (int i = 0; i < k; i++) { long long int kk; cin >> kk; if (kk < y) cov++; sum += kk; } int used ...
#include <bits/stdc++.h> using namespace std; int p[2][252], f[252][252], C[252], mod = 1e9 + 7, inv[252]; int qp(int a, int x) { int i = 1; for (; x; x >>= 1, a = 1ll * a * a % mod) if (x & 1) i = 1ll * i * a % mod; return i; } int main() { int n, m, i, j, k, a; scanf( %d%d , &n, &m...
#include <bits/stdc++.h> using namespace std; char str[110]; void in(long long &x, long long &y) { scanf( %s , str); int len = strlen(str); int at; for (int i = 0; i < len; i++) if (str[i] == / ) at = i; x = 0; for (int i = 0; i < at; i++) x = x * 10 + (str[i] - 0 ); y = 0; ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; int m; cin >> n >> m; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); int ans = 0; for (int i = 0; i < m; i++) { ...
#include <bits/stdc++.h> using namespace std; struct __s { __s() { if (1) { ios_base::Init i; cin.sync_with_stdio(0); cin.tie(0); } } ~__s() { if (!1) fprintf(stderr, Execution time: %.3lf s. n , (double)clock() / CLOCKS_PER_SEC); ...
#include <bits/stdc++.h> using namespace std; map<string, int> nums; int liking[7][7]; bool usable[7]; int team[7]; vector<int> members[3]; int mindifference, maxliking; int a, b, c; void teaming(int currteam, int memberno) { int i, j, t; if (currteam == 2 && memberno == 7) { int exp1 = ...
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; int n, m; int a[66], w[66]; long long dp[66][66][66]; int sa, sb, sum; long long inv[10010]; void solve1(int x) { memset(dp, 0, sizeof(dp)); dp[0][0][0] = 1; long long zi, mu; for (int i = 0; i < m; ++i) ...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, n; string str; cin >> n >> a >> b >> str; if (str[b - 1] == str[a - 1]) cout << 0 n ; else cout << 1 n ; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); string a, b; cin >> a >> b; if (a == b) cout << a << endl; else cout << 1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; map<string, int> m1; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int n, k, t; cin >> n >> k >> t; int temp = n * k * t / 100; int cnt = 0; while (n--) { if (temp > 0) { if (temp < k) { ...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e8; const double EPS = 1e-9; const long long MOD = (long long)(1e9 + 7); const long long MAXV = (long long)(5e3 + 10); const long long MAXE = (long long)(1e5 + 10); int n, m; int c[200]; vector<pair<int, int> > aux; bool cmp(pair<i...
#include <bits/stdc++.h> using namespace std; int a[400100]; int b[400100]; int main() { int n; cin >> n; int k = 0; for (int i = 1; i <= n; i++) { int l; cin >> l; if (l == 0) { k = 1; } else { if (k == 1) a[i - 1] = l; else a[...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); double fRand(double fMin, double fMax) { double f = (double)rand() / RAND_MAX; return fMin + f * (fMax - fMin); } template <class T> T min(T a, T b, T c) { return min(a, min(b, c)); } template <class T> T max(T a, ...
#include <bits/stdc++.h> using namespace std; int main() { long long a[100000]; long long n, i; cin >> n; for (i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); a[0] = 1; for (i = 1; i <= n - 1; i++) { if (a[i] == a[i - 1] || a[i] == a[i - 1] + 1) continue; ...
#include <bits/stdc++.h> using namespace std; long long sqr(long long a) { return a * a; } int main() { ios_base::sync_with_stdio(0); int n, m; cin >> n >> m; vector<long long> sumx(n, 0ll); vector<long long> sumy(m, 0ll); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { ...
#include <bits/stdc++.h> using namespace std; int n, ans; bool pd(int n) { for (int i = 2; i <= sqrt(n); i++) if (n % i == 0) return false; return true; } int main() { scanf( %d , &n); if (pd(n)) puts( 1 ); else if (n % 2 == 0 || pd(n - 2)) puts( 2 ); else puts(...
#include <bits/stdc++.h> using namespace std; vector<int> ans, adj[200007]; bool vis[200007]; int inputorder[200007], relorder[200007]; bool cmp(int a, int b) { return relorder[a] < relorder[b]; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n, x, a...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int n, sz[N], sum[N]; int64_t r[N][3], ans; vector<pair<int, int>> g[N]; void dfs(int x, int f) { sz[x] = 1; for (auto &e : g[x]) { int y = e.first, w = e.second; if (y == f) continue; dfs(y, x), sz[x] += sz[y]; ...
#include <bits/stdc++.h> using namespace std; int k[3], n, pos[200005]; int dp[200005][3]; int main() { ios::sync_with_stdio(0); for (int i = 0; i < 3; i++) cin >> k[i], n += k[i]; for (int t, p = 0; p < 3; p++) for (int i = 1; i <= k[p]; i++) { cin >> t, pos[t] = p; } for (i...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, num = 0, dem = 0; cin >> n; if (n % 2 == 0) { num = (n / 2) - 1; dem = (n / 2) + 1; } else { num = n / 2; dem = n - num; } set<int> x, ...
#include <bits/stdc++.h> using namespace std; using i64 = long long int; using ii = pair<int, int>; using ii64 = pair<i64, i64>; i64 ipow(i64 x, i64 n) { if (n == 0) return 1ll; i64 half = ipow(x, n / 2); half = (half * half) % 1000000007; if (n % 2 == 0) return half; else retu...
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> g[200010]; int vis[200010], d[200010]; stack<int> his; void dfs(int u, int dd) { his.push(u); d[u] = dd; for (int v : g[u]) { if (!d[v]) dfs(v, dd + 1); else if (d[u] - d[v] + 1 >= ceil(sqrt(n))) { pu...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const double EPS = 1e-7; const int INF = 1000000000; char buf[100]; int maxl[2000000]; int maxr[2000000]; int minl[2000000]; int minr[2000000]; pair<int, int> g[2000000]; int n; int X = 0; void dfs(int, int); void ad...
#include <bits/stdc++.h> using namespace std; inline long long max(long long a, long long b) { return ((a > b) ? a : b); } inline long long min(long long a, long long b) { return ((a > b) ? b : a); } inline long long gcd(long long a, long long b) { if (b == 0) return a; a %= b; return gcd(b, a); }...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int x = 0, y = 0, dp = 0, tmp; int sum = 0; for (int i = 0; i < s.length(); i++) { if (s[i] == U ) { y++; if (x < y) { if (dp == 2) sum++; dp = 1; ...
#include <bits/stdc++.h> using namespace std; const double pi = 3.1415926536; const long long INF = 1e18; const int32_t M = 1e6 + 7; const int32_t MM = 998244353; long long a, b, c, d; void solve() { cin >> a >> b >> c >> d; double p, q, x; p = (double)a / b; q = (double)c / d; x = (1 ...
#include <bits/stdc++.h> using namespace std; vector<int> ans; int n, r, fr[101][101]; int main() { cin >> n; for (int i = 0; i < n; i++) { scanf( %d , &r); for (int x, j = 0; j < r; j++) { scanf( %d , &x); fr[i][x]++; } } for (int i = 1; i <= 100; i++) { ...
#include <bits/stdc++.h> using namespace std; const int N = 2e6 + 5; const int mod = 1e9 + 7; int a[N], f[N]; int main() { int n; int p = 0; scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d , &a[i]); if (a[i] == 0) f[p++] = i; } int v = 0; for (int i = 0; i < n;...
#include <bits/stdc++.h> using namespace std; int dist[605][605], u, v, a[205], n, Vv, E, m, fix[605], match[605], w, ans, l, r, k; priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > q; vector<pair<int, int> > V[605]; vector<pair<pair<int, int>, int...