func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int x, y; cin >> x >> y; int ans = 0; int d = max(abs(x), abs(y)); if (d == 0) { cout << 0 << n ; return 0; } else ans = (d - 1) * 4; if (...
#include <bits/stdc++.h> using namespace std; struct Aho { Aho *son[26]; Aho *fail; int cntstr, faildp; Aho() { for (int i = 0; i < 26; ++i) son[i] = NULL; fail = NULL; cntstr = 0; faildp = -1; } }; void insert(Aho *x, int i, const string &str) { if (i < str.size(...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int MOD = 1e9 + 7; const int base = 101; inline void chmax(int& x, int y) { if (x < y) x = y; } inline void chmin(int& x, int y) { if (x > y) x = y; } inline int LSB(int i) { return (i & -i); } int n, m, dp[10005...
#include <bits/stdc++.h> using namespace std; const long long p = 1e9 + 7; int mk[705][705][3][3]; char s[705]; long long ck(int l, int r, int lc, int rc) { if (l > r) return !lc || !rc || lc != rc; if (mk[l][r][lc][rc]) return mk[l][r][lc][rc]; for (int i = l, cnt = 0;; i++) { if (s[i] == ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( avx,avx2,fma ) using namespace std; using ll = long long; using ull = unsigned long long; template <typename T> void print(vector<T> v) { for (T i : v) cout << i << ; cout << n ; } template <typename T> void prin...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; const int INF = 0x3f3f3f3f; int n, m, a[maxn], b[maxn], f[maxn], g[maxn], l[maxn], p[maxn], ans[maxn]; bool vis[maxn]; int main() { scanf( %d , &n); for (int i = (1), _end_ = (n); i <= _end_; ++i) scanf( %d , &a[i]); a[++n]...
#include <bits/stdc++.h> using namespace std; int getChar(char c) { if (c == + ) return 1; return 0; } string s; stack<int> mystack; int main() { cin >> s; int n = s.size(); int temp; for (int i = 0; i < n; i++) { temp = getChar(s[i]); if (mystack.empty()) mystac...
#include <bits/stdc++.h> using namespace std; const int inf = 2000000000; const double eps = 1e-9, Pi = 2 * acos(0); int main() { ifstream fin( input.txt ); ofstream fout( output.txt ); string s; cin >> s; map<string, int> make_pair; for (int i = 0; i <= 9; i++) { string x; c...
#include <bits/stdc++.h> using namespace std; int N, memo[1 << 25]; pair<int, int> arr[30]; int dist(int a, int n) { int k1 = arr[n].first - arr[a].first; int k2 = arr[n].second - arr[a].second; return k1 * k1 + k2 * k2; } int dp(int mask) { if (__builtin_popcount(mask) == N) { return ...
#include <bits/stdc++.h> using namespace std; char a[51][51]; int main() { memset(a, 0 , sizeof(a)); int n; cin >> n; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) cin >> a[i][j]; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) { int x = a[i][j] - 0 ...
#include <bits/stdc++.h> using namespace std; char str[2][400000 + 10]; int n; void sortstr(int t, int l, int r) { if ((r - l + 1) & 1) return; int md = (l + r) / 2; sortstr(t, l, (l + r) / 2), sortstr(t, (l + r) / 2 + 1, r); bool needswap = false; for (int i = l, j = md + 1; i <= md; i++, j...
#include <bits/stdc++.h> using namespace std; int n, m, gxx; pair<int, int> a[411111]; int p[411111]; int Gxx[411111], bb[411111]; int degree[411111]; int h, t; void make_ans(int x, int y, int tot) { int now_x = degree[x] - 1 - tot; int need_x = max(h - now_x, 0); int now_y = degree[y] - 1 -...
#include <bits/stdc++.h> using namespace std; int n, k; int v[100000 + 1]; int mx, rez; pair<int, int> rz[100000 + 1]; int stkLen; int stkLen2; int stk[100000 + 1]; int stk2[100000 + 1]; int s, s2; void readFile() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(); cin >> n >> k...
#include <bits/stdc++.h> using namespace std; long long ar[200010]; void solve() { long long a, b, c = 0, i, j, t, k, lie, m, n, o, x, y, z; long long p = 0, sm = 0, cnt = 0; scanf( %lld , &n); string s; cin >> s; if (n == 1) { printf( Yes n ); return; } for (i = 0; i <...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const int mod = 1e9 + 7; const int N = 1e6 + 10; const int inf = 1e9; int t, n, k; char s[N]; int cnt[N]; int a[N], b[N]; int main() { ios::sync_with_stdio(false); cin >> t; while (t--) { cin >> n >> k; ci...
#include <bits/stdc++.h> using std::string; using std::vector; namespace Template { struct IN { template <class T> void fr(T& a) { T s = 0; int w = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) w = -1; ch = getchar(); } while (c...
#include <bits/stdc++.h> template <typename T> void MACRO_VAR_Scan(T& t) { std::cin >> t; } template <typename First, typename... Rest> void MACRO_VAR_Scan(First& first, Rest&... rest) { std::cin >> first; MACRO_VAR_Scan(rest...); } template <typename T> void MACRO_VEC_ROW_Init(int n, T& t) ...
#include <bits/stdc++.h> using namespace std; template <typename A, typename B, typename C> struct triple { A X; B Y; C Z; triple(A a = 0, B b = 0, C c = 0) : X(a), Y(b), Z(c) {} }; template <typename A, typename B, typename C> triple<A, B, C> make_triple(A a = 0, B b = 0, C c = 0) { ret...
#include <bits/stdc++.h> using namespace std; const int inf = 1000000000 + 7; const int N = 1000006; int n, a[305], ar[6], s, aa, bb, cc, mn = inf, x, t; int main() { cin >> n >> s; for (int i = 1; i <= n; i++) { scanf( %d , &x); ar[x]++; } for (int i = s / n; i >= 0; i--) { ...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const int MAXN = 200005; int n, x[MAXN]; long long a[MAXN], t; long long b[MAXN]; void solve() { for (int i = 0; i + 1 < n; i++) { if (x[i] > x[i + 1]) { cout << No << endl; return; } } fo...
#include <bits/stdc++.h> using namespace std; int N, Q, C, Rt, L[200005], R[200005], G[200005], F[200005], ch[200005][2]; struct Nod { int Now, Max, Min, Laz; Nod() { Min = 1 << 30; Max = -Min; } } T[200005]; vector<int> son[200005]; void Upd(int x, int k) { if (x) T[x].Now += k,...
#include <bits/stdc++.h> using namespace std; const long long N = 112, INF = 1e18; long long t, n, m, a[N]; long long B10(string s) { reverse(s.begin(), s.end()); long long ret = 0; for (long long i = 0; i < s.size(); i++) { if (s[i] == 1 ) ret += (1ll << i); } return ret; } strin...
#include <bits/stdc++.h> using namespace std; int p[100100]; int main() { int n, a, b, t, cn = 1; cin >> n; for (int i = 0; i < n; i++) { cin >> a; p[i] = a; } sort(p, p + n); int ans = 0; vector<int> v; for (int i = 0; i < n; i++) { int j = 0; for (j = 0; j...
#include <bits/stdc++.h> using namespace std; const int N = 2100; char mp[N][N]; int n, m, lp, rp, dis[N][N]; bool vis[N][N]; struct poi { int x, y; } q[N * N], st; void expan(int x, int y, int di) { int i; for (i = x; mp[i][y] != * ; i--) { q[++rp] = (poi){i, y}; dis[i][y] = di...
#include <bits/stdc++.h> using namespace std; char buf[25]; struct node { long long x, y; bool operator<(node tp) const { if (x != tp.x) return x < tp.x; return y < tp.y; } }; map<long long, long long> h1, h2; map<node, long long> t, q; const long long inf = 1e17; const long long...
#include <bits/stdc++.h> using namespace std; void RI() {} template <typename... T> void RI(int& head, T&... tail) { scanf( %d , &head); RI(tail...); } template <typename T> void _dump(const char* s, T&& head) { cerr << s << = << head << endl; } template <typename T, typename... Args> ...
#include <bits/stdc++.h> using namespace std; int n, m; long long a, b[100100], p[100100]; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> m >> a; for (int i = 1; i <= n; i++) cin >> b[i]; for (int i = 1; i <= m; i++) cin >> p[i]; sort(b + 1, b + ...
#include <bits/stdc++.h> using namespace std; int n, a[100000], outpalsz, inn, b[100000]; long long result; int inicount[100001], iniodd; int ccount[100001], codd; int main() { cin.sync_with_stdio(false); cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n - 1 - i && a[i...
#include <bits/stdc++.h> using namespace std; long long get(string a) { long long len = a.length(); long long b = 0; long long cnt = 1; for (int i = len - 1; i >= 0; i--) { b += ((a[i] - 0 ) % 2) * cnt; cnt *= 2; } return b; } int p[262150]; int main() { int t; cin...
#include <bits/stdc++.h> using namespace std; const int MOD = (int)1e9 + 7; const int INF = (int)1e9; const long long LINF = (long long)1e18; const long double PI = acos((long double)-1); const long double EPS = 1e-9; inline long long gcd(long long a, long long b) { long long r; while (b) { ...
#include <bits/stdc++.h> using namespace std; int main() { string str; cin >> str; int ans(0); for (int i = 0; i < str.size(); ++i) if (str[i] != str[str.size() - 1 - i]) ++ans; if (ans == 2 || (ans == 0 && str.size() % 2 == 1)) cout << YES << endl; else cout << NO << e...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:256000000 ) using namespace std; int main() { srand(1373737); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, t, k, d, q; cin >> n >> q; vector<int> arr(n); for (int i = 0; i < (int)q; i++) { cin...
#include <bits/stdc++.h> using namespace std; template <class T> inline bool uin(T& a, T b) { return a > b ? (a = b, true) : false; } template <class T> inline bool uax(T& a, T b) { return a < b ? (a = b, true) : false; } int main() { ios::sync_with_stdio(false); cin.tie(0); long lon...
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize( O2 ) #pragma GCC optimize( unroll-loops ) struct POINT { int x, y; POINT() : x(0), y(0) {} POINT(int x, int y) : x(x), y(y) {} POINT operator+(const POINT &t) const { return POINT(x + t.x, y + t.y); } POINT operator-(const P...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); int i, j, n, m, k, l, r; cin >> n >> m; int a[n][m]; pair<int, int> start_end[n][m]; for (i = 0; i < n; i += 1) for (j = 0; j < m; j += 1) { cin >> a[i][j]; start_end[i][j].first = i; ...
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &x) { x = 0; char ch = getchar(); long long fh = 1; while (ch < 0 || ch > 9 ) { if (ch == - ) fh = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) x = x * 10 + ch - 0 , ch = getchar(); ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m, h; cin >> n >> m >> h; vector<int> ms(m), ns(n); vector<vector<int> > ok(n, vector<int>(m)); for (int i = 0; i < m; i++) { cin >> ms[i]; } for...
#include <bits/stdc++.h> using namespace std; int r, g, j, f[200001], sc, kq, mod = round(1e9) + 7; long long i, h; int main() { cin >> r >> g; f[0] = 1; for (i = 1; i * (i + 1) / 2 <= r + g; i++) { for (j = r; j >= 0; j--) { if (j >= i) f[j] = (f[j] + f[j - i]) % mod; } } ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 7; vector<pair<int, int> > s; int co[maxn], deg[maxn]; int main() { int n; cin >> n; for (int i = 0; i < n - 1; i++) { pair<int, int> q; cin >> q.first >> q.second; s.push_back(q); } for (int i = 1; i <=...
#include <bits/stdc++.h> using namespace std; void solve() { long long n, k, kol = 0; cin >> n >> k; string s; cin >> s; vector<long long> a(n); for (long long i = 0; i < n; i++) { a[i] = s[i] - 0 ; } for (long long i = 0; i < n - 1 && k; i++) { if (a[i] == 4 && a[i + 1]...
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; int n, l; long long a[300000][3]; long long b[300000][3]; long long t[300000][2]; vector<int> c[3000000]; vector<pair<long long, long long> > g; long long p[3000000]; long long dab[3000000][2]; void sayno() { printf(...
#include <bits/stdc++.h> using namespace std; vector<vector<long long> > matmul(vector<vector<long long> > &a, vector<vector<long long> > &b) { int i, j, k, n = a.size(); vector<vector<long long> > ans(n, vector<long long>(n)); for (i = 0; i < n; i++) for (j = 0...
#include <bits/stdc++.h> using namespace std; int n, a[110], b[110], sum = 0; pair<int, int> dp[110][11000], q = {-1, -1}; pair<int, int> Rec(int i, int W) { if (i == n) { if (W >= sum) return {0, 0}; else return {1e9, 1e9}; } if (dp[i][W] != q) return dp[i][W]; pair<...
#include <bits/stdc++.h> using namespace std; char s[200005]; int n; int mem[200005][27]; int dirr[200005][27]; bool vis[200005][27]; char other(char c, char d) { if ( a != c && a != d) return a ; if ( b != c && b != d) return b ; return c ; } int solve(int ind, int lst) { if ...
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; const int N = 3020; const int D = 1001; int c[N][N], x[N], y[N], b[N], v[N][N], f[N][N], w[N]; int dis(int i, int j) { return max(abs(x[i] - x[j]), abs(y[i] - y[j])); } int C(int x, int y) { return x >= y ? c[x][y] : 0; } int main...
#include <bits/stdc++.h> using namespace std; int n, m, t1, t2; vector<int> q1, q2; vector<vector<int> > Visted; int des(int point1, int point2, int point3, int point4) { return abs(point1 - point3) + abs(point2 - point4); } int main() { cin >> n >> m >> t1; Visted.resize(n + 10, vector<int>(m...
#include <bits/stdc++.h> using namespace std; template <class TH> void _dbg(const char *sdbg, TH h) { cerr << sdbg << = << h << endl; } template <class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) { while (*sdbg != , ) cerr << *sdbg++; cerr << = << h << , ; _dbg(sdbg + 1...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n - 1; i++) cout << (a[i] + a[i + 1]) << ; cout << a[n - 1]; }
#include <bits/stdc++.h> using namespace std; int j, i, a, b, c, k, d, e, f[1005], n, mi, ma; int main() { cin >> n; for (i = 0; i < n; i++) { cin >> f[i]; ma = max(f[i], ma); } for (i = 0; i < n - 1; i++) for (j = i + 1; j < n; j++) { c = 0; for (k = i; k <= j; k...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( avx,avx2,fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) using namespace std; long long MOD = 1e9 + 7; long long k; vector<long long> v, w, num; vector<pair<long long, pair<long long, long long> > > zp; vect...
#include <bits/stdc++.h> using namespace std; long long read() { long long w = 0; char c = getchar(); while (c < 0 || c > 9 ) c = getchar(); while (c >= 0 && c <= 9 ) w = w * 10 + c - 48, c = getchar(); return w; } long long n, s[100005], e[100005]; bool f[100005][2]; bool check(lo...
#include <bits/stdc++.h> using namespace std; const int N = 16, Inf = 1e9, lastS = (1 << N) - 1; static int n, sqrn, R, B, ans, lasts; struct TCard { bool c; int r, b; } card[N]; static int f[lastS][N * N + 1][2], cardr[lastS], cardb[lastS]; inline int GetF(int s, int rem, bool c) { rem = min(...
#include <bits/stdc++.h> using namespace std; ifstream file( input.txt ); using namespace std; void maker(int x); int main() { int y; cin >> y; maker(y + 1); } void maker(int x) { int a, b, c, d; a = (x / 1000) % 10; b = (x / 100) % 10; c = (x / 10) % 10; d = (x / 1) % 10; ...
#include <bits/stdc++.h> using namespace std; template <typename... Args> void logger(string vars, Args&&... values) {} template <typename T> inline void maxa(T& a, T b) { a = max(a, b); } template <typename T> inline void mina(T& a, T b) { a = min(a, b); } mt19937 rng(chrono::steady_clock::...
#include <bits/stdc++.h> using namespace std; const int maxn = 2000 + 100; map<pair<long long, long long>, int> rat; int n; pair<long long, long long> px[maxn], py[maxn]; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } int main() { cin >> n; for (int i = 1, a, b, c; ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 25; int dp[MAXN][MAXN][MAXN]; int n, t; int main() { scanf( %d%d , &n, &t); t = 2 * t; dp[1][0][1] = dp[1][0][2] = dp[1][0][3] = 1; for (int i = 1; i < n; ++i) for (int j = 0; j <= t; ++j) for (int k = 1; k <= 4; ++k)...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; multiset<long long int> s; map<string, int> mp; while (t--) { char ch; long long int x; cin >> ch >> x; string str(18, 0 ); string t...
#include <bits/stdc++.h> #pragma warning(disable : 4996) #pragma comment(linker, /STACK:666000000 ) using namespace std; const int INF = (1 << 30) - 1; const long double EPS = 1e-9; const long double PI = fabs(atan2(0.0, -1.0)); int n; void load() { cin >> n; } const int SZ = 1010; int sv[SZ]; in...
#include <bits/stdc++.h> using namespace std; const int N = 1e5; map<int, int> dic; int n, a[N + 10], ma[N + 10], ma2[N + 10]; int main() { ios::sync_with_stdio(0), cin.tie(0); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; ma[1] = a[1]; ma2[1] = -1; for (int i = 2; i <= n; i++) {...
#include <bits/stdc++.h> using namespace std; long long a[1000005] = {0}; long long b[1000005] = {0}; long long c[1000005] = {0}; long long d[1000005] = {0}; long long s; long long i, j = 0, l; long long count1 = 0; long long count2 = 0; long long count3 = 0; long long count4 = 0; long long ans ...
#include <bits/stdc++.h> using namespace std; int a[35], b[35], diff[35]; int main() { std::ios::sync_with_stdio(false); int t; t = 1; while (t--) { long long x, x1, val, val1, i, j, res = 0; cout << ? 0 0 << endl; cin >> x; x1 = x; if (x == 0) { for (i = 0;...
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 7; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int n, k; cin >> n >> k; long long int ans = 1; while (k % 2 == 0) { k = k / 2; ans++; } cout << an...
#include <bits/stdc++.h> using namespace std; const int N = 2e4 + 10, mod = 1e9 + 7, M = 510; const double PI = 3.1415926535; long long res[40], p[40], ei[40], sum[N], cnt; double pre[N]; int path[100]; void dfs(int u, int s, long long va) { if (u == -1) { sum[s] = ((long long)sum[s] + va) % mod...
#include <bits/stdc++.h> using namespace std; int N, good; bool prime[100010]; vector<int> fact, num, lis; int main() { memset(prime, true, sizeof(prime)); for (int i = 2; i * i <= 100000; i++) if (prime[i]) for (int j = 2; i * j <= 100000; j++) prime[i * j] = false; for (int i = 2; ...
#include <bits/stdc++.h> using namespace std; const int N = 2300; int dp[N], a[N], res = 0, n; void dfs(int u, int d) { if (d == n) { dp[u] = 0; return; } int l = u * 2, r = l + 1; dfs(l, d + 1); dfs(r, d + 1); int x = dp[l] + a[l], y = dp[r] + a[r]; if (x < y) swap(x, y)...
#include <bits/stdc++.h> using namespace std; long long n, root, val, rem; int main() { cin >> n; root = floor((sqrt(1.0 + 8.0 * n) - 1.0) / 2.0); val = root * (root + 1) / 2; if (n == val) --root; val = root * (root + 1) / 2; rem = n - val; cout << rem << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 2; const long long M = 1e6 + 2; const long long mod = 998244353; long long ar[N], fact[M], inv[M], cnt[N]; long long binpow(long long x, long long y) { long long tich = 1; while (y) { if (y & 1) { tich *= x; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<pair<int, int>> v; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; v.push_back(make_pair(a, b)); } int x1 = v[0].first; int y1 = v[0].second; vector<int> p1, p2; fo...
#include <bits/stdc++.h> using namespace std; template <class T> inline bool chmax(T &a, T b) { return a < b ? (a = b, 1) : 0; } template <class T> inline bool chmin(T &a, T b) { return a > b ? (a = b, 1) : 0; } int main() { int n, m; cin >> n >> m; map<int, vector<int>> obs; int...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { long long n, k; cin >> n >> k; if (n > k) cout << k << endl; else { int ne = (k - 1) / (n - 1); cout << k + ne <...
#include <bits/stdc++.h> int mat[110][110]; int main() { int n, k, i, j; scanf( %d %d , &n, &k); if (n * n < k) { printf( -1 n ); return 0; } for (i = 0; i < n; i++) { for (j = i; j < n; j++) { if (i == j) { if (k > 0) { k--; mat[i][j] ...
#include <bits/stdc++.h> int n, k; bool visited[101][101][1010]; double ar[101], dp[101][101][1010]; double F(int i, int j, int k) { if (i > j) return 1.0 - F(j, i, k); if (k == 0) return 1.0; if (visited[i][j][k]) return dp[i][j][k]; int a, b, c, d, l; double x, y, p = 1.0 / ((n * (n + 1)) ...
#include <bits/stdc++.h> using namespace std; template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const double EPS = 1e-9; const double PI = acos(-1.); const long long LL_INF = 1e17 + 16; const int INF = 1e9 + 10...
#include <bits/stdc++.h> using namespace std; void dfs(set<int> &temp, list<int> adj[], vector<bool> &v, int s, int &t1, int &t2, vector<int> b, vector<int> w) { v[s] = true; list<int>::iterator it; for (it = adj[s].begin(); it != adj[s].end(); it++) { if (!v[*it]) { temp.insert...
#include <bits/stdc++.h> using namespace std; long long n, m, ans, x, i, j, s; double a[100], b[100]; map<double, pair<long long, long long> > mp; map<double, pair<long long, long long> >::iterator it, it2; long long num(long long x) { s = 0; while (x) { s++; x -= x & -x; } retur...
#include <bits/stdc++.h> int main() { long long n, k; scanf( %I64d , &n); while (n % 3 == 0) n /= 3; printf( %I64d , 1 + n / 3); getchar(); getchar(); }
#include <bits/stdc++.h> using namespace std; constexpr long long INF = numeric_limits<long long>::max() / 4; constexpr long long n_max = 2e5 + 10; template <typename A, typename B> string to_string(pair<A, B> p); string to_string(const string &s) { return + s + ; } string to_string(const char c) {...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int test = 1; cin >> test; while (test--) { long long int n, m; cin >> n >> m; long long int sum1 = 0, sum2 = 0; long long int a[n], b[n], mina[n], mi...
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; bool compare(int a, int b) { return a > b; } int main() { int t, p, f, cnts, cntw, s, w; scanf( %d , &t); while (t--) { scanf( %d%d , &p, &f); scanf( %d%d , &cnts, &cntw); scanf( %d%d , &s, &w); if ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e3 + 10; long long n, k; int main() { scanf( %I64d%I64d , &n, &k); long long x; x = sqrt(9 + 8 * (n + k)) - 3; x /= 2; printf( %I64d n , n - x); return 0; }
#include <bits/stdc++.h> using namespace std; const long long MOD = 998244353; const int N = 3e3; long long dmod(long long x) { return x % MOD; } int n, k; int h[N + 5]; long long memo[N + 5][2 * N + 5]; long long dp(int idx, int gap) { if (idx > n) { if (gap > 0) return 1; return 0; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, x, m = 0, sum = 0; cin >> n >> x; int *arr = new int[n]; for (long long i = 0; i < n; i++) cin >> arr[i], sum += arr[i]; if (sum > 0) while (sum > 0) { sum -= x; m++; } else while (sum < 0) { ...
#include <bits/stdc++.h> using namespace std; int brute(int s, int x) { int ans = 0; for (int i = 1; i <= s; ++i) for (int j = 1; j <= s; ++j) if (i + j == s && (i ^ j) == x) ++ans; return ans; } long long ways0(long long s, long long x) { if (s == x) return 2; return 0; } ...
#include <bits/stdc++.h> using namespace std; template <class T> inline void dmin(T& x, T y) { y < x ? x = y : 0; } template <class T> inline void dmax(T& x, T y) { y > x ? x = y : 0; } template <class T> inline void dmin(T& x, vector<T> y) { for (auto t : y) t < x ? x = t : 0; } templ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } sort(arr, arr + n); bool f = true; for (int j = 1; j < n; j++) { int diff ...
#include <bits/stdc++.h> using namespace std; int a, b, k, t, suan, d[1100002], f[1110000]; int main() { cin >> a >> b >> k >> t; int shu = k * 2 * t; d[shu] = 1; int y = d[0]; for (int i = 1; i <= t * 2; i++) { f[0] = y; for (int j = 1; j <= shu * 2 + k; j++) { f[j] = (f[j...
#include <bits/stdc++.h> using namespace std; long long int modulo = 1000000007; const int limite = 1000001; long long int elev[limite]; int ocupado[limite]; int main() { ios_base::sync_with_stdio(false); int n, m, k; cin >> n >> m >> k; elev[0] = 1; for (int i = 1; i < limite; i++) elev...
#include <bits/stdc++.h> using namespace std; bool v[6]; int a[100009][6], maxx = -1, t; long long m = 1e9 + 7; struct pi { long long ah[60][60]; }; pi multi(pi x, pi y) { pi z; for (int i = 1; i <= t; i++) { for (int j = 1; j <= t; j++) { z.ah[i][j] = 0; for (int k = 1; ...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, n, i, j, money; cin >> a >> b >> c; cin >> n; int m[n]; money = 0; for (i = 0; i < n; i++) { cin >> m[i]; if (m[i] > b && m[i] < c) money = money + 1; } if (a > b && a < c) cout << money; el...
#include <bits/stdc++.h> using namespace std; template <typename T> void display(T a[], int size) { for (int i = 0; i < size; i++) { cout << a[i] << ; } cout << endl; } void display(vector<pair<int, int> > a) { for (int i = 0; i < a.size(); i++) { cout << ( << a[i].first << ,...
#include <bits/stdc++.h> using namespace std; int N, dp[100005][3], MOD = 1000000007; char s[2][100005]; long long ans = 1; int main() { scanf( %d%s%s , &N, s[0], s[1]); for (int i = 0; i < N; ++i) { if (s[0][i] == ? ) ans = (((ans * 10) % (MOD) + (MOD)) % (MOD)); if (s[1][i] == ? ) ans ...
#include <bits/stdc++.h> using namespace std; int main() { long long n, c = 0, d = 0, k; string str; cin >> n >> str; for (int i = 0; i < n; i++) { if (str[i] == - ) c++; } if (c == n) { cout << 0 << endl; return 0; } else if (str[0] == - ) { for (int i = 0; i <...
#include <bits/stdc++.h> using namespace std; int M; const int MAX = 100001; vector<int> _size, marked, _pow, _ipow; vector<pair<int, int> > adjList[MAX + 1]; int getSize(int u, int p = -1) { _size[u] = 1; for (auto [v, w] : adjList[u]) if (v != p && !marked[v]) _size[u] += getSize(v, u); ...
#include <bits/stdc++.h> using namespace std; const int N = 2e6 + 100, M = 1e6 + 100; int n, up[N], down[M], nei[M][2]; int lim; bool mark[M], bad[M]; vector<int> vec; int f(int a) { return lower_bound(vec.begin(), vec.end(), a) - vec.begin(); } bool dfs(int v) { mark[v] = true; for (int i = 0; ...
#include <bits/stdc++.h> using namespace std; int val[200007], add[200007]; int main() { int n, t, a, x, k, l = 1; long long sum = 0; scanf( %d , &n); for (int i = 0; i < n; ++i) { scanf( %d , &t); if (t == 1) { scanf( %d%d , &a, &x); add[a] += x; sum += a * x; ...
#include <bits/stdc++.h> using namespace std; constexpr int N = 2e5 + 10; long long n, w, k, happy[N], nice, t[N], mytime, ans; bool in[N]; pair<int, int> lowest; set<pair<int, int>> st; queue<int> q; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> w >...
#include <bits/stdc++.h> using namespace std; inline void speedUp() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } long long int t, n, m, p[100005], q[100005], Podd, Peven, Qodd, Qeven, tot; int main() { speedUp(); int t, n; cin >> t; while (t--) { tot =...
#include <bits/stdc++.h> using namespace std; int main(void) { int n; scanf( %d , &n); int v[n]; for (int i = 0; i < n; i++) scanf( %d , v + i); if (n > 2) { for (int i = 0; i + 3 <= n; i++) { int a = v[i], b = v[i + 1], c = v[i + 2]; int ans1 = -1, ans2 = -1; set<i...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-2; struct cplx { double x, y; cplx(double x1 = 0, double x2 = 0) { x = x1, y = x2; } } g[2000001], f[2000001]; cplx operator+(cplx a, cplx b) { return cplx(a.x + b.x, a.y + b.y); } cplx operator-(cplx a, cplx b) { return cplx(a.x - ...
#include <bits/stdc++.h> struct edge { int to, nxt; } e[100005], e2[100005]; int h[100005], n, cnt, hei[100005], gson[100005], node[100005], N, fa[100005]; void ins(int x, int y) { e[++cnt].nxt = h[x]; e[cnt].to = y; h[x] = cnt; } void dfs1(int x) { hei[x] = 1; for (int i = h[x]; i; ...