func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { long long n, sum = 0; cin >> n; for (int i = 0; i < 60; i++) { long long x = 1LL << i; if (n & x) { sum += (1LL << (i + 1)) - 1; } } cout << sum...
#include <bits/stdc++.h> using namespace std; long long n, k, q, a, b, x, y, i = 1, j, p[150000], mas[150005]; pair<int, int> m[10]; int main() { cin >> n >> k >> q; while (i <= n) { cin >> p[i]; i++; } i = 0; while (i < q) { cin >> a >> b; if (a == 1) { if (p...
#include <bits/stdc++.h> using namespace std; void chmax(int& a, int b) { a = max(a, b); } void chmin(int& a, int b) { a = min(a, b); } int nth_bit(int64_t num, int n) { return (num >> n) & 1; } int main() { string S; int X; cin >> S >> X; int N = S.size(); vector<int> A(N); for (int i...
#include <bits/stdc++.h> using namespace std; long long C[4005][4005]; const int mod = 998244853; long long dp[2005][2005]; void norm(long long& x) { while (x < 0) x += mod; while (x >= mod) x -= mod; } int main() { int n, m; cin >> n >> m; C[1][0] = 1; C[1][1] = 1; for (int i ...
#include <bits/stdc++.h> using namespace std; int n, arr[100005], has[100005], t; vector<int> v[100005]; int main() { cin >> n; for (int i = 1; i <= n; i++) { int a; cin >> a; arr[a]++; has[i] = arr[a]; v[has[i]].push_back(a); t = max(t, has[i]); } for (int i ...
#include <bits/stdc++.h> using namespace std; template <typename T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf( %d , &x); } void _R(long long &x) { scanf( % PRId64, &x); } void _R(double &x) { scanf( %lf , &x); } void _R(char &x) { scanf( %c , &x); } void _R(char *x) { scanf( %s , x); }...
#include <bits/stdc++.h> using namespace std; //.define // #define FILE_IN_OUT #define RET(_x) cout << (_x) << n ; return; #define all(_obj) (_obj).begin(), (_obj).end() #define loop(_n) for (int i = 0; i < (_n); ++i) #define sz(_obj) static_cast<int>((_obj).size()) #ifdef SHJ_LOCAL #define debug...
#include <bits/stdc++.h> using namespace std; const int M = 5e3 + 10; int a[M]; int dp[M][M]; int main() { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , a + i), dp[i][i] = a[i]; for (int d = 1; d < n; d++) { for (int i = 1; i + d <= n; i++) { int j = i + d; ...
#include <bits/stdc++.h> using namespace std; const long long eps = 1e9 + 7; const double inf = 1e-12; bool F(set<pair<int, int> > &a) { pair<int, int> p = *a.rbegin(); a.erase(p); --p.first; if (p.first != 0) { a.insert(p); } if (!a.empty() && a.rbegin()->first == a.begin()->first...
#include <bits/stdc++.h> using namespace std; int read() { bool f = 0; int x = 0; char c = getchar(); while (c < 0 || 9 < c) { if (c == - ) f = 1; c = getchar(); } while ( 0 <= c && c <= 9 ) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar(); return !f ? x : -x; ...
#include <bits/stdc++.h> using namespace std; const int MAX = 200005; const int MOD = 1000000007; long long fun(long long a, long long b) { if (a > b) return a; return b; } void swp(long long *a, long long *b) { long long temp = *a; *a = *b; *b = temp; } int main() { ios::sync_wi...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; long long max(long long a, long long b) { if (a > b) { return a; } else { return b; } } long long min(long long a, long long b) { if (a < b) { return a; } else { return b; } } long l...
#include <bits/stdc++.h> using namespace std; int main() { int t; t = 1; while (t--) { int n; cin >> n; int cnt1 = 0, cnt2 = 0, x; for (int i = 0; i < n; i++) { cin >> x; if (x % 2 == 0) cnt1++; else cnt2++; } if (cnt2 % 2 =...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int test = 0; test < t; test++) { bool answer = true; int n; cin >> n; vector<int> a(n); vector<int> b(n); for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >...
#include <bits/stdc++.h> using namespace std; unsigned long long arr[200000], cum[200000]; unsigned long long forone; unsigned long long n; unsigned long long make(unsigned long long st, unsigned long long mult, unsigned long long lim, unsigned long long level) { if (st > n) retu...
#include <bits/stdc++.h> using namespace std; int x, t, a, b, da, db, i, j, p, ans = 0; int main() { scanf( %d %d %d %d %d %d , &x, &t, &a, &b, &da, &db); i = 0; for (i = 0; i < t; i++) for (j = 0; j < t; j++) { if (a - i * da + b - j * db == x) ans = 1; } for (i = 0; i < t; i+...
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, a, b; cin >> n >> a >> b; long long left = a; long long right = n - b - 1; long long end = max(left, right); long long ans = n - end; co...
#include <bits/stdc++.h> using namespace std; int n, p, start[390000], fin[390000]; map<pair<int, int>, int> mp; int main() { scanf( %d %d , &n, &p); vector<int> cnt(n, 0); for (int i = 0; i < n; i++) { int x, y; scanf( %d %d , &x, &y); x--; y--; if (x > y) swap(x, y); ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1000 + 5; int main() { int n, que[maxn]; scanf( %d , &n); for (int i = 0; i < n; i++) scanf( %d , &que[i]); sort(que, que + n); if (n % 2 == 0) n--; printf( %d n , que[n / 2]); }
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 5; int n, k, x, y; set<pair<int, int> > s; vector<pair<int, int> > a[MAXN]; vector<int> ans; inline void start() { scanf( %d%d , &n, &k); for (int i = 1; i <= n; i++) { scanf( %d%d , &x, &y); a[x].push_back({y, i}); ...
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j, k, sum = 0; cin >> n; pair<int, int> a[n]; for (i = 0; i < n; i++) { cin >> a[i].first; a[i].second = i; } sort(a, a + n); for (i = 0; i < n; i++) { sum = sum + ((a[n - i - 1].first * i) + 1); }...
#include <bits/stdc++.h> using namespace std; const long long MAXN = +100500; const long long INF = 4e18; long long a[MAXN]; int main() { long long n, k; cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; } if (k >= 3) { sort(a + 1, a + n + 1); cout << a[n]; ...
#include <bits/stdc++.h> using namespace std; long long a, b; bool check(int k, int x, int y) { long long ca = 1LL * k * x; long long cb = 1LL * k * y; return ca <= a && cb <= b; } long long gcd(long long a, long long b) { if (!b) return a; else return gcd(b, a % b); } int ...
#include <bits/stdc++.h> using namespace std; const int N = 1000005; int n, k; int v[N], c[N], p[N]; double f[N]; double C(int n, int m) { return f[n] - f[m] - f[n - m]; } struct Node { int Max, Min; } node[N * 4]; void pushup(int x) { node[x].Max = max(node[((x << 1) + 1)].Max, node[((x << 1)...
#include <bits/stdc++.h> using namespace std; long long int inv(long long int k) { long long int vl = 1000000007 - 2; long long int val = 1; long long int b = k; for (int i = 0; i < 63; i++) { if ((vl >> i) & 1) { val *= b; val %= 1000000007; } b = b * b; b %=...
#include <bits/stdc++.h> using namespace std; int main() { int n, temp; cin >> n; long long int sum = 0, sum2 = 0; for (int i = 0; i < n; i++) { cin >> temp; sum += temp; } for (int i = 0; i < n - 1; i++) { cin >> temp; sum2 += temp; } cout << sum - sum2 << en...
#include <bits/stdc++.h> using namespace std; int inf_int = 1e9; long long inf_ll = 1e16; const double pi = 3.1415926535898; const int mod = 1e9 + 9; const int MAXN = 2e5 + 100; bool debug = false; char a[1005][1005]; char used[1005][1005][4][3]; int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0};...
#include <bits/stdc++.h> using namespace std; const int N = 300005; int n, k, pos[N]; long long c[N], ans; vector<int> v; priority_queue<pair<long long, int> > q; int main() { scanf( %d%d , &n, &k); for (int i = 1; i <= n; i++) scanf( %lld , &c[i]); for (int i = 1; i <= n + k; i++) { if ...
#include <bits/stdc++.h> int mod = 1000000007; const double pi = 3.141592653689793238460; const int inf = 0x3f3f3f3f; using namespace std; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);...
#include <bits/stdc++.h> using namespace std; const int N = 100000 + 6; int g[N]; int main() { int n, m, v, i; cin >> n >> m >> v; long long top = 1 + (n - 1) * (n - 2) / 2; if (n - 1 > m || top < (long long)m) { cout << -1; return 0; } --v; for (i = 0; i < n; ++i) g[i] =...
#include <bits/stdc++.h> using namespace std; double M; struct E { int x, y, z, tp, id; bool operator<(const E yy) const { double p1 = tp ? z : z + M, p2 = yy.tp ? yy.z : yy.z + M; return p1 < p2; } } e[100005]; int n, m, k, fa[50005], p[50005], d[50005]; int gf(int x) { return fa[x]...
#include <bits/stdc++.h> using namespace std; int n, m, tot, X, Y, a[25][25], d[25], id[25][25]; double p[25], b[500][2], c[500][500], ans[25]; void work() { scanf( %d %d %d %d , &n, &m, &X, &Y); if (X == Y) { for (int i = 1; i <= n; i++) printf( %.10lf , 1.0 * int(i == X)); return; } ...
#include <bits/stdc++.h> using namespace std; int main() { int h, w, ii, jj, ans = 0; cin >> h >> w; char a[505][505]; for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) cin >> a[i][j]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (a[i][j] == * ) { ...
#include <bits/stdc++.h> using namespace std; long long fac[100001]; long long inv_fac[100001]; int val[100001]; vector<int> cnt(53, 0); int l[100001]; int r[100001]; long long keep[53][53]; long long dp[54][100001]; long long dp1[54][100001]; long long mod = 1e9 + 7; inline void add(long long &...
#include <bits/stdc++.h> using namespace std; const long long N = 100010, M = 100010, inf = 1e18; long long m, n, p, d[N], a[M], f[M], sum[M], g[M], x[M], y[M]; inline long long read() { char ch = getchar(); long long as = 0, f = 1; for (; ch < 0 || ch > 9 ; ch = getchar()) if (ch == - ) f...
#include <bits/stdc++.h> using namespace std; const int M = 1e5 + 5; vector<pair<long long, long long>> v; int main() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); long long x, y, bx, by, xs, ys, t, temp1, temp2, temp; long long ax, ay; int ans = 0; cin >> x >> y >> ax >...
#include <bits/stdc++.h> using namespace std; int f[101010]; long long s[101010]; long long a[101010]; int main() { ios_base::sync_with_stdio(0); long long n, l; cin >> n >> l; for (int i = 1; i <= n; ++i) cin >> a[i]; sort(a + 1, a + n + 1); if (n == 1) { cout << fixed << setpre...
#include <bits/stdc++.h> using namespace std; const int maxn = 501; int dp[maxn][maxn]; int n; int a[maxn]; int dp2[maxn]; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i], dp[i][i] = a[i]; for (int len = 1; len <= n; len++) { for (int i = 1; i <= n - len + 1; i++) { ...
#include <bits/stdc++.h> const int N = 1000010, P = 1000000007; int n, i, j, x, ans, po[N], a[N], f[N]; int main() { scanf( %d , &n); for (po[0] = i = 1; i <= n; i++) po[i] = 2 * po[i - 1] % P; while (n--) scanf( %d , &x), a[x]++; for (i = N - 1; i > 1; i--) { for (j = i, x = 0; j < N; j += ...
#include <bits/stdc++.h> using namespace std; vector<int> a; int x; int main() { while (cin >> x) { a.push_back(x); } if (((a[3] - a[2]) == (a[2] - a[1])) && ((a[2] - a[1]) == (a[1] - a[0]))) { cout << a[3] + a[3] - a[2] << endl; return 0; } else { if (a[0] != 0) { ...
#include <bits/stdc++.h> using namespace std; template <class T> T __sqr(const T x) { return x * x; } template <class T, class X> inline T __pow(T a, X y) { T z = 1; for (int i = 1; i <= y; i++) { z *= a; } return z; } template <class T> inline T gcd(T a, T b) { a = abs(a...
#include <bits/stdc++.h> using namespace std; template <class T> istream& operator>>(istream& in, vector<T>& vec) { for (auto& v : vec) { in >> v; } return in; } template <class T> ostream& operator<<(ostream& o, const vector<T>& vec) { o << [ ; for (const auto& v : vec) { o...
#include <bits/stdc++.h> using namespace std; const int N = 2005; int n, m, ans[N], h[N]; bitset<N> a[N]; vector<int> e[N]; bool check1() { for (int i = (int)(1); i <= (int)(n); i++) if (e[i].size() & 1) return 0; return 1; } void gauss() { int it = 1; for (int i = (int)(1); i <= (...
#include <bits/stdc++.h> #pragma warning(disable : 4786) #pragma comment(linker, /STACK:16777216 ) using namespace std; int A[100005]; int I[100005]; int D[100005]; int n; int max(int a, int b) { if (a > b) return a; return b; } int ABS(int a) { if (a < 0) return a = a * -1; return ...
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; long long POW(long long a, long long b, long long MMM = MOD) { long long ret = 1; for (; b; b >>= 1, a = (a * a) % MMM) if (b & 1) ret = (ret * a) % MMM; return ret; } long long gcd(long long a, long long b) { return b ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int N = 1000005; const double PI = 4 * atan(1); const double eps = 1e-7; long long x, y, z; int main() { ios::sync_with_stdio(0); cin >> x >> y >> z; long long ans = 0; ans = x / z + y / z; long long a, b; ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int a[N], b[N], d[N], used[N], dis[N], ANS[N], dlt[N]; int n, m, Y0, Y1, lft, ans; vector<int> ch[N], fa[N]; priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > pq; int ABS(int x) { ...
#include <bits/stdc++.h> using namespace std; std::mt19937 rnd( (int)std::chrono::steady_clock::now().time_since_epoch().count()); long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } const int MOD = 1000000007; void inc(int& a, int b) { if ((a += b) >= MOD) a -= MOD; } ...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); char t[n + 1]; scanf( %s , t); int i = 0, k = 1; while (t[i] != 0 ) { printf( %c , t[i]); i = i + k; k++; } return 0; }
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long INFF = 0x3f3f3f3f3f3f3f3fll; const long long M = 1e9 + 7; const long long maxn = 1e6 + 7; const double pi = acos(-1.0); const double eps = 0.00000001; long long gcd(long long a, long long b) { return b ? gcd(b, a %...
#include <bits/stdc++.h> using namespace std; int main() { int n, a, mn, mx, ans = 0; cin >> n >> a; mn = mx = a; for (int i = 1; i < n; i++) { cin >> a; if (a < mn) { mn = a; ans++; } if (a > mx) { mx = a; ans++; } } cout << ans;...
#include <bits/stdc++.h> using namespace std; inline int gi() { char tmp = getchar(); int ans = 0, flag = 1; while (!isdigit(tmp)) { if (tmp == - ) flag = -1; tmp = getchar(); } while (isdigit(tmp)) { ans = ans * 10 + tmp - 0 ; tmp = getchar(); } return ans * fl...
#include <bits/stdc++.h> using namespace std; int main() { map<string, string> hh; map<string, string>::iterator it; int n; string a, b, c; cin >> n; while (n--) { cin >> a >> b; it = hh.find(a); if (it == hh.end()) hh[b] = a; else { c = it->second; ...
#include <bits/stdc++.h> using namespace std; int n, m, c[23][23], d[23], u[23]; int main() { scanf( %d%d , &n, &m); for (int xt, yt, i = 1; i <= m; ++i) { scanf( %d%d , &xt, &yt); if (c[xt][yt] || xt == yt) continue; ++d[xt], ++d[yt]; c[xt][yt] = c[yt][xt] = 1; } for (int ...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<pair<int, int> > v; for (int i = 0; i < n; i++) { int a; cin >> a; v.push_back(make_pair(a, i)); } sort(v.begin(), v.end()); int cur = 0; vector<int> ans; for (int i = 0; ...
#include <bits/stdc++.h> using namespace std; bool Check(char x) { if (x <= 3 && x >= 1 ) return true; else return false; } int main() { char s[1000]; cin >> s; char x; for (int i = 0; i < strlen(s); ++i) { for (int j = i + 1; j < strlen(s); ++j) { if (s[j] <...
#include <bits/stdc++.h> int a[300300]; int b[300300]; int t[300300]; int n, q; void update(int u, const int &val) { while (1 <= u && u <= n) { t[u] += val; u = u + (u & (-u)); } } int sum(int u) { int res = 0; while (1 <= u && u <= n) { res += t[u]; u = u & (u - 1)...
#include <bits/stdc++.h> using i64 = long long; std::vector<std::vector<int>> read_tree1(int v) { std::vector<std::vector<int>> graph(v); while (v-- > 1) { int x, y; std::cin >> x >> y; graph[x - 1].push_back(y - 1); graph[y - 1].push_back(x - 1); } return graph; } templa...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int MAXN = 2e5 + 5; int n, k, d, ansL = 1, ansR = 1, top1, top2, flag, pos; int a[MAXN], st1[MAXN], st2[MAXN]; map<int, int> lst; namespace SegmentTree { struct Tree { int l, r; int w, tag; } tree[MAXN << 2]; voi...
#include <bits/stdc++.h> using namespace std; const int N = 2005, K = 55, mod = 998244353; int n, k, b[N], f[2 * K][N], g[2 * K][N], C[N][N]; int main() { scanf( %d%d , &n, &k); for (int i = 1; i <= n; i++) scanf( %d , &b[i]); f[k][0] = 1; for (int i = 1; i <= n; i++) { memset(g, 0, sizeof...
#include <bits/stdc++.h> using namespace std; template <class T> void printArray(vector<T> arr) { for (T a : arr) cout << a << ; cout << n ; } void printVerdict(bool verdict) { cout << (verdict ? YES : NO ) << n ; } vector<long long> findPrime(long long n) { vector<long long> ret; ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5; const long long M = 1e9 + 9; int n, x, y; pair<int, int> pos[N]; map<pair<int, int>, int> mp; set<int> q; long long ans; int children(int x, int y) { int ret = 0; for (int dx = -1; dx <= 1; dx++) { map<pair<int, int>, int>:...
#include <bits/stdc++.h> using namespace std; const long long UNDEF = -1; const long long INF = 1e18; template <typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; } template <typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true : false; ...
#include <bits/stdc++.h> using namespace std; static const int INF = 500000000; template <class T> void debug(T a, T b) { for (; a != b; ++a) cerr << *a << ; cerr << endl; } string s[2005]; int n, K; int lcp[2005]; int prof[2005][2005]; struct uf { int par[2005]; vector<int> dp[20...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); int arr[n + 10]; for (int i = 1; i <= n; i++) scanf( %d , &arr[i]); int start, end; start = 1; int pos_1 = -1, pos_2 = -1; int cnt = 0; int t = 0; for (int i = 1; i <= n;) { pos_1 = -1; ...
#include <bits/stdc++.h> using namespace std; struct bign { int len, s[109]; bign() { memset(s, 0, sizeof(s)); len = 1; } bign(int num) { *this = num; } bign(const char *num) { *this = num; } bign operator=(const int num) { char s[109]; sprintf(s, %d , num); *t...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long N = 5e5; long long id[N], a[N], pos[N]; int main() { ios_base::sync_with_stdio(false); long long n, t, m, l, k, ans, i, j, res = 0, fl; t = 1; long long x; while (t--) { long long o; ci...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; long long gcd(long long a, long long b) { if (b == 0) return a; else return gcd(b, a % b); } signed main() { long long t; cin >> t; while (t--) { long long n; cin >> n; long long maxa...
#include <bits/stdc++.h> using namespace std; long long Gcd(long long a, long long b) { if (a % b == 0) return b; return Gcd(b, a % b); } long long Max(long long a, long long b) { if (a > b) return a; return b; } long long Min(long long a, long long b) { if (a < b) return a; return b...
#include <bits/stdc++.h> const double EPS = 1e-24; const long long int MOD = 1000000007ll; const double PI = 3.14159265359; int INF = 2147483645; long long int INFINF = 9223372036854775807; template <class T> T Max2(T a, T b) { return a < b ? b : a; } template <class T> T Min2(T a, T b) { re...
#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, m, a, b; cin >> n >> m >> a >> b; a--; b--; vector<vector<int> > graph(n); for (int i = 0; i < m; i++) { int u, v;...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; const int M = 0x3f3f3f3f; long long n, m, k, q, h; int ld[N], rd[N]; vector<long long> p; int main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin >> n >> m >> k >> q; vector<vector<long long> > vec(n + 1); ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); string a; cin >> a; char vowels[5] = { a , e , i , o , u }; for (int i = 0; i < a.size() - 1; ++i) { bool flag = false; for (int k = 0; k < 5; ++k) { ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; const long long Inf = 0x3f3f3f3f3f3f3f3f; int n, x, y, z, cnt, tot, head[maxn], vis[maxn]; long long res, r[maxn], l[maxn], l0[maxn], r0[maxn], sum[maxn], ans1, ans2 = Inf, f[maxn], cir[maxn]; struct Edge { int to, next, w; ...
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; bool Finish_read; template <class T> inline void read(T &x) { Finish_read = 0; x = 0; int f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == - ) f = -1; if (ch == EOF) return; ch = getchar();...
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, a; cin >> n >> m >> a; cout << (n / a + (n % a != 0)) * (m / a + (m % a != 0)); return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 200100; int n, b; queue<pair<int, int> > q; long long ans[MAXN]; int main() { scanf( %d%d , &n, &b); long long available = 0; memset(ans, 0xff, sizeof ans); for (int i = 0, t, d; i < n; ++i) { scanf( %d%d , &t, &d); w...
#include <bits/stdc++.h> using namespace std; int main() { int x[3], l; scanf( %d%d%d%d , x, x + 1, x + 2, &l); long long ans = 1LL * (l + 3) * (l + 2) * (l + 1) / 6; for (int i = 0; i < 3; i++) for (int lx = 0; lx <= l; lx++) { int xx = min(l - lx, x[i] + lx - x[(i + 1) % 3] - x[(i + ...
#include <bits/stdc++.h> using namespace std; int n, a[100003], i; int main() { cin >> n; for (i = 1; i <= n; i++) cin >> a[i]; long long p = clock(); while (clock() - p < 1400) ; sort(a + 1, a + 1 + n); for (i = 1; i <= n; i++) cout << a[i] << ; return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 3010; int a[MAXN], b[MAXN], c[MAXN]; int d[MAXN][2]; int main() { int n; while (~scanf( %d , &n)) { for (int i = 1; i <= n; ++i) scanf( %d , &a[i]); for (int i = 1; i <= n; ++i) scanf( %d , &b[i]); for (int i = 1; i <= n;...
#include <bits/stdc++.h> using namespace std; int n, l, a[110], s, x, len; int main() { cin >> n >> l; for (int i = 1; i <= n; i++) { cin >> a[i]; if (a[i] > s) s = a[i]; } for (int i = l; i <= s; i++) { for (int j = 1; j <= n; j++) x += a[j] / i; if (len < i * x) len = i *...
#include <bits/stdc++.h> using namespace std; template <int MOD_> struct modnum { static constexpr int MOD = MOD_; static_assert(MOD_ > 0, MOD must be positive ); private: using ll = long long; int v; static int minv(int a, int m) { a %= m; assert(a); return a == 1 ? 1...
#include <bits/stdc++.h> using namespace std; int a, b; int x; int main() { scanf( %d%d%d , &a, &b, &x); if (a >= b) for (int i = 0; i <= x - 2; i++) { printf( %d , i & 1); a -= !(i & 1); b -= (i & 1); } else { for (int i = 1; i <= x - 1; i++) { prin...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); long long n, m, p; cin >> n >> m >> p; long long a; long long b; long long u = 0, v = 0; for (long long i = 1; i <= n; i++) { cin >> a; if (u == 0 && a % p != 0) { ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int n, k; cin >> n >> k; vector<int> *dist = new vector<int>[n]; int len = 0; for (int i = 0; i < n; i++) { int d; cin >> d; dist[d].push_back(i); len = max(len, d); } ...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, n; cin >> a >> b >> n; bool aa = 0, bb = 1; if (a < b) swap(a, b), swap(aa, bb); for (int i = 0; i < a - (n + 1) / 2 - (n % 2 == 0); i++) cout << aa; for (int i = 0; i < (n + 1) / 2; i++) cout << aa << bb; for (int i = ...
#include <bits/stdc++.h> char s[100005], stack[100005], ss; int main() { long long n, k, now, i, i2, l, plus = 0, kid, pos; scanf( %lld %lld , &n, &k); for (i = 1; i <= k; i++) { scanf( %lld , &now); plus = 0; ss = 0; kid = n; while (kid / 2 + plus + 1 != now) { if ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 10; const int MAXM = 4e6 + 10; const long long MOD = 1e9 + 7; const long long INF = 0x3f3f3f3f; const unsigned long long BASE = 233; const int base = 5; mt19937_64 mt(time(0)); char rubbish[110]; bool GETDATA; inline long long re...
#include <bits/stdc++.h> using namespace std; int ts, kk = 1; template <class T> inline T _sq(T a) { return a * a; } template <class T, class X> inline T _pow(T a, X y) { T z = 1; for (int i = 1; i <= y; i++) { z *= a; } return z; } template <class T> inline T _gcd(T a, T b...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const int maxn = 1007; long long dp[maxn][maxn][4]; char s[maxn]; int T, k; long long dfs(int pos, int dis, int ok, int limit) { if (pos == -1) { return ok; } if (!limit && dp[pos][dis][ok] != -1) return dp[pos]...
#include <bits/stdc++.h> using namespace std; clock_t time_p = clock(); void timer() { time_p = clock() - time_p; cerr << Execution Time: << (double)(time_p) / CLOCKS_PER_SEC << n ; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, k, r = 2...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e3 + 6.66; const int MAXM = 2e3 + 6.66; const long long MOD = 1e9 + 7; long long dp[MAXN][MAXM]; long long dp1[MAXN][MAXM]; long long par[MAXN][MAXM]; long long par2[MAXN][MAXM]; int main() { ios::sync_with_stdio(false); cin.tie(N...
#include <bits/stdc++.h> using namespace std; long long i, n, m, a[1000001], t1, t2, sum; int main() { cin >> n >> m; for (i = 0; i < m; i++) { scanf( %I64d %I64d , &t1, &t2); a[t1]++; a[t2]++; } for (i = 1; i <= n; i++) sum += a[i] * (n - 1LL - a[i]); sum /= 2LL; cout <<...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000; set<pair<long long, long long> > q; long long prod(pair<long long, long long> a, pair<long long, long long> b) { return a.first * b.second - a.second * b.first; } bool check(pair<long long, long long> a, pair<long long, long long> b,...
#include <bits/stdc++.h> using namespace std; const int MAXN = 200005; int N, M, K; int A[MAXN]; int B[MAXN]; set<int> adj[MAXN]; int deg[MAXN]; set<pair<int, int> > st; bool inGraph[MAXN]; int ans[MAXN]; void update(int x) { if (!inGraph[x]) return; set<pair<int, int> >::iterator it = st....
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC optimize( unroll-loops ) #pragma GCC target( avx2 ) using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long k; cin >> k; long long pref = 0; vector<long long> poww10(17); poww10[0] ...
#include <bits/stdc++.h> using namespace std; int l, r, x, y; vector<int> primes; int cnt(int idx, int a, int b) { if (idx == primes.size()) return a >= l && a <= r && b >= l && b <= r; return cnt(idx + 1, a * primes[idx], b) + cnt(idx + 1, a, b * primes[idx]); } int main() { cin >> l >> r >> x ...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); const ld pi = acos(0) * 2; template <typename T> inline void read(T &x) { char c; bool nega = 0; while ((!isdigit(c = get...
#include <bits/stdc++.h> using namespace std; struct graph { int n; vector<vector<int>> adj; graph(int n) : n(n), adj(n) {} void add_edge(int u, int v) { adj[u].push_back(v); } vector<int> &operator[](int u) { return adj[u]; } }; vector<vector<int>> scc_gabow(graph &adj) { int n = adj.n;...
#include <bits/stdc++.h> using namespace std; const int N = 5005; short dp[N][N]; int ans[N]; int main() { string s; cin >> s; int n; n = s.size(); for (int len = 1; len <= n; len++) { for (int l = 0; l < n - len + 1; l++) { int r = l + len; if (len == 1) { ...