solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int main() { int n, k, a[1005]; scanf("%d %d", &n, &k); for (int i = 0; i < n; i++) scanf("%d", a + i); sort(a, a + n); int ub = k, id = -1, ans = 0; while (id < n - 1) { int pid = id; id = upper_bound(a, a + n, ub * 2) - a - 1; if (id == pid) { ...
8
#include <bits/stdc++.h> int a[1000005], p[1000005], L[1000005], R[1000005], n, m, x, t = 2; long long c[1000005]; void read(int &x) { char ch; x = 0; for (ch = getchar(); ch < '0' || ch > '9'; ch = getchar()) ; for (; ch >= '0' && ch <= '9'; x = x * 10 + ch - 48, ch = getchar()) ; } void dfs(int l, int...
17
#include <bits/stdc++.h> unsigned GetMin(unsigned passangers_count, const std::vector<unsigned>& airplanes) { unsigned result = 0; for (std::vector<unsigned>::const_iterator b = airplanes.begin(), e = airplanes.end(); (b != e) && passangers_count; ...
3
#include <bits/stdc++.h> using namespace std; int m, last; int nxt[400400][26], link[400400], dp[400400], pos[400400]; void extend(int c) { if (nxt[last][c] && dp[nxt[last][c]] == dp[last] + 1) { last = nxt[last][c]; return; } int x = last, y = last = ++m; dp[y] = dp[x] + 1; while (x && !nxt[x][c]) nx...
20
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const long long INF = 0x3f3f3f3f3f3f3f3f; const int N = 50; int n, m, q; vector<pair<int, int>> fc; int fn, s, t; vector<int> e[N + 7], to, fw, co; void add(int u, int v, int f, int c) { e[u].push_back(int((to).size())), to.push_back(v), fw.pus...
23
#include <bits/stdc++.h> using namespace std; double binary_search_max(); bool ok(double); long long k, n; double EN, EA; int arr[100000]; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL), cout.tie(NULL); cin >> n >> k; for (int i = 0; i < n; ++i) { cin >> arr[i]; } cout << std::fixed; cout <<...
8
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; const long long LB = 0; const long long RB = (1LL << 60LL) - 1; vector<tuple<int, long long, long long>> reduced[2]; vector<pair<long long, long long>> all[2][65]; inline void insert(int id, int depth, long long l, long long r, long long qs, ...
23
#include <bits/stdc++.h> using namespace std; const int maxn = 212345; struct Seg { int l, r, lv, rv; } T[maxn << 2]; vector<int> G[maxn]; int n, q, clk, st[maxn << 1][19], in[maxn], out[maxn], dep[maxn], w[maxn]; void dfs(int u, int p) { in[u] = ++clk; st[clk][0] = u; for (int v : G[u]) { if (v == p) conti...
21
#include <bits/stdc++.h> char str[200005]; int main() { int n; scanf("%d", &n); scanf("%s", str); int sum = 0; for (int i = 0; i < n; i++) { if (str[i] == '<') { sum++; } else break; } for (int i = n - 1; i >= 0; i--) { if (str[i] == '>') { sum++; } else break; } ...
2
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 100; set<pair<int, int>> seg[4 * MAXN]; int tx[MAXN], ty[MAXN], x[MAXN], y[MAXN], qt[MAXN]; void ins(int qv, int xl = 0, int xr = MAXN, int id = 0) { if (tx[qv] >= xr || tx[qv] < xl) return; seg[id].insert({ty[qv], qv}); if (xr - xl == 1) return...
22
#include <bits/stdc++.h> char map[10][10]; struct Q { int x, y; } q[100000]; int l, r; bool mark[10][10]; bool judge(int xx, int yy) { if (xx < 0 || yy < 0 || xx >= 8 || yy >= 8 || map[xx][yy] == 'S') return 0; if (mark[xx][yy]) return 0; xx--; if (xx < 0 || yy < 0 || xx >= 8 || yy >= 8 || map[xx][yy] == 'S')...
7
#include <bits/stdc++.h> using namespace std; int dp[501][501]; int main() { int n, i, j, k; vector<int> vec; scanf("%d", &n); for (i = 0; i < n; i++) { int x; scanf("%d", &x); vec.push_back(x); } for (i = 0; i < n; i++) dp[i][i] = 1; for (j = 1; j < n; j++) { for (i = 0; i + j < n; i++) {...
11
#include <bits/stdc++.h> const int N = 1 << 12; int k, n, a[N], p[N], q[N], r[N]; void do_xor(int x, int y, int z) { int t = r[p[x] ^ z]; if (t == x) return; if (t == y) { std::swap(p[x], p[y]); r[p[x]] = x, r[p[y]] = y; return; } std::swap(p[x], p[t]); r[p[x]] = x, r[p[t]] = t; std::swap(q[y]...
23
#include <bits/stdc++.h> using namespace std; long long A[300001]; int main() { ios_base::sync_with_stdio(0); cin.tie(nullptr); long long n, k, mx = 0; cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> A[i]; mx = max(mx, A[i]); } sort(A + 1, A + n + 1); long long l = mx, h = 10000000000000; ...
6
#include <bits/stdc++.h> using namespace std; const int N = 222; int n, x, k; int a[N]; long long dp[N][N]; void Input() { cin >> n >> k >> x; for (int i = 1; i <= n; i++) cin >> a[i]; } void maximize(long long &a, long long b) { a = max(a, b); } void Output() { memset(dp, -1, sizeof(dp)); dp[0][0] = 0; for (...
11
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); long double l, r, k; cin >> l >> r >> k; bool any = false; for (long double kk = 1; kk <= r; kk *= k) if (kk >= l) { cout << std::fixed << setprecision(0) << kk << " "; any = true; } if (!any) cout <<...
7
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ; string s; cin >> s; int a = 0, b = 1; for (int i = 0; i < int(s.size()); i++) if (s[i] == '1') a = min(a, b) + 1; else b = min(a, b) + 1; cout << a; return 0; }
11
#include <bits/stdc++.h> #include <math.h> using namespace std; #define ll long long int inline double round( double val ) { if( val < 0 ) return ceil(val - 0.5); return floor(val + 0.5); } ll mod=1e9+7; ll mul(ll a,ll b) { return ((a%mod)*(b%mod))%mod; } ll add(ll a,ll b) { return ((a%mod)+(b%mod))%mod...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 7, maxm = 5e6 + 7; struct Node { int h[maxm], e[maxm], ne[maxm], cnt; void add(int u, int v) { e[++cnt] = v; ne[cnt] = h[u]; h[u] = cnt; } } G1, G2; char s[100010][60]; int sk[maxm], dfn[maxm], low[maxm], clock_dfs; int dp[maxm], sz[...
17
#include <bits/stdc++.h> int main() { int n1, n2 = 0, n3 = 0; std::vector<int> v1(101, 0); for (int i = 0; i < 5; i++) { std::cin >> n1; v1[n1]++; } for (int i = 0; i < v1.size(); i++) { if (v1[i] == 2) n2 = std::max(n2, i * 2); if (v1[i] >= 3) n2 = std::max(n2, i * 3); } for (int i = 0; i...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, p, q, r, s, a, b; cin >> n; for (int i = 0; i < n; i++) { cin >> p >> q >> r >> s; if (s != p) a = p; else a = q; b = s; cout << a << ' ' << b << '\n'; }...
0
#include <bits/stdc++.h> int main() { int n, m, i, j; scanf("%d %d", &n, &m); int ara[m], min = 0, max = 0, t = 0, arr[m]; for (i = 0; i < m; i++) { scanf("%d", &ara[i]); } for (i = 0; i < m; i++) { arr[i] = ara[i]; } for (i = 0; i < n; i++) { t = 0; for (j = 1; j < m; j++) { if (a...
3
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int m; cin >> m; if (n == m + 1) { cout << 0; for (int i = 0; i < m; ++i) cout << 1 << 0; } else if ((n + 1) * 2 == m) { cout << 11; for (int i = 0; i < n; ++i) cout << 0 << 11; } else if ((n + 1) * 2 - 1 == m) { ...
6
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int n; cin >> n; string s; cin >> s; vector<long long int> v; long long int cnt = 0; for (int i = 0; i < s.size(); i++) { if (i != 0 && s[i] != s[i - 1]) { v.push...
9
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long a, b, c, d; cin >> a >> b >> c >> d; long long n = 1005; if (a == 1 and b == 1 and c == 1 and d == 1) { cout << endl; return 0; } while (n > 0) { --n; if (a == 1 ...
14
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n; cin >> n; long long a[n]; long long sum = 0; for (long long i = 0, _n = (n); i < _n; i++) { cin >> a[i]; sum = sum + a[i]; } sort(a, a + n); long long ans = sum; for (lo...
5
#include <bits/stdc++.h> using namespace std; int a[111111], b[1111], d[111]; long long j, i, n, m = 0, k, t; int ans = 0; int main() { string s, st; cin >> st >> s; sort(s.begin(), s.end()); j = s.size() - 1; for (i = 0; i < st.size(); i++) if (st[i] < s[j] && j >= 0) st[i] = s[j--]; cout << st; }
3
#include <bits/stdc++.h> using namespace std; const int N = 200050; int n, head[N], pre[N << 1], to[N << 1], len[N << 1]; int ok, sta[N], cnt, vis[N], huan[N]; vector<int> hp; long long mv[N], pv[N], ct[N], dis[N], maxv, ans, tmp; set<pair<long long, int> > pos, neg; set<pair<long long, int> >::iterator it, ip; inline ...
17
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, c; double xx, yy, zz; while (cin >> a >> b >> c) { xx = (a + b - c) / 2.0; yy = (b + c - a) / 2.0; zz = (c + a - b) / 2.0; if (ceil(xx) == xx and ceil(yy) == yy and ceil(zz) == zz and xx >= 0 and yy >= 0 and zz >= 0...
4
#include <bits/stdc++.h> using namespace std; inline long long int absdiff(long long int a, long long int b) { return (a > b) ? a - b : b - a; } long long int fast_expo(long long int x, long long int p) { if (p == 0) return 1; else if (p % 2 == 0) { long long int t = fast_expo(x, p / 2) % 1000000007; ...
6
#include <bits/stdc++.h> using namespace std; const long long MOD = (1e9) + 7; const int INF = 1e9; const long long INF64 = 1e18; const double EPS = 1e-12; const double PI = acos(-1); const long long MD = 6235164; const long long T = 23917; const int N = 400100; const int M = 2010; int n, m, k; string p, s; string ans,...
16
#include<bits/stdc++.h> using namespace std; #define int long long signed main(){ int t,n;cin>>t; while(t--){ cin>>n; int r[n+1],c[n+1]; r[0]=1;c[0]=1; for(int i=1;i<=n;i++){cin>>r[i];} for(int i=1;i<=n;i++){cin>>c[i];} sort(r,r+n+1);sort(c,c+n+1); int cos...
12
#include <bits/stdc++.h> using namespace std; template <typename _T> inline void _DBG(const char *s, _T x) { cerr << s << " = " << x << "\n"; } template <typename _T, typename... args> void _DBG(const char *s, _T x, args... a) { while (*s != ',') cerr << *s++; cerr << " = " << x << ','; _DBG(s + 1, a...); } con...
26
#include <bits/stdc++.h> using namespace std; long long n, k; vector<long long> a, b; int main() { cin >> n >> k; for (long long i = 0; i < n; i++) { long long f; cin >> f; a.push_back(f); b.push_back(f); } long long ans = 0; for (long long i = 1; i <= n - 1; i++) { long long sum = a[i] + ...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; const int maxm = 310; const int mod = 1e9 + 7; const int inf = 1e9 + 7; const double eps = 1e-6; int n, m; int v[maxn], d[maxn], p[maxn]; int vis[maxn]; vector<int> vans; queue<int> que; void gao() { int i, j; int sum = 0; for (j = i + 1; j <=...
10
#include <bits/stdc++.h> using namespace std; map<int, int> mint; map<int, string> mstr; set<int> sint; int a[500], chk = 1; int main() { ios::sync_with_stdio(0); char str[500]; int k = 0, n, l = 0, i, j, x; a[k++] = 1; char c; while (cin >> c && c != '=') { if (c == '+') { a[k++]++; chk++; ...
10
#include <bits/stdc++.h> using namespace std; typedef set<int, bool (*)(int, int)> sic; typedef set<pair<int, int>, bool (*)(pair<int, int>, pair<int, int>)> spic; typedef set<long long int, bool (*)(long long int, long long int)> slc; typedef set<pair<long long int, long long int>, bool (*)(pair<long long ...
11
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const ll mod = 1e9 + 7; const ld eps = 1e-9; const ld PI = acos(-1); void solve(){ ll n,k; cin >> n >> k; vector<pair<ll,ll>> a(n); for(int i=0;i<n;i++){ cin >> a[i].first >> a[i].second; } boo...
2
#include <bits/stdc++.h> using namespace std; int mult(int x, int y) { long long int ans, x1 = (long long int)x, y1 = (long long int)y; ans = (x1 * y1) % 1000000007; return (int)ans; } int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int lcm(int a, int b) { return a * (b / gcd(a, b)); } long long int ...
14
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,unroll-loops") #pragma GCC target("avx,avx2,sse,sse2") using namespace std; long long fastexp(long long a, long long n, long long nod = LLONG_MAX) { long long ans = 1; while (n) { if (n & 1) ans = (ans * a) % nod; a = (a * a) % nod; n >>= 1; } ret...
9
#include <bits/stdc++.h> using namespace std; template <typename T> T gcd(T a, T b) { return (b ? __gcd(a, b) : a); } template <typename T> T lcm(T a, T b) { return (a * (b / gcd(a, b))); } template <class T> ostream &operator<<(ostream &os, vector<T> V) { os << "[ "; for (auto v : V) os << v << " "; return o...
16
#include <bits/stdc++.h> using namespace std; const int maxint = -1u >> 1; const double pi = 3.14159265358979323; const double eps = 1e-8; int x, a, b, n; bool num[8]; int main() { cin >> n; cin >> x; cin >> a >> b; bool ans = true; x = 7 - x; for (int i = (0); i < (n - 1); i++) { cin >> a >> b; mem...
3
#include <bits/stdc++.h> using namespace std; struct Point { Point(double x = 0, double y = 0) : x(x), y(y) {} double x, y; }; Point first; Point operator-(const Point& p1, const Point& p2) { return Point(p1.x - p2.x, p1.y - p2.y); } double operator^(const Point& p1, const Point& p2) { return p1.x * p2.y - p1.y...
12
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_string(const string...
11
#include <bits/stdc++.h> using namespace std; vector<long long> v; int main() { long long i, j, n, m, t, p, cas = 1; while (scanf("%I64d %I64d %I64d", &n, &m, &p) == 3) { v.push_back(n); v.push_back(m); v.push_back(p); sort(v.begin(), v.end()); if ((v[0] + v[1]) % 2 == 0) printf("%I64d\n",...
13
#include <bits/stdc++.h> using namespace std; int n, m; int f[3][3][77977 << 2], a[3][3]; inline void add(int &a, int b) { a += b; if (a >= 777777777) a -= 777777777; } void up(int id) { for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) f[i][j][id] = 0; for (int i = 0; i < 3; i++) for (int j = 0; ...
16
#include <bits/stdc++.h> using namespace std; long long a[200001], b[200001]; long long l, r, mid, ans; int n, m, i, j, k; int tb; long long dist(int x, int y) { if (a[x] > b[y]) return a[x] - b[y]; else return b[y] - a[x]; } long long min(long long a, long long b) { if (a < b) return a; else re...
11
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int N = 200005; inline int read() { int x = 0, f = 1; char c = 0; while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while ('0' <= c && c <= '9') x = 10 * x + c - '0', c = getchar(); return x * f; } stru...
18
#include <bits/stdc++.h> using namespace std; using ll = long long; const int NAX = 2e5 + 5, MOD = 1000000007; void solveCase() { int n, m; cin >> n >> m; vector<vector<int>> a(n, vector<int>(m)); vector<vector<int>> b(n, vector<int>(m)); int cnta = 0, cntb = 0; for (auto &x : a) for (auto &y : x) { ...
7
#include <bits/stdc++.h> using namespace std; int const N = 26; int main() { vector<int> vec(N); for (int i = 0; i < N; i++) { cin >> vec[i]; } string str; cin >> str; long long cnt = 0, tmp = 0; map<long long, long long> m[N]; for (int i = 0; i < (int)str.size(); i++) { int chr = str[i] - 'a'; ...
10
#include <bits/stdc++.h> using namespace std; std::mt19937 rng( (int)std::chrono::steady_clock::now().time_since_epoch().count()); using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; const int INF = 0x3f3f3f3f; const ll INFLL = 0x3f3f3f3f3f3f3f3fLL; const int MOD = 1000000007; const int MAXN...
5
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; const long double eps = 1e-22; struct point { long double x, y; int s, r; point(long double x = 0, long double y = 0) : x(x), y(y) {} inline point operator-(const point &p) const { return point(x - p.x, y - p.y); } inline long double ...
18
#include <bits/stdc++.h> using namespace std; struct T { int x, in, r; }; int n; T target[10005]; bool conf(T left, T right) { return left.x < right.x; } int lb(int val) { int left, right, pivot; left = 0; right = n - 1; while (left <= right) { pivot = (left + right) / 2; if (target[pivot].x == val) ...
9
#include <bits/stdc++.h> using namespace std; int n, m; int dp[2][1010]; int main() { int i, y; int tmp; scanf("%d%d", &n, &m); memset(dp, 0, sizeof(dp)); for (i = 1; i <= n; i++) { scanf("%d", &tmp); tmp = tmp % m; memset(dp[i & 1], 0, sizeof(dp[1])); dp[i & 1][tmp] = 1; for (y = 0; y < m...
11
#include <bits/stdc++.h> using namespace std; int a, b, c, d, e, f; const int maxn = 101000; int bio[maxn]; int bio2[maxn]; int main() { scanf("%d%d%d", &a, &b, &c); for (int i = 0; i < a; ++i) { scanf("%d", &d); bio[i] = d; } for (int i = 0; i < b; ++i) { scanf("%d", &d); bio2[i] = d; } if ...
8
#include <bits/stdc++.h> using namespace std; int main() { int h = (1 << 4) - 1; long long n; cin >> n; long long ans = 0; for (int i = 0; i <= h; i++) { long long cur = 1; int c = 0; if (i & 1) cur *= 2, c++; if (i & 2) cur *= 3, c++; if (i & 4) cur *= 5, c++; if (i & 8) cur *= 7, c++...
3
#include <bits/stdc++.h> using namespace std; char s[100][100], str[100]; int vis[100], k, cha, b[100], n; void dfs(int wei) { int i, j, minx = 99999999, maxx = -99999999, num; if (wei == k + 1) { for (i = 1; i <= n; i++) { num = 0; for (j = 1; j <= k; j++) { num = num * 10 + s[i][b[j]] - '0...
6
#include <bits/stdc++.h> using namespace std; long double deg[10010], length[10010], nowdeg; const long double pi = acos(-1.); int n, q, t1 = 1, t2 = 2; struct node { long double x, y; long double operator*(node a) { return x * a.y - y * a.x; } node operator+(node a) { return (node){x + a.x, y + a.y}; } node op...
18
#include <bits/stdc++.h> using namespace std; int main() { long long w, h, k; cin >> w >> h >> k; long long ans = 0; for (long long i = 0; i < k; i++) { ans = ans + 2 * w + 2 * h - 4; w = w - 4; h = h - 4; } cout << ans; }
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; cin >> t; while (t--) { int n, a, b; cin >> n >> a >> b; string s = "abcdefghijklmnopqrstuvwxyz"; for (int i = 0; i < n; i++) { cout << s[i % b]; } cout << "\n";...
1
#include <bits/stdc++.h> using namespace std; map<int, int> has; map<int, vector<int> > lst; set<int> st; int main() { int N; scanf("%d", &N); int cnt = 0; for (int i = 0; i < N; i++) { int x; scanf("%d", &x); set<int>::iterator it = st.lower_bound(x); if (it == st.begin()) { cnt++; ...
8
#include <bits/stdc++.h> using namespace std; int n, m, k, t, c; string arr[1010]; vector<char> ans; char di; vector<pair<char, int> > op; int main() { scanf("%d %d", &n, &m); for (int i = 0; i < n; i++) cin >> arr[i]; scanf("%d", &k); while (k--) { scanf(" %c %d", &di, &t); op.push_back(make_pair(di, t...
9
#include <bits/stdc++.h> using namespace std; void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } long long n, m, t, num; int k; map<pair<long long, long long>, int> mp; struct Point { long long x, y; int num; bool flag = false; }; Point p[200007], ch[200007], tp[200007]; bool cm...
26
#include <bits/stdc++.h> using namespace std; multiset<int> se1, se2, se3; int main() { int k, n1, n2, n3, t1, t2, t3; scanf("%d", &k); scanf("%d%d%d", &n1, &n2, &n3); scanf("%d%d%d", &t1, &t2, &t3); for (int i = 1; i <= n1; ++i) se1.insert(0); for (int i = 1; i <= n2; ++i) se2.insert(0); for (int i = 1; ...
11
#include <bits/stdc++.h> using namespace std; int n, k, x; string s; int main() { while (getline(cin, s)) { switch (s[0]) { case '+': { n++; break; } case '-': { n--; break; } default: x = s.find(':'); k = k + n * (s.size() - x - 1); ...
2
#include <bits/stdc++.h> const int vx[4] = {-1, 0, 0, 1}, vy[4] = {0, -1, 1, 0}; int n, m; struct Map { int a[55][55], k, x1[10800], y1[10800], x2[10800], y2[10800]; void read() { for (int i = 1, x, y; i <= m; i++) scanf("%d%d", &x, &y), a[x][y] = i; } void move(int x, int y, int d) { a[x + vx[d]][y + v...
19
#include <bits/stdc++.h> using namespace std; using ll = long long; ll md = 1000000007; ll exp(ll a, ll b) { ll r = 1ll; while (b > 0) { if (b & 1) { r = r * (a % md); r = (r + md) % md; } b >>= 1; a = (a % md) * (a % md); a = (a + md) % md; } return (r + md) % md; } ll gcd(ll a,...
9
#include <bits/stdc++.h> namespace Rstd { using namespace std; template <typename T> inline bool chkmax(T &x, T y) { return x < y ? x = y, 1 : 0; } template <typename T> inline bool chkmin(T &x, T y) { return x > y ? x = y, 1 : 0; } template <typename T> inline void read(T &x) { char c = getchar(); x = 0; boo...
11
#include <bits/stdc++.h> using namespace std; const int maxn = 1000100; int n, m, dx, dy, x[maxn], y[maxn], s[maxn]; int main() { scanf("%d%d%d%d", &n, &m, &dx, &dy); int xx = 0, yy = 0; for (int i = 1; i < n; ++i) { xx = (xx + dx) % n, yy = (yy + dy) % n; x[xx] = i; y[i] = yy; } for (int i = 1; i...
12
#include <bits/stdc++.h> using namespace std; char ch[2507][2507]; int sum[2507][2507]; int n, m; int ac(int k) { memset(sum, 0, sizeof sum); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { sum[i / k][j / k] += ch[i][j] - '0'; } } int ret = 0; for (int i = 0; i <= (n - 1) / k; i++) {...
6
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; namespace IO { template <class A, class B> ostream &operator<<(ostream &out, pair<A, B> a) { out << a.first << " " << a.second; return out; } template <class A, class B> ostream &operator<<(ostream &out, ve...
16
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007, N = 1000010; long long gcd(long long a, long long b) { return (a % b == 0) ? b : gcd(b, a % b); } int n, f[N], g[N], fa[N]; long long sz[N]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%lld", &sz[i]); for (int i = 2;...
19
#include <bits/stdc++.h> int main() { long long n; unsigned long long sum; scanf("%I64d", &n); sum = (n * (n + 1)) * 3; printf("%I64u", sum + 1); }
3
#include <bits/stdc++.h> using namespace std; const int maxn = 345678; const int m = 998244353; int mul(int a, int b) { return (long long)a * b % m; } vector<int> e[maxn]; int f[2][2][maxn], pa[maxn]; int solve(int r, int eq, int v, int p) { pa[v] = p; if (f[r][eq][v] != -1) return f[r][eq][v]; if (e[v].size() ==...
16
#include <bits/stdc++.h> using namespace std; int n, m, t, r, rez; vector<int> G[100005], GT[100005], C[100005]; vector<int> H[100005]; char viz[100005]; struct nod { int a, b; }; nod A[100005]; bool mark[100005], good[100005]; void read() { scanf("%d%d", &n, &m); int x, y; while (m) { scanf("%d%d", &x, &y)...
14
#include <bits/stdc++.h> using namespace std; const int INF = 2e6; const long long LINF = 8e18; const int MOD = 1e9 + 7; const long double EPS = 1e-9; vector<long long> A[1005][2]; long long mat[502][502][2]; void zigzag(int N, int M, int d) { for (int i = 0; i < N + M; i++) { int start_c = max(0, i - N); int...
7
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1e5 + 5; const int MOD = 1e9 + 7; constexpr int MAX_VAL = 1e7 + 5; constexpr int LOGMAX = 31 - __builtin_clz(MAX_N) + 5; bool prime[MAX_VAL]; vector<int> primes, adj[MAX_N]; vector<tuple<int, int, int, int> > ops[MAX_VAL]; int st[MAX_N], en[MAX_N], arr[MAX...
20
#include <bits/stdc++.h> int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int main() { int n, x, mx = -1, d; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &x); mx = mx > x ? mx : x; d = i == 0 ? x : gcd(d, x); } x = mx / d; x = n - x; if (x & 1) puts("...
8
#include <bits/stdc++.h> int main() { int n, a, b, c; fscanf(stdin, "%d%d%d%d", &a, &b, &c, &n); int ans = 0; for (int i = 1; i <= n; i++) { int x; fscanf(stdin, "%d", &x); if ((b < x) && (x < c)) ans++; } fprintf(stdout, "%d\n", ans); fclose(stdin); fclose(stdout); return 0; }
0
#include <bits/stdc++.h> using namespace std; int n, m, u, v, cnt = 0; vector<int> g[3002]; bool vis[3002]; void dfs(int s) { cnt++; vis[s] = true; for (int i = 0; i < g[s].size(); i++) { if (!vis[g[s][i]]) dfs(g[s][i]); } } int main() { scanf("%d%d", &n, &m); if (n != m) { cout << "NO" << endl; ...
7
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; long long a[1000] = {0}; for (long long i = 1; i <= n; i++) cin >> a[i]; a[n + 1] = 1001; long long ans = 0; long long curr = 0; for (long long i = 1; i < n + 1; i++) { if (a[i] == a[i - 1] + 1 && a[i] == a[i + 1] - ...
5
#include <bits/stdc++.h> using namespace std; int val[60]; int n; int grid[2][60]; int mask1[25][1200008 + 1], mask2[25][1200008 + 1]; void solve(int l, int r, int mask[][1200008 + 1]) { memset(mask, -1, sizeof mask); for (int i = 0; i <= 24; i++) for (int j = 0; j < 1200008 + 1; j++) mask[i][j] = -1; for (in...
23
#include <bits/stdc++.h> using namespace std; int n, h, w; const long long MOD = 1e9 + 7; int L[2], R[2], C[2], D[2]; int ans; string trace; bool go(long long d, bool memo) { char here = trace[d % n]; if (here == 'L') memo ? C[0] = L[0] - 1 : C[0]--; else if (here == 'R') memo ? C[0] = R[0] + 1 : C[0]++; ...
17
#include <bits/stdc++.h> using namespace std; const int MAX = 13; int kol[MAX]; int m, d; int main() { ios_base::sync_with_stdio(0); cin.tie(0); kol[1] = 31; kol[2] = 28; kol[3] = 31; kol[4] = 30; kol[5] = 31; kol[6] = 30; kol[7] = 31; kol[8] = 31; kol[9] = 30; kol[10] = 31; kol[11] = 30; ko...
0
#include <bits/stdc++.h> const int maxn = 1e6 + 5; const int mod = 1e9 + 7; const int inf = 1e9; using namespace std; int main() { int n; cin >> n; if (n > 36) cout << "-1" << endl; else if (n == 1) cout << "6" << endl; else { while (n) { if (n >= 2) { cout << "8"; n -= 2; ...
4
#include <bits/stdc++.h> using namespace std; using lli = long long int; using pii = pair<int, int>; using vi = vector<int>; using vb = vector<bool>; using vvi = vector<vector<int>>; using vlli = vector<long long int>; using vpii = vector<pair<int, int>>; int n, q, x, l, r; char c; string s; map<char, set<int>> pos; vi...
13
#include <bits/stdc++.h> using namespace std; long long tn; int n, m, a, arr[110], ind, mx; int main() { cin >> n >> m; for (int i = 0; i < m; i++) { ind = mx = -1; for (int j = 1; j <= n; j++) { cin >> a; if (a > mx) { mx = a; ind = j; } } arr[ind]++; } ind = m...
3
#include <bits/stdc++.h> using namespace std; template <typename _T> inline void read(_T &f) { f = 0; _T fu = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') fu = -1; c = getchar(); } while (c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); } f ...
21
#include <bits/stdc++.h> using namespace std; struct edge { int v, t, i; edge(int v_, int t_, int i_) { v = v_; t = t_; i = i_; } }; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m, q; cin >> n >> m >> q; vector<pair<int, int>> inp; vector<vector<edge>> adj(n ...
11
#include <bits/stdc++.h> using namespace std; long long n, x[1005], y[1005], maxx, maxy, minx, miny; int main() { cin >> n; cin >> x[1] >> y[1]; minx = x[1]; maxx = x[1]; miny = y[1]; maxy = y[1]; for (int i = 2; i <= n; i++) { cin >> x[i] >> y[i]; minx = min(x[i], minx); maxx = max(maxx, x[i]...
5
#include <bits/stdc++.h> using namespace std; int main() { long long s, x; while (cin >> s >> x) { long long dp[41][2]; memset(dp, 0, sizeof dp); dp[0][0] = 1; for (int i = 0; i < 40; i++) { if (x & (1LL << i)) { if (s & (1LL << i)) dp[i + 1][0] += 2 * dp[i][0]; if (!(s & (1LL ...
9
#include <bits/stdc++.h> using namespace std; long long ans; const int maxn = 11000; const int mod = 1000000007; char s[3][maxn]; long long dp[2][1 << 3]; bool flag[4]; int n; int x, y; const int d[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; bool build(int dir) { int dx = x, dy = y; for (int i = 1; i <= 2; ++i) { ...
13
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author */ #include <iostream> #include <fstream> #include <algorithm> #include <array> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include...
24
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); printf("%d\n", (n - 1) / 2); }
2
#include <bits/stdc++.h> using namespace std; const int maxx = 2e5 + 100; struct edge { int next; int to; } e[maxx << 1]; int head[maxx << 1]; int vis[maxx], fa[maxx], sum[maxx], ans[maxx]; int n, tot = 0; inline void add(int u, int v) { e[tot].next = head[u], e[tot].to = v, head[u] = tot++; } inline void dfs(int...
10
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000 * 1000 * 1000 + 7; const long long INF = 1ll * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 7; const long long MOD2 = 998244353; const long long N = 1000 * 100 + 5; const long long N2 = 1000 * 1000; const double PI = 3.14159265; long long power(long ...
11
#include <bits/stdc++.h> using namespace std; const int MAXN = 200100; const int INF = MAXN; int n, k, p[MAXN], c[MAXN]; multiset<pair<int, int> > s, ovi; vector<int> ans[MAXN]; void print(multiset<pair<int, int> > &t) { for (auto &x : t) cerr << "(" << x.first << "," << x.second << ") "; cerr << endl; } int main()...
11
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; long long A, B, C, L[4], R[4]; long long a[N][4]; int n, t; bool check(long long x) { for (int i = 0; i < 4; i++) L[i] = a[1][i] - x, R[i] = a[1][i] + x; for (int i = 2; i <= n; i++) for (int j = 0; j < 4; j++) { L[j] = max(L[j], a[i][j]...
21
#include <bits/stdc++.h> using namespace std; template <typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; } template <typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; } template <typename H> void r...
13
#include <bits/stdc++.h> using namespace std; int main() { int n, m, c = 0; cin >> n >> m; int a[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> a[i][j]; } } for (int i = 0; i < n; i++) { if (a[i][0] == 1 || a[i][m - 1] == 1) { c++; } } for (int i = ...
2