func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const int N = 50 + 5; int n, dp[N][N][N][N]; char g[N][N]; int dfs(int x, int y, int h, int w) { if (dp[x][y][h][w] != -1) return dp[x][y][h][w]; if (h == 1 && w == 1) return dp[x][y][h][w] = g[x][y] == # ; if (h == 0 || w == 0) return dp[x][y][h][w] ...
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; const int inf = 0x3f3f3f3f; int n, m; int mi[maxn], cnt[maxn]; int main() { cin >> n >> m; memset(mi, 0x3f, sizeof(mi)); for (int i = 1; i <= m; i++) { int x, y; cin >> x >> y; mi[x] = min(mi[x], (y - x + n)...
#include <bits/stdc++.h> using namespace std; template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << ; cout << endl; } template <class T> void chmin(T &t, const T &f) { if (t > f) t = f; } template <class T> void chmax(T &t, const T &f) { if (t < f) t = f; ...
#include <bits/stdc++.h> using namespace std; const int MN = 70010; vector<int> vs[MN]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<string> vs(n); for (int i = 0; i < n; i++) cin >> vs[i]; vector<string> ans(n); for (int len = 1; len < 10; l...
#include <bits/stdc++.h> using namespace std; template <class T> inline void remax(T& A, T B) { if (A < B) A = B; } template <class T> inline void remin(T& A, T B) { if (A > B) A = B; } string ToString(long long num) { string ret; do { ret += ((num % 10) + 0 ); num /= 10; ...
#include <bits/stdc++.h> using namespace std; long long exgcd(long long a, long long b, long long &x, long long &y) { if (b == 0) { x = 1, y = 0; return a; } long long g = exgcd(b, a % b, x, y); long long t; t = x, x = y, y = t - (a / b) * y; return g; } int main() { long...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int N = 1010; int dp[N][N][2]; int bits[N]; int t, k; long long dfs(int len, int pos, int num, bool mark) { int maxx; long long sum; if (!len) { if (num == 1) { return true; } else { return...
#include <bits/stdc++.h> using namespace std; int vis[200005][3], n; long long dp[200005][3], a[200005]; long long dfs(int x, int s) { if (dp[x][s]) return dp[x][s]; if (vis[x][s]) return -1; vis[x][s] = 1; int k; if (s) k = x + a[x]; else k = x - a[x]; if (k <= 0 || k > ...
#include <bits/stdc++.h> using namespace std; double PI = acos(-1.0); long long mod = 998244353; struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >>...
#include <bits/stdc++.h> #define inp_out_work ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define testCase int T; cin>>T; while(T--) #define debug(P) cout<<#P<< <<P<<endl #define endl n using namespace std; typedef long long ll; int main() { testCase { int n; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n % 2 == 0) cout << (n * n) / 2 << endl; else cout << (n / 2) * (n / 2) + (n / 2 + 1) * (n / 2 + 1) << endl; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) if ((i + j) % 2 == 0)...
#include <bits/stdc++.h> using namespace std; const int N = (int)2e6 + 10; vector<int> a[N]; vector<int> pos[N]; string ans; int n; string s[N]; int m; vector<int> cur; int cnt[N]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); memset(cnt, 0, sizeof(cnt)); m = 0; ci...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; while (cin >> a >> b >> c) { long long l = 0, r = 100000000; while (l <= r) { long long t = (l + r) / 2; long long w = b * t; long long d = b * t; bool ok = true; while (d < a * c) { ...
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0; char ch = getchar(); while (ch < 0 || ch > 9 ) ch = getchar(); while (ch >= 0 && ch <= 9 ) x = x * 10 + ch - 0 , ch = getchar(); return x; } vector<pair<int, int> > v[1000000 + 5]; int s[1000000 / 5], num =...
#include <bits/stdc++.h> using namespace std; using LL = long long; const LL MOD = 998244353; string s; LL cal(int x) { if (x < 10 || x > 18) return 0; return 9 - (x - 10); } struct SegmentTree { struct Node { int L, R, l, r; LL v[2][2]; }; vector<Node> N; int p; ve...
#include <bits/stdc++.h> using namespace std; vector<int> av; int main() { int n; scanf( %d , &n); for (int i = max(1, n - 100); i <= n; i++) { int j = i, ans = i; while (j) { ans += j % 10; j /= 10; } if (ans == n) av.push_back(i); } int avs = av.size()...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC optimize( Ofast ) using namespace std; long long int n, res[200005], cnt = 0, ans[200005]; vector<long long int> g[200005]; vector<long long int> v[200005]; map<long long int, long long int> c; queue<long long int> q; void dfs1(long long ...
#include <bits/stdc++.h> using namespace std; const int block_size = 320; const long long mod = 1e9 + 7; const long long inf = 1e9 + 7; const long double eps = 1e-9; const double PI = atan(1) * 4; template <typename T> inline int sign(const T &a) { if (a < 0) return -1; if (a > 0) return 1; ...
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int n; cin >> n; long long int a[n]; long long int sum = 0; for (int i = 0; i < n; i++) { cin >> a[i]; if (!(i & 1)) sum += a[i]; } long...
#include <bits/stdc++.h> using namespace std; const int MAXN = 35000 + 10; const int MAXK = 55; int tree[MAXN << 2], info[MAXN << 2]; int dp[MAXK][MAXN]; int nums[MAXN]; int pre[MAXN], cur[MAXN]; void build(int node, int start, int end, int i) { if (start == end) { tree[node] = dp[i][start - 1...
#include <bits/stdc++.h> using namespace std; typedef struct { int x; int y; long long z; long long o; } H; long long b, g, i, j, k, sz, t, p[200040], w[200040]; int pv[200040]; H e[400005]; int C(H a, H b) { return a.x < b.x; } void BP(void); void S(void); long long dfs(int v); in...
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; if ((a >= 0 && b < 0) || (a < 0 && b >= 0)) { cout << -1 ; return 0; } if (a == 0 && b == 0) { cout << -1 ; return 0; } if (a < 0 && b < 0) { cout << -1 ; return 0; ...
#include <bits/stdc++.h> using namespace std; int main() { int fr[301][301]; int al[301]; int i, j, n; cin >> n; for (i = 1; i <= n; ++i) for (j = 1; j <= n; ++j) cin >> fr[i][j]; for (i = 1; i <= n; ++i) cin >> al[i]; int k, best[301], best_time[301], cur; for (j = 1; j <= n; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int x = 0, xi = INT_MIN, q = 0; vector<int> v; for (int i = 0; i < n; i++) { int y; cin >> y; q = x; v.push_back(y); xi = max(x, v[i]); if (x != q) x = i; } long long ans = 0; ...
#include <bits/stdc++.h> using namespace std; inline int min(int _a, int _b) { return _a < _b ? _a : _b; } inline int max(int _a, int _b) { return _a > _b ? _a : _b; } template <class _T> inline void rd(_T &_a) { int _f = 0, _ch = getchar(); _a = 0; while (_ch < 0 || _ch > 9 ) { if (_ch =...
#include <bits/stdc++.h> using namespace std; int a, b, n, m; int A[100010], B[100010], L[100010]; double dis(int a, int b, int c, int d) { return sqrt( double((a - c + 0.0) * (a - c + 0.0) + (b - d + 0.0) * (b - d + 0.0))); } double getK(int y) { return 1.0 * y * a / (b * 1.0); } int find(dou...
#include <bits/stdc++.h> using namespace std; long long int base(long long int n, long long int k) { string res = ; long long int temp = 0, i; while (n >= k) { res += to_string(n % k); n /= k; } res += to_string(n); reverse(res.begin(), res.end()); for (i = 0; i < res.lengt...
#include <bits/stdc++.h> using namespace std; const int MAXM = 2e5 + 3, MAXN = 2e5 + 3, MAXQ = 2e5 + 3, MAXC = 2e5 + 3, ADD = 1 << 18; int n, m, q; int edge_from[MAXM << 1], edge_to[MAXM << 1], edge_nex[MAXM << 1]; int cntm = 1, head[MAXN]; void link(int from, int to) { edge_from[++cntm] = f...
#include <bits/stdc++.h> using namespace std; int adj[205][205]; int rgraph[205][205]; int n, m; int parent[205]; bool visited[205]; int a[105]; int b[105]; bool bfs(int s, int t) { memset(visited, 0, sizeof(visited)); queue<int> q; q.push(s); visited[s] = true; parent[s] = -1; ...
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long t; t = 1; for (long long test = 1; test <= t; test++) { long long n; cin >> n; vector<long long> a; for (long long i = 0; i <= n - 1; i++) { l...
#include <bits/stdc++.h> using namespace std; const long long N = 200001; std::vector<long long> g[N]; long long s[N]; long long h[N]; long long a[N] = {0}; bool visited[N] = {false}; void dfs1(long long n, long long parent, long long depth) { h[n] = depth; for (long long v : g[n]) { if (v...
#include <bits/stdc++.h> template <typename C> int sz(const C &c) { return c.size(); } using namespace std; int main() { iostream::sync_with_stdio(false); int64_t n; cin >> n; int k; cin >> k; int64_t maxV = 0; int maxI = 1; int64_t maxC = 0; for (int i = 1; i <= k; ++i...
#include <bits/stdc++.h> using namespace std; long long a[10], rest[10]; int n, res = 1e9, pre[10], tmp, size[10], flag = 0; vector<int> ve[10]; map<long long, long long> mp; int count(long long x) { if (mp[x]) return mp[x]; long long tmp = x; long long res = 0; for (long long i = 2; i * i <...
#include <bits/stdc++.h> using namespace std; int n, m, INF = 2e9; vector<vector<int>> value; void shift_column(int j, int k) { vector<int> res(n); for (int i = 0; i < n; i++) res[(i - k + n) % n] = value[i][j]; for (int i = 0; i < n; i++) value[i][j] = res[i]; } void run() { cin >> n >> m; ...
#include <bits/stdc++.h> using namespace std; int n, m, a[300100], b[300100], pos[300100]; vector<pair<int, int> > ans; inline void ws(int xx, int yy) { ans.push_back(make_pair(xx, yy)); } int main() { scanf( %d , &n); for (int i = 1; i <= n; ++i) { scanf( %d , &a[i]); pos[a[i]] = i; }...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC optimize( no-stack-protector ) #pragma GCC optimize( unroll-loops ) #pragma GCC target( sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native ) #pragma GCC optimize( fast-math ) using namespace std; inline void ForSpeed() { ios_base::sync_wit...
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; const int LIM = 100005; #define int long long #define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define mem(a,b) memset(a,b,sizeof(a)) #define all(a) a.begin() , a.end() #define pii pair<int,int> #define vi vector...
#include <bits/stdc++.h> using namespace std; bool debug = 0; int n, m, k; int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; string direc = RDLU ; long long ln, lk, lm; void etp(bool f = 0) { puts(f ? YES : NO ); exit(0); } void addmod(int &x, int y, int mod = 1000000007) { assert(y >=...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10, V = 1e5; inline int read() { register int x = 0, f = 0; register char c = getchar(); while (c < 0 || c > 9 ) f |= c == - , c = getchar(); while (c >= 0 && c <= 9 ) x = (x << 3) + (x << 1) + c - 0 , c = getchar(); ret...
#include <bits/stdc++.h> using namespace std; void init() { freopen( input.txt , r , stdin); } int abs(int x) { if (x < 0) { return -x; } return x; } int main() { int n, m, x1, y1, x2, y2; cin >> n >> m >> x1 >> y1 >> x2 >> y2; n = abs(x1 - x2) + 1; m = abs(y1 - y2) + 1; ...
#include <bits/stdc++.h> using namespace std; int gcd(long long a, int b) { if (a < b) { return gcd(b, a); } if (b == 0) { return a; } return gcd(b, a % b); } class Triplet { public: long long gcd; long long x; long long y; }; Triplet gcdExtendedEuclid(int a, i...
#include <bits/stdc++.h> const long long mod = (long long)1e9 + 7; const int maxn = (int)1e5 + 1; long long inf = 1LL << 60; using namespace std; inline void read(int &n) { int x = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); ...
#include <bits/stdc++.h> using namespace std; int dp[2][300005], x[300005], y[300005]; int n, k; int main() { cin >> n >> k; for (int i = 1; i <= n; i++) cin >> x[i]; for (int i = 1; i <= n; i++) cin >> y[i]; for (int i = 1; i <= n; i++) { if (!(~dp[0][i - 1])) { dp[0][i] = -1; ...
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, /STACK:1024000000,1024000000 ) const double pi = acos(-1.0), eps = 1e-8; const int maxm = 1100000, inf = 0x3f3f3f3f; bool f[maxm]; vector<int> v[maxm]; int top, st[maxm]; int a[maxm]; void dfs(int x, int pre) { f[x] = true; ...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 11111, MAX_M = 222222; class Flow_Algorithm { public: int g[MAX_M], nxt[MAX_M], flow[MAX_M], c[MAX_N], h[MAX_N], nm; int d[MAX_N], q[MAX_N]; int S, T; void addedge(int x, int y, int w) { g[nm] = y; nxt[nm] = c[x]; ...
#include <bits/stdc++.h> using namespace std; constexpr int N = 2e5 + 3; vector<int> c[N]; vector<int> e[N]; int main() { ios_base::sync_with_stdio(false); int n, m, q; cin >> n >> m >> q; for (int it = 0; it < q; ++it) { int r, C; cin >> r >> C; c[r].push_back(C); } ...
#include <bits/stdc++.h> using namespace std; static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL; template <typename T> T mulmod(T a, T b, T m) { long long int q = (long long int)(((long double)a * (long double)b) / (long double)m); long long int r = a * b - ...
#include <bits/stdc++.h> using namespace std; const long long N = 100005; const long long M = 998244353; long long pow1(long long a, long long b) { int res = 1; while (b > 0) { if (b & 1) { res = (res * a) % M; } a = (a * a) % M; b >>= 1; } return res % M; } i...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k, i, j; cin >> n >> k; long long int x = 1; long long int ans = n - 1; for (i = 0; i < k; i++) { vector<long long int> v; long long int m; cin >> m; long long int t = -1; for (j = 0; j < m;...
#include <bits/stdc++.h> using namespace std; int main() { int num, hight, temp, width = 0; cin >> num >> hight; vector<int> v; for (int i = 0; i < num; i++) { cin >> temp; v.push_back(temp); if (v[i] > hight) width += 2; else width++; } cout << width;...
#include <bits/stdc++.h> using namespace std; const double pi = 2 * acos(0); int main() { ios_base::sync_with_stdio(0); cin.tie(0); int q; cin >> q; while (q--) { int n, r; cin >> n >> r; set<int> s; vector<int> v; for (long long i = 0; i < n; i++) { int a...
#include <bits/stdc++.h> using namespace std; const int N = 100005; int n, a[N], b[N], posa[N], posb[N], dif[N], ans, ord[N], t1; multiset<int> rig, lef; int abss(const int i) { return i < 0 ? -i : i; } bool cmp(int i, int j) { return dif[i] < dif[j]; } int main() { scanf( %d , &n); for (int i = 1...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int MAX = 100005; const int MAX1 = 1005; const int MAX2 = 105; const int LEN = 105; const int BASE = 1000000000; const double EPS = 1e-7; const int MOD = 1000000007; long long pow(long long a, long long b) { long lon...
#include <bits/stdc++.h> using namespace std; template <typename T> inline T S(T a) { return a * a; } template <class T> inline string tostring(T a) { ostringstream os( ); os << a; return os.str(); } template <typename T> inline long long tolong(T a) { long long res; istringst...
#include <bits/stdc++.h> const int inf = (1ll << 30) - 1; const int maxn = (int)1e5 + 10; using namespace std; int n; vector<int> g[100100]; int a[100100]; int in[100100]; int out[100100]; int dp[100100]; map<int, int> t[400400]; int timer = 0; void dfs(int v) { in[v] = timer; a[timer] =...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; bool zero = false; int *arr = new int[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } int neg = 0; for (int i = 0; i < n; i++) { if (arr[i] < 0) neg++; if (arr[i] == 0) { ...
#include <bits/stdc++.h> using namespace std; int N, K; namespace solve { const int maxn = 305, Mod = 777777777; long long dp[maxn][maxn][maxn], C[maxn][maxn]; long long DP() { for (int i = 0; i <= N; ++i) C[i][0] = 1; for (int i = 1; i <= N; ++i) for (int j = 1; j <= i; ++j) C[i][j] =...
#include<bits/stdc++.h> #define fo(i, n) for(int i=0; i<n; i++) #define boost ios::sync_with_stdio(false); cin.tie(0) #define ll long long int using namespace std; int main() { boost; int t; cin>>t; while(t--){ int n, max_freq = 0, i; cin>>n; map<int, int> m; f...
#include <bits/stdc++.h> using namespace std; const int N = 500001; int arr[N]; vector<pair<int, int> > v[N]; int ans[N], n, m; int bit[N]; map<int, int> last; void update(int idx, int val) { for (; idx <= n; idx += idx & -idx) { bit[idx] = min(bit[idx], val); } } int query(int idx) { ...
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(false); long long int n, i, t, k, c, s = 0, x, sum = 0, st1 = 0, st2 = 0, curr = 0; cin >> n; vector<pair<long long int, long long int> > v; vector<long long int> p; fo...
#include <bits/stdc++.h> using namespace std; namespace io { const int SI = 1 << 21 | 1; char IB[SI], *IS, *IT, OB[SI], *OS = OB, *OT = OS + SI - 1, c, ch[100]; int f, t; inline void flush() { fwrite(OB, 1, OS - OB, stdout), OS = OB; } inline void pc(char x) { *OS++ = x; if (OS == OT) flush(); }...
#include <bits/stdc++.h> using namespace std; int n, k, m; int nt, kt, mt; int su[100004]; long long sum = 0; double res; int main() { scanf( %d%d%d , &n, &k, &m); nt = n; kt = k; mt = m; for (int i = 0; i < n; i++) { scanf( %d , su + i); sum += su[i]; } res = 1.0 *...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 100; const int MOD = 1e9 + 7; const int oo = 1e9 + 100; const long double EPS = 1e-9; const string DIRS = UDLR ; int n, x, y; char str[MAXN]; int acc[256][MAXN]; int get(char ch, int fr, int to) { if (to < fr) return 0; re...
#include <bits/stdc++.h> using namespace std; int a[200010], b[200010]; bool used[200010]; int main() { int n, k = 0, i, x; scanf( %d , &n); for (i = 1; i <= n; i++) scanf( %d , &a[i]); for (i = 1; i <= n; i++) scanf( %d , &b[i]); int ans = 1 - accumulate(b + 1, b + n + 1, 0) % 2; for (i...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, m, i, cnt = 0, sum = 0, ans = 0, x, j; string s; vector<string> v; cin >> n >> m; int a[m]; for (i = 0; i < n; i++) { cin >> s; v.push_back(s...
#include <bits/stdc++.h> using namespace std; void chekarre(int* arr, int n) { cout << [ ; for (int i = 0; i < n; i++) cout << arr[i] << ; cout << ] << endl; } bool comp(int i, int j) { return (i > j); } int a[2000007]; int main() { int n; long long sum = 0; cin >> n; for (...
#include <bits/stdc++.h> using namespace std; int n, a, b; int ans, nn; char x[100010]; int change(int t) { int rtn = 0, bit = 1; while (t) { rtn += (t % 10) * bit; bit *= ans; t /= 10; } return rtn; } int main() { scanf( %d%d , &a, &b); int aa = a, bb = b; wh...
#include <bits/stdc++.h> using namespace std; const long long OO = 1e8; const double EPS = (1e-7); int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; } const int N = 100; bool adjMatrixBool[N][N]; int adjMatrix[N][N]; vector<int> adjMatrixAll[N][N]; map<pair<int, int>, int>...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const long long INF = 1000 * 1000 * 1000 + 7; const long long LINF = INF * (long long)INF; const int MOD = 1000 * 1000 * 1000 + 7; const int MAX = 10000 + 47; long long F[MAX]; vector<int> R; int main() { ios::sync_with_st...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; const double PI = acos(-1.0); const long long int mod = 1e9 + 7; const int MAXN = 1e6 + 5; void cp() { long long int n, i, k; cin >> n >> k; long long int a[n], sum = 0; for (int i = 0; i < n; i++) cin >> a[i]; sort(a...
#include <bits/stdc++.h> using namespace std; const int INF = INT_MAX; const long long INFL = LLONG_MAX; int dx[] = {1, -1, 0, 0}; int dy[] = {0, 0, 1, -1}; int main() { ios_base::sync_with_stdio(0); cout.precision(15); cout << fixed; cout.tie(0); cin.tie(0); int n, k; cin >> n >...
#include <bits/stdc++.h> using namespace std; long long a[300005]; long long c[300005] = {0}; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int n; cin >> n; int i; for (i = 1; i <= n - 1; i++) cin >> a[i]; long long m = 0; long long r = 0; for ...
#include <bits/stdc++.h> using namespace std; int myrand(int m) { return (rand() * (1 << 15) + rand()) % m; } int main() { srand(time(0)); int n, ind, x; cin >> n >> ind >> x; --ind; vector<int> left(n); vector<bool> vis(n, 0); for (int i = 0; i < n; ++i) left[i] = i; vis[ind] = 1;...
#include <bits/stdc++.h> using namespace std; bool done1[33][2][2], done2[33][2][2], done3[33][2][2]; long long memo1[33][2][2], memo2[33][2][2], memo3[33][2][2]; long long lim; int n; long long dp1(int, int, int); long long dp2(int, int, int); long long dp3(int, int, int); long long dp1(int i, int s1...
#include <bits/stdc++.h> using namespace std; int32_t main() { long long n; cin >> n; map<string, long long> count; for (long long i = 0; i < n; i++) { string s; cin >> s; count[s]++; } string s1 = a , s2 = a ; for (map<string, long long>::iterator it = count.begin();...
#include <bits/stdc++.h> using namespace std; int to(int x, int y) { return (x * 60) + (y); } long long int gcd(long long int a, long long int b) { return b == 0 ? a : gcd(b, a % b); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; int arr[n + ...
#include <bits/stdc++.h> int N; char s[507][507]; int rX[] = {-1, 0, 1, 0}; int rY[] = {0, -1, 0, 1}; int spoj[507][507]; int rozm[1000007]; int akt[1000007]; int terRozm; int wyn; void dfs(int y, int x, int num) { spoj[y][x] = num; terRozm++; for (int i = 0; i < 4; i++) { int nx =...
#include <bits/stdc++.h> using namespace std; int n, m, x, c, a[200001], tin[200001], tout[200001], sz[200001], seg[524288]; string s; bool lazy[524288]; vector<int> G[200001]; void dfs(int i) { tin[i] = ++c; ++sz[i]; for (int j : G[i]) { dfs(j); sz[i] += sz[j]; } tout[i] = c...
#include <bits/stdc++.h> using namespace std; const int INF = 1e8 + 1; vector<vector<int> > adj; vector<bool> visited; int contadorNodos = 0; void DFS(int nodo) { contadorNodos++; for (auto it : adj[nodo]) { DFS(it); } } void letras(string &s) { for (int i = 0; i < s.size(); i++) {...
#include <bits/stdc++.h> using namespace std; const bool online_judge = true; const long long inf = 1LL << 60; long long toInt(string s) { long long res; stringstream ss; ss << s; ss >> res; return res; } string toString(long long n) { stringstream ss; ss << n; return ss.str(...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 100; struct node { int flag, a, b; long long sum; } t[maxn * 8]; int a[maxn], cnt[maxn * 2], js[maxn * 2]; void pushdown(int x, int l, int r) { if (t[x].flag) { int num = t[x].flag; t[2 * x].sum += num * l; t[...
#include <bits/stdc++.h> using namespace std; long long n, a[100001], b[100001]; vector<long long> v[100001]; signed main() { cin >> n; long long i; for (i = 1; i < n + 1; i++) { cin >> a[i]; v[a[i]].push_back(i); } bool ok = 1; long long clr = 1; for (i = 0; i < 100001; ...
#include <bits/stdc++.h> using namespace std; template <class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; } template <class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; } const long long maxn = 1000001, mod = 1e9 + 7; int main() { ios_base::sync_with_st...
#include <bits/stdc++.h> using namespace std; struct Trie { Trie *nx[2]; int cnt; Trie() { nx[0] = nx[1] = nullptr; cnt = 0; } }; Trie *root; void ins(long long x) { Trie *now = root; for (int bit = 45; bit >= 0; --bit) { int p = (x >> bit) & 1LL; if (now->nx[p]...
#include <bits/stdc++.h> using namespace std; int n; int b[5000]; int f[5000]; int main() { scanf( %d , &n); for (int i = 0; i < (int)(n); i++) scanf( %d , b + i); for (int i = 0; i < (int)(n); i++) b[i]--; for (int i = 0; i < n; i++) { int c[5000] = {}; pair<int, int> best = mak...
#include <bits/stdc++.h> using namespace std; using ll = long long; int t; int main() { cin >> t; while (t--) { int n, m; bool nope = false; cin >> n >> m; for (int i = 0; i != n; i++) { for (int j = 0; j != m; j++) { ll a; cin >> a; if ((a >...
#include <bits/stdc++.h> using namespace std; using LL = long long; const int maxn = 3000010; int n, b; int pre[maxn], vis[maxn]; vector<int> prime; struct init { init() { memset(pre, 0, sizeof pre); prime.clear(); for (int i = 2; i < maxn; i++) { if (pre[i] == 0) { ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0), cin.tie(0); string s; cin >> s; sort(s.begin(), s.end()); reverse(s.begin(), s.end()); cout << s[0]; for (long long int(i) = (1); (i) < (s.length()); (i)++) { if (s[i] == s[i - 1]) cout << s...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { if ((i * (i + 1)) / 2 == n) { cout << YES << endl; return 0; } if ((i * (i + 1)) / 2 > n) { cout << NO << endl; return 0; } } ret...
#include <bits/stdc++.h> using namespace std; bool KT(long long k, long long n) { long long take = 0, cur = n; while (cur > 0) { long long temp = min(k, cur); take += temp; cur -= temp; cur -= cur / 10; } if (take * 2 >= n) return true; return false; } int main() { ...
#include <bits/stdc++.h> using namespace std; struct in { int x, y; } a[300000]; int get(int prex, int prey, int x, int y, int k) { int num, ans = 100000000; if (prex <= k) { num = (prex + x + k - 1) / k - 1; if (y == num) ans = prex + x - num * k; else if (y > num && y <= ...
#include <bits/stdc++.h> float a1(float x, float y, float z) { if (x >= 1.0) return z * log(y) + log(log(x)); else if (x < 1.0 && y < 1.0 && z < 1.0) return z * log(y) + log(log(1 / x)); else return 0.0 / 0.0; } float a2(float x, float y, float z) { if (x >= 1.0) return log...
#include <bits/stdc++.h> using namespace std; vector<int> vi; void primefact(int n) { while (n % 2 == 0) { vi.push_back(2); n /= 2; } int i = 3; while (i <= n) { while (n % i == 0) { vi.push_back(i); n /= i; } i += 2; } if (n > 2) vi.push_back(...
#include <bits/stdc++.h> using namespace std; const int N = 200005; const long long INF = 1e9; const long long MOD = 1000000007; int prevs[20]; int main() { ios ::sync_with_stdio(0); cin.tie(0); int n, q; cin >> n >> q; int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; int a...
#include <bits/stdc++.h> using namespace std; int n; char s[1000005]; int main() { int i, j, l, r, p = 0; scanf( %s , s); n = strlen(s); for (j = 0; j < n && s[j] != . ; j++) ; if (j == n) { s[n] = . ; n++; } for (i = 0; i < n && s[i] == 0 ; i++) ; if (...
#include <bits/stdc++.h> using namespace std; const int Maxn = 1000 + 10; const int INF = 0x7f7f7f7f; const double eps = 1e-10; const double pi = acos(-1.0); inline int realcmp(double a, double b) { return (a > b + eps) ? 1 : ((a + eps < b) ? -1 : 0); } int main() { double hh, mm; ios::sync_...
#include <bits/stdc++.h> struct point { long x; long y; long z; }; const long maxn = 5001; const double inf = 2000000000; const double eps = 1.0e-8; point a[maxn]; double nnew, min; long n, q, choice1, choice2; double d[maxn]; double sqr(double x) { return (x * x); } double dist(point ...
#include <bits/stdc++.h> using namespace std; int main() { int n, x, i, y, ans = 0, q; scanf( %d%d , &n, &x); y = int(sqrt(x)); if (n < y) y = n; for (i = 1; i <= y; i++) { if (x % i == 0) { q = x / i; if (q <= n) { if (i == q) ans++; else ...
#include <bits/stdc++.h> using namespace std; const int mx = 1e9; struct Data { int p1, p2, p3, p4; Data(int a = mx, int b = mx, int c = mx, int d = mx) { p1 = a, p2 = b, p3 = c, p4 = d; } }; inline Data UN(Data a, Data b) { Data c; c.p1 = min(a.p1 + b.p1, a.p2 + b.p3), c.p2 = min(a....
#include <bits/stdc++.h> using namespace std; int main() { long long t, x, y, a, b; scanf( %lld , &t); while (t--) { scanf( %lld %lld %lld %lld , &x, &y, &a, &b); bool yes = false; int i = 0; int tens = 1000000; while (x <= y) { if (x == y) { yes = true; ...