func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int a[200009]; int s1[200009]; int s2[200009]; int id1[200009]; int id2[200009]; int main() { int n; cin >> n; for (int i = 1; i <= 2 * n; ++i) id1[i] = -1; for (int i = 1; i <= 2 * n; ++i) id2[i] = -1; for (int i = 0; i < n; ++i) { c...
#include <bits/stdc++.h> using namespace std; void per() { cerr << endl; } template <typename Head, typename... Tail> void per(Head H, Tail... T) { cerr << H << ; per(T...); } template <class T> bool uin(T& a, T b) { return a > b ? (a = b, true) : false; } template <class T> bool uax(...
#include<bits/stdc++.h> #include<algorithm> #define ll long long using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int testcases; cin>>testcases; while(testcases--){ int n,k; cin>>n>>k; unsigned ll sum = 0 ; cin>>sum; ...
#include <bits/stdc++.h> using namespace std; int n, q; long long ans = 0; vector<int> graph[100005]; int depth[100005]; int parent[100005]; int weight[100005]; int ancestor[100005][17]; int comp[100005]; vector<int> comp_members[100005]; int comp_root[100005]; long long ansv[100005]; void mer...
#include <bits/stdc++.h> using namespace std; const int MOD = pow(10, 9) + 7; int main() { ios_base::sync_with_stdio(false); int k; cin >> k; string s; cin >> s; int n = s.length(); int l = 0, r = 0; long long ans = 0LL; long long count1 = 0; while (l < n && k != 0) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n, x, k, i, j, t; vector<int> b, a; vector<bool> v; cin >> n >> k; v.resize(n, false); for (i = 0; i < n; i++) { cin >> x; b.push_back(x); if (x == 0) { v[i] = true; a.push_back(i + 1); } ...
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, k; cin >> n >> k; long long a[n + 2][n + 2], i, j; string s; memset(a, 0, sizeof(a)); for (i = 1; i <= n; i++) { cin >> s; for (j = 1...
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> bool compare(T x, U y) { return (abs(x - y) <= 1e-9); } const int MOD = 1e9 + 7; void solve() { long long a, b; cin >> a >> b; if (b == a) { cout << 1; return; } if ((b - a) >= 10) cout ...
#include <bits/stdc++.h> using namespace std; int solve(string &s) { int len = s.length(); int ret = 0; for (int i = 0; i < len; ++i) { if (s[i] == V && i + 1 < len && s[i + 1] == K ) { ++ret; } } return ret; } int main() { string s; while (cin >> s) { in...
#include <bits/stdc++.h> using namespace std; int a[100000], k, i, n, j; char c; int main() { string s; cin >> k; i = 0; int p = 0; getline(cin, s); getline(cin, s); for (j = 0; j < s.length(); j++) { c = s[j]; p++; if (c == ? || c == . || c == ! ) { if...
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, /STACK:60777216 ) const int N = 1111111; char s[N]; int n, k; const int mod = 1000000007; int f[N], g[N], h[N], ps[N], pW[N], pX[N], pB[N], p2[N], pr[N]; inline void solve(int *f, int *g, char W, char B, char X) { pW[0] = pX[0] =...
#include <bits/stdc++.h> using namespace std; int inf = INT_MAX >> 1; double PI = 3.1415926535897932384626433832795; set<vector<char> > st; int ans = 0; void rotX(vector<char> &c); void rotY(vector<char> &c); void solve(string s) { vector<char> c(6); for (int i = 0; i < s.size(); i++) c[i] = s[i...
#include <bits/stdc++.h> using namespace std; int main() { long long t; long n; cin >> t; int a[t]; for (int i = 0; i < t; i++) { cin >> a[i]; } for (int i = 0; i < t; i++) { if (a[i] <= 2) { cout << 0 << endl; } else { n = (a[i] / 2.0); if (a[i]...
#include <bits/stdc++.h> using namespace std; char str[120][120]; int n; int grid[26][26]; int ru[26], vis[26]; char ans[30]; int cheat; void cmp(int a, int b) { int lena = strlen(str[a]); int lenb = strlen(str[b]); int len = min(lena, lenb); for (int i = 0; i < len; i++) { if (str...
#include <bits/stdc++.h> using namespace std; int main() { int tt; cin >> tt; while (tt--) { long long n; cin >> n; string s = to_string(n); int c = 0; for (int i = 0; i < s.size(); i++) { if (s[i] != 0 ) c++; } cout << c; cout << n ; for ...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; const int N = (int)5e5 + 100; const int M = (int)2e6 + 100; const int inf = (int)1e9 + 100; string s, t; long long mod = 998244353; bool was[3001][3001]; long long table[3001][3001]; long long f(int x, int y) { if (x < 0) r...
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353LL; typedef struct EDGE { int from, to, type, vis; EDGE() { vis = 0; } EDGE(int _f, int _t, int _ty) : from(_f), to(_t), type(_ty) { vis = 0; } } Edge; char s[2010]; vector<Edge> edges; vector<int> G[2010]; int n, v...
#include <bits/stdc++.h> using namespace std; const int seed = 131; const long long LLMAX = 2e18; const int MOD = 1e9 + 7; const double eps = 1e-8; const int MAXN = 1e6 + 10; const int hmod1 = 0x48E2DCE7; const int hmod2 = 0x60000005; inline long long sqr(long long x) { return x * x; } inline int sq...
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void smin(T &a, U b) { if (a > b) a = b; } template <typename T, typename U> inline void smax(T &a, U b) { if (a < b) a = b; } template <class T> inline void gn(T &first) { char c, sg = 0; while (c =...
#include <bits/stdc++.h> using namespace std; struct option { int s; int t; bool operator<(const option &next) const { if (this->s == next.s) return this->t < next.t; else return this->s < next.s; } }; vector<int> num1; vector<int> num2; vector<option> oLis; int...
#include <bits/stdc++.h> using namespace std; int a[26], b[26]; long long int q; int comp(long long int k) { long long int qs = q; for (int i = 0; i < 26; i++) qs -= max(b[i] * k - a[i], 0LL); return qs >= 0; } int main() { cin.tie(0); cin.sync_with_stdio(0); cout.precision(10); ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 3005; queue<int> q; vector<int> G[MAXN]; int d[MAXN][MAXN]; bool vis[MAXN]; void bfs(int s) { memset(vis, 0, sizeof(vis)); vis[s] = true; d[s][s] = 0; q.push(s); while (!q.empty()) { int u = q.front(); q.pop(); ...
#include <bits/stdc++.h> using namespace std; priority_queue<pair<int, char> > pr; bool is_prime(int n) { if (n == 1) return 0; for (int i = 2; i * i <= n; i++) if (n % i == 0) return 0; return 1; } vector<int> prime, pos[1004]; map<int, int> mark, mark2; map<int, int>::iterator it; bo...
#include <bits/stdc++.h> using namespace std; int n, t, k, cnt = 0; int a[200005], st[200005]; struct hehe { int x, y; } e[200005]; void add(int x, int y) { cnt++; e[cnt].x = x; e[cnt].y = y; } void solve() { int i, j; int minn = 1, maxx = 1; a[0] = 1; st[0] = 1; for ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:1024000000,1024000000 ) using namespace std; long long qp(long long a, long long b, long long mod) { long long t = 1; while (b) { if (b & 1) t = t * a % mod; b >>= 1; a = a * a % mod; } return t; } struct DOT { int ...
#include <bits/stdc++.h> const int MAX = 1e3 + 5; using namespace std; int edge, mx, ans, seen[MAX], a, n, m, k, spec[MAX], check[MAX][MAX]; vector<int> adj[MAX]; vector<int> cur; void dfs(int node) { if (seen[node] == 1) return; seen[node] = 1; cur.push_back(node); for (int i = int(0); i <=...
#include <bits/stdc++.h> using namespace std; long long int po(int a) { if (a == 0) return 1; long long int x = po(a / 2); x = x * x; x %= 1000000007; if (a % 2 == 0) { return x; } else { x = x * 2; x %= 1000000007; return x; } } int main() { int x, y; ...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1e6 + 5; const double delta = 1e-6; const long long mod = 1e9 + 7; struct ev { double coord; int type; int mincost; }; const bool operator<(const ev& f, const ev& s) { return f.coord < s.coord; } void init() {} class fenwick {...
#include <bits/stdc++.h> using namespace std; int dp[4010][4010]; int pa[4010][4010], pb[4010][4010]; char a[4010], b[4010]; int ti, td, tr, te; int la, lb; int main() { scanf( %d%d%d%d , &ti, &td, &tr, &te); scanf( %s%s , a + 1, b + 1); la = strlen(a + 1); lb = strlen(b + 1); for (int...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; int n, k; long long quick(long long A, long long B) { if (B == 0) return 1; long long tmp = quick(A, B >> 1); tmp *= tmp; tmp %= MOD; if (B & 1) tmp *= A, tmp %= MOD; return tmp; } in...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; char **a = new char *[n]; for (int i = 0; i < n; i++) { a[i] = new char[m + 1]; cin >> a[i]; } for (int i = 0; i < n; i++) for (int j...
#include <bits/stdc++.h> using namespace std; mt19937 gen(chrono::system_clock::now().time_since_epoch().count()); const int N = 1e6 + 10; const long long MOD = 1e9 + 7; const long long p1 = 57, M1 = 1e9 + 3; const int rx[4] = {-1, 0, 1, 0}; const int ry[4] = {0, 1, 0, -1}; const int hx[8] = {-2, -2, -1...
#include <bits/stdc++.h> using namespace std; void solve() { long long int n, k; cin >> n >> k; string s; cin >> s; string ans = ; long long int reqd = k / 2, op = 0, cl = 0; for (auto x : s) { if (op < reqd) { if (x == ( ) { ans.push_back(x); op++; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j, s1 = 0, s2 = 0, s3 = 0, s4 = 0; int a[105][105]; cin >> n; int k = (n + 1) / 2; for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) { cin >> a[i][j]; } cout << endl; } for (i = 1; i <= n; i+...
#include <bits/stdc++.h> using namespace std; int32_t main() { ios::sync_with_stdio(0); int64_t n, m, d; cin >> n >> m >> d; vector<pair<int64_t, int64_t> > a1(n), a2(m); for (auto &e : a1) { cin >> e.first >> e.second; e.second = -e.second; } for (auto &e : a2) { cin >...
#include <bits/stdc++.h> using namespace std; int main() { int n, b; cin >> n >> b; if (n - b <= b) { cout << -1; } else { cout << b * n << n ; for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= b + i; j++) { cout << i << ; if (j % n == 0) { ...
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool chkmin(T &x, T y) { return y < x ? x = y, 1 : 0; } template <typename T> inline bool chkmax(T &x, T y) { return x < y ? x = y, 1 : 0; } const int INF = 0x3f3f3f3f; const int N = 2e3 + 10, mod = 1e9 + 7; int dir[4...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100010; long long int tmp = 85; long long int a[MAXN], b[MAXN], ind[MAXN]; vector<long long int> o; long long int n, d, x; long long int getNextX() { x = (x * 37 + 10007) % 1000000007; return x; } int main() { cin >> n >> d >> ...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int a = 1; for (int i = 1; i < s.size(); i++) { if (s[i] == 1 ) { a += 10; } else { a += s[i] - 0 ; } } cout << a << n ; }
#include <bits/stdc++.h> using namespace std; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); string s; cin >> s; long long i; bool flag = true; for (i = 0; i < s.length(); i++) { if (s[i] == 0 ) { s.erase(i, 1); flag = false; break; } } ...
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; int add(int x, int y) { x += y; while (x >= MOD) x -= MOD; while (x < 0) x += MOD; return x; } int mul(int x, int y) { return (x * 1ll * y) % MOD; } int power(int n, int m, int p) { int res = 1; while (m > 0) { ...
#include <bits/stdc++.h> using namespace std; void itval(istream_iterator<string> it) {} template <typename T, typename... Args> void itval(istream_iterator<string> it, T a, Args... args) { cerr << *it << = << a << endl; itval(++it, args...); } const long long int MOD = 1e9 + 7; template <type...
#include <bits/stdc++.h> using namespace std; const long long INFL = 1LL << 60; const long long INF = 1 << 30; long long MOD = 1000000007; vector<long long> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0}; vector<long long> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0}; void pres(double A, long long x = 10) { cout << fixed...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int n, x, m, tmp, ans, sum, t; int a[N], b[N], h[N]; string s, p; map<string, int> pol; vector<int> nei[N]; bool mark[N]; void read_input() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; if (a[i] > 1 && ...
#include <bits/stdc++.h> using pi = std::pair<int, int>; using vec = std::vector<pi>; const int N = 300007, P = 1019260817; char str[N]; int n, fa[N], size[N], dep[N], son[N], top[N], dfn[N], id[N], pw[N], ipw[N], h[N][2]; std::vector<int> e[N]; int sgn(int x) { return x < 0 ? -1 : 1; } int sub(in...
#include <bits/stdc++.h> using namespace std; default_random_engine generator; uniform_int_distribution<int> distribution(1, INT_MAX); vector<vector<long long> > one(int sz) { vector<vector<long long> > ret; ret.resize(sz); for (int i = 0; i < ret.size(); i++) { ret[i].resize(sz); for (i...
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize( O3 ) #pragma comment(linker, /stack:200000000 ) #pragma GCC optimize( Ofast,unroll-loops,no-stack-protector,fast-math ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) const long long mod = 1e9 + 7; const lo...
#include <bits/stdc++.h> #pragma GCC optimize(3, Ofast , inline ) #pragma GCC target( avx,avx2 ) using namespace std; template <class t> inline t read(t &x) { char c = getchar(); bool f = 0; x = 0; while (!isdigit(c)) f |= c == - , c = getchar(); while (isdigit(c)) x = (x << 1) + (x << ...
#include <bits/stdc++.h> using namespace std; int now, ot, mi, last, cnt, le, d[10010], st[10010][15], len[10010], ans[10010], trs[10010][26], fa[10010], tot[10010], lev[10010]; char s[10010]; inline int ext(int x) { for (now = last; s[le - len[now]] ^ x; now = fa[now]) ; if (trs[now][x]) re...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long n; cin >> n; long count1 = 0, count2 = 0; int f = 0; while (n != 1) { if (n % 3 == 0) { n = n / 3; count1++; } if (n % 2 == 0) { ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100000 + 10; struct Edge { int v; bool used; Edge(int v, int used) : v(v), used(used) {} }; vector<int> adj[MAXN], odd, ans; vector<Edge> edges; int p, n, m, deg[MAXN]; int cur[MAXN]; void dfs(int u) { for (auto &idx = cur[...
#include <bits/stdc++.h> using namespace std; const long double PI = acos(-1.0); const long double eps = 1e-6; const int maxw = 1e6 + 10; const int maxn = 5e2 + 10; int n, m, K; char s[maxn][maxn]; vector<int> res[maxn]; int num[maxn][maxn], dp[maxn][maxn]; void solve() { for (int i = 1; i <= n;...
#include <bits/stdc++.h> using namespace std; long long t, x, y, n; int main() { cin.tie(NULL); ios::sync_with_stdio(false); cin >> t; while (t--) { cin >> n >> x >> y; vector<int> ans; int number = y - x; for (int i = 1; i <= number; i++) { if (number % i) continue...
#include <bits/stdc++.h> const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, -1, 0, 1}; using namespace std; char str[5001]; class Point { public: int Left; int Right; int Up; int Down; }; Point f1[5001], f2[5001]; int ans1, ans2, n, m; int dfs(int p, int tot) { int tmp; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n == 2) { cout << 1 2 << endl; return 0; } bool usedN = false; for (int i = 0; i < n; i++) { int maxi = 0; for (int j = 0; j < n; j++) { int a; cin >> a; if (a > ...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int a[3003]; double f[3003 * 3003]; int main() { int n; scanf( %d , &n); for (int i = 1; i < n + 1; i++) scanf( %d , &a[i]); int cnt = 0; for (int i = 1; i < n + 1; i++) { for (int j = i + 1; j < n + 1; j++) { ...
#include <bits/stdc++.h> using namespace std; class DSU { public: vector<int> parent; int total_components; DSU(int n) { parent.resize(n + 1); for (int i = 1; i <= n; i++) { parent[i] = i; } total_components = n; } int get(int x) { if (parent[x] == x) { ...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const int N = 10003; const long long oo = 1e18; int get(int x, int l, int r) { if (x <= l) return l - x; if (r <= x) return x - r; return 0; } int l[N], r[N], zn[N]; long long d1[N], d2[N]; vector<int> st; map<in...
#include <bits/stdc++.h> using namespace std; long long int pows[51]; vector<int> base_3(long long int n) { vector<int> f(51); int r = 0; while (n > 0) { f[r++] = (int)n % 3; n /= 3; } return f; } int main() { int q; cin >> q; pows[1] = 3; pows[0] = 1; for (...
#include <bits/stdc++.h> using namespace std; const int qq = 3e5 + 10; vector<int> G[qq]; multiset<int, greater<int> > myset; int num[qq]; void Del(int x) { auto t = myset.find(x); myset.erase(t); } int main() { int ans = 2e9 + 10; int n; scanf( %d , &n); int a, b; for (int i...
#include <bits/stdc++.h> using namespace std; void debug_out() { cerr << endl; } template <class T> ostream& prnt(ostream& out, T v) { out << v.size() << n ; for (auto e : v) out << e << ; return out; } template <class T> ostream& operator<<(ostream& out, vector<T> v) { return prnt(ou...
#include <bits/stdc++.h> using namespace std; int a[10][5]; int ulx, uly, drx, dry; bool isd(int x, int y) { return x <= drx && x >= ulx && y <= dry && y >= uly; } bool vis[210]; int numtot; int pos; int len; int abs(int x) { return x < 0 ? -x : x; } bool isd2(int x, int y) { return abs(x - a[po...
#include <bits/stdc++.h> using namespace std; int n, m, S, T, du[10010]; struct edge { int u, v, cap, flow; edge() {} edge(int u, int v, int c, int f) : u(u), v(v), cap(c), flow(f) {} }; vector<edge> edges; vector<int> e[10010]; inline void add_edge(int u, int v, int c) { edges.push_back(e...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const int N = 1005; int n, m; int a[N], ans[N], pre[N]; int main() { int i, j, k, t, nc = 0; while (scanf( %d%d , &n, &m) != EOF) { int tmin = -1, tpre = -1; for (i = 1; i <= m; i++) { scanf( %d , &a[i]);...
#include <bits/stdc++.h> #pragma comment(linker, /stack:200000000 ) #pragma GCC optimize( Ofast ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) using namespace std; class FKuroniAndThePunishment { public: vector<long long> primes; void pre(int n) { vector<bool...
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; int n, k, now, last; long long dp[2][505][505], sum[505], ans = 0, s; int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> n >> k; memset(dp[1], 0, sizeof dp[1]); dp[1][1][1] = 1; for (int i...
#include <bits/stdc++.h> using namespace std; bool poss = true; int n, rt = 0; vector<int> v, res; vector<vector<int>> adj; vector<pair<int, int>> dfs(int second, int p) { vector<pair<int, int>> cur; for (auto i : adj[second]) { if (i != p) { vector<pair<int, int>> ch = dfs(i, second);...
#include <bits/stdc++.h> using namespace std; int n, m, q; struct matrix { int val; } matr[109][109]; matrix* mat[109][109]; int main() { scanf( %d %d %d , &n, &m, &q); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { matr[i][j].val = 0; mat[i][j] = &matr[i][j]; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 100; const int maxpow = 1 << 17; const int inf = 1e9 + 7; long long h[maxn]; int par[maxn]; struct node { pair<int, int> a; node(pair<int, int> _a) : a(_a) {} node() : a(0, -1) {} void merge(node x, node y) { a = max(x.a,...
#include <bits/stdc++.h> using namespace std; int main() { int n, r = 0, l = 0; vector<int> d; cin >> n; d.resize(n); for (int i = 0; i < n; ++i) { int x, y; cin >> x >> y; l += x; r += y; d[i] = x - y; } int maxx = abs(r - l), n_max = -1; for (int i = 0...
#include <bits/stdc++.h> using namespace std; int main() { int TC; cin >> TC; while (TC--) { int p, f, cnts, cntw, s, w; cin >> p >> f >> cnts >> cntw >> s >> w; if (s < w) { swap(s, w); swap(cnts, cntw); } int maxi = 0; for (int i = 0; i <= min(p / w,...
#include <bits/stdc++.h> using namespace std; vector<bool> vis; vector<vector<long long>> adj; void dfs(long long node) { vis[node] = true; for (long long child : adj[node]) { if (vis[child]) continue; dfs(child); } } signed main() { ios::sync_with_stdio(false); cin.tie(0); ...
#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(); ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long ti; cin >> ti; for (long long io = 0; io < ti; io++) { long long n, m; cin >> n >> m; vector<long long> a, ao, b; for (long long i = 0; i < m; i++) { ...
#include <bits/stdc++.h> using namespace std; struct ed { int a, b, w; } p[600010]; int n, m, fa[600010], d[600010], ans; bool cmp(ed a, ed b) { return (a.w > b.w); } int gf(int x) { return (fa[x] != x) ? fa[x] = gf(fa[x]) : x; } int main() { cin >> n >> m; for (int i = 1; i <= m; i++) cin >> ...
#include <bits/stdc++.h> int arr[100005]; int k; void unsort(int left, int right) { if (k <= 0 || left >= right - 1) return; int mid = (left + right) / 2; std::swap(arr[mid - 1], arr[mid]); --k; unsort(left, mid); unsort(mid, right); } int main() { int n; scanf( %d%d , &n, &k);...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, i, j, res = 0, k, v1, v2; cin >> n; vector<long long> v; for (i = 0; i < n; i++) { cin >> j; v.emplace_back(j); } if (n == 1) { cout << v[0] << ...
#include <bits/stdc++.h> using namespace std; const int MAX = 100010; string nick[MAX]; int ara[MAX], ord[MAX], b[MAX]; int save[MAX]; bool cmp(int a, int b) { if (ara[a] == ara[b]) return nick[a] < nick[b]; return ara[a] > ara[b]; } deque<int> D; int main() { ios_base::sync_with_stdio(fal...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 100; vector<int> a[N]; int d[N]; void work(int l, int r) { d[l]++; d[r + 1]--; } int main() { cin.tie(0); cin.sync_with_stdio(false); memset(d, 0, sizeof(d)); int n, c, m, tp, i, j, x, y; cin >> n >> c; int s...
#include <bits/stdc++.h> using namespace std; const int N = 2005, M = N * N; bool vis[N]; char s[N][2][25]; int n, m, dfn[N], low[N], tt, S[N], col[N]; int hd[N], V[M], nx[M], fs[N], q[N], id[N], in[N]; vector<int> e[N]; void add(int u, int v) { nx[++tt] = hd[u]; V[hd[u] = tt] = v; } void ta...
#include <bits/stdc++.h> using namespace std; int main() { char c; int ans = 0; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { cin >> c; if (c == . ) continue; if (c == Q ) ans += 9; if (c == q ) ans -= 9; if (c == R ) ans += 5; if (...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long base = 31; int xx[4] = {0, 0, 1, -1}; int yy[4] = {-1, 1, 0, 0}; string step = URDL ; long long Pow(long long a, long long b) { long long res = 1; if (b <= 0) return 1; while (b > 0) { if (b % 2...
#include <bits/stdc++.h> long long int n, k; long long int a[100010], max; long long int print[100010], pc; int main(void) { long long int i, j, f, l, mid; long long int sum, baki = 2147483647; scanf( %I64d %I64d , &n, &k); for (i = 1; i <= n; i++) { scanf( %I64d , &a[i]); if (max < ...
#include <bits/stdc++.h> using namespace std; template <class T> void pr(const string& name, T t) { cerr << name << : << t << endl; } template <typename T, typename... Types> void pr(const string& names, T t, Types... rest) { auto comma_pos = names.find( , ); cerr << names.substr(0, comma_pos...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < 10; i++) { } set<int> s(a.begin(), a.end()); if (s.size() < k) { cout << NO << endl; } else { ...
#include <bits/stdc++.h> using namespace std; vector<int> G[100005]; vector<int> rG[100005]; int f[100005]; int n, m; bool canUsing[100005]; bool canAss[100005]; void dfs0(int u) { canUsing[u] = 1; if (f[u] == 1) return; for (int i = 0; i < rG[u].size(); i++) { int v = rG[u][i]; ...
#include <bits/stdc++.h> using namespace std; bool letras[26]; int main() { list<char> kbd; list<char>::iterator i; int t, j; bool foundKbd; string s; for (cin >> t; t > 0; t--) { foundKbd = true; cin >> s; for (j = 0; j < s.size() && foundKbd; j++) { if (kbd.size...
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) { if (ch == - ) f = -1; } for (; isdigit(ch); ch = getchar()) { x = x * 10 + ch - 48; } return x * f; } const int mxN = 1e5; co...
#include <bits/stdc++.h> using namespace std; template <class T> T gi() { T x = 0; bool f = 0; char c = getchar(); while (c != - && (c < 0 || c > 9 )) c = getchar(); if (c == - ) f = 1, c = getchar(); while (c >= 0 && c <= 9 ) x = x * 10 + c - 0 , c = getchar(); return f ? -x...
#include <bits/stdc++.h> using namespace std; int main() { int n, k, i; double sum = 0, num, av, av1; cin >> n >> k; int a[n]; for (i = 0; i < n; i++) { cin >> a[i]; sum = sum + a[i]; } av1 = sum / n; if (av1 >= (k - .5)) { cout << 0 << endl; return 0; } e...
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { x = x * 10 + ch - 0 ; ch = getchar(); } return x * f;...
#include <bits/stdc++.h> using namespace std; int main() { int n, k, sum = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> k; sum += (int)abs(k); } cout << sum << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { bool check = false; int left, right; cin >> left >> right; for (int i = left; i <= right; i++) { int num = i; bool ch[10] = {false}; while (num > 0) { if (ch[num % 10]) break; ch[num % 10] = true; nu...
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << : << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, , ); ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int A[n], ans = 0, maxi = -1; for (int i = 0; i < n; i++) { cin >> A[i]; if (A[i] == 1) ans++; else { maxi = max(ans, maxi); ans = 0; } } for (int i = 0; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; template <typename T> using minpq = priority_queue<T, vector<T>, greater<T>>; long long pl, pr, vl, vr; int k; long long inter(long long a, long long b, long long c, long long d) { return max(0LL, min(b, d) - max(a, c) + 1); } int main() { ios::sync_...
#include <bits/stdc++.h> using namespace std; int dx[4] = {0, 0, 1, -1}; int dy[4] = {1, -1, 0, 0}; const int maxn = 1e5 + 10; char dir[4] = { R , L , D , U }; vector<vector<int> > a, ind, nxt; pair<int, int> rh[maxn]; vector<int> vect[maxn], pos_undo; int nxt2[maxn], pos[maxn], n, m, mt[maxn], cnt...
#include <bits/stdc++.h> const int N = 1e6 + 10; using namespace std; inline int min(int a, int b) { return a < b ? a : b; } int main() { int a, b, c; while (~scanf( %d%d%d , &a, &b, &c)) { int k = min(min(a / 3, b / 2), c / 2); a -= 3 * k; b -= 2 * k; c -= 2 * k; if (a == ...
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cout << name << : << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const int N = 1234567; int x[N], y[N]; int n; double areas[N]; void line(int i, int j, double &a, double &b, double &c) { i %= n; j %= n; a = y[j] - y[i]; b = x[i] - x[j]; c = -a * x[i] - b * y[i]; } void i...