func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; const int LIM = 100005; long long power(long long x, long long n) { long long res = 1; while (n) { if (n & 1) { res = res * x % mod; } x = x * x % mod; n >>= 1; } return (res % mod); } i...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, s, x, k, ans = 0, ch = 0; cin >> n >> s; s = 8 * s; vector<long long int> vec(n); vector<pair<long long int, long long int>> dat; for (long long int i = 0; i < n; i++) cin >> vec[i]; sort(vec.begin(), vec.end());...
#include <bits/stdc++.h> using namespace std; const int maxn = (int)1e6; const int inf = (1ll << 31) - 1; int p[maxn], l[maxn]; int n; pair<pair<int, int>, int> e[maxn]; pair<int, int> st[maxn]; int sum[maxn], answer[maxn]; int main() { scanf( %d , &n); for (int i = 0; i < n; ++i) { scan...
#include <bits/stdc++.h> using namespace std; inline int cmp(double x, double y = 0, double tol = 1e-9) { return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1; } int main() { int n; double a, d, t0, vm, t_vm, def, last = 0; scanf( %d %lf %lf , &n, &a, &d); def = sqrt(2 * d / a); for (int i...
#include <bits/stdc++.h> using namespace std; double pa[2020], pb[2020], pab[2020]; int n, a, b; double dp[2020]; int opt[2020]; pair<int, int> solve(double mida, double midb) { dp[0] = 0; opt[0] = 0; for (int i = 1; i <= n; i++) { double& d = dp[i]; int& o = opt[i]; d = dp[i -...
#include <bits/stdc++.h> using namespace std; char IO; inline long long rd() { long long res = 0, f = 1; while (IO = getchar(), IO < 48 || IO > 57) if (IO == - ) f = 0; do res = (res << 3) + (res << 1) + (IO ^ 48); while (IO = getchar(), IO >= 48 && IO <= 57); if (f) return res; ret...
#include <bits/stdc++.h> using namespace std; const int N = 1000005; int n, q[N], top1, top2; struct ky { int x, y; long long w, val; bool operator<(const ky& p) const { return x < p.x; } } a[N]; long long f[N], ans; inline double slope(const int x, const int y) { return a[x].x == a[y].x ?...
#include <bits/stdc++.h> using namespace std; const int lim = 10; char ch[11]; int i, j, k, n, m, a[21], t; int main() { scanf( %d , &n); memset(a, 0, sizeof(a)); for (i = 1; i <= n; i++) { scanf( %s%d , ch, &k); if (ch[0] == & ) { for (j = 0; j < lim; j++) { t = ((k...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); int test; for (cin >> test; test--;) { int m, n; cin >> m >> n; vector<vector<int>> s(m + 5, vector<int>(n + 5)); for (int i = 1; i <= m; ++i) { ...
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &x) { x = 0; int fl = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) fl = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { x = (x << 1) + (x << 3) + ch - 0 ; ...
#include <bits/stdc++.h> using namespace std; const long double pi = 3.1415926535897932384626433832795l; template <typename T> inline auto sqr(T x) -> decltype(x * x) { return x * x; } template <typename T1, typename T2> inline bool umx(T1& a, T2 b) { if (a < b) { a = b; return 1; ...
#include <bits/stdc++.h> using namespace std; long long sum_prefix(vector<long long> &t, int len) { long long res = 0; int i = len; while (i >= 0) { res += t[i]; i &= (i + 1); i--; } return res; } long long sum_interval(vector<long long> &t, int l, int r) { return sum_p...
#include <bits/stdc++.h> template <typename T> void scan(T &x) { x = 0; bool _ = 0; T c = getchar(); _ = c == 45; c = _ ? getchar() : c; while (c < 48 || c > 57) c = getchar(); for (; c < 48 || c > 57; c = getchar()) ; for (; c > 47 && c < 58; c = getchar()) x = (x << 3) + (x <...
#include <bits/stdc++.h> using namespace std; template <typename T> void tk_input(vector<T> &arr) { for (T &i : arr) cin >> i; } void solve() { int n, k; cin >> n >> k; string s; cin >> s; priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int>...
#include <bits/stdc++.h> using namespace std; const int N = 100010; set<pair<int, int> > s, e; long long dp[N]; int l[N], r[N]; struct Point { int x, h, k; bool f; } p[2 * N]; struct temp { int h, k; } q[N]; int m; bool cmp1(const temp &a, const temp &b) { return a.h > b.h; } bool cm...
#include <bits/stdc++.h> using namespace std; template <typename TH> void _dbg(const char* sdbg, TH h) { cerr << sdbg << = << h << n ; } template <typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t) { while (*sdbg != , ) { cerr << *sdbg++; } cerr << = << h <<...
#include <bits/stdc++.h> using namespace std; int main() { long long n, i, j, k; cin >> n; long long a[n]; for (i = 0; i < n; i++) { cin >> a[i]; } long long ans = 10000000000; for (i = 1; i < n - 1; i++) { long long b[n]; for (k = 0; k < n; k++) { b[k] = a[k]; ...
#include <bits/stdc++.h> using namespace std; int main() { long long t, n, i, m; cin >> t; while (t--) { cin >> n; string s; cin >> s; if (n % 2 == 0) { int f = 0; for (i = 0; i < n; i++) { long long a1 = int(s[i] - 0 ); if ((i + 1) % 2 == 0 &...
#include <bits/stdc++.h> using namespace std; int main() { int n, h, value, width = 0; vector<int> v; cin >> n; cin >> h; for (int i = 0; i < n; i++) { cin >> value; v.push_back(value); } for (int j = 0; j < v.size(); j++) { if (v[j] > h) width = width + 2; ...
#include <bits/stdc++.h> using namespace std; long long f[1001][1001], s[1001][1001]; long long a[10001], ans[10001]; int main() { int n, m, k; cin >> n >> k; for (int i = 1; i <= n; i++) { scanf( %lld , &a[i]); } sort(a + 1, a + n + 1); a[0] = -10080124100; long long sum = 0; ...
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; if (n == 0 || n == 1) { cout << 0 << endl; return; } long long a[n]; vector<int> pos; long long even = n / 2, odds = n - even; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; const int maxm = 1e6 + 10; const int mod = 1e9 + 7; queue<string> que; string str; set<string> se; int ans, n, k; void bfs() { if (k - 1 == 0) return; que.push(str); while (que.size()) { string now = que.front();...
#include <bits/stdc++.h> using namespace std; const long long N = 1000005; const long long M = 1000000007; long long n, m, cc, len; long long s[5]; int main() { long long sum = 0; for (long long i = 0; i < 3; i++) scanf( %I64d , &s[i]), sum += s[i]; sort(s, s + 3); long long ans = -1; fo...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long INF = LLONG_MAX; const long long MINF = LLONG_MIN; const int N = 2e5 + 5; template <typename T> inline T abs(T x) { return x < 0 ? -x : x; } inline long long pow_mod(long long x, long long n) { long lo...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9, MOD = 1e9 + 7; const int n_ = 1e5 + 1000; long long gcd(long long a, long long b) { return (a ? gcd(b % a, a) : b); } long long power(long long a, long long n) { long long p = 1; while (n > 0) { if (n % 2) { p = p *...
#include <bits/stdc++.h> using namespace std; string nsp(string s) { string t = ; for (int i = 0; i < s.size(); i++) if (s[i] != ) t = t + s[i]; return t; } string gfbu(string s, char c, int a) { string t = ; for (int i = a; i < s.size() - 1; i++) { if (s[i] == c) return t...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int n, k, i; cin >> n >> k; string s[3]; cin >> s[0] >> s[1] >> s[2]; bool a[3][105]; while (s[0].size() <= n + ...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 1000; const long long INF64 = 1e18; const int N = 1001000; const int MOD = 1e9 + 7; const double EPS = 1E-9; long long gcd(long long a, long long b) { return a == 0 ? b : gcd(b % a, a); } int add(int first, int second, int m) { firs...
#include <bits/stdc++.h> const long long int MOD = 1e9 + 7; using namespace std; constexpr int mul(int a, int b) { return 1LL * a * b % MOD; } template <typename... T> constexpr int mul(int a, int b, T... t) { return mul(mul(a, b), t...); } template <class T> inline T Min(const T &a, const T &b) { ...
#include <bits/stdc++.h> using namespace std; int n, m; int score(pair<int, int> a) { int d = abs(a.first - a.second); return min(d, n - d); } const int N = 1e5 + 7; int nxt[N], prv[N]; vector<int> regions[N]; vector<int> adj[N]; int level[N]; int sz[N]; void dfs1(int u, int par) { ass...
#include <bits/stdc++.h> using namespace std; int main() { int n, x, y; cin >> n; x = 1; y = n * n; while (x < y) { cout << x << << y << endl; x++; y--; } return 0; }
#include <bits/stdc++.h> using namespace std; vector<string> split(const string& s, char c) { vector<string> v; stringstream ss(s); string x; while (getline(ss, x, c)) { v.emplace_back(x); } return move(v); } void err(vector<string>::iterator it) {} template <typename T, typename...
#include <bits/stdc++.h> using namespace std; double pi = acos(-1); long long power(long long a, long long b) { long long p_res = 1; while (b > 0) { if (b % 2 == 1) { p_res *= a; b--; } a *= a; b /= 2; } return p_res; } int cc[300001]; int ans[300001];...
#include <bits/stdc++.h> using namespace std; const int N = 300100; const int K = 1001000; vector<int> v[K]; int a[N], s[N]; int l[N], r[N]; int q[N], id[N]; int main() { int n, k; scanf( %d%d , &n, &k); for (int i = 0; i < n; i++) { scanf( %d , &a[i]); } s[0] = a[0] % k; v...
#include <bits/stdc++.h> using namespace std; inline void read(int &x) { char ch = getchar(); x = 0; while (!isdigit(ch)) ch = getchar(); while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar(); } const int N = 1e5 + 10; int n, a[N], s[N], c[N << 1]; inline void add(int x) { for (; x; x...
#include <bits/stdc++.h> using namespace std; const double eps = 1.0e-5; const int maxn = 100000 + 10; const int mod = 1e9 + 7; int a, b[505], n; int main() { memset(b, 0, sizeof(b)); long long ans = 0; int tmp; scanf( %d , &n); for (int i = 1; i <= n - 1; i++) ans = (2 * ans + 1) % mod;...
#include <bits/stdc++.h> using namespace std; const long long maxn = 5e5 + 10; const long long INF = 1e18; long long n, a[maxn], po, maxx = 0, m[maxn]; int main() { std::ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> m[i]; if (...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d; scanf( %d%d%d%d , &a, &b, &c, &d); int a1 = abs(a - c) * 2; int b1 = abs(b - d) * 2; int ans = a1 + b1 + 4; if (a != c && b != d) printf( %d n , ans); else printf( %d n , ans + 2); return 0; }
#include <bits/stdc++.h> using namespace std; long long n, k, a, b; long long mini = (long long)1e15; long long maxi = 0; long long gcd(long long a, long long b) { if (b == 0) return a; else return gcd(b, a % b); } void calc(long long l) { if (l <= 0 || l > n * k) return; long ...
#include <bits/stdc++.h> int main() { int n, m; scanf( %d%d , &n, &m); std::vector<std::vector<int>> graph(n); for (int i = 0; i < m; ++i) { int a, b; scanf( %d%d , &a, &b); a--; b--; graph.at(a).push_back(b); graph.at(b).push_back(a); } std::vector<int> col...
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int main() { int n, l[300], c[300]; cin >> n; for (int i = 0; i < n; i++) cin >> l[i]; for (int i = 0; i < n; i++) cin >> c[i]; unordered_map<int, int> um; for (int i = 0; i < n; i++) ...
#include <bits/stdc++.h> using namespace std; struct B { int p, id; }; priority_queue<B> q; bool operator<(const B &a, const B &b) { return a.p < b.p; } int main() { string s; long long a, b, l, len, cost, i; B tmp; cin >> s; l = 0; len = s.size(); cost = 0; for (i = 0; i...
#include <bits/stdc++.h> using namespace std; struct p { int x; int i; } a[200123]; int cmp(p a, p b) { if (a.x != b.x) return a.x < b.x; else return a.i < b.i; } int main() { int n; int i, j; scanf( %d , &n); for (i = 0; i < n; i++) { scanf( %d , &a[i].x); ...
#include <bits/stdc++.h> using namespace std; const int inf = 1000000000; const double pi = 2 * acos(0.0); const int MOD = 1000000007; vector<int> g[5]; int id[222][222], k[222]; bool ok[222]; int wh[222]; int main() { int n; cin >> n; for (int i = 1; i <= n; ++i) { cin >> wh[i]; ...
#include <bits/stdc++.h> using namespace std; int main() { int a; cin >> a; int i = 1; while (true) { int cnt = i / 2 + 1; if (cnt == a) { break; } ++i; } cout << i << << 2 << endl; cout << 1 2 n ; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vvll = vector<vll>; using vb = vector<bool>; using vd = vector<double>; using vs = vector<string>; using pii = pair<int, int>; using pll = pair<ll, ll>;...
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const long long INF = 1e18; const double eps = 1e-10; mt19937 mrand(chrono::high_resolution_clock::now().time_since_epoch().count()); template <class T> inline void upmin(T &x, T y) { x = x > y ? y : x; } template <class T> inlin...
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 5; stack<pair<long long, long long> > q; long long n, a[N], go[N]; struct cell { long long max_l, max_r, or_l, or_r; }; bool d[N][35]; cell b[N]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0...
#include <bits/stdc++.h> using namespace std; vector<int> ev[1000099]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> p(n), pos(n); for (int(i) = (0); (i) < (int)(n); ++(i)) { cin >> p[i]; p[i]--; pos[p[i]] = i; ev[n - i].push_bac...
#include <bits/stdc++.h> int main() { int a, b, c, d, p1, p2, p3, p4; scanf( %d %d %d %d , &a, &b, &c, &d); p1 = ((3 * a / 10)); p2 = (a - (a * c / 250)); if (p1 > p2) { p1 = p1; } else if (p2 > p1) { p1 = p2; } else if (p2 == p1) { p1 = p1; } p3 = ((3 * b / 10));...
#include <bits/stdc++.h> using namespace std; int main() { int numOfComparisons, HomeUniform, GuestUniform, count = 0; cin >> numOfComparisons; int *Home = new int[numOfComparisons]; int *Guest = new int[numOfComparisons]; for (int i = 0; i < numOfComparisons; i++) { cin >> Home[i] >> Gues...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; template <class T> using pq = priority_queue<T>; template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>; int scan() { return getchar(); } void scan(int& a) { cin >> a; } void scan(long long& a) { cin >> a; } vo...
// Author : Mc_LaReN #include <bits/stdc++.h> #define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) using namespace std; const int MOD = 1e9 + 7, MX = 400005; #define DEBUG cerr<< /n>>>I m Here<<</n <<endl; #define what_is(x) cerr << #x << is << x << endl; #define pf push_front ...
#include <bits/stdc++.h> using namespace std; long long int a[200]; int main() { long long int n, ans = 0, m, i, j, x, y; cin >> n >> m; for (i = 1; i <= n; i++) cin >> a[i]; for (i = 1; i <= m; i++) { cin >> x >> y; long long int ret = 0; for (j = x; j <= y; j++) { ret +...
#include <bits/stdc++.h> using namespace std; using namespace std; int main() { int t; cin >> t; while (t--) { long long a, b, c, d; long long ar[6]; cin >> a >> b >> c; ar[0] = a; ar[1] = b; ar[2] = c; sort(ar, ar + 3); cout << ar[2] + 1 << endl; } ...
#include <bits/stdc++.h> using namespace std; bool mark[72][72][72]; int a[10]; pair<int, pair<int, int> > Par[72][72][72]; pair<int, int> par[72][72][72]; queue<pair<int, pair<int, int> > > q; vector<pair<int, int> > v; char c[100][100]; int main() { ios_base::sync_with_stdio(false); int n; ...
#include <bits/stdc++.h> using namespace std; int n, p; bool prime(int num) { for (int i = 2; i <= sqrt(num); i++) { if (num % i == 0) return 0; } return 1; } int main() { cin >> n; if (prime(n)) { return cout << 1 << endl << n, 0; } p = (n - 3) / 2; cout << 3 << ...
#include <bits/stdc++.h> using namespace std; void my_functions() { return; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; long long int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } string s; cin >> s; long l...
#include <bits/stdc++.h> using namespace std; void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << = << a << n ; err(++it, args...); } long long powMod(long long x, long long y) { long lon...
#include <bits/stdc++.h> using namespace std; const int maxn = 5e3 + 5; const int N = 1e4 + 5; const int inf = 0x3f3f3f3f; struct hor { int x1, x2, y; bool operator<(const hor& a) const { return y < a.y; } } h[maxn]; struct ver { int y1, y2, x; bool operator<(const ver& a) const { return y...
#include <bits/stdc++.h> const int INF = 500000001; const double EPS = 1e-9; const double PI = acos(-1.0); using namespace std; int main() { srand(time(NULL)); char ch[101][105]; int n, m; int bl[105][105]; while (~scanf( %d %d , &n, &m)) { for (int i = 0; i < n; i++) { scanf...
#include <bits/stdc++.h> using namespace std; long long vec3[17][1 << 17]; long long mn(int i, int j) { int p = 31 - __builtin_clz(j - i); return min(vec3[p][i], vec3[p][j - (1 << p)]); } void mn_init(int n) { int mp = 31 - __builtin_clz(n); for (int p = 0; p < mp; ++p) for (int x = 0; x...
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > v; vector<string> veg; bool comp(pair<int, int> p1, pair<int, int> p2) { return (p1.first < p2.first or ((p1.first == p2.first) and (p1.second < p2.second))); } int main() { int n, m, k, t, x, y; veg.push_back( Gra...
#include <bits/stdc++.h> using namespace std; const int maxlongint = 2147483647; const int inf = 1000000000; char s[10], a[1000][1100]; ; int main() { scanf( %s , s); int n; cin >> n; for (int i = 1; i <= n; i++) scanf( %s , a[i]); int ans = 0; for (int i = 1; i <= n; i++) { if...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 7; vector<int> G[N]; int vis[N] = {0}, p[N]; long long sum[N] = {0}; stack<int> s; void dfs(int u, int fa) { s.push(u); vis[u] = 1; for (int i = 0; i < (int)G[u].size(); i++) { int v = G[u][i]; if (v == fa) continue;...
#include <bits/stdc++.h> using namespace std; int t[10], card[105]; int main() { int i, sum, ans; sum = 0; for (i = 1; i <= 5; i++) { cin >> t[i]; sum = sum + t[i]; card[t[i]]++; } ans = sum; for (i = 100; i >= 1; i--) { if (card[i] == 2) { if (sum - 2 * i <...
#include <bits/stdc++.h> using namespace std; long long mM(long long a, long long b, long long mod) { long long res = 0; a %= mod; while (b) { if (b & 1) res = (res + a) % mod; a = (2 * a) % mod; b >>= 1; } return res; } long long fpow(long long first, long long second, lon...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; vector<int> e[N]; set<int> s[N]; queue<int> q; bool vis[N]; int d[N]; int main() { int n; scanf( %d , &n); for (int i = 1; i < n; i++) { int u, v; scanf( %d %d , &u, &v); d[u]++, d[v]++; e[u].push_ba...
#include <bits/stdc++.h> using namespace std; long long x, y, m; int main() { cin >> x >> y >> m; if (x >= m || y >= m) cout << 0 << n ; else { if (x <= 0 && y <= 0) cout << -1 << n ; else { long long cc = 0; if (x > y) swap(x, y); if (x < 0) { ...
#include <bits/stdc++.h> using namespace std; int main() { vector<int> v; int n, m; cin >> n >> m; int maks = 0; for (int i = 0; i < n; i++) v.push_back(i + 1); do { int res = 0; for (int i = 0; i < n; i++) { for (int j = i; j < n; j++) { int x = 100; ...
#include <bits/stdc++.h> using namespace std; int main() { string s1, s2, s3; long long a = 0, b = 0, c = 0; string unia; cin >> s1 >> s2 >> s3; long long *trm1, *trm2; string *uni; uni = &unia; if (s1[0] == A ) trm1 = &a; else if (s1[0] == B ) trm1 = &b; else i...
#include <bits/stdc++.h> using namespace std; int main() { int N; ios_base::sync_with_stdio(0); cin >> N; string K; cin >> K; int zm = N; for (int i = 1; i < N; i++) { if (K[i] != K[i - 1]) { zm--; if (i < N - 1) K[i] = K[i + 1]; } } cout << zm; }
#include <bits/stdc++.h> int mod = 1000000007; using namespace std; using namespace std; int n, k; int a[400005]; int pos[400005]; map<int, int> m; int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); ; cin >> n >> k; for (int i = 1; i <= n; i++) pos[i] = 1e7; m[a[...
#include <bits/stdc++.h> using namespace std; int arr[11][11]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { arr[1][i] = 1; } for (int i = 2; i <= n; i++) { for (int j = 1; j <= n; j++) { arr[i][j] = arr[i - 1][j] + arr[i][j - 1]; } } cout << ar...
#include <bits/stdc++.h> using namespace std; int main() { int i, j, n, m, k; int h; while (scanf( %d%d%d , &n, &m, &h) != EOF) { int sum1, sum2; sum1 = sum2 = 0; for (i = 1; i <= m; i++) { scanf( %d , &k); if (i == h) sum1 = k; else sum2 += ...
#include <bits/stdc++.h> using namespace std; int main(void) { int n, m, c; cin >> n >> m >> c; vector<int> a(n), b(m); for (int i = 0; i < n; i++) cin >> a[i]; for (int j = 0; j < m; j++) cin >> b[j]; vector<int> beg(n); beg.assign(n, 0); vector<int> start(n), end(n); start.assi...
#include <bits/stdc++.h> int main() { int a[100]; int e, n, i, j; scanf( %d , &n); for (i = 0; i < n; i++) { a[i] = 0; } for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { scanf( %d , &e); if (i >= j) { continue; } a[i] |= e; a[j] ...
#include <bits/stdc++.h> #define fo(a,b,c) for (a=b; a<=c; a++) #define fd(a,b,c) for (a=b; a>=c; a--) #define fu(x) (((x)&1)?-1:1) #define add(a,b) a=((a)+(b))%mod #define min(a,b) (a<b?a:b) #define max(a,b) (a>b?a:b) #define mod 998244353 #define Mod 998244351 #define ll long long //#define file ...
#include <bits/stdc++.h> using namespace std; const long long int MOD = 1e9 + 7; const long long int INF = 2e15; const long long int MAXN = 2e5 + 5; long long int fastexpo(long long int b, long long int exp) { if (exp == 0) return 1; if (exp == 1) return b; long long int ans = (fastexpo(b, exp / 2...
#include <bits/stdc++.h> using namespace std; long long tg, ans[22]; int state[22][22], fa_inc[22][22], fa_n4[22][22], fa_n7[22][22]; int t, cs = 0, dg[22]; int main() { scanf( %d , &t); for (cs = 1; cs <= t; ++cs) { scanf( %I64d , &tg); for (int i = 0; i < 19; ++i) dg[i] = tg % 10, tg /= ...
#include <bits/stdc++.h> using namespace std; long long dp[200005][4]; vector<int> v[200005]; int mod = 998244353; void dfs(int first, int f) { dp[first][0] = 1; int visf = 0; for (auto it : v[first]) { if (it != f) { dfs(it, first); if (visf) { dp[first][1] *= (dp[...
#include <bits/stdc++.h> inline int two(int n) { return 1 << n; } inline int test(int n, int b) { return (n >> b) & 1; } inline void set_bit(int& n, int b) { n |= two(b); } inline void unset_bit(int& n, int b) { n &= ~two(b); } inline int last_bit(int n) { return n & (-n); } inline int ones(int n) { int...
#include <bits/stdc++.h> using namespace std; int v1, v2, v3, vm; inline long long readll() { int sign = 1; char c; for (c = getchar(); !isdigit(c); c = getchar()) if (c == - ) sign = -sign; long long res = c - 0 ; for (c = getchar(); isdigit(c); c = getchar()) res = res * 10 + c - 0 ...
#include <bits/stdc++.h> using namespace std; int x[105]; int main() { int n, p, q; cin >> n >> p; for (int i = 0; i < p; ++i) cin >> x[i]; cin >> q; for (int i = p; i < p + q; ++i) cin >> x[i]; sort(x, x + p + q); int k = 0; for (int i = 0; i < p + q; ++i) { if (x[i] == k + ...
#include <bits/stdc++.h> using namespace std; const int N = 1505; int n, k; map<tuple<int, int, int>, bool> memo; bool query(int a, int b, int c) { if (b == a || b == c) return 1; if (a > c) swap(a, c); auto s = make_tuple(a, b, c); if (memo.count(s)) return memo[s]; cout << ? << a + 1 ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); long long x, y, m; cin >> x >> y >> m; if (x <= 0 && y <= 0) { if (max(x, y) >= m) cout << 0 ; else cout << -1 ; return 0; } if (x > y) swap(x, y); long long odp =...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a; int sum = 0; for (int i = 0; i < n; i++) { cin >> a; sum += a; } cout << (sum % n == 0 ? n : n - 1) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, d, h; cin >> n >> d >> h; if (d > 2 * h || d < h) { cout << -1 << endl; return 0; } if (d == 1 && h == 1 && n != 2) { cout << -1 << endl; return 0; } vector<pair<int, int> > p; for (int i = ...
#include <bits/stdc++.h> using namespace std; int x1, x2, x3; int Y1, y2, y3; int main() { cin >> x1 >> Y1 >> x2 >> y2; x3 = (x1 <= x2 ? x2 + 1 : x2 - 1); y3 = (Y1 <= y2 ? y2 + 1 : y2 - 1); int r = 0; if (x1 == x2 || Y1 == y2) r = 2; cout << r + 2 * abs(x1 - x3) + 2 * abs(Y1 - y3); r...
#include <bits/stdc++.h> using namespace std; long long n, a[569], sq[250069], zs, inf = 1e18; void cyc(long long x) { swap(a[x + 1], a[x + 2]); swap(a[x], a[x + 1]); zs++; sq[zs] = x; } int main() { long long t, rr, i, j, ii, e; pair<long long, long long> mne; scanf( %lld , &t); ...
#include <bits/stdc++.h> using namespace std; const int maxN = 1e5 + 1; struct Node { int t, x, l, c; } pnt[maxN]; long long t, pos[maxN]; int m, n; int solve(long long t) { int l, r, m; while (t > 0) { l = 1, r = n + 1; while (l + 1 < r) { m = (l + r) >> 1; if (pos...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( avx,avx2,fma ) using namespace std; const long double pi = acos(-1); const long long int mod = 1e9 + 7; bool debug = false; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; long lo...
#include <bits/stdc++.h> using namespace std; template <class T> void chmin(T& a, const T& b) { if (a > b) a = b; } template <class T> void chmax(T& a, const T& b) { if (a < b) a = b; } tuple<long long, long long, long long> adj[400001]; long long cnt; long long nm; int main() { long l...
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 5; const int mod = 1e9 + 7; long long n, k, arr[MAX], ans = 0; int main(int argc, char** argv) { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> k; if (n == 1) { cout << 0; exit(0); } bool mode...
#include <bits/stdc++.h> using namespace std; const int Maxn = 100005; char str[Maxn]; int slen; int cnt[Maxn]; bool was[Maxn]; int Z[Maxn]; vector<pair<int, int> > res; int main() { scanf( %s , str); slen = strlen(str); cnt[slen]++; was[slen] = true; int L = -1, R = -1; for (i...
#include <bits/stdc++.h> using namespace std; int n, m, a[1000000]; long long bank; vector<int> t; int main() { cin >> n >> m; for (int i = 0, k; i < n; i++) { cin >> k; int p = -1; bool q = false; for (int j = 0; j < k; j++) { cin >> a[j]; if (a[j] < m) p = 1; ...
//In rememberance to GOD// //May GOD take care to me,my family and all the creatures// #include<bits/stdc++.h> using namespace std; #define ll long long #define int ll #define mod ((int)1e9+7) #define pii pair<int,int> #define vi vector<int> #define vvi vector<vi> #define vc vector<char>...
#include <bits/stdc++.h> using namespace std; int n, m, q; int p[200001]; int a[200001]; vector<int> cur[200001]; int pos[200001]; int par[200001][21]; struct cmp { bool operator()(pair<int, int> a, pair<int, int> b) { return a.second > b.second; } }; priority_queue<pair<int, int>, vec...
#include <bits/stdc++.h> using namespace std; const int N = 105; vector<int> adj[N]; int a[N], d[N], din[N]; int main() { int n; scanf( %d , &n); for (int i = 0; i < n; i++) scanf( %d %d , a + i, d + i); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i == j) cont...
#include <bits/stdc++.h> using namespace std; int arr[100005]; long long sum[100005]; map<int, long long> f; long long solve(int n, int k) { if (f.count(k)) return f[k]; long long ret = 0; long long cur = n - 2; long long p = k; while (cur >= 0) { ret += sum[cur]; cur -= p; ...