func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; long long n, m, k, mod = 1e9 + 7; map<long long, long long> mp; string s; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); srand(time(0)); cin >> n >> k; vector<long long> a(n + 2); vector<long long> b(k + 2); for...
#include <bits/stdc++.h> using namespace std; int N, K, M, S; int arr[500000]; int raito[500005]; int seen[500005]; int bucket[500005]; int shift[500005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> M >> K >> N >> S; for (int i = 0; i < M; i++) { cin >> arr[i]; ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 400010; int n; int fa[MAXN][21]; int dep[MAXN]; int LCA(int x, int y) { if (dep[x] < dep[y]) swap(x, y); for (int i = 20; i >= 0; i--) { if (dep[x] - (1 << i) >= dep[y]) { x = fa[x][i]; } } if (x == y) return ...
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize( Ofast,no-stack-protector ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) #pragma GCC optimize( unroll-loops ) long long fun(long long n, long long m, long long mid) { long long val = 0; for (long long i...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } int main() { long long a, b; while (cin >> a >> b) { long long suma = 0, sumb = 0; long long ca = 0, c...
#include <bits/stdc++.h> using namespace std; int n, k, dp[2000 + 10][2000 + 10]; bool v[2000 + 10][2000 + 10]; vector<int> vec[2000 + 10]; int solve(int curr, int kk) { if (kk > k) return 0; if (kk == k) return 1; if (v[curr][kk]) return dp[curr][kk]; for (int i = 0; i < vec[curr].size(); i++...
#include <bits/stdc++.h> using namespace std; int a[100005]; int dp[302][100005]; int main() { ios::sync_with_stdio(0); int n, q; cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; cin >> q; memset(dp, 0, sizeof(dp)); for (int k = min(300, n); k >= 1; --k) { for (int i = n; i ...
#include <bits/stdc++.h> using namespace std; long long n, ans = 0, minm; long long A[10 * 100000 + 6]; unordered_map<long long, long long> M; long long pos, neg, cc = 0, k = 0; int main() { scanf( %lld , &n); for (int i = 1; i <= n; ++i) { scanf( %lld , &A[i]); M[A[i] - i]++; ans ...
#include <bits/stdc++.h> using namespace std; int a[200005], ans1 = 1, ans2 = 0; int main() { int n, b, b1; scanf( %d , &n); for (int i = 1; i <= n; ++i) { scanf( %d , &a[i]); } sort(a + 1, a + 1 + n); b1 = 0; for (int i = 2; i <= n; ++i) { b = a[i] - a[i - 1]; if (b ...
#include <bits/stdc++.h> using namespace std; int main(int argc, const char* argv[]) { int cases; cin >> cases; while (cases--) { int num; scanf( %d , &num); vector<pair<int, int> > coords; pair<int, int> z(0, 0); coords.push_back(z); for (int i = 0; i < num; ++i) { ...
#include <bits/stdc++.h> using namespace std; const int M = 110; int a[M]; int main() { int n, cnt = 0; scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d , a + i); if (a[i] % 2 == 0) cnt++; } if (n % 2 == 0) { printf( No n ); return 0; } if (a[1] % 2 =...
#include <bits/stdc++.h> using namespace std; template <class T> T mulmod(T a, T b) { if (b == 0) return 0; if (b == 1) return a; T x = mulmod(a, b >> 1); x = (x + x) % 1000000007; if (b & 1) x = (x + a) % 1000000007; return x; } template <class T> T larger(T a, T b) { return (a ...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const double eps = 1e-8; const double PI = acos(-1.0); const int maxn = 200 + 10; char str[maxn]; struct TwoSat { int n; vector<int> G[maxn * 2]; bool mark[maxn * 2]; int S[maxn * 2], c; bool isv[maxn]; int s...
#include <bits/stdc++.h> using namespace std; int thien, n, tt, h; string s; int main() { cin >> tt; for (int ii = 1; ii <= tt; ii++) { cin >> n; thien = 0; h = 0; for (int i = 1; i <= n; i++) { cin >> s; if (s.length() % 2 != 0) thien++; for (int j = 0; j...
#include <bits/stdc++.h> using namespace std; const int maxn = 300010; int p1[maxn], p2[maxn], q[maxn]; int main() { int n, m; scanf( %d%d , &n, &m); for (int i = 0; i < n; i++) { scanf( %d , &p1[i]); p1[i]--; p2[p1[i]] = i; q[i] = n; } for (int i = 0; i < m; i++) { ...
#include <bits/stdc++.h> using namespace std; int n, a[200001]; const double esl = 1e-11; double cal(double x) { double t = 0; double ans = 0; for (int i = 1; i <= n; i++) { if (t + a[i] - x < 0) { ans = max(ans, t); t = 0; } else { t += ((double)a[i] - x); ...
#include <bits/stdc++.h> const int N = 5e4 + 10; int n, m; std::vector<char> a[N]; int sx[N], sy[N]; int main() { int T; scanf( %d , &T); while (T--) { scanf( %d%d , &n, &m); for (int i = 1; i <= n; ++i) { a[i].resize(m + 2); getchar(); for (int j = 1; j <= m; +...
#include <bits/stdc++.h> using namespace std; auto clk = clock(); mt19937_64 rang( chrono::high_resolution_clock::now().time_since_epoch().count()); void test_case() { long long int n; cin >> n; long long int a[n + 1]; long long int t = -1, b = -1, c = -1; for (long long int i = 1; i <...
#include <bits/stdc++.h> using namespace std; long long nthRoot(long long A, long long N) { float xPre = rand() % 10; float eps = 1e-3; float delX = LLONG_MAX; float xK; while (delX > eps) { xK = ((N - 1.0) * xPre + (float)A / pow(xPre, N - 1)) / (float)N; delX = abs(xK - xPre); ...
#include <bits/stdc++.h> using namespace std; template <class T> inline void amin(T& a, const T& b) { if (a > b) a = b; } template <class T> inline void amax(T& a, const T& b) { if (a < b) a = b; } template <class T> inline void rv(vector<T>& v, int n) { vector<T>(n).swap(v); for (int ...
#include bits/stdc++.h using namespace std; #define all(x) x.begin(),x.end() #define pb push_back #define ff first #define ss second #define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define ar array #define int long long #define F(i,a,b) for(i=a;i<b;++i) #define RF(i,b,a) for(i=b;i>=a;...
#include <bits/stdc++.h> int main() { char str[3][100]; int i; for (i = 0; i < 3; i++) { scanf( %s , &str[i][0]); } int r = 0, p = 0, s = 0; for (i = 0; i < 3; i++) { if (str[i][0] == r ) r++; else if (str[i][0] == p ) p++; else if (str[i][0] == s ) ...
#include <bits/stdc++.h> using namespace std; long long int powe(long long int d, long long int s) { if (s == 1) return d; else if (s == 0) return 1; else { long long int u, v = d; for (u = 1; u < s; u++) { d = d * v; } return d; } } bool isprime(long ...
#include <bits/stdc++.h> using namespace std; using llint = long long; using par = pair<int, int>; const int MAXN = 200100; llint w[MAXN]; vector<par> edges[MAXN]; int p[MAXN], in[MAXN], out[MAXN], idx[MAXN], id; void dfs(int u) { in[u] = ++id; for (const auto& edge : edges[u]) { if (edge....
#include <bits/stdc++.h> using namespace std; using ll = long long; ll BASE_NUM = 998244353; class UnionFindTree { map<ll, ll> union_tree_data; public: UnionFindTree() {} UnionFindTree(vector<ll> verticals) { for (auto v : verticals) { union_tree_data[v] = v; } } vo...
#include <bits/stdc++.h> #define fi first #define se second #define gc getchar() //(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++) #define mk make_pair #define pii pair<int, int> #define pll pair<ll, ll> #define pb push_back #define IT iterator #define V vector #define TP template <...
#include <bits/stdc++.h> using namespace std; bool found = false; long long b, A[10000], n, orig_a; void bfs(long long a, long long k) { if (found) return; if (a > b) return; if (a == b) { found = true; n = k; a = orig_a; cout << YES << endl; cout << n + 1 << endl; ...
#include <bits/stdc++.h> using namespace std; class Compare { public: bool operator()(pair<long long, long long> a, pair<long long, long long> b) { return (a.first + a.second) > (b.first + b.second); } }; int main() { long long test, x, n, m, k, w, d, f, y; priority_queue<pair<long long...
#include <bits/stdc++.h> using namespace std; const int P = 1e9 + 7; vector<int> b[200005]; int L[200005], R[200005], u[200005], v[200005], opt[200005], size[200005]; int m, n, ql, qr, upd, tot, now, ans, i, x; struct data { int cnt, sum; data() { cnt = 1; } void multi(int x) { cnt = 1ll *...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const long double PI = 3.141592653589793; const long long maxn = 100005; long long x, y, z, n, k; void _print(long long t) { cerr << t; } void _print(string t) { cerr << t; } void _print(char t) { cerr << t; } void _print(...
#include <bits/stdc++.h> const double eps = 1e-8; const long long INF = 0x3f3f3f3f; const int mod = 20000311; const int maxn = 1e5 + 5; const int N = 1005; using namespace std; int a[maxn] = {0}; int dp[maxn][305] = {0}; int n; int dfs(int p, int k) { if (p > n) return 0; if (dp[p][k] != -1)...
#include <bits/stdc++.h> using namespace std; string Max(int n, int s) { string str = ; while (s >= 9 && n > 0) { str += 9 ; s -= 9; n--; } if (n == 0 && s > 0) return -1 ; if (n > 0) { str += char(s + 48); for (int i = 1; i < n; i++) str += 0 ; } retur...
#include <bits/stdc++.h> using namespace std; inline int max3(int a, int b, int c) { return max(a, max(b, c)); } inline int min3(int a, int b, int c) { return min(a, min(b, c)); } const int INF = 1e9; const long long LINF = 1e18; const double EPS = 1e-6; const double PI = acos(-1.0); const int maxn = 15...
#include <bits/stdc++.h> using namespace std; const int M = 1e9 + 7; const int MAX_N = 1002; int dp_end[MAX_N][MAX_N]; int dp_not[MAX_N][MAX_N]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { dp_end[0][i] = (i + 1) / 2; dp_not[0][i] = i / 2; } for (int i = 1; i ...
#include <bits/stdc++.h> using namespace std; void c_p_c() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int32_t main() { c_p_c(); long long n; string s[222222]; map<string, bool> check; cin >> n; for (long long i = 1; i <= n; i++) { cin >> ws; getlin...
#include <bits/stdc++.h> using std::max; using std::min; const int inf = 0x3f3f3f3f, Inf = 0x7fffffff; const long long INF = 0x3f3f3f3f3f3f3f3f; __inline__ __attribute__((always_inline)) unsigned int rnd() { static unsigned int seed = 416; return seed ^= seed >> 5, seed ^= seed << 17, seed ^= seed >> ...
#include <bits/stdc++.h> using namespace std; void fact(int n) { const int N = 1e5; vector<int> arr(N, 0); int q = 2; arr[0] = 1; int len = 1; int x = 0; int carry = 0; while (q <= n) { x = 0; carry = 0; while (x < len) { arr[x] = arr[x] * q + carry; ...
#include <bits/stdc++.h> using namespace std; bool vis[100006]; int main() { int n, k; while (cin >> n >> k) { memset(vis, false, sizeof(vis)); int st = 1, ed = 1 + k; int cnt = 0; while (cnt < k && st <= ed) { if (st != ed) vis[st] = vis[ed] = true, cout << st <<...
#include <bits/stdc++.h> using namespace std; const int N = 500023; bool vis[N]; vector<int> adj[N]; void solve() { long long int n, m; cin >> n >> m; map<long long int, long long int> cntA; map<long long int, long long int> cntB; map<long long int, long long int> cntC; map<long long i...
#include <bits/stdc++.h> using namespace std; int n, x; int cnt[100], b[105][105], sol[105][105], c[105][105], a[105][105]; inline void Mult_Mat(int a[][105], int b[][105]) { int i, j, k, s; for (i = 0; i < x; ++i) for (j = 0; j < x; ++j) { s = 0; for (k = 0; k < x; ++k) ...
#include<bits/stdc++.h> #define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL); #define int long long #define ull unsigned long long #define FOR(i,a,b) for(int i=a;i<b;i++) #define all(x) (x).begin(), (x).end() #define pb push_back #define mp make_pair #define in insert #define ff first #def...
#include <bits/stdc++.h> using namespace std; const int N = 110; const int mo = 1e9 + 7; int n, k, a[N], num[3], nn, f = 0; long long ans, now[N][N], dp[N][N], aa[N]; long long po(long long a, long long b) { if (b == 0) return 1; if (b == 1) return a; long long c = po(a, b / 2); if (b & 1) ...
#include <bits/stdc++.h> using namespace std; const int MX = 1000000000; int n, m, x, i, j, a[5050], f[5050]; int main() { scanf( %d%d , &n, &m); for (i = 3; i <= n; i++) f[i] = f[i - 1] + (i - 1) / 2; if (f[n] < m) { puts( -1 ); return 0; } for (i = 3; i <= n; i++) if (f[i...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; const int INF = (int)1e9 + 7; const long long linf = (long long)1e16 + 7; struct pnt { double x, y; pnt(double x, double y) : y(y), x(x) {} pnt() = default; }; int cmp(double a, double b) { if (abs(a - b) < eps) return ...
#include<bits/stdc++.h> using namespace std; #define pf printf #define PF(a) printf( %d n ,(a)) #define PF2(a,b) printf( %d %d n ,(a), (b)) #define PF3(a,b,c) printf( %d %d %d n ,(a), (b), (c)) #define PFL(a) printf( %lld n ,(a)) #defin...
#include <bits/stdc++.h> using namespace std; int main() { int n, i; cin >> n; string s; map<char, int> m; for (i = 0; i < n; i++) { cin >> s; m[s[0]]++; } int ans = 0, f1, f2; for (auto it = m.begin(); it != m.end(); it++) { f1 = it->second / 2; f2 = it->seco...
#include <bits/stdc++.h> using namespace std; int Read() { int x = 0; char ch = getchar(); while (!isdigit(ch)) ch = getchar(); while (isdigit(ch)) x = (x << 3) + (x << 1) + ch - 0 , ch = getchar(); return x; } void Write(int x) { if (x < 0) putchar( - ), x = -x; if (x == 0) putchar...
#include <bits/stdc++.h> using namespace std; int main() { long long n, d, a, b; cin >> n >> d >> a >> b; vector<pair<long long, int> > v(n); for (int i = 0; i < n; i++) { long long x, y; cin >> x >> y; v[i].first = x * a + y * b; v[i].second = i + 1; } sort(v.begin()...
#include <bits/stdc++.h> using namespace std; int main() { int t; long long x, y, p, q; cin >> t; while (t--) { cin >> x >> y >> p >> q; long long l = 0, h = 1e9, ans = -1, mid, a, b; while (l <= h) { mid = (l + h) / 2; a = p * mid; b = q * mid; if (...
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 7; const long long int N = 2 * (1e5); const long long int maxo = 1e14; const long long int inf = 1e17; int main(int argc, char const *argv[]) { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int x0, y0, ax,...
#include <bits/stdc++.h> using namespace std; void setIO(string name = ) { ios_base::sync_with_stdio(0); cin.tie(0); if (int((name).size())) { freopen((name + .in ).c_str(), r , stdin); freopen((name + .out ).c_str(), w , stdout); } } long long gcd(long long a, long long b) { r...
#include <bits/stdc++.h> using namespace std; int main() { string s = ; for (int i = 1; i < 1000; i++) { s += to_string(i); } int n; cin >> n; cout << s[n - 1]; return 0; }
#include <bits/stdc++.h> using namespace std; const int adj[8][2] = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}, {-1, -1}, {-1, 1}, {1, 1}, {1, -1}}; const long long int LLINF = 9e18; const int INF = 2e9; const int MOD = 1e9 + 7; const double EPS = 1e-10; const double PI = acos(-1); cons...
#include <bits/stdc++.h> using namespace std; int a[101]; int b[101]; int storage[200001]; int storage2[200001]; int* value = storage + 100000; int* prevalue = storage2 + 100000; int n, k; int main() { scanf( %d%d , &n, &k); int gtzero = 0, lezero = 0; for (int i = 0; i < n; i++) scanf( %d...
#include <bits/stdc++.h> using namespace std; int main() { int num, a1, a2, b1, b2, c1, c2, d, a, b, c; cin >> num >> a1 >> a2 >> b1 >> b2 >> c1 >> c2; a = a2; b = b2; c = c2; if (a + b + c == num) cout << a << << b << << c; else { d = a + b + c - num; if (c - d...
#include <bits/stdc++.h> using namespace std; const int N = 500005; const int maxx = 1000005; int n, x, y, q, l, r; int a[N]; struct Tree { int ans, m, tag; } tr[maxx * 6]; void pushdown(int rt) { int lson = rt << 1; int rson = rt << 1 | 1; tr[lson].m += tr[rt].tag; tr[rson].m += tr[...
#include <bits/stdc++.h> using namespace std; using ll = long long; const int inf = 1e9 + 7; const ll longinf = 1LL << 60; const ll mod = 1e9 + 7; int main() { int h, w, n, q; cin >> h >> w >> n >> q; vector<int> v[h]; for (int i = (int)(0); i < (int)(n); ++i) { int x, y; cin >> ...
#include <bits/stdc++.h> using namespace std; int main() { int n; int cnt = 0; cin >> n; string a; for (int i = 0; i < n; i++) { cin >> a; if (a == Tetrahedron ) cnt += 4; else if (a == Cube ) cnt += 6; else if (a == Octahedron ) cnt += 8; ...
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, /STACK:20000000 ) string problem_name = a ; void init() { freopen((problem_name + .in ).c_str(), rt , stdin); } long long res = 0; int ms[300100]; int len; void mul(int val) { int p = 0; for (int i = 0; i < 300000; i++) { ...
#include <bits/stdc++.h> const long long mod = 1e9 + 7; using namespace std; const long long N = 102; const long long M = 1e4 + 2; long long dp[N][M], c[N][N], cnt[N]; signed main() { long long n, i, j, k, l, ans = 0, type = 0; cin >> n; dp[0][0] = 1; c[0][0] = 1; for (i = 1; i <= n; i++...
#include <bits/stdc++.h> using namespace std; const int dx[] = {0, 1, -1, 0, 1, -1, -1, 1}; const int dy[] = {-1, 0, 0, 1, 1, 1, -1, -1}; const int N = 0; const int MOD = 0; const int INF = 1e9 + 10; const long long int LLINF = 1e18 + 10; int main() { ios_base::sync_with_stdio(0); cin.tie(0); ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int suma = 0, sumg = 0, a, g; char *arr = new char[n]; for (int i = 0; i < n; i++) { scanf( %d %d , &a, &g); if (abs(suma + a - sumg) < abs(sumg + g - suma)) { suma += a; arr[i] = A ; }...
#include <bits/stdc++.h> using namespace std; bool isPowerOfTwo(int x) { return (x && !(x & (x - 1))); } bool is_prime(int n) { if (n == 1) return false; for (int i = 2; i <= sqrt(n); i++) { if (n % i == 0) { return false; } } return true; } void solve() { int n; ci...
#include <bits/stdc++.h> using namespace std; using int64 = long long; int64 bit_count(int64 n) { int64 a{}; while (n) { a += 1; n >>= 1; } return a; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while (T--) { int64 n, m; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) { if (i == 1) printf( 14 n ); else { if (i == 2) printf( 16 n ); else printf( %lld n , (1LL * i * (i + 1) * (i + 1) - (i - 1))); }...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast,no-stack-protector ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx ) #pragma GCC target( avx,tune=native ) using namespace std; const int inf = 0x3f3f3f3f; const double eps = 1e-6; const int mod = 1000000007; inline string getstr(string ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long t; cin >> t; while (t--) { int n; string a, b; cin >> n >> a >> b; vector<int> res; for (int i = 0; i < n; i++) { if (a[i] != b[i...
#include <bits/stdc++.h> using namespace std; const int MAX = 2 * 1e5 + 5; const int INF = 1e9; const int MOD = 1e9 + 7; int N, K, A[MAX], table[20][MAX]; int main() { cin >> N >> K; for (int i = 0; i < (N); ++i) cin >> A[i]; for (int i = 0; i < (N); ++i) table[0][i] = A[i]; vector<int> b(N,...
#include <bits/stdc++.h> using namespace std; int main() { int r, g, b, ck, maximum = 0, temp; scanf( %d %d %d , &r, &g, &b); if (r % 2 == 1) r++; r = r / 2; if (g % 2 == 1) g++; g = g / 2; if (b % 2 == 1) b++; b = b / 2; temp = 27 + r * 3; if (temp > maximum) maximum = temp;...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; for (int i = 0; i < s.size(); i++) { for (char a = a ; a <= z ; a++) { string t = ; for (int j = 0; j < i; j++) { t += s[j]; } t += a; for (int j = i; j < s.size(); ...
#include <bits/stdc++.h> using namespace std; inline void output(long long int x) { if (x % 2) cout << x / 2 << n ; else cout << x / 2 - 1 << n ; return; } long long int N, K; int main() { cin >> N >> K; if (N >= K) output(K); else { if ((N << 1) - 1 < K) ...
#include <bits/stdc++.h> using namespace std; const int N = 5005; const int mod = 1000000007; int n, a, b, k; int dp[N][N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> a >> b >> k; for (long long i = 1; i <= n; ++i) { dp[0][i] = i; } for ...
#include <bits/stdc++.h> using namespace std; int mdc(int a, int b) { return !b ? a : mdc(b, a % b); } int main() { int n, m, x, y, a, b, p, d, x1, y1, x2, y2; cin >> n >> m >> x >> y >> a >> b; d = mdc(a, b); a /= d; b /= d; p = min(n / a, m / b); a *= p; b *= p; if (x + a / 2...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long N = 3e5 + 10; long long pow(long long a, long long b, long long m) { long long ans = 1; while (b) { if (b & 1) ans = (ans * a) % m; b /= 2; a = (a * a) % m; } return ans; } long lon...
#include <bits/stdc++.h> using namespace std; float distance(long long x, long long y, long long a, long long b) { return sqrt((x - y) * (x - y) + (a - b) * (a - b)); } int32_t main() { float n, x1, y1, x2, y2; cin >> n >> x1 >> y1 >> x2 >> y2; if ((x1 == x2 && (x1 == n || x1 == 0)) || (...
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, l, r, c, ans; cin >> a >> b >> l >> r; c = l % (a + b); if (c > a) { ans = 1; l += (a + b - c + 1); if (l <= r) ans += min(a, r - l + 1); if (a > b) { l += (2 * b); if (l <= r) ans += m...
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; const int maxn = 1e3 + 10; int n, m, mp[maxn][maxn], cnt, dx[] = {0, 1, 0, -1}, dy[] = {-1, 0, 1, 0}; bool vis[maxn][maxn]; vector<int> ans; void dfs(int x, int y) { if (vis[x][y] || x <= 0 || x > n || y <= 0 || y > m) return; ...
#include <bits/stdc++.h> using namespace std; int n, t; char v[500010]; vector<pair<int, int> > inter; int memo[500010]; int calcula(int ind) { int res = 0; int x = ind; int ini = 0; int fim = 0; bool erro = false; int lh = -1; inter.clear(); for (int i = 0; i < (n); i++) { ...
#include <bits/stdc++.h> int main() { int t = 1, i, n; scanf( %d , &n); for (i = 1; i <= n - 1; i++) { t = (t + i - 1) % n + 1; printf( %d , t); } return 0; }
#include <bits/stdc++.h> using namespace std; struct Point { int x, y; Point(int x = 0, int y = 0) : x(x), y(y) {} Point operator-(const Point z) const { return Point(x - z.x, y - z.y); } friend long long Cross(Point a, Point b) { return 1ll * a.x * b.y - 1ll * a.y * b.x; } } a[2010], b[...
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> pii; typedef long long ll; typedef unsigned long long ull; template <typename T> bool umax(T& a, const T& b) { return b <= a ? false : (a = b, true); } template <typename T> bool umin(T& a, const T& b) { return b >= a ? false...
#include <bits/stdc++.h> using namespace std; struct node { int p, q; } a[1009]; bool cmp(node a, node b) { if (a.p != b.p) return a.p < b.p; if (a.p == b.p) return a.q > b.q; } int main() { int m, n, i; scanf( %d%d , &m, &n); for (i = 1; i <= n; i++) { scanf( %d%d , &a[i].p, &...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int len = s.size(); cout << s[0]; int flag = 0; for (int i = 1; i < len; i++) { if (s[i] == d && s[i + 1] == o && s[i + 2] == t && (i + 2 != len - 1)) { cout << . ; i += 2; ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullptr); long long n, k, a, z = 0; cin >> n >> k; vector<int> x(n), c(n); for (int i = 0; i < n; i++) cin >> x[i]; cin >> a; for (int i ...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 * 2; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; string s; cin >> s; int l = 0, r = n - 1; while (l <= n && s[l] == 0 ) ...
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, /stack:200000000 ) #pragma GCC optimize( Ofast ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native ) #pragma GCC optimize( -ffloat-store ) const long long INF = 0xFFFFFFFFFFFFFFFL; const long long...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; scanf( %d%d , &n, &k); int mat[n + 1][n + 1]; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) mat[i][j] = 0; } int br = 0; for (int i = 1; i <= n; i += 2) { for (int j = 1, x = i; j <= n && x <= ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a = 1; int b = 2; bool ok = true; int k; for (int i = 0; i < n; i++) { cin >> k; if (k != a && k != b) { ok = false; } else { if (b == 3 && a == 1) { a = min(2, k);...
#include <bits/stdc++.h> using namespace std; const int N = 5, M = 20; int n, m, a[N], b[M], ans[M]; set<vector<int> > use[M + 1]; void find(int y, vector<int>& current) { if (y == m) { for (int i = 0; i < n; i++) if (a[i] != current[i]) return; for (int i = 0; i < n; i++) { fo...
#include <bits/stdc++.h> using namespace std; const int maxn = 1100; int n; char s[maxn + 10]; int data[maxn + 10]; int dp[maxn + 10][2]; int main() { cin >> n; getchar(); gets(s); int i; for (i = 0; s[i]; i++) data[i] = s[i] - 0 ; if (i == 1) printf( 0 n ); else { ...
#include <bits/stdc++.h> using namespace std; const int N = 200005; const int D = 30; struct node { int a, b; }; vector<int> road[N], h[N]; vector<node> q[N]; int n, m, t, fa[N][D + 1], w[N][D + 1], head[N], sum[N], ans[N], g[N]; int cnt, tot, dep[N], id[N], size[N], c[N]; int lowbit(int x) { re...
#include <bits/stdc++.h> using namespace std; struct prog { int i; int cmp; } a[100005]; int ans[100005]; bool cmp(prog a, prog b) { if (a.cmp == b.cmp) return a.i < b.i; else return a.cmp < b.cmp; } int main() { int n, m; while (cin >> n >> m) { priority_queue<pr...
#include <bits/stdc++.h> using namespace std; const int maxN = 3e5 + 11, maxlg = 2e1; typedef int i_N[maxN]; typedef long long l_N[maxN]; int N, M, Q, par[maxN][maxlg], umax[maxN][maxlg], umin[maxN][maxlg]; vector<int> adj[maxN], pos[maxN]; vector<pair<int, int> > query[maxN]; pair<int, int> edge[maxN];...
#include <bits/stdc++.h> using namespace std; template <class T, class L> bool smax(T& x, L y) { return x < y ? (x = y, 1) : 0; } template <class T, class L> bool smin(T& x, L y) { return x > y ? (x = y, 1) : 0; } const int maxn = 16; int n, a[maxn], b[maxn][maxn], ex, x[maxn]; bool mark[max...
#include <bits/stdc++.h> using namespace std; set<pair<pair<int, int>, pair<int, int> > > s; vector<int> ed[2][300000]; int n, m, k; int a[300000], b[300000]; long long ans[300000]; bool add(int x, int y, int dx, int dy) { pair<pair<int, int>, pair<int, int> > g = make_pair(make_pair(x, y), ma...
#include <bits/stdc++.h> using namespace std; inline long long read() { char ch = getchar(); long long x = 0, f = 1; while (ch < 0 || ch > 9 ) f = ch == - ? -1 : 1, ch = getchar(); while (ch >= 0 && ch <= 9 ) x = x * 10 + ch - 0 , ch = getchar(); return x * f; } int main(int argc, c...
#include <bits/stdc++.h> using namespace std; const int MAX = 205, MAXL = 1 << 20; char qq[MAXL]; char s[MAX][MAX]; pair<int, int> kamo[MAX][MAX]; vector<pair<int, int> > R[MAX][MAX]; int indeg[MAX][MAX]; int cik[MAX][MAX]; int imacik[MAX * MAX][10]; int brred, brstup; int pr[10], ps[10]; int bi...
#include <bits/stdc++.h> using namespace std; template <typename T> struct Segtree { int N; vector<T> seg, lazy; Segtree(int _n) : N(_n) { seg.resize(4 * N, 0); lazy.resize(4 * N, 0); } T join(T x, T y) { return max(x, y); } void push(int x, int s, int e) { if (!lazy[x]) ...
#include <bits/stdc++.h> using namespace std; void addmod(int &a, long long b) { a = (a + b); if (a >= 1000000007) a -= 1000000007; } void mulmod(int &a, long long b) { a = (a * b) % 1000000007; } template <class T> bool domin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } template <clas...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10; int l = 1, r = 0; int a[MAXN], b[MAXN], now[MAXN], num[MAXN << 1], cnt[MAXN], ans[MAXN]; map<int, int> ms; struct Change { int p, x, y; } c[MAXN]; struct Query { int l, r, t, id; bool operator<(const Query &A) const { ...