func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const int maxn = 1e4 + 5; int a[maxn]; int main() { int n, m; scanf( %d%d , &n, &m); for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); } while (m--) { int l, r, x; scanf( %d%d%d , &l, &r, &x); int cnt1 = 0, cnt2 = 0; ...
#include <bits/stdc++.h> using namespace std; map<long long, int> getFactors(long long n) { long long num = n; long long sqrn = sqrt(n); map<long long, int> ret; for (long long i = 2; i <= sqrn; i++) while (num % i == 0) { ret[i]++; num /= i; } if (num > 1 && num != n...
#include <bits/stdc++.h> using namespace std; int v[100005], u[100005], w[100005], dist[100005]; vector<pair<int, int> > edges[100005]; priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > pq; int main() { int n, m, s, l; while (cin >> n >> m >> s) ...
#include <bits/stdc++.h> using namespace std; const int MAX = 1000000 + 10; const int Mod = 998244353; const int alp = 3; int n, S; int C[MAX]; int dp[MAX]; namespace opt { int N; int a[MAX], b[MAX], w[MAX], tmp[MAX]; int Pow(int a, int b) { int k = 1; for (; b; b /= 2, a = (long long)a * ...
#include <bits/stdc++.h> using namespace std; long long aX[100001]; long long aY[100001]; int main() { long long n, k; cin >> n >> k; long long x, y; cin >> x >> y; long long mod = n * 2; for (int i = 0; i < n; i++) cin >> aX[i] >> aY[i]; k = k % mod; long long cx = 0, cy = 0; ...
#include <bits/stdc++.h> using namespace std; long long int arr[100005]; long long int l1[100005]; long long int l2[100005]; long long int d[100005]; long long int e[100005]; long long int tree[100005]; long long int tree2[100005]; void update(long long int idx, long long int val, long long int n) { ...
#include <bits/stdc++.h> int main() { int i, A[30], k = 0, B[7]; for (i = 1; i <= 24; i++) { scanf( %d , &A[i]); } for (i = 1; i <= 6; i++) { if (A[4 * i] == A[4 * i - 1] && A[4 * i - 2] == A[4 * i - 3] && A[4 * i] == A[4 * i - 2]) { B[i] = 1; } else B[i] = ...
#include <bits/stdc++.h> double pi = 3.1415926535897931159979635; using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long cf = 0, cs = 0, c47 = 0, c74 = 0; string a; cin >> a; long long s = a.size(); for (int i = 0; i < s; i++) { if (a[i]...
#include <bits/stdc++.h> using namespace std; int heights(long long int n) { long long int count = 0, m, k; for (long long int x = 1; x <= n; x++) { m = 3 * x * x + x; if (m > 2 * n) break; else { k = x + n; if (k % 3 == 0) count++; } } return count; ...
#include <bits/stdc++.h> using namespace std; int w; string ch(string s, char x, string b) { int n = s.size(); bool cx = 0; char mina = z ; for (int i = 0; i < n; i++) { if (s[i] == x && b[i] > s[i]) { cx = 1; mina = min(mina, b[i]); } } if (!cx) { return...
#include <bits/stdc++.h> using namespace std; const int SIZE = 84; const int VERTS = SIZE * SIZE; int n, m; int v, s, t; int pict[SIZE][SIZE]; const int dir[4][2] = {{1, 0}, {-1, 0}, {0, -1}, {0, 1}}; inline bool good(int x, int y) { return x >= 0 && y >= 0 && x < n && y < m; } struct Edge { int a...
#include <bits/stdc++.h> using namespace std; const long long MOD = 998244353; const double oula = 0.57721566490153286060651209; using namespace std; map<long long, string> mp; int main() { std::ios::sync_with_stdio(false); long long n; cin >> n; long long nn = sqrt(n); string tmp; f...
#include <bits/stdc++.h> using namespace std; int N; int axor[1 << 16]; int degree[1 << 16], s[1 << 16]; vector<pair<int, int>> edge; set<pair<int, int>> q; int main() { scanf( %d , &N); for (int i = 0; i < N; i++) { scanf( %d %d , &degree[i], &s[i]); q.insert({degree[i], i}); } ...
#include <bits/stdc++.h> using namespace std; unsigned long long int gcd(unsigned long long int a, unsigned long long int b) { unsigned long long int max = a > b ? a : b; unsigned long long int min = a < b ? a : b; if (max % min == 0) return min; if (max % min == 1) return 1; return gcd(min, max...
#include <bits/stdc++.h> using namespace std; long long a, b, c, n, m, k = 0, T, maxx = -0x3f3f3f3f; int main() { scanf( %lld , &T); while (T--) { scanf( %lld%lld , &n, &k); long long t = 0, tmp = 0; if (n == 2 && k == 3) { cout << No << endl; continue; } wh...
#include <bits/stdc++.h> using namespace std; map<vector<long long>, long long> mp; int main() { long long n; cin >> n; long long a[] = {2, 3, 5, 7}; vector<long long> t; for (long long mask = 1; mask < (1 << 4); mask++) { t.clear(); for (long long j = 0; j < 4; j++) { if (...
#include <bits/stdc++.h> using namespace std; const int maxN = 2005; const int dx[10] = {0, 0, 0, 1, -1, 1, 1, -1, -1}; const int dy[10] = {0, 1, -1, 0, 0, -1, 1, -1, 1}; int n, area, sx, sy; bool p[maxN][maxN], vis[maxN][maxN]; void init() { scanf( %d , &n); for (int i = 1; i <= n; ++i) for...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, k; cin >> n >> k; int sum = n - n % k; sum += min(n % k, k / 2); cout << sum << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; int floor[n][2 * m]; for (int i = 0; i < n; i++) { for (int j = 0; j < 2 * m; j++) { cin >> floor[i][j]; } } int count = 0; for...
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; map<int, int> mx, my; map<pair<int, int>, int> mp; for (int i = 0; i < n; i++) { int first, second; cin >> first >> second; mx[first]++; my[second]++; mp[{first, second}]++; }; lon...
#include <bits/stdc++.h> using namespace std; int up[200005]; int down[200005]; vector<int> answer; bool done = true; ; int main() { int n; cin >> n; for (int i = 1; i < n; i++) { cin >> up[i]; } for (int i = 1; i < n; i++) { cin >> down[i]; } answer.push_back(0); ...
#include <bits/stdc++.h> using namespace std; long long int modexpo(long long int x, long long int y) { if (y == 0) return 1; if (y % 2) { long long int viky = modexpo(x, y / 2); return (((x * viky) % 1000000000) * viky) % 1000000000; } else { long long int viky = modexpo(x, y / 2); ...
#include <bits/stdc++.h> using namespace std; long long int ax, ay, bx, by, cx, cy; double k1, k2, k3; int main() { long long int dis_ab, dis_ac, dis_bc, max_dis = -1; cin >> ax >> ay >> bx >> by >> cx >> cy; dis_ab = (ax - bx) * (ax - bx) + (ay - by) * (ay - by); k1 = (double)(ax - bx) / (ay - ...
#include <bits/stdc++.h> int main() { int n; std::scanf( %d , &n); for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { std::printf( %d , j * n + (j % 2 == 0 ? i : n - i - 1) + 1); } std::printf( n ); } return 0; }
#include <bits/stdc++.h> using namespace std; const int INF = 1000000001; const double EPS = 10e-9; const int MAXN = 100005; pair<int, int> t[MAXN << 1]; int MOD; void rob() { int n; scanf( %d , &n); int tmp; for (typeof(0) i = (0); i < (n); ++i) { scanf( %d , &tmp); t[i] = mak...
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 10; int arr[MAX]; int n; int query(int x, int y, int z) { cout << ? << x << << y << << z << endl; int a; cin >> a; return a; } array<int, 3> col[2]; int ans[MAX]; vector<int> v; int main() { int t; ...
#include <bits/stdc++.h> using namespace std; const int N = 1010; struct node { double x; double y; double t; double p; bool operator<(const node& W) const { return t < W.t; } } q[N]; double dp[N]; bool check(node a, node b) { double dx = a.x - b.x; double dy = a.y - b.y; ret...
#include <bits/stdc++.h> using namespace std; int n, m, k; int x[505], y[505]; int x_koord[1005], y_koord[1005], kk, kkx, kky; int z[1055][1055]; bool popuni(int sz) { kk = 0; for (int i = 1; i <= k; i++) { int xl = x[i] - sz; if (xl < 1) { xl = 1; } int xr = x[i] + s...
#include <bits/stdc++.h> using namespace std; char s[1000010]; int n, p[1000010]; int main() { scanf( %s , s), n = strlen(s); for (int i = 0; i < n; i++) if (s[i] == 1 ) p[n - 1 - i] = 1; for (int i = 0, j; i < n + 2;) if (!p[i]) i++; else { j = i; while (p...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int i, j, k; int n; cin >> n; int x = n / 4; string s = abcd ; string ans = ; if (n % 4 == 0) for (i = 0; i < x; i++) ans += s; else { if (n % 4 == 1) ...
#include <bits/stdc++.h> using namespace std; void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << << H; debug_out(T...); } const int INF = 1e9; const long long MOD = 1e9 + 7; const int N = 1e5 + 5, MO = 350, SQ = 650; in...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); long long t, n, i, j, flag = 0, temp, nodes, a, b, m, k, sz, sm, res; long long mn, mx; long long l, r; long long x, y, z; long long c, d; t = 1; vector<pair<int, int>> v; string s; char c...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; char a[N], b[N]; int s[N][26]; void init() { int n = strlen(a + 1); memset(s, 0, sizeof(s)); for (int i = n; i >= 1; i--) { for (int j = 0; j < 26; j++) { s[i - 1][j] = s[i][j]; } s[i - 1][a[i] - a ] =...
#include <bits/stdc++.h> using namespace std; const long long int N = 500009; const long long int mod = 1000000007; long long int n, k; string s; string see; vector<long long int> v; void pre() { see = s; for (auto i : s) see += i; for (auto i : s) see += i; } int32_t main() { cin >>...
#include <bits/stdc++.h> using namespace std; int nod(int a, int b) { int c; if (a > b) swap(a, b); for (;;) { c = b % a; b = a; a = c; if (a == 0) return b; } } int main() { int x, y, a, b; cin >> x >> y >> a >> b; int d = x * y / nod(x, y); int c = b / d...
#include <bits/stdc++.h> using namespace std; int n = 0, a, tc; int p[100005]; vector<int> cho[6][100005]; int sum[6]; int ret = 0; void doit(int x, int cur) { if (x == n - 1) { ret += cho[x + 5 - n][cur].size(); return; } for (int i = 0; i < cho[x + 5 - n][cur].size(); i++) { ...
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 10; int n, q, k; vector<pair<int, int> > tree[N << 2]; int ask[N], ans[N]; struct que { int x, y, times, l; }; queue<que> Q; int fa[N], h[N], siz[N]; int find(int o) { if (o != fa[o]) { return find(fa[o]); } retu...
#include <bits/stdc++.h> using namespace std; const int s_size = 1e5 + 5; const int mod = 1e9 + 7; int f[(s_size + 1) >> 1] = {1}, t[(s_size + 1) >> 1], g[(s_size + 1) >> 1]; int fac[s_size] = {1}, inv[s_size], ans[s_size]; int num(char c); void fac_inv(void); int qpow(int a, int b); int main(void) { ...
#include <bits/stdc++.h> using namespace std; long long int INF = (long long int)1e16; int n, m, r; vector<int> s, b; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); s.clear(); b.clear(); cin >> n >> m >> r; int x, y; int bax = INT_MAX; int bay = INT_MIN; for ...
#include <bits/stdc++.h> using namespace std; int cont[1003], sum[1003]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int ans = 0; string s1, s2; cin >> s1 >> s2; int n = s1.size(); int m = s2.size(); for (int i = 0; i < n; i++) cont[s1[i] - a ]++; for (int i = 0...
#include <bits/stdc++.h> using namespace std; inline long long getint() { long long num = 0, flag = 1; char c; while ((c = getchar()) < 0 || c > 9 ) if (c == - ) flag = -1; while (c >= 0 && c <= 9 ) num = num * 10 + c - 48, c = getchar(); return num * flag; } int n, m, q, R; i...
#include <bits/stdc++.h> using namespace std; int n; long long m; int soln[51]; long long mr = 0; int main() { cin >> n >> m; --m; for (int k = 1; k < n; ++k) { mr = mr * 2 + (m & 1); m >>= 1; } int i = 1, j = n; for (int k = 1; k <= n; ++k) { if (mr & 1) so...
#include <bits/stdc++.h> using namespace std; long long n, k, x; long long m[200010]; long long answer; struct node { long long pre; long long next; } p[200010]; int main() { long long a; while (~scanf( %I64d %I64d %I64d , &n, &k, &x)) { answer = p[1].pre = p[n].next = 0; a = x...
#include <bits/stdc++.h> using namespace std; int main() { int x, y, z; cin >> x >> y >> z; if (z == 0) { if (x > y) cout << + ; else if (x < y) cout << - ; else cout << 0 ; } else { if (x > y + z) cout << + ; else if (y > x + z) ...
#include <bits/stdc++.h> int main() { char name[100], winner[100]; int sh, uh, a, b, v, c, d, e; int n, i; int sum; int total = sum; scanf( %d , &n); scanf( %s %d %d %d %d %d %d %d , name, &sh, &uh, &a, &b, &c, &d, &e); sum = sh * 100 - uh * 50 + a + b + c + d + e; total = sum; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j = 0; char d; cin >> n; string s; cin >> s; char a[n][n + 1]; for (i = 0; i < n; i++) { s.copy(a[i], n - i, i), s.copy(a[i] + (n - i), i), a[i][n] = 0; d = ( 9 - a[i][0] + 1) % 10; for (j = 0; j < n;...
#include <bits/stdc++.h> using namespace std; template <class T1> void deb(T1 e) { cout << e << endl; } template <class T1, class T2> void deb(T1 e1, T2 e2) { cout << e1 << << e2 << endl; } template <class T1, class T2, class T3> void deb(T1 e1, T2 e2, T3 e3) { cout << e1 << << e2 ...
#include <bits/stdc++.h> using namespace std; const int inf = 2000000000; static inline int Rint() { struct X { int dig[256]; X() { for (int i = 0 ; i <= 9 ; ++i) dig[i] = 1; dig[ - ] = 1; } }; static X fuck; int s = 1, v = 0, c; for (; !fuck.dig[c = getchar...
#include <bits/stdc++.h> int main() { int n, p, q, i, j; int cnt = 0; char s[1000]; scanf( %d %d %d n , &n, &p, &q); gets(s); while (n % q != 0 && n >= p) { ++cnt; n -= p; } if (n % q != 0) puts( -1 ); else { printf( %d n , cnt + n / q); for (i = 0; i ...
#include <bits/stdc++.h> using namespace std; char a[4][100][100]; int c[6]; int check(int le, int s, char st) { int ct = 0; for (int i = 0; i < s; i++) { for (int j = 0; j < s; j++) { if ((i - (s - 1) / 2 + j - (s - 1) / 2) % 2 == 0 && a[le][i][j] != st) { ct++; } else i...
#include <bits/stdc++.h> using namespace std; int N, M, cnt, maxi; char c; int star[105][105]; int lefted[105][105]; int righted[105][105]; int up[105][105]; int down[105][105]; int chk[105][105]; struct ryunha { int x, y, r; } ans; vector<ryunha> res; int main(void) { cin >> N >> M; ...
#include <bits/stdc++.h> using namespace std; const int inf = 1000000007; const long long linf = 1LL << 62; const unsigned long long ulinf = 1ULL << 63; const double eps = 0.000001; const double pi = 3.14159265358979323846; template <class T> T abs(T a) { return a >= 0 ? a : -a; } template <clas...
#include <bits/stdc++.h> using namespace std; const int MAX = 200500; int inp[MAX]; int out[MAX]; bool flag[MAX]; map<long long, int> ID; map<long long, int> hasInp; namespace hopcroftKarp { int ptr[100011], next[200011], zu[200011]; int n, m, match[100011], D[100011], q[100011]; void init(int _n)...
#include <bits/stdc++.h> using namespace std; int dp[2][505][505]; char mp[505][505]; const int mod = 1000000007; int dis(int a, int b, int c, int d) { return abs(a - c) + abs(b - d) <= 1; } int main() { int n, m; scanf( %d%d , &n, &m); for (int i = 0; i < n; i++) scanf( %s , mp[i]); if (mp[...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3f; const int MOD = 1e9 + 7; int dir[8][2] = {-1, 0, 1, 0, 0, -1, 0, 1, -1, -1, -1, 1, 1, -1, 1, 1}; template <typename S, typename T> ostream &operator<<(ostream &os, const pair<S, T> x) { ...
#include <bits/stdc++.h> using namespace std; const int maxn = 3333; int cnt[maxn][maxn][2], fuck[maxn], dep[maxn][maxn], dis[maxn][maxn]; struct Edge { int t, next, v; } edge[maxn << 1]; int head[maxn], tot, n; void new_edge(int a, int b, int t) { edge[tot].t = b; edge[tot].next = head[a]; ...
#include <bits/stdc++.h> using namespace std; bool besarDulu(const int &a, const int &b) { return a > b; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { int h, m; cin >> h >> m; int minutes = (24 - h - 1) * 60 + (60 - m); c...
#include <bits/stdc++.h> using namespace std; bool cur1; int n, m, K; int L[100005 * 120], R[100005 * 120], res[100005 * 120], tt, rt[100005 * 3]; int update(int p, int l, int r, int x, int v) { int c = ++tt; L[c] = L[p], R[c] = R[p]; if (l == r) { res[c] = min((p ? res[p] : 0x3f3f3f3f), v);...
#include <bits/stdc++.h> using namespace std; long long MOD = 1e9 + 7; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; int t; cin >> t; while (t != 0) { t--; int n, k, l = -1, r = -1; cin >> n >> k; int c = k + 1, z, res = 0; ...
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long b[n]; pair<long long, long long> arr[n]; for (long long i = 0; i < n; i++) { cin >> b[i]; arr[i].first = b[i] - i + 200000; arr[i].second = b[i]; } sort(arr, arr + n); long l...
#include <bits/stdc++.h> using namespace std; mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); mt19937_64 rnd64( chrono::high_resolution_clock::now().time_since_epoch().count()); long long power(long long a, long long m, long long mod) { long long ans = 1; while (m) { ...
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; long long power(long long x, long long y) { if (y == 0) return 1; long long a = power(x, y / 2); if (y % 2) { return (a * ((a * x) % mod)) % mod; } else { return (a * a) % mod; } } int main() { long long...
#include <bits/stdc++.h> using namespace std; string b[51]; bool check(pair<int, int> f, pair<int, int> s) { bool r1 = true, r2 = true, c1 = true, c2 = true; for (int i = f.first; i <= s.first; i++) { if (b[i][f.second] == W ) c1 = false; if (b[i][s.second] == W ) c2 = false; } for (...
#include <bits/stdc++.h> enum var_type { TYPE_DOUBLE, TYPE_STRING, TYPE_INT, TYPE_T, }; using namespace std; struct proc { string name; vector<var_type> types; }; vector<proc> procedures; map<string, var_type> vars; vector<int> results; var_type get_type(string type_name) { ...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) const int inf = 0x3f3f3f3f; const long long LL_INF = 0x3f3f3f3f3f3f3f3f; template <typename T> T gcd(T a, T b) { if (a == 0) return b; return gcd(b % a, a); } long long power(long long a, long long b, long long m = 1000000007) { long long ans...
#include <bits/stdc++.h> using namespace std; const int N = 1 << 20; long long fac[20]; vector<long long> lst; vector<long long> lucky; void prepare(int cnt, int all, long long now) { if (cnt == all) { lucky.push_back(now); return; } prepare(cnt + 1, all, now * 10 + 4); prepare(c...
#include <bits/stdc++.h> using namespace std; int block(long int x) { vector<long int> v; while (x > 0) { v.push_back(x % 2); x = x / 2; } int ret = 0; for (int i = 0; i < v.size(); i++) { if (v[i] == 1) { ret++; } } return ret; } void pprint(long int ...
#include <bits/stdc++.h> using namespace std; const int N = 5001; long long a[N], mem[N][2], b[N]; int n, m; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; b[i] = a[i]; } sort(b, b + n); m = unique(b, b + n) - b; for (int i = n - 1; i >= 0; i--) mem...
#include <bits/stdc++.h> using namespace std; template <class T, class V> T power(T t, V v) { T second = 1; while (v--) second *= t; return second; } void _print(long long t) { cerr << t; } void _print(int t) { cerr << t; } void _print(string t) { cerr << t; } void _print(char t) { cerr << t...
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << : << arg1 << n ; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, , ); ...
#include <bits/stdc++.h> using namespace std; int main() { int s1, s2, s3, a, b, c; cin >> s1 >> s2 >> s3; a = (s1 * s2) / s3; a = pow(a, 0.5); b = (s2 * s3) / s1; b = pow(b, 0.5); c = (s1 * s3) / s2; c = pow(c, 0.5); cout << 4 * (a + b + c) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; void solve() { long long n, ans = 0; cin >> n; for (;; ans++) { if (n == 1) break; if (n % 6 == 0) n /= 6; else if (n % 3 == 0) { if ((n * 2) % 3 != 0) { cout << -1 n ; return; } n *= 2; ...
#include <bits/stdc++.h> using namespace std; using ll = long long; void debug() { cerr << ] n ; } template <class H, class... T> void debug(H h, T... t) { cerr << h; if (sizeof...(t)) { cerr << , ; } debug(t...); } void solve() { int n; cin >> n; string s; cin >> ...
#include <bits/stdc++.h> using namespace std; double g[110][110], x[110]; int n, m, ues[110]; pair<pair<int, int>, int> p[5010]; bool vis[110]; void read(int &x) { char ch = getchar(); int mark = 1; for (; ch != - && (ch < 0 || ch > 9 ); ch = getchar()) ; if (ch == - ) mark = -1,...
#include <bits/stdc++.h> using namespace std; struct node { int k, a; bool operator<(const node &X) const { return a > X.a; } }; int n, fa[5010], limi[5010], ans[5010]; int order[5010], co; vector<int> edge[5010]; vector<int> val[5010]; priority_queue<node> train[5010]; void dfs(int u, int fat...
#include <bits/stdc++.h> using namespace std; int read() { int f = 1; int res = 0; char ch; do { ch = getchar(); if (ch == - ) f = -f; } while (ch < 0 || ch > 9 ); do { res = res * 10 + ch - 0 ; ch = getchar(); } while (ch >= 0 && ch <= 9 ); return f =...
#include <bits/stdc++.h> using namespace std; int ans[1000005]; int main() { int n; cin >> n; int a[n], b[n]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> b[i]; int l = 0; for (int i = 0; i < n; i++) { for (int j = i; j < n; j++) { if (b[j] ...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int n = s.size(); string s1 = hello ; int n1 = s1.size(); int i = 0, j = 0; int count = 0; while (j < n1 && i < n) { if (s1[j] == s[i]) { j++; count++; } i++; } i...
#include <bits/stdc++.h> using namespace std; long long i, j = 0, k, sum = 0, ctr = 0, c = 0, ok = 0; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long a, b, c; cin >> a >> b >> c; for (i = a; i >= 0; i--) { if (c >= i * 4 && b >= i * 2) { ok = i; ...
#include <bits/stdc++.h> using namespace std; int main() { int cen, feet = 0, inch; cin >> cen; inch = cen / 3; if (cen % 3 == 2) inch++; if (inch >= 12) { feet = inch / 12; inch = inch % 12; } cout << feet << << inch << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int nmin, nmax = 1; int n, m, a, b; scanf( %d%d , &n, &m); nmin = n; for (int i = 0; i < m; i++) { scanf( %d%d , &a, &b); if (b < a) swap(a, b); nmin = min(nmin, b); nmax = max(nmax, a); } if (nmax < nmin)...
#include <bits/stdc++.h> using namespace std; int infinity = 10000000; int railway[401][401]; int calculatedistance(int start, int end, bool bus) { bool visitedtown[401]; int distance[401]; queue<int> myQueue; for (int i = 1; i <= 400; i++) visitedtown[i] = false; for (int i = 1; i <= 400; i...
#include <bits/stdc++.h> using namespace std; int limit[100005] = {0}; int main() { ios::sync_with_stdio(false); memset(limit, 0, sizeof(limit)); int n; cin >> n; for (int i = 0; i < n; i++) { int x, k; cin >> x >> k; if (x == limit[k]) limit[k]++; else if (x > ...
#include <bits/stdc++.h> using namespace std; int main() { int i, j, w, h; string temp; vector<string> img; cin >> w >> h; for (i = 0; i < h; i++) { cin >> temp; img.push_back(temp); } for (j = 0; j < w; j++) { for (i = 0; i < h; i++) cout << img[i][j] << img[i][j]; ...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int a[1005][1005]; int main() { int h, w; cin >> h >> w; vector<int> r(h), c(w); for (int i = 0; i < h; i++) { cin >> r[i]; } for (int i = 0; i < w; i++) { cin >> c[i]; } memset(a, -1, sizeof(a)); ...
#include <bits/stdc++.h> using namespace std; template <typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << ; cout << endl; } template <typename T> void chmin(T &t, const T &f) { if (t > f) t = f; } template <typename T> void chmax(T &t, const T &f) { if (t < f)...
#include <bits/stdc++.h> using namespace std; const int N = 1000005; int l[N], r[N], n, i, ans, a[N], w, j; char c[N]; bool bb[N]; set<int> s; set<int>::iterator it; inline void maintain(int i) { if ((l[i] && c[i] != c[l[i]]) || (r[i] <= n && c[r[i]] != c[i])) s.insert(i); else if (s.count...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; string s; cin >> s; vector<int> A(91, 0); for (int i = 0; s[i]; i++) { A[(int)s[i]]++; } for (int i = 65; i < 65 + k; i++) if (A[i] == 0) { cout << 0 ; return 0; } ...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; struct Matrix { long long coef[105][105]; Matrix() { for (int i = (0); i <= (101); ++i) for (int j = (0); j <= (101); ++j) coef[i][j] = 0; } Matrix operator*(Matrix a) { Matrix res; for (int i...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const long long int INF = 1e18 + 2; bool compareBysecond(pair<long long int, long long int> a, pair<long long int, long long int> b) { return a.second > b.second; } int log(long long int x) { int cnt = 0; ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000 + 10; const int MAXM = 10000 + 10; const int INF = 1000 * 1000 * 1000; int n, m, a[MAXM], b[MAXM], c[MAXM], q[MAXN], d[MAXN][MAXN], s, minimum[MAXN]; int main() { int check = 0; int sum = 0; int pt = 0; cin >> n; for (in...
#include <bits/stdc++.h> using namespace std; char arr[2][100010]; int vis[2][100010]; int k, n, curj1, curj2; bool valid(int i, int j) { if (i >= 0 && i < 2 && j >= 0 && j >= n) return true; if (i >= 0 && i < 2 && j >= 0 && j < n && arr[i][j] != X && vis[i][j] == 0) return true; return fa...
#include <bits/stdc++.h> using namespace std; int Res[2][7010], N[2][7010], Loss[2][7010]; int n, m, k, OpN[2]; queue<pair<int, int> > Q; int main() { srand((unsigned)time(0)); ios::sync_with_stdio(false); cin.tie(0); cin >> n; cin.get(); for (int i = 0; i < 2; i++) { cin >> m; ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long a, b, c, d; cin >> a >> b >> c >> d; bool prob[5]; for (bool& i : prob) { i = true; } if ((a == 0 && b == 0) || (a + b) % 2 == 0) { prob[1] = prob[2] = ...
#include <bits/stdc++.h> using namespace std; vector<int> p[3030]; long long dist[3030][3030]; pair<long long, long long> out[3030][5]; pair<long long, long long> in[3030][5]; void bfs(int x) { dist[x][x] = 0; queue<pair<long long, long long> > q; q.push(make_pair(0, x)); pair<long long, lon...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10, mod = 1e9 + 7; void solve() { int n; cin >> n; int a[n]; for (int i = 0; i < n; ++i) { cin >> a[i]; } int ans = 0; for (int i = 1; i < n; ++i) { if (a[i] == 3 && a[i - 1] == 1) { ans += 4; }...
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << : << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ...
#include <bits/stdc++.h> using namespace std; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, k; cin >> n >> k; vector<string> s(n); for (long long i = 0; i < n; i++) cin >> s[i]; vector<long long> g[n * n]; for (long long i = 0; i < n; i++) ...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using std::abs; using std::cerr; using std::cin; using std::cout; using std::map; using std::max; using std::min; using std::pair; using std::set; using std::string; using std::swap; using std::vector; using ll = long long; using uint = u...
#include <bits/stdc++.h> using namespace std; const long double EPS = 1e-9; const long double PI = atan(1) * 4; const long long M = 1000000007; struct PT { double x, y; PT() {} PT(double x, double y) : x(x), y(y) {} PT(const PT &p) : x(p.x), y(p.y) {} PT operator+(const PT &p) const { retu...