func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int query(long long a, long long b) { cout << a << << b << endl << flush; int ans; cin >> ans; return ans; } int main() { long long n; cin >> n; long long a = 0, b = 0, sa = 1, sb = 1; int ans = query(a + sa, b + sb); while (a...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 5; int a[maxn], cnt[maxn]; int main() { int n, m, k; cin >> n >> m >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; } int l = 1, r = 1; int ans = 0; cnt[a[1]]++; while (l <= n) { if (((r - l + 1) - ...
#include <bits/stdc++.h> using namespace std; #define ll long long #define MOD (ll)1000000007 #define pii pair<int,int> #define pll pair<ll,ll> #define UNIQUE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end()); ll GCD(ll a,ll b){return b?GCD(b,a%b):a;} ll power(ll a,ll b){ll ret=1;whi...
#include <bits/stdc++.h> using namespace std; bool has[20]; int dp[1010][12][12]; int use[1010][12][12]; int main() { for (int i = 1; i <= 10; i++) { char c; cin >> c; if (c == 1 ) has[i] = true; } int m; cin >> m; if (m == 1) { for (int i = 1; i <= 10; i++) ...
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < int(n); i++) cin >> a[i]; long long diff = 0; int m = a[0]; int ans = 0; for (int i = 0; i < n; i++) { if (a[i] >= m) { m = a[i]; } else { d...
#include <bits/stdc++.h> using namespace std; long long fa[400005], iv[400005]; pair<long long, long long> p[2005]; long long dp[2005]; long long pw(long long bs, long long x) { long long ans = 1; while (x) { if (x & 1) ans = ans * bs % 1000000007; bs = bs * bs % 1000000007; x /= 2; ...
#include <bits/stdc++.h> using namespace std; const int MAXPOW = 20; const int MAXA = 1048577; const int MAXN = 100009; int n; int k; vector<int> a; unordered_set<int> visited[MAXN]; bool used[MAXA]; void gen() { freopen( input.txt , w , stdout); n = 100000; printf( %d n , n); for (...
#include <bits/stdc++.h> using namespace std; const int N = 100010; int Mo[N], a[N]; inline int gi() { int x = 0, o = 1; char ch = getchar(); while (ch != - && (ch < 0 || ch > 9 )) ch = getchar(); if (ch == - ) ch = getchar(), o = -1; while (ch >= 0 && ch <= 9 ) x = x * 10 + ch - 0...
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { long long n; cin >> n; string s; cin >> s; long long i; map<char, long long> mp; for (i = 0; i < n; i++) { mp[s[i]]++; } if (n == 2) { if ...
#include <bits/stdc++.h> using namespace std; int main() { int n, x, y, flag = 0; cin >> n >> x >> y; n /= 2; if ((n == x && n == y) || (n == (x - 1) && n == (y - 1)) || (n == (x) && n == (y - 1)) || (n == (x - 1) && n == (y))) flag = 1; if (flag) cout << NO << endl; el...
#include <bits/stdc++.h> using namespace std; const int MAXN = 200005; const int inf = 1000000007; int main() { int a, b, c; int x, y, z; cin >> a >> b >> c; cin >> x >> y >> z; int da = a - x; int db = b - y; int dc = c - z; int can = max(0, da / 2) + max(0, db / 2) + max(0, dc ...
#include <bits/stdc++.h> using namespace std; int n, k; long long s[211111], mx[211111]; int a[211111], bg[211111]; long long hf, ans; int bhf, aa, bb; int main() { scanf( %d%d , &n, &k); for (int i = 1; i <= n; ++i) { scanf( %d , &a[i]); s[i] = s[i - 1] + a[i]; } for (int i = ...
#include <bits/stdc++.h> using namespace std; string s[100] = { 111111101010101111100101001111111 , 100000100000000001010110001000001 , 101110100110110000011010001011101 , 101110101011001001111101001011101 , 101110101100011000111100101011101 , 100000101010101011010000101000001 , 11111...
#include <bits/stdc++.h> using namespace std; long long n, a[1000003]; pair<long long, long long> b[1000003]; long long calc1() { for (int i = 0; i < n; i++) b[i] = make_pair(-a[i], i); sort(b, b + n); set<signed> s1; s1.insert(-1); s1.insert(n); long long ret = 0; for (int i = 0; i ...
#include <bits/stdc++.h> using namespace std; const int N = 100005; int i, j, k, n, m; pair<int, int> p[N]; int a[N]; int c[N]; int main() { cin >> n; for (i = 0; i < n; ++i) { cin >> p[i].first; p[i].second = i; } sort(p, p + n); k = 0; for (i = 0; i < n; ++i) { ...
#include <bits/stdc++.h> using namespace std; struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _; const int lgn = 32; int n; vector<vector<int>> gr; vector<vector<int>> P; vector<int> lvl, ans, dp; map<pair<int, int>, int> ind; void pre(...
#include <bits/stdc++.h> using namespace std; bool rsort1(const pair<long long int, long long int> &a, const pair<long long int, long long int> &b) { return (a.first > b.first); } bool rsort2(const pair<long long int, long long int> &a, const pair<long long int, long long int> &b...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int a, b; cin >> a; set<int> s; while (a--) { int b; cin >> b; s.insert(b); } cout << s.size() << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n == 1) { cout << 1; return 0; } long long a[100005]; for (int i = 0; i < n; i++) cin >> a[i]; long long ans = 0, kol = 1; for (int i = 0; i < n - 1; i++) if (a[i] == a[i + 1]) k...
#include <bits/stdc++.h> using namespace std; int main() { long long n, p, q, a; cin >> p >> q >> n; for (int i = 1; i <= n; i++) { cin >> a; if (q == 0 || a > p / q) return cout << NO , 0; p -= q * a; swap(p, q); } cout << ((q) ? NO : YES ); }
#include <bits/stdc++.h> #define maxn 1086 using namespace std; typedef long long ll; int n, m; ll a[maxn][maxn]; ll sum[maxn], sum2[maxn]; map<ll, int> mp; int main(){ scanf( %d%d , &m, &n); for(int i = 1;i <= n;i++) for(int j = 1;j <= m;j++) scanf( %lld , &a[i][j]); for(int i = 1;...
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> A, B; int d[10000010]; int a[10000010]; int pr[10010], pn; bool isp[100010]; void GetPrime(int n) { memset(isp + 2, 1, sizeof(isp) - 2); for (int i = 2; i < n; i++) { if (isp[i]) pr[pn++] = i; for (int j = 0; j < pn ...
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long x, y; long long a = 0, d = 0; for (long long i = 0; i < n; i++) { cin >> x >> y; if (x < 0) { a++; } else d++; } if (a <= 1) { cout << Yes << endl; } ...
#include <bits/stdc++.h> using namespace std; int n, k, ans, mx; vector<vector<int>> g; vector<bool> vis; bool a[100001]; void bfs(int src) { vis[src] = true; queue<int> q; q.push(src); while (!q.empty()) { int u = q.front(); q.pop(); for (int i = 0; i < g[u].size(); i++) {...
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; long long N = 100107; long long binpow(long long x, long long y) { if (y == 0) return 1; if (y == 1) return x % mod; else if (y % 2 == 0) { long long w = binpow(x, y / 2) % mod; return (w * w) % mod; } else ...
#include <bits/stdc++.h> using namespace std; int n, m, a, b, fr, k1, k2; int dist[3005][3005]; bool flag[3005][3005]; vector<int> v[3005]; queue<int> q; int main() { scanf( %d %d , &n, &m); for (int i = 1; i <= m; i++) { scanf( %d %d , &a, &b); v[a].push_back(b); v[b].push_back(...
#include <bits/stdc++.h> using namespace std; int cnt[200001], n, par; vector<int> adj[200001]; vector<pair<int, int> > v; void count(int h, int p) { cnt[h]++; for (auto it : adj[h]) if (it ^ p) { count(it, h); cnt[h] += cnt[it]; } } int ct(int h, int p) { for (auto...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); ; long long t; cin >> t; while (t--) { long long n, m; cin >> n >> m; string s; cin >> s; vector<long long> p(m), arr(26, 0); vector...
#include <bits/stdc++.h> using namespace std; int n, m, bal; string s, t; int main() { ios_base::sync_with_stdio(false); cin >> s; n = s.length(); bal = m = 0; for (int i = n - 1; i >= 0; --i) { if (s[i] == 0 ) --bal; else { if (bal + m >= 0) { int j = ...
#include <bits/stdc++.h> using namespace std; int n, m; int l[200000], r[200000], p[200001]; vector<int> beg[200001], ed[200001]; map<unsigned long long, unsigned long long> cnt, sum; unsigned long long h[200000], all; mt19937_64 mt(time(0)); int main() { scanf( %d%d , &n, &m); all = 0; for ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string str; cin >> str; for (int i = 0;; i += 2) { if (i >= str.length() - 1) break; if (str[i] == str[i + 1]) { str.erase(str.begin() + i); i -= 2; } } if (str.length() % 2) str...
#include <bits/stdc++.h> using namespace std; int Map[15][15] = {0}, ro[15] = {0}, co[15] = {0}; int main() { int r, c, n, k, r1, c1, i, j, l1, l2, l3, l4, ans = 0, sum = 0; scanf( %d%d%d%d , &r, &c, &n, &k); for (i = 1; i <= n; i++) { scanf( %d%d , &r1, &c1); Map[r1][c1] = 1; } fo...
#include <bits/stdc++.h> using namespace std; const int MAXN = 60; long long fib[MAXN]; int main() { int n; long long k; cin >> n >> k; fib[0] = 1; fib[1] = 1; for (int i = 2; i <= n; i++) fib[i] = fib[i - 1] + fib[i - 2]; int i = 0; while (i < n) { if (fib[n - i - 1] < k) ...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; int cnt; cin >> n; for (int i = 0; i < n; i++) { cin >> k; cnt = 0; if (k == 1 || k == 2 || k == 3 || k == 5 || k == 7 || k == 11) { cout << -1 << endl; } else { if (k % 4 == 3) { k...
#include <bits/stdc++.h> using namespace std; string S; int MOD; int len; long long dp[1 << 18][100]; int cnt[1 << 18]; int bits[1 << 18]; int DMASKS[1 << 18]; int powers[20]; int orig; long long solve(int mask, int mod) { if (mask == 0) { return mod == 0; } long long &ret = dp[m...
#include <bits/stdc++.h> using namespace std; const int M = 220000; vector<int> e1[M], e2[M]; int p[M], dis[M]; int main() { int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; e1[u].push_back(v); e2[v].push_back(u); } int k; cin >> k...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; if (n == 1 || n == 2) { cout << n << n ; return 0; } int ans = 2, temp = 2; for (in...
#include <bits/stdc++.h> using namespace std; const double Pi = 3.14159265358979323; int main() { ios_base::sync_with_stdio(0); cin.tie(); double x0, y0, v, T, n, x, y, r; vector<tuple<double, double> > c; cin >> x0 >> y0 >> v >> T; T = v * T * 1.0; cin >> n; while (n--) { ci...
#include<bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; using namespace std; // typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; #define ll long long ...
#include <bits/stdc++.h> using namespace std; int n, k; int a[200005]; int cnt[400005]; int cv[400005]; int main() { int t; scanf( %d , &t); while (t--) { memset(cnt, 0, sizeof(cnt)); memset(cv, 0, sizeof(cv)); scanf( %d%d , &n, &k); for (int i = 1; i <= n; i++) scanf( %d...
#include <bits/stdc++.h> using namespace std; int a[100000]; vector<int> adjNos[100001]; vector<long long int> diff; int main() { int n; int m; long long int sum = 0; cin >> n >> m; for (int i = 0; i < m; i++) { cin >> a[i]; } for (int i = 0; i < m; i++) { if (i < m - 1...
#include <bits/stdc++.h> using namespace std; typedef struct node_t { int l, r, k, id; friend bool operator<(const node_t& a, const node_t& b) { if (a.r == b.r) return a.l > b.l; return a.r < b.r; } void print() { printf( l = %d, r = %d, k = %d, id = %d n , l, r, k, id); } } node_t; ...
#include <bits/stdc++.h> using namespace std; template <typename T, size_t N> long long SIZE(const T (&t)[N]) { return N; } template <typename T> long long SIZE(const T &t) { return t.size(); } string to_string(const string s, long long x1 = 0, long long x2 = 1e9) { return + ((x1 < s.siz...
#include <bits/stdc++.h> using namespace std; const int mx = 2e5 + 7; const int base = 19260817; int a[mx]; int n; unsigned long long hs[mx * 2]; void init() { hs[0] = 1; for (int i = 1; i <= 2 * n; i++) hs[i] = hs[i - 1] * base; } int main() { int m, x; scanf( %d , &n); init(); ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:16777216 ) using namespace std; void rot(int n, int *x, int *y, int rx, int ry); int xy2d(int n, int x, int y) { int rx, ry, s, d = 0; for (s = n / 2; s > 0; s /= 2) { rx = (x & s) > 0; ry = (y & s) > 0; d += s * s * ((3 * rx) ^ ...
#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); puts( Even ); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { char s[60]; while (scanf( %s , s) == 1) { int k = strlen(s); int sum = 0; for (int i = 0; i < k / 2; i++) { if (s[i] == s[k - i - 1]) sum++; } int ans = k; if (sum == k / 2) ans -= 1; int t = 0; ...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; unsigned seed = chrono::system_clock::now().time_since_epoch().count(); mt19937 eng(seed); long long random2() { return (1ll << 31ll) * eng() + eng(); } long long n, m, k, q, T; const long long big = 1000000007; const long long big...
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e9, maxn = (int)1e5 + 1; const double eps = (double)1e-8; const int mod = (int)1000000007; int c[200009], a[200009], t, k, f, n; vector<int> b[200009], o; int main() { cin >> n; memset((c), 0, sizeof(c)); ; for (int i = (1...
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(NULL); ios::sync_with_stdio(false); long long int n, m, i, j, k, ans = 0; cin >> n >> m; long long int A[n], B[m]; string str(500, 0 ); for (i = 0; i < n; i++) cin >> A[i]; for (i = 0; i < m; i++) { cin >> k; ...
#include <bits/stdc++.h> static const int MAXN = 2e5 + 4; static const int MAXK = 2e5 + 3; static int n, k; static std::pair<int, int> p[MAXN]; static int idx[MAXN]; static std::vector<int> q[MAXN]; static int ans[MAXN]; int main() { scanf( %d%d , &n, &k); for (int i = 0; i < n; ++i) { sca...
#include <bits/stdc++.h> using namespace std; mt19937 rng_32(chrono::steady_clock::now().time_since_epoch().count()); const long long maxn = 3e5 + 10; struct E { long long to, nxt; } e[maxn * 2]; long long tot, head[maxn]; long long Add[maxn << 2], lz[maxn << 2]; void adde(long long u, long long v) ...
#include <bits/stdc++.h> using namespace std; complex<double> a[524288], b[524288], r[524288], o[524289]; void fft(complex<double> *x, int n, int base) { int size = 0, mask = (n >> 1) - 1; for (int i = base - 1; i >= 0; --i, size = (size << 1) | 1, mask >>= 1) { for (int j = 0; j < n; ++j) { ...
#include <bits/stdc++.h> using namespace std; int n, k, v; map<int, int> mp; vector<int> a; bool can(int mid) { int rem = 0; for (int i = 0; i < a.size(); i++) { if (mp[a[i]] >= mid) { rem += mp[a[i]] / mid; } } return rem >= k; } bool cmp(int s, int f) { return mp[s] >...
#include <bits/stdc++.h> using namespace std; void update(int *arr, int pos, int diff) { while (pos <= 100001) { arr[pos] = max(arr[pos], diff); pos += pos & -pos; } } int sum(int *arr, int pos) { int ret = 0; while (pos > 0) { ret = max(ret, arr[pos]); pos -= pos & -pos;...
#include <bits/stdc++.h> signed main() { std::string s; std::cin >> s; long long n = s.size(); long long p = 0; long long ttl = 0; while (1) { if (p == n) break; while (p < n && std::isalpha(s[p])) ++p; long long a = 0; std::string tmp; while (p < n && (s[p] == ....
#include <bits/stdc++.h> #pragma comment(linker, /STACK:256000000 ) using namespace std; vector<char> cc; void solve() { int n, m, k, d = 0; cin >> n >> m >> k; vector<string> arr(n), ans(n); for (int i = 0; i < n; i++) { cin >> arr[i]; ans[i].resize(m); for (int j = 0; j < m;...
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e9; const double eps = (double)1e-8; const int mod = (int)1000000007; const int maxn = (int)1e6 + 5; int n, l, r, z[2 * maxn]; string a, b, c, d; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >>...
#include <bits/stdc++.h> using namespace std; int n, m, k, s, x, y, cur, pr, cans, tot, a[2005][2005], dp[4][2005][2005]; vector<pair<int, int> > all[10]; int ans[10][10]; int dist(int x2, int y2, int x3, int y3) { return abs(x2 - x3) + abs(y2 - y3); } int main() { ios_base::sync_with_stdio(0); cin ...
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 7; const int K = 3; int main() { long long int t; cin >> t; while (t--) { long long int n; cin >> n; long long int ans = -1; for (int i = 1; i <= n; ++i) { long long int x; cin >> x;...
#include <bits/stdc++.h> using namespace std; int main(void) { int n; cin >> n; long long ans = n; for (int i = 2; i * i <= n; ++i) if (n % i == 0) { while (n % i == 0) n /= i, ans += n; } if (n > 1) ++ans; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int n; int a[200200]; void solve() { scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d , &a[i]); } int pref = 0; for (int i = 0; i < n; i++) { if (a[i]) pref++; else break; } if (pref == n) { ...
#include <bits/stdc++.h> using namespace std; const int N = 4e5 + 5; struct Edge { int to, nxt; } e[N * 2]; int n, head[N], cntE, siz[N], f[N][2]; int ans[N], g[N], mxpt[N], pos[N]; inline void add(int u, int v) { e[++cntE] = (Edge){v, head[u]}; head[u] = cntE; } void dfs1(int u, int fa) {...
#include <bits/stdc++.h> using namespace std; int n, m; pair<int, int> a[200]; pair<int, int> b[200]; int pp[200]; int main() { scanf( %d%d , &n, &m); for (int i = 1; i <= n; i++) { int aa, bb; scanf( %d%d , &aa, &bb); a[i].first = min(aa, bb), a[i].second = max(aa, bb); } ...
#include <bits/stdc++.h> using namespace std; const int maxn = (int)2e5 + 10; vector<int> res[maxn]; int main() { string s; cin >> s; stack<int> st, st2; int ma = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == 1 ) { if (st.empty()) { cout << -1 << endl; ...
#include <bits/stdc++.h> using namespace std; const int MX = 255; int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}; char s[MX][MX]; long long tot[MX][MX]; int was[MX][MX]; int cur[MX][MX]; int main() { int n, m, p, w; scanf( %d %d %d %d , &n, &m, &p, &w); for (int i = 1; i <= n; i++) { s...
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > ans; int p[2000], damage[2000], u[2000]; int main() { int n, Max, r, used = 0, TT; cin >> n >> Max >> r; for (int i = 1; i <= n; i++) cin >> p[i] >> damage[i]; int cap = Max; memset(u, 0, sizeof(u)); for (int s = 0;; s...
#include <bits/stdc++.h> using namespace std; const long long int N = 100001; bool ok; long long int n, q; long long int trie[6 * N][5], done[6 * N]; long long int nxt = 1; string s; void insert(string s) { long long int node = 0; for (char c : s) { if (trie[node][c - a ] == 0) { ...
#include <bits/stdc++.h> using namespace std; int ar[310]; bool mp[310][310]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) cin >> ar[i]; string str; for (int i = 1; i <= n; i++) { cin >> str; for (int j = 0; j < n; j++) if (str[j] == 1 ) mp[i][j + 1] = true...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; long long int n; cin >> n; string s; cin >> s; vector<long long int> v(n + 1, 0); for (long long int i = 1; i <= n; i++) { if (s[i - 1] == ( ) ...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using vi = vector<int>; using vll = vector<ll, ll>; using pii = pair<int, int>; using pll = pair<ll, ll>; ll modpow(ll a, ll b, ll mod = (ll)(1e9 + 7)) { if (!b) return 1; a %= mod; return modpow(a * ...
#include <bits/stdc++.h> using namespace std; template <typename T> bool chmax(T& a, const T& b) { return a < b ? (a = b, true) : false; } template <typename T> bool chmin(T& a, const T& b) { return b < a ? (a = b, true) : false; } int N; string S; int main() { cin >> S; N = S.size()...
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; const long long INFLL = 1000000000000000000LL; const int h = 300000000; int l, r; int pr[(h >> 6) + 1]; int main() { scanf( %d%d , &l, &r); int res = 0; int r2 = (r - 1) / 2; pr[0] |= 1; for (int i = (1), _b = ((...
#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define f first #define s second #define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0) /* ll dx[8]={-1,-1,-1,0,0,1,1,1}; ll dy[8]={-1,0,1,-1,1,-1,0,1}; bool sortbysec(const pair<int,int> &a, ...
#include <bits/stdc++.h> using namespace std; const int maxn = 200010; map<int, int> mp; int n; struct pnt { int x, w; bool operator<(const pnt &p) const { return x < p.x; } } p[maxn]; int ask(int x) { int res = 0; for (int i = x; i > 0; i -= (i & -i)) if (mp.count(i)) res = max(res,...
#include <bits/stdc++.h> int main() { int n; scanf( %d , &n); for (int i = n + 1; i < 10000; i++) { int d = i % 10; int c = (i % 100 - d) / 10; int a = i / 1000; int b = (i - 1000 * a) / 100; if (a != b && a != c && a != d && b != c && b != d && c != d) { printf( %d%d...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 2; long long n, m; long long a[N], b[N]; long long f(long long x) { long long res = 0; for (long long(i) = (0); (i) < (n); (i)++) { if (a[i] < x) res += llabs(a[i] - x); } for (long long(i) = (0); (i) < (m); (i)++) { ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; long long ma = -1e15, need = 0; for (int i = 0; i < n; i++) { long long a; cin >> a; ma = max(a, ma); ...
#include <bits/stdc++.h> using namespace std; int main() { double eps = 1e-12; double y1, y2, yw, xb, yb, r; cin >> y1 >> y2 >> yw >> xb >> yb >> r; double yk = yw - r; double yt = y1 + r; double d1 = yk - yt; double d2 = yk - yb; double xk = xb * d1 / (d2 + d1); double A = yt - ...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int mod = 1e9 + 7; int n, a[500010], b[500010], c[500010], bit[500010]; void init() { for (int i = 1; i <= n; i++) { bit[i] = 0; } } int lowbit(int x) { return x & (-x); } void add(int u, int x) { for (; u ...
#include<bits/stdc++.h> // #define int long long #define ld long double #define fi first #define se second #define vll vector<int> #define pii pair<int,int> #define pb push_back #define sz(v) (int)(v).size() #define inf (int)(1e8) #define md (int)(1e9+7) #define all(v) (v).begin(),(v).end() #def...
#include <bits/stdc++.h> using namespace std; long long mx, mx2; void solve(long long m, long long blocks, long long sum) { if (m == 0) { if (blocks > mx) { mx = blocks; mx2 = sum; } else if (blocks == mx && sum > mx2) { mx2 = sum; } return; } long long ...
#include <bits/stdc++.h> using namespace std; int num[300]; int main() { int n, a, minn = 99999, sum = 0, sum2 = 0; scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , &num[i]); for (int i = 1; i <= n; i++) sum += abs(num[i]); printf( %d n , sum); return 0; }
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); long long t, n, m; cin >> t; while (t--) { cin >> n >> m; if (n == 1 || m == 1 || (n == 2 && m == 2)) { cout << YES << endl; } else { cout << NO << en...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma ) #pragma GCC optimize( unroll-loops ) using namespace std; const double eps = 1e-12; const long long MOD = 1e9 + 7; const double PI = acos(-1.0); const long long INF = 1e18; ...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d; cin >> a >> b >> c >> d; int k = a + b + c + d; if (k % 2 == 0) { if (a + b == k / 2 || a + c == k / 2 || a + d == k / 2 || b + c == k / 2 || b + d == k / 2 || c + d == k / 2 || a + b + c == k / 2 || ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 510; const int MAXQ = 100010; const double EPS = 1e-10; const double DINF = 1e30; const int IINF = ~0U >> 3; const long long LINF = 1LL << 61; void debug() { cout << error_here << endl; } char str[MAXN][MAXN]; int a[MAXN][MAXN], b[MAXN...
#include <bits/stdc++.h> using namespace std; long long int comp(pair<long long int, long long int> a, pair<long long int, long long int> b) { if (a.first != b.first) return a < b; return a.second < b.second; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ...
#include <bits/stdc++.h> using namespace std; const int mx = 1e5 + 10; int p[mx]; int main() { int n; cin >> n; if (n % 4 > 1) { puts( -1 ); return 0; } int l = 1, r = n; while (l < r) { p[l] = l + 1; p[l + 1] = r; p[r] = r - 1; p[r - 1] = l; l +...
#include <bits/stdc++.h> using namespace std; long long int power(long long int a, long long int b) { long long int res = 1; a %= 1000000007; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % 1000000007; a = a * a % 1000000007; } return res; } long long int modI...
#include <bits/stdc++.h> using namespace std; long long int pp(long long int a, long long int b) { if (b == 0) return 1; long long int t = pp(a, b / 2); if (b % 2 == 0) return t * t; else return t * t * a; } string ss(string s, long long int j) { for (long long int i = 0; i < j; ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:66777216 ) using namespace std; static unsigned rnd() { static int second = 124612741; second ^= second << 13; second ^= second >> 17; return second ^= second << 5; } inline int fpow(int a, int st, int mod) { int ans = 1; while (...
#include <bits/stdc++.h> using namespace std; template <typename A> ostream &operator<<(ostream &cout, vector<A> const &v); template <typename A, typename B> ostream &operator<<(ostream &cout, pair<A, B> const &p) { return cout << ( << p.first << , << p.second << ) ; } template <typename A> os...
#include <bits/stdc++.h> using namespace std; FILE *in; FILE *out; const int MAX = 1048576; const int TREE = 2097152; const int MOD = 1000000007; int n; int a[MAX]; int tree[TREE]; bool seen[MAX]; int query(int idx1, int idx2) { idx1 += (TREE >> 1); idx2 += (TREE >> 1); if (idx1 == idx...
#include <bits/stdc++.h> int main() { int cnt = 0, f[4], i, j, x[200], y[200], n; scanf( %d , &n); for (i = 0; i < n; i++) { scanf( %d %d , &x[i], &y[i]); } for (i = 0; i < n; i++) { f[1] = 0; f[2] = 0; f[3] = 0; f[0] = 0; for (j = 0; j < n; j++) { if (j...
#include <bits/stdc++.h> using namespace std; template <class A, class B> ostream& operator<<(ostream& o, pair<A, B>& p) { return o << ( << p.first << , << p.second << ) ; } template <class T> ostream& operator<<(ostream& o, const vector<T>& v) { o << { ; for (typeof((v).begin()) it = (v)...
#include <bits/stdc++.h> int minDig(uint64_t n) { int k = n % 10, min = k; n /= 10; while (n != 0) { k = n % 10; if (k <= min) min = k; n /= 10; } return min; } int maxDig(uint64_t n) { int k = n % 10, max = k; n /= 10; while (n != 0) { k = n % 10; if ...
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { std::cerr << name << : << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ...
#include <bits/stdc++.h> using namespace std; int a[10005][6], n, m; map<int, int> f[10005]; int power(int x, int y) { int s = 1; for (; y; y /= 2, x = 1ll * x * x % 1000000007) if (y & 1) s = 1ll * s * x % 1000000007; return s; } int main() { scanf( %d%d , &n, &m); for (int i = 2;...
#include<bits/stdc++.h> #define L(i, j, k) for(int i = (j), i##E = k; i <= i##E; i++) #define R(i, j, k) for(int i = (j), i##E = k; i >= i##E; i--) #define mkp make_pair #define pii pair<int, int> #define ll long long #define db double #define sz(a) a.size() #define x first #define y second #define...