func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; using ll = long long; const int inf = 0x3f3f3f3f; const int N = 1e5 + 5; const int M = 1e5 + 5; const int mod = 1e9 + 7; int T; int n, ind, l, r; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> ind >> l >> r; if (l == 1 &&...
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << 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; namespace output { void pr(short x) { cout << x; } void pr(unsigned x) { cout << x; } void pr(int x) { cout << x; } void pr(long long x) { cout << x; } void pr(unsigned long long x) { cout << x; } void pr(double x) { cout << x; } void pr(long double x) { c...
#include <bits/stdc++.h> using namespace std; void solve(); int main() { srand(time(0)); cout.setf(ios::fixed); cout.precision(10); int tn = 1; for (int i = 0; i < tn; ++i) solve(); } vector<int> g[100001]; const long long mod = 1000000007; inline void add(long long &a, long long b) { ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int n, m; cin >> n >> m; int a[n][m]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) cin >> a[i][j]; int flag = 0; for (int i = n - 2; i >= 1; i--) { ...
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; namespace IO_Optimization { inline int read() { int X = 0, w = 0; char ch = 0; while (!isdigit(ch)) { w |= ch == - ; ch = getchar(); } while (isdigit(ch)) { X = (X << 3) + (X << 1) + (ch ^ 48); ch ...
#include <bits/stdc++.h> using namespace std; long long a[1 << 20], b[1 << 20], ans; char s[20][1 << 20]; int bit[1 << 20], now, k, n, m, i, N; void FWT(long long *a, int o) { for (int i = 1; i < N; i <<= 1) for (int j = 0; j < N; j += i << 1) for (int k = 0; k < i; k++) { long lon...
#include <bits/stdc++.h> using namespace std; using ll = long long; void solve(istream &cin = std::cin, ostream &cout = std::cout) { int test; cin >> test; int n, m; ll t; while (cin >> n >> m >> t) { vector<int> p(n); for (int &x : p) cin >> x; const int bound = *max_element...
#include <bits/stdc++.h> using namespace std; const int inf = int(1e9) + 7; const double eps = 1e-9; vector<pair<int, int> > g[111]; int dp[111][111][30]; int n, m; int dfs(int u, int v, int x) { if (dp[u][v][x]) return dp[u][v][x]; dp[u][v][x] = 2; for (int i = 0; i < int((g[u]).size()); ++i)...
#include <bits/stdc++.h> using namespace std; int main() { double n, a, d, t, v; cin >> n >> a >> d; double minitime = 0; for (int i = 0; i < n; i++) { cin >> t >> v; double t1 = v / a; double s = a * 0.5 * t1 * t1; if (s > d) { t += sqrt(2 * d / a); } else { ...
#include <bits/stdc++.h> using namespace std; long long int dp[5005][5005]; int main() { long long int n, m, k; cin >> n >> m >> k; long long int arr[n + 1]; long long int sum[n + 1]; for (int i = 1; i <= n; i++) cin >> arr[i]; sum[1] = 0; for (int i = 1; i <= m; i++) sum[1] += arr[i];...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); string s; char big = a ; string s1 = ; cin >> s; for (int i = s.size() - 1; i >= 0; i--) { if (int(s[i]) >= int(big)) { s1 += s[i]; big...
#include <bits/stdc++.h> using namespace std; int n, m; vector<pair<int, int>> g[51][51]; int ch[51][51], vis[51][51], cnt; pair<int, int> par[51][51]; bool isValid(int x, int y) { if (x < 0 || y < 0 || x > n - 1 || y > m - 1) return false; return true; } int dx[] = {-1, 0, 0, 1}; int dy[] = {...
#include <bits/stdc++.h> int main() { int a, b, ans = 0; scanf( %d %d , &a, &b); if (a > b) { ans = (a - b) / 2; printf( %d %d , b, ans); } else if (a < b) { ans = (b - a) / 2; printf( %d %d , a, ans); } else if (a == b) { ans = (a - b) / 2; printf( %d %d , b, a...
#include <bits/stdc++.h> using namespace std; long long n, m1, m2, len, bo, ans, fa[1000005], f[1000000], dep[1000000], nex[1000000], wen[1000000], hea[1000000], val[1000000], v[1000000]; struct arr { long long x, y, z, bo; } a[1000000]; bool cmp(arr x, arr y) { return x.z < y.z; } void add(long l...
#include <bits/stdc++.h> using namespace std; const int MAXK = 1005, MAXM = 30, MOD = 7340033; int f[MAXM][MAXK]; void DP() { static int g[MAXK]; int m, k, i, j; f[0][0] = 1; for (m = 1; m < MAXM; m++) { memset(g, 0, sizeof(g)); g[0] = 1; for (i = 1; i <= 4; i++) for (k...
#include <bits/stdc++.h> using namespace std; const int maxN = 2000 + 5; char s[maxN]; int t, n, k; vector<pair<int, int> > ans; void Reverse(int l, int r) { ans.push_back(make_pair(l, r)); for (int i = l; i <= (l + r) / 2; ++i) swap(s[i], s[l + r - i]); } int main() { scanf( %d , &t); w...
#include <bits/stdc++.h> int main() { int n, i, z = 0, o = 0; char str[120]; scanf( %d , &n); getchar(); gets(str); for (i = 0; i < n; i++) { if (str[i] == 0 ) { z++; } else { o++; } } if (o > 0) { printf( 1 ); } for (i = 0; i < z; i++) ...
#include <bits/stdc++.h> using namespace std; int n, a, b; vector<pair<int, int> > res; vector<vector<int> > v; int cl[100000 * 2 + 5]; bool visited[100000 * 2 + 5]; void dfs(int now, int color) { if (visited[now]) return; visited[now] = true; cl[now] = color + 1; for (int i = 0; i < v[now...
#include <bits/stdc++.h> using namespace std; string s; long long int n, k; long long int L, R; bool query(long long int l, long long int r) { l = max(1LL, l); r = min(n, r); cout << l << << r << endl; cin >> s; if (s == Bad ) exit(0); if (s == Yes ) { if (l == r) exit(0); ...
#include <bits/stdc++.h> using namespace std; int a[200100]; int b[200100]; int p[200100]; int m[200100]; int main() { int n; scanf( %d , &n); for (int i = (0); i < (n); ++i) scanf( %d , &a[i]); for (int i = (0); i < (n); ++i) { scanf( %d , &b[i]); p[b[i]] = i; } int res ...
#include <bits/stdc++.h> using namespace std; vector<pair<long long, long long> > v; map<char, bool> mpp; map<int, int>::iterator it; set<string> s; set<pair<int, int> >::iterator iter; deque<char> d; long long a[500001]; int main() { ios::sync_with_stdio(false); long long n, a, b, c, d, ans =...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; int dp[maxn], num[30]; int main() { int i, j, k, n, m, t, l, ans, x, y, z; char s[maxn]; scanf( %d , &t); while (t--) { scanf( %d%d%d , &n, &m, &k); scanf( %s , s); ans = 1e9; memset(num, 0, sizeof(nu...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; const int INF = 0x3f3f3f3f; const double eps = 1e-9; const int mod = 1e9 + 7; int dp[N]; int main() { dp[0] = 1; int num; while (scanf( %d , &num) != EOF) { bool flag = 0; if (num == 1) { printf( 1 1 n );...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; const int mod = (int)1e+9 + 7; const double pi = acos(-1.); const int maxn = 1000100; long long a[maxn]; int main() { { srand(time(0)); const string file = ; if (!file.empty()) { freopen((file + .in ).c...
#include <bits/stdc++.h> using namespace std; int main() { long long a1, a2, a3, a4, c = 0; cin >> a1 >> a2 >> a3 >> a4; string s; cin >> s; for (int i = 0; i < s.size(); i++) { if (s[i] == 1 ) c += a1; else if (s[i] == 2 ) c += a2; else if (s[i] == 3 ) ...
#include <bits/stdc++.h> using namespace std; class Edge { public: int neighbour; int edge_number; int weight; Edge(int neigh, int edge_no, int weig) { neighbour = neigh; edge_number = edge_no; weight = weig; } }; int main() { int n, m; cin >> n >> m; vector<...
#include <bits/stdc++.h> using namespace std; long long dp[55][55]; int main() { int n, m, t; cin >> n >> m >> t; dp[0][0] = 1; for (int i = 1; i <= 31; ++i) for (int j = 1; j <= 31; ++j) dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j]; long long sol = 0; for (int i = 4; i <= n; ++i) ...
#include <bits/stdc++.h> using namespace std; int dp[81][81][81][81]; vector<pair<int, int>> graph[81]; int solve(int v, int l, int r, int k) { if (k == 0) return 0; if (dp[v][l][r][k] != -1) return dp[v][l][r][k]; int &ret = dp[v][l][r][k]; ret = 1000000; for (auto e : graph[v]) { int...
#include <bits/stdc++.h> using namespace std; int main() { char s1[1000], s2[1000], s3[1000]; int i, l1, l2, l3; scanf( %s%s%s , s1, s2, s3); l1 = strlen(s1); l2 = strlen(s2); l3 = strlen(s3); strcat(s1, s2); sort(s1, s1 + l1 + l2); sort(s3, s3 + l3); if (l1 + l2 == l3) { ...
#include <bits/stdc++.h> using namespace std; int main() { string a, b; cin >> a >> b; if (a == b) cout << a; else cout << 1; return 0; }
// #include <bits/stdc++.h> using namespace std; #define fi first #define se second #define all(x) x.begin(), x.end() #define lch (o << 1) #define rch (o << 1 | 1) typedef double db; typedef long long ll; typedef unsigned int ui; typedef pair<int, int> pint; typedef tuple<int, int, int> ti...
#include <bits/stdc++.h> using namespace std; const int N = 700 + 5; int n, m, d[N], cnt[N][N]; bitset<N> adj[N]; long long ans; int main() { scanf( %d%d , &n, &m); for (int i = 0, u, v; i < m; i++) { scanf( %d%d , &u, &v); d[--u]++, d[--v]++; adj[u][v] = adj[v][u] = true; } ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; struct Sync_stdio { Sync_stdio() { cin.tie(NULL); ios_base::sync_with_stdio(false); } } _sync_stdio; struct FAIL { FAIL() { cout << CHANGE!!! << n ; } }; string go(int iter, long long...
// Author: HarshKumar #include <bits/stdc++.h> using namespace std; #define ll int64_t const ll N = 1e6 + 6, M = 1e9 + 7; int main() { ios::sync_with_stdio(false), cin.tie(nullptr); ll n, k; cin >> n >> k; ll x = min(k * k + 1, n); string s(x, a ); map<char, ll> f; ...
#include <bits/stdc++.h> using namespace std; long long inf = std::numeric_limits<long long>::max(); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long T; cin >> T; while (T--) { long long n, i; cin >> n; string str; cin.ignore(); cin >> str; ...
#include <bits/stdc++.h> using namespace std; char s[10]; int f[2001], c[2001], mtr[2001][2001], n, m, q, x, y; int main() { scanf( %d%d%d , &n, &m, &q); for (int i = 1; i <= n; i++) { f[i] = i; for (int j = 1; j <= m; j++) { scanf( %d , &mtr[i][j]); c[j] = j; } } ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; char s[maxn]; struct Node { int sum, pmx, lmx, mi, ma, d; Node() {} Node(int a, int b, int c, int d, int e, int f) { sum = a; pmx = b; lmx = c; mi = d; ma = e; d = f; } }; Node segT[m...
#include <bits/stdc++.h> using namespace std; long long mo(long long a) { return a % (long long)(1e9 + 7); } long long po(long long x, long long y, long long p) { long long res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y >>= 1; x = (x * x) % p; } return ...
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; int p; string s[100]; string s1, s2, s3 = , s4 = , s5 = , s6, s7, s8, s9; for (int i = 0; i < a; i++) { int p = 0; cin >> s[i]; s6 = s[i]; reverse(s6.begin(), s6.end()); if...
#include <bits/stdc++.h> int n, m, q; char str[1005]; bool a[1005][1005]; std::vector<std::pair<int, int> > del; int num[1005][1005], tot, ld, ru; std::set<std::pair<int, int> > s; namespace FU { int f[1005 * 1005]; std::vector<int> inv[1005 * 1005]; std::set<int> su; void init(int i) { if (su...
#include <bits/stdc++.h> const int MAXN = 100010; int flag[MAXN << 2]; int a[MAXN << 2]; int add; int N, Q; void PushDown(int rt) { int lc = rt << 1; int rc = rt << 1 | 1; if (flag[rt]) { flag[lc] += flag[rt]; flag[rc] += flag[rt]; flag[rt] = 0; } return; } void bui...
#include <bits/stdc++.h> int a[100001], b[100000], map[100000], c[634][100001]; int main() { int n, q; std::cin >> n >> q; for (int i = 1; i <= n; ++i) std::cin >> a[i]; memcpy(b, &a[1], sizeof(b)); std::stable_sort(b, b + n); int N = 0, i = 0; while (i < n) { int r = std::upper_bo...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10, Mod = 1e9 + 7; long long fact[2 * MAXN], dp[MAXN], ps[MAXN], inv[MAXN * 2]; pair<long long, long long> a[MAXN]; long long power(long long x, long long y) { if (!y) return 1; long long ans = power(x, y / 2); ans *= ans; an...
#include <bits/stdc++.h> using namespace std; double p[21], dp[(1 << 21)], ans[21]; int n, k; int main() { scanf( %d %d , &n, &k); for (int i = 0; i < n; i++) scanf( %lf , p + i); dp[0] = 1; for (int bit = 1; bit < (1 << n); bit++) if (__builtin_popcount(bit) <= k) { double rp = 1;...
#include <bits/stdc++.h> const int N = 100, M = 1000; int n, m; double dp[N + 2][N * M + 2]; int main() { scanf( %d %d , &n, &m); if (m == 1) { printf( 1.0 ); return 0; } dp[0][0] = m - 1; int sumr = 0; for (int i = 1; i <= n; i++) { int rank; scanf( %d , &rank); ...
#include <bits/stdc++.h> int Set(int N, int pos) { return N = N | (1 << pos); } int reSet(int N, int pos) { return N = N & ~(1 << pos); } bool check(int N, int pos) { return (bool)(N & (1 << pos)); } using namespace std; string s; int n; bool dp[10010][4], taken[10010][4]; bool isSafe(int pos, int l1) {...
/* * author: zhaoyiping * time: 2021-06-04 23:08:02 */ #include <bits/stdc++.h> using namespace std; const int MAXN = 3e5 + 5; // vector<int> g[MAXN]; long long a[MAXN]; long long c[MAXN]; int fa[MAXN][20]; int deep[MAXN]; int main() { ios::sync_with_stdio(false); cin.tie(0); int ...
#include <bits/stdc++.h> using namespace std; string toBinary(long long n) { string r; while (n != 0) { r = (n % 2 == 0 ? 0 : 1 ) + r; n /= 2; } return r; } int main() { int total; cin >> total; while (total--) { string binaryNum; long long num; cin >...
#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> #pragma GCC optimize( Ofast ) using namespace std; const int M = 1000005; const int nmax = 500010; const int MOD = (1e9) + 7; int nextX[] = {1, -1, 0, 0}; int nextY[] = {0, 0, 1, -1}; int n, m, t; int f[1010][1010]; char s[1010][1010]; bool good(int x, int y) { return (x >...
#include <bits/stdc++.h> using namespace std; int n, m, c0, d0, hsl; int a[15], b[15], c[15], d[15]; int dp[1005][15]; bool dpf[1005][15]; int proc(int x, int num) { if (num == 0) { return 0; } else if (dpf[x][num]) { return dp[x][num]; } else { int &ret = dp[x][num]; ret...
#include <bits/stdc++.h> using namespace std; long long l, w, k; int main() { cin >> l >> w >> k; if (k > l + w - 2) { cout << -1; return 0; } if (k + 1 <= max(l, w)) { long long e = max(l, w); long long t = min(l, w); long long j = (t / (k + 1)) * max(l, w); lo...
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> istream& operator>>(istream& in, pair<T1, T2>& a) { in >> a.first >> a.second; return in; } template <typename T1, typename T2> ostream& operator<<(ostream& out, pair<T1, T2> a) { out << a.first << << a.second;...
#include <bits/stdc++.h> using namespace std; struct e { int a, b; }; e p[100005]; int n, k; bool use[100005]; priority_queue<int, vector<int>, std::greater<int> > Q; bool criteriu(e a, e b) { return a.b > b.b; } long long af; int main() { scanf( %d %d , &n, &k); for (int i = 1; i <= n; ...
#include <bits/stdc++.h> long long n, m, Q; long long T; std::vector<long long> req, l, r; std::vector<long long> fill(std::vector<long long>& req) { std::vector<long long> ans(m + 1); long long tem = T; for (long long i = m; i; i--) { ans[i] = 0; if (i < m) ans[i] = ans[i + 1]; if...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 7; const int MOD = 1e9 + 7; long long a[maxn]; int main() { int n; scanf( %d , &n); long long ans = 0; for (int i = 1; i <= n; ++i) { scanf( %lld , &a[i]); ans += a[i] * (n - a[i] + 1); if (i == 1) continue;...
#include <bits/stdc++.h> using namespace std; int a[1000][1000]; int main(int argc, const char* argv[]) { int n, m, k; cin >> n >> m >> k; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> a[i][j]; } } int r[1000]; int c[1000]; for (int i = 0; i < 1...
#include <bits/stdc++.h> using namespace std; int main() { long long n; long long cur = 9; long long ans = 0; long long dig = 1; cin >> n; while (n > 0) { ans += min(n * dig, cur * dig); n -= cur; cur *= 10; dig++; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int mx = 1e3 + 10; bool f[2][mx]; int nxt[mx], bef[mx]; int d[mx]; int main() { int n, x, u; scanf( %d %d , &n, &x); memset(bef, -1, sizeof bef); memset(nxt, -1, sizeof nxt); for (int i = 1; i <= n; i++) { scanf( %d , &u); i...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; const int L = 20; int h[N], par[N][L]; int getLca(int u, int v) { if (h[v] < h[u]) swap(u, v); int k = h[v] - h[u]; for (int i = 0; i < L; i++) if (k >> i & 1) v = par[v][i]; if (u == v) return v; for (int i = L - ...
#include <bits/stdc++.h> using namespace std; int main() { int t; string str; cin >> t; while (t--) { cin >> str; sort(str.begin(), str.end()); int sz = str.size(); if (str[0] == str[sz - 1]) cout << -1 << endl; else cout << str << endl; } return...
#include <bits/stdc++.h> using namespace std; using cd = complex<double>; const long long INF = 1e15; const int mod = 1e9 + 7; const double Pi = acos(-1); void Fastio() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } int n, cnt = 0; long long x, y; bool Deg[200005]; vect...
#include <bits/stdc++.h> using namespace std; const int maxn = 105; const long long INF = (long long)0x7fffffffffff; long long dp[maxn][maxn][maxn], wi[maxn], c[maxn]; long long min(long long a, long long b) { return a > b ? b : a; } int main() { int n, m, k, temp, flag = 1, ans1 = 0; cin >> n >> m ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 3e3 + 5; const int mod = 998244353; inline void add_mod(int &a, int b) { a += b; if (a >= mod) a -= mod; } inline void chk_mod(int &a) { if (a < 0) a += mod; } inline long long pw(long long a, long long b) { long long res = 1...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); long long int n; cin >> n; long long int k; cin >> k; long long int sum = k; for (int i = (int)2; i <= (int)n; i++) { cin >> k; sum = sum + ((k - 1ll) * ((long long i...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (a == 0) return b; if (b == 0) return a; return gcd(b % a, a); } long long power(long long a, long long b) { long long res = 1; while (b > 0) { if (b % 2 != 0) res = (res * 1ll * a); b /= 2...
#include <bits/stdc++.h> using namespace std; int n, m, k; string s; vector<string> t; vector<pair<pair<int, int>, int> > cro; bool cmp(const pair<pair<int, int>, int> &x, const pair<pair<int, int>, int> &y) { if (x.second == y.second) { if (x.first.first == y.first.first) return x.firs...
#include <bits/stdc++.h> using namespace std; void fio() {} void pti() { double timeuse = clock() * 1000.0 / CLOCKS_PER_SEC; cerr << Timeuse << timeuse << ms << endl; } void end() { exit(0); } namespace io { const int SIZ = 55; int que[SIZ], op, qr; char ch; template <class I> inline ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 100; const int Mod = 1e9 + 7; struct Mat { long long A[2][2]; Mat() { memset(A, 0, sizeof(A)); } void init(void) { for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) A[i][j] = (i == j); } Mat operator+(struc...
#include <bits/stdc++.h> using namespace std; bool solve() { int a, b; scanf( %d %d , &a, &b); int both = int(floor(pow((double)a * b, 1.0 / 3) + 0.5)); if (both == 0) return a == 1 && b == 1; if (a % both != 0 || b % both != 0) return false; if ((long long)a * b != (long long)both * both * ...
#include <bits/stdc++.h> using namespace std; void cline() { cout << n ; } template <typename T, typename... V> void cline(T t, V... v) { cout << t; if (sizeof...(v)) cout << ; cline(v...); } void cspc() { cout << ; } template <typename T, typename... V> void cspc(T t, V... v) { ...
#include <bits/stdc++.h> using namespace std; long long C[1200][1200]; int main() { for (int i = 0; i < 1200; i++) C[i][i] = C[i][0] = 1LL; for (int i = 2; i < 1200; i++) for (int j = 1; j < i; j++) C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % 1000000007; long long k, n, m; scanf( %I6...
#include <bits/stdc++.h> using namespace std; template <typename T> void chkmax(T& x, T y) { if (x < y) x = y; } template <typename T> void chkmin(T& x, T y) { if (x > y) x = y; } inline int read() { int x = 0; char c = getchar(); bool f = 0; while (c < 48) f |= c == - , c = get...
#include <bits/stdc++.h> using namespace std; template <class T> inline void minu(T& x, T y) { x = min(x, y); } template <class T> inline void maxu(T& x, T y) { x = max(x, y); } inline long long bit(long long n) { return 1LL << n; } template <class T> ostream& operator<<(ostream& os, vector<...
#include <bits/stdc++.h> using namespace std; int cnt[200005], n, k, a[200010], ans, sum, num = 1; int main() { cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; sum += a[i]; } if (sum % k) { cout << No ; return 0; } else { sum /= k; for (int i = 1...
#include <bits/stdc++.h> using namespace std; int isreq(char c) { return (c == H ) || (c == Q ) || (c == 9 ); } int main() { int n; cin >> n; int cnt = 0; string str; for (int i = 0; i < n; i++) { cin >> str; if (str[1] == + ) { cnt++; } else if (str[1] == - ) { ...
#include <bits/stdc++.h> using namespace std; template <class T> int len(const T& c) { return (int)c.size(); } int main() { int n, bb; double b1; vector<double> b; cin >> n >> bb; for (int i(0), _n(n); i < _n; ++i) { cin >> b1; b.push_back(b1); } double sum = accumu...
#include <bits/stdc++.h> using namespace std; int main() { int r, c; int j, i; cin >> r >> c; char a; map<int, int> m, n; for (j = 0; j < r; j++) { for (i = 0; i < c; i++) { cin >> a; if (a == S ) { m[i]++; n[j]++; } } } cout <...
#include <bits/stdc++.h> using namespace std; const int maxn = 402; int a[maxn], f[maxn][2]; int n, m, s, ans; int main() { int i, j, k; scanf( %d%d , &n, &m); while (m--) { scanf( %d , &k); while (k--) { scanf( %d , &i); a[i] = ++s; } } for (k = 1; k <= n...
#include <bits/stdc++.h> using namespace std; vector<int> a, b; int main() { int n, m; cin >> n >> m; int x = n + m; int mx = 1; while (1LL * mx * (mx + 1) / 2 <= x) mx++; mx--; for (int i = mx; i >= 1; i--) { if (n >= i) { n -= i; a.push_back(i); } else { ...
#include <bits/stdc++.h> using namespace std; int n; int p[4][4]; int a[(1 << 16)]; int sum1[4]; int sum2[4]; int dio1, dio2; bool ok; int mask; void dfs(int x) { int i, j; if (x == n * n) { if (dio1 == dio2 && dio1 == sum1[0] && sum1[1] == dio1 && sum1[2] == dio1 && sum2[0] ...
#include <bits/stdc++.h> using namespace std; int N, M, A, B; int main() { scanf( %d%d%d%d , &N, &M, &A, &B); int rA = (A - 1) / M + 1, cA = A - (rA - 1) * M; int rB = (B - 1) / M + 1, cB = B - (rB - 1) * M; if (B == N) cB = M; if (rA == rB) { puts( 1 ); exit(0); } if (rA +...
#include <bits/stdc++.h> using namespace std; int ans[11][11]; bool ok; string s; int sol; queue<int> dulj, broj; int pomocnopolje[11][11]; void bfs(int x, int y, int a, int b) { broj.push(a); dulj.push(1); int v[10] = {0}; while (!broj.empty()) { int duljina = dulj.front(); ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; const int INF = 0x3f3f3f3f; template <typename Tp> struct RMQ { int n; int len[MAXN]; Tp mx[MAXN][21]; Tp mi[MAXN][21]; void build_rmq() { for (int j = 1; (1 << j) <= n; j++) for (int i = 1; i + (1 << j) ...
#include <bits/stdc++.h> namespace std { template <typename A, typename B> inline string to_string(pair<A, B> p); template <typename A, typename B, typename C> inline string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> inline string to_string(tuple<A, B, C, D> p);...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; while (n--) { int a; cin >> a; if (a < 4) { cout << 1 << endl; } else { if (a % 2 == 0) { cout << (a / 2) << endl; } else { cout << ((a - 1) / 2) << endl; ...
#include <bits/stdc++.h> using namespace std; const int N = 100000 + 10; const int M = 1000000007; const double eps = 1e-9; const double PI = acos(-1); const int oo = 1000000000; typedef double TT; struct point { TT x, y; point() : x(0), y(0) {} point(TT a, TT b) { x = a; y = b; ...
#include <bits/stdc++.h> using namespace std; long long a, b, c, l; long long sum; int main() { cin >> a >> b >> c >> l; sum = ((l + 1) * (l + 2) * (l + 3)) / 6; for (long long i = 0; i <= l; i++) { long long temp1 = a - b - c + i; if (temp1 >= 0) { long long temp2 = l - i; ...
#include <bits/stdc++.h> using namespace std; using ll = long long int; using pii = pair<int, int>; constexpr int ALPHABET_SIZE = z - a + 1; constexpr int MAX_SIZE = 256; constexpr int INF = 1e8; int n; string s; string as, bs, cs; vector<int> next_pos[ALPHABET_SIZE]; int calced_pos[MAX_SIZE][...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const long long INF = 1e18; const int MAXN = 2e5 + 5; const int T = 1e3 + 10; int dx[] = {-1, 1, 0, 0}; int dy[] = {0, 0, -1, 1}; long long binpow(long long val, long long deg) { if (!deg) return 1; if (deg & 1) return binpow...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) using namespace std; const double PI = 3.141592653589793238463; const int INF = 0x3f3f3f3f; const int INFS = 1000000000; const long long LLINF = 9223372036854775807; const...
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<vi> vvi; typedef vector<vll> vvll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<pii> vpii; typedef ve...
#include <bits/stdc++.h> using namespace std; int n, ans, kol[100500]; vector<int> v; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 0; i < n; i++) { int x; cin >> x; v.push_back(x); } sort(v.begin(), v.end()); for (in...
#include <bits/stdc++.h> using namespace std; int main() { int n, x, y, dist1, dist2; char ch[3], a; ch[0] = getchar(); a = getchar(); ch[2] = getchar(); cin >> n; n = n % 4; if (n == 1 && ((ch[0] == ^ && ch[2] == > ) || (ch[0] == > && ch[2] == v ) || (ch[0] ==...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; string s; int a; int x = 0, y = n + 1; for (int i = 0; i < m; i++) { cin >> s; cin >> s; cin >> s; if (s[0] == r ) { cin >> s; cin >> a; if (a > x) x = a; ...
#include <bits/stdc++.h> using namespace std; int main() { int q, n; cin >> q; while (q--) { cin >> n; vector<int> original; int temp; for (int i = 0; i < n; i++) { cin >> temp; original.push_back(temp); } for (int i = 0; i < original.size(); i++) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; priority_queue<int> q; for (int i = 0; i < 32; i++) { if (n & (1 << i)) { q.push(i); } } if (q.size() > k) { cout << NO n ; } else { while (q.size() != k) { int f ...
#include <bits/stdc++.h> using namespace std; template <class T> inline T mod_v(T num) { if (num >= 0) return num % 1000000007; else return (num % 1000000007 + 1000000007) % 1000000007; } template <class T> inline T gcd(T a, T b) { a = abs(a); b = abs(b); while (b) { a ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, k; cin >> n >> k; vector<long long int> vec(n); for (int i = 0; i < n; i++) { cin >> vec[i]; } sort(vec.begin(), vec.end()); long long int sum = vec[n - 1]; ...