func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; ifstream f( text.in ); int t, coada[26 * 2 + 5], p, u, n, ind, frecventa[26 + 5], imposibil; string sir; int main() { cin >> t; while (t--) { cin >> sir; n = sir.size(); p = u = 26; coada[p] = sir[0] - a + 1; frecventa[sir[0...
#include <bits/stdc++.h> using namespace std; struct c { long long f, s, i; }; bool com(c a, c b) { return (a.f + b.s < a.s + b.f); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); long long n, i, m, u, v; cin >> n >> m; vector<c> cp(n); for (i = 0; i < n; i++) { ...
#include <bits/stdc++.h> const int N = 3e5 + 10; const int mod = 1e5 + 7; using namespace std; int a[N], b[N]; pair<long long, int> dp[N][2]; void solve() { int n; scanf( %d , &n); for (int i = 1; i <= n; ++i) scanf( %d%d , &a[i], &b[i]); dp[1][0] = {0, a[1]}; dp[1][1] = {b[1], a[1] + 1}...
#include <bits/stdc++.h> using namespace std; int T, n, k; char s[10]; int chk(int l1, int r1, int l2, int r2) { printf( ? %d %d n , r1 - l1 + 1, r2 - l2 + 1); for (int i = l1; i <= r1; i++) printf( %d , i); putchar( n ); for (int i = l2; i <= r2; i++) printf( %d , i); putchar( n ); ...
#include <bits/stdc++.h> using namespace std; int memo[4][10000011]; int path; int main() { scanf( %d , &path); memo[0][path] = 1; for (int i = path - 1; i >= 0; i--) { for (int j = 0; j < 4; ++j) for (int k = 0; k < 4; ++k) { if (j != k) { memo[j][i] = (memo[j][i...
#include <bits/stdc++.h> using namespace std; char a[1100], b[1100][1100]; const int inf = 2000000000; int c[1100], len[1100], f[1100][1100], sum[1100], ran[2][1100], to[1100], d[1100], n, m, fr[1100]; int cal(int i) { int j, res = 0; for (j = len[i]; j > m; j--) res += c[b[i][j] - 0 ]; ret...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; const int MOD = 1000000007; int x[3], y[3]; pair<int, int> p; int main() { ios_base::sync_with_stdio(false); cin.tie(0); for (int i = (0); i <= (2); i++) cin >> x[i] >> y[i]; int ans = INT_MAX; for (int i = (0); i <= ...
#include <bits/stdc++.h> using namespace std; const int MN = 200005; int N, M; int A[MN]; int main() { scanf( %d %d , &N, &M); for (int i = 1; i <= N; i++) scanf( %d , &A[i]); sort(A + 1, A + 1 + N); while (M--) { int X, Sol = 0; scanf( %d , &X); for (int it = 1 << 18; it; it...
#include <bits/stdc++.h> using namespace std; int a, b, c, d, e; int main() { cin >> a >> b >> c >> d >> e; int t = min(a, min(b, min(c / 2, min(d / 7, e / 4)))); cout << t << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int t, memo[402][402][402], idx, n, m; string x, y; void read(string &s) { char c[404]; scanf( %s , c); s = c; } int dp(int i, int j, int k) { if (i == n) { if (k == m) return j; else return -10; } int &ret = m...
#include <bits/stdc++.h> using namespace std; int main() { long long int i, j, k, n, m, a1 = 0, a0 = 0, a2 = 0, c = 0, d; vector<char> vc, s; char a; vector<long long int> vi; while (cin >> a) { s.push_back(a); } for (i = 0; i < s.size(); i++) { if (s[i] == ( ) a1++;...
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, i; cin >> n >> m; i = n / 2 + (n & 1); i = (m >= i) ? 0 : n - 2 * m; cout << i << ; if (!m) { cout << n; return 0; } for (i = 1; ((i * (i - 1)) / 2) < m; i++) ; cout << n - i; retu...
#include <bits/stdc++.h> int a[100005] = {}; int b[100005] = {}; std::vector<int> ans; std::vector<std::pair<int, int> > arr; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); std::cout.tie(NULL); int n, li = -1; std::cin >> n; for (int i = 0; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; char mp[1005][1005]; char p[4] = { A , B , C , D }; int n, m; int main() { int i, j, k; while (scanf( %d%d , &n, &m) != EOF) { for (i = 0; i < n; i++) scanf( %s , mp[i]); bool flag = false; for (i = 0; i < n; i++) { for (j = 0;...
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, k, a; scanf( %I64d%I64d%I64d , &n, &m, &k); if (n + m - 2 < k) printf( -1 ); else { if (n > m) { a = n; n = m; m = a; } if (n >= k + 1) { printf( %I64d , max((m / (k + 1...
#include <bits/stdc++.h> using namespace std; long long n; signed main() { long long ans; cin >> n; n++; if (n == 1) ans = 0; else if (n % 2 == 0) ans = n / 2; else ans = n; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int r, c, n, k; scanf( %d%d%d%d n , &r, &c, &n, &k); int a[r][c]; for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { a[i][j] = 0; } } int x, y; for (int i = 0; i < n; i++) { scanf( %d %d n , &x,...
#include <bits/stdc++.h> bool solve(int *c, int *ans) { if (c[5] || c[7]) return false; while (c[3] > 0) { c[3]--; if (!c[1] || !c[6]) return false; else { c[1]--, c[6]--; ans[2]++; } } while (c[1] > 0) { c[1]--; if (!c[2]) return fal...
#include <bits/stdc++.h> using namespace std; long double det(long double x, long double y, long double z, long double t) { return x * t - y * z; } long long int pow(long long int n, long long int m) { if (m == 0) return 1; if (m == 1) return n % (int)1e9 + 7; long long int t = pow(n, m / 2) % (...
#include <bits/stdc++.h> using namespace std; int n; int main() { multiset<int> Q; scanf( %d , &n); long long ans = 0; for (int i = 0; i < n; i++) { int x; scanf( %d , &x); if (Q.size() == 0 || (*Q.begin()) > x) { Q.insert(x); } else { ans += x - *Q.begin();...
#include <bits/stdc++.h> using ll = long long; using namespace std; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } template <typename T> void read(T &x) { x = 0; char ch = getchar(); ll f = 1; while (!isdigit(ch)) { if (ch == - ) f *= -1; ch = getchar(); } while (isd...
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; using vi = vector<int>; using ll = long long; int main() { ios_base::sync_with_stdio(0); cin.tie(0); vi count(3); enum { R, B, G }; map<char, int> val = {{ R , R}, { B , B}, { G , G}}; int n; cin >> n; vi...
#include <bits/stdc++.h> using namespace std; long long cq, q, c[2000 + 10][2000 + 10], cg[2000 + 10][2000 + 10], pos[2000 + 10], n, m, k, bl[2000 + 10][2000 + 10][3], cnt[2000 + 10]; template <class T> bool Read(T &x) { char c; bool f = 0; while (c = getchar(), c != EOF) { if (c == - )...
#include <bits/stdc++.h> using namespace std; const double eps = 0.5; const double pi = acos(-1.0); const long long INF = 2e18; const int maxn = 100005; int main() { int t; scanf( %d , &t); while (t--) { int n; scanf( %d , &n); n = n + n; double ans = cos(pi / (2.0 * n)) ...
#include <bits/stdc++.h> using namespace std; int aa[1005]; int bb[1005]; long long wei(long long x) { long long a = 0; while (x) { aa[a] = x % 10; x /= 10; a++; } return a; } long long wei2(long long x) { long long a = 0; while (x) { bb[a] = x % 10; x /...
#include <bits/stdc++.h> using namespace std; int main() { int s, a, b, c; cin >> s >> a >> b >> c; if (a == 0 && b == 0 && c == 0) { printf( %.10f %.10f %.10f n , s, 0, 0); } else { int sum = a + b + c; printf( %.10f %.10f %.10f n , ((double)a * s) / sum, ((double)b * s) / sum, ...
#include <bits/stdc++.h> using namespace std; struct LCT { int ch[555555][2], f[555555], tag[555555], key[555555], sum[555555], st[555555], ls[555555], rs[555555]; LCT() { for (int i = 1; i <= 550000; i++) { sum[i] = ch[i][0] = ch[i][1] = f[i] = tag[i] = key[i] = 0; } } b...
#include <bits/stdc++.h> using namespace std; const int maxS = 1 << 15; const int mod = 1e9 + 7; int n; int a[65]; int d[65]; int s[15], tots; int t[65], tott; int in[65], cnt[maxS + 5]; int f[maxS + 5][65]; int ans, st; namespace usual { int C[65][65]; int add(int ta, int tb) { return ta + ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; map<int, map<int, int>> solution; solution[1000][999999000] = 474176509; solution[1][1000000000] = 327451602; solution[4][1000000000] = 433920973; solution[750][1000000000] = 324554228; solution[1000]...
#include <bits/stdc++.h> using namespace std; template <class T> inline void maz(T &a, T b) { if (a < b) a = b; } template <class T> inline void miz(T &a, T b) { if (a > b) a = b; } template <class T> inline T abs(T a) { return a > 0 ? a : -a; } const int N = 100100, INF = 1e9; const...
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; if (b > a) { swap(a, b); } cout << b << ; int r = a - b; cout << r / 2; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); string s; cin >> s; int n = (int)s.size(); vector<vector<int>> a(26, vector<int>(n + 1)); for (int i = 1; i < n + 1; ++i) { a[s[i - 1] - a ][i] += 1; } for (int i = 0; ...
#include <bits/stdc++.h> using namespace std; long long t[505]; long long p[505][505]; long long dp[505][505]; const long long oo = 4557430888798830399LL; int main() { ios_base::sync_with_stdio(0), cin.tie(0); int n, m, k; cin >> n >> m >> k; vector<string> s(n); for (auto &i : s) cin >>...
#include <bits/stdc++.h> using namespace std; int dp[41][1 << 7][1 << 7], num[1 << 7], vis[3][30], n, m; void init() { int i, j, k; for (i = 0; i <= 40; i++) { for (j = 0; j < 1 << 7; j++) { for (k = 0; k < 1 << 7; k++) { dp[i][j][k] = -11111111; } } } } int g...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; int dcmp(double x) { if (fabs(x) < eps) return 0; return (x > 0) ? 1 : -1; } const unsigned long long hash1 = 201326611; const unsigned long long hash2 = 50331653; const int N = 1000000 + 10; const int M = 1000 + 10; const ...
#include <bits/stdc++.h> using namespace std; int n, m, k; long long pow2(int x) { if (x == 0) return 1; if (x == 1) return 2; long long h = pow2(x / 2); return (h * h * (x & 1 ? 2 : 1)) % 1000000009; } int main() { cin >> n >> m >> k; int x = n / k; int y = n % k; int z = m - ...
#include <bits/stdc++.h> using namespace std; const int maxn = 50100; unsigned long long arr[maxn]; int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); unsigned long long s = 0, res = 0; long long n; cin >> n; for (int i = 0; i < n; i++) cin >> arr[i], s += arr[i]; s ...
#include <bits/stdc++.h> using namespace std; bool prime[1000009]; vector<long long> pri; void SieveOfEratosthenes() { memset(prime, true, sizeof(prime)); for (long long p = 2; p * p <= 1000000; p++) { if (prime[p] == true) { for (long long i = p * p; i <= 1000000; i += p) prime[i] = false...
#include <bits/stdc++.h> using namespace std; const int maxn = 105, maxm = 1000005; const int inf = 0x3f3f3f3f; int f[maxn][maxn]; int p[maxm], d[maxm], pre[maxm], nxt[maxm]; int main() { int n, m; char ch; cin >> n; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { ...
#include <bits/stdc++.h> using namespace std; int n; int a[210000]; long long sum[210000]; long long calc_move(int from, int to) { return a[from] * 1ll * (to - from) - (sum[to] - sum[from]); } long long crossover(int from, int to) { long long headstart = calc_move(from, to); if (headstart < 0)...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; inline int Max(int a, int b) { return a > b ? a : b; } const int maxn = 2e5 + 20; int maxy[maxn << 2], mark[maxn], x[maxn], y[maxn]; set<int> s[maxn]; int n, m; char op[20]; vector<int> v; void build(int l, int r, int rt) { ...
#include <bits/stdc++.h> using namespace std; int32_t main() { long long q; cin >> q; for (long long i = 0; i < q; i++) { long long a, b, c; cin >> a >> b >> c; long long ans = 0; long long num = min(min(a, b), c); ans += num; a -= num; b -= num; c -= num;...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; int main() { cin.tie(0), cout.tie(0); ios::sync_with_stdio(false); int t; cin >> t; while (t--) { int n, l, r, now = 1; cin >> n; for (int i = 0; i < n; i++) { cin >> l >> r; if (now < l) {...
#include <bits/stdc++.h> using namespace std; int n, m; int nd, na; int nm; int atq[124], def[124], meu[124]; int foi[124]; int killAll() { memset(foi, 0, sizeof(foi)); for (int i = 0; i < nd; i++) { int j = 0; while (j < nm && (meu[j] <= def[i] || foi[j] == 1)) j++; if (j == nm)...
#include <bits/stdc++.h> using namespace std; long long int power(long long int x, long long int n) { if (n == 0) return 1; else if (n % 2 == 0) return power(x * x, n / 2); else return x * power(x * x, (n - 1) / 2); } long long int highestPowerof2(long long int n) { long long i...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; const int INF = 1e9 + 7; vector<int> adjList[MAXN]; vector<int> vec; bool visited[MAXN]; void dfs(int start) { visited[start] = true; for (auto u : adjList[start]) { if (!visited[u]) { dfs(u); } } v...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int x = 1, y = 1; int k = 0; cin >> k; bool fl = false; for (int i = 1; i <= n; i++) { int t; if (i != n) cin >> t; else t = 1 - k; if (t == k && fl == false) { x++...
#include <bits/stdc++.h> using namespace std; const int maxn = 200 + 5; int mp[maxn][maxn], dp[maxn][maxn], n, m; int main() { int t; scanf( %d , &t); while (t--) { memset(dp, 0, sizeof dp); scanf( %d%d , &n, &m); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) sc...
#include <bits/stdc++.h> using namespace std; int a[654321]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; int a, b, c, d; cin >> a >> b >> c >> d; map<int, int> mapka; mapka[1] = a; mapka[2] = c; mapka[n - 1] = d; mapka[n] = b; set...
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; template <class T> int getbit(T x, int pos) { return (x >> (pos - 1)) & 1; } template <class T> void turn_on(T &x, int pos) { x = x | ((T)1 << (pos - 1)); } template <class T> void turn_off(T &x, int pos) { x = x & ~((T)1...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 100; struct Node { int a, b, id; Node() {} Node(int a, int b, int id) : a(a), b(b), id(id) {} bool operator<(const Node& th) const { return a < th.a; } } node[N]; int vis[N]; int main() { int n, m; while (scanf( %d%d ,...
#include <bits/stdc++.h> using namespace std; const int maxn = 1000 * 100; int n; pair<int, int> sora[maxn + 100]; int lpos = 0; bool seen[maxn + 100]; bool comp(pair<int, int> a, pair<int, int> b) { if (a.first < b.first) return true; else { if (a.first == b.first) return a.se...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); double fRand(double fMin, double fMax) { double f = (double)rand() / RAND_MAX; return fMin + f * (fMax - fMin); } template <class T> T min(T a, T b, T c) { return min(a, min(b, c)); } template <class T> T max(T a, ...
#include <bits/stdc++.h> using namespace std; int n, a[5005], b[5005], ans[5005], s, q[10005], x[10005]; map<int, int> m; void ask(int x, int y) { printf( ? %d %d n , x, y); fflush(stdout); } int main() { scanf( %d , &n); for (int i = 0; i < n; i++) ask(i, 0), scanf( %d , a + i), x[a[i]] = i...
#include <bits/stdc++.h> using namespace std; int32_t main() { long long n, k; cin >> n >> k; vector<long long> a(n); vector<long long> b(n); vector<long long> c(n); long long sum1 = 0; for (long long i = 0; i < n; i++) { cin >> a[i]; } for (long long i = 0; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const long long MOD = (long long)1e9 + 7; long long add(long long x, long long y) { x += y; if (x >= MOD) return x - MOD; return x; } long long sub(long long x, long long y) { x...
#include <bits/stdc++.h> using namespace std; const int maxn = 55; const int maxm = 2e4 + 5; int a[maxn][maxm], dp[maxm], nxt[maxm], sum[maxn][maxm]; int pre[maxm], suff[maxm]; int n, m, k; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m >> k; for (int i = 0; i <=...
#include <bits/stdc++.h> using namespace std; char a[51][51], b[51][51]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int ax, ay, bx, by, xx, yy, s = 0, ans = 0; cin >> ax >> ay; for (int i = 1; i <= ax; i++) { for (int j = 1; j <= ay; j++) cin >> a[i...
#include <bits/stdc++.h> using namespace std; int countbit(int a) { int i = 0; while (a != 0) { if (a & 1) i++; a /= 2; } return i; } int dp[1100000] = {0}; int main() { int a[150]; int arr[150], arr1[150] = {0}; int n, m; cin >> n; for (int i = 0; i < n; i++) c...
#include <bits/stdc++.h> using namespace std; void sol() { int n, m, k; cin >> n >> m >> k; int a[n + 1][m + 1]; for (int i = 1; i <= n; i++) for (int ii = 1; ii <= m; ii++) cin >> a[i][ii]; for (int i = 1; i <= k; i++) { int x, y; cin >> y; x = 1; while (x != n + 1...
#include<bits/stdc++.h> using namespace std; #define pii pair<int,int> #define vi vector<int> #define mii map<int,int> #define pqs priority_queue<int,vi,greater<int> > #define mod 1000000007 #define int long long #define pb ...
#include <bits/stdc++.h> using namespace std; const long long MOD = (long long)1e9 + 7; const long long MOD1 = 2286661337; const long long MOD2 = 998244353; const int INF = (int)1e9 + 7; const double EPS = 1e-7; const int N = (int)2e5; int n; long long a[N], b[N]; bool is_same_() { for (int i = ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:268435456,268435456 ) using namespace std; int above[41][41], dp[41][41][41][41]; char s[42]; int main() { int n, m, q, s1, s2, s3, s4; scanf( %d %d %d , &n, &m, &q); for (int i = 1; i <= n; i++) { scanf( %s , s + 1); for (int j ...
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> vec[300000]; int mn(int x); int mx(int x) { if (!vec[x].size()) return 0; int ret = n; for (int i = (0); i < (vec[x].size()); i++) ret = min(ret, mn(vec[x][i])); return ret; } int mn(int x) { if (!vec[x].size()) return...
#include <bits/stdc++.h> using namespace std; int T, n, m, sa[40010], sb[40010], ls, du[201], ans; bool g[201][201]; int getint() { int w = 0; bool q = 0; char c = getchar(); while ((c > 9 || c < 0 ) && c != - ) c = getchar(); if (c == - ) c = getchar(), q = 1; while (c >= 0 && c ...
#include <bits/stdc++.h> using namespace std; long long cross(pair<long long, long long> a, pair<long long, long long> b, pair<long long, long long> c) { return abs((b.first - a.first) * (c.second - a.second) - (b.second - a.second) * (c.first - a.first)); } vector<pair<long...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; s += 0 ; int c = 1; char sc = s[0]; bool xd = false; string res = ; for (int i = 1; i < s.size(); i++) { if (sc != s[i]) { if (c == 1) { res += sc; xd = false; ...
#include <bits/stdc++.h> using namespace std; int64_t mod = 1e9 + 7; int64_t mod1 = 1e9 + 6; int64_t power(int64_t a, int64_t b) { if (b == 0) return 1; else if (b % 2 == 0) return power((((a % mod) * (a % mod)) % mod), b / 2) % mod; else return ((a % mod) * (power((((a % mod) * (a...
#define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; #include<bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int t; cin>>t; while(t--){ int xa,ya,xb,yb,xf,yf; cin>>x...
#include <bits/stdc++.h> using namespace std; const int MAXN = 400; int n, m, dp[MAXN + 5][MAXN + 5]; char s[MAXN + 5], t[MAXN + 5]; inline void ckmax(int &x, int y) { x = x > y ? x : y; } int main() { int T; scanf( %d , &T); while (T--) { scanf( %s%s , s + 1, t + 1); n = strlen(s + ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); string s1, s2; cin >> s1 >> s2; if (s1.size() > s2.size()) cout << s1.size(); else if (s2.size() > s1.size()) cout << s2.size(); else if (s1 == s2) ...
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 5; int n, k, par[N]; int64_t f[N], g[N]; vector<pair<int, int> > ke[N]; vector<int64_t> c[N]; void dfs(int u) { int64_t sum = 0; for (auto e : ke[u]) if (e.second != par[u]) { int v = e.second, w = e.first; par...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; namespace SBT { const int _N = N << 2 | 1; int lc[_N], rc[_N], siz[_N], val[_N], rp[_N], rsiz[_N]; int tp, dl[_N], tot, q[_N], qc[_N]; const double alpha = 0.55; inline int _new(int v, int ct) { int u = tp ? dl[tp--] : ++tot; l...
#include <bits/stdc++.h> using namespace std; long long n, k, M, D, N, sol, x, mid, f, l, T; long long up(long long a, long long b) { long long tmp = a / b; if (a % b != 0) tmp = tmp + 1ll; return tmp; } long long rep(long long a) { long long tmp = n / a; tmp = up(tmp, k); return tmp; ...
#include <bits/stdc++.h> using namespace std; inline int max(int a, int b) { return a > b ? a : b; } inline int min(int a, int b) { return a < b ? a : b; } map<int, int> mp; int main() { int n, x; cin >> n; mp.clear(); for (int i(0); i < (n); ++i) { cin >> x; ++mp[x]; } lon...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long a[305]; int prt[305], num[305] = {0}, ha[305] = {0}; long long f[305][605] = {0}; long long c[305][305], jc[305]; int n; bool pd(int i, int j) { long long ha = sqrt(a[i] * a[j]); if (ha * ha == a[i] * a[j]) re...
#include <bits/stdc++.h> using namespace std; const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1}; const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1}; const int Mod = 1000000000 + 0; template <typename T> inline T sq(T x) { return x * x; } template <typename T> inline T In() { T x; cin >> x; return...
#include <bits/stdc++.h> const long long mod = (long long)1e9 + 7; const int maxn = (int)4e5 + 2; long long inf = 1LL << 60; const double eps = 1e-9; using namespace std; template <class N> inline void read(N &n) { N x = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (c...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const int iinf = 1 << 29; const long long llinf = 1ll << 60; const double PI = 3.14159265; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); long long mrand(long long B) { return (unsigned long long)rng() % ...
#include <bits/stdc++.h> using namespace std; int n, k; struct Poi { int x, y, ff; bool operator<(const Poi &A) const { return x < A.x || (x == A.x && y < A.y); } } pp[(200100)]; int row[(200100)], cntr; int cnt[(200100)], pre[(200100)]; long long ans[(200100)]; inline void solve() { ...
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int x, long long int y) { if (y == 0) return x; return gcd(y, x % y); } long long exp(long long a, long long b) { if (b == 0) return 1; long long res = exp(a, b / 2); if (b % 2) return res * res * a; else ...
#include <bits/stdc++.h> using namespace std; int main() { int n, a[105], sum = 0, i, j, x, k; scanf( %d , &n); for (i = 0; i < n; i++) { scanf( %d , &a[i]); sum += a[i]; } x = sum / (n / 2); for (j = 0; j < n; j++) { for (k = j + 1; k < n; k++) { if (a[j] + a[k] ==...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f, N = 1e3 + 5, MOD = 1e9 + 7; int T, cas = 0; int n, m; bool vis[N]; vector<int> primes; void Init_Primes() { memset(vis, 0, sizeof(vis)); int m = sqrt(N + 0.5); for (int i = (2); i <= (m); i++) if (!vis[i]) ...
#include <bits/stdc++.h> using namespace std; int d1[5], c1[5], d2[5], c2[5]; int min2[5], min1[5]; int main() { int n; cin >> n; for (int i = 1; i <= 4; i++) { cin >> c1[i] >> d1[i] >> c2[i] >> d2[i]; min1[i] = min(c1[i], d1[i]); min2[i] = min(c2[i], d2[i]); } int tmp = 1e...
#include <bits/stdc++.h> using namespace std; int a, x, y, xx, yy; int main() { cin >> a >> x >> y >> xx >> yy; if (abs(x - xx) == a) cout << a + min(2 * a - y - yy, y + yy); else if (abs(y - yy) == a) cout << a + min(2 * a - x - xx, x + xx); else cout << abs(xx - x) + abs(yy - y...
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, c; cin >> a >> b >> c; long long d = b * b - 4 * a * c; if (a != 0) { double x = a, y = b; if (d < 0) cout << 0; if (d == 0) { cout << 1 << endl; printf( %lf , -y / (2 * x)); } if...
#include <bits/stdc++.h> using namespace std; const int N = 200005; bitset<N> vis; int n, m, d[N], bound; vector<int> g[N]; set<int> h[N]; unsigned long long a, b, c, ans, sum[N]; inline unsigned long long get(int u, int v) { if (u > v) swap(u, v); unsigned long long x = a * u * 1LLU * (u - 1) /...
#include <bits/stdc++.h> using namespace std; int main() { int arr[200][200]; int n, m, ok = 1000000000, ans = 0; scanf( %d %d , &n, &m); for (int i = 0; i < n; i++) { ok = 1000000000; for (int j = 0; j < m; j++) { scanf( %d , &arr[i][j]); if (ok > arr[i][j]) ok = arr[i][...
#include <bits/stdc++.h> using namespace std; int main() { long long int a; cin >> a; if (a <= 1) { cout << a; } else if (a == 2) { cout << 2; } else if (a == 3) { cout << 6; } else if (a == 4) { cout << 20; } else if (a == 5) { cout << 70; } else if (a ...
#include <bits/stdc++.h> using namespace std; long long a[200001], b[200001]; int main() { int t; int i, j; cin >> t; while (t--) { long long n, m; cin >> n >> m; for (i = 0; i < n; i++) cin >> a[i] >> b[i]; long long A = 0, B = 0, Ap = 0, Bp = 0; long long tot = 0, s...
#include <bits/stdc++.h> using namespace std; int main() { int n; long long mx = 0, x = 0; cin >> n; for (int i = 0; i < n; i++) { long long y; cin >> y; y += mx; mx += max(0LL, x - y), x = max(y, x); } cout << mx << endl; return 0; }
#include <bits/stdc++.h> using namespace std; struct fastIO { inline fastIO operator>>(int& num) { num = 0; char c = getchar(); while (c != - && (c < 0 || c > 9 )) c = getchar(); bool foo = 0; if (c == - ) { foo = 1; c = getchar(); } while (c >= 0...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( avx,avx2,fma ) using namespace std; const long long MOD = 1e9 + 7; const long long mxN = 1e5 + 3; vector<long long> g[mxN]; long long good[mxN]; long long total[mxN], people[mxN]; long long h[mxN]; bool ok[mxN]; void dfs1(l...
#include <bits/stdc++.h> using namespace std; const int N = 100; int l[N], r[N], t[N], c[N]; int main() { int n, m; scanf( %d %d , &n, &m); for (int i = 0; i < m; ++i) { scanf( %d %d %d %d , l + i, r + i, t + i, c + i); } int ans = 0; for (int i = 1; i <= n; ++i) { int win = ...
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; int n, m; int clauses[123123][2]; vector<int> uses[123123]; bool vis[123123]; vector<int> chain[123123]; int counter; vector<pair<long long, long long>> dips; long long ans; int rightc(int cnr) { int xnr = abs(clauses[cn...
#include <bits/stdc++.h> using namespace std; const int MX = 3005; int n, a[MX], mem[MX][MX], ind[MX]; vector<int> pos[MX]; int dp(int i, int j) { if (i > j) return 0; int &res = mem[i][j]; if (res != -1) return res; res = dp(i, j - 1); for (int k = ind[j] - 1, x; k >= 0 && (x = pos[a[j]][...
#include <bits/stdc++.h> using namespace std; long long solve() { long long k, a, b; cin >> k >> a >> b; if (a > b) swap(a, b); if (a == 0) { if (b % k == 0) return b / k; return -1; } long long ans = a / k + b / k; if (b % k != 0 && a < k) return -1; if (a % k != 0 && b ...
#include <bits/stdc++.h> using namespace std; template <typename T> void read_to_vector(size_t N, std::vector<T> &v) { for (size_t i = 0; i < N; i++) { T tmp; std::cin >> tmp; v.push_back(tmp); } } template <typename T> void print_vector(const std::vector<T> &v) { for (auto it ...
#include <bits/stdc++.h> using namespace std; int main() { int n, v = 0, p = 0; string s, result = ; cin >> n >> s; v = (n - 11) / 2; p = v; for (int i = 0; i < n; i++) { if (s[i] == 8 ) { if (v > 0) v--; else result += s[i]; } else { ...
#include <bits/stdc++.h> using namespace std; int arr[510]; int dp[510][510]; int main() { int n; scanf( %d , &n); for (int i = 0; i <= n - 1; i++) scanf( %d , &arr[i]); for (int l = 1; l <= n; l++) { for (int i = 0; i <= n - 1; i++) { int j = i + l - 1; if (j > n - 1) cont...