func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const int maxn = (int)(1e5) + 5; int l[maxn], r[maxn]; int main() { ios::sync_with_stdio(false); int n; cin >> n; for (int i = 1; i <= n; ++i) cin >> l[i] >> r[i]; sort(l + 1, l + n + 1); sort(r + 1, r + n + 1); long long ret = n; for...
#include <bits/stdc++.h> using namespace std; ostream &operator<<(ostream &out, string str) { for (char c : str) out << c; return out; } template <class L, class R> ostream &operator<<(ostream &out, pair<L, R> p) { return out << ( << p.first << , << p.second << ) ; } template <class T> ...
#include <bits/stdc++.h> char str[100005], ans[100005]; int out[100005]; struct Edge { int link[400005], next[400005], son[400005], l; void clear() { l = 0; memset(son, 0, sizeof(son)); } void addedge(int x, int y) { link[++l] = y; next[l] = son[x]; son[x] = l; } ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n][4]; int l = 0; char l0[3], l1[3], l2[3]; for (int i = 0; i < n; i++) { cin >> l0 >> l1; for (int j = 0; j <= l; j++) { if (j == l) { a[j][0] = l0[0]; a[j][1] = l0[1]; ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0), cin.tie(0); int arr[4]; for (int i = 0; i < (int)4; i++) cin >> arr[i]; sort(arr, arr + 4); bool ok = 0; for (int mask = 0; mask < (1 << 4); mask++) { int sum1 = 0; int sum2 = 0; for (int bi...
#include <bits/stdc++.h> inline int read() { int s = 0, w = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) w = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) s = s * 10 + ch - 0 , ch = getchar(); return s * w; } inline long long readll() { long...
#include <bits/stdc++.h> using namespace std; int a[40005]; int main() { int i, j; int n, m, x; while (scanf( %d %d , &n, &m) != EOF) { if ((n == 1 || n == 2) && m == 1) { printf( -1 n ); continue; } if (n < (2 * m + 1)) { if (m == 1) { printf( %d n ...
#include <bits/stdc++.h> using namespace std; bool collinear(int x1, int y1, int x2, int y2, int x3, int y3) { return (y1 - y2) * (x1 - x3) == (y1 - y3) * (x1 - x2); } int main() { int n, x, y; cin >> n; vector<pair<int, int> > points; for (int i = 0; i < n; i++) { cin >> x >> y; ...
#include <bits/stdc++.h> using namespace std; int Get() { char c; while (c = getchar(), c < 0 || c > 9 ) ; int X = c - 48; while (c = getchar(), c >= 0 && c <= 9 ) X = X * 10 + c - 48; return X; } int Pow(int A, int B, int Mod) { if (!B) return 1; int T = Pow((long long)A...
#include <bits/stdc++.h> using namespace std; int par[20][100001], dep[100001], lg[100001], sizes[100001]; bool isParent[100001]; vector<int> adj[100001]; void dfs(int u) { for (int i = 0; i < adj[u].size(); i++) { int v = adj[u][i]; if (v != par[0][u]) { isParent[u] = true; de...
#include <bits/stdc++.h> using namespace std; const int maxn = 300100; int head[maxn], nxt[maxn << 1], ver[maxn << 1], tot; void addedge(int a, int b) { nxt[++tot] = head[a]; ver[tot] = b; head[a] = tot; nxt[++tot] = head[b]; ver[tot] = a; head[b] = tot; } int f[maxn], getlen; void...
#include <bits/stdc++.h> using namespace std; int arr[5002]; int main() { int n, i; scanf( %d , &n); if (n <= 2) { printf( 1 n1 n ); return 0; } if (n == 3) { printf( 2 n1 3 n ); return 0; } int curr = (n & 1) ? n : n - 1; for (i = 0; i < n; i++) { if ...
#include <bits/stdc++.h> using namespace std; long long n, i, m = 1000000007, a, b; int main() { cin >> n; a = 1, b = 1; for (i = 0; i < 3 * n; i++) a = (a * 3) % m; for (i = 0; i < n; i++) b = (b * 7) % m; cout << (a - b + m) % m; return 0; }
#include <bits/stdc++.h> const int mxn = 1e5; int cost[mxn][3], go[mxn][2], deg[mxn], path[mxn]; int color[mxn]; long long cc[3][3]; int main() { int n, u, a, b, c = 0; scanf( %d , &n); for (int j = 0; j < 3; ++j) for (int i = 1; i <= n; ++i) scanf( %d , &cost[i][j]); for (int i = 1; i <...
#include <bits/stdc++.h> using namespace std; map<string, int> ma; map<string, int>::iterator p; long i, n, m; double ex, k; int main() { cin >> n >> m >> k; string st; for (i = 1; i <= n; i++) { cin >> st >> ex; ma[st] = (int)(ex * k + 1e-9); if (ma[st] < 100) ma.erase(st); ...
#include <bits/stdc++.h> using namespace std; long long cc = 1e9 + 7; map<int, int> A; map<int, int>::iterator itr, it; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { string s; cin >> s; int nn = s.size(); vector<int> p; for (int j = 0; j < nn; j++) { ...
#include<bits/stdc++.h> using namespace std; typedef long long int ll; #define endl n bool powerOf2(ll x){ return x && (!(x&(x-1))); } void solve(){ ll u, v; cin>>u>>v; if(v<u || (powerOf2(u) && !powerOf2(v))){ cout<< No n ; ...
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 7; int clr[MAX] = {0}, vis[MAX] = {0}, res = 0; vector<int> adj[MAX]; void dfs(int u, int p, int clr_p) { int f = 0; if (!vis[clr[u]]) { f = 1; vis[clr[u]] = 1; res++; } else if (p != -1 && clr_p != clr[u]) ...
#include <bits/stdc++.h> using namespace std; int n, m; vector<pair<int, int> > e; bool check(vector<pair<int, int> > res) { if (res.size() > (n + m + 1) / 2) return false; vector<int> d(n, 0), d2(n, 0); for (pair<int, int> i : res) { d[--i.first]++; d[--i.second]++; } for (pair<...
#include <bits/stdc++.h> using namespace std; long long input() { long long x; scanf( %lld , &x); return x; } const int inf = 1e9; int clamp(int a, int l, int r) { if (a < l) a = l; if (a > r) a = r; return a; } int main() { int n, m; cin >> n >> m; vector<int> pos(1010...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5; int m; int num[MAXN + 10]; int tree[4 * MAXN + 10]; int prop[4 * MAXN + 10]; void upd(int cn, int b, int e, int l, int r, int x, int p = 0) { if (l <= b && e <= r) { tree[cn] += x + p; prop[cn] += x + p; return; ...
#include <bits/stdc++.h> using namespace std; const int INF = (int)2e9; const int mod = (int)1e9 + 123; const int N = (int)1e6 + 10; const long long LLINF = (long long)3e18 + 10; const long double pi = acos(-1); template <typename T1, typename T2> bool umin(T1 &x, T2 y) { if (x > y) return x = y, tr...
#include <bits/stdc++.h> using namespace std; const int N = 2e5; int n, m, k, a[N][5]; int sparse[5][17][N]; vector<int> last(5, 0); void build(int u) { for (int i = 0; i < n; i++) sparse[u][0][i] = a[i][u]; for (int j = 1; j <= 17; j++) for (int i = 0; i + (1 << (j - 1)) < n; i++) spa...
#include <bits/stdc++.h> using namespace std; struct pi { int x, y, t; double p; } pp[1005]; double dp[1005]; int cmp(pi a, pi b) { return a.t < b.t; } double get(int a, int b) { return sqrt(pow(pp[a].x - pp[b].x, 2.0) + pow(pp[a].y - pp[b].y, 2.0)); } int main() { int i, j, n; cin >...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7, mod2 = 998244353; unsigned long long base = 131; const int w = 1e7 + 5; long long m, n; int main() { long long i, j, k, t, qqq; cin >> n; string a, b; cin >> a >> b; int flag = 0; for (i = a.size() - 1; i >=...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; const int maxm = 1e5 + 10; const int INF = 0x3f3f3f3f; const long long LINF = 3e17 + 1; const int mod = 998244353; int n, m, eid, sz; inline int read() { register int x = 0, f = 1; char ch = getchar(); while (!isdigit(c...
#include <bits/stdc++.h> using namespace std; const long long inf = 1LL << 28; const long long mod = 1LL; int arr[3 * 100010]; int main() { int n, k, i, ans, flag, j; while (scanf( %d %d , &n, &k) == 2) { for (i = 0; i < n; i++) { scanf( %d , &arr[i]); } sort(arr, arr + n); ...
#include <bits/stdc++.h> const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; const char dz[4] = { R , U , L , D }; int n, m, bs, i, j, xa, ya, xb, yb, xx, yy, dd, d[1010], a[1010][1010], g[1010], c[1010], x[1010], y[1010], u[1010], f[1010], it; long long cnt, cur; char s[5]; int mai...
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 7; const long long INF = 1e18; const long long mod = 1e9 + 7; int n; int a; int b; int mxa; int mxb; int main() { ios_base::sync_with_stdio(0); cin >> n >> a >> b; mxb = b; for (int i = 1; i <= n; i++) { in...
#include <bits/stdc++.h> int prm[20] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53}; long long n, ans; void find(int k, long long cnt, long long sum) { int i; if (sum > n) return; if (sum == n && cnt < ans) ans = cnt; for (i = 1; i <= 63; i++) { if (ans / prm[k] < cnt) break;...
#include <bits/stdc++.h> using namespace std; int v[4000 + 10], d[4000 + 10], p[4000 + 10]; int result[4000 + 10], check[1000000 + 10]; int main() { int n, a, b; scanf( %d , &n); for (int i = 0; i < n; i++) { cin >> v[i] >> d[i] >> p[i]; } int lost = 0; for (int i = 0; i < n; i++) ...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 7; const int inf = 0x3f3f3f3f; const long long INF = 0x3f3f3f3f3f3f3f3f; const int mod = 1e9 + 7; const double eps = 1e-8; const double PI = acos(-1); int n; long long h[N], dp[N][2]; int main() { scanf( %d , &n); for (int i =...
#include <bits/stdc++.h> using namespace std; const double PI = 4 * atan(1); int T, N; long long X[100013], Y[100013], Z[100013]; long long xmi, xma, ymi, yma, zmi, zma, smi, sma; long long ansx, ansy, ansz; inline bool is(long long x, int p) { return (((x % 2) + 2) % 2) == p; } bool go(long long d) { ...
#include <bits/stdc++.h> using namespace std; int arr[4]; int aux[100010]; int next(int x) { if (x == 0) { if (arr[1] > 0) return 1; else return -1; } if (x == 1) { if (arr[0] > 0) return 0; else if (arr[2] > 0) return 2; else ret...
#include <bits/stdc++.h> using namespace std; const int INF = 1 << 25; const long long LL_INF = 1ll << 61; int main() { int n; scanf( %d , &n); vector<int> count(3, 0); for (int i = 0; i < n; i++) { int num; scanf( %d , &num); count[num]++; } if (count[1] == 0) { ...
#include <bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define ppb pop_back #define pf push_front #define ppf pop_front #define all(x) (x).begin(),(x).end() #define uniq(v) (v)....
#include <bits/stdc++.h> using namespace std; template <typename... As> struct tpl : public std::tuple<As...> { using std::tuple<As...>::tuple; tpl() {} tpl(std::tuple<As...> const& b) { std::tuple<As...>::operator=(b); } template <typename T = tuple<As...>> typename tuple_element<0, T>::type ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; int t; cin >> t; while (t--) { int n, g[105], sum = 0, s = 0; cin >> n; for (register int i = 0; i < n; i++) cin >> g[i], g[i] == 0 ? sum++, g[i]++...
#include <bits/stdc++.h> using namespace std; int main() { cin.sync_with_stdio(0); cin.tie(0); int n; cin >> n; int setb = 0; int t[1000][1000]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> t[i][j]; } } int q; cin >> q; for (int i...
#include <bits/stdc++.h> using namespace std; stack<int> stk; vector<pair<int, int> > edge[500010]; vector<pair<int, int> > w[500010]; int a[500010], b[500010], c[500010], fa[500010], rk[500010]; bool ans[500010]; int n, m, q; int Find(int x) { while (x != fa[x]) x = fa[x]; return x; } void ...
#include <bits/stdc++.h> using namespace std; char board[3][3]; int cross, nought; bool cross_win() { if (board[0][0] == X && board[0][1] == X && board[0][2] == X ) return true; if (board[1][0] == X && board[1][1] == X && board[1][2] == X ) return true; if (board[2][0] == X &...
#include <bits/stdc++.h> using namespace std; double a, d, l, e; int n; int main() { scanf( %lf %lf , &a, &d); scanf( %d , &n); l = n * d + .5; e = d; double pos = 0, fa = 4 * a; for (int i = 0; i < n; i++) { pos = fmod(pos + e, fa); if (pos <= a) printf( %.10lf %.10l...
#include <bits/stdc++.h> using namespace std; void FAST_IO(string filein = , string fileout = , string fileerr = ) { if (fopen(filein.c_str(), r )) { freopen(filein.c_str(), r , stdin); freopen(fileout.c_str(), w , stdout); } cin.tie(0), cout.tie(0)->sync_with_stdio(0); } void H...
#include <bits/stdc++.h> using namespace std; vector<int> adj[1000005]; char op[1000005]; bool A[1000005][2], val[1000005]; void dfs(int u) { if (op[u] == I ) return; dfs(adj[u][0]); if (op[u] == N ) { val[u] = !val[adj[u][0]]; return; } dfs(adj[u][1]); if (op[u] == A ) ...
#include<bits/stdc++.h> using namespace std; int T,n,m,flag,k,a[110],b[110],ans[300]; int main() { scanf( %d ,&T); while (T--) { scanf( %d%d%d ,&k,&n,&m); for (int i=1;i<=n;i++) scanf( %d ,&a[i]); for (int i=1;i<=m;i++) scanf( %d ,&b[i]); flag=1; for (int i=1,j=1;i<=n||j<=m;) { if...
#include <bits/stdc++.h> using namespace std; bool X[1000001], vis[1000001]; int main() { int n; while (scanf( %d , &n) == 1) { vector<int> V; int x; for (int i = 0; i < n; i++) { scanf( %d , &x); X[x] = true; V.push_back(x); } deque<int> Q; for ...
#include <bits/stdc++.h> using namespace std; int a[100001], parent[100001], sz[100001], p[(100001 / 320 + 1)], mx[(100001 / 320 + 1)], h[(100001 / 320 + 1)][100001]; bool isBlockDirty[(100001 / 320 + 1)]; int Find(int i) { if (i == parent[i]) return i; else { parent[i] = Find(parent[i...
#include <bits/stdc++.h> using namespace std; long long int n, h, m, k; vector<long long int> freight; int workingTrains(long long int time) { if (time - k >= 0) { return n - (lower_bound(freight.begin(), freight.end(), time) - upper_bound(freight.begin(), freight.end(), time - k)); ...
#include <bits/stdc++.h> using namespace std; void optimizeIO() { ios_base::sync_with_stdio(false); cin.tie(NULL); } int main() { optimizeIO(); int n, t; cin >> n >> t; string s1, s2, s3; cin >> s1 >> s2; s3 = s1; int sa = 0; vector<int> v, v2; for (typeof(n) i = 0; i...
#include <bits/stdc++.h> using namespace std; const int N = 100100; const int BIT = 17; int n, m; int P[N]; int pot2[33]; set<int> S[18]; set<int>::iterator it; long long sol; inline int find(int bit, int pos) { if (S[bit].empty()) return 0; it = S[bit].lower_bound(pos); if (it == S[bit]...
#include <bits/stdc++.h> using namespace std; const int Maxn = 65536 + 10; int n, deg[Maxn], s[Maxn]; vector<pair<int, int> > ans; set<pair<int, int> > mys; int main() { scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d%d , &deg[i], &s[i]); mys.insert(make_pair(deg[i], i)); } ...
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; const double eps = 1e-10; int main() { int n; scanf( %d , &n); int feet, inches; inches = n / 3; if (n - inches * 3 > 1) inches++; feet = inches / 12; inches %= 12; cout << feet << << inches << endl; ...
#include <bits/stdc++.h> using namespace std; const int N = 100005, mod = 1e9 + 7, M = 100; int n, m, k; int q[N][6], a[N][6], r[6], f[6], e[6]; inline void inq(int id, int x) { while (f[id] <= e[id] && a[x][id] >= a[q[e[id]][id]][id]) e[id]--; q[++e[id]][id] = x; } inline void outq(int id, int x)...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1555; const int dx[4] = {0, 0, 1, -1}; const int dy[4] = {1, -1, 0, 0}; int n, m; template <typename T> inline T mod(const T& lhs, const T& rhs) { T _lhs = lhs; while (_lhs < 0) { _lhs += rhs; } return _lhs % rhs; } c...
#include <bits/stdc++.h> using namespace std; template <class T> T MAX(T a, T b) { return a > b ? a : b; } template <class T> T MIN(T a, T b) { return a < b ? a : b; } template <class T1> void deb(T1 p) { cout << Debugging: << p << endl; } template <class T1, class T2> void deb(T1...
#include <bits/stdc++.h> #pragma GCC optimize( inline , 2) using namespace std; const long long N = 5005; const long long inf = 1e18; long long n, hd[N], nxt[N << 1], to[N << 1], w[N << 1], tot = 1; long long sz[N << 1]; long long aa[N << 1], eg[N << 1]; void add(long long a, long long b, long long c) {...
#include <bits/stdc++.h> using namespace std; int n, m, y, Y, it = 1, x1[100001], x2[100001], d[100001], u[100001]; int dist(int x, int y) { return abs(x - y); } int main() { scanf( %d%d%d%d , &n, &m, &y, &Y); for (int i = 1; i <= n; i++) scanf( %d , &x1[i]); for (int i = 1; i <= m; i++) { sca...
#include <iostream> #include <algorithm> using namespace std; typedef long long ll; const ll mod = 1e9+7; const int SZ = 1e5+10; ll fact[SZ]; void buildFact(){ fact[0] = 1; for(int i = 1; i < SZ; i++){ fact[i] = fact[i-1] * i; fact[i] %= mod; } } ll powe(ll ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); long long N, P; cin >> N >> P; vector<long long> l(N), r(N); for (long long i = 0; i < N; ++i) cin >> l[i] >> r[i]; double exp_val = 0; for (long long i = 0; i < N; ++i) { l...
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; int a[100010], b[100010]; int main() { int n, k, m; scanf( %d%d , &n, &k); int val = 1; for (int i = 0; i < k; i++) val *= 10; m = n / k; for (int i = 0; i < m; i++) scanf( %d , &a[i]); for (int i = 0; i < m; i...
#include <bits/stdc++.h> int main() { int n, s, i, a, b, t, j, v, f, c; int candy = -1, d; scanf( %d%d , &n, &s); s = s * 100; while (n--) { scanf( %d%d , &a, &b); d = (a * 100) + b; if (d <= s) { f = s - d; c = f % 100; if (c > candy) candy = c; } ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 3; const int M = 26; char s1[N], s2[N]; int z1[N][M], z2[N][M]; int n; bool check(int l1, int r1, int l2, int r2) { int l, i, t1, t2; for (i = 0; i < M; ++i) { t1 = z1[r1 - 1][i]; if (l1) t1 -= z1[l1 - 1][i]; t2 = ...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int N = 1e6 + 5; int dp[N][2]; int main() { int n, x; scanf( %d , &n); dp[0][0] = dp[0][1] = 1; for (int i = 1; i <= n; ++i) { scanf( %d , &x); for (int j = 1; j * j <= x; ++j) { if (x % j) continu...
#include <bits/stdc++.h> using namespace std; int n, ans[110]; int main() { scanf( %d , &n); for (int i = n; i > 0; i--) { printf( ? ); for (int j = 1; j < n; j++) printf( 1 ); printf( %d n , i); fflush(stdout); int k; scanf( %d , &k); if (k) { ans[n] = ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; bool o[100]; int n, k1, k2; int a[100]; int b[100]; for (int j = 0; j < t; j++) { cin >> n >> k1 >> k2; for (int i = 0; i < k1; i++) cin >> a[i]; for (int i = 0; i < k2; i++) cin >> b[i]; ...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7, N = 3e5 + 7, M = 998244353; vector<int> G[N], add[N], del[N]; long long f[N], fi[N], inv[N]; int cans[41], dp[1 << 20][21]; int C(int n, int k) { return f[n] * fi[k] % M * fi[n - k] % M; } void ADD(int& a, int b) { a += b; if (...
#include <bits/stdc++.h> using namespace std; int e[1010][1010]; int main(void) { int n, a, b; scanf( %d%d%d , &n, &a, &b); if (a > 1 && b > 1) { printf( NO n ); return 0; } int x = n - max(a, b) + 1; if (x <= 0 || ((n == 2 || n == 3) && x == n)) { printf( NO n ); r...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; const long long INF = 1000000000; template <class T> inline void read(T &x) { char c; int flag = 1; while ((c = getchar()) < 0 || c > 9 ) if (c == - ) flag *= -1; x = c - 0 ; while ((c = getchar()) >...
#include <bits/stdc++.h> int main(int argc, char const *argv[]) { int T; scanf( %d , &T); while (T--) { int n, m; scanf( %d%d , &n, &m); std::vector<short> vertices(3 * n, 0); std::vector<int> edges; for (int i = 0; i < m; i++) { int u, v; scanf( %d%d , &u, &v...
#include <bits/stdc++.h> using namespace std; struct node { int L, R, i; } q[100001]; bool cmp(node x, node y) { if (x.L / 555 != y.L / 555) { return x.L / 555 < y.L / 555; } return x.R < y.R; } map<int, int> mpp; int ans = 0, I; int arr[100000 + 1], ct[100001], arr2[100001]; voi...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-10; const int inf = 1 << 28; int in() { int x; scanf( %d , &x); return x; } long long In() { long long x; cin >> x; return x; } double inreal() { double x; scanf( %lf , &x); return x; } string ins...
#include <bits/stdc++.h> using namespace std; int t, n, m; long long a, k, ak; char c; unordered_map<long long, bool> ma; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> t; for (int ti = 1; ti <= t; ++ti) { ma.clear(); cin >> n >> m; k = (1ll << m) - n; for (...
#include <bits/stdc++.h> using namespace std; bool flag; long long Max = -1e18, tpMax = -1e18, dep[600005], a[600005]; int n, m, sz[600005], In[600005], TOT, LA[600005], NE[600005 << 1], EN[600005 << 1]; long long LE[600005 << 1]; void Link(int x, int y, int z) { EN[++TOT] = y; LE[TOT] = z; ...
#include <bits/stdc++.h> using namespace std; template <typename T> void pfill(T* pst, const T* ped, T val) { for (; pst != ped; *(pst++) = val) ; } const double pi = acos(-1); const double eps = 0; typedef class Point { public: int x, y, deg, id; Point() : x(0), y(0), deg(0), id(0) {...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int N = 1050; const long long mod = 1e9 + 7; int l, r, n, id = 1; int a[N]; bool vis[N]; char ans[N][N]; void work(int now, int i) { bool flag = true; while (!vis[i]) { vis[i] = 1; if (flag) { i...
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cout << 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; const int maxn = 1e5 + 3; bool dp[30][(1 << 14)][30]; int cnt[(1 << 14)], deg[(1 << 14)]; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; vector<int> a; int c = 0; bool fail = 0; for (int i = 1; i <= n; i++) { int ...
#include <bits/stdc++.h> using namespace std; bool maxl(long long a, long long b) { return a > b; } bool minl(long long a, long long b) { return a < b; } bool cmp(int a, int b) { return a > b; } inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch ...
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> istream& operator>>(istream& in, pair<T1, T2>& a) { in >> a.first >> a.second; return in; } template <typename T1, typename T2> ostream& operator<<(ostream& out, pair<T1, T2> a) { out << a.first << << a.second;...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 7; string a[N]; int r[N], c[N]; int main() { ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { int n, m; cin >> n >> m; for (int i = 0; i <= n; i++) r[i] = 0; for (int j = 0; j <= m;...
#include <bits/stdc++.h> using namespace std; long long n, m, i, ans, mas[2000000], j; int main() { cin >> n >> m; for (i = 0; i < n; i++) { cin >> mas[i]; while (m < mas[i] - mas[j]) j++; if (i > j + 1) ans += (i - j - 1) * (i - j) / 2; } cout << ans; }
#include <bits/stdc++.h> using namespace std; struct _2DLL { _2DLL *R, *D; int val; _2DLL() { R = D = NULL; val = 0; } }; int n, m, q; _2DLL *grid[1005][1005]; int main() { scanf( %d%d%d , &n, &m, &q); for (int i = 0; i <= n; i++) for (int j = 0; j <= m; j++) grid[i...
#include <bits/stdc++.h> long int pos[100001] = {0}, neg[100001] = {0}; int main() { long int n, count = 0, i; scanf( %ld , &n); long int arr[n]; for (i = 0; i < n; i++) { scanf( %ld , arr + i); if (arr[i] > 0) pos[arr[i]]++; else if (arr[i] < 0) neg[-arr[i]]++; ...
#include <bits/stdc++.h> using namespace std; int p[35], d[35], g[35], h[35], w[55], n, a, b, c, s, MOD; bool f[35][35][50005], v[35][35][50005]; int main() { int i, j, k, r = 0, x; scanf( %d%d , &n, &MOD); for (i = 0; i <= 40; i++) { if (i < 10) w[i] = 10 % MOD; else w[i...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<pair<int, int>> dec; vector<pair<int, int>> inc; dec.push_back({1e7, 0}); inc.push_back({-...
#include <bits/stdc++.h> using namespace std; int n, m, k, i, j, a; int c[11]; int main() { cin >> n >> m >> k; for (i = 1; i <= n; ++i) { for (j = 1; j <= m; ++j) { char x; cin >> x; c[j] += (x == Y ); } } for (i = 1; i <= m; ++i) a += (c[i] >= k); cout ...
#include <bits/stdc++.h> using namespace std; string s; int t2[2], t[2]; vector<int> type; int main() { cin >> s; int n = s.length(); int c = 1; while (c < n && s[c] == s[0]) c++; if (c == n) { cout << 0 n ; return 0; } int prev = 0; for (int i = 1; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; int n; void even() { puts( YES ); printf( %d * %d = %d n , 1, 2, 2); printf( %d * %d = %d n , 2, 3, 6); printf( %d * %d = %d n , 6, 4, 24); for (int i = 5; i + 1 <= n; i += 2) { printf( %d - %d = 1 n , i + 1, i); printf( 1 * 24 = 24 n )...
#include <bits/stdc++.h> using namespace std; int mx[4005], need[4005]; int n, l[4005], r[4005], a[4005]; bool inter(int i, int j) { if (l[i] >= l[j] && l[i] <= r[j]) return 1; if (r[i] >= l[j] && r[i] <= r[j]) return 1; if (l[j] >= l[i] && l[j] <= r[i]) return 1; if (r[j] >= r[i] && r[j] <= r[i...
#include <bits/stdc++.h> using namespace std; const int MAXN = 3010; int n; struct edge { int ne, to; edge(int N = 0, int T = 0) : ne(N), to(T) {} } e[MAXN << 1]; int fir[MAXN], num = 0; inline void join(int a, int b) { e[++num] = edge(fir[a], b); fir[a] = num; } int pa[MAXN][MAXN], si...
#include <bits/stdc++.h> using namespace std; const double pi = 3.141592653589793238463; vector<vector<int> > g; int parent[1009]; void dfs(int u, int prev) { parent[u] = prev; for (int v : g[u]) if (v != prev) dfs(v, u); } bool fme[1009], fhim[1009]; int main() { cin.tie(0); cin.s...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const int INF = 0x3f3f3f3f; int m, n, c[N], cnt[N]; vector<int> g[N]; int bit[N]; void add(int x, int t) { for (; x <= n; x += x & -x) bit[x] += t; } int ask(int x) { int ret = 0; for (; x > 0; x -= x & -x) ret += bit[x];...
#include <bits/stdc++.h> #pragma warning(disable : 4996) #pragma comment(linker, /STACK:1024000000,1024000000 ) const long double pi = acosl(-1.); int T; const long long mod = 258280327; long long gcd(long long x, long long y) { if (!y) return x; return gcd(y, x % y); } long long quickfind(long...
#include <bits/stdc++.h> using namespace std; const int N = 205; int d[N], head[N], tot; int to[N * N], nex[N * N], vis[N * N]; vector<pair<int, int> > ans; void init() { tot = 0; memset(d, 0, sizeof(d)); memset(head, -1, sizeof(head)); ans.clear(); } void add(int u, int v, int w) { ...
#include <bits/stdc++.h> using namespace std; int n; int a[(int)2e5][2]; int main() { cin >> n; if (n == 3) { cout << 1 2 3 << endl; return 0; } for (int i = 0; i < n; i++) { cin >> a[i][0] >> a[i][1]; a[i][0]--; a[i][1]--; } int next = 0; for (int i =...
#include <bits/stdc++.h> using namespace std; const long long N = 998244353; struct mat { long long a[2][2]; }; mat mul(mat a, mat b) { mat c; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { c.a[i][j] = 0; for (int k = 0; k < 2; k++) c.a[i][j] += a.a[i][k] * b.a[k...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long INF = 4e18; const int MAX_LOG = 21; const int MAX_N = (1 << 17); int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, k, a, b, c, d; cin >> n >> k >> a >> b >> c >> d; if...
#include <bits/stdc++.h> using namespace std; bool comp(int x, int y) { return x > y; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; int tt = 1; long long m, n, k; while (tt--) { cin >> n >> k; vector<int> vec(n); for (long long i = 0; i <...
#include <bits/stdc++.h> using namespace std; int n, a[100005], res = 1e9, A, B, x[100005], kq[100005], kq1[100005], dem = 0, e[100005]; void no(int val) { if (a[n] >= 0 || a[n - 1] >= 0 || res <= val) return; res = val; for (int i = 2; i <= n - 1; i++) kq[i] = x[i]; return; ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int l, r; cin >> l >> r; vector<long long int> v, ans; long long int x = 1; while (x <= r) { v.push_back(x); x *= 2; } x = 1; while (x <= r) { ...