func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int n, m; char x[1001][1001]; int check(int i, int j) { if (x[i][j] == . ) { for (int a = -1; a <= 1; a++) { for (int k = -1; k <= 1; k++) { if (i + a >= 0 && i + a < n && j + k >= 0 && j + k < m && x[i + a][j + k] == * ) ...
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 100; int n, m, k, ans; int num[maxn]; int main() { ios::sync_with_stdio(false); while (scanf( %d%d%d , &n, &m, &k) != EOF) { ans = 0; for (int i = 0; i < n; ++i) { scanf( %d , &num[i]); } ans = num[...
#include <bits/stdc++.h> using namespace std; long long n, k, m; long long t[300005]; long long a[300005]; long long s; long long res[300005], ans[300005]; long long cnt[300005]; long long pre[300005], p[300005], pp[300005]; struct query { long long l; long long r; long long id; } q[3000...
#include <bits/stdc++.h> using namespace std; int64_t b, s, c; int64_t pr[3]; int64_t m; int64_t req[] = {0, 0, 0}; bool binary_search(int64_t mid) { int64_t to[3]; for (int64_t i = 0; i < 3; i++) { to[i] = req[i] * mid; } to[0] -= b; to[1] -= s; to[2] -= c; int64_t cost = ...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const int mod = 1000000007; const int inf = 0x3f3f3f3f; const int maxn = 200005; void task() { int r1, c1, r2, c2; cin >> r1 >> c1 >> r2 >> c2; int Rook = 0, Bishop = 0, King = 0; if (r1 == r2 or c1 == c2) Rook...
#include <bits/stdc++.h> using namespace std; int ans = 0; int m; void dfs(int parent, int s, int cnt, vector<int> &cats, vector<vector<int> > &adj) { if (cats[s] == 1) cnt++; else cnt = 0; if (cnt > m) return; if (s != 1 && adj[s].size() == 1) { ans++; return;...
#include <bits/stdc++.h> using namespace std; int n, m, a[1000006], ans[1000006]; bool b[1000006]; stack<pair<int, int> > s1, s2; int main() { int i, j; scanf( %d , &n); for (i = 1; i <= n; i++) scanf( %d , &a[i]); scanf( %d , &m); for (i = 1; i <= m; i++) { scanf( %d , &j); b[...
#include <bits/stdc++.h> using namespace std; const int N = 1e2, W = 10; long long dp[N + 5][N + 5][W + 5][W + 5]; int n1, n2, k1, k2; int main() { memset(dp, -1, sizeof(dp)); cin >> n1 >> n2 >> k1 >> k2; for (int i = 0; i <= n1; i++) { for (int j = 0; j <= n2; j++) { for (int k = 0;...
#include <bits/stdc++.h> using namespace std; int ans[] = {0, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51, 1, 2, 1, 14, 1, 2, 2, 14, 1, 6, 1, 4, 2, 2, 1, 52, 2, 5, 1, 5, 1, 15, 2, 13, 2, 2, 1, 1...
#include <bits/stdc++.h> using namespace std; long long EPS = 1000000007; const int INF = 1000000000; double PI = 3.14159265358979323846; const int MAXN = 1000040; long long abss(long long h) { return max(h, -h); } double fabss(double h) { return max(h, -h); } long long ceill(long long x, long long y) {...
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (a == 0) return b; return (b % a, a); } int binarysearch(int a[], int ele, int n) { int beg = 0, end = n, mid, ans; while (beg <= end) { mid = beg + (end - beg) / 2; if (a[mid] > ele) { ans = mid; ...
#include <bits/stdc++.h> using namespace std; const int N = 505; int dis[N][N]; int vis[N], arr[N]; long long ans[N]; int main() { int n; cin >> n; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { cin >> dis[i][j]; } } for (int i = 1; i <= n; ++i) { ...
#include <bits/stdc++.h> using namespace std; const int N = 200 * 1000 + 20; int p[N], q[N], n, ans[N], cnt[N], seg[N << 2]; void build(int id = 1, int st = 0, int en = n) { if (en - st == 1) { seg[id] = 1; return; } int mid = st + en >> 1; build(id << 1, st, mid); build(id << 1 ...
#include <bits/stdc++.h> using namespace std; inline long long read() { long long s = 0, w = 1; register char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) w = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar...
#include <bits/stdc++.h> using namespace std; inline int rdi() { int d; scanf( %d , &d); return d; } inline char rdc() { scanf( ); return getchar(); } inline string rds() { string s; cin >> s; return s; } inline double rddb() { double d; scanf( %lf , &d); re...
#include <bits/stdc++.h> using namespace std; int x[4]; int y[4]; int newx[4]; int newy[4]; int T; int get() { int answ = INT_MAX; for (auto y1 : y) for (auto y2 : y) { int delta = abs(y1 - y2); if (delta == 0) continue; set<int> s; for (auto x1 : x) ...
#include <bits/stdc++.h> using namespace std; vector<char> sequ; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; long long num; cin >> n; vector<long long> a(n); vector<long long> b(n); for (int i = 0; i < n; i++) { cin >> a[i]; } for (in...
#include <bits/stdc++.h> using namespace std; int main() { int n, x; int a; scanf( %d%d , &n, &x); int sum = 0; while (n--) { scanf( %d , &a); sum += a; } int count = 0; if (sum == 0) { } else { if (abs(sum) <= x) { count = 1; } else { coun...
#include <bits/stdc++.h> using namespace std; int mp[27][27]; int dp[111][111][26]; bool flag[111][111][26]; char s[111]; inline void checkmax(int &a, int b) { if (a < b) a = b; } int main() { int i, j, k, n, m; scanf( %s , s); scanf( %d , &k); scanf( %d , &n); for (i = 1; i <= n...
#include <bits/stdc++.h> int main() { static char xx[100 + 1], yy[100 + 1]; int n, i; scanf( %s%s , xx, yy); n = strlen(xx); for (i = 0; i < n; i++) if (xx[i] < yy[i]) { printf( -1 n ); return 0; } printf( %s n , yy); return 0; }
#include <bits/stdc++.h> using namespace std; int arr[100002]; int main() { int i, n, ans = 0, mm = 0; cin >> n; n = n << 1; for (i = 0; i < n; i++) { int a; scanf( %d , &a); ans = ans - arr[a]; arr[a] = arr[a] ^ 1; ans += arr[a]; mm = max(mm, ans); } co...
#include <bits/stdc++.h> using namespace std; inline int read() { int s = 0, w = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) w = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) s = s * 10 + ch - 0 , ch = getchar(); return s * w; } int main() { ...
#include <bits/stdc++.h> using namespace std; bool foiare[1024], cand[1024], foivert[1024]; int n, a[32]; int main() { scanf( %d , &n); memset(foiare, false, sizeof(foiare)); memset(foivert, false, sizeof(foivert)); for (int i = 0; i < n; i++) { for (int j = 1; j <= 1000; j++) if (...
#include <bits/stdc++.h> int n, m; long double p[3010][310], delta[310], f[310][3010], ans = 0, lastf[3010]; int num[310]; void solve(int cur) { num[cur]++; if (num[cur] >= n) { delta[cur] = 0; return; } memcpy(lastf, f[cur], sizeof(f[cur])); f[cur][0] = 0; for (int i = 1; i ...
#include <bits/stdc++.h> using namespace std; int a[10000], b[10000]; void mergesort(int *a, int *b, int n) { int i0, i1, iRight, iEnd, width, i, j; for (width = 1; width < n; width <<= 1) for (i = 0; i < n; i += (width << 1)) { i0 = i; i1 = iRight = min(i + width, n); iEnd =...
#include <bits/stdc++.h> using namespace std; void Test() { long long n; cin >> n; string s[n]; for (long long i = 0; i < n; i++) { cin >> s[i]; } long long ans = 0; for (char i = a ; i <= e ; i++) { vector<pair<long long, long long> > v; for (long long j = 0; j < n; ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 5; const int MAXM = 4e5 + 5; template <typename T> void chkmax(T &x, T y) { x = max(x, y); } template <typename T> void chkmin(T &x, T y) { x = min(x, y); } template <typename T> void read(T &x) { x = 0; int f = 1...
#include <bits/stdc++.h> using namespace std; int T, pw[10000005], N, K, X, c[10000005], d[10000005]; long long exp(long long a, long long b) { if (b == 0) return 1; if (b == 1) return a; long long res = exp(a, b >> 1); if (b & 1) { return a * (res * res % 998244353) % 998244353; } r...
#include <bits/stdc++.h> int main() { int p, q, l, r; scanf( %d %d %d %d , &p, &q, &l, &r); std::vector<std::pair<int, int> > fixed; std::vector<std::pair<int, int> > changing; for (int k = 0; k < p; k++) { int a, b; scanf( %d %d , &a, &b); fixed.push_back(std::pair<int, int>(a, ...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const int mod = 1000000007; const int inf = 0x3f3f3f3f; const int maxn = 200005; void task() { int n; cin >> n; vector<int> row(n, 0), coulmn(n, 0); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) { ...
#include <bits/stdc++.h> using namespace std; int main() { int k; cin >> k; int a[k + 1]; for (int i = 0; i < k; i++) cin >> a[i]; long long int comb[1005][1005]; comb[0][0] = 1; for (int i = 1; i < 1005; i++) { comb[i][0] = 1; for (int j = 1; j <= i; j++) { comb[i][j...
#include <bits/stdc++.h> using namespace std; const int N = 50005, M = 50005; int mo; struct matrix { int a[2][2]; int *operator[](const int i) { return a[i]; } const int *operator[](const int i) const { return a[i]; } friend matrix operator*(const matrix &a, const matrix &b) { matrix c; ...
#include <bits/stdc++.h> using namespace std; string s[1010]; int main() { int n; cin >> n; bool f = 1; for (int i = 0; i < n; ++i) { cin >> s[i]; if (f && s[i].substr(0, 2) == OO ) { f = 0; s[i][0] = + ; s[i][1] = + ; } if (f && s[i].substr(3, 2)...
#include<bits/stdc++.h> using namespace std; #define ll int long long #define mp make_pair //#define for(i,n) for(int i=0;i<n;i++) #define F first #define S second #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define N 1000000007 #define pq priority queue #define pb ...
#include <bits/stdc++.h> using namespace std; int main() { int t, n, counter, a, b, c; cin >> t; while (t--) { cin >> a >> b >> c; counter = 0; while (++counter) { (a < b) ? a += b : b += a; if (max(a, b) > c) break; } cout << counter << endl; } }
#include <bits/stdc++.h> long long query(long long q) { std::printf( ? %lld n , q); std::fflush(stdout); long long res; std::scanf( %lld , &res); return res; } long long qpow(long long a, int b) { long long res = 1; while (b) { if (b & 1) res *= a; b >>= 1, a *= a; } ...
#include <bits/stdc++.h> using namespace std; set<pair<int, int> > ss; struct Node { int l, r, ope; bool operator<(const Node &b) const { if (l != b.l) return l < b.l; return ope > b.ope; } }; Node a[200010]; int num[100010], ans[100010]; int main() { int n, m; scanf( %d , ...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const double eps = 1e-6; const int MOD = 1e9 + 7; const int INF = 0x3f3f3f3f; const long long INFLL = 0x3f3f3f3f3f3f3f3f; const int MAXN = 5e5 + 5; int n, k; struct nodes { int maxn[12], minn[12], siz; bool operator<(c...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 15; int a[N], dp[N][2]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int i = 1; i <= n; i += 1) { cin >> a[i]; } int ans = 0; for (int i = n; i >= 1; i -= 1) { dp[i][0] =...
#include <bits/stdc++.h> using namespace std; const long long N = 100100; const long long Mod = 1e9 + 7; long long Rec(long long i, long long j, long long c); long long p[N]; long long x[N]; vector<long long> Adj[N]; vector<long long> Dp[N][2]; int main() { long long n; cin >> n; for (long...
#include <bits/stdc++.h> using namespace std; int n; string s; map<char, bool> m; int main() { cin >> n >> s; char pl = a ; int sum = 0, sum2 = 0; int len = s.size(); int book = 0; for (int i = 0; i < len / 2; ++i) { if (isalpha(s[i])) { if (!m[s[i]]) { m[s[i]]...
#include <bits/stdc++.h> using namespace std; bool sortcol(const vector<long long int>& v1, const vector<long long int>& v2) { if (v1[0] == v2[0]) return v1[1] < v2[1]; return v1[0] < v2[0]; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n, m; cin >> n >> m...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k; int x1, x2, y1, y2; cin >> n >> m >> k; map<int, vector<pair<int, int> > > cols; map<int, vector<pair<int, int> > > rows; map<int, int> sc; map<int, int> sr; for (int i = 0; i < k; i++) { cin >> x1 >> y1 >>...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; t = 1; while (t--) { long long int n; cin >> n; long long int a[n]; for (int i = 0; i < n; i += 1) cin >>...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int n, q, i, j, l, r; cin >> n >> q; int auxi[n + 2], sum[n + 2]; memset(auxi, 0, sizeof(auxi)); memset(sum, 0, sizeof(sum)); vector<pair<...
#include <bits/stdc++.h> const int MAXN = 2e5 + 10; const int mod = 1e9 + 7; void reduce(int& x) { x += x >> 31 & mod; } int mul(int a, int b) { return (long long)a * b % mod; } int pow(int a, int b, int res = 1) { for (; b; b >>= 1, a = mul(a, a)) if (b & 1) res = mul(res, a); return res; } ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; const int N = 9; const int MAX = 100007; const int H = 1 << 9; int n; int letter[MAX][N]; int dist[N][N]; int ch[MAX]; vector<int> l[N]; bool checked[N]; int mask[MAX]; int cnt[N][H]; void BFS(int x) { vector<int...
#include <bits/stdc++.h> using namespace std; int n, a[200005], cnt = 0; bool vis[200005]; void f(int x) { while (!vis[x]) vis[x] = 1, x = a[x]; } int main() { scanf( %d , &n); for (int i = 1; i <= n; ++i) scanf( %d , a + i); for (int i = 1; i <= n; ++i) if (!vis[i]) { ++cnt; ...
#include <bits/stdc++.h> using namespace std; int main() { int q; cin >> q; for (int i = 0; i < q; i++) { int n; cin >> n; int gnum; while (1) { gnum = n; while (gnum > 0) { if (gnum % 3 == 2) { break; } gnum = gnum / 3; ...
#include <bits/stdc++.h> using namespace std; long long n; long long arr[100005]; int c5; int find(long long a, long long b, long long c) { long long arr[4]; arr[0] = a; arr[1] = b; arr[2] = c; sort(arr, arr + 3); if (arr[0] < arr[1] && arr[1] < arr[2]) return 6; else if (arr...
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; int main() { map<int, int> m, p; int n; cin >> n; for (int i = (1); i <= (n); i++) { int u, v; cin >> u >> v; m[u]++; if (v != u) p[v]++; } int ans = 1e9; if (n % 2) n++; for (auto i : m)...
#include <bits/stdc++.h> using namespace std; const long long prime = 1e9 + 7; const long long maxN = 1e5 + 5; const long double pi = 3.1415926536; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, k, a, rem = 1e18, t = 1, b = 0; cin >> n >> k; for (long long i = (...
#include <bits/stdc++.h> using namespace std; vector<long long> v[3000]; long long h[200000], pw[200000]; string st, st1, st2; long l1, l2, l, ans, fl, g1[20000], g2[20000]; long long gethash(long a, long b) { return (h[b + 1] - h[a]) * pw[st.size() - b + 1]; } int main() { cin >> st; cin >>...
#include <bits/stdc++.h> using namespace std; int cnt_9s(long long int num); long long int power(int num, int exp); int main() { long long int num, sale, rem; cin >> num >> sale; while (1) { rem = power(10, cnt_9s(num) + 1); if (sale >= num % rem + 1) sale -= (num % rem + 1), num...
#include <bits/stdc++.h> using namespace std; char a[100100]; int main() { scanf( %s , a); int en; int len = strlen(a); int r = 0, l = 0; int ll, rr; int flag = 0; int last; int cnt = 0; for (int i = 0; a[i] != 0 ; i++) if (a[i] == # ) en = i; for (int i = 0; i < l...
#include <bits/stdc++.h> using namespace std; const int MAX = 300010; int n; int maxx; int node[2 * MAX][30]; int cau[MAX]; int site; int other; void in() { scanf( %d , &n); int a, b; char c; for (int i = 1; i < n; i++) { scanf( %d %d %c , &a, &b, &c), node[a][c - a ] = b; }...
#include <bits/stdc++.h> using namespace std; class IO { static const int bufSize = 1 << 18; char inBuf[bufSize], outBuf[bufSize]; char *ip1 = inBuf, *ip2 = inBuf; int goodReadBit = 0, op1 = -1, op2 = bufSize - 1; template <typename T> __inline__ __attribute__((always_inline)) void __RI(T& x...
#include <bits/stdc++.h> using namespace std; const int tmw168 = 1e5; long long a, b, p, q, invp; long long gcd(long long x, long long y) { if (y == 0) return x; return gcd(y, x % y); } long long test(long long r) { r = r * invp % q; r += a / q * q; if (r < a) r += q; return r; } ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int n, pos; string s; cin >> n >> s; bool flag = false; for (int i = 1; i < n; i++) { if (s[i] == s[i - 1]) continue; else { flag = true; pos = i; break; ...
#include <bits/stdc++.h> using namespace std; const int Z = 3 * (int)1e3 + 111; const int N = 3 * (int)1e5 + 111; const int INF = (int)1e9 + 111; const int MOD = (int)1e9 + 7; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; double l, d, v, g, r; cin >> l >> ...
#include <bits/stdc++.h> using namespace std; int N, ANS, X[201], Y[201]; char S[205]; int main() { scanf( %d %s , &N, S); for (int i = 0; i < N; i++) { X[i + 1] += X[i], Y[i + 1] += Y[i]; char c = S[i]; if (c == U ) Y[i + 1]++; if (c == R ) X[i + 1]++; if (c == D ) Y[i ...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const double EPS = 1e-9; const int N = (1 << 15); const int OO = 200000; struct edge { int from, to, w; edge(int from, int to, int w) : from(from), to(to), w(w) {} bool operator<(const edge& e) const { return w < e.w; } ...
#include <bits/stdc++.h> using namespace std; long long n, k, x, y, z, A[(1 << 17)], B[(1 << 17)], C[(1 << 17)], mmp[(1 << 17)], Comb[18][18]; long long O[(1 << 17)], Ans[4][(1 << 17)]; long long powmod(long long x, long long y = 998244353 - 2, long long p = 998244353) { x %= p; ...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int flag = 0; int count = 0; if (isupper(s[0])) { flag = 1; count = 1; } for (int i = 1; i < s.length(); i++) { if (isupper(s[i])) count++; } if (count == s.length()) { for (int...
#include <bits/stdc++.h> using namespace std; int ans[7], flag; int a[1005], n; int pos[4][30], pn[4]; struct Pair { int l, r; } p[4][300]; int pai[4]; stack<int> s; bool check() { for (int i = 1; i <= n; i++) { if (a[i] != i) return false; } return true; } void find_pos(int ...
#include <bits/stdc++.h> using namespace std; int n, k, dp[103][10003], C[103][103]; long long m; int Plus(int x, int y) { return (x += y) >= 1000000007 ? x % 1000000007 : x; } int mul(long long x, int y) { return (x *= y) >= 1000000007 ? x % 1000000007 : x; } int qpow(int x, long long y) { int an...
#include <bits/stdc++.h> using namespace std; int n, x, y, m, nr, nr1, st, dr, i, j, z, p1, p2, aux, a[1004], b[1004], s[1004], d[1004]; bool ok, c[1004]; int main() { scanf( %d %d %d , &n, &x, &y); ok = true; y = 1; s[1] = 1; d[1] = n; while (ok == true) { nr1 = 0; nr ...
#include <bits/stdc++.h> using namespace std; template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template <typename A, ...
#include <bits/stdc++.h> using namespace std; inline void prin(int n) { printf( %d n , n); } int main() { int n; cin >> n; long long cur = 3, mi = 7; for (int i = 1; i < 3 * n; i++) { cur *= 3; cur %= (int)1e9 + 7; } for (int i = 1; i < n; i++) { mi *= 7; mi %= (int...
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> string print_iterable(T1 begin_iter, T2 end_iter, int counter) { bool done_something = false; stringstream res; res << [ ; for (; begin_iter != end_iter and counter; ++begin_iter) { done_something = true; ...
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, i, j, k, c = 0, sm = 0, t = 0, ans = 0; cin >> n >> m; int a[n + 2], b[n + 2]; for (i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < n; i++) { sm += a[i]; if (sm > m) { sm -= a[t]; ++t; } ...
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize( Ofast,no-stack-protector ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) #pragma GCC optimize( unroll-loops ) template <class T1, class T2, class T3> inline T3 bigMod(T1 b, T2 p, T3 M) { if (!p) return 1;...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; map<char, int> m; vector<int> v; for (int i = 0; i < s.size(); i++) { m[s[i]]++; } map<char, int>::iterator it = m.begin(); while (it != m.end()) { v.push_back((*it).second); it++; } ...
#include <bits/stdc++.h> using namespace std; int n, m; int a[1 << 20]; int main() { scanf( %d%d , &n, &m); map<int, int> p; for (int i = 1; i <= n; i++) { int fi; scanf( %d , &fi); if (p.count(fi)) { p[fi] = 0; } else { p[fi] = i; } } bool im = ...
#include <bits/stdc++.h> using namespace std; long long qpow(int a, int n, int modulus) { int ret = 1; while (n) { if (n & 1) ret = ret * a % modulus; a = a * a % modulus; n >>= 1; } return ret; } int main() { int n; scanf( %d , &n); if (n < 3) puts( -1 ); ...
// God put a smile upon your face <3 #include <bits/stdc++.h> #define slld(longvalue) scanf( %lld , &longvalue) #define ll long long #define ull unsigned long long #define pll pair < long long, long long > #define fastio ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0) #define pb ...
#include <bits/stdc++.h> using namespace std; int n, x, y, nr; int a[110], b[110]; bool used[110]; int main() { cin >> n; cin >> x; for (int i = 1; i <= x; ++i) { cin >> nr; used[nr] = true; } cin >> y; for (int i = 1; i <= y; ++i) { cin >> nr; used[nr] = true; ...
#include <bits/stdc++.h> using namespace std; string s[105]; int main() { int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) { s[i] = Aa ; s[i][0] += i / 26; s[i][1] += i % 26; } for (int i = 1; i <= n - k + 1; i++) { string x; cin >> x; if (x == NO ) s...
#include <bits/stdc++.h> using namespace std; const int mxn = 1e6 + 6; int n, r, c, t = 1, fr[mxn], nxt[mxn], ans[mxn]; char s[6 * mxn]; inline void dfs(int x) { if (!x) return; dfs(x >> 1); for (int i = 1; i <= n; ++i) { ans[i] = ans[ans[i]]; if (x & 1) ans[i] = nxt[ans[i]]; } }...
#include <bits/stdc++.h> using namespace std; bool check(string s) { for (int i = 0; i < s.size() - 1; i++) { if (s[i] == s[i + 1] && s[i] == 1 ) { return false; } } return true; } int main() { int n; cin >> n; string v; cin >> v; int flag = 0, f = 1; if ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); string s1, s2; cin >> s1 >> s2; long long i, n = s1.size(), k1 = 0, k2 = 0, flag = 0, cnt = 0; for (i = 0; i < n; i++) { if (s1[i] == 4 && s2[i] == 7 ) ...
#include <bits/stdc++.h> using namespace std; unsigned long long i, n, k, a[100001], b[100001]; unsigned long long solve(unsigned long long val) { unsigned long long cnt = 0; for (i = 0; i < n; i++) { if (a[i] * val > b[i]) cnt += val * a[i] - b[i]; } if (cnt > k) return 0; return 1; }...
#include <bits/stdc++.h> using namespace std; const int maxn = 7e3 + 11; int n; vector<int> s[2]; const int loose = 0; const int win = 1; bool vis[2][maxn][2]; int deg[maxn][2]; int32_t main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n; for (int k, i = 0; i < 2; i++)...
#include <bits/stdc++.h> using namespace std; const long long N = 505, M = 1e9 + 7; long long K, m, n, a[N], H[N], num[N], F[N], G[N], x, ans[N], C[N]; inline long long ksm(long long x, long long y) { long long ans = 1; for (; y; y >>= 1, x = x * x % M) if (y & 1) (ans *= x) %= M; return ans; ...
#include<bits/stdc++.h> #define maxn 1000000 using namespace std; int n,d; int a[maxn]; long long prod[10]; long long nprod[10]; long long inf=1e15; vector<int> ans[10]; vector<int> nans[10]; bool tk[maxn]; int inv[10]; int mp[10]; int omp[10]; int main() { scanf( %d %d ,&n,&d); ...
#include <bits/stdc++.h> using namespace std; void marmot0814() { int n; cin >> n; int p1 = 1, p2 = 2, p3 = 3; while (n--) { int v; cin >> v; if (v == p3) { cout << NO n ; return; } else if (v == p1) { swap(p2, p3); } else { swap(p1, p3)...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 100; const int mod = 998244353; void MOD(long long &x) { if (x >= mod) x -= mod; } struct Tree { long long mul[maxn << 2], add[maxn << 2], sum[maxn << 2]; void push(int l, int r, int rt) { if (mul[rt] != 1) { sum[...
#include <bits/stdc++.h> long long res; int max; const int N = 205; int f[N], tt[N], cnt, next[N]; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } void dfs(int u) { cnt++; f[u] =...
#include <bits/stdc++.h> using namespace std; double ppow(double a, int b) { if (b == 1) return a; if (b == 0) return 1; double y = ppow(a, b / 2); y = y * y; if (b % 2 == 1) y = y * a; return y; } int main() { int n, m, i; double s = 1, ans = 0, c = 0, x; scanf( %d%d , &n, &...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 5500; int n, T; double p[MAX_N]; int t[MAX_N]; double dq[MAX_N]; int main() { scanf( %d%d , &n, &T); for (int i = 0; i < n; i++) { scanf( %lf%d , &p[i], &t[i]); p[i] /= 100; } vector<double> cur(T + 1), nxt(T + 1);...
#include <bits/stdc++.h> using namespace ::std; const long double PI = acos(-1); const long long MOD = 1000000000 + 7; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } long long add(long long a, long long b, long long m = MOD) { return (a % m + b % m + 2 * m) % m; } long ...
#include <bits/stdc++.h> using namespace std; template <class T> T sqr(T x) { return x * x; } template <class T> T distsqr(T x, T y, T a, T b) { return sqr(x - a) + sqr(y - b); } double cosine_angle(double a, double b, double c) { return (double)(sqr(a) + sqr(b) - sqr(c)) / ((double)2.0 * a ...
#include <bits/stdc++.h> const int N = 1e3 + 5; using namespace std; int main() { ios::sync_with_stdio(false); int arr[N][N], str, sve, k, n[N], m[N], i, j, x, y; char ch; cin >> str >> sve >> k; for (i = 1; i <= str; i++) for (j = 1; j <= sve; j++) cin >> arr[i][j]; for (i = 1; i <=...
#include <bits/stdc++.h> using namespace std; int main() { int n, l; cin >> n >> l; vector<int> a(n); vector<int> b(n); for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 0; i < n; ++i) cin >> b[i]; vector<int> c(n); for (int zsuv = 0; zsuv < l; ++zsuv) { for (int i = 0; i <...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1); int main() { ios::sync_with_stdio(false); int m, n, k; while (cin >> m >> n >> k) { k *= 2; if (m >= k && n >= k) { cout << First << endl; } else { cout << Second << endl; } } ...
#include <bits/stdc++.h> using namespace std; vector<pair<long long, long long>> g[111111]; long long d[111111]; set<long long> t[111111]; int main() { int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) { d[i] = 1e13; } for (int i = 1; i <= m; i++) { long long a, b, cost; ...
#include <bits/stdc++.h> using namespace std; int main() { int a1, a2, a3, a4; cin >> a1 >> a2 >> a3 >> a4; int a[4]; a[0] = a1; a[1] = a2; a[2] = a3; a[3] = a4; sort(a, a + 4); if (a[0] + a[1] + a[2] == a[3]) { cout << YES ; } else if (a[0] + a[3] == a[1] + a[2]) { ...
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { 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; int main() { unsigned long long ans = 1e18, n, k; cin >> n >> k; vector<unsigned long long> v; for (unsigned long long i = 1; i <= n; i++) if (n % i == 0) v.push_back(i); for (unsigned long long x : v) if (x < k) ans = min(ans, (n / x) * ...
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 5; int n, v, e; bool bo[N][N], vis[N]; vector<int> path[N][N]; int a[N], b[N]; vector<int> G[N]; long long A, B; void dfs(int x) { A += a[x]; B += b[x]; vis[x] = 1; for (int i = 0; i < G[x].size(); i++) { int u = G...