func_code_string
stringlengths
59
71.4k
#include bits/stdc++.h #define int long long using namespace std ; const int M=998244353,mxM=5e4 ; int d[21][mxM+1],n,m,p,iv[21],f1[21],f2[21]; signed main(){ cin >> n >> m ; for(int i=0;i<n;i++) for(int j=0;j<m;j++) cin >> d[i][j] ; iv[1]=1 ; for(int i=2;i<n+1;i++) iv[i]=M-M/i*...
#include <bits/stdc++.h> using namespace std; inline bool read(int &x) { char ch; bool flag = false; for (ch = getchar(); !isdigit(ch); ch = getchar()) if (ch == - ) flag = true; for (x = 0; isdigit(ch); x = x * 10 + ch - 0 , ch = getchar()) ; x = flag ? -x : x; if (ch == n )...
#include <bits/stdc++.h> using namespace std; const int N = 1e6; long long int n, k, mx, sum, a[N]; int main() { cin >> n >> k; sum++; for (int i = 0; i < n; i++) { cin >> a[i]; if (i) { if (a[i] != a[i - 1]) { sum++; mx = max(mx, sum); } else { ...
#include <bits/stdc++.h> using namespace std; void _print(int t) { cerr << t; } void _print(string t) { cerr << t; } void _print(char t) { cerr << t; } void _print(long double t) { cerr << t; } void _print(double t) { cerr << t; } void _print(unsigned long long t) { cerr << t; } template <class T, class...
#include <bits/stdc++.h> using namespace std; vector<int> a; int n, k, f, c, ans; int main() { cin >> n >> k; for (int i = 2; i <= n; i++) { f = 0; for (int j = 2; j <= i / 2; j++) f += (i % j == 0); if (f == 0) a.push_back(i); } for (int i = 2; i < a.size(); i++) for (in...
#include <bits/stdc++.h> using namespace std; int n, k, f[200009]; int judge(int len) { if (len == 2) return 0; if (len == 3) return k == (n - 1) ? 1 : 0; if ((long long)(k - 2) * ((len - 1) / 2 - 1) < n - len - k + 2) return 0; return 1; } int main() { scanf( %d%d , &n, &k); int l = 2...
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18; const long long N = 100001; long long mod = 1000000007; long long min(long long a, long long b) { if (a < b) return a; else return b; } long long max(long long a, long long b) { if (a > b) return a; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } sort(a.begin(), a.end()); int curr_len = 0; int l = 0, r = a.size() - 1; while (l <= r) { if (a[l] - 1 < int(1e6) - a[r]) { ...
#include <bits/stdc++.h> using namespace std; const int MAX = 400; struct hh { double x, y; } a[MAX]; double jisuan(hh a, hh b, hh c) { double x1, y1, x2, y2; x1 = b.x - a.x; y1 = b.y - a.y; x2 = c.x - a.x; y2 = c.y - a.y; return (x1 * y2 - x2 * y1) / 2; } int main() { int ...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; cout << (n * 6 - 1) * k << endl; for (int i = 0; i < n; i++) cout << (i * 6 + 1) * k << << (i * 6 + 2) * k << << (i * 6 + 3) * k << << (i * 6 + 5) * k << endl; return 0; }
#include <bits/stdc++.h> using namespace std; default_random_engine gen(42); uniform_real_distribution<double> ran(0, 1); void vin(std::vector<int> &a) { for (auto &x : a) cin >> x; } void vout(std::vector<int> &a) { for (auto x : a) cout << x << ; cout << endl; } bool vm(array<pair<int, ...
#include <bits/stdc++.h> using namespace std; class Node { public: vector<int> kids; int pos[26]; int size; int depth; Node() { this->size = 0; memset(pos, 0, sizeof(pos)); } void push(int kid, int next) { this->kids.push_back(kid); pos[next] = this->kids.size(...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int C = 26; void add(int &x, int y) { x += y; while (x >= MOD) x -= MOD; while (x < 0) x += MOD; } int fix(int x) { while (x >= MOD) x -= MOD; while (x < 0) x += MOD; return x; } int pw(int a, int b) { ...
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, /STACK:64000000 ) const int MAXN = 1000002; int n, l, t; int a[MAXN << 1]; inline void init() { scanf( %d%d%d , &n, &l, &t); for (int i = 0; i < n; ++i) scanf( %d , &a[i]); sort(a, a + n); } int main() { init(); t...
#include <bits/stdc++.h> using namespace std; int main() { int i, j, k, a, b, c, n, t, f, d; string s, v; map<char, int> ma, sa; vector<int> vv; map<char, int>::iterator it, ki; cin >> s; f = 0; c = 0; for (j = 0; j < s.size(); j++) { if ((s[j] >= A && s[j] <= Z )) { ...
#include <bits/stdc++.h> using namespace std; int alpha[26] = {0}, dig[105] = {0}; long long int gcd(long long int a, long long int b) { if (a == 0) return b; return gcd(b % a, a); } long long int lcm(long long int a, long long int b) { return ((a * b) / gcd(a, b)); } bool isPrime(int n) { ...
#include <bits/stdc++.h> using namespace std; int n, u, v, N; vector<char> ans(1e5 + 5); vector<int> sub(1e5 + 5); vector<set<int> > adj(1e5 + 5); void dfs(int u, int par) { sub[u] = 1; for (int v : adj[u]) { if (v != par) { dfs(v, u); sub[u] += sub[v]; } } } int ...
#include <bits/stdc++.h> using namespace std; long long n, mod = 1e9 + 7ll, cont, maxi = 1000000000000ll, cont2, val[400005], ans, bestval = 1000000000000ll; pair<long long, long long> dp[400005], num, ft[400005]; pair<int, int> v[400005]; map<int, int> ind; vector<int> opz[400005], tmp; vo...
#include <bits/stdc++.h> using namespace std; string arr[9]; int moves1[4] = {2, 2, -2, -2}, moves2[4] = {2, -2, 2, -2}; int grid[2][9][9]; bool visited[9][9]; int incrementer; void canMeet(int row, int col, int nw) { for (int i = 0; i < 4; ++i) { if (row + moves1[i] >= 0 && row + moves1[i] < 8 ...
#include <bits/stdc++.h> using namespace std; int AR[1000000 + 7]; int main() { int cnt = 0, k; string s; cin >> k >> s; AR[0] = 1; int64_t r = 0; for (int i = 0; s[i] != 0 ; i++) { if (s[i] == 1 ) cnt++; if (cnt >= k) r += AR[cnt - k]; AR[cnt]++; } printf( %I6...
#include <bits/stdc++.h> using namespace std; long long int solve() { long long int n; cin >> n; vector<bool> dp(2 * n + 1, 0); vector<long long int> p(2 * n); vector<long long int> nums; long long int cover = 0; vector<long long int> inv(2 * n + 1); for (long long int j = 0; j < 2 *...
#include <bits/stdc++.h> using namespace std; int n; int s[220]; int d[220]; int sol[220]; vector<pair<int, int> > v; int main() { ios_base::sync_with_stdio(0); cin.tie(0); ; cin >> n; for (int(i) = (0); (i) < (n); (i)++) cin >> s[i] >> d[i]; for (int(i) = (0); (i) < (n); (i)++) { ...
#include <bits/stdc++.h> using namespace std; int n, seq[100005]; char s[2][55]; string a[100005], b[100005], cur; void solve() { scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %s %s , s[0], s[1]); a[i] = s[0]; b[i] = s[1]; } for (int i = 0; i < n; i++) { scanf( ...
#include <bits/stdc++.h> using namespace std; set<string> s; string v; map<string, bool> m; void rot(string x) { if (m[x] == 1) return; m[x] = 1; s.erase(x); string y = x; y[0] = x[1]; y[1] = x[2]; y[2] = x[3]; y[3] = x[0]; rot(y); y = x; y[1] = x[4]; y[4] = x[3...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int l = 1; int r = n; bool trn = 0; while (l <= r) { if (!trn) cout << l++; else cout << r--; cout << ; trn = !trn; } }
#include <bits/stdc++.h> using namespace std; const int M = 105; bool visit[M]; string second[M]; int main() { int n, m; scanf( %d %d , &n, &m); for (int i = 1; i <= n; i++) cin >> second[i]; vector<string> v; for (int i = 0; i < m; i++) { int x; scanf( %d , &x); visit[x]...
#include <bits/stdc++.h> using namespace std; inline long long mmul(long long a, long long b) { return (a * b) % 998244353; } inline long long madd(long long a, long long b) { return (a + b) % 998244353; } long long mpow(long long a, long long p) { if (p == 0) return 1; long long halfPow = mpow(a, p / 2...
#include <bits/stdc++.h> using namespace std; long long a[1009]; int cmp(int a, int b) { return a > b; } int main() { long long T; scanf( %lld , &T); while (T--) { long long n, sum = 0; scanf( %lld , &n); for (int i = 1; i <= n; i++) { scanf( %lld , &a[i]); sum = su...
#include <bits/stdc++.h> using namespace std; #define FAST ios_base::sync_with_stdio(false); cin.tie(NULL); #define prs(n) cout << fixed << setprecision(n) #define ll long long #define db double #define fo(i,m,n) for(int i = m; i <= n; i++) #define fob(i,m,n) for(int i ...
#include <bits/stdc++.h> using namespace std; char str[1000000]; int len; bool yes(char s[3], int ls, int le) { while (true) { start: int mid = le - ls - 1, i; if (le != len - 1) { if (s[0] != s[1]) return 0; } int c[3] = {0}, sd[2]; c[(s[1] - 0 ) ^ 1] += len - le ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100100, INFTY = 0x3f3f3f3f; int A[MAXN], B[MAXN]; vector<int> p[MAXN]; int posb[330]; int resp[330]; int main() { int N, M, S, E; posb[0] = 0; resp[0] = 0; for (int i = 1; i <= 300; i++) { posb[i] = MAXN; resp[i] = ...
#include <bits/stdc++.h> using namespace std; const int N = 100005; long long child[N], w[N], dp[N][65][3], ans[N][2]; void pre(int n) { for (int i = 0; i < n; i++) { dp[i][0][0] = w[i]; dp[i][0][2] = w[i]; dp[i][0][1] = child[i]; } for (int j = 1; j < 65; j++) { for (int i =...
#include <bits/stdc++.h> using namespace std; int T; signed long long S[101010], E[101010]; int win[101010], lose[101010]; int canwin(signed long long s, signed long long e) { if (s == e) return 0; if (s >= e) return 1; if (e % 2) { return !(s % 2); } else { if (s * 2 > e) return (...
#include <bits/stdc++.h> using namespace std; int main() { map<int, bool> hash; int p, n; bool has = false; cin >> p >> n; for (int i = 0; i < n; i++) { int x; cin >> x; x %= p; if (hash.count(x) && !has) { cout << i + 1 << endl; has = true; } else {...
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-10; const double PI = acos(-1.0); int dp[51][51][51]; int dfs(int n, int m, int k) { if (dp[n][m][k] >= 0) return dp[n][m][k]; if (k == 0 || n * m == k) return dp[n][m][k] = 0; dp[n][m][k] = 1e9; for (int j = 0; j <= k; ++j) {...
#include <bits/stdc++.h> using namespace std; int main() { int n; long long int d; cin >> n >> d; vector<int> check_days; int a[n]; long long int prefix_sum[n]; cin >> a[0]; if (a[0] == 0) check_days.push_back(0); prefix_sum[0] = a[0]; for (int i = 1; i < n; i++) { cin ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 5000; map<int, int> cntmap; long long ans; int arr[MAXN]; char s[MAXN]; int a, ln; void fillmap(int x) { cntmap[x]++; } void getans(int x) { if (x == 0) { if (a == 0) ans += (ln * (ln + 1)) / 2; } else if (a % x == 0) i...
#include <bits/stdc++.h> using namespace std; const long double PI = acos(-1.0); const long double EPS = 1e-12; const int MAXN = (int)1e5; const int INF = (int)2e9; int main() { int n, a[100]; scanf( %d , &n); for (int i = 0; i < n; ++i) scanf( %d , &a[i]); int ans = INF; for (int i = 0;...
#include <bits/stdc++.h> using namespace std; const int N = 20, Mod = 1e9 + 7; int pl, pr, vl, vr, k; long double p, q; vector<int> v; void count(int t) { int L, R; L = min(v[t], pr) - max(v[t - 1] + 1, pl); R = min(v[t + k] - 1, vr) - max(v[t + k - 1], vl); p += max(L + 1, 0) * 1ll * max(R ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; const int M = 5.1e6 + 5; const int B = 10; int n, q; int h[M]; int go[B + 1][N]; vector<int> dv[N]; int best[8][M]; int main() { for (int i = 2; i * i < M; i++) { if (!h[i]) { for (int j = i; j < M; j += i) h[j] =...
#include <bits/stdc++.h> using namespace std; const long long inf = 0x3f3f3f3f3f3f3f3fll; inline long long read() { long long x = 0, f = 1; char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) f = -1; c = getchar(); } while (c >= 0 && c <= 9 ) { x = (x << 1) + (x...
#include <bits/stdc++.h> using namespace std; int pr[2 * 100 * 1000 + 10]; int a[2 * 100 * 1000 + 10]; int main() { int max_n = 0; int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] > max_n) max_n = a[i]; } for (int i = 0; i <= max_n; i++) pr[i] = 1; for...
#include <bits/stdc++.h> using namespace std; map<double, int> Freq; int main() { double N; double W; scanf( %lf%lf , &N, &W); vector<double> vec; for (int i = 0; i < N * 2; i++) { double a; scanf( %lf , &a); vec.push_back(a); } sort((vec).begin(), (vec).end()); d...
#include <bits/stdc++.h> using namespace std; vector<int> edge[200002], col; int vis[200002]; queue<int> q; void bfs(int s) { vis[s] = 1; q.push(s); while (!q.empty()) { int x = q.front(); q.pop(); set<int> st; for (auto y : edge[x]) { if (vis[y]) { st.ins...
#include <bits/stdc++.h> using namespace std; struct node { int val, id; friend bool operator<(node a, node b) { return a.id > b.id; } }; int main() { int t, m, n; struct node p; while (~scanf( %d %d , &m, &n)) { priority_queue<node> a; priority_queue<node> b; int id = 0; ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5; const int MAXM = 2e5; int NV, NH; int V[MAXN]; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> NV >> NH; for (int i = 0; i < NV; i++) { cin >> V[i]; } priority_queue<int, vector<int>, gre...
#include <bits/stdc++.h> using namespace std; const long double EPS = 1e-3; const int INF = (long double)(1e9); const long long mod = (int)(1e+9 + 7); const int N = (int)(2e3); int days_month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; long long ekn; long long inverse; long long expo(long ...
#include <bits/stdc++.h> using namespace std; const int N = 2 * (int)1e5 + 100; int n, k; char a[N]; int main() { scanf( %d %d , &n, &k); scanf( %s , a); int tmp = 0, result = 0, ans = 0; for (int i = 0; i < 26; i++) { char ch = a + i; tmp = 0; result = 0; for (int j ...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 110; const int INF = 1 << 28; const double EPS = 1e-9; const double PI = 3.14159265358979; int n, d; int a[MAX_N]; int x[MAX_N], y[MAX_N]; int g[MAX_N][MAX_N]; int main() { cin >> n >> d; for (int i = (1); i < (n - 1); i++) cin ...
#include <bits/stdc++.h> using namespace std; map<long long, long long> Map; void modify(long long x, long long y) { map<long long, long long>::iterator it; long long c; scanf( %I64d , &c); while (x != y) { if (x < y) swap(x, y); it = Map.find(x); if (it != Map.end()) it-...
#include <bits/stdc++.h> int a[1000005]; double tt; int main() { int n, i, t; double vb, vs, x, y, d; while (scanf( %d %lf %lf , &n, &vb, &vs) != EOF) { t = 2; for (i = 1; i <= n; i++) { scanf( %d , &a[i]); } scanf( %lf %lf , &x, &y); d = a[2] / vb + sqrt((x - a[2...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; int sumOfDigits(int n) { int ans = 0; if (n <= 9) return n; while (n) { ans += n % 10; n /= 10; } return ans; } int main() { cin.tie(NULL); ios_base::sync_with_stdio(false); int a; cin ...
#include <bits/stdc++.h> using namespace std; const long long maxn = 4e5 + 10; const long long mod = 998244353; const long long inf = 1e18 + 10; const long long Log = 21; long long n, m, k; long long pw(long long a, long long b) { if (b == 0) return 1; long long x = pw(a, b / 2); x = (x * x) %...
#pragma GCC optimize( -Ofast , -funroll-all-loops ) #pragma GCC optimize(2) #pragma GCC optimize(3, Ofast , inline ) #include<bits/stdc++.h> using namespace std; typedef long long ll; int _; int n; int a[30010]; void solve(){ cin >> _; while(_--){ cin >> n; int cn...
#include <bits/stdc++.h> using namespace std; const int maxn = 200005; int n, a[maxn], total; void solve() { vector<int> ans; for (int i = 1; i <= n; i++) { if (a[i] * n == total) ans.push_back(i); } cout << (int)ans.size() << endl; for (int i = 0; i < ans.size(); i++) { if (i) p...
#include <bits/stdc++.h> using namespace std; long long arr[1000000], arr1[1000000], cnt2[1000000]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, k, i, j, x, y, z, ans, a, b, c; cin >> n >> k; for (i = 1; i <= n; i++) { cin >> arr[i]; } for (i = 1; i ...
#include <bits/stdc++.h> using namespace std; const int N = 500010; struct edge { int nxt, t; } e[N * 3]; int head[N], edge_cnt; void add_edge(int x, int y) { e[edge_cnt] = (edge){head[x], y}; head[x] = edge_cnt++; } int dfn[N], low[N], Tar_cnt, stk[N], stk_top, loop_cnt, ID[N], P[N], tot, s...
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; int n, q, a[300500], dp[300500][30], best[300500][30], last[30]; int f(int x, int bt) { if (a[x] & (1 << bt)) return x; if (dp[x][bt] != -1) return dp[x][bt]; int mn = 1e9; for (int i = 0; i <= 27; i++) { if (a[...
#include <bits/stdc++.h> using namespace std; const int OO = (int)2e9; const double PI = 2 * acos(0.0); const double EPS = 1e-9; int dcmp(double a, double b) { return fabs(a - b) <= EPS ? 0 : a > b ? 1 : 2; } int DI[] = {-1, 0, 1, 0, 1, -1, -1, 1}; int DJ[] = {0, 1, 0, -1, 1, -1, 1, -1}; map<int, long l...
#include <bits/stdc++.h> using namespace std; priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > que; stringstream ssin; const long long LINF = 0x7fffffffffffffffll; const int N = 4e5 + 5, M = 4e5 + 5, mod = 1e9 + 7, INF = 0x3f3f3f3f; int n, idx, sum; ...
#include <bits/stdc++.h> using namespace std; long long inv(long long a, long long mod) { long long b = mod, p = 1, q = 0; while (b) { long long c = a / b, d = a; a = b; b = d % b; d = p; p = q; q = d - c * q; } return (p + mod) % mod; } int fs = 505050; vec...
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 20, MAX2 = 1e7 + 10; int an[MAX], n, x; bool primes[MAX2]; void seive(long long n) { for (long long i = 2; i <= n; i++) primes[i] = 1; for (long long i = 2; i <= n; i++) { if (primes[i] == 1) { for (long long j = i * i; ...
#include <bits/stdc++.h> using namespace std; template <class T> inline T lcm(T a, T b) { return a / gcd(a, b) * b; } long long read_ll() { char c = getchar(); while ((c < 0 || c > 9 ) && c != - ) c = getchar(); long long ret = 0; int neg = 0; if (c == - ) neg = 1, c = getchar(); ...
#include <bits/stdc++.h> using namespace std; const int N = 2010; int n, a[N], p[N], pos[N]; vector<int> c[26], ans; string s, t; void add(int x) { if (0 < x) { ans.push_back(x); } vector<int> nw; for (int i = n - 1; i >= n - x; --i) { nw.push_back(p[i]); } for (int i = n...
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; int main() { int n, m; cin >> n >> m; vector<int> session(n); vector<vector<int> > s2d(m); for (int i = 0; i < n; i++) { cin >> session[i]; if (session[i]) s2d[session[i] - 1].push_back(i); } vector<i...
#include <bits/stdc++.h> using namespace std; int n; int f[500000], g[500000], a[500000]; map<long long, int> mp; struct bit1 { int s[500000]; int num; void add(int x, int z) { for (int i = x; i <= num; i += (i & -i)) s[i] = max(s[i], z); } int ask(int x) { int tmp = 0; f...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 256; const char nxt = n ; inline void in(string Q) { Q += .in ; freopen(Q.c_str(), r , stdin); } inline void out(string Q) { Q += .out ; freopen(Q.c_str(), w , stdout); } inline void open_file(string Q) { in(Q...
#include <bits/stdc++.h> using namespace std; char BUFFER[100000 + 5]; bool readn(int &n) { return scanf( %d , &n) == 1; } bool readl(long long &n) { return scanf( %I64d , &n) == 1; } bool readd(double &n) { return scanf( %lf , &n) == 1; } bool reads(string &s) { s = ; int n = scanf( %s , BUFFER);...
#include <bits/stdc++.h> using namespace std; signed main() { long long n; cin >> n; vector<long long> a(n), b(n); for (long long i = 0; i < n; ++i) cin >> a[i]; for (long long i = 0; i < n; ++i) cin >> b[i]; if (n == 1) { if (a[0] == b[0]) cout << SMALL n << 0; else ...
#include <bits/stdc++.h> using namespace std; int n, p[200009], b[200009], ans, u[200009], sum; void dfs(int v) { if (u[v] == 1) { ans++; return; } u[v] = 1; dfs(p[v]); } int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> p[i]; for (int i = 1; i <= n; i++) cin >...
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { int h1, a1, c1; int h2, a2; cin >> h1 >> a1 >> c1; cin >> h2 >> a2; int th1 = h1; int th2 = h2; int count = 0; while (th2 > 0) { if (th1 > a2 || th2 - a1 <= 0) { count++; th2 ...
#include <bits/stdc++.h> using namespace std; int main() { int t, i, j, curr, n; cin >> curr >> n; int arr[curr + 1]; int temp; arr[0] = 1; int count = curr - 1; for (i = 1; i <= curr; i++) arr[i] = 0; for (i = 0; i < n; i++) { cin >> temp; if (temp == 1) { int a,...
#include <bits/stdc++.h> using namespace std; int a[10001]; int best = 100000000; int main() { int n, m, d; scanf( %d %d %d , &n, &m, &d); scanf( %d , &a[0]); int c = a[0] % d; int lll = n * m; for (int i = 1; i < lll; i++) { scanf( %d , &a[i]); if (a[i] % d != c) { c...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; pair<int, int> s[n + 1]; for (int a = 0; a < n; a++) { int x, y; cin >> x >> y; s[a] = make_pair(max(x - y, 1), min(x + y, m)); } sort(s, s + n); int dp[m + 1]; dp[m] = 0; for (i...
#include <bits/stdc++.h> using namespace std; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); const int N = 3e5; int n, a[N + 1], b[N + 1], c[N + 1]; int dp[N + 1]; vector<int> g1[N + 1], g2[N + 1]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; fo...
#include <bits/stdc++.h> using namespace std; int dx[] = {-1, 0, 0, 1}; int dy[] = {0, -1, 1, 0}; int dx1[] = {-1, -1, -1, 0, 0, 0, 1, 1, 1}; int dy1[] = {-1, 0, 1, -1, 0, 1, -1, 0, 1}; const double eps = 1e-9; const int inf = 2000000000; const long long int infLL = 9000000000000000000; const long lon...
#include <bits/stdc++.h> using namespace std; void __print(int x) { cout << x; } void __print(long x) { cout << x; } void __print(long long x) { cout << x; } void __print(unsigned x) { cout << x; } void __print(unsigned long x) { cout << x; } void __print(unsigned long long x) { cout << x; } void __prin...
#include <bits/stdc++.h> using namespace std; int a[101]; int main() { bool f = false; int n, counter = 1; long long ans = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] == 0 && f) counter++; if (a[i] == 1 && !f) f = true, ans = 1; else if (a[i...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int tt; cin >> tt; while (tt--) { int n; cin >> n; vector<int> a(n + 1); for (int i = 1; i <= n; i++) { cin >> a[i]; } int lo = 1, hi = n; while (...
#include <bits/stdc++.h> using namespace std; const int N = 4e5 + 9; vector<int> ans[N]; vector<char> arr; int k, n, q, a, hash[N][50], ar[N], s; char c; string str; bool flag; int main() { cin >> k; cin >> str; int n = str.size(); for (int i = 1; i <= k; i++) for (int j = 0; j <...
#include <bits/stdc++.h> using namespace std; const int N = (int)1e5 + 7; const long long INF = (long long)1e18; int n; int m; vector<pair<int, int>> g[N]; long long dist[N]; int par[N]; int t[N]; int root(int x) { if (t[x] == x) { return x; } else { return t[x] = root(t[x]); ...
#include <bits/stdc++.h> const long long mod = 1e9 + 9; using namespace std; const long long N = 105; long long vis[N], l[N], who[N], n, m; void fail() { cout << -1 n ; exit(0); } int32_t main() { cin >> n >> m; for (long long i = 1; i <= m; i++) cin >> l[i]; long long cur = l[1]; ...
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, a, b, i, j, ans = 999999; cin >> n >> m >> i >> j >> a >> b; if ((i == 1 && j == 1) || (i == 1 && j == m) || (i == n && j == 1) || (i == n && j == m)) ans = 0; else if ((a + i <= n || i - a >= 1) && (j - b >= 1 ...
#include <bits/stdc++.h> using namespace std; const int maxn = 100086; int z[maxn], n, m, num, order[maxn][2], last[maxn], ans[maxn], len, in[maxn]; bool flag, ok[maxn]; char s[2]; int main() { scanf( %d %d , &n, &m); for (int i = 1; i <= m; i++) { scanf( %s , s); scanf( %d , &num); ...
#include <bits/stdc++.h> using namespace std; vector<int> g[1002]; bool vis[1002]; bool my[1002], chen[1002]; int dfs(int n) { if (my[n] == 1) return n; vis[n] = 1; for (int i = 0; i < g[n].size(); i++) { int v = g[n][i]; if (!vis[v]) { int ans = dfs(v); if (ans != -1) ...
#include <bits/stdc++.h> using namespace std; int main() { long long int sasha_chiz, masha_chiz, coconut_price, sasha_buy_co, masha_buy_co, sum_buy_co, given_chiz = 0; cin >> sasha_chiz >> masha_chiz >> coconut_price; sasha_buy_co = sasha_chiz / coconut_price; masha_buy_co = masha_chiz / coc...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; string s; long long nb, nc, ns, push_back, pc, ps, money, cntb, cntc, cnts, l, r, mid, mb, ms, mc; int main() { ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin >> s >> nb >> ns >> nc >> push_back >> p...
#include <bits/stdc++.h> using namespace std; int a[100005]; int main() { int i, n; cin >> n; for (i = 1; i <= n - 1; i++) cin >> a[i]; sort(a + 1, a + n); for (i = 1; i <= n; i++) if (a[i] != i) break; cout << i << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = int(1e6) + 50, P = int(1e9) + 7; long long fac_NESC[N], rev[N], pow_NESC[N], revfac[N], w; int k; inline void inc(long long &x, long long y) { x = (x + y) % P; } inline long long M(long long x, long long y) { return x * y % P; } inline long long ...
#include <bits/stdc++.h> using namespace std; void read(long long &x) { x = 0; char c = getchar(); long long f = 1; while (c < 0 || c > 9 ) { if (c == - ) f = -f; c = getchar(); } while (c >= 0 && c <= 9 ) { x = (x << 3) + (x << 1) + c - 0 ; c = getchar(); ...
#include <bits/stdc++.h> using namespace std; int read() { int x = 0; bool flg = false; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == - ) flg = true; for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch ^ 48); return flg ? -x : x; } int n; stru...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; string s; int pre[N], nxt0[N], now = 100002; int ans[N]; int n; void init() { vector<int> v; for (int i = n - 1; i >= 1; i--) { int p = s[i] - 0 ; int pos = upper_bound(v.begin(), v.end(), -p) - v.begin(); if (...
#include <bits/stdc++.h> using namespace std; using ll = long long; const int mod = 1e9 + 7; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; vector<int> a(n); for (int &elem : a) cin >> elem; vector<vector<i...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, cnt11 = 0, cnt10 = 0, cnt01 = 0; string s, t; cin >> n >> s >> t; for (int i = 0; i < 2 * n; ++i) { if (s[i] == 1 && t[i] == 1 ) ++cnt11; else if (s[i] == 1 ) ...
#include <bits/stdc++.h> using namespace std; int n, m, k; int n1, n2, n3; int c[510]; int sc[510]; int pai[100010]; int type[100010]; int peso[100010]; int dp[510][510]; vector<pair<pair<int, int>, int> > edges; int find(int i) { return pai[i] = (pai[i] == i) ? i : find(pai[i]); } void join(int...
#include <bits/stdc++.h> using namespace std; int sum, i, j, a[5][5], n, b[20]; int check() { int res = 0; int i, j, nowsum; for (i = 0; i < n; i++) for (j = 0; j < n; j++) { a[i][j] = b[i * n + j]; } for (i = 0; i < n; i++) { nowsum = 0; for (j = 0; j < n; j++) now...
#include <bits/stdc++.h> using namespace std; const int N = int(3002), mod = int(1e9) + 7; char second[N][N]; int n, m; long long dp1[N][N], dp2[N][N], a, b, c, d; bool used[N][N]; inline long long dp(int x, int y) { if (x <= 0 || y <= 0) return 0; if (second[x][y] == # ) return 0; if (x == 1...
#include <bits/stdc++.h> using namespace std; const int M = 1000000007; struct mint { int val = 0; mint() {} mint(int a) : val(a) { while (val < 0) { val += M; } while (val >= M) { val -= M; } } mint(long long a) : val(a % M) { if (v...
#include <bits/stdc++.h> using namespace std; const int maxn = 1200005; const int OO = 0x3f3f3f3; int vis[maxn]; vector<int> p; int N = 1200000; void find_prime() { p.clear(); memset(vis, 0, sizeof(vis)); for (int i = 2; i <= N; i++) if (!vis[i]) for (int j = i * 2; j <= N; j += ...
#include <bits/stdc++.h> using namespace std; int main() { int n, k, i, j; while (~scanf( %d%d , &n, &k)) { if (n <= 2 * k) { printf( -1 n ); continue; } else { printf( %d n , n * k); for (i = 1; i <= n; i++) { for (j = 1; j <= k; j++) { if (...