func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int main() { ios_base ::sync_with_stdio(0); cin.tie(NULL); int n, m; cin >> n >> m; if (n == 1) cout << n; else cout << ((m - 1) >= (n - m) ? m - 1 : m + 1); return 0; }
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const long double PI = acos((long double)-1); long long cnt[32][2]; class Node { public: Node* child[2]; long long cnt; Node() { child[0] = child[1] = NULL; cnt = 0; } }; class Trie { private: Node...
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, /STACK:36777216 ) template <class T> inline T &RD(T &); template <class T> inline void OT(const T &); inline long long RD() { long long x; return RD(x); } inline double &RF(double &); inline double RF() { double x; ...
#include <bits/stdc++.h> using namespace std; template <class T1> void deb(T1 e1) { cout << e1 << endl; } template <class T1, class T2> void deb(T1 e1, T2 e2) { cout << e1 << << e2 << endl; } template <class T1, class T2, class T3> void deb(T1 e1, T2 e2, T3 e3) { cout << e1 << << e...
#include <bits/stdc++.h> using namespace std; const int N = 200005; int arr[N], f[N]; int main() { int n; scanf( %d , &n); set<int> st; for (int i = 1; i <= n; ++i) { st.insert(i); scanf( %d , arr + i); } st.insert(n + 1); int q; scanf( %d , &q); int t, x, v; ...
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define pb push_back #define ll long long #define all(x) x.begin() , x.end() #define rep(i,s,e) for (int i = s; i < e; ++i) #define rev(i,s,e) for (int i = s; i > e; --i) const int N = 2e5 + 99 ; int main() { ...
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; long long g = n - 1, res = 0; while (g > 0 && k > 0) { res += g * 2 - 1; k--; g -= 2; } cout << res; return 0; }
#include <bits/stdc++.h> using namespace std; vector<int> tmp; vector<vector<int>> sol[4]; int lov[7][7]; int hero(string s) { if (s == Troll ) return 0; if (s == Dracul ) return 1; if (s == Anka ) return 2; if (s == Snowy ) return 3; if (s == Hexadecimal ) return 4; if (s == Cha...
#include <bits/stdc++.h> using namespace std; int main() { int i, n; scanf( %d , &n); for (i = 1; i <= 4; ++i) { int m1, m2, a, b; scanf( %d%d , &a, &b); m1 = min(a, b); scanf( %d%d , &a, &b); m2 = min(a, b); if (m1 + m2 <= n) { printf( %d %d %d n , i, m1, n -...
#include <bits/stdc++.h> using namespace std; const int INF = 1 << 29; const double EPS = 1e-9; const char *crop[3] = { Carrots , Kiwis , Grapes }; int m, n, nw, nq; int main() { scanf( %d%d%d%d , &m, &n, &nw, &nq); set<int> waste[40000]; for (int i = (0); i < (nw); ++i) { int x, y; ...
#include <bits/stdc++.h> using namespace std; const int INF = 100000000; const double eps = 1e-10; const int MAXN = 110; set<int> sx, sy; int in[10][2]; set<int>::iterator it1, it2; int main() { int x, y; for (int i = 0; i < (8); ++i) { scanf( %d%d , &x, &y); in[i][0] = x; in[i...
#include <bits/stdc++.h> using namespace std; int main() { int t; long long int a, b, c; cin >> t; while (t--) { cin >> a >> b >> c; long long int max_val = (a + c); long long int min_val = b; if (a + c <= b) { cout << 0 << endl; } else if (b + c < a) { ...
#include <bits/stdc++.h> using namespace std; const int N = 110; long long read(void) { char ch = getchar(); long long sum = 0; bool f = 0; while ((ch < 0 || ch > 9 ) && ch != - ) ch = getchar(); if (ch == - ) { f = 1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) s...
#include <bits/stdc++.h> int main(void) { int a[5]; int Min; while (scanf( %d%d%d%d%d , a, a + 1, a + 2, a + 3, a + 4) != EOF) { Min = a[0]; if (a[1] < Min) Min = a[1]; if (a[2] / 2 < Min) Min = a[2] / 2; if (a[3] / 7 < Min) Min = a[3] / 7; if (a[4] / 4 < Min) Min = a[4] / 4;...
#include <bits/stdc++.h> using namespace std; using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << : << arg1 << n ; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = s...
#include <bits/stdc++.h> using namespace std; int n, ar[1000001], x, ars[1000001]; int main() { cin >> n >> x; for (int i = 0; i < n; i++) { cin >> ar[i]; ars[ar[i]]++; } long long ans = 0; for (int i = 0; i < n; i++) { ars[ar[i]]--; ans += (ars[(ar[i] ^ x)]); } ...
#include <bits/stdc++.h> const int MaxN = 300; using namespace std; int n, m; long long K; int A1[MaxN + 5][2], A3[MaxN + 5][MaxN + 5]; const long long INF = 1e18; long long A2[MaxN + 5][MaxN + 5]; int fail[MaxN + 5]; void Get(string s) { int z = (int)s.length(); fail[0] = 0; for (int i = ...
#include <bits/stdc++.h> using namespace std; int a, b, c, d, i; int digits(int n) { int d = 0; while (n) { n /= 10; d++; } return d; } int main() { cin >> a >> b; c = a; d = digits(b); for (i = 1; b; i++) { c += (b % 10) * (int)floor(pow((double)10, (double)d...
#include <bits/stdc++.h> using namespace std; int n; int main() { multiset<int> Q; cin >> n; long long ans = 0; long long times = 0; bool b = false; int count = 0; for (int i = 0; i < n; i++) { int x; cin >> x; if (Q.size() == 0 || (*Q.begin()) > x) { Q.insert...
#include <bits/stdc++.h> using namespace std; int read() { char ch = getchar(); int x = 0; while (ch < 0 || ch > 9 ) ch = getchar(); while (ch >= 0 && ch <= 9 ) x = x * 10 + ch - 0 , ch = getchar(); return x; } const int maxn = 2e5 + 5, inf = 1e9; struct Data { int next, to, w; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5; const int INF = 0x3f3f3f3f; long long get(long long n) { long long res = 2; long long ans = 0; while (res <= n) { ans += n / res; res *= 2; } return ans; } int main() { long long n; cin >> n; long...
#include <bits/stdc++.h> using namespace std; void solve() { int n, k; cin >> n >> k; set<int> s; for (int i = 0; i < n; i++) { int a; cin >> a; s.insert(a); } if (s.size() > k) { cout << -1 << endl; return; } cout << n * k << endl; for (int i = 0; i...
#include <bits/stdc++.h> using namespace std; long parent[100]; long nm[100]; vector<long> v[100]; long pp(long z) { if (parent[z] == z) { return z; } else { parent[z] = pp(parent[z]); } } int main() { long i, j, k, l, m, n, p, two, one; scanf( %ld%ld , &n, &m); for (i ...
#include <bits/stdc++.h> using namespace std; int compare(const void* pa, const void* pb) { long long int p1 = *(const long long int*)pa; long long int p2 = *(const long long int*)pb; if (p1 < p2) return 1; else if (p1 > p2) return -1; else if (p1 == p2) return 0; } long lo...
#include <bits/stdc++.h> using namespace std; int n, m; char s[505]; int sz; int val[505]; int ch[505][11]; void insert() { int f, k = 0; scanf( %s%d , s, &f); for (int i = 0; s[i]; ++i) { int c = s[i] - 0 ; if (!ch[k][c]) ch[k][c] = ++sz; k = ch[k][c]; } val[k] += f...
#include <bits/stdc++.h> using namespace std; const int LEN = (int)1e5; int n; long long a[LEN]; vector<int> g[60]; int bfs(int r, int t) { queue<int> q; static int d[LEN]; memset(d, 0, sizeof d); q.push(r); d[r] = 1; while (!q.empty()) { int u = q.front(); q.pop(); ...
#include <bits/stdc++.h> using namespace std; int main() { int s[10], a, b, c; cin >> a >> b >> c; s[0] = a + (b * c); s[1] = a * (b + c); s[2] = a * b * c; s[3] = (a + b) * c; s[4] = a + b + c; s[5] = (a * b) + c; sort(s, s + 5, greater<int>()); cout << s[0] << endl; ret...
#include <bits/stdc++.h> using namespace std; template <class T> T __trace(string s, T x) { cerr << s << x << endl; return x; } template <class T> ostream& operator<<(ostream& os, const vector<T>& v) { for (T x : v) os << x << ; return os; } template <class T> istream& operator>>(is...
#include <bits/stdc++.h> using namespace std; template <typename T> inline void _read(T& x) { char ch = getchar(); bool sign = true; while (!isdigit(ch)) { if (ch == - ) sign = false; ch = getchar(); } for (x = 0; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - 0 ; ...
#include <bits/stdc++.h> using namespace std; set<string> S; void flip(string& s1) { char temp = s1[0]; for (int i = 1; i < 4; i++) s1[i - 1] = s1[i]; s1[3] = temp; return; } bool isFirst(string s1) { for (int i = 0; i < 4; i++) { if (S.find(s1) != S.end()) return false; flip(s...
#include <bits/stdc++.h> using namespace std; inline void Boost() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } const int NMax = 1e5 + 50; struct Event { int d, w, t; bool operator<(const Event &e) const { if (w != e.w) return w > e.w; return d > e.d; } ...
#include <bits/stdc++.h> using namespace std; const int N = 2510; const int INF = 0x3f3f3f3f; int prime[400]; bool isprime[N]; int k; void init() { k = 0; for (int i = 2; i <= N; i++) { if (!isprime[i]) { prime[k++] = i; for (int j = i + i; j <= N; j += i) isprime[j] = 1; ...
#include <bits/stdc++.h> using namespace std; class Node { public: int vol, l, r, tot; Node(int val) { tot = vol = val; l = r = 0; } Node() { tot = vol = 0; l = r = 0; } }; int main() { int H, q; cin >> H >> q; vector<Node> tree(1); string s; in...
#include <bits/stdc++.h> using namespace std; void solve() { long long int n; cin >> n; long long int a, c1 = 0, c2 = 0, c3 = 0; vector<long long int> v1; vector<long long int> v2; vector<long long int> v3; for (int i = 1; i <= n; i++) { cin >> a; if (a == 0) { v3.pus...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int w, h; cin >> w >> h; int ans = 1; for (int i = 0; i < w + h; i++) { ans = (ans * 2) % 998244353; } cout << ans % 998244353 << n ; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int sum = 0; string s; for (int i = 0; i < n; i++) { cin >> s; if (s == Icosahedron ) sum += 20; else if (s == Dodecahedron ) sum += 12; else if (s == Octahedron ) sum +...
#include <bits/stdc++.h> using namespace std; mt19937 rng(std::chrono::duration_cast<std::chrono::nanoseconds>( chrono::high_resolution_clock::now().time_since_epoch()) .count()); const long long int N = 20005; const long long int LG = 22; long long int n, m; long long in...
#include <bits/stdc++.h> using namespace std; string out; long long int T; unsigned canDo1[5000 / 32 + 1], canDo2[5000 / 32 + 1]; unsigned *cd1 = canDo1, *cd2 = canDo2, *sw; int A[5000]; list<int> P; int N; void process() { cin >> N; N *= 2; P.clear(); for (int i = 0; i < N; i++) cin >...
#include <bits/stdc++.h> using namespace std; long n, k, bd, s, ar[6000], ans, calc[1200000]; long lst[1200000]; long del; long q; void check(long mod) { del = 0; for (int i = 1; i <= n; i++) { q = ar[i] % mod; if (lst[q] == mod) ++del; else lst[q] = mod; if (...
#include <bits/stdc++.h> using namespace std; template <typename T> inline istream &operator>>(istream &s, vector<T> &v) { for (T &t : v) { s >> t; } return s; } template <typename T> inline ostream &operator<<(ostream &s, const vector<T> &v) { for (int i = 0; i < int(v.size()); ++i) {...
#include <bits/stdc++.h> using namespace std; int n, q, k; struct node { int c[2], fa, siz, tot; int val, id, mid, mv; bool rev; node() { rev = false; } } t[600010]; void maintain(int rt) { t[rt].siz = t[t[rt].c[0]].siz + t[t[rt].c[1]].siz + t[rt].tot; t[rt].mid = t[rt].id; t[rt].m...
#include <bits/stdc++.h> using std::cerr; const int N = 998244, M = 1001; int n, m, d[N], las[N], seq[N], cnt[M][M], blo, x[N], y[N]; inline void add(int a, int b, int val) { seq[a] += val, seq[b + 1] -= val; } signed main() { std::ios::sync_with_stdio(0); scanf( %d%d , &n, &m), blo = sqrt(m); for...
#include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #include<cstring> #include<queue> #define ll long long using namespace std; const int N=310,M=100005,mod=1e9+7; int n,tot; ll inv,ans; int head[N],ver[M],Nxt[M],dep[N],fa[N][20]; ll f[N][N]; void add(int x,int y){ ver[+...
#include <bits/stdc++.h> using namespace std; int lcp[25][25]; int b[25]; string s[25]; int ans = 0; void BT(int now, int n, int k) { if (now == n) { int have = 0; for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) if (b[i] && b[j]) have += lcp[i][j]; ans = m...
#include <bits/stdc++.h> using namespace std; pair<double, double> arr[1000]; int n; double m, r; void solve() { vector<pair<int, int> > v; double h = m; int t = 0; while (h > 0) { int best_i = -1; for (int i = 0; i < n; ++i) { if (arr[i].first >= h) { if (best_i ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:128777216 ) const int null = 0; using namespace std; template <class T> int size(const T &a) { return int(a.size()); } template <class T> T abs(const T &a) { return (a < 0 ? -a : a); } template <class T> T sqr(const T &a) { retur...
#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 N = 4e5; vi cnt(N, 0); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int a; cin >> a; string s...
#include <bits/stdc++.h> using namespace std; inline int read() { int f = 1, res = 0, ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) res = res * 10 + ch - 48, ch = getchar(); return f * res; } int _sta[1 << 8...
#include <bits/stdc++.h> using namespace std; const int SZ = 2000010; const int INF = 1e9 + 10; const int mod = 1e9 + 7; const long double eps = 1e-8; long long read() { long long n = 0; char a = getchar(); bool flag = 0; while (a > 9 || a < 0 ) { if (a == - ) flag = 1; a = g...
#include <iostream> #include <cmath> using namespace std; int main() { int t; cin >> t; while(t--) { int xa, ya, xb, yb, xf, yf; cin >> xa >> ya >> xb >> yb >> xf >> yf; if(xa==xb && xb==xf && yf > ya && yf < yb) ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:102400000,102400000 ) using namespace std; const int mo = 1000000007; const int inf = 0x3f3f3f3f; const int INF = 2000000000; int n, m, phi; int lt[100008], size[100008], f[100008], vis[100008], a[100008], b[100008], sum, tot, root, pre1[10000...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, x1, y1, x2, y2; scanf( %d%d%d%d%d%d , &n, &m, &x1, &y1, &x2, &y2); int x, y; x = abs(x1 - x2); y = abs(y1 - y2); if (x > y) swap(x, y); if (y < 4) { cout << First << endl; return 0; } if (x < 3 && ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 55; int n, m; int a[MAXN]; double dp[MAXN][MAXN][MAXN]; double C[MAXN][MAXN]; void init() { C[0][0] = 1.0; for (int i = 1; i <= 50; i++) { C[i][0] = 1.0; for (int j = 1; j <= i; j++) C[i][j] = C[i - 1][j - 1] + C[i - 1][j];...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, i, j; long long int sum = 0, x; cin >> n >> m; int a[n][m]; for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { cin >> a[i][j]; } } for (i = n - 2; i >= 1; i--) { for (j = m - 2; j >= 1; j--) {...
#include <bits/stdc++.h> using namespace std; double f(double m, vector<int> &v) { int n = v.size(); vector<long double> v2(n); for (int i = 0; i < (n); i++) v2[i] = v[i] - m; long double mx_otr = 0; long double mn_otr = 0; long double cur = 0; for (int i = 0; i < (n); i++) { cur +...
#include <bits/stdc++.h> using namespace std; const int N = 300005; int n, tt, rt, ans, ls[N], rs[N], val[N], tg[N], rd[N]; inline int nw(int v) { val[++tt] = v; rd[tt] = rand(); return tt; } inline void add(int x, int v) { val[x] += v; tg[x] += v; } inline void dn(int x) { add(l...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6; char buff[MAXN + 5]; string input, subs; int freq[10]; int counter(int num) { int ret = 0; while (num) { ret++; num /= 10; } return ret; } string res; bool flag; void solve(bool taken) { for (int i = ...
#include <bits/stdc++.h> using namespace std; void B(); int main() { ios::sync_with_stdio(0); cout.tie(0); cin.tie(0); B(); } class segmen { public: long long x1, y1, x2, y2; segmen(long long xx1, long long yy1, long long xx2, long long yy2) : x1{xx1}, x2{xx2}, y1{yy1}, y2{y...
#include <bits/stdc++.h> using namespace std; const long long N = 50; long long fac[N + 1]; void init() { fac[0] = 1; for (long long i = 1; i <= N; i++) { fac[i] = (i * fac[i - 1]) % 1000000007LL; } } long long pw(long long a, long long e) { if (e == 0) { return 1; } long...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; string s; cin >> s; char a, b; a = s[0]; b = s[s.length() - 1]; int j = s.length() - 2; int i = 0; int maxcount = 0; while (j - i >= 0) { int k1 = j - i; int k = s[k1]; i...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, d, t, result, stored = 0; cin >> n >> d; for (int i = 0; i < n; i++) { cin >> t; stored += t; } d -= (n - 1) * 10; if (d - stored >= 0) { cout << (n - ...
#include <bits/stdc++.h> using namespace std; void solution() { long long n; long long k; cin >> n >> k; vector<long long> v(n); for (long long i = 0; i < n; i++) cin >> v[i]; long long sum = 0; sort(v.begin(), v.end()); for (long long i = 0; i < (k); i++) { sum += (v[n - k - 1...
#include <bits/stdc++.h> using namespace std; int Get() { char c; while (c = getchar(), (c < 0 || c > 9 ) && c != - ) ; bool Flag = (c == - ); if (Flag) c = getchar(); int X = 0; while (c >= 0 && c <= 9 ) { X = X * 10 + c - 48; c = getchar(); } return Flag ?...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; namespace StrAlgo { vector<int> Kmp(string s) { int n = (int(s.size())); vector<int> ans(n + 1); for (int i = 2; i <= n; i++) { ans[i] = ans[i - 1]; while (ans[i] > 0 && s[ans[i]] != s[i - 1]) ans[i] = ans[ans[i]]; ...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const double EPS = 1e-9; const long long MOD = 100000000; const int N = 300009; const int N2 = 300009; void fast() { std::ios_base::sync_with_stdio(0); } int main() { long long n, m; long long x = 0; scanf( %lld%lld ...
#include <bits/stdc++.h> using namespace std; const int N = 21; int n; long long s, a[N], down = 1, ans; void exgcd(long long a, long long b, long long &x, long long &y) { if (b == 0) { x = 1, y = 0; return; } exgcd(b, a % b, y, x); y -= a / b * x; } long long inv(long long x) ...
#include <bits/stdc++.h> using namespace std; const int N = 500001; const int oo = 1e9; const int LOGN = 20; const int MOD = 1000000007; const double PI = acos(-1); int n, a[N]; int main() { cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i]; } int mn = oo, idx = -1; for (int ...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const double EPS = 1e-6; const int MOD = 1e9 + 7; const int MAXN = 1100001; const double PI = acos(-1.0); long long ipt[MAXN]; long long lsum[MAXN], rsum[MAXN]; long long sum[MAXN]; int main() { long long n, len; while...
#include <bits/stdc++.h> using namespace std; using cat = long long; int main() { cin.sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10); int N, MX = 500000; cin >> N; vector<cat> A(N); for (int i = 0; i < N; i++) cin >> A[i]; sort(begin(A), end(A)); vector<int> ...
#include <bits/stdc++.h> using namespace std; const int N = 4e4; int main() { ios::sync_with_stdio(false); int n; while (cin >> n) { int a[12]; for (int i = 0; i < n; ++i) cin >> a[i]; sort(a, a + n); long long p = clock(); while (clock() - p < 1400) ; cout ...
#include <bits/stdc++.h> using namespace std; class DTrie { int N = 30; struct node { node* left = nullptr; node* right = nullptr; int cnt = 0; }; void _add(node* cur, int a, int p) { cur->cnt++; if (p == -1) return; if (a & (1 << p)) { if (cur->right == n...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int i = 0; i < t; i++) { int s, tens, sum = 0; cin >> s; for (; s > 0;) { tens = s / 10; s -= tens * 10; s += tens; sum += tens * 10; if (s >= 10 && s <= 18) { ...
#include <bits/stdc++.h> using std::map; using std::max; using std::min; using std::set; using std::sort; using std::swap; using std::vector; inline int readInt() { int ans = 0; char c; do c = getchar(); while (!isdigit(c)); while (isdigit(c)) { ans = ans * 10 + c - 0 ; ...
#include <bits/stdc++.h> const int N = 4e6 + 10; int idx[N], rank[N]; struct Point { int x, y; } A[N], Line[N]; inline double slope(Point a) { return double(A[a.x].y - A[a.y].y) / double(A[a.x].x - A[a.y].x); } inline long long area(Point A, Point B, Point C) { return fabs(1LL * (A.x - C.x) * ...
#include <bits/stdc++.h> using namespace std; int N; pair<int, int> Result[100005]; bool Use[100005]; int counter, Array[100005]; void buildArray(int prime) { Array[0] = 0; for (int k = prime; k <= N; k += prime) { if (Use[k] == 0) { Array[++Array[0]] = k; Use[k] = 1; } ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base ::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n; cin >> n; vector<long long> a(n); long long i, j; for (i = 0; i < n; i++) cin >> a[i]; sort(a.begin(), a.end()); for (i = 0; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int a[10][10]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { cin >> a[i][j]; } } int x1 = a[0][1] + a[0][2]; int x2 = a[1][0] + a[1][2]; int x3 = a[2...
#include <bits/stdc++.h> using namespace std; struct point { double x, y; point(double x = 0, double y = 0) : x(x), y(y) {} point operator-(const point &b) const { return point(x - b.x, y - b.y); } double operator*(const point &b) const { return x * b.y - y * b.x; } }; point p[200050]; int a[2...
#include <bits/stdc++.h> using namespace std; const int N = 1e9; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; int a[n + 5]; long long ans = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; ans += a[i] * a[i]; } sort(a + 1, a...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int maxn = (1 << 22) + 5; bool vis[maxn << 2][2]; int n, m; int a[maxn]; bool p[maxn]; void dfs(int id, int s) { if (vis[id][s]) return; vis[id][s] = 1; for (int i = 0; i < n; i++) { if (id & (1 << i)) { ...
#include <bits/stdc++.h> int main(int argc, char* argv[]) { int t, cups = 0, medals = 0, n, shelives_needed = 0; for (int i = 0; i < 3; i++) { scanf( %d , &t); cups += t; } for (int i = 0; i < 3; i++) { scanf( %d , &t); medals += t; } scanf( %d , &n); if (cups % 5 !...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx ) using namespace std; int a, b, c, d, n, m, k; long long pc[1000001]; long long dp[7][333335]; int f[6]; const int N = 333333; const long long infll = (long long)1000000000 * 1000000000...
#include <bits/stdc++.h> using namespace std; bool vis[10000001]; int gcd(int a, int b) { return (b == 0 ? a : gcd(b, a % b)); } int lcm(int a, int b) { return ((a * b) / gcd(a, b)); } int main() { int n; scanf( %d , &n); int sum = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; ...
#include <bits/stdc++.h> using namespace std; vector<vector<int> > re; vector<pair<int, int> > e, o; int n, c[404][404], sink, Find, pre[404], flow; bool ch[100009], visit[404]; void init() { for (int i = 2; i * i <= 100000; i++) { if (!ch[i]) { for (int j = i * i; j <= 100000; j += i) ch[...
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int max = INT_MIN, min = INT_MAX; for (int i = 0; i < N; ++i) { int x; cin >> x; if (x > max) max = x; if (x < min) min = x; } cout << max - min + 1 - N << endl; }
#include <bits/stdc++.h> using namespace std; long long a, b[1001], c, cnt1, cnt2, d, n, m; string s; int main() { cin >> a; if (a == 1) { cout << 1; return 0; } for (int i = 1; i <= a; i++) { cin >> b[i]; c += b[i]; } sort(b + 1, b + a + 1); reverse(b + 1, b ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 20; const int MAXX = 65536; int n, m; long long year; vector<int> graph[MAXN], rev_graph[MAXN]; vector<int> sol; long long dp[MAXX]; long long countPermutations(int mask, int pos) { dp[0] = 1; for (int i = 1; i < 1 << (n - pos); ++...
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long m = 0, a = 1, b = 1, ans = 0; while (m <= n) { m = a + b; a = b; b = m; ans++; } cout << ans - 1; return 0; }
#include <bits/stdc++.h> using namespace std; const int MaxN = 1e5; const int Inf = 1 << 30; double a[105]; int main() { int n, cnt; double pos, pp, ans, sum; while (~scanf( %d , &n)) { sum = 0; pos = 4.5; pos *= n; for (int i = 1; i <= n; i++) { scanf( %lf , &a[i])...
#include <bits/stdc++.h> using namespace std; int n; vector<int> tree[300003]; int colors[300003]; int blueC[300003]; int redC[300003]; int ans = 0; pair<int, int> dfs(int nd, int pr) { int blue = (colors[nd] == 2); int red = (colors[nd] == 1); for (int i = 0; i < (int)tree[nd].size(); i++) ...
#include <bits/stdc++.h> using namespace std; int n, p[50], sz[50], v[50], id[50], ct, lg[(1 << 24)], bc[(1 << 24)]; unsigned int f[(1 << 24)], av[50]; char s[50][50]; vector<int> vc[50]; int fd(int x) { return p[x] == x ? x : p[x] = fd(p[x]); } int main() { scanf( %d , &n); for (int i = 1; i <= n...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int MAX = 1123; int ans[MAX]; int main() { int n; cin >> n; memset(ans, INF, sizeof(ans)); for (int i = 0; i < 10; i++) { vector<int> data1, data2; for (int j = 1; j <= n; j++) { if (j & (1 << i...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int r, c, i, j, flag = 0; cin >> r >> c; char a[r + 2][c + 2]; for (i = 0; i < (r + 2); i++) { for (j = 0; j < (c + 2); j++) a[i][j] = . ; } for (i =...
#include <bits/stdc++.h> using namespace std; int n, m, k; vector<int> adj[100005]; int din[100005]; queue<int> que; int Vec[100005], V_size; int a, b, c, d, cur; bool succ; int main() { int Test; scanf( %d , &Test); while (Test--) { scanf( %d%d%d , &n, &m, &k); for (int i = 1;...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; int n, num, ctr; string s; while (t--) { cin >> n >> s; num = 0; ctr = 0; for (char ch : s) { if (ch == ) ) { ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; cin >> t; while (t--) { int n, m, i, x = 0, y, z; cin >> n; string s[n + 1]; for (int i = 0; i < n; i++) cin >> s[i]; vector<pa...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007LL; const long long MXSZ = 1000000LL; long long fpow(long long b, long long e) { long long ret = 1; while (e > 0) { if (e & 1) (ret *= b) %= mod; (b *= b) %= mod; e >>= 1; } return ret; } long lon...
#include <bits/stdc++.h> using namespace std; long long dist[200001] = {0}; int n, ans[200001], Val[200001], lg, tree[200001][20]; vector<vector<pair<int, long long> > > G(200001); void Build(int v, int par = 0) { tree[v][0] = par; for (int i = 1; i <= lg; i++) tree[v][i] = tree[tree[v][i - 1]][i - 1]...
#include <bits/stdc++.h> using namespace std; string A, B; int used[10][2]; int memo[10][2]; int m; int dp(int pos, int mayor) { if (pos == m) return mayor; if (used[pos][mayor]) return memo[pos][mayor]; used[pos][mayor] = 1; int &dev = memo[pos][mayor] = 0; if (B[pos] == ? ) { if...
#include <bits/stdc++.h> using namespace std; struct ufds { int n; vector<int> p, s; ufds(int n = 0) : n(n), p(n), s(n, 1) { for (int i = 0; i < n; i++) p[i] = i; } int findSet(int i) { return p[i] == i ? i : (p[i] = findSet(p[i])); } bool inSameSet(int i, int j) { return findSet(i) ==...