solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; const int maxn = 10 + 5; char a[maxn][maxn], b[maxn][maxn]; int n; int main() { cin >> n; for (int i = 0; i < n; i++) { scanf("%s", a[i]); } for (int i = 0; i < n; i++) { scanf("%s", b[i]); } for (int f1 = 0; f1 < 2; f1++) { for (int f2 = 0; f2 < 2; ...
1
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n; long long d, dp[N]; pair<long long, long long> arr[N]; bool cmp(pair<long long, long long> a, pair<long long, long long> b) { return a.first < b.first; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n...
2
#include <bits/stdc++.h> using namespace std; string a[5000]; int main() { string n; long long i, h, q, j, t; cin >> n; a[1] = "4"; a[2] = "7"; if (n == "4" || n == "7") { if (n == "4") cout << 1; else cout << 2; return 0; } i = 2; q = 2; h = 0; t = 2; while (a[i] != n) {...
2
#include <bits/stdc++.h> using namespace std; int n; int a[300007]; priority_queue<int, vector<int>, greater<int> > pr; long long ans = 0; int main() { ios_base::sync_with_stdio(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; if (!pr.empty()) { int p = pr.top(); pr.pop(); if (p...
4
#include <bits/stdc++.h> using namespace std; long long power(long long a, long long b) { long long res = 1; a %= 1000000007; for (; b; b >>= 1) { if (b & 1) res = res * a % 1000000007; a = a * a % 1000000007; } return res; } string a, b, c; int q, n, t; int arr[100009]; int const mi = 1e5 + 9; unorde...
4
#include <bits/stdc++.h> using namespace std; long long power(long long b, long long p, long long m) { if (b == 0) return 0; long long res = 1; while (p) { if (p % 2) { res = (res * b) % m; p--; } else { b = (b * b) % m; p /= 2; } } return res; } long long Root(long long r,...
4
#include <bits/stdc++.h> using namespace std; int n; vector<int> parent; vector<vector<int>> children; int max_degree; vector<pair<int, int>> result; void into(int root, int time) { int orig_time = time; result.emplace_back(root + 1, time); for (int i = 0; i < children[root].size(); i++) { time++; if (tim...
6
#include <cstdio> using namespace std; int dy[] = {0, 1, 1, 1}; int dx[] = {1, 0, 1, -1}; char c[10][10]; char solve(){ for(int i = 3; i < 6; ++i) for(int j = 3; j < 6; ++j) for(int k = 0; k < 4; ++k){ int t = 1; for(int d = 1; d < 3; ++d){ if(c[i][j] == c[i + dy[k] * d][j + dx[k] * d]){ ++t; } } ...
0
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int N = 1e5 + 4; int solve() { string s; cin >> s; int c; scanf("%d", &c); int n = (int)s.size(); int dp[n + 1][c + 1][2], dp1[n + 1][c + 1][2]; for (int i = 0; i < n + 1; i++) for (int j = 0; j < c + 1; j++) for (int f...
3
#include <cstdio> using namespace std; int main() { int x, y; while( scanf( "%d %d", &x, &y ), x || y ) printf( "%d %d\n", x > y ? y : x, x > y ? x : y ); return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<int> arr[n + 1]; for (int i = 1; i <= n; ++i) { vector<int> v; arr[i] = v; } for (int i = 0; i < m; ++i) { int a, b; cin >> a >> b; arr[a].push_back(b); arr[b].push_back(a); } int ans = 100...
2
#include <iostream> #include <algorithm> #include <string> #include <vector> #include <math.h> using namespace std; int main(){ int a,b,c,d,e,f; cin>>a>>b>>c>>d>>e>>f; int ans1=0,ans2=0; double ans=0; for(int i=0;100*a*i<=f;i++){ int x=100*a*i; for(int j=0;x+100*b*j<=f;j++){ int y=x+100*b*j; ...
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 2000 + 10, LG = 14; int n, par[MAXN][LG], d[MAXN][MAXN], dsu[MAXN]; long long dis[MAXN]; int h[MAXN], e; vector<pair<int, int> > adj[MAXN]; vector<pair<int, pair<int, int> > > vec; int find(int a) { if (a == dsu[a]) return a; return dsu[a] = find(dsu[a]...
4
#include <bits/stdc++.h> using namespace std; typedef struct { int h; int m; } node; int suanq(int hh, int mm, int h, int m) { if (h < hh || (h == hh && m <= mm)) return -1; int count = 0; for (int i = hh; i <= h; i++) { for (int j = mm; j <= 60; j++) { if (i == h && j == m) return count; coun...
1
#include <bits/stdc++.h> using namespace std; long long int tc, n, m, k; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; cin >> tc; while (tc--) { long long int pc, fc; cin >> pc >> fc; long long int scnt, axecnt; cin >> scnt >> axecnt; long long int sw, a...
2
#include <bits/stdc++.h> using std::cin; using std::cout; const int N = 100054; int mod; int n, l, r; int o = 0, pr[10], al[10], pral[10][32]; int maj[N], fact[N], finv[N], c[N][10]; inline int min(const int x, const int y) { return x < y ? x : y; } int exgcd(int a, int b, int &x, int &y) { if (b) { int d = exgcd...
4
#include <bits/stdc++.h> using namespace std; string s, s1; set<long long> S; long long tmp; long long p; int vat; int k; bool b[1002]; int main() { cin >> s; cin >> s1; for (int i = 0; i < 26; ++i) b[i + 'a'] = !(s1[i] - '0'); cin >> k; for (int i = 0; i < s.size(); ++i) { tmp = 0; vat = 0; p = 1...
4
#include <bits/stdc++.h> using namespace std; int main() { string a, b; cin >> a >> b; string c; c.assign(b.size() - 1, '$'); a = c + a + c; int ans = numeric_limits<int>::max(); for (int i = 0; i < a.size() - b.size() + 1; ++i) { int cur = 0; for (int j = 0; j < b.size(); ++j) if (a[i + j] ...
3
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 7; vector<pair<long long, long long> > val[N]; vector<long long> v[N]; long long n, x, y, u, d, acc; long long ans[N], dep[N]; map<long long, long long> uno; void dfs(long long ver, long long par) { dep[ver] = dep[par] + 1; for (auto it : val[ver]) {...
5
#include <bits/stdc++.h> using namespace std; const long long int maxn = 1e3 + 5; const long long int inf = 1e9 + 7; long long int a[maxn][maxn]; bool b[maxn][maxn]; long long int n, m; bool check(long long int mid) { for (long long int i = 0; i < maxn; i++) for (long long int j = 0; j < maxn; j++) b[i][j] = 0; ...
4
#include <bits/stdc++.h> using namespace std; long long int n, m, a[100007], cf, cm, mm, d[100007], ans = 0, now; vector<vector<long long int> > v; vector<long long int> ok(2); pair<long long int, long long int> ans1; long long int find(long long int l, long long int r) { if (r < l) return 0; long long int ans = d[...
2
#include <bits/stdc++.h> using namespace std; const double eps = 1e-10; const int SIZEN = 110, SIZEM = 5010; void Gauss_Jordan(double A[SIZEN][SIZEN], double b[SIZEN], int N) { for (int j = 1; j <= N; j++) { int r = j; for (int i = j + 1; i <= N; i++) { if (fabs(A[i][j]) > fabs(A[r][j])) r = i; } ...
3
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { int tt; cin >> tt; while (tt--) { int n; cin >> n; int a[n]; a[0] = 1; a[1] = 1; for (int i = 2; i < n; ++i) a[i] = 0; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; j++) cout << a[(i + j...
2
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (a > b) swap(a, b); while (a > 0) { b %= a; if (b == 0) return a; a %= b; } return b; } long long sol(long long s, long long t, long long n, long long k) { long long haba = (t - s + n * k) % (n * k); long ...
1
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; int ans = 0; set<int> s; s.insert(a[n - 1]); for (int i = n - 2; i >= 0; i--) { if (a[i] > *s.begin()) ans++; s....
2
#include <bits/stdc++.h> using namespace std; const long long N = 1010, M = 1001000, mod = 1000000007; long long n, m, k, inv[M], fac[M], f[N][N]; long long qpow(long long a, long long b) { long long res = 1; while (b) { if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1; } return res; } inlin...
4
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; int n; long long int dn[6010], dinamik2[6010]; int main() { string ar; string ar2; cin >> ar; cin >> ar2; n = ((int)(ar2.size())); long long res = 0; for (int k = 0; k < ((int)(ar.size())); k++) { for (int j = 0; j < ((int)(ar2....
3
#include <bits/stdc++.h> using namespace std; char s[] = "1001010111001010"; int main() { int n; scanf("%d", &n); printf("%c\n", s[n - 1]); return 0; }
4
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int i = 0; i < t; i++) { int n; cin >> n; for (int j = 0; j < n; j++) { cout << 7 << " "; } cout << endl; } }
1
#include <iostream> #include <vector> using namespace std; int main(){ int N; vector<int> p(4),t(4); cin >> N; for(int i=0;i<4;i++) cin >> p[i]; for(int i=0;i<4;i++) cin >> t[i]; int ans = 1e9; for(int i=0;i<=N;i++) for(int j=0;j<=N;j++) for(int k=0;k<=N;k++){ int res = N-i*t[0]-j*t...
0
#include <bits/stdc++.h> using namespace std; const int dx[9] = {0, 0, 0, 1, 1, 1, -1, -1, -1}, dy[9] = {0, 1, -1, 0, 1, -1, 0, 1, -1}; int x[4], y[4]; string ans[2] = {"OTHER", "CHECKMATE"}; bool first, mark[2][20][20]; inline void Rock(int x, int y) { for (int i = x + 1; !mark[1][i][y]; i++) mark[0][i][y]...
2
#include <bits/stdc++.h> using namespace std; mt19937 rng(98); struct node { int x, y, c; long long s; node *l, *r; node(int x) : x(x), y(rng()), l(nullptr), r(nullptr) { c = 1; s = x; } void recalc(); }; int cnt(node *n) { return n ? n->c : 0; } long long sum(node *n) { return n ? n->s : 0; } void ...
5
#include <bits/stdc++.h> using namespace std; const int MAXN = 2005; const int MAXT = 1000005; const int mod = 1e9 + 7; int n, k; int trie[MAXT][26], term[MAXT], cnt; int dfn[MAXT], dout[MAXT], par[MAXT], dep[MAXT], piv; vector<int> v; bool in(int s, int t) { return dfn[s] <= dfn[t] && dout[t] <= dout[s]; } void dfs(in...
6
#include <bits/stdc++.h> using namespace std; signed main() { long long n; cin >> n; vector<long long> v(n); for (long long i = 0; i < n; i++) cin >> v[i]; vector<vector<long long> > dp(n, vector<long long>(n, -1)); for (long long i = 0; i < n; i++) dp[i][i] = v[i]; for (long long len = 2; len <= n; len++...
5
#include <bits/stdc++.h> using namespace std; pair<int, int> a[2001]; int n; int pos[2001]; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i].first; a[i].second = i; } sort(a, a + n); int cnt = 0; for (int i = 0; i < n; i++) { bool ok = true; while (i + 1 < n && a[i].first == ...
2
#include <iostream> #include <algorithm> #include <string> #define rep(i,n) for(int i=0;i<n;i++) using namespace std; int main(){ int n; while(cin>>n and n>0){ string s[n]; rep(i,n) cin>>s[i]; int cnt=0; rep(i,n-1){ if(s[i]=="lu" and s[i+1]=="ru") cnt++; if(s[i]=="ru" and s[i+1]=="lu") cnt++; if(s[i]=...
0
#include <bits/stdc++.h> using namespace std; struct SegmentTree { long long l, r, dat, add; } t[4 * 300002]; long long head[300002], ver[300002 * 2], nxt[300002 * 2], dfs[300002], l; long long n, q, i, w[300002], top[300002], pos[300002], son[300002], size[300002], fa[300002], dep[300002], dfn[300002], tim, root...
5
#include <bits/stdc++.h> using namespace std; const long long t9p7 = 1000000007; void soln(long long t) { long long m, n, k, a, b, c, cnt = 0, ans = 0, mn = LONG_LONG_MAX, mx = LONG_LONG_MIN; string str; cin >> n; vector<long long> arr(n), pre_1(n + 2, 0); for (long long(i) = (1)...
1
#include <bits/stdc++.h> using namespace std; int a, b, r; int shang[105], xia[105]; int go(int i, int j) { if (i < j) { swap(i, j); } int r = 1; while (i % j != 0) { r = i % j; i = j; j = r; } return j; } int main() { while (cin >> a >> b) { int si = 0, xi = 0; bool sb = 0, xb = 0...
2
#include <bits/stdc++.h> using namespace std; string ans; long long a[400000], b[400000], f[400000]; long long n, i, j, m, d; string s; bool p[300]; int x, y; int main() { int t; cin >> t; while (t--) { cin >> d >> m; f[0] = 1 % m; long long sum = 1 % m; long long cur = 2, i = 1; while (cur <=...
4
#include <bits/stdc++.h> using namespace std; double dp[2002][2002]; int main() { int n, t; double p; cin >> n >> p >> t; dp[0][0] = 1; for (int i = 0; i <= t; i++) for (int j = 0; j <= n; j++) { if (j == n) dp[i + 1][j] += dp[i][j]; else { dp[i + 1][j + 1] += p * dp[i][j]; ...
4
#include <bits/stdc++.h> using namespace std; int zerk(char s) { char k = 0; for (int i = 0; i < 4; i++) k = k + (s / ((int)(pow(2.0, i))) % 2) * pow(2.0, 7 - i) + (s / ((int)(pow(2.0, 7 - i))) % 2) * pow(2.0, i); if (k < 0) return k + 256; else return k; } int main() { char *s = new char[...
3
#include <bits/stdc++.h> int three[1111], rest[1111]; int main() { int t, a, i, j, answer = 0, m = 0, e = 0, r = 0, n; scanf("%d", &t); for (i = 1; i <= t; i++) { answer = 0, e = 0, r = 0, m = 0; scanf("%d", &n); for (j = 1; j <= n; j++) { scanf("%d", &three[j]); } for (j = 1; j <= n; j+...
2
#include <bits/stdc++.h> using namespace std; int main() { double a, b, c, d, p, q, prob; cin >> a >> b >> c >> d; p = a / b; q = (1 - c / d) * (1 - a / b); prob = p / (1 - q); printf("%.8lf", prob); return 0; }
2
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long int x1, y1, x, y; cin >> x >> y >> x1 >> y1; long long int sum = abs(x - x1) + abs(y - y1); if (x != x1 && y != y1) sum = sum + 2; cout << sum << endl; } }
1
#include <bits/stdc++.h> using namespace std; int n; struct pt { long long x, y, xc; }; pt ar[200000]; int fw[200001]; int xoc[200001]; inline void fa(int v) { if (xoc[v]) return; xoc[v] = 1; while (v <= 200000) { fw[v]++; v += (v & -v); } } inline long long sa(int id) { long long tt = 0; while (i...
6
#include <bits/stdc++.h> using namespace std; const int MAXN = 100 + 10, INF = 1e9; int a[MAXN], mat[MAXN][MAXN], d[MAXN]; bool mark[MAXN]; set<pair<int, int> > s; pair<int, int> p[MAXN]; int n, alpha; void dijkstra(int cur) { for (int k = 0; k < n; k++) { mark[cur] = true; int x = cur; for (int i = 0; i ...
2
#include <bits/stdc++.h> using namespace std; int x; long long X; long long ans[200001]; int n, i, a; int main() { scanf("%d", &n); a = 0; for (i = 1; i <= n; i++) { scanf("%d", &x); X = x; while (a >= 0) if (X == ans[a]) { X += 1; a--; } else break; ans[++a] = ...
5
#include <bits/stdc++.h> #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; constexpr long long mod = 998244353; const long long INF = mod * mod; const long double eps = 1e-12; const long double pi = acosl(-1.0); long long mod_pow(long long x, long long n, lo...
6
#include <bits/stdc++.h> using namespace std; vector<int> v[200005]; queue<pair<int, int> > q; bool visited[200005]; vector<int> vv[5]; void solve() { int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) { v[i].clear(); visited[i] = 0; } for (int i = 1; i <= m; i++) { int l, r; cin >> l >> r;...
5
#include <bits/stdc++.h> using namespace std; const int Imx = 2147483647; const int mod = 1000000007; const long long Lbg = 2e18; inline long long getnum() { register long long r = 0; register bool ng = 0; register char c; c = getchar(); while (c != '-' && (c < '0' || c > '9')) c = getchar(); if (c == '-') ...
6
#include <bits/stdc++.h> using namespace std; long long bin_pow(long long a, long long b) { if (b == 0) return 1; if (b % 2 == 0) { long long t = bin_pow(a, b / 2); return t * t % 1000000007; } else return a * bin_pow(a, b - 1) % 1000000007; } int main() { ios::sync_with_stdio(false); cin.tie(0); ...
3
#include <iostream> #include <algorithm> using namespace std; static const int MAX = 1000; static const int VMAX = 10000; int A[MAX], B[MAX], T[VMAX+1]; int s, n; int solve() { int ans = 0; bool V[MAX]; for (int i = 0; i < n; i++){ B[i] = A[i]; V[i] = false; } sort(B, B + n); ...
0
#include <bits/stdc++.h> using namespace std; bool check(vector<int> freq1, vector<int> freq2) { for (int i = 0; i < 26; i += 1) { if (freq2[i] > freq1[i]) return false; } return true; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; string s; cin >> s; vector<vector...
2
#include <bits/stdc++.h> using namespace std; int main() { int a, b; while (~scanf("%d%d", &a, &b)) { for (int i = 0; i <= 1000005; i++) { if (i <= a) continue; else { int sum = i; int sums = 0; vector<int> vec; vec.clear(); while (sum) { int...
2
#include <bits/stdc++.h> int main() { int rows, days, a[105]; int test_cases; scanf("%d", &test_cases); while (test_cases--) { scanf("%d %d", &rows, &days); for (int i = 1; i <= rows; i++) { scanf("%d", &a[i]); } while (days--) { for (int i = 2; i <= rows; i++) { if (a[i] > 0...
1
#include <bits/stdc++.h> using namespace std; int GCD(int A, int B) { if (!B) return A; return GCD(B, A % B); } int main() { int i, n, r, c; scanf("%d", &n); for (i = sqrt(n); i > 0; i--) { if (n % i == 0) { r = i; c = n / i; break; } } printf("%d %d\n", r, c); return 0; }
1
#include <cstdio> #include <iostream> #include <algorithm> #include <queue> #include <map> #define F first #define S second using namespace std; int n; int f[111111]; int x[111111]; int y[111111]; priority_queue< pair<int,int> > que[3][4]; int main(void){ cin >> n; for(int i = 0; i < n; i++){ cin >> x[i] >> y[i...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 5005; struct node { int v; int w; node(int _v, int _w) { v = _v, w = _w; } }; int dp[maxn][5005]; vector<node> G[maxn]; const int INF = 1e9 + 7; int ans[maxn][5005]; int path[maxn]; int main() { int n, m, u, v; int k, w; scanf("%d%d%d", &n, &m, ...
3
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; class { public: long long dp[100009]; vector<pair<int, int> > V[100009]; long long n, X[100009], T[100009]; void solve() { long long TT; cin >> n >> TT; for (int i = 1; i <= n; i++) cin >> X[i]; for (int i = 1; i <= n;...
6
#include <bits/stdc++.h> using namespace std; string sep(string s) { string res = ""; for (int i = 0; i < int((s).size()); ++i) { if (s[i] == '>' && s[i + 1] == '<') { res += s[i]; res += ' '; } else res += s[i]; } return res; } void ps(string s, int n) { for (int i = 0; i < n; ++i) ...
2
#include <bits/stdc++.h> using namespace std; int n, ans; int main() { scanf("%d", &n); ++n; printf("%d\n", n >> 1); }
1
#include <bits/stdc++.h> using namespace std; bool ccw(pair<long long, long long> p0, pair<long long, long long> p1, pair<long long, long long> p2) { double lv = 0.0; lv += double(p0.first) * double(p1.second); lv += double(p1.first) * double(p2.second); lv += double(p2.first) * double(p0.second); do...
2
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18; const long double eps = 1e-6; const long long maxn = 1e5; signed main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); long long n; cin >> n; string s; cin >> s; vector<pair<long long, long long>> v(n); for (long long ...
2
#include <bits/stdc++.h> using namespace std; string s; vector<pair<int, int> > v; void rev(int st, int ed) { int i, j; string sec; for (i = st; i <= ed; i++) { sec += s[i]; } reverse(sec.begin(), sec.end()); for (i = st, j = 0; i <= ed; i++, j++) s[i] = sec[j]; } int main() { int t, n, k, i, j, got; ...
1
#include <bits/stdc++.h> using namespace std; int n; bool valid(int x) { return x >= 1 && x <= n; } int main() { long long a, b, c, d, R = 0; cin >> n >> a >> b >> c >> d; int x, y, z, w; for (int i = 1; i <= n; i++) { x = i; y = b + x - c; z = a + x - d; w = z + b - c; if (valid(y) && valid...
2
#include <bits/stdc++.h> using namespace std; char s[2500]; int n; long long res, a[2500]; bool pal[2500][2500]; void innit() { n = strlen(s); int i, j; for (i = n; i >= 1; i--) s[i] = s[i - 1]; s[n + 1] = '\n'; for (i = n; i >= 1; i--) for (j = i; j <= n; j++) if ((s[i] == s[j]) && ((i + 1 >= j) ||...
4
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; int main() { ios_base::sync_with_stdio(false); ; cin.tie(0); ; cout.tie(0); ; int tc, n, s, k; cin >> tc; while (tc--) { unordered_map<int, int> m; cin >> n >> s >> k; for (int i = 0, ent; i < k; i++) { cin >> ...
1
#include <bits/stdc++.h> const int MAXN = 1005, MAXM = 1005; template <typename _T> void read(_T &x) { x = 0; char s = getchar(); int f = 1; while (s > '9' || s < '0') { if (s == '-') f = -1; s = getchar(); } while (s >= '0' && s <= '9') { x = (x << 3) + (x << 1) + (s - '0'), s = getchar(); } ...
1
#include <bits/stdc++.h> using namespace std; const int N = 1000; int n, a[N]; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int main() { scanf("%d", &n); int g = 0; for (int i = 0; i < n; i++) { scanf("%d", a + i); g = gcd(g, a[i]); } if (g != a[0]) { puts("-1"); return 0; } ...
3
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long t = 1, caseno = 0; while (t--) { long long n; cin >> n; long long bin[6]; for (long long i = 0;...
1
#include <bits/stdc++.h> using namespace std; const int N = 55, M = 2e4 + 5; int n, m, k, animal[N][M], sum[N][M], lmax[N][M], rmax[N][M], dp[N][M]; int maxv[M << 2], lazy[M << 2]; int get(int i, int s, int e) { return sum[i][e] - sum[i][s - 1]; } void pushdown(int id) { if (lazy[id] == 0) return; int d = lazy[id];...
6
#include <cstdio> #define rep( i, a, b ) for( int i = (a) ; i <= (b) ; i ++ ) #define per( i, a, b ) for( int i = (a) ; i >= (b) ; i -- ) typedef long long LL; const int mod = 1e9 + 7; const int MAXN = 5e6 + 5, MAXM = 2e5 + 5; template<typename _T> void read( _T &x ) { x = 0;char s = getchar();int f = 1; while( s...
5
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; int f = 0, s = 0, t = 0; int i; for (i = 1; i <= 6; i++) { int dist1 = i - a; if (dist1 < 0) dist1 = dist1 * -1; int dist2 = i - b; if (dist2 < 0) dist2 = dist2 * -1; if (dist1 < dist2) f++; else ...
1
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int a[3]; int i = 0; for (i = 0; i < 3; i++) cin >> a[i]; sort(a, a + 3); int c = a[2] - a[0] - a[1]; if (c < 2) cout << "Yes" << endl; else cout << "No" << endl; } return 0; }
1
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int t; cin >> t; while (t--) { map<long long int, long long int> m; long long int n, k, d; cin >> n >> k >> d; long long int a[n]; for (long long int i = 0; ...
2
#include <bits/stdc++.h> using namespace std; long long ans; vector<unsigned> e[1000001]; unsigned i, j, n, m, a[1000000], b[1000000]; unsigned long long t, c[1000001]; int main() { scanf("%d%d", &n, &m); for (i = 0; i < m; ++i) { scanf("%d%d", a + i, b + i); --a[i]; --b[i]; e[a[i]].push_back(b[i]);...
3
#include<iostream> using namespace std; int a[100000],n; int part(int a[],int p,int r) { int x=a[r]; int i=p-1; for(int j=p;j<r;j++) { if(a[j]<=x) { i++; swap(a[i],a[j]); } } swap(a[i+1],a[r]); return i+1; } int main() { cin>>n; for(int i=0;i<n;cin>>a[i++]); int q=part(a,0,n-1); for(int i=0;i<...
0
#include <bits/stdc++.h> using namespace std; int main() { string s; int n; cin >> n >> s; sort(s.begin(), s.end()); cout << s << endl; return 0; }
1
#include<bits/stdc++.h> using namespace std; int mod; long long dp[404][404]; long long C[1005][1005]; int qpow(long long x,int n){ long long ans=1; for(;n;n>>=1,x=x*x%mod)if(n&1)ans=ans*x%mod; return ans; } int main(){ int n; scanf("%d%d",&n,&mod); dp[1][1]=1; for(int i=0;i<=2*n;i++){ for(int j=0;j<=i;j++){ ...
5
#include <bits/stdc++.h> using namespace std; const long long P = 998244353; const long long N = 4e5 + 5; long long fpow(long long x, long long k) { if (k < 0) return 0; long long ans = 1, base = x; while (k) { if (k & 1) ans = 1ll * ans * base % P; base = 1ll * base * base % P, k >>= 1; } return ans;...
6
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int t; cin >> t; long long int x = 0; while (t--) { string s; cin >> s; if (s[1] == '+') x++; else x--; } cout << x << "\n"; return 0; }
1
#include <bits/stdc++.h> using namespace std; long long memo[52][52][52][52]; long long presum[52][52] = {0}; int n; long long sum(int u1, int v1, int u2, int v2) { return presum[u2][v2] + presum[u1 - 1][v1 - 1] - presum[u1 - 1][v2] - presum[u2][v1 - 1]; } long long dp(int u1, int v1, int u2, int v2) { if ...
6
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const double eps = 1e-6; const int INF = 0x3f3f3f3f; const int maxn = 2e5 + 11; int N, M, T, P, Q; int col[maxn]; list<int> v0; list<int> G[maxn]; vector<int> bv; vector<int> bG[maxn]; int p[maxn]; void init(int n) { fill(p, p + n + 1, 0); ...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 1004; int main() { int n, m; while (scanf("%d %d", &n, &m) == 2) { int ans = 0; for (int i = 1; i * m <= n; i++) ans++; int tmp = ans; for (int i = n + 1; ans; i++) { ans--; if (i % m == 0) { ans++; tmp++; ...
1
#include <bits/stdc++.h> using namespace std; int const inf = 1000 * 1000 * 1000; long long const inf64 = 1ll * inf * inf; int const N = 100005; bool prime[N]; vector<int> d[N]; int color[N]; int arr[N]; int sz; int main() { for (int i = 0; i < N; i++) prime[i] = 1; prime[0] = prime[1] = 0; for (int i = 2; i * i ...
2
#include <bits/stdc++.h> using namespace std; vector<long long> a; char op[3]; long long res; void Gao(vector<long long> a) { if (a.size() == 1) { if (res == -1) res = a[0]; else res = min(res, a[0]); return; } vector<long long> tmp; for (int i = 0; i < a.size(); i++) for (int j = i ...
2
#include <bits/stdc++.h> int n = 0; int T[100010] = {0}; int main() { scanf("%d", &n); int m = n; int in = 0; while (m--) { scanf("%d", &in); T[in] = T[in - 1] + 1; } int ans = 0; for (int i = 1; i <= n; i++) { if (ans < T[i]) { ans = T[i]; } } printf("%d", n - ans); return 0; ...
1
#include<bits/stdc++.h> using namespace std; using i64 = int64_t; int main(){ int n; cin >> n; vector<i64> v; for(int i=0;i<n;++i){ i64 a; cin >> a; v.push_back(a); } sort(v.begin(), v.end()); i64 ans = 0; if(n%2){ for(int i=0;i<n/2;++i)ans -= v[i]*2; ...
0
#include <iostream> using namespace std; int main(void){ int n; int i; int ans; while(cin>>n){ ans=n+1; for(i=0;i<n;i++){ ans+=i; } cout<<ans<<endl; } return(0); }
0
#include <bits/stdc++.h> using namespace std; using ll = long long; ll n, m; vector<ll> a; bool solve(ll x) { ll start = 0; for (auto i : a) { if (i <= start && i + x >= start) { } else if (start + m <= i + x) { } else if (i < start) { return false; } else { start = i; } } return...
1
#include <bits/stdc++.h> using namespace std; int main(void) { string a; cin >> a; int len = a.length(); int flag = 0; for (int i = 0; i < len; i++) { bool work = false; int v = a[i]; int u = v - 1; if (u < 97) { work = false; } else { work = true; flag = 1; a[i] = ...
1
#include <bits/stdc++.h> using namespace std; using uint = unsigned int; using ll = long long; const int M = 1e9 + 7; const ll MLL = 1e18L + 9; #pragma unused(M) #pragma unused(MLL) template <class... T> void printl(T&&...) {} template <class... T> void printc(T&&...) {} template <class... T> void prints(T&&...) {} int...
3
#include <iostream> #include <fstream> #include <sstream> #include <string> #include <cstring> #include <vector> #include <set> #include <map> #include <unordered_map> #include <queue> #include <deque> #include <stack> #include <algorithm> #include <bitset> #include <cmath> #include <cstdlib> #include <ctime> #include ...
0
#include<iostream> #define MAX 1000001 #include<vector> #include<set> using namespace std; int main(){ int n,a,b; while(cin>>n>>a>>b,n){ int ans=0; vector<int> tab(MAX);tab[0]=1; for(int i=min(a,b);i<=n;i++){ if(i-a>=0&&tab[i-a]){ tab[i]=1; ans++; }else if(i-b>=0&&tab[i-b]){ tab[i]=1; ans+...
0
#include <bits/stdc++.h> using namespace std; char a[120][120]; int main() { int n, m, x, y, count = 0, flag = 0; cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (a[i][j] == 'B') { flag = 1; x = i; y = j; ...
1
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); void solve() { long long h1; cin >> h1; ; long long h2; cin >> h2; ; long long a; cin >> a; ; long long b; cin >> b; ; h1 += 8 * a; if (h1 >= h2) { cout << 0 << endl; return; } if (a <= b) { cout << -1 ...
1
#include<bits/stdc++.h> using namespace std; int main(){ int n,i,j,k,ans=0;cin>>n; int a[n]; bool u[n],c[n],q[n]; for(i=0;i<n;i++) scanf("%d",&a[i]); memset(c,0,sizeof(c)); memset(q,0,sizeof(q)); for(i=0;i<n;i++){ if(q[i]) continue; j=i; memset(u,0,sizeof(u)); while(!((!u[j]&&q[j])||c[j]))...
0
#include <bits/stdc++.h> using namespace std; const long long bas = 1331, Mod = 1e9 + 7; long long n, ans[1000000 + 5], has[1000000 + 5], _[1000000 + 5]; char ch[1000000 + 5]; inline long long Calc(register long long x, register long long y) { return (has[y] - has[x - 1] * _[y - x + 1] % Mod + Mod) % Mod; } signed ma...
6
#include <bits/stdc++.h> int flag; int main() { int y, k, n, x; scanf("%d%d%d", &y, &k, &n); x = k - y % k; while (y + x <= n) { printf("%d ", x); x += k; flag = 1; } if (!flag) printf("-1"); return 0; }
1