func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> const int N = 1050000; const double pi = acos(-1.0); int a[N], ans[N], rev[N << 1]; std::complex<double> b[N << 1]; void FFT(std::complex<double> *a, int n, int f) { for (int i = 0; i < n; i++) if (i < rev[i]) std::swap(a[i], a[rev[i]]); for (int i = 1; i < n; i <<= 1) {...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; vector<int> a(n); vector<long long> pf(n); for (int i = 0; i < n; i++) { cin >> a[i]; pf[i] = a[i]; if (i) pf[i] += pf[i - 1]; }...
#include <bits/stdc++.h> using namespace std; const int P = 1e9 + 7; int add(int a, int b) { if ((a += b) >= P) a -= P; return a < 0 ? a + P : a; } int mul(int a, int b) { return 1ll * a * b % P; } int kpow(int a, int b) { int r = 1; for (; b; b >>= 1, a = mul(a, a)) { if (b & 1) r = m...
#include <bits/stdc++.h> using namespace std; #define endl n typedef long long int lli; #define __ ios_base::sync_with_stdio(false);cin.tie(NULL); int main(){__ int t= 1,n; cin>>t; while(t--){ string s; cin>>s; n = s.size(); bool flag = true; ...
#include <bits/stdc++.h> using namespace std; int main() { string s, t; long long n; cin >> n; cin >> s; cin >> t; sort(s.begin(), s.end()); sort(t.begin(), t.end()); long long cnt = 0; long long i = 0; long long j = 0; while (i < n && j < n) { if (s[i] <= t[j]) { ...
#include <bits/stdc++.h> using namespace std; string months[] = { January , February , March , April , May , June , July , August , September , October , November , December }; int main() { string x; int k; cin >> x >> k; int...
#include <bits/stdc++.h> using namespace std; int n, k, i, j, x, lg[1 << 20], f1[1 << 20], f2[1 << 20], ans, n1, n2, a; long long e[42]; bool g[1 << 20]; int main() { scanf( %d%d , &n, &k); for (i = 0; i < n; i++) for (j = 0; j < n; j++) { scanf( %d , &x); if (x) e[i] |= 1ll << j...
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &x) { x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == - ) f = 1; for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); if (f) x = -x; } template <typename F> i...
#include <bits/stdc++.h> using namespace std; using LL = long long; const int MOD = 998244353; int f[1002][1000]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; vector<int> x(n); for (int i = 0; i < n; ++i) cin >> x[i]; sort(x.begin(), x.end()); ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; vector<pair<int, int> > v, r; cin >> n >> m; for (int a = 0, b; a < n; a++) { cin >> b; v.push_back(make_pair(b, a)); } sort(v.begin(), v.end()); for (int a = 0; a < n; a++) r.push_back(make_pair(v[a].second...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int t; cin >> t; while (t) { t--; long long int n, k; cin >> n >> k; long long int a[k]; map<long long int, long long int> m; for (int i = 0; ...
#include <bits/stdc++.h> using namespace std; int n; int main() { while (~scanf( %d , &n)) { printf( %d n , (n - 1) / 2); } return 0; }
#include <bits/stdc++.h> using namespace std; int test = 0; const int MAXN = 300009; const long long MOD = 119 << 23 | 1; class { public: vector<int> V[MAXN]; int fa[MAXN * 2], cnt[MAXN * 2]; int n, m; int curset[MAXN * 2], ans; int findfa(int x) { if (fa[x] == x) return x; ...
#include <bits/stdc++.h> using namespace std; int main() { unsigned long long a, b, x, y; cin >> a >> b; x = (a - b) / 2; y = x + b; if ((x > y) || (x + y != a) || (x ^ y) != b) cout << -1 << endl; else cout << x << << y << endl; return 0; }
#include <bits/stdc++.h> using namespace std; vector<pair<int, pair<char, string>>> vec; int main() { unsigned long long int n, i, j, n1, cnt = 0; cin >> n; string s; char r; for (i = 1; i <= n; i++) { cin >> s; n1 = s.size(); cnt = 0; for (j = 0; j < n1; j++) { ...
#include <bits/stdc++.h> using namespace std; const int N = 153, M = 1e5 + 7; int n, m, K, ed; char s[M]; bitset<N * N> wall, now, can; int main() { scanf( %d%d%d , &n, &m, &K); for (int i = 1; i <= n; i++) { scanf( %s , s + 1); for (int j = 1; j <= m; j++) { if (s[j] == # ) ...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; using vi = vector<int>; const int Z = int(1e5 + 1); const int inf = int(2e9 + 1); const ll llinf = ll(2e18 + 1); const ll mod = ll(1e9 + 7); int main() { ios_base::sync_with_st...
#include <bits/stdc++.h> using namespace std; const int oo = 0x3f3f3f3f; const double EPS = 1e-9; const int MAXN = (int)1e5 + 10; const long long MOD = (long long)1e9 + 7; long long TEN_POW[MAXN]; long long MOD_INV[MAXN]; long long FACT[MAXN]; long long INV_FACT[MAXN]; long long ACC[MAXN]; long lo...
#include <bits/stdc++.h> const int inf = 0x3f3f3f3f, Inf = 0x7fffffff; const long long INF = 0x7fffffffffffffff; const double eps = 1e-10; unsigned int seed = 19260817; const unsigned int _RAND_MAX_ = 4294967295u; __inline__ __attribute__((always_inline)) unsigned int Rand() { return seed = seed * 99824...
#include <bits/stdc++.h> using namespace std; const int maxn = 2050; const int inf = 0x3f3f3f3f; const int mod = 998244353; long long fpow(long long x, long long y) { long long ans = 1; while (y) { if (y & 1) ans = ans * x % mod; x = x * x % mod; y >>= 1; } return ans; } ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; long long a[N], b[1050], c[N]; int cnt = 0; void init() { cnt = 0; for (int i = 1; i < N - 50; i++) a[cnt++] = i * i; cnt = 0; for (int i = 1; i < 1010; i++) b[cnt++] = i * i * i; int u = 0, t = 0; cnt = 0; while...
#include <bits/stdc++.h> using namespace std; void print(vector<long long> &a) { for (int i = 0; i < a.size(); i++) cout << a[i] << n [i == a.size() - 1]; } void print(vector<int> &a) { for (int i = 0; i < a.size(); i++) cout << a[i] << n [i == a.size() - 1]; } void print(int a[], int l, int r...
#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 = acos((long double)-1); const long double EPS = 1e-9; long long gcd(long long a, long long b) { long long r; while (b) { r = a %...
#include<bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--) { long long n, m; cin>>n>>m; long k[n], c[m]; for(long i=0;i<n;i++) cin>>k[i]; sort(k,k+n,[](long& a,long& b){ return a>b; }); for(long i=0;i<m;i++) cin>>c[i]; long long p = 0; ...
#include <bits/stdc++.h> using namespace std; long long int a[100005], sg[100005 * 4], lz[100005 * 4], res, x, y, z, n; void lazy(long long int low, long long int high, long long int pos) { sg[pos] += lz[pos]; if (low != high) lz[pos * 2 + 1] += lz[pos], lz[pos * 2 + 2] += lz[pos]; lz[pos] = 0; } ...
#include <bits/stdc++.h> using namespace std; const long long inf = 12345678987654321ll; long long dp[3000]; int n; int main() { cin >> n; int t, c; for (int i = 1; i <= n; i++) dp[i] = inf; for (int i = 1; i <= n; i++) { cin >> t >> c; ++t; for (int i = n + t; i > n; i--) { ...
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, /STACK:102400000,102400000 ) const int maxn = 1e5 + 300; const int INF = 0x3f3f3f3f; int main() { int k; scanf( %d , &k); if (k == 1) { puts( YES n2 1 n1 2 ); } else if (k % 2 == 0) { puts( NO ); } else { ...
#include <bits/stdc++.h> using namespace std; int main() { int n, res = 0, i, t; vector<string> v; cin >> n; for (i = 0; i < n; i++) { string s; cin >> s; v.push_back(s); } for (int j = 0; j < 7; j++) { t = 0; for (i = 0; i < n; i++) { if (v[i][j] == 1 ...
#include <bits/stdc++.h> using namespace std; const long double EPS = 1E-9; const int INF = (int)1E9; const long long INF64 = (long long)1E18; const long double PI = 2 * acos(.0); long long dp[10][10][2]; vector<int> number; int pivot = 1; long long solve(int pos, bool is_bounded, int lucky_digits) { ...
#include <bits/stdc++.h> using namespace std; void run_case() { long long n; cin >> n; vector<long long> a(n, 0); for (long long i = 0; i < n; i++) cin >> a[i]; long long mini[n]; mini[n - 1] = a[n - 1]; for (long long i = n - 2; i >= 0; i--) { mini[i] = min(mini[i + 1], a[i]); ...
#include <bits/stdc++.h> using namespace std; long long i, j, k, n, m, x, y, T, ans, mx, mi, cas, num, len; bool flag; long long a[105]; const int mod = 1000000007; typedef struct matrixnod { long long m[105][105]; } matrix; matrix mat(matrix a, matrix b) { matrix c; for (long long i = 0; i ...
#include <bits/stdc++.h> using namespace std; bool v[5050]; int main() { ios::sync_with_stdio(0); int n; cin >> n; int x[n]; set<int> st; int r = 0; for (int i = 0; i < n; i++) { cin >> x[i]; if (x[i] > n) r++; else { st.insert(x[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; int a[200010], c[200010]; int main() { int n, t, k; scanf( %d%d%d , &n, &t, &k); for (int i = 1; i <= t; i++) scanf( %d , &a[i]); a[0] = (k > n - t ? 2 : 1); for (int i = 0; i <= t; i++) { c[i] = min(a[i], a[i + 1]); k -= a[i] - c[i]; ...
#include <bits/stdc++.h> int colour[100001]; int main() { int n, m; scanf( %d %d , &n, &m); int vect1[n], vect2[n], vect3[n]; for (int i = 0; i < m; i++) { scanf( %d %d %d , &vect1[i], &vect2[i], &vect3[i]); } int white = 1, red = 1, blue = 1; for (int i = 0; i < m; i++) { wh...
#include <bits/stdc++.h> using namespace std; int n, m, k, w; char ax[500005]; char bx[500005]; int Next[500005], next2[500005]; int sig[500005][2]; int hh[500005][2]; bool tepan() { int i, j, a, b; for (i = 1; i <= n; i++) { if (sig[i][0] == m) { w = max(1, i - k + 1); w =...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 2; int ar[N], ar1[N]; signed main() { ios::sync_with_stdio(0); cin.tie(0); int n, i, j, k, l, r; long long sum; cin >> n >> sum; if (sum < 1ll * n * (n + 1) / 2) { cout << -1; return 0; } for (i = 1; i ...
#include <bits/stdc++.h> using namespace std; bool mark[10][10][10][10]; int n, ans; int main() { memset(mark, false, sizeof(mark)); scanf( %d , &n); while (n--) { string x, y, z; if (n == 0) { cin >> x; cin >> y; } else { cin >> x; cin >> y; ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; int N; vector<int> adj[200001]; vector<int> L[200001]; vector<int> R[200001]; int dp[200001]; int ans[200001]; inline void addmod(int& x, int v) { x += v; if (x >= MOD) x -= MOD; } void dfs(int u, int p) { for (a...
#include <bits/stdc++.h> using namespace std; string str; int cnt1, cnt2; int main() { cin >> str; for (int i = 0; i < str.size(); i++) str[i] == o ? cnt1++ : cnt2++; puts(cnt1 == 0 || cnt2 % cnt1 == 0 ? YES : NO ); return 0; }
#include <bits/stdc++.h> int main() { int a, b, h = 0, r = 0; scanf( %d %d , &a, &b); while (a > 0) { h += a; r += a % b; a = a / b; while (r >= b) { a++; r -= b; } } printf( %d n , h); }
#include <bits/stdc++.h> using namespace std; template <typename T> void out(T x) { cout << x << endl; exit(0); } const long long mod = 1e9 + 7; const int maxn = 1e6 + 5; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int n, start, x; int ans = 1e9 + 10; int beforeVal =...
#include <bits/stdc++.h> using namespace std; long long M = 1000000007; signed main() { long long t; cin >> t; for (long long u = 0; u < t; u++) { long long k = 0; vector<long long> v; string s; cin >> s; for (long long i = 0; i < s.size(); i++) { if (i + 4 < s.si...
#include <bits/stdc++.h> using namespace std; int main() { long int quant, mul; scanf( %ld %ld , &quant, &mul); long int *nums = (long int *)calloc(quant, sizeof(long int)); set<long int> s; for (long int i = 0; i < quant; i++) { scanf( %ld , &nums[i]); } sort(nums, nums + quant); ...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1e5 + 1; int main() { { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int t; cin >> t; while (t--) { int n, m, k; cin >> n >> m >> k; priority_queue<pair<int, int>> pq; for (int...
#include <bits/stdc++.h> using namespace std; pair<int, int> a[107][107]; int b[107][107]; int main() { int m, p; scanf( %d %d , &m, &p); int i, j; for (i = 1; i <= m; i++) for (j = 1; j <= p; j++) a[i][j].first = i, a[i][j].second = j; int q; scanf( %d , &q); while (q--) { ...
#include <bits/stdc++.h> inline int sbt(int x) { return __builtin_popcount(x); } using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cout << name << : << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Arg...
#include <bits/stdc++.h> using namespace std; struct S { long long t, w; } s[300009]; bool comp(S a, S b) { return a.t > b.t; } int main() { int n; scanf( %d , &n); n--; long long c, tmp; scanf( %lld %lld , &c, &tmp); for (int i = 0; i < n; i++) { scanf( %lld %lld , &s[i].t, ...
#include <bits/stdc++.h> using namespace std; int vis[200003], nd, lm, fl, bad[200003]; vector<int> g[200003]; int expo(int y) { long long x = 2ll, res = 1ll; while (y) { if (y & 1) { res = (res * x); if (res >= 1000000007) res %= 1000000007; } y >>= 1; x *= x; ...
#include <bits/stdc++.h> int deg[25]; double g[25][25]; double p[510][510]; int main() { int n, m, a, b; scanf( %d%d%d%d , &n, &m, &a, &b); a--; b--; int s = n * n; int x, y; for (int i = 0; i < m; i++) { scanf( %d%d , &x, &y); x--; y--; deg[x]++; deg[y]...
#include <bits/stdc++.h> using namespace std; int A[2005][2005]; int N, P[2005]; const int MOD = 998244353; int DP[2005][2005]; bool FreeIn[2005], FreeOut[2005]; int Arb[2][2005], Fact[2005]; int Power[2005]; inline long long norm(long long x) { return x >= MOD ? x - MOD : x; } void precalcPower() {...
#include <bits/stdc++.h> using namespace std; const int INF = std::numeric_limits<int>::max(); struct Cmp { Cmp(const vector<deque<int>>& cont) : cont_(&cont) {} bool operator()(int i, int j) const { do { if (!(!cont_->at(i).empty())) { std::cerr << empty deque << std::endl; ...
#include <bits/stdc++.h> using namespace std; int n; int a[100005]; int tmp[100005]; int sl = 0; int dp[100005]; int zs = 0; int sz[1200005]; int dd[100005]; int cl[100005]; vector<int> g[100005]; int sol() { zs = 0; for (int i = 1; i <= sl; ++i) { int u = tmp[i]; for (auto &...
#include <bits/stdc++.h> using namespace std; const int N = 100005; long long cnt[N]; int main() { long long n, k; cin >> n >> k; long long sum = 0, right = 0, left = 0; for (int i = 0; i < n; i++) { cin >> cnt[i]; sum += cnt[i]; right = max(right, cnt[i]); } if (sum ==...
#include <bits/stdc++.h> using namespace std; int n; long long a, b, w, x; int main() { while (scanf( %d , &n) != EOF) { cin >> a >> b; for (int i = 1; i <= n; i++) { scanf( %I64d , &w); x = w * a / b; x = x * b; printf( %I64d%c , (w * a - x) / a, n [i == n]); ...
#include <bits/stdc++.h> using namespace std; int main(int argc, char const* argv[]) { string a, inp, min; int n, i, l; cin >> a >> n; l = a.size(); min = ; while (n--) { cin >> inp; for (i = 0; i < l; i++) if (inp[i] != a[i]) break; if (i == l && (inp < min || mi...
#include <bits/stdc++.h> using namespace std; char rd; int sig; template <class T> inline void read(T &a) { for (a = 0, rd = getchar(); ( 0 > rd || rd > 9 ) && rd != - ; rd = getchar()) ; for (rd == - ? sig = -1, rd = getchar() : sig = 1; 0 <= rd && rd <= 9 ;) a *= 10, a +...
#include <bits/stdc++.h> using namespace std; int main() { map<string, int> mp; vector<string> vec; string s; int n, m, v; double k; cin >> n >> m >> k; for (int i = 0; i < n; i++) { cin >> s >> v; if (v >= 100) { mp[s] = k * v + 1e-9; if (mp[s] >= 100) ...
#include <bits/stdc++.h> int main() { int n; long long x; scanf( %d , &n); x = (n - 2); x = x * x; printf( %I64d , x); return 0; }
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &x) { x = 0; char c = getchar(); bool p = 0; for (; c < 0 || c > 9 ; c = getchar()) if (c == - ) p = 1; for (; c >= 0 && c <= 9 ; c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48); if (p) x =...
#include <bits/stdc++.h> using namespace std; int n, m; char s[1100][1100]; bool a[1100][1010]; bool canDraw(int x, int y, int level) { int i = level; { if (x + i < 0 || x + i >= n) return false; if (y + i < 0 || y + i >= m) return false; if (s[x + i][y] == . ) return false; i...
#include <bits/stdc++.h> using namespace std; using int64 = long long int; const int kModulo = 1000000007; struct Edge { int from, to; }; vector<int> Inverse(const vector<int>& a) { const int n = a.size(); vector<int> result(n); for (int i = 0; i < n; ++i) { result[a[i] - 1] = i; }...
#include <bits/stdc++.h> using namespace std; const int N = 60 + 7; const int INF = (int)1e9; int n; int m; int q; int dp[N][N][N]; int one[N][N][N]; int main() { ios::sync_with_stdio(0); cin.tie(0); for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) for (int k = 0; k < ...
#include <bits/stdc++.h> using namespace std; int a[110]; int dp[110][110]; map<int, int> mp; bool cmp(int p, int q) { return p > q; } int main() { int n, m; while (scanf( %d%d , &n, &m) == 2) { memset(a, 0, sizeof(a)); memset(dp, 0, sizeof(dp)); int u; int b = -1; for ...
#include <bits/stdc++.h> int main() { int n; scanf( %d , &n); int x, i = 1; while (i <= n) { scanf( %d , &x); printf( n%d %d , 1, x - 1); i++; } }
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; const int maxn = 1010; int n, K, mxa; int a[maxn]; inline int MOD(int x) { return x < mod ? x : x - mod; } inline int Mod(int x) { return x < 0 ? x + mod : x; } void input() { int i; scanf( %d%d , &n, &K); for (i = 1; i...
#include <bits/stdc++.h> using namespace std; const int MAXN = 105; const int mod = 1e9 + 7; vector<int> e[MAXN]; int n, sz[MAXN], f[MAXN][MAXN][2], tmp[MAXN][2], c[MAXN][MAXN]; inline int add(int x, int y) { return x + y >= mod ? x + y - mod : x + y; } inline void inc(int &x, int y) { x = x + y >= mod ? ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:64000000 ) using namespace std; const long double PI = 3.14159265358979323846; const long double gammama = 0.57721566490153286060; const long double eps = 1e-8; const long long INF = 777777777777 + 1; vector<int> a(10, 0); int pow(int x, int st) {...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t--) { int n, l; cin >> n >> l; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } int il = 0, ir = n - 1...
#include <bits/stdc++.h> #include<string> #include<vector> using namespace std; //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> //using namespace __gnu_pbds; //typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> o_set; typedef...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; inline long long mul(long long a, long long b) { return (mod + (a * b) % mod) % mod; } inline long long add(long long a, long long b) { return (mod + (a + b) % mod) % mod; } long long pwr(long long a, long long b) { i...
#include <bits/stdc++.h> using namespace std; vector<int> V[20005]; int a[1000005], b[1000005]; bool cmp1(int x, int y) { return b[x] < b[y]; } bool cmp2(int x, int y) { return b[x] > b[y]; } int main() { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d , &a[i]), scanf( %d ...
#include <bits/stdc++.h> using namespace std; int l, r; string s; bool b_occured[10]; bool judge() { memset(b_occured, 0, sizeof(b_occured)); bool ret = false; for (int i = 0; i < s.length(); i++) { if (b_occured[s[i] - 0 ] == false) b_occured[s[i] - 0 ] = true; else { ...
#include <bits/stdc++.h> using namespace std; int a[100000]; void solve() { int i, j, n; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; bool ok = 0; for (int i = 2; i <= n; i++) if (a[i] != a[i - 1]) ok = 1; if (!ok) { cout << NO << n ; return; } ...
#include <bits/stdc++.h> using namespace std; template <typename T> inline void Read(T &n) { char ch; bool flag = false; while (!isdigit(ch = getchar())) if (ch == - ) flag = true; for (n = ch ^ 48; isdigit(ch = getchar()); n = (n << 1) + (n << 3) + (ch ^ 48)) ; if (flag)...
#include <bits/stdc++.h> using namespace std; int main() { long int n; cin >> n; vector<pair<long int, long int> > vec; for (long int i = 1; i <= n; i++) { long int a, b; cin >> a >> b; vec.push_back({a, b}); } long int count = 1; long int limit = vec[0].first; for ...
#include <bits/stdc++.h> template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } using namespace std; const double eps = 1e-...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; void add(int& x, int y) { ((x += y) >= MOD) && (x -= MOD); } void sub(int& x, int y) { add(x, -y + MOD); } int mul(int x, int y) { return x * 1ll * y % MOD; } int mpow(int a, int p) { int res = 1; for (; p > 0; p >>= 1, a = mul(a...
#include <bits/stdc++.h> using namespace std; long long int parent[26]; long long int find(long long int x) { if (x == parent[x]) return x; return parent[x] = find(parent[x]); } void merge(long long int x, long long int y) { parent[y] = x; } signed main() { long long int n; cin >> n; for...
#include <bits/stdc++.h> using namespace std; vector<int> adj[200010], adjr[200010]; int dist[200010], n, m, nop[200010], minp, maxp; void BFS(int scr) { queue<int> q; q.push(scr); dist[scr] = 1; nop[scr] = 0; while (!q.empty()) { int u = q.front(); q.pop(); for (long long ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; const long long mod = 1e9 + 7; int n, c[505], d[505][505], fa[505], a[505]; long long dp[505][505], comb[505][505]; int Find(int x) { return x == fa[x] ? x : fa[x] = Find(fa[x]); } void Union(int u, int v) { int x = Find(u); i...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } const int MAXK = 30000; const int LGN = 16; const int N = 1 << LGN; const int MOD = 1000000007; const double MYPI = acos(-1); typedef struct Pol { int x[MAXK + 1]; } Pol; ...
#include <bits/stdc++.h> using namespace std; const int N = 50 + 5; int n, a[N][N], tot; int main() { cin >> n; int i = 0, j = n / 2, x, y; for (int k = 1; k <= n * n; k++) { if (a[i][j]) { i = (x + 1) % n; j = y; } a[i][j] = k; x = i; y = j; i = (...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int x, y, a, b; cin >> x >> y >> a >> b; if ((y - x) % (a + b) != 0) { cout << -1 << endl; } else { cout << (y - x) / (a + b) << endl; } } }
#include <bits/stdc++.h> using namespace std; int mod = 1000000007; inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } inline long long toll(string s) { long long v; istringstream sin(s); sin >> v; return v; } template <class T> inline string ...
#include <bits/stdc++.h> using namespace std; const long double pi = 3.14159265359; const int N = 1e5 + 5; const int MOD = 1e9 + 7; int c[N]; vector<int> ans; vector<int> g[N]; int main() { ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); ; int n; cin >> n; int r, p; ...
#include <bits/stdc++.h> using namespace std; #define erorp(x) cout<<#x<< ={ <<(x.F)<< , <<x.S<< } <<endl; #define print(v,r) f(i,0,r) cout<<v[i]<< ; cout<<endl; #define Get(x,y) scanf( %I64d%I64d ,&x,&y); #define is_bit(x,y) (x%(1<<(y+1))>=(1<<y)) #define eror(x) cout<<#x<< = <<(x)<<endl; #define f_(...
#include <bits/stdc++.h> using namespace std; const int size = 1e5 + 7; long long a[size], ans = 2e9, res, val, n, k, i; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; for (i = 0; i < n; i++) { cin >> a[i]; if (!i) val = a[i] % k; ...
#include <bits/stdc++.h> using namespace std; int gcd(int a, int(b)) { if (b == 0) return a; return gcd(b, a % b); } int main() { long long int n; cin >> n; for (long long int i = 2; i < sqrt(n) + 1; i++) { long long int sq = (i * i); while (n % sq == 0) n /= i; } cout <<...
#include <bits/stdc++.h> using namespace std; int a[100010]; int b[15]; bool cmp(int x, int y) { if (x == 100 || y == 100) return x < y; else return x % 10 > y % 10; } int main() { int n, k; b[0] = 0; for (int i = 1; i <= 10; i++) b[i] = b[i - 1] + 10; while (scanf( %d%d ...
#include <bits/stdc++.h> using namespace std; int main() { int a1, a2, a3, a4; cin >> a1 >> a2 >> a3 >> a4; if (a1 + a2 == a4 + a3) { cout << YES << endl; } else if (a1 + a3 == a2 + a4) { cout << YES << endl; } else if (a4 + a1 == a3 + a2) { cout << YES << endl; } els...
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > snakeG(int x1, int y1, int x2, int y2) { vector<pair<int, int> > res; int n = y2 - y1 + 1, m = x2 - x1 + 1; for (int i = 0; i < m; ++i) { for (int j = 0; j < n; ++j) { if (i % 2 == 0) { res.push_back(make_pair(...
#include <bits/stdc++.h> using namespace std; bool fl, vis[200005]; int en, d[200005], head[200005]; struct edge { int u, v, w, nxt; } e[200005 * 4], e0[200005]; void dfs(int); void adde(int, int, int); int calc(int x) { int ans = 0; while (x) { ans ^= x & 1; x >>= 1; } r...
#include <bits/stdc++.h> using namespace std; struct edge { int v, u; long long w; edge() {} edge(int a, int b, long long c) : v(a), u(b), w(c) {} bool operator<(edge e) const { return w < e.w; } }; const int N = 100 * 1000 + 10; vector<int> graph[N]; vector<long long> wei[N]; edge e[N...
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { long long n, k; cin >> n >> k; vector<long long> p; vector<long long> pre; for (long long i = 0; i < n; i++) { p.push_back(i + 1); } long long sum = 0; ...
#include <bits/stdc++.h> using namespace std; const long long MAXN = 100005; const int D = 1005; struct data { int ind; long long Sum; data(int _ind, long long _Sum) { ind = _ind; Sum = _Sum; } }; bool compare(data A, data B) { if (A.Sum < B.Sum) return true; if (A.Sum ==...
#include <bits/stdc++.h> const int inf = INT_MAX; const int MAX = 1e3 + 8; const long long MOD = 1e9 + 7; const int TOT_PRIMES = 1e6 + 9; const int MAX_A = 71; const int LN = 20; using namespace std; int main() { int n, k; cin >> n >> k; int a[32]; memset(a, 0, sizeof(a)); for (int i...
#include <bits/stdc++.h> using namespace std; int main(void) { string s; cin >> s; vector<set<int>> v(26); for (int i = 0, l = s.size(); i < l; i++) { v[s[i] - a ].insert(i); } int q; cin >> q; int t; while (q--) { cin >> t; if (t == 1) { int pos; ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int i = 0; i < t; i++) { long long n, k; cin >> n >> k; long long ans = 0; while (n != 0) { if (n % k == 0) { n /= k; ans++; } else { ans += n % k; ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1005; int N, K; long long L[MAXN], R[MAXN]; double dp[MAXN][MAXN]; double calc(long long l, long long r) { long long ret = 0, cur = 1; for (; cur <= r; cur *= 10) { if (cur == 1e18) { ret++; break; } if ...