func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; double Fib(double x, double z); string BinDec(unsigned long long x); string StringInt(long long x); unsigned long long StringInt(string x); unsigned long long BinDec(string x); unsigned long long POWMOD(unsigned long long x, unsigned long long y, ...
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, k; cin >> n >> m >> k; if (n + m - 2 < k) { cout << -1 n ; return 0; } long long ans = max(n * (m / (k + 1)), m * (n / (k + 1))); if ((k - m + 2) > 0) ans = max(ans, n / (k - m + 2)); if ((k - n + 2) ...
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, /STACK:667772160 ) 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 ...
#include <bits/stdc++.h> using namespace std; const int NN = 1000007; vector<int> adj[NN]; int vst[NN], ans[NN]; int main() { int n, m; scanf( %d%d , &n, &m); for (int i = 1; i <= m; i++) { int u, v; scanf( %d%d , &u, &v); adj[u].push_back(v); } for (int i = 1; i <= n; i+...
#include <bits/stdc++.h> using namespace std; int q; long long L, R; vector<long long> vec, vec2; long long solve(long long x); set<int> st; void precalc() { for (long long i = 2; i <= 1e6; i++) { for (long long j = i * i * i; j <= 1e18; j *= i) { vec.push_back(j); if (j > (1e18)...
#include <bits/stdc++.h> using namespace std; const long long INF = (1e18); const int N = (2 * (1e5)); int n; string s; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; pair<int, int> p[n]; for (int i = 0; i < n; i++) { cin >> p[i].first; ...
#include <bits/stdc++.h> using namespace std; const int inf = -0x3ffffff; const int maxn = 5e6 + 5; int fa[maxn]; int fin(int x) { if (x == fa[x]) return x; return fa[x] = fin(fa[x]); } long long n, m; long long vis[maxn]; const long long mod = 1e9 + 7; long long get(long long x, long long y...
#include <bits/stdc++.h> using namespace std; struct Dbg { template <typename T> Dbg& operator,(const T& v) { cerr << v << , ; return *this; } } Dbg; template <typename T> ostream& operator<<(ostream& _o_, const vector<T>& _v_) { if (!_v_.empty()) { _o_ << [ ; copy(_...
#include <bits/stdc++.h> using namespace std; vector<int> adj[300005]; int indeg[300005]; queue<int> q; int dp[300005][26], ma = 1; string s; int n, m, x, y, cnt = 0; bool co = 1; int main() { cin >> n >> m; cin >> s; for (int i = 0; i < m; i++) { cin >> x >> y; x--; y--;...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC target( sse4 ) using namespace std; const int mxN = 2e5 + 5; const long long inf = 1e18; template <class T> T gcd(T a, T b) { return ((b == 0) ? a : gcd(b, a % b)); } pair<int, long long> dp[2][4]; long long mn[mxN], mx[mxN]; int ...
#include <bits/stdc++.h> #define pb push_back #define pf push_front #define fi first #define se second using namespace std; typedef long long ll; int main() { ios::sync_with_stdio(0); cin.tie(0); ll t, n, k; cin >> t; while(t--) { cin >> n >> k; for(ll i=1;...
#include <bits/stdc++.h> using namespace std; const int N = 200 * 1000 + 13; int n; int a[N]; void get(long long T, long long& pr, long long& cnt) { pr = 0, cnt = 0; for (int i = 0; i < int(n); i++) { if (T >= a[i]) { T -= a[i]; pr += a[i]; ++cnt; } } } int ...
#include <bits/stdc++.h> using namespace std; const int oo = 0x3f3f3f3f; const long long OO = 1LL << 61; const int MOD = 1000000007; long long dp[1005][20005]; int a[1005]; int main() { int n; while (scanf( %d , &n) != EOF) { for (int i = 1; i <= n; i++) scanf( %d , &a[i]); memset(dp, ...
#include <bits/stdc++.h> using namespace std; long long x, y, p, q; int main() { int t; scanf( %d , &t); int x, y, p, q; while (t--) { scanf( %d %d %d %d , &x, &y, &p, &q); if (p == q) { printf( %d n , x == y ? 0 : -1); continue; } if (p == 0) { prin...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int Maxn = (1 << 23) + 5; const int N = 50; const int M = 24; int read() { int s = 0, f = 1; char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) f = -1; c = getchar(); } while (c >= 0 ...
#include <bits/stdc++.h> using namespace std; const int K = 5; const int Mod = 1e9 + 7; void add(int &a, long long b) { a = (a + b) % Mod; } long long encode(const vector<int> &p) { assert(p.size() == K); long long x = 0; for (auto i : p) { x = (x << K) + i; } return x; } bool in...
#include <bits/stdc++.h> using namespace std; void printvector(vector<long long> v) { for (int i = 0; i < v.size(); i++) { cout << v[i] << ; } cout << endl; } map<long long, long long> mp; long long a[100005][3] = {0}; int main() { long long m, n, i, j, k, l; cin >> m; for (...
#include <bits/stdc++.h> using namespace std; long long pwr(long long base, long long p, long long mod = (1000000007LL)) { long long ans = 1; while (p) { if (p & 1) ans = (ans * base) % mod; base = (base * base) % mod; p /= 2; } return ans; } long long gcd(long long a, long lon...
#include <bits/stdc++.h> using namespace std; const long long I1 = 1e9; const long long I2 = 1e18; const int32_t M1 = 1e9 + 7; const int32_t M2 = 998244353; template <typename T, typename T1> T maxn(T &a, T1 b) { if (b > a) a = b; return a; } template <typename T, typename T1> T minn(T &a, T...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int x, y, n; cin >> x >> y >> n; int d = n % x; if (d < y) cout << n - d - (x - y) << endl; else if (d > y) cout << n - (d - y) << endl; else cout << n <<...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, a, b, t, u; cin >> n >> m >> a >> b; if (a <= (float(b) / float(m))) { cout << n * a; } else { t = ceil(float(n) / float(m)) * b; u = n / m * b + n % m * a; cout << min(t, u); } }
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 20; vector<int> bad[N], comp[N]; int off[N], delta[N], col[N]; long long cnt_on[N]; long long ans = 0; bool hatman[N]; long long ok(long long x) { x += 10; x %= 2; return x; } inline void mer(int u, int v, int f) { int...
#include <bits/stdc++.h> static const int MAXN = 100005; int n = 0, m, ans_len = 0; char s[MAXN], ans[MAXN] = { 0 }; std::pair<char, int> p[MAXN]; std::set<int> marked; std::multiset<int> distance; int main() { scanf( %d , &m); getchar(); while ((s[n] = getchar()) >= a && s[n] <= z ) ++n; ...
#include <bits/stdc++.h> using namespace std; char vis[305][305]; int main() { int n; cin >> n; vector<int> v(n); for (int i = 0; i < n; i++) cin >> v[i]; char c; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> vis[i][j]; } } for (int k = 0; k...
#include <bits/stdc++.h> using namespace std; bool isprime(long long int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } vector<lo...
#include <bits/stdc++.h> template <typename T> class IntegerIterator : public std::iterator<std::input_iterator_tag, T, std::ptrdiff_t, T*, T> { public: explicit IntegerIterator(T value) : value(value) {} IntegerIterator& operator++() { ++value; return *this; } IntegerIterator o...
#include <bits/stdc++.h> using namespace std; map<vector<int>, int> mp; map<int, int> dp[100050]; set<int> ans; vector<int> vec[100050]; int n, cnt = 0; int getid(vector<int> t) { if (mp.find(t) == mp.end()) return mp[t] = ++cnt; else return mp[t]; } int getv(int x, int y) { if...
#include <bits/stdc++.h> using namespace std; struct people { int a, d, id; bool operator<(people other) const { if (a != other.a) return a > other.a; return id < other.id; } }; people s[111]; int n; int main() { int i, j, ans = 0; scanf( %d , &n); for (i = 1; i <= n; ++i...
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 2e5 + 5; struct tree { int l, r, add, lv, rv; ll sum; } tr[N << 2]; int n, q, a[N]; void Add(int rt, int x) { tr[rt].lv = tr[rt].rv = tr[rt].add = x; tr[rt].sum = 1ll * (tr[rt].r - tr[rt].l + 1) * x; } vo...
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &x) { x = 0; char ch = getchar(); int fh = 1; while (ch < 0 || ch > 9 ) { if (ch == - ) fh = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) x = x * 10 + ch - 0 , ch = getchar(); x *= ...
#include <bits/stdc++.h> using namespace std; long long const N = 35; long long dp[N][2][2]; long long get(long long l, long long r) { if (l < 0 || r < 0) return 0; memset(dp, 0, sizeof dp); dp[35][1][1] = 1; for (long long i = 34; i >= 0; i--) { for (long long j = 0; j <= 1; j++) { ...
#include <bits/stdc++.h> using namespace std; void task(); int main() { task(); return 0; } const int N = 6400 + 2; const int S = N - 2; const int T = N - 1; struct Rib { int to; int cap; int flow; int back; int cost; }; const int INF = 0x3f3f3f3f; vector<Rib> g[N]; i...
#include <bits/stdc++.h> using namespace std; struct Node { bool fr; int lb, rb; Node *lc, *rc; }; void buildSeg(Node *&p, int l, int r) { p = new Node; p->fr = true; p->lb = l; p->rb = r; if (p->lb < p->rb) { int mid = (p->lb + p->rb) / 2; buildSeg(p->lc, p->lb, mid)...
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007; long long mod2 = 998244353; long long mod3 = 1000003; long long mod4 = 998244853; long long mod5 = 1000000009; long long inf = 1LL << 60; double pi = 3.141592653589793238462643383279L; double eps = 1e-9; int dh[4] = {1, -1, 0,...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); printf( %d n , (n / 2) - 2); return 0; }
#include <bits/stdc++.h> using namespace std; const int INF = 10000000; char c[200]; int a[200], n, dp[200][200][200][2]; bool vis[200][200][200][2]; int f(int i, int j, int l, bool t) { if (i > j) return a[l]; int &ret = dp[i][j][l][t]; if (vis[i][j][l][t]) return ret; ret = -INF; vis[i...
#include <bits/stdc++.h> using namespace std; const long long INF = LLONG_MAX; const int mxn = 1011; bool DEBUG = 0; string s[mxn]; bool grid[mxn][mxn], chg[mxn][mxn]; long long dist[mxn][mxn]; const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, -1, 0, 1}; int n, m; bool check(int x, int y) { ...
#include <bits/stdc++.h> using namespace std; int main() { int q; cin >> q; while (q--) { map<char, long long int> d; string p; int n, m; cin >> n >> m; cin >> p; vector<map<char, long long int>> x(n + 2); for (int i = 0; i < n; i++) { x[i][p[i]]++; ...
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &x) { x = 0; char c = getchar(); T sig = 1; for (; !isdigit(c); c = getchar()) if (c == - ) sig = -1; for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - 0 ; x *= sig; } class Solution {...
#include <bits/stdc++.h> using namespace std; long long mult(long long a, long long b, long long p = 1000000007) { long long ans = a; ans *= b; return ((ans >= p) ? ans % p : ans); } long long add(long long a, long long b, long long p = 1000000007) { long long ans = a + b; return ((ans >= p)...
#include <bits/stdc++.h> using namespace std; bool cur1; int A[100005]; void check_min(int &x, int y) { if (x > y) x = y; } void check_max(int &x, int y) { if (x < y) x = y; } struct node { int sum; int mx, L, R; int mxL, ToL, mxR, ToR; void Init(int d, int x) { sum = d; ...
#include <bits/stdc++.h> using namespace std; struct node { int id; int no; } a[100001]; int n, tot = 1, minn = 2100000000; bool cmp(node a, node b) { if (a.no != b.no) return a.no < b.no; return a.id < b.id; } int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) { scan...
#include <bits/stdc++.h> using namespace std; long long maxi = LLONG_MIN; long long mini = LLONG_MAX; void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } long long t, i, j, k, n, temp, flag, ans, m; string s; int main() { int k; cin >> k; int f = -1; ...
#include <bits/stdc++.h> using namespace std; int n, q, PREV, pos; ; int arr[200005]; long long ps[200005], x, sebelum; long long k[200005]; bool good; void binser() { int ki = PREV, ka = n; pos = 1; x += sebelum; while (ki <= ka) { int mid = (ki + ka) / 2; if (ps[mid] <= x) ...
#include <bits/stdc++.h> using namespace std; double d = 0; bool intersect(int, int); bool belong(int, int); bool none(int, int); void solve() { int x1, y1, r1, R1, x2, y2, r2, R2; cin >> x1 >> y1 >> r1 >> R1; cin >> x2 >> y2 >> r2 >> R2; int x = abs(x1 - x2); int y = abs(y1 - y2); d...
#include <bits/stdc++.h> using namespace std; template <class T> void read(T& num) { char CH; bool F = false; for (CH = getchar(); CH < 0 || CH > 9 ; F = CH == - , CH = getchar()) ; for (num = 0; CH >= 0 && CH <= 9 ; num = num * 10 + CH - 0 , CH = getchar()) ; F &&...
#include <bits/stdc++.h> using namespace std; template <class T> using min_heap = priority_queue<T, vector<T>, greater<T>>; template <class T, class U> inline void MAX(T &a, U b) { if (a < b) a = b; } template <class T, class U> inline void MIN(T &a, U b) { if (a > b) a = b; } template <clas...
#include <bits/stdc++.h> using namespace std; long long MOD = 998244853; long long mpow(long long a, long long b) { if (b == 0) return 1; long long t1 = mpow(a, b / 2); t1 *= t1; t1 %= MOD; if (b % 2) t1 *= a; t1 %= MOD; return t1; } long long mpow(long long a, long long b, long lo...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, d; cin >> n >> m >> d; vector<int> v(n * m, 0); for (int i = 0; i < n * m; i++) cin >> v[i]; int ans = INT_MAX; for (int i = 0; i < n * m; i++) { int temp_ans = 0; for (int j = 0; j < n * m; j++) { if (a...
#include <bits/stdc++.h> using namespace std; char s[100005]; struct node { int x, op; } a[100005]; bool cmp(node q, node w) { return q.x < w.x; } int cnt; bool vis[100005]; int main() { int now, len, i; scanf( %d , &now); scanf( %s , s + 1); len = strlen(s + 1); s[0] = + ; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; string s1, s2, s3; cin >> n; while (n--) { cin >> s1 >> s2 >> s3; for (int i = 0; i < s1.length(); i++) { if (s3.at(i) != s2.at(i) && s3.at(i) != s1.at(i)) { cout << NO n ; break; } ...
#include <bits/stdc++.h> using namespace std; long long int mod1 = 1000000007; long long int mod2 = 67280421310721; long long int mod3 = 998244353; long long int INF = 1e18; long long int pow1(long long int a, long long int b) { long long int res = 1; while (b > 0) { if (b & 1) res = res * a; ...
#include <bits/stdc++.h> using namespace std; vector<long long> a; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, x, ct, i; cin >> n; for (i = 0; i < n; i++) { cin >> x; while ((x % 2) == 0) x = x / 2; while ((x % 3) == 0) x = x / 3; a.push_b...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5; const long long INF = 2e9; int n, m, dp[N], d[N], og[N], son[N], pr[N], top[N], num[N], sz, p[N], ans[N], a[N], b[N]; int t[5 * N], ob[5 * N]; vector<int> g[N]; void build(int v, int l, int r) { ob[v] = -1; if (l == r) { ...
#include <bits/stdc++.h> using namespace std; int main() { int q = 1; while (q--) { double n, r; cin >> n >> r; double ans; ans = (r) / (1 / sin(3.14159265 / n) - 1); cout << setprecision(9) << ans; } }
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 6; const int MAX = 1e7 + 7; int n, k; int a[N]; int dp[MAX]; bool can(int x) { memset(dp, 0, sizeof(dp)); for (int i = x; i <= MAX; i++) { dp[i] = max(1, dp[i / 2] + dp[(i + 1) / 2]); } int kk = k; for (int i = 0; ...
#include <bits/stdc++.h> using namespace std; int n, a[200011], b[200011], q[200011][2], l, r; long long sum[2]; char s[200011]; int main() { scanf( %d , &n); for (int i = 1; i <= n; ++i) scanf( %d , a + i); scanf( %s , s + 1); for (int i = 1; i <= n; ++i) b[i] = (s[i] == L ? -1 : 1); so...
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } bool mod(long double a, long double b) { return a / b - floor(a / b); } int occurs(vector<int> v, int n) { auto it = lower_bound(((v)).begin(), ((v)).end(), (n)); auto it1 = uppe...
#include <bits/stdc++.h> using namespace std; template <class T> inline void rd(T &x) { x = 0; char c = getchar(); int f = 1; while (!isdigit(c)) { if (c == - ) f = -1; c = getchar(); } while (isdigit(c)) x = x * 10 - 0 + c, c = getchar(); x *= f; } int curtest; vo...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10; int d[MAXN], s[MAXN]; vector<pair<int, int> > ans; set<pair<int, pair<int, int> > > ver; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; for (int i = 0; i < n; i++) { cin >> d[i] >> s[i]...
#include <bits/stdc++.h> const int maxx = 1000001; int x[maxx], y[maxx]; unsigned long long hash[maxx], vl[maxx], count = 0, check = 1, mul = 1; bool compare(unsigned long long a, unsigned long long b) { return a > b; } unsigned long long sum1ton(unsigned long long n) { return n * (n - 1) / 2; } int main() ...
#include <bits/stdc++.h> using namespace std; const int N = 1010; int d[N]; int a[N][N], b[N][N], c[N][N], row[N], col[N]; int main() { int n, m; scanf( %d%d , &n, &m); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { scanf( %d , &a[i][j]); } } for (int i =...
#include <bits/stdc++.h> using namespace std; template <typename T_key, typename T_value, bool maximum_mode = false> struct online_prefix_max { map<T_key, T_value> optimal; bool better(T_value a, T_value b) { return (a < b) ^ maximum_mode; } pair<T_key, T_value> query(T_key key_limit) const { au...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int arr[n], vis[200005] = {0}; for (int i = 0; i < n; i++) { cin >> arr[i]; if (arr[i] <= n) vis[arr[i]]++; } sort(arr, arr + n); vector<in...
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; vector<long long> V; for (long long i = 1; i * i <= n; ++i) { if (!(n % i)) { V.push_back(i); V.push_back(n / i); } } sort(V.begin(), V.end()); for (long long i = V.size() - 1; i...
#include <bits/stdc++.h> using namespace std; int n, m, k; int main() { cin >> n >> m >> k; if (m >= n && k >= n) cout << Yes ; else cout << No ; return 0; }
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); int n, h, a[100005]; pair<int, int> A[100005]; void solve() { sort(A, A + n); for (int i = (0); i < (n); i++) a[i] = A[i].first; int res = a[n - 1] + a[n - 2] - a[0] - a[1], ind = n - 1; if (n >= 3) { int v = max...
#include <bits/stdc++.h> using namespace std; const long long maxx = 1e6 + 7; const long long maxn = 5000 + 7; const long long mod = 998244853; const long long maxs = 5 * (1E5) + 7; const long long maxm = 4e5 + 7; const long long maxk = 1008 + 7; const long long maxw = 100 + 7; const long long maxh = ...
#include <bits/stdc++.h> using namespace std; const int N = 500005; int n, u, v, cnt = 0, h[N] = {-1}, in[N], out[N], ans[N], val[N], pa[N]; bool chk[N]; vector<int> cur; vector<int> adj[N]; vector<pair<int, int>> ve; multiset<int, greater<int>> second, ed, ch[N]; struct segment_tree { int tr[4 * ...
#include <bits/stdc++.h> int n; int tot; int top; int tot1; int a[2005][2005]; int stack[2005]; int instack[2005]; int visit[2005]; int dfn[2005]; int low[2005]; inline void tarjan(int u) { if (visit[u]) return; int v; dfn[u] = low[u] = ++tot; stack[++top] = u; instack[u] = 1; ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:256000000 ) #pragma gcc optimize(O3) using namespace std; const double eps = 1e-9; const double pi = acos(-1.0); const double dinf = 1e250; const long long INF = static_cast<long long>(2e18); const unsigned long long inf = static_cast<unsigned lon...
#include <bits/stdc++.h> using namespace std; int pre[30], g[2000100], f[2000100]; char s[2000100]; int n, m, k, ans; int main() { scanf( %d%d , &n, &k); scanf( %s , s + 1); m = strlen(s + 1); for (int i = 1; i <= m; i++) pre[s[i] - a + 1] = i; n = n + m; pre[27] = 2000000; for (...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2010; const int MAXM = 4100000; int F[MAXN]; struct node { long long x, y, c; } a[MAXN]; struct Edge { long long u, v, w; } edge[MAXM]; int tol; vector<long long> vec1; vector<pair<long long, long long> > vec2; void addedge(l...
#include <bits/stdc++.h> using namespace std; const int N = 30; const int M = 110; const int LIT = 2500; const int INF = 1 << 28; string s; int n, m; int val[N][N]; void init() { cin >> n; memset(val, 0, sizeof(val)); for (int i = 1; i <= n; i++) { string a, b; int v; cin...
#include <bits/stdc++.h> using namespace std; long long a[200000 + 1], b[200000 + 1]; int c[200000 + 1], t[200000 + 1]; int n, m, k, s; vector<pair<long long, int> > v; inline int check(int p) { int i; v.clear(); long long mna = (1LL << 62), mnb = (1LL << 62); for (i = 1; i <= p; i++) { ...
#include <bits/stdc++.h> using namespace std; int n, m, zz; string s; int a[28]; int main(void) { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int ntest; cin >> ntest; while (ntest--) { cin >> n >> m >> zz >> s; for (int i = 0; i < 28; ++i) a[i] = 0; for (in...
#include <bits/stdc++.h> using namespace std; int main() { int a[5], sum = 0; for (int i = 0; i < 5; i++) { cin >> a[i]; sum += a[i]; } if (sum % 5 == 0 && sum != 0) cout << (sum / 5); else cout << -1; }
#include <bits/stdc++.h> using namespace std; const int LIM = 1e+5 + 100; int n, m, k; int get_rd(int i, int j) { if (i == j) { return n; } else if (i < j) { return n + (j - i); } else { return n - (i - j); } } int get_ld(int i, int j) { if (i + j == n) { return n...
#include <bits/stdc++.h> using namespace std; int v[100001]; int acum[100001]; long long cnt = 0, ans[100001]; struct Q { int i, j, p; Q(int a, int b, int c) : i(a), j(b), p(c){}; Q() {} bool operator<(const Q &other) const { if (i / 300 == other.i / 300) return j < other.j; return...
#include <bits/stdc++.h> const int mod = 1000000007; const int inf = 1000000009; const long long INF = 1000000000000000009; const long long big = 1000000000000000; const long double eps = 0.0000000001; using namespace std; int DP[2005][2005], T[2005]; int main() { ios::sync_with_stdio(false); ci...
#include <bits/stdc++.h> using namespace std; const int maxn = 100; int a[maxn], b[maxn]; int main() { int t; scanf( %d , &t); while (t--) { int n; scanf( %d , &n); int MIN1 = 0x7fffffff; int MIN2 = 0x7fffffff; for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); ...
#include <bits/stdc++.h> using namespace std; void solve() { int n, m, x, y, i; cin >> n >> m >> x >> y; cout << x << << y << endl; int k = x + 1; int p = x - 1; for (i = 1; i < m + 1; i++) { if (i != y) cout << x << << i << endl; } int jj = 1; while (k <= n) { ...
#include <bits/stdc++.h> using namespace std; int main() { int wall[110][110] = {0}; int r, c; scanf( %d %d%*c , &r, &c); char a[110]; for (int i = 1; i < r; i++) gets(a); int flag = 0; int seg = 0; for (int i = 0; i < c; i++) { char x; scanf( %c , &x); if (flag == ...
#include <bits/stdc++.h> using namespace std; const int N = 2012; int f[N][N][2]; int n, m, k, flag; int ex, ey; inline int find(int x, int y, int p) { if (y < 0) return y; return f[x][y][p] == y ? y : f[x][y][p] = find(x, f[x][y][p], p); } int dis(int x, int y) { return abs(ex - x) + abs(ey - y...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; const int INF = 1e9 + 10; int n, current; pair<int, int> best; int ans[N], block[N], sz[N]; vector<int> tree[N], tree_c[N]; int dfs1(int i, int parent) { sz[i] = 1; for (int k = 0; k < tree[i].size(); ++k) { int j = tree...
#include <bits/stdc++.h> using namespace std; namespace fastIO { bool IOerror = 0; inline char nc() { static char buf[100000], *p1 = buf + 100000, *pend = buf + 100000; if (p1 == pend) { p1 = buf; pend = buf + fread(buf, 1, 100000, stdin); if (pend == p1) { IOerror = 1; ...
#include <bits/stdc++.h> using namespace std; bool check(long long ar[], long long n) { bool flag = true; for (long long i = 1; i < n; i++) { if (ar[i] >= (ar[i - 1] + ar[(i + 1) % n])) { flag = false; break; } } return flag; } int32_t main() { long long n; ci...
#include <bits/stdc++.h> void sort(int *a, int n) { int isSorted = 0; int i; int tmp; while (isSorted == 0) { isSorted = 1; for (i = 0; i < n - 1; i++) { if (a[i] > a[i + 1]) { tmp = a[i]; a[i] = a[i + 1]; a[i + 1] = tmp; isSorted = 0; ...
#include <bits/stdc++.h> using namespace std; inline int read() { int sum = 0, ff = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == - ) ff = -1; ch = getchar(); } while (isdigit(ch)) sum = sum * 10 + (ch ^ 48), ch = getchar(); return sum * ff; } int Q, n, a[10005], ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:64000000 ) using std::cerr; using std::cin; using std::cos; using std::cout; using std::endl; using std::make_pair; using std::max; using std::min; using std::next_permutation; using std::pair; using std::priority_queue; using std::queue...
#include <bits/stdc++.h> using namespace std; int n, i, j, k, l, w[200005], h[200005], a, b, m, m1; int main() { scanf( %d , &n); for (i = 1; i <= n; i++) { scanf( %d%d , &w[i], &h[i]); if (h[m] <= h[i]) { m1 = m; m = i; } else if (h[m1] <= h[i]) { m1 = i; }...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string rl; cin >> rl; vector<int> A(n, 0); for (int i = 0; i < n; i++) cin >> A[i]; int diff = 2147483647; int t; for (int i = 0; i < n - 1; i++) if (rl[i] == R && rl[i + 1] == L ) { t = ...
#include <bits/stdc++.h> using namespace std; void print(int n) { cout << n << endl; } int main() { int n, l, sum = 0; cin >> n; string s; s = to_string(n); l = s.size(); for (int i = l; i > 0; i--) sum += pow(2, i - 1); reverse(s.begin(), s.begin() + l); for (int i = 0; i < l; i++...
#include <bits/stdc++.h> using namespace std; const long long linf = 1e18 + 5; const int mod = (int)1e9 + 7; const int logN = 17; const int inf = 1e9; const int N = 2e5 + 5; int s, n, m, h1[N], h, t, x, y, z; vector<int> v[N]; pair<int, int> e[N]; void print(int x, int y) { cout << YES n ; ...
#include <bits/stdc++.h> using namespace std; const int mx = 2e3 + 505; struct node { double x, y; } a[mx]; double pw(double x) { return x * x; } double dist(node a, node b) { return sqrt(pw(a.x - b.x) + pw(a.y - b.y)); } double f[2][mx], g[2][mx]; int main() { int n; scanf( %d , &n); fo...
#include <bits/stdc++.h> using namespace std; const int maxn = 300000 + 10; int n; const int nn = 65536 * 4; long long sha[maxn]; long long tree[nn * 2 + 10], tag[nn * 2 + 10]; long long fix; long long og[maxn]; void _down(int id) { tree[id * 2] += tag[id], tag[id * 2] += tag[id]; tree[id * 2 ...
#include <bits/stdc++.h> template <typename A, typename B> inline char smax(A &a, const B &b) { return a < b ? a = b, 1 : 0; } template <typename A, typename B> inline char smin(A &a, const B &b) { return b < a ? a = b, 1 : 0; } template <typename I> inline void read(I &x) { int f = 0, c; ...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; void print_mat(vector<vector<long long> > mat) { for (long long y = 0; y < (long long)((long long)((mat).size())); ++y) { for (long long x = 0; x < (long long)((long long)((mat[y]).size())); ++x) printf( %lld , mat[...
#include <bits/stdc++.h> using namespace std; long long int pc; void PrintCase() { printf( Case %lli: , ++pc); } long long int GCD(long long int a, long long int b) { if (a < b) swap(a, b); if (b == 1) return 1; if (!b) return a; if (!(a % b)) return b; else return (a, a % b); ...
#include <bits/stdc++.h> using namespace std; static const double EPS = 1e-10; template <typename T, typename S> vector<T>& operator<<(vector<T>& a, S b) { a.push_back(b); return a; } template <typename T> void operator>>(vector<T>& a, int b) { while (b--) if (!a.empty()) a.pop_back(); ...