func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int main() { long long int n; scanf( %lld , &n); long long int a[n]; long long int i, j, k; long long int ans = 0; k = 0; for (i = 0; i < n; i++) { scanf( %lld , &j); if (j == 1) { a[k++] = i; } } if (k == 0)...
#include <bits/stdc++.h> int b[1000005], a[1000005]; int main() { int n, i; scanf( %d , &n); for (i = 0; i < n; i++) scanf( %d , &a[i]); b[n - 1] = a[n - 1]; for (i = n - 2; i >= 0; i--) b[i] = a[i] + a[i + 1]; for (i = 0; i < n; i++) printf( %d , b[i]); printf( n ); return 0; } ...
#include <bits/stdc++.h> using namespace std; namespace io { template <typename T> inline void read(T &x) { bool flag = false; char c = getchar(); while ((c < 0 || c > 9 ) && c != - ) c = getchar(); c == - ? flag = true, x = 0 : x = c - 0 ; c = getchar(); while (c >= 0 && c <= ...
#include <bits/stdc++.h> const int N = 300010; const int MOD = 1e9 + 7; struct xxx { int id; char c; } s[N]; std::string a, b, c; int gap, n; int sa[N], lcp[N], rank[N], tmp[N], bucket[N], cnt[N][3], ans[N], dp[19][N], fw[N]; void update(int i, int v) { while (i < N) { fw[i] = (f...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:1073741824 ) using namespace std; const int N = 3e5 + 100; int col[N], d[N][2]; vector<int> v[N]; int main() { #pragma warning(disable : 4996) int n, m; scanf( %d%d , &n, &m); for (int i = 0; i < m; i++) { int a, b; scanf( %d...
#include <bits/stdc++.h> using namespace std; const int maxn = 1000005; const long long mod = 1e9 + 7; const int N = 1e6; vector<int> rec[maxn]; long long fac[maxn], ans; int n, m; int ord[maxn], bit; bool comp(int a, int b) { return rec[a][bit] < rec[b][bit]; } void mysort(int l, int r, int j) { ...
#include <bits/stdc++.h> using namespace std; int Power(int base, int exp) { int ans = 1; while (exp > 0) { if (exp & 1) ans = (1LL * ans * base) % 1000000007; exp = exp >> 1; base = (1LL * base * base) % 1000000007; } return ans; } vector<map<long double, int> > p_CntS(2005); ...
#include <bits/stdc++.h> int ans = 0; double H = 100, len = 100000; int F[110000], T[110000], FF[110000], TT[110000]; bool vis[110000]; int judge(bool fuck, double st, double t) { int ret = 0; int top, flo; double point = st; memset(vis, 0, sizeof(vis)); while (point < len) { top = (...
#include <bits/stdc++.h> using namespace std; struct point { int x, y; point() {} point(int x, int y) : x(x), y(y) {} } p[1010]; point operator-(const point &a, const point &b) { return point(a.x - b.x, a.y - b.y); } long long operator*(const point &a, const point &b) { return (long long...
#include <bits/stdc++.h> using namespace std; const int N = 500000; const long long minx = -0x5fffffffffffffff; struct nn { long long x, y; nn() { y = minx; } }; int n, u, v; nn num[N]; vector<int> node[N]; long long dfs(int f, int x) { for (int i = 0; i < node[x].size(); i++) { if (...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int n, k; cin >> n >> k; if (k > (n * n + 1) / 2) { cout << NO ; return 0; } cout << YES n ; int tmp = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if...
#include <bits/stdc++.h> using namespace std; using namespace chrono; const int infinity = (int)1e9 + 42; const int64_t llInfinity = (int64_t)1e18 + 256; const int module = (int)1e9 + 7; const long double eps = 1e-8; mt19937_64 randGen(system_clock().now().time_since_epoch().count()); inline void raiseE...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, m; string s, t; cin >> n >> m >> s >> t; bool can = false; if (s == t) can = true; else { if (n <= m + 1) { for (int i = 0; i < int(n); i++) { ...
#include <bits/stdc++.h> using namespace std; long long a[200001], b[200001], c[200001]; int main() { long long n, ans = 0; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> b[i]; for (int i = 0; i < n; i++) c[i] = a[i] - b[i]; sort(c, c + n); for (i...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a, b; if (n == 2) { cout << 2 << endl; } else cout << 1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; unsigned long long preLef[N], preRig[N], sum[N], a[N]; map<unsigned long long, unsigned long long> f, g; int n, m; unsigned long long Rand() { return (unsigned long long)rand() * rand() * rand() + (unsigned long long)rand()...
#include <bits/stdc++.h> using namespace std; const int N = 1e4 + 5; int n, a[N]; int main() { ios ::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen( main.in , r )) freopen( main.in , r , stdin); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; int cnt = 0; for (int i...
#include <bits/stdc++.h> using namespace std; char s[10]; int main() { int n, i, len; long long wi = 1, he = 1; scanf( %d , &n); for (i = 1; i <= n; i++) { scanf( %s , s); len = strlen(s); if (len == 4) { wi++; he++; } else if (!strcmp(s, UL ) || !strcmp(s,...
#include <bits/stdc++.h> using namespace std; string rotate(string s, int off, int* a) { string new_s(s); for (int i = 0; i < 4; i++) new_s[a[(i + off) % 4] - 1] = s[a[i] - 1]; return new_s; } string rotate1(string s, int off) { int a[] = {1, 3, 5, 6}; return rotate(s, off, a); } string ...
// Problem: A. Searching Local Minimum // Contest: Codeforces - Codeforces Round #700 (Div. 1) // URL: https://codeforces.com/contest/1479/problem/A // Memory Limit: 512 MB // Time Limit: 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) #include <iostream> #include <iosfwd> #...
#include <bits/stdc++.h> using namespace std; const int INF = INT_MAX; const long long INFL = LLONG_MAX; const long double pi = acos(-1); class SumSegTree { private: vector<long long> sum, lazy; int N; void check_index(int i) { if (i < 0 || N <= i) { throw index out of bound ; ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); pair<int, int> home, uni; cin >> home.first >> home.second >> uni.first >> uni.second; int count; cin >> count; int solution = 0; int64_t a, b, c; for (int i = 0; i < count; i++) { cin >> a ...
#include <bits/stdc++.h> using namespace std; int main(void) { int n; char str[102][102]; scanf( %d , &n); bool row, col; row = col = false; for (int i = 0; i < n; i++) { scanf( %s , str[i]); bool bolong = false; for (int j = 0; j < n; j++) { if (str[i][j] == . ) {...
#include <bits/stdc++.h> using namespace std; mt19937_64 rng( (unsigned)chrono::system_clock::now().time_since_epoch().count()); const long double error = 1e-7; const long double PI = acosl(-1); const int nmax = 2e5 + 10; int master[nmax]; int sz[nmax]; void init(int u) { master[u] = u; sz...
#include <bits/stdc++.h> using namespace std; int L[100010]; int P[100010][20]; vector<int> pp[100010][20]; int T[100010]; vector<int> tt[100010]; int arr[100010]; vector<int> graph[100010]; vector<int> fnc(vector<int> &a, vector<int> &b) { vector<int> ans; int aa = a.size(), bb = b.size(), i,...
#include <bits/stdc++.h> using namespace std; int n, m, i, j, k, lst, a[22], b[1 << 18], o[1 << 18]; long long f[1 << 18][18], g[1 << 18]; char s[22][22]; void rec(int sum, int x, int mask) { if (sum == 0) { for (i = 0; i < (1 << n); i++) if (b[i] > lst) for (j = 0; j < n; j++) f[i...
#include <bits/stdc++.h> using namespace std; int n, m; int a[107]; map<string, int> f; vector<pair<int, string>> b; bool cmp(pair<int, string> u, pair<int, string> v) { return u.first > v.first; } int main() { cin >> n >> m; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= m; i+...
#include <bits/stdc++.h> using namespace std; struct node { long long cos, rlev; bool operator<(const node &a) const { return cos < a.cos; } } f[300005]; int main() { int n, k; while (scanf( %d%d , &n, &k) != EOF) { for (int i = 1; i <= n; i++) { scanf( %I64d , &f[i].cos); ...
#include <bits/stdc++.h> using namespace std; long long mul(long long a, long long b, long long p = 1000000007) { return ((a % p) * (b % p)) % p; } long long add(long long a, long long b, long long p = 1000000007) { return (a % p + b % p) % p; } void input(long long a[], long long sz) { for (lon...
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 20; struct edge { int v, l, r; edge() {} edge(int a, int b, int c) { v = a; l = b; r = c; } }; struct nd { int no, lim, to; nd() {} nd(int a, int b, int c) { no = a; lim = b; to...
#include <bits/stdc++.h> using namespace std; const int N = 1000008; int n, m, k, d, i, j, e; int tmp[N], pos[N], p[N], c[N]; char s[N]; int main() { scanf( %s %d , s, &m); n = strlen(s); while (m--) { scanf( %d%d , &k, &d); for (i = 0; i < n; i++) { c[i] = (i + 1) % n; ...
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> ke[1000010]; bool cx[1000010], visited[1000010]; void dfs(int u) { visited[u] = true; for (int v : ke[u]) if (!visited[v]) dfs(v); } long long c2(int x) { return (1LL * x * (x - 1)) >> 1; } int main() { if (fopen( a.tx...
#include <bits/stdc++.h> using namespace std; int get_point(int N) { int score[10] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1}; if (N > 10) return 0; return score[N - 1]; } int main() { int T; map<string, int> n_map; map<string, string> n_win; cin >> T; for (int i = 0; i < (T); ++i) { ...
#include <bits/stdc++.h> using namespace std; const int N = 300005; int n, m, ans, two, one, l, r, k, a[N], dp[N][205]; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); a[i] /= 100; } memset(dp, 127, sizeof(dp)); dp[0][0] = 0; for (int i = 0; i...
#include <bits/stdc++.h> using namespace std; const int N = 40; const int F = N / 2 + N % 2; const int S = N - F; const long long N_MASKS = (1ll << N); const long long F_MASKS = (1ll << F); const long long S_MASKS = (1ll << S); double liquid; int n, f, s; long long adj[N]; int firstSizes[F_MASKS];...
#include <bits/stdc++.h> using namespace std; long long dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; long long power(long long a, long long b) { long long res = 1; while (b) { if (b % 2) res = (res * a) % 5; b = b >> 1; a = (a * a) % 5; } return res; } int main() { ios...
#include <bits/stdc++.h> using namespace std; const int maxn = 200005; vector<int> lk[maxn]; int fa[maxn], dep[maxn], a[maxn], b[maxn], n; void dfs(int now, int pre) { fa[now] = pre; dep[now] = dep[pre] + 1; for (auto p : lk[now]) if (p != pre) dfs(p, now); } vector<int> cir; int rt, l...
#include <bits/stdc++.h> using namespace std; const int N = 5010; struct Edge { int v, u, f, r, c; Edge() {} Edge(int v, int u, int f, int c, int r) : v(v), u(u), f(f), c(c), r(r) {} }; const int inf = 1e9; const int C = 4000; int n, m, k, nflow, s, t, parent[N], number[N], a[N], b[N]; int d...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n; double a[N]; double max_poor(double x) { int i; double pre, mpre, ret = 0; pre = mpre = 0; for (i = 0; i < n; i++) { pre += a[i] - x; ret = max(ret, abs(pre - mpre)); mpre = min(mpre, pre); } ...
#include <bits/stdc++.h> const long long MOD = 1000000007; const int MAX = 1e9 + 7; const int MIN = -1e9 + 7; using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long b, g; cin >> b >> g; long long n; cin >> n; if (b >= n && g >= n) { ...
#include <bits/stdc++.h> using namespace std; const int MAXN = int(5e4) + 100; const int MOD = int(360); const int oo = INT_MAX; const long double PI = acos(-1.0); const long double EPS = 1e-9; struct pt { long double x, y; pt() {} pt(long double x, long double y) : x(x), y(y) {} }; inline...
#include <bits/stdc++.h> using namespace std; int main() { int n, k = 0; string home; cin >> n; cin >> home; for (int i = 0; i < n; i++) { string now; cin >> now; now = now.substr(5, 3); if (now == home) k++; } if (k == n - k) cout << home ; else ...
#include <bits/stdc++.h> using namespace std; template <typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>; struct RangeIncrement { vector<long long> tree, lazy; RangeIncrement(int n) : tree(n << 2), lazy(n << 2) {} void refresh(int i, int l, int r) { if (lazy[i] != 0) { ...
#include <bits/stdc++.h> using namespace std; int cnt[100100]; int R[100100]; int n; long long power(long long a, long long b) { long long res = 1; while (b) { if (b & 1) res = (res * a) % 1000000007; a = (a * a) % 1000000007; b >>= 1; } return res; } int main() { mem...
#include <bits/stdc++.h> using namespace std; const int maxn = 500100; const int maxp = 40; int n, q; double d[maxn][maxp]; int p[maxn]; void upd(int v, int k, double x) { while (v && k < maxp) { double a = d[v][k]; d[v][k] *= x; x = (d[v][k] + 1) / (a + 1); v = p[v]; k++...
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll INF = 1e14 + 7; using vi = vector<int>; using pii = pair<int, int>; using pli = pair<ll, int>; int ask(int i, int j) { cout << ? << i << << j << endl; int ans; cin >> ans; return ans; } int main() { ...
#include <bits/stdc++.h> using namespace std; int a[200005]; int b[200005]; bool f[200005]; int main() { int q, n; cin >> q; while (q--) { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; b[i] = 1; f[i] = 0; } for (int i = 1; i <= n; i++) { ...
#include <bits/stdc++.h> inline int readChar(); template <class T = int> inline T readInt(); template <class T> inline void writeInt(T x, char end = 0); inline void writeChar(int x); inline void writeWord(const char* s); static const int buf_size = 4096; inline int getChar() { static char buf[buf_...
#include <bits/stdc++.h> using namespace std; long long pw(long long a, long long b) { if (b == 0) return 1; if (b % 2 == 1) return (a * pw(a * a, b / 2)); else return (1 * pw(a * a, b / 2)); } void solve() { long long n, k; cin >> n >> k; long long a[n], b[k]; for (int i...
#include <bits/stdc++.h> using namespace std; struct node { long long lvl1, lvl2, id; }; node t[500005]; bool cmp(struct node x, struct node y) { if (x.lvl1 < y.lvl1) return true; else return false; } vector<node> sh; vector<long long> adj[500005]; long long vis[500005], lvl1[5...
#include <bits/stdc++.h> #pragma warning(disable : 4786) #pragma comment(linker, /STACK:102400000,102400000 ) using namespace std; const double eps = 1e-8; const double PI = acos(-1.0); const int MAXN = 200005; const int mod = 1000000007; const long long llinf = (long long)(1e18) + 500; const int inf...
#include <bits/stdc++.h> using namespace std; char str[1000005 + 1]; int main() { int ans = 0, i; stack<int> S; scanf( %s , str); for (i = 0; str[i] != 0 ; ++i) { if (str[i] == ( ) S.push(i); if (str[i] == ) && !S.empty()) { S.pop(); ans += 2; } } pri...
#include <bits/stdc++.h> using namespace std; void solve() { int y, b, r; cin >> y >> b >> r; while (1) { if (r - 1 <= b && r - 2 <= y) { break; } --r; } cout << 3 * r - 3; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); ...
#include <bits/stdc++.h> using namespace std; int main() { string n; cin >> n; long long even = 0; long long odd = 0; long long len = n.length(); long long aeven = 0; long long aodd = 0; long long beven = 0; long long bodd = 0; for (int i = 0; i < len; i++) { if (n[i] =...
#include <bits/stdc++.h> using namespace std; int const N = 100000; long long a[N + 1]; long long f[N * 3]; inline int lc(int root) { return root << 1; } inline int rc(int root) { return (root << 1) | 1; } void build(int root, int l, int r) { f[root] = -1; if (l == r) { f[root] = a[l]; ...
#include <bits/stdc++.h> using namespace std; map<long long int, int> mp; int main() { long long int b, q, l, m, t; scanf( %lld%lld%lld%lld , &b, &q, &l, &m); for (int i = 0; i < m; i++) { scanf( %lld , &t); mp[t] = 1; } if (b < -l || b > l) { printf( 0 n ); return 0; ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); string a, c; int b, d, p; int pos[110]; p = 0; cin >> b >> d; cin >> a; cin >> c; int t = 0, la, lc; la = a.length(); lc = c.length(); int k = 0; for (int i = 0; i < lc; i++) ...
#include <bits/stdc++.h> using namespace std; int n, m, a, b; set<pair<int, int> > s; set<int> sc; vector<int> ans; int main() { cin >> n >> m; for (int i = 1; i <= m; ++i) { cin >> a >> b; s.insert(make_pair(min(a, b), max(a, b))); } for (int i = 1; i <= n; ++i) { sc.inser...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:10000000 ) using namespace std; template <typename T> inline T abs(T a) { return ((a < 0) ? -a : a); } template <typename T> inline T sqr(T a) { return a * a; } const int INF = (int)1E9 + 7; const long double EPS = 1E-9; const long d...
#include <bits/stdc++.h> using namespace std; int a[100001]; int getBound(int start, int dir, int size, int k) { int cnt = 0; bool seen[100001]; fill(seen, seen + 100001, false); for (int i = start; i <= size && i > 0; i += dir) { if (!seen[a[i]]) cnt++, seen[a[i]] = true; if (cnt == k...
#include <bits/stdc++.h> using namespace std; const long long MAX = 10e5; vector<long long> graph[MAX]; queue<long long> q; bool visit[MAX]; long long a[MAX]; long long s[MAX]; long long parent[MAX]; int main() { memset(visit, false, sizeof(visit)); long long nodes; cin >> nodes; for (...
#include <bits/stdc++.h> using namespace std; void solve() { string s; cin >> s; string ans = ; int cnt(0); for (int i = 0; i < s.size(); i++) { if (s[i] == 0 && cnt == 0) { cnt++; } else ans += s[i]; } if (cnt == 0) { for (int i = 0; i < ans.size() ...
#include <bits/stdc++.h> using namespace std; int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}; const int N = 500005; vector<int> arr[N], cnt[N], adj[N]; int vis[N], st[N], fin[N], dep[N]; int tim; char inp[N]; void dfs(int i, int d) { vis[i] = 1; dep[i] = d; st[i] = ++tim; arr[d].push_bac...
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int a[3], i; for (i = 0; i < 3; i++) cin >> a[i]; sort(a, a + 3); if (a[2] <= a[1] + a[0] + 1) cout << YES << endl; else cout << NO << endl; ...
#include <bits/stdc++.h> using namespace std; string to_string(string s) { return + s + ; } string to_string(const char* s) { return to_string((string)s); } string to_string(bool b) { return (b ? true : false ); } template <typename A, typename B> string to_string(pair<A, B> p) { return ( + ...
#include <bits/stdc++.h> using namespace std; struct rangeincrease { int l, r; }; rangeincrease actions[100001]; rangeincrease inprogress[100001]; int actionL = 0; int nums[100001]; int opened = 0; int main() { int n; int i; cin >> n; for (i = 1; i <= n; i++) { cin >> nums[i]...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( avx,avx2,fma ) using namespace std; bool ispoweroftwo(long long n) { return n & (!(n & (n - 1))); } long long mod = 1000000007; long long dx[] = {1, 0, -1, 0}; long long dy[] = {0, -1, 0, 1}; bool test = 0; const long long inf ...
#include <bits/stdc++.h> using namespace std; const long long MX = 200005; long long n, m; vector<long long> adj[2][MX]; long long st[MX], fin[MX]; long long deg[2][MX]; long long ans, tim; long long cur = 1; pair<long long, long long> seg[4 * MX]; long long lazy[4 * MX]; pair<long long, long long...
#include <bits/stdc++.h> using namespace std; const int N = 205, inf = 1e9; int n, a[N]; int tot, lnk[N], fro[N * N * 2], nxt[N * N * 2], son[N * N * 2], c[N * N * 2], ori[N * N * 2]; int S, T, dep[N], cur[N]; queue<int> q; int cnt; bool vis[N]; vector<int> ans[N]; bool isprm(int x) { if (...
#include <bits/stdc++.h> using namespace std; const int NMax = 1003; enum directions { EAST, NORTH }; struct point { int x, y; }; point a[NMax]; int n; int test(int searchDir, point a[], long double x, long double y) { if (searchDir == NORTH) { int nr = 0; for (int i = 1; i <= n; ++i...
#include <bits/stdc++.h> using namespace std; long long px1[133000], px2[133000], py1[133000], py2[133000], sx1[133000], sx2[133000], sy1[133000], sy2[133000]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; long long a[n + 1], b[n + 1], c[n + 1],...
#include <bits/stdc++.h> using namespace std; const int mod = 1051131; const int Inv2 = (mod + 1) >> 1; inline void setIO(string a) {} long long Power; int m, s, n, nn; int a[(1 << 25) + 23]; void work(int n, int p, int q) { if (n == 1) { int &An = a[1]; (p += q) %= mod; for (long ...
#include <bits/stdc++.h> using namespace std; int n, arr[30010], book[30010]; bool judge() { int ps, gap; int t1 = 1, t2; while (t1 <= n && book[t1]) t1++; t2 = t1 + 1; if (t1 > n) return false; while (t2 <= n && book[t2]) t2++; if (t2 > n) return true; gap = arr[t2] - arr[t1]; ...
#include <bits/stdc++.h> using namespace std; int ekub(int a, int b) { return b == 0 ? a : ekub(b, a % b); } long long s[51][51]; int main() { long long i, j, n, m, a, b, ans = 1e9; cin >> n >> m; for (i = 1; i <= n; i++) for (j = 1; j <= m; j++) { cin >> s[i][j]; s[i][j] += s[...
#include <bits/stdc++.h> namespace P_TEMPLATE { class fastin { private: int _ch, _f; public: inline fastin& operator>>(char& c) { c = getchar(); return *this; } template <typename _Tp> inline fastin& operator>>(_Tp& _x) { _x = 0; while (!isdigit(_ch)) _f |= (_ch ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:66777216 ) using namespace std; const int N = 100007; int n, a[N], cnt[N]; vector<int> D[N]; long long power(long long a, long long b) { if (b == 0) { return 1; } if (b & 1) { return (a * power(a, b - 1)) % 1000000007LL; } ...
#include <bits/stdc++.h> using namespace std; void init_code() { ios_base::sync_with_stdio(false); cin.tie(NULL); } int main() { init_code(); int t; cin >> t; while (t--) { int n; cin >> n; vector<pair<int, int>> v; vector<pair<int, int>> v1; for (int i = 0;...
#include <bits/stdc++.h> using namespace std; void solve() {} void no() { cout << NO << n ; exit(0); } const long long maxn = 100050; long long a[maxn]; long long psa[maxn]; signed main() { ios::sync_with_stdio(0); cin.tie(0); long long n; cin >> n; for (long long i = 1; ...
#include <bits/stdc++.h> using namespace std; const int N = 1234567; int pref[N], a[N], b[N]; char c[N]; int solve(vector<pair<int, int> > z, int b) { sort(z.begin(), z.end()); int cnt = z.size(); if (cnt < 2) { return 0; } pref[0] = 0; for (int i = 0; i < cnt; i++) { pref[...
#include <bits/stdc++.h> inline int abs(int n) { return n < 0 ? -n : n; } bool board[20][20]; int dx[] = {-3, -2, -2, -1, -1, 0, 0, 1, 1, 2, 2, 3}; int dy[] = {0, 1, -1, 2, -2, 3, -3, 2, -2, 1, -1, 0}; int dfs(int p, int n, int m) { int mx = p, t, cnt = 0; for (int i = 0; i < n; i++) { for (int ...
#include <bits/stdc++.h> using namespace std; using db = long double; using pll = pair<long long, long long>; const long long sz = 300003; long long dp[sz][2], n; long long a[sz]; long long dfs(long long i, long long par) { if (i >= n) return 0; long long &res = dp[i][par]; if (res == -1) { ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; int counts[n + 1]; memset(counts, 0, sizeof(counts)); ...
#include <bits/stdc++.h> using namespace std; const int N = 105; const int inf = 10000000; int n, k; int l[N], r[N]; int main() { scanf( %d%d , &n, &k); int midx = (k + 1) / 2, midy = (k + 1) / 2; for (int i = 0; i < n; i++) { int m, ans = inf, x, y1, y2; scanf( %d , &m); for (...
#include <bits/stdc++.h> using namespace std; const int N = 500010; const int M = 16; const int inf = 0x3f3f3f3f; const int S = 1 << 15; map<string, int> mp; int vs[15], n, m; char s[N][12], sx[12]; int dp[S], cnt[S][16]; int cal(int st) { int res = 0; while (st) { if (st & 1) res++; ...
#include <bits/stdc++.h> using namespace std; template <typename T> using V = vector<T>; const int MM = 5e5 + 5; using T = long long; bool QUERY; struct Line { mutable T a, b, p; T Eval(T first) const { return a * first + b; } bool operator<(const Line& o) const { return QUERY ? p < o.p : a < ...
#include <bits/stdc++.h> using namespace std; struct Item { int x[3], y[3]; }; bool check(Item t); inline int Dist(int x1, int y1, int x2, int y2) { return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); } int main() { Item it; for (int i = 0; i < 3; i++) cin >> it.x[i] >> it.y[i]; if (...
#include <bits/stdc++.h> using namespace std; void input(long long int n, long long int a[]) { for (long long int i = 0; i < n; ++i) cin >> a[i]; } long long int bin_expo(long long int A, long long int B, long long int M) { long long int result = 1ll; while (B > 0) { if (B % 2 == 1) { ...
#include <bits/stdc++.h> using namespace std; int main() { int sum, t, p, pos, a[100005], b[100005], n, f, c, f1; cin >> t; while (t--) { memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); cin >> n; f = 1; sum = 0; p = 0; f1 = 1, c = 0; for (int i = 0; i < ...
#include <bits/stdc++.h> using namespace std; int left_[105], right_[105], mark[105]; int main() { int n, j; std::ios::sync_with_stdio(0); while (~scanf( %d , &n)) { int ans = 0; memset(left_, 0, sizeof(left_)); memset(right_, 0, sizeof(right_)); memset(mark, 0, sizeof(mark)); ...
#include <bits/stdc++.h> using namespace std; int gcd(int f, int s) { if (s == 0) return f; else return gcd(s, f % s); } int const N = 1000006; long long const M = 1020; long double const ep = .000000000000000001; long long arr[N], arr1[N]; int main() { int n, m; scanf( %d , ...
#include <bits/stdc++.h> using namespace std; long long fact[100005]; long long power(long long x, long long y, long long p) { long long res = 1; x = x % p; while (y > 0) { if (y & 1) res = ((res % p) * (x % p)) % p; y = y >> 1; x = ((x % p) * (x % p)) % p; } return res; } ...
#include <bits/stdc++.h> using namespace std; bool seat[100][100] = {0}; int main() { int n, k; scanf( %d %d , &n, &k); while (n--) { int num, x, l, r, min_sum; min_sum = 100000; scanf( %d , &num); for (int i = 1; i <= k; i++) { for (int j = 1; j <= k - num + 1; j++) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n % 2 == 0) { if (n >= 8 && n % 4 == 0) cout << ((n / 4) - 1) << endl; else if (n > 4 && n < 8) cout << 1 << endl; else if (n <= 4) cout << 0 << endl; else cout << ...
#include <bits/stdc++.h> using namespace std; int main() { int n, shet = 0; long long int ans = 0; cin >> n; ans = n; int* mas = new int[n]; for (int i = 0; i < n; i++) { cin >> mas[i]; } for (int i = 1; i < n; i++) { if (mas[i] == mas[i - 1]) { shet++; an...
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int main() { int a, i, temp; long long int sum = 0, n, fra; cin >> a; for (i = 2; i <= a - 1; i++) { temp = a; while (temp > 0) { sum += temp % i; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; while (scanf( %d%d , &n, &m) != EOF) { for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (i % 2 == 0) { printf( # ); } else { if (i / 2 % 2 == 0 && j == m - 1) ...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const int M = 1e5 + 5; const int N = 1e6 + 5; const int mod = 1e9 + 7; const double pi = acos(-1.0); const int INF = 0x3f3f3f3f; const long long lINF = 0x3f3f3f3f3f3f3f3fLL; const int sINF = 0xcfcfcfcf; char s[M * 2], s1[M]; in...
#include <bits/stdc++.h> using namespace std; #define ll long long #define vi vector<int> #define pii pair<int,int> #define mii map<int,int> #define pqb priority_queue<int> #define pqs priority_queue<int,vi,greater<int> > #define ff first #define ss second #define pb push_back #define mp m...
#include <bits/stdc++.h> using namespace std; char str[10000]; int n, m, Q; map<string, int> mem; map<string, int>::iterator iter; struct Func { string name; int num; int v[10]; bool operator==(const Func& A) const { if (name != A.name) return false; if (num != A.num) return fals...
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; int main() { long long n, a; long long fuck = 0, fucck = 0; cin >> n; priority_queue<int> prio1, prio2; for (int i = 0; i < n; ++i) { cin >> a; prio1.push(a); fuck += a; } for (int i = 0; i < n;...