func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int main() { int pkt; int start = 0; int lr = 0; cin >> pkt; if (pkt < 0) pkt = pkt / -1; for (int a = 1; start != pkt; a++) { start = start + a; lr++; if (start > pkt) { if ((start - pkt) % 2 == 1) ; e...
#include <bits/stdc++.h> using namespace std; const double h = 1e-6; const int MAX_ = 200005; inline long long int mul(long long int a, long long int b) { return (a * 1ll * b) % 1000000007; } inline long long int sub(long long int a, long long int b) { long long int c = a - b; if (c < 0) c += 10...
#include <bits/stdc++.h> char s[100 + 5], ans[100 + 5][250 + 5]; int main() { int n, i, j, p, l, r; scanf( %d%s , &n, s); for (i = l = r = 0; i<n; ++i, r = l> r ? l : r) l += s[i] == [ ? 2 : -2; for (i = p = 0; i < n; ++i, ++p) { ans[l][p] = ans[r][p] = + ; for (j = l + 1; j < r; ++j)...
#include <bits/stdc++.h> using namespace std; long n, m, dx, dy, qx, qy, ps[1 << 20]; long t, ans[1 << 20]; long a, b; long bst, bp; int main() { ios_base::sync_with_stdio(0); cin >> n >> m >> dx >> dy; qx = qy = 0; for (int i = 0; i < n; i++) { ps[qx] = qy; qy += dy; qx +=...
#include <bits/stdc++.h> using namespace std; long long p = 1000000007ll; int main(void) { long long n; cin >> n; vector<pair<long long, long long> > loops; long long tmp = 0; for (long long i = (0); i < (n); ++i) { string com; cin >> com; if (com == for ) { long lon...
#include <bits/stdc++.h> using namespace std; const long long lar = 1e16; const long long nlar = -1e16; const long long INF = LLONG_MAX; const long long NINF = LLONG_MIN; const long long mod = 998244353; const long long N = 1e6 + 100; struct hash_pair { template <class T1, class T2> size_t opera...
#include <bits/stdc++.h> using namespace std; const int nmax = 5e5 + 42; struct info { int u, v, cost; }; info inp[nmax]; pair<int, int> my[nmax]; int n, k, m; int parent[nmax]; int root(int node) { if (parent[node] == node) return node; parent[node] = root(parent[node]); return parent...
#include <bits/stdc++.h> using namespace std; using ld = long double; using ll = long long; using ull = unsigned long long; const ll mod = 1004535809, mod_g = 3; const int N = int(1e5 + 10); template <typename T> inline T read() { T x = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > ...
#include <bits/stdc++.h> using namespace std; const long long int MOD = (long long int)1e9 + 7; long long int powmod(long long int a, long long int b) { long long int res = 1; while (b > 0) { if (b & 1) res = (res * a) % MOD; a = (a * a) % MOD; b = b >> 1; } return res % MOD; }...
#include <bits/stdc++.h> using namespace std; const int MAXN = 10000; const int MAXK = 20; int V[MAXK + 3][MAXN + 3], Ans[MAXK + 3][MAXN + 3]; int main() { V[0][1] = 0; for (int j = 2; j <= MAXN; j++) { V[0][j] = 1; } for (int i = 1; i <= MAXK; i++) { int k = 1; for (int j = ...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; void solve() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); for (auto i : a) { cout << i << ; } } int main() { ios_base::sync_with_stdio(false); ...
#include <bits/stdc++.h> using namespace std; const long long int maxN = 1e5 + 10; long long int n, i, a[maxN], mx, cnt, nxt; stack<pair<long long int, long long int> > st; int main() { cin >> n; for (long long int i = 0; i < n; i++) cin >> a[i]; for (long long int i = n - 1; i >= 0; i--) { ...
#include <bits/stdc++.h> using namespace std; int n, m, a, b, c, d, x, y, p, q, t, ans[400009], res, mi, T, lca[22][400009], sub[400009]; vector<int> v[400009]; int ma[2]; void dfs(int id, int par) { lca[1][id] = par; lca[0][id] = id; for (int i = 0; i < v[id].size(); i++) { int u = v[...
#include <bits/stdc++.h> template <class T1, class T2> inline bool cmin(T1 &a, const T2 &b) { return b < a ? (a = b, true) : false; } template <class T1, class T2> inline bool cmax(T1 &a, const T2 &b) { return a < b ? (a = b, true) : false; } template <class Type> Type read() { Type a; b...
#include <bits/stdc++.h> using namespace std; int N; pair<pair<int, int>, int> arr[2050]; int vis[2050]; char s[2050]; double angle(pair<int, int> x, pair<int, int> y, pair<int, int> z) { pair<int, int> xy = {y.first - x.first, y.second - x.second}; pair<int, int> xz = {y.first - z.first, y.second -...
#include <bits/stdc++.h> using namespace std; template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << { << p.first << , << p.second << } ; return os; } const int N = 3e5 + 5; const int oo = 1e9 + 7; vector<pair<int, pair<int, int> > > g[N]; int f[N]; ...
#include <bits/stdc++.h> using namespace std; int n; string queue_[6] = { , Sheldon , Leonard , Penny , Rajesh , Howard }; int main() { cin >> n; double count = 1; bool used = false; while (count * 5 < n) { n -= count * 5; count *= 2; used = true; } int x = ceil(n...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 7; const int logn = 19; vector<int> adj[maxn]; int idcnt, l[maxn], r[maxn], dep[maxn], anc[maxn][logn]; void dfs1(int u, int up) { l[u] = ++idcnt; dep[u] = dep[up] + 1; anc[u][0] = up; for (int i = 1; i < logn; i++) { ...
#include <bits/stdc++.h> using namespace std; long long k, res, a[1111], n; set<long long> s; int main() { cin >> n >> k; for (long long i = 1; i <= sqrt(n); i++) { if (n % i == 0) s.insert(i), s.insert(n / i); } for (long long i : s) { res++; if (res == k) { cout << i;...
#include <bits/stdc++.h> using namespace std; template <class c> struct rge { c b, e; }; template <class c> rge<c> range(c i, c j) { return rge<c>{i, j}; } template <class c> auto dud(c* x) -> decltype(cerr << *x, 0); template <class c> char dud(...); struct debug { template <class c...
#include <bits/stdc++.h> using namespace std; long long N = 0, M, K; long long MOD = 998244353; string S, S1; struct st { long long x, i; }; bool operator<(const st& a, const st& b) { if (a.x == b.x) return a.i < b.i; return a.x < b.x; } long long gcd(long long a, long long b) { while ...
#include <bits/stdc++.h> using namespace std; const long long M = 1e9 + 7; long long fastpo(long long a, long long x) { if (x == 0) return 1ll; if (x == 1) return a; long long y = fastpo(a, x / 2); if (x % 2 == 0) { return y * y; } return y * y * a; } long long inv(long long a, l...
#include <bits/stdc++.h> using namespace std; void test() { int t; cin >> t; while (t--) { int i = 0; } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; int i = 0; int n; cin >> n; map<int, int> m; for (int i = 0; i < n; i++) {...
#include <bits/stdc++.h> #define rep(i, a, b) for (int i = a; i <= b; i++) #define per(i, a, b) for (int i = a; i >= b; i--) using namespace std; typedef unsigned long long ull; typedef pair <int, int> pii; typedef long long ll; template <typename T> inline void read(T &f) { f = 0; T fu = 1;...
#include <bits/stdc++.h> using namespace std; long long int M, tp, xx, lll, cc, ndl = 0, N, dl, nf, nef, T; struct bl { long long int type; long long int l, c, x; }; bl t; vector<bl> B; vector<long long int> C; map<long long int, long long int> MP; ifstream in( input.txt ); long long int fin...
#include <bits/stdc++.h> using namespace std; const int M = 102, T = 1000 * 1000 * 1000 + 7; int a[2600][M]; bool mrk[2600][M]; string s; int ff(long long sum, int n) { if (sum < 0) return 0; if (mrk[sum][n]) return a[sum][n]; if (sum > 25 && n == 1) return 0; if (sum <= 25 && n == 1) return...
#include <bits/stdc++.h> using namespace std; const int maxv = 10001; map<string, int> tidx; map<int, int> fp[maxv]; struct Edge { int to, next; } edge[maxv * 2]; int m, idx, head[maxv], ednum, deg[maxv]; char tmp[22]; bool mp[maxv][maxv]; void addedge(int u, int v) { edge[ednum] = Edge{v, h...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d, e, f, k, m; int n[101][2]; cin >> m; for (int i = 0; i < m; i++) { cin >> a >> b >> c >> d >> k; if (a % c == 0) e = a / c; else e = a / c + 1; if (b % d == 0) f = b / d; ...
#include <bits/stdc++.h> using namespace std; long long n, x, y; string s; int main() { cin.tie(0); ios_base::sync_with_stdio(0); cin >> n >> x >> y >> s; long long zeros = 0; int last = -1; for (auto c : s) { int b = (c - 0 ); if (b != last && !b) zeros++; last = b; ...
#include <bits/stdc++.h> using namespace std; template <class T> T sq(T x) { return x * x; } const long long inf = 2147383647; const double pi = 2 * acos(0.0); const double eps = 1e-9; const long long maxint = 2147483647; const long long minint = -2147483648; int n, m; long long arr[100010], b...
#include <bits/stdc++.h> using namespace std; const int N = 5000 + 100; const int M = 30; int n; string s; string t; int mat[M][M][N]; int ones[N]; int ans; long double javab; set<char> g; bool mark[30]; int chand[30]; bool oomade[30]; int main() { cin >> s; n = s.size(); for (...
#include <bits/stdc++.h> using namespace std; int main() { int months[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int n, m; cin >> n >> m; vector<int> ans; string s; int idx = 0; while (getline(cin, s)) { int month = (s[5] - 0 ) * 10 + (s[6] - 0 ); int day = (s[...
#include <bits/stdc++.h> using namespace std; int fir[5000]; int sec[5000]; int init(int x, int y) { printf( ? %d %d n , x, y); fflush(stdout); scanf( %d , &x); return x; } void print(int sch, const vector<int> &ans) { printf( ! n ); fflush(stdout); printf( %d n , sch); fflus...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long n, m, ans = 999999999999999999, mn = 123456789000LL; cin >> n >> m; long long x = n; vector<pair<long long, long long> > v; long long cnt = 0; for (long long i = 2; i <= sqr...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; int min1 = a; int min2 = b / 2; int min3 = c / 4; int res = min(min(min1, min2), min3); cout << res * 7; return 0; }
#include <bits/stdc++.h> using namespace std; void solve() { int n,i,j=2,x,m,d,k; cin >> n; if(n%2==1) {cout << NO << endl;return;} while(j<1000000009 && j<=n) { if(n==j) { // cout << loop << endl; cout << YES << end...
#include <bits/stdc++.h> using namespace std; long long n, k; vector<long long> v; long long dp[1001][2001][4]; long long rec(long long i, long long mask, long long comp) { if (i == n && comp == k) return 1; else if (i == n) return 0; else if (comp > k) return 0; if (dp[i][co...
#include <bits/stdc++.h> using namespace std; long long g, x, y, z; int n, m; int nn, mm; deque<long long> q; long long a[3010][3010]; long long b[3010][3010]; long long c[3010][3010]; int main() { scanf( %d%d%d%d , &nn, &mm, &n, &m); scanf( %lld%lld%lld%lld , &g, &x, &y, &z); for (int i =...
#include <bits/stdc++.h> using namespace std; long long _pow(long long a, long long b, long long m) { if (b == 0) return 1; long long t = _pow(a, b / 2, m); t = (t * t) % m; if (b & 1) return (t * a) % m; else return t; } int main(int argc, char *argv[]) { int n; cin >> n...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; const int mod = 1e9 + 7; const int N = 1e5 + 10; inline int add(int x, int y) { x += y; if (x >= mod) x -= mod; return x; } inline int mul(int x, int y) { x = (1LL * x * y) % mod; return x; } int main() { ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; vector<pair<int, int>> a; cin >> n; for (int i = 0; i < n; i++) { int x; cin >> x; a.push_back({x, i}); } sort(a.begin(), a.end(), greater<pair<int, int>>());...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC target( sse4 ) using namespace std; int q; unsigned int a[200002]; unsigned int b[200002]; unsigned int w; int main() { scanf( %d , &q); for (int i = 0; i < q; ++i) { int t, l, r, k; scanf( %d%d%d , &t, &l, &r); --...
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0; char ch = getchar(); while (!isdigit(ch)) ch = getchar(); while (isdigit(ch)) x = x * 10 + ch - 0 , ch = getchar(); return x; } struct Question { int x, l, r, dat; inline Question(int tmp1 = 0, int tmp2 = 0...
#include <bits/stdc++.h> using namespace std; bool isgood(const vector<vector<char> > &graph, const vector<char> &choice) { int n = (int)graph.size() / 2; assert((int)graph[0].size() == 2 * n); assert((int)choice.size() == n); for (int i = 0; i < n; i++) { bool ok = false; int lbound = 2...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, s, a, b, c, d; cin >> n >> s; d = s; for (int i = 0; i < n; i++) { cin >> a >> b; c = a + b; d = max(c, d); } cout << d; }
#include <bits/stdc++.h> using namespace std; int N, K; long long Time; int Free; multiset<long long> Working; int main() { scanf( %d%d , &N, &K); Free = K; Time = 0; long long S, M; for (int i = 0; i < N; ++i) { scanf( %I64d%I64d , &S, &M); S = max(S, Time); if (Free >...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int N = 2e5 + 1; vector<long long int> a[N]; vector<long long int> order, pos(N); bool topsort(long long int n) { order.clear(); queue<long long int> q; vector<long long int> indeg(n + 1, 0); for (long long int i = ...
#include <bits/stdc++.h> using namespace std; long double optN(long long m, int k) { long double ret = 1; m *= k; long long nowC = k; for (int i = 1; i <= k; ++i) { if (m < nowC * i) { ret += m / i; return ret; } ret += nowC; m -= nowC * i; if (m / (i + ...
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-9; const int INF = 1 << 28; const long long INFL = 1LL << 62; int toi(string x) { int z; istringstream iss(x); iss >> z; return z; } string str[] = { YES , NO }; int modulo(int m, int n) { return m >= 0 ? m % n : (n - a...
#include <bits/stdc++.h> using namespace std; long long n, b[100005], a[200005]; void solve() { cin >> n; for (long long i = 1; i < n / 2 + 1; i++) cin >> b[i]; a[1] = 0; a[n] = b[1]; for (long long i = 2; i < n / 2 + 1; i++) { a[i] = max(a[i - 1], b[i] - a[n - i + 2]); a[n - i + 1...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, x1, x2, y1, y2, i, sum = 0; cin >> n; for (i = 0; i < n; i++) { cin >> x1 >> y1 >> x2 >> y2; sum += ((x2 - x1) + 1) * ((y2 - y1) + 1); } cout << sum << endl; }
#include <bits/stdc++.h> using namespace std; const int Inf = (int)1e9; const long long InfL = (long long)1e18; const int MaxN = (int)2e5 + 5; vector<int> adj[MaxN], ans; int n, a, deg[MaxN], dead[MaxN]; void dfs2(int x, int p) { dead[x] = true; ans.push_back(x); for (auto u : adj[x]) --deg[u]...
#include <bits/stdc++.h> int mod = 1000000007; const int M = INT_MAX; using namespace std; int powb(int x, int y) { int res = 1; x = x % M; while (y > 0) { if (y % 2) res = (res * x) % M; y /= 2; x = (x * x) % M; } return res; } int gcd(int a, int b) { if (b == 0) r...
#include <bits/stdc++.h> using namespace std; void read(int &val) { int x = 0; int bz = 1; char c; for (c = getchar(); (c < 0 || c > 9 ) && c != - ; c = getchar()) ; if (c == - ) { bz = -1; c = getchar(); } for (; c >= 0 && c <= 9 ; c = getchar()) x = x * 10 + c...
#include <bits/stdc++.h> using namespace std; long long n, m, L, start, endP; vector<vector<long long> > edges; vector<vector<long long> > neighbors; vector<vector<long long> > paths; long long weights[1000][1000] = {0}; long long dijk() { vector<long long> distances(n, LLONG_MAX); distances[start...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int socks[n + 1]; memset(socks, 0, sizeof(socks)); int maxi = -1; int brc = 0; for (int i = 1; i <= 2 * n; i++) { int x; cin >> x; if (socks[x] == 0) { socks[x]++; brc++; }...
#include <bits/stdc++.h> using namespace std; void Freopen() { freopen( title .in , r , stdin); freopen( title .out , w , stdout); } int read() { int g = 0, f = 1; char ch = getchar(); while (ch < 0 || 9 < ch) { if (ch == - )...
#include <bits/stdc++.h> using namespace std; int prime[1000000]; bool status[1000100]; int pos; void sieve() { int i, j; for (i = 0; i < 1000100; i++) { status[i] = false; } int sq = sqrt(1000100); for (i = 4; i <= 1000100; i += 2) { status[i] = true; } for (i = 3; i <...
#include <bits/stdc++.h> using namespace std; template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << ; cerr << endl; } const int MAX_N = 100000; vector<int> primes; bool isPrime[MAX_N]; void MakePrimes() { for (int i = 0; i < (int)(MAX_N); ++i) isPrime[i] = true; ...
#include <bits/stdc++.h> using namespace std; const int M = 1e9 + 7; void solve() { int n, k; cin >> n >> k; string s; cin >> s; vector<pair<int, int>> res; string s2; int n2 = n - 2 * (k - 1); for (int i = 0; i < 2 * (k - 1); ++i) { if (i % 2) { s2.push_back( ) ); ...
#include <bits/stdc++.h> using namespace std; void solve() { long long i, j, k, l, n, m, a, b, u; cin >> n; vector<long long> v(n); map<long long, long long> mp; long long ans = 0LL; priority_queue<pair<long long, long long>> pq; for (i = 0; i < n; i++) { cin >> v[i]; mp[v[i]...
#include <bits/stdc++.h> int main() { int m, n; scanf( %d %d , &n, &m); if (n == 1) { if (m == 2) { printf( 0 n ); printf( 1 1 n ); printf( 1 2 n ); printf( 1 1 n ); return 0; } else { printf( 1 n ); printf( 1 %d 1 1 n , m); for (...
#include<bits/stdc++.h> #define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL) ;cout.tie(NULL) using namespace std; #define ll long long int #define pb push_back #define endn n #define mp make_pair #define ss second #define ff first #define deb(x) cout << #x << << x << endl ...
#include <bits/stdc++.h> using namespace std; long long read() { long long x = 0; char s = getchar(); bool w = 0; while (s < 0 || s > 9 ) { w |= s == - ; s = getchar(); } while (s >= 0 && s <= 9 ) { x = (x << 3) + (x << 1) + (s ^ 48); s = getchar(); } r...
#include <bits/stdc++.h> using namespace std; bool prime[10000007]; void SieveOfEratosthenes() { memset(prime, true, sizeof(prime)); for (long long int p = 2; p * p <= 10000007; p++) { if (prime[p] == true) { for (long long int i = p * p; i <= 10000007; i += p) prime[i] = false; } ...
#include <bits/stdc++.h> using namespace std; inline bool is_palindrome(const string& s) { return std::equal(s.begin(), s.end(), s.rbegin()); } const long long MOD = 1000000007; const long long INF = 1e9 + 5; const double eps = 1e-7; const double PI = acos(-1.0); inline void debug_vi(vector<int> a) ...
#include <bits/stdc++.h> using namespace std; template <class T> void in(T &x) { x = 0; bool f = 0; char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) f = 1; c = getchar(); } while ( 0 <= c && c <= 9 ) { x = (x << 3) + (x << 1) + (c ^ 48); c = getchar(...
#include <bits/stdc++.h> using namespace std; const long long MAX = 100001; long long n, k, l[MAX], inf = 1000000000000; multiset<long long> kek; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k; for (int i = 0; i < n; i++) { cin >> l[i + 1]; } lon...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n], b[1000000] = {0}; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n / 2; i++) { if (a[i] - i - 1 >= 0) b[a[i] - i - 1]++; if (a[n - 1 - i] - i - 1 >= 0) b[a[n - 1 - i] - i...
#include <bits/stdc++.h> using namespace std; long long n, m, a, b; int main() { scanf( %lld %lld %lld %lld , &n, &m, &a, &b); long long int mm = n % m; unsigned long long ans = min((m - mm) * a, mm * b); printf( %llu n , ans); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << setprecision(20); auto solve = [&]() -> string { long long int n, k, a, b; cin >> n >> k >> a >> b; long long int remG = a; long long int remB = b; str...
#include <bits/stdc++.h> using namespace std; int bit[2][100011], head[100011], tail[100011], name[100011], dist[100011], n, z, D; vector<int> adj[100011]; int query(int x, int* bit) { int r = 0; while (x) { r += bit[x]; x -= x & -x; } return r; } void update(int x, int v, ...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, i, j, k, p, t, a = 0, b = 0; cin >> n; vector<long long int> vec; for (i = 0; i < n; i++) { cin >> p; if (p % 2 == 0) a++; else b++; vec.push_back(p); } if (a == 0 || b == 0) {...
#include <bits/stdc++.h> int main() { int n, p, q, p1[150], q1[150], pq[300], i, j, k, l, m; scanf( %d , &n); scanf( %d , &p); for (i = 0; i < p; i++) { scanf( %d , &p1[i]); } scanf( %d , &q); for (j = 0; j < q; j++) { scanf( %d , &q1[j]); } if ((p == 0) && (q == 0)) { ...
#include <bits/stdc++.h> using namespace std; const long double EPS = 1e-9; long double _A[19][100009], _b[19], _c[100009]; struct LPSolver { int m, n; vector<int> B, N; vector<vector<long double> > D; LPSolver(const vector<vector<long double> > &A, const vector<long double> &b, con...
#include <bits/stdc++.h> using namespace std; int n; long long a[1111], b[1111]; int main() { cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; for (int i = 1; i <= n; ++i) cin >> b[i]; long long ans = 0; for (int i = 1; i <= n; ++i) { long long cur1 = 0, cur2 = 0; for (int j =...
#include <bits/stdc++.h> using namespace std; const long long N = 3e5 + 10; const long long M = 3e5 + 1; const long long oo = 1e9; long long n, minn, ans; long long bit[N], deg[N]; pair<long long, long long> nex[N]; vector<long long> vi[N]; void upd(long long pos, long long val) { for (long long i...
#include <bits/stdc++.h> using namespace std; long long n, k, c[3000001], s; set<pair<long long, long long> > d, t; set<pair<long long, long long> >::iterator p; int main() { cin >> n >> k; for (int i = 1; i <= n; i++) cin >> c[i]; for (int i = 1; i <= k; i++) d.insert({c[i], i}); for (int i =...
#include <bits/stdc++.h> using namespace std; long long sqr(long long x) { return x * x; } int n, m, x, y; int main() { cin >> x >> y >> n; long double ans = 1e9, p = 0; for (int i = 0; i < n; ++i) { int x1, y1, v; cin >> x1 >> y1 >> v; p = sqrt(sqr(x1 - x) + sqr(y1 - y)) / v; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 20; long long n, m, x, y, ans, low, dp[maxn][1 << maxn]; bool f[maxn][maxn]; long long lowbit(long long x) { long long ret = 0; while (x) { if (x & 1) return ret; else ret++; x /= 2; } } int main()...
#include <bits/stdc++.h> using namespace std; int q[2005], a[2005], cum[2005]; int cnt = 1, n; set<int> use; set<pair<int, int> > s; set<pair<int, int> >::iterator it; map<int, vector<int> > mp; long long diff(int dif) { return (dif * 1LL * (dif + 1)) / 2; } int main() { scanf( %d , &n); int c...
#include <bits/stdc++.h> using namespace std; const int maxN = 101000 * 8; const int G = 3; const int Mod = 998244353; int n; long long m; int Fc[maxN], Ifc[maxN]; int In[maxN], A[maxN], B[maxN], C[maxN], R[maxN]; int QPow(int x, int cnt); void NTT(int *P, int N, int opt); int main() { Fc[0] =...
#include <bits/stdc++.h> using namespace std; long long mi = 2e9; long long ma = -2 * 1e9; const int N = 1e5 + 5; int main() { std::ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); long long na, nb, ka, kb; cin >> na >> nb >> ka >> kb; long long a[na], b[nb]; for (int i...
#include <bits/stdc++.h> const long long Inf = 1ll << 50; const long long N = 200010; using namespace std; long long cl[2 * N], b, c, d, i, j, k, l, n, ans, a[N], y, kk; int main() { scanf( %I64d%I64d , &n, &k); for (i = n + 1; i > 0; i--) scanf( %I64d , &a[i]); memset(cl, 0, sizeof(cl)); cl[0...
#include <bits/stdc++.h> using namespace std; long long arr[300000]; long long temp[300000]; int main() { int q; cin >> q; while (q--) { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> arr[i]; temp[i] = arr[i]; } int st = 0; int endIdx1 = -1;...
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; long long k = 0, m = 1; while (t > 0) { if (t % 10 == 4) { k = k + m; } else { k = k + 2 * m; } m = m * 2; t = t / 10; } cout << k; }
#include <bits/stdc++.h> using namespace std; int marked[1000006]; int f(int i, int j) { if (j == 1) { return marked[i]; } return f(marked[i], j - 1); } vector<int> v; int main() { int n, a, b; scanf( %d %d %d , &n, &a, &b); int cut = -1; for (int i = 0; i <= n; i++) { ...
#include <bits/stdc++.h> using namespace std; void vin(vector<long long int> &v, long long int t) { for (long long int i = 0; i < t; i++) cin >> v[i]; } void vout(vector<long long int> &v, long long int t) { for (long long int i = 0; i < t; i++) cout << v[i] << ; cout << endl; } void ingraph(...
#include <bits/stdc++.h> using namespace std; struct SCC { int N; vector<bool> used; vector<int> vs; vector<int> cmp; void dfs(int v, const vector<int> G[]) { used[v] = true; for (auto u : G[v]) { if (!used[u]) dfs(u, G); } vs.push_back(v); } void rdfs(int...
#include <bits/stdc++.h> int main() { int n(0); scanf( %d n , &n); std::string number; getline(std::cin, number); if (number.size() <= 3) { std::cout << number << std::endl; } else { int index(0); if (number.size() % 2) { std::cout << number.substr(0, 3); inde...
#include <bits/stdc++.h> using namespace std; struct E { int ad, id, ne; } e[100010 * 4]; int n, m, q, u[100010], v[100010], w[100010], h1[100010], h2[100010], de[100010], fa[100010], f[100010], p0[100010], p1[100010]; bool o[100010]; void add(int* he, int x, int y, int d) { static int t = 0; ...
#include <bits/stdc++.h> #pragma GCC optimize( -O3 , unroll-loops ) using namespace std; template <typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; } template <typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; } const long long MOD = 1e9 ...
#include <bits/stdc++.h> using namespace std; int xd[] = {0, 1, 0, -1}; int yd[] = {1, 0, -1, 0}; int xx[] = {0, 1, 0, -1, 1, -1, 1, -1}; int yy[] = {1, 0, -1, 0, 1, 1, -1, -1}; int kx[] = {-2, -1, -2, -1, 1, 2, 2, 1}; int ky[] = {1, 2, -1, -2, -2, -1, 1, 2}; bool islucky(int x) { int four = 0, seve...
#include <bits/stdc++.h> const long long N = 100100; const long long MAX = 1000000100; using namespace std; long long a[N] = {0}; int main() { long long n; while (scanf( %lld , &n) != EOF) { map<long long, long long> num; for (long long i = 0; i < n; i++) { scanf( %lld , &a[i]); ...
#include <bits/stdc++.h> using namespace std; int m = 0, b = 0; int main() { int n; cin >> n; int Arrpi[n]; for (int j = 0; j < n; ++j) { cin >> Arrpi[j]; } int A[n]; for (int l = 0; l < n; ++l) { m = Arrpi[l] - 1; b = l + 1; A[m] = b; } for (int y = 0; ...
#include <bits/stdc++.h> using namespace std; char getc() { char c = getchar(); while ((c < A || c > Z ) && (c < a || c > z ) && (c < 0 || c > 9 )) c = getchar(); return c; } int gcd(int n, int m) { return m == 0 ? n : gcd(m, n % m); } int read() { int x = 0, f = 1; char c =...
#include <bits/stdc++.h> using namespace std; template <typename T> inline T read() { register T sum = 0; register char cc = getchar(); int sym = 1; while (cc != - && (cc > 9 || cc < 0 )) cc = getchar(); if (cc == - ) sym = -1, cc = getchar(); sum = sum * 10 + cc - 0 ; cc = getc...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, c, q, i; cin >> q; for (i = 1; i <= q; i++) { cin >> n; c = 0; while (1) { if (n % 2 == 0) { n = n / 2; c++; } else if (n % 3 == 0) { n = (2 * n) / 3; c++...
#include <bits/stdc++.h> using namespace std; const int N = 1505; const int mo = 998244353; int n, m, a[N][N]; int fa[N], sz[N], S[N]; int f[N][N], tmp[N]; pair<int, int> e[N * N]; int get(int x) { return x == fa[x] ? x : fa[x] = get(fa[x]); } void merge(int x, int y) { memset(tmp, 0, sizeof(tmp))...
#include <bits/stdc++.h> using namespace std; string to_string(string s) { return + s + ; } string to_string(const char *s) { return to_string((string)s); } string to_string(bool b) { return (b ? true : false ); } template <typename A, typename B> string to_string(pair<A, B> p) { return ( + ...