func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; long long maxa = 0; for (int i = 0; i < k; i++) { maxa +=...
#include <bits/stdc++.h> using namespace std; const double pi = 3.141592653589793238462643383; int main() { { int n, m, k, t; cin >> n >> m >> k >> t; set<int> s; ; for (long long i = 0; i < k; i++) { int a, b; cin >> a >> b; int id = (a - 1) * m + b; ...
#include <bits/stdc++.h> using namespace std; array<string, 1510> arr; unordered_set<string> f; int n, k, t = int( S + E + T ); char get(char c1, char c2) { if (c1 == c2) return c1; return t - c1 - c2; } int main() { scanf( %d%d , &n, &k); for (int i = 1; i <= n; i++) { cin >> ar...
#include <bits/stdc++.h> using namespace std; mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); int n; cin >> n; vector<int> a(n); for (int& i : a) cin >> i; int M = *min_element((a).begin(), (a)...
#include <bits/stdc++.h> using namespace std; int main() { int t; int n; cin >> t; while (t--) { cin >> n; for (int i = 0; i < n; i++) cout << 400 << ; cout << endl; } }
#include <bits/stdc++.h> int _min(int a, int b) { if (a < b) return a; return b; } int _max(int a, int b) { if (a > b) return a; return b; } int main() { int i, j, k; int n; int x1, y1, x2, y2, x3, y3, res; scanf( %d %d , &x1, &y1); scanf( %d %d , &x2, &y2); scanf( %d %...
#include <bits/stdc++.h> using namespace std; int n, k, m, ax, ay, cx, cy; int d[100][100], s[100][100]; void take(int ax, int ay, int m) { for (int y = ay; y < ay + m; ++y) { for (int i = y; i <= k; ++i) ++s[ax][i]; } } int main() { while (scanf( %d%d , &n, &k) != EOF) { cx = cy = (...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; int o = 0, s = 0; for (int i = 0; i < n; i++) { cin >> a[i]; s = s + a[i]; if ((a[i] % 2) != 0) { o++; } } if ((s % 2) == 0) { cout << n - o; } else { cou...
#include <bits/stdc++.h> using namespace std; const int N = 2 * 1e5 + 100, mod = 1e9 + 7; int n, k, a, b; int dp[5010][5010], pr[5010][5010]; int add(int a, int b) { a += b; if (a < 0) a += mod; if (a >= mod) a -= mod; return a; } int main() { scanf( %d%d%d%d , &n, &a, &b, &k); dp[...
#include <bits/stdc++.h> using namespace std; const int n0 = 1503, inf = 1e9; int n, s, m, k, a[n0], b[n0], p[n0], L[n0]; int dp[2][n0], mx[n0], best[n0]; int num(int pos) { for (int i = 1; i <= n; i++) { p[i] = p[i - 1] + (a[i] <= b[pos]); } memset(&dp, -0x3f, sizeof(dp)); int res = 0; ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 4e4 + 44; const long long INF = 1e11 + 9; const double eps = 1e-12; int main() { int t; scanf( %d , &t); long long x1, y1, x2, y2, n, m; long long x3, y3, x4, y4; long long answ = 0, ansb = 0; while (t--) { scanf( %ll...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> deg(n), s(n); for (int i = 0; i < n; i++) cin >> deg[i] >> s[i]; vector<pair<int, int>> edges; queue<int> q; for (int i = 0; i < n; i++) if (deg[i] == 1) q.push(i); while (!q.empty()) { ...
#include <bits/stdc++.h> using namespace std; int main() { long long n, m; cin >> n >> m; long long k[n]; pair<long long, long long> dt[m]; for (int i = 0; i < n; i++) cin >> k[i]; for (int i = 0; i < m; i++) cin >> dt[i].first >> dt[i].second; long long total = 0; for (int i = 0; i ...
#include <bits/stdc++.h> using namespace std; char c[1005], s[55], t[55]; int ns[55], nt[55]; int tos[55][30], tot[55][30]; int lenc, lens, lent; int dp[1005][55][55]; void init() { lenc = strlen(c + 1), lens = strlen(s + 1), lent = strlen(t + 1); ns[1] = 0, nt[1] = 0; for (int i = 2, j = 0; i...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } const int MAXN = 1000; const int MAXK = 1000; int n, K; char s[MAXN + 1]; int act[MAXN + 1][2 * MAXK + 1]; char ret[MAXN + 1]; void run() { scanf( %d%d%s , &n, &K, s); m...
#include <bits/stdc++.h> using namespace std; int main() { string nameOne, nameTwo, tmpOne, tmpTwo; cin >> nameOne >> nameTwo; int n; cin >> n; cout << nameOne << << nameTwo << endl; for (int i = 0; i < n; i++) { cin >> tmpOne; cin >> tmpTwo; if (tmpOne == nameOne) ...
#include <bits/stdc++.h> using namespace std; void solve(long long int arr[], long long int n, long long int l) { for (int i = 1; i < n; i++) { arr[i] = min(arr[i], 2 * arr[i - 1]); } long long int exp[n]; for (int i = 0; i < n; i++) { exp[i] = 1LL << i; } long long int ans = LLO...
#include <bits/stdc++.h> using namespace std; bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m, i, j, c; string s, f = YES ; vector<string> v; cin >> n >> m; ...
#include <bits/stdc++.h> using namespace std; long long fastPrime(long long n) { if (n == 2) return true; if (n % 2 == 0) return false; for (long long i = 3; i * i <= n; i++) { if (n % i == 0) return false; } return true; } int main() { ios::sync_with_stdio(0); cin.tie(0); ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 5e5 + 5; template <typename T> void chkmax(T& x, T y) { if (y > x) x = y; } template <typename T> void chkmin(T& x, T y) { if (y < x) x = y; } int N, Q, a[1 << 18]; long long sum; int main() { scanf( %d%d , &N, &Q); for...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int maxm = 1e5 + 80; const int maxn = 5e3 + 80; const int up = 20; template <class T> void read(T &x) { x = 0; char c = getchar(); int f = 1; for (; c < 0 || c > 9 ; c = getchar()) if (c == - ) f = -1; ...
#include <bits/stdc++.h> using namespace std; const int nmax = 1e7 + 5; int cnt[2][nmax]; int valu[100005]; vector<int> g[100005]; int liflevel; int koyta[2]; void dfs(int u, int level = 0) { cnt[level % 2][valu[u]]++; koyta[level % 2]++; for (int v : g[u]) dfs(v, level + 1); if (g[u].em...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:16777216 ) using namespace std; const int MX = 1 << 23; int a, b, c, d, i, j, n, m, k; int lenl[MX + 1], lenr[MX + 1], cnt[MX + 1], len[MX + 1], num[MX + 1]; pair<int, int> sm[MX + 1]; map<int, int> onwork; inline int create(int l, int r) { sm...
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; long long Bpow(long long a, long long s) { if (s == 0) { return 1; } long long u = Bpow(a, s / 2); if (s & 1) return u * u % mod * a % mod; else return u * u % mod; } int32_t main() { long long n; ...
#include <bits/stdc++.h> using namespace std; long long t[2003]; long long viz[2003]; pair<long long, long long> a[2003]; pair<pair<long long, long long>, long long> b[2003]; vector<long long> v[2003]; vector<pair<pair<long long, long long>, long long> > much; vector<pair<pair<long long, long long>, lon...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:16777216 ) using namespace std; const double pi = acos(-1.0); const int inf = (int)1e9; const double eps = 1e-4; const int ss = (int)1e6 + 3; const int base = inf; bool pred(const pair<int, int>& i, const pair<int, int>& j) { if (i.first == j....
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; const long long INFLL = 1e18 + 1; const int MAX = 200001; const long long MOD = 1000000007; long long inq(long long k, long long q) { if (q == 0) return 1; long long l = inq(k, q / 2); if (q % 2 == 0) return l * l % MOD; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 100; const long long inf = 1e18; int bcg[maxn]; struct Edge { int u, v, nxt; long long w; } edge[maxn * 2], edge1[maxn * 2]; vector<Edge> vec[maxn]; struct Node { long long p; int v; friend bool operator<(Node a, No...
#include <bits/stdc++.h> using namespace std; const unsigned int INF = 2000000001; const long long INF0 = 2000000001000000001; const bool DEBUG_OUTPUT = false; const int modulo = 1000000007; const int go[8][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}, {1, 1}, {-1, -1}, {1, -1}, {-1, 1}}...
#include <bits/stdc++.h> using namespace std; const int MAXN = 11; int n; int a[MAXN][MAXN]; void read() { cin >> n; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) cin >> a[i][j]; } } const int INF = 1e9 + 7; const int MAXANS = MAXN * MAXN * 2; int dp[MAXANS][MAXN * MAXN][...
#include <bits/stdc++.h> using namespace std; inline int Read() { int x = 0, f = 1, c = getchar(); for (; !isdigit(c); c = getchar()) if (c == - ) f = -1; for (; isdigit(c); c = getchar()) x = x * 10 + c - 0 ; return x * f; } const int MAXN = 1000005; const int mod = 1e9 + 7; int n, ...
#include <bits/stdc++.h> using namespace std; int main() { { long long i, j, n, a, b, c, d, mx, mn; cin >> n >> a >> b >> c >> d; mx = max(a + b, a + c); mx = max(mx, b + d); mx = max(mx, c + d); mn = min(a + b, a + c); mn = min(mn, b + d); mn = min(mn, c + d); ...
#include <bits/stdc++.h> using namespace std; int n, m, k, ans, x, y, sum, res, day1, day2, moun1, moun2, year1, year2; bool l; char a[100]; string s, s1, s2; vector<int> v; int main() { cin >> n; if (!(n & 1)) { cout << -1; return 0; } for (int i = 0; i < n; i++) printf( %d ,...
#include <bits/stdc++.h> using namespace std; map<long long, long long> m; void solve() { long long n; cin >> n; map<long long, long long>::iterator itr; long long x, maxm = INT_MIN; for (long long i = 0; i < n; i++) { cin >> x; m[x - (i + 1)] += x; } for (auto &it : m) { ...
#include <bits/stdc++.h> using namespace std; bool isVowel(char c) { if (c == a or c == e or c == i or c == o or c == u or c == y ) return true; return false; } int32_t main() { ios::sync_with_stdio(false); cin.tie(nullptr); long long n; cin >> n; string s; cin >...
#include <bits/stdc++.h> using namespace std; int arr[11]; string str[11]; int m, n; int f(int k) { if (k == n) { for (int i = 0; i < m; i++) if (arr[i] != 0) return 0; return 1; } int ans = 0; bool c = 0; for (int i = 0; i < m; i++) if (str[i][k] == 0 ) { ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, m, k; cin >> n >> m >> k; vector<int> val(n); for (int i = 0; i < n; i++) { cin >> val[i]; } if (m == 1) { cout << max(val[0], val[n - 1]) << endl; ...
#include <bits/stdc++.h> using namespace std; int a[500005]; int main() { int n, b, i, ma = 0, ju, cnt, le, st, j; scanf( %d , &n); int hahaha = 1; for (i = 0; i < n; i++) { scanf( %d , &a[i]); } le = 1; ju = a[0]; for (i = 1; i < n; i++) { if (a[i] != ju) le++;...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int mod = 1e9 + 7; const int maxn = 1e6 + 10; int n, k, cnt[maxn], a[maxn], L[maxn], R[maxn]; stack<pair<int, int> > stk; int main() { scanf( %d , &n); ; scanf( %d , &k); ; for (int i = 1; i <= n; i++) scan...
#include <bits/stdc++.h> using namespace std; int p[50001], n, l, r; queue<int> ver[50001]; void go(int pre, int v) { int t; p[v] = pre; if (v != l) { while (!ver[v].empty()) { t = ver[v].front(); ver[v].pop(); if (t != pre) go(v, t); } } } int main() { ...
#include <bits/stdc++.h> long long gcd(long long x, long long y) { if (x > y) std::swap(x, y); return y % x == 0 ? x : gcd(y % x, x); } using namespace std; int main() { int n; scanf( %d , &n); int a[20]; bool flag = true; for (int i = (1); i <= (n); i++) scanf( %d , a + i); for ...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 50; int n, cnt, f[N][18], d[N], fa[N], id[N], s[N]; vector<int> v1[N], v2[N]; void dfs1(int x, int ff) { for (int i = 0; i < 17; i++) f[x][i + 1] = f[f[x][i]][i]; for (int i = 0, y; i < v1[x].size(); i++) if ((y = v1[x][i]) != ff)...
#include <bits/stdc++.h> using namespace std; int main() { string a, b; int n, m; cin >> n >> m; cin >> a >> b; int pw = 1; int ans = 0, res = 0; for (int i = 0; i < m; i++) { if (i < n && a[n - i - 1] == 1 ) res = (res + pw) % 998244353; if (b[m - i - 1] == 1 ) ans = (ans ...
#include <bits/stdc++.h> using namespace std; long long a, b, ans, w1, w2; int main() { cin >> a >> b; ans = 2 * a + 2 * b + 2; w1 = 2 * a + 2 * b + 2; w2 = 2 * a + 2 * b + 2; for (long long i = 1; i <= sqrt(a + b); i++) { if (a % i == 0 && a / i < w1) w1 = a / i; if (b % i == 0 &&...
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 100; int num[N]; bool vis[N]; vector<int> v; int n, k; int main() { scanf( %d %d , &n, &k); int mn = 1e9 + 1000; for (int i = 1; i <= n; i++) { scanf( %d , &num[i]); if (num[i] < mn) { mn = num[i]; vi...
#include <iostream> int main(void) { int count; std::cin >> count; for (int i = 0; i < count; ++i) { int number; std::cin >> number; int64_t sum = 0; for (int j = 0; j < number; ++j) { int part; std::cin >> part; sum += part; } std::cout << (sum % number) * (number -...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<int, int>; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<int> v(n); for (auto &i : v) cin >> i; int q; cin >> q; vector<int> idx(n, 0); vector<int> ops(q, 0); ...
#include <bits/stdc++.h> #define ll long long #define ld long double #define lchild 2*node #define rchild 2*node+1 #define mid (l+r)/2 #define mod 1000000007 #define mx 200007 #define pii pair<int,int> #define pci pair<int,int> #define ff first #define ss second #define piii pair<int,pii> usin...
#include <bits/stdc++.h> using namespace std; const int maxn = 200005; int a[maxn]; int main() { int n; scanf( %d , &n); for (int i = 0; i < n * 2; i++) scanf( %d , &a[i]); sort(a, a + n * 2); long long area = 1ll * (a[n - 1] - a[0]) * (a[n * 2 - 1] - a[n]); for (int i = 1; i < n; i++) {...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> b; if (a >= b) { c = (a - b) / 2; cout << b << << c; } else { c = (b - a) / 2; cout << a << << c; } }
#include <bits/stdc++.h> using namespace std; int main() { int n, d; scanf( %d %d , &n, &d); int data[n + 10]; for (int i = 0; i < n; i++) scanf( %d , &data[i]); long long ans = 0; for (int i = 0; i < n - 1; i++) { int h = upper_bound(data, data + n, data[i] + d) - data; h--; ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 123; int n, t, label[N], times = 0; vector<int> e[N]; vector<pair<int, int> > res; void newLabel(int u) { res.push_back(make_pair(u, times)); label[u] = times; } void dfs(int u, int backLabel = -1, int p = 0) { newLabel(u); ...
#include <bits/stdc++.h> using namespace std; struct point { double df, de; void init(double _df, double _de) { df = _df; de = _de; } } V[100]; int nf, ne, ns, rf, re, rs, df, de; int n, top, place[13]; double ans = 0, dp[21][21], lf, le, ls; bool cmp(const point &a, const point &b...
#include <bits/stdc++.h> using namespace std; template <class T> struct rge { T b, e; }; template <class T> rge<T> range(T i, T j) { return rge<T>{i, j}; } struct debug { template <class T> debug& operator<<(const T&) { return *this; } }; using ll = long long; template <t...
#include <bits/stdc++.h> using namespace std; void solve() { long long a, b; cin >> a >> b; if (b - a > 5) { cout << 0 << n ; } else { long long val = 1; for (long long j = a + 1; j <= b; j++) { val *= (j % 10); val %= 10; } cout << val << n ; } ...
#include <bits/stdc++.h> using namespace std; struct Point { int x; int y; }; struct Rect { int left; int top; int right; int bottom; }; bool FindBoundary(const vector<Point> &pts, Rect *getRect) { if (pts.empty()) { return false; } auto it = pts.begin(); getRec...
#include<bits/stdc++.h> using namespace std; typedef long long ll; //#define rep(i,a,b) for(int i=a;i<b;i++); void solve(){ ll n; cin>>n; string s; cin>>s; vector<ll>v; for(int i=0;i<n;i++){ if (s[i]== * ){ v.push_back(i); } } if (v.size()<=1 or v.size()==n){ cout<<0<<en...
#include <bits/stdc++.h> using namespace std; const double PI = 3.141592653589793; const long long I_MAX = 1LL << 60; long long mod = 1000000007; const long long maxN = 2E5; vector<long long> inv(maxN + 5, 1); vector<long long> fac(maxN + 5, 1); void ADD(long long &x, long long y) { x += y; if (...
#include <bits/stdc++.h> using namespace std; int main() { int W, H, n; scanf( %d%d%d , &W, &H, &n); multiset<int> w, h; w.insert(-W); h.insert(-H); set<int> wa, ha; wa.insert(0); wa.insert(W); ha.insert(0); ha.insert(H); for (int i = 0; i < n; i++) { char t; ...
#include <bits/stdc++.h> using namespace std; const long long MAX = 1000009; long long mod = 998244353; long long n, kek[MAX]; vector<long long> child[MAX]; long long bin(long long num, long long power) { if (power == 0) return 1; else { long long an = (num) % mod; if (power % 2 ==...
#include <bits/stdc++.h> using namespace std; bool chk(int n, int first) { return n & (1 << first); } void set(int& n, int first) { n = n | (1 << first); } void reset(int& n, int first) { n = n & ~(1 << first); } const int mx = 600010; bool f[mx]; int a[mx][3], _size; char s[mx]; int new_node() { ...
#include <bits/stdc++.h> using namespace std; class Solution { public: long long minCost(int n, vector<int>& blocks, vector<int>& prices) { int m = prices.size(); vector<int> pre(n, 0); iota(pre.begin(), pre.end(), 0); if (!blocks.empty() && blocks[0] == 0) { return -1; ...
#include <bits/stdc++.h> using namespace std; int a[1000005]; int main() { string s; int p = 1, q = 1, ans = 0, ansCount = 1; a[0] = -1; cin >> s; for (int i = 0, sz = s.length(); i < sz; i++) { if (s[i] == ( ) { a[p] = i; p++; } else { p--; if (p =...
#include <bits/stdc++.h> using namespace std; long long n, m, k; vector<long long> arr; void solve() { cin >> n >> m >> k; arr.resize(n); for (long long i = 0; i < n; i++) cin >> arr[i]; vector<long long> b; long long l = arr[n - 1] - arr[0]; ; for (int i = 1; i < n; i++) { b.p...
#include <bits/stdc++.h> using namespace std; int main() { int tc; cin >> tc; for (int t = 1; t <= tc; t++) { int b, p, f, rsl = 0; int h, c; cin >> b >> p >> f; cin >> h >> c; b /= 2; if (h >= c) { int mbp = min(b, p); rsl += mbp * h; b -= mbp...
#include <bits/stdc++.h> const int maxn = 3e5 + 5; const long long inf = 1e18; int ind[maxn], now, n; using namespace std; set<pair<int, int>> e[maxn]; vector<long long> answers; bool vis[maxn]; long long dp[maxn][2]; struct node { int u, val; inline bool operator<(const node &b) const { retur...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-5; const int inf = (1 << 31) - 1; const int hinf = 1000000000; const int mod = 1000000007; const int N = 3030; int dp[3030][3030]; int n; int head[3030]; int weizhi; struct node { int u, v, w, next; } point[3030 << 1]; voi...
#include <bits/stdc++.h> using namespace std; using namespace std::chrono; template <typename A> ostream &operator<<(ostream &cout, vector<A> const &v); template <typename A, typename B> ostream &operator<<(ostream &cout, pair<A, B> const &p) { return cout << ( << p.first << , << p.second << ) ; ...
#include <bits/stdc++.h> using namespace std; long long f[20][55][2600], c[20]; long long l[5005], tot = 0; void Turn(long long k) { memset(c, 0, sizeof(c)); while (k) c[++c[0]] = k % 10, k /= 10; return; } int gcd(int x, int y) { return x % y ? gcd(y, x % y) : y; } long long Search(int x, int...
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 100, INF = 1e9; struct edge { long long to, cost, id; }; vector<edge> g[N]; long long d[N], cost[N], path[N], used[N]; pair<long long, long long> from[N]; long long n, m; void bfs() { fill(d, d + n, INF); d[0] = 0; ...
#include <bits/stdc++.h> using namespace std; const int N = 1000010; const int mod = 1e9 + 7; int t[N], dp[2][3][3]; int main() { int n, K; scanf( %d%d , &n, &K); for (int i = 1; i <= n; i++) { int x; scanf( %d , &x); t[x]++; } int cur = 1, pre = 0; for (int i = 1; i ...
#include <bits/stdc++.h> using namespace std; long long int MOD = 1e9 + 7; long long int INF = 1e18; long long int sub(long long int a, long long int b, long long int p = MOD) { return ((a % p) - (b % p) + p) % p; } long long int mult(long long int a, long long int b, long long int p = MOD) { return...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000005; const long long MOD = 1000000007; long long k, w, ans; long long fac[MAXN]; long long inv[MAXN]; long long power(long long a, long long b) { long long res = 1; while (b) { if (b & 1) (res *= a) %= MOD; (a *= a) %= ...
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007; const double sn = 1e-9; const long double PI = 3.141592653589793238L; int n, c, d; int mc[100005]; int md[100005]; vector<pair<int, int>> ac; vector<pair<int, int>> ad; bool cmp(pair<int, int> p1, pair<int, int> p2) { return p...
#include <bits/stdc++.h> using namespace std; #define FOR(n) for(int i = 0; i < int(n); ++i) #define RFOR(n) for(int i = n; ~i; --i) int gcd(int a, int b) { if(b == 0) return a; return gcd(b, a % b); } void solve() { int n; cin >> n; map<pair<int, int>, in...
#include <bits/stdc++.h> using namespace std; vector<vector<int> > edges(2e5 + 5); bool vis[200005]; int lev[200005]; int n, m, a, b, mx; void bfs(int node) { int level = 0; deque<pair<int, int> > dq; dq.push_back({level, node}); vis[node] = 1; while (!dq.empty()) { node = dq.front...
#include <bits/stdc++.h> using namespace std; int d, n, m; int cntl[100011], cntr[100011], cntt[100011], cntb[100011]; struct Sofa { int x1, y1, x2, y2; } sofa[100011]; int main() { scanf( %d , &d); scanf( %d %d , &n, &m); for (int i = 0; i < d; i++) { int x1, y1, x2, y2; scanf( ...
#include <bits/stdc++.h> int main() { long long int n; long long int x; long long int y; long long int number; scanf( %I64d %I64d %I64d , &n, &x, &y); number = y - (n - 1); while (true) { if (number <= 0) { printf( -1 n ); break; } if (number * number + n ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int c = 0, h = 0; while (n > c + h) { h++; c += h; n -= c; } cout << h << endl; }
#include <bits/stdc++.h> using namespace std; constexpr long long ROWS = 2; constexpr long long NMAX = 1e5; long long h[ROWS][NMAX]; long long dp[ROWS][NMAX]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long COLS; cin >> COLS; for (long long i = 0; i < ROWS; ++i) ...
#include <bits/stdc++.h> using namespace std; long long ans = 0; long long mod = 1e9 + 7; int cnt[100005], Tcnt[100005], arr[100005]; vector<int> pri; void era() { pri.push_back(2); for (int i = 3; i <= 100000; i += 2) { if (!arr[i]) for (long long j = (long long)i * i; j <= 100000; j ...
#include <bits/stdc++.h> const long long MaxN = 205; const long long lim = 1e18 + 5; template <class t> inline void read(t &s) { s = 0; register long long f = 1; register char c = getchar(); while (!isdigit(c)) { if (c == - ) f = -1; c = getchar(); } while (isdigit(c)) s = (...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:16777216 ) using namespace std; const double eps = 1e-9; const double pi = acos(-1.0); const int mod = (int)1e9 + 7; const int maxn = (int)1e5 + 10; int pp[4 * maxn]; int a[maxn], c[6][6], pw[maxn][6], pref[maxn][6]; struct node { int cnt; ...
#include <bits/stdc++.h> using namespace std; const int N = 6e5 + 20; int main() { int n, filas, columnas; cin >> n; while (n--) { cin >> filas >> columnas; int arr[300][300] = {0}; bool ya = false; for (int i = 0; i < filas; i++) { for (int j = 0; j < columnas; j++) { ...
#include <bits/stdc++.h> using namespace std; char str[100010]; int f[100010][26 + 2], pre[100010][26], suf[100010][26], g[100010], n; int ans[26 + 2]; int dfs(int l, int r, int c, int fl) { if (l > r) return 0; if (ans[c] != -1) return ans[c]; int u = 0; for (int i = 0; i < 26; i++) { i...
#include <bits/stdc++.h> namespace ZDY { #pragma GCC optimize(3) template <class T> __inline__ __attribute__((always_inline)) T ABS(T x) { return x > 0 ? x : -x; } template <class T> __inline__ __attribute__((always_inline)) T MAX(T x, T y) { return x > y ? x : y; } template <class T> __inli...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; char dis[2000010]; int a[2000010]; int main() { int t; scanf( %d , &t); for (int i = 0; i < 200010; i += 3) { dis[i] = R , dis[i + 1] = G , dis[i + 2] = B ; } while (t--) { int n, k; scanf( %d %d...
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, c, d, e, f, g, h, i, j, k, l, n, v, t; cin >> n >> k; long long m[k]; for (i = 0; i < k; i++) cin >> m[i]; if (n % 2 == 0) { a = m[k - 1]; if (a & 1) cout << odd n ; else cout << even n...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long n; cin >> n; int s = 0, a; a = n / 100; n = n % 100; s += a; if (n != 0) { a = n / 20; n %= 20; s += a; if (n != 0) { a = n / 10; ...
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 9; int pre[MAX], suf[MAX], a[MAX]; long long ans = 0, cnt = 0; int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> a[i], pre[i] = (i > 0 ? pre[i - 1] + a[i] : a[i]); int sum = pre[n - 1] / 3; if (pre[n -...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const long long INF = 1e18; const double EPS = 1e-6; const int MAX_N = 500 + 5; int n; int arr[MAX_N]; int memo[MAX_N][MAX_N]; int memo2[MAX_N][MAX_N]; int dp(int l, int r) { if (l == r) return memo[l][r] = arr[l]; if (me...
#include <bits/stdc++.h> using namespace std; template <class T> inline void gn(T &first) { char c, sg = 0; while (c = getchar(), (c > 9 || c < 0 ) && c != - ) ; for ((c == - ? sg = 1, c = getchar() : 0), first = 0; c >= 0 && c <= 9 ; c = getchar()) first = (first << 1) +...
#include <bits/stdc++.h> using namespace std; const long long INF = 1ll << 32; int n, m, s, e; string ans = ; bool ch(int l, int r, int idx, bool b) { bool re = 1; if (l <= idx && idx <= r) re = 0; if (b) { if (l <= idx + 1 && idx + 1 <= r) re = 0; } else if (l <= idx - 1 && idx - 1 <=...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; int a[n]; vector<int> vec; for (int i = 0; i < n; i++) { cin >> a[i]; }; int...
#include <bits/stdc++.h> using namespace std; inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; } const int INF = (((1 << 30) - 1) << 1) + 1; const int nINF = 1 << 31; pair<long long, long long> egcd(long long a, long long b, pair<long long, long long> x = {1, 0...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 7; int a[maxn]; int n, s; int main() { scanf( %d%d , &n, &s); if (s >= 2 * n) { s -= 2 * n; puts( YES ); printf( %d , 2 + s); for (int i = 1; i < n; ++i) printf( %d , 2); puts( ); puts( 1 ); ...
#include <bits/stdc++.h> using namespace std; int main() { long long n, s = 0; cin >> n; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; s += a[i]; } sort(begin(a), end(a)); if (s % 2 == 0 && 2 * a[n - 1] <= s) cout << YES ; else cout << NO ; ...
#include <bits/stdc++.h> using namespace std; template <typename T> T gcd(T x, T y) { if (x < y) swap(x, y); while (y > 0) { T f = x % y; x = y; y = f; } return x; } struct Node { Node *l, *r; long long a, b; Node() : l(NULL), r(NULL), a(0), b(0) {} }; Node* m...
#include <bits/stdc++.h> using namespace std; long long GCD(long long x, long long y) { while (y != 0) { long long t = x % y; x = y; y = t; } return x; } long long n, a, b; long long cs; bool calc() { scanf( %lld %lld , &a, &b); long long g = GCD(a, b); long long p ...
#include <bits/stdc++.h> using namespace std; string s; int main(void) { int n; cin >> n >> s; int l = 0, r = 0; for (auto &c : s) if (c == L ) ++l; else ++r; cout << r + l + 1 << endl; return 0; }