solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; using ld = long double; using ll = long long; using ull = unsigned long long; const ll mod = 1004535809, mod_g = 3; const int N = int(1e5 + 10); template <typename T> inline T read() { T x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '...
5
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main(){ string s; cin >> s; bool isE=false; for(int i = 1;i < s.size();i ++){ if(s[i]==s[i-1]) {cout << i << " " << i+1 << endl;isE=1;break;} if(i-1&&s[i]==s[i-2]) {cout << i-1 << " " << i+1 << endl;isE=1;break;} ...
0
#include <bits/stdc++.h> using namespace std; int main() { int n,r,l,a=0; cin>>n; for(int i=0; i<n; i++){ cin>>r>>l; a+=l-r+1; } cout<<a; }
0
#include <bits/stdc++.h> using namespace std; long long cnt, ina, sa, in, aaaa, aaaaa, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, sum, maxi, maxj, mini, minj, ser, res; long long aa[100007], aaa[17], bb[17]; string s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10; char c1, c2, c3, ...
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t ; while(t--) { long long int x, y ; cin >> x >> y ; cin.ignore(); string path ; int flagx=0 , flagy =0 ; getline(cin,path); if (x<0) { x = x*(-1) ; if (count(p...
1
#include <bits/stdc++.h> using namespace std; template <class T> void swaper(T &a, T &b) { T c = a; a = b; b = c; } template <class T> T GCD(T a, T b) { if (b == 0) return a; else return GCD(b, a % b); } template <class T> T MulMod(T a, T b, T mod) { T x, y; x = 0; y = a; while (b > 0) { i...
1
#include <bits/stdc++.h> using namespace std; int N, K; vector<int64_t> V[200000]; priority_queue<int64_t> Q; priority_queue<int64_t, vector<int64_t>, greater<int64_t>> P, R; priority_queue<pair<int64_t, int>> T; vector<int> c_order; bitset<200000> c_used; int co = 0; int64_t irregular = 0; int64_t pick(){ if(...
0
#include<bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; long long a[n]; for (auto &it : a) cin >> it; sort(a, a + n); long long ans = a[n - 1], pref_sum = a[0]; for (int i = 1; i < n; i++) { ans += -1 * 1LL * (1LL * i * a[i] - pref_sum); pref_sum += a[i]...
3
#include <bits/stdc++.h> using namespace std; map<int, int> mmp; map<int, int>::iterator it; int main() { long long ans = 1; int n, m, x; cin >> n >> m; for (int i = 1; i <= m; i++) cin >> x, mmp[x]++; if (n > m) cout << 0 << endl; else if (n == m) cout << 1 << endl; else { for (int i = 2; i <...
2
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC target( \ "fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") #pragma GCC optimize("unroll-loops") template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (co...
5
#include <bits/stdc++.h> using namespace std; using lint = long long int; using pint = pair<int, int>; using plint = pair<lint, lint>; struct fast_ios { fast_ios() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; template <typename T> void ndarray(vector<T> &...
6
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; const int inf = 1e5 + 5; const int MAXM = 1e5 + 5; const int MAXN = 2e5 + 4; long long s; bool cal(long long x) { long long xx = x, cnt = 0; while (xx) { cnt += (xx % 10); xx /= 10; } return (x - cnt) >= s; } int main() { long lo...
3
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; int n, m; int mat[110][10010]; char str[10010]; queue<int> que; void bfs(int r) { int cur, nxt; while (!que.empty()) { cur = que.front(); que.pop(); nxt = cur + 1; if (nxt > m) nxt = 1; if (mat[r][nxt] == -1) { que.p...
1
#include <bits/stdc++.h> using namespace std; long long MOD = 1000000007; long long dr[800000]; long long pr[800000]; long long sf[800000]; long long w[800000]; long long a[800000]; void bl(long long v, long long l, long long r) { if (r == l + 1) { dr[v] = w[l]; pr[v] = 0; sf[v] = 0; return; } bl(...
3
#include <bits/stdc++.h> using namespace std; string vow = "aeiou"; const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2}; const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1}; const int dx[] = {-1, 0, 0, 1}; const int dy[] = {0, -1, 1, 0}; const long double pie = 3.14159265358979; const long long mod = 1e9 + 7; void bad() ...
2
#include<cmath> #include<cstdio> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); for (; ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') f = -1; for (; ch >= '0' && ch <= '9'; ch = getchar()) x = (x << 1) + (x << 3) + ch - '0'; return x * f; } const double pi = acos(-1.0); cons...
0
#include <bits/stdc++.h> using namespace std; long long n, m, k; long long a[1011][1011] = {}, p; long long sx[1011] = {}, sy[1011] = {}; long long heap[2011] = {}, num = 0; long long prx[1000011] = {}, pry[1000011] = {}; void heap_add(long long x) { heap[++num] = x; long long i = num; while (i > 1) { if (hea...
2
#include <bits/stdc++.h> using namespace std; long long n, m, ans, t, pn, cnt; long long a[200010], s[500050], num[1000010]; bool vis[200010]; void find_(long long n) { pn = 0; for (long long i = 2; i * i <= n; ++i) { if (n % i == 0) { s[pn++] = i; while (n % i == 0) n /= i; } } if (n != 1) ...
3
#include <bits/stdc++.h> using namespace std; void fastIO() { ios_base::sync_with_stdio(false); cin.tie(NULL); } void solve() { long long int l, r, d; cin >> l >> r >> d; if (d < l) { cout << d << "\n"; return; } else { long long int rem = r % d; rem = d - rem; cout << r + rem << "\n"; ...
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; int a[n], i; for (i = 0; i < n; i++) { cin >> a[i]; } int l[n], r[n], ans = INT_MIN; l[0] = 1; r[n - 1] = 1; for (i = 1; i < n; i++) { if (a[i] > a[i - 1]) { l...
4
#include <bits/stdc++.h> using namespace std; int a[100005]; int b[100005]; int main() { ios::sync_with_stdio(false); int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; b[i] = a[i]; } sort(b + 1, b + 1 + n); int ans = 0; for (int i = 1; i <= n; i++) { if (a[i] != b[i]) ans++; } ...
1
#include <bits/stdc++.h> using namespace std; const int MAXN = 100 * 1000 + 10; const double EPS = 1e-9; const long long MOD = 1000 * 1000 * 1000 + 7; int n, m; void swap_columns(vector<vector<int> > &v, int a, int b) { for (int i = 0; i < v.size(); ++i) { swap(v[i][a], v[i][b]); } } bool is_ok(vector<int> &a) ...
2
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; struct segmentTree { int n = 0; vector<long long> t; vector<long long> lazy; void build(int len) { n = len + 1; t.resize(len * 4); lazy.resize(len * 4); } void push(int p, int l, int r) { if (!lazy[p]) return; if (l !=...
5
#include <bits/stdc++.h> int a, b, c; int m[105][105]; int main() { scanf("%d%d%d", &a, &b, &c); for (int i = 0; i < a; i++) for (int j = 0; j < b; j++) scanf("%d", &m[i][j]); bool locked[105]; int used[105]; int out[105]; memset(locked, false, sizeof locked); memset(out, 0, sizeof out); for (int i ...
2
#include <bits/stdc++.h> using namespace std; long long ans[200050]; pair<long long, long long> A[200050]; queue<long long> q; int n, s; int main() { scanf("%d%d", &n, &s); long long free = 0; for (int i = 0; i < n; ++i) { scanf("%I64d %I64d", &A[i].first, &A[i].second); if (A[i].first < free) { if ...
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int x, y, z; cin >> x >> y >> z; if (x == y && y >= z) { cout << "YES\n"; cout << x << " " << z << " " << z << "\n"; } else if (x =...
1
#include <bits/stdc++.h> using namespace std; int n, k, l; int a[2000005], z[2000005]; long double d[2000005]; int resi() { for (int i = 0; i < 2 * n; i++) z[i + 1] = z[i] + a[i]; long double lo = 1e-7, hi = l + 1; int steps = 50, sol = 0; while (steps--) { long double mid = (lo + hi) / 2; for (int i = ...
6
#include<bits/stdc++.h> long long a[4] = {1}; char s[100005]; int main(){ scanf("%s", s); for(char c:s) for(int j = 3; j >= 0; j--) a[j] = (a[j]*(c-'?'?1:3) + (j&&!(c-'?'&&c-'A'-j+1)?a[j-1]:0))%1000000007; printf("%lld\n", a[3]); }
0
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j; int a[101]; int ans, k; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &a[i]); } ans = 0; for (i = 0; i < n; i++) { k = 0; for (j = i; j < n; j++) { k ^= a[j]; ans = max(k, ans); } } printf("%...
1
#include <bits/stdc++.h> using namespace std; double c, d, e, f, r, v, g, h, i, j, k, l, m, n, o, p, q, t, x, y, z; long long int mn = 8675435789, mx = -8675868757, md = 1000000007, aa = 0, bb = 0, cc = 0; string s, u, w; long long int a[250002], b[250002]; map<long long int, long long int> mp, mq; queue<...
1
#include <bits/stdc++.h> const int N = 2e5 + 10, Mod = 998244353; namespace Fast_IO { const int bufsize = 1 << 22; inline char Getchar() { static char buf[bufsize], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, bufsize, stdin), p1 == p2) ? EOF : *p1++; } templat...
4
#include <bits/stdc++.h> using namespace std; int main() { double d, h, v, e; cin >> d >> h >> v >> e; double decrease = v / ((d / 2) * (d / 2) * acos(-1)); double add = e; if (decrease > add) { cout << "YES" << endl; printf("%.12f\n", h / (decrease - add)); } else { cout << "NO" << endl; } ...
1
#include <bits/stdc++.h> using namespace std; typedef long long lint; typedef pair<int, int> pi; int n, a[100005], b[100005]; int hs[100005], he[100005]; int main(){ cin >> n; for(int i=1; i<=n; i++) scanf("%d",&a[i]); for(int i=1; i<=n; i++) scanf("%d",&b[i]); for(int i=1; i<=n; i++){ if(a[i] != a[i-1]){ hs[...
0
#include <bits/stdc++.h> using namespace std; struct edge { int to, p1, p2; }; bool vis[100010]; int dp[100010][2][2][2]; vector<edge> G[100010]; const int md = 1e9 + 7; int con[100010][2]; void add(int &x, int y) { x += y; if (x >= md) x -= md; } void dfs(int x) { vis[x] = true; bool f = false; for (int i ...
3
#include<iostream> #include<vector> #include<map> #include<queue> #include<algorithm> using namespace std; const int N = 13; const vector<vector<int>> NEXT = { {2}, {2, 5}, {0, 1, 3, 6}, {2, 7}, {5}, {1, 4, 6, 9}, {2, 5, 7, 10}, {3, 6, 8, 11}, {7}, {5, 10}, {6, 9, 11, 12}, ...
0
#include <bits/stdc++.h> using namespace std; struct edge { int y; edge* next; }; edge* new_edge() { static edge a[1000005]; static int top = 0; return &a[top++]; } edge* li[1000005]; void insert_edge(int x, int y) { edge* t = new_edge(); t->y = y; t->next = li[x]; li[x] = t; } long long sums[1000005]...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 5e3 + 50; int f[maxn][maxn]; int mod[8], pos[100005], s[maxn]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &s[i]); int ans = -1; memset(f, 0, sizeof(f)); for (int i = 0; i < n; i++) { memset(pos, 0, sizeof(p...
4
#include <bits/stdc++.h> using namespace std; const long long EPS = 1e-15; int toInt(string s) { int sm; stringstream second(s); second >> sm; return sm; } int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; } int main() { int n, k, remaining = 0, flag = 0; std::cin >> n >> k; c...
2
#include <bits/stdc++.h> using namespace std; int flag[10000010] = {0}; void init() { for (int i = 4; i <= 10000010; i += 2) flag[i] = 2; for (int i = 3; i <= 10000010 / i; i += 2) { if (flag[i] == 0) { for (int j = i * i; j < 10000010; j += i * 2) flag[j] = i; } } } void func(vector<int>& ans, vect...
3
#include <bits/stdc++.h> using namespace std; int binary_search(int a[], int n, int x) { int low = 0, high = n - 1, result = -1, mid = 0; while (low <= high) { mid = low + (high - low) / 2; if (a[mid] == x) { return mid; } else if (a[mid] > x) { result = mid; high = mid - 1; } else...
2
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 5; vector<int> v[N]; bool viz[N]; int cnt; pair<long long, long long> a[N]; void dfs(int x) { viz[x] = 1; cnt++; for (auto it : v[x]) if (!viz[it]) dfs(it); } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); vector<pair<lo...
4
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int q; cin >> q; while (q--) { int n; long long int m; cin >> n >> m; long long int t[n + 1], l[n + 1], r[n + 1]; t[0] = 0; for (int i = 1; i <= n; i++) cin >> t[i] >> l[i] >> r[...
3
#include<bits/stdc++.h> using namespace std; #define ll long long int main(){ ll a,b; cin>>a>>b; if(a<=9&&b<=9) cout<<a*b; else cout<<-1; }
0
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int w, b; cin >> w >> b; for (int i = 0; i < w; i++) { for (int j = 0; j < b; j++) { if (i == 0 && j == 0) { cout << "W"; } else { cout << "B"; } } co...
1
#include <iostream> using namespace std; int main(){ int n; cin >> n; int s = 0, m = 0; for(int i=0; i<n; i++){ int L; cin >> L; s += L; m = max(m, L); } if(m < s - m){ cout << "Yes" << endl; } else{ cout << "No" << endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; #define ll long long constexpr ll inf = 1e9+7; ll solve(vector<ll> As, bool flag) { ll ans = 0; ll sum = 0; for (auto A : As) { sum += A; if (flag && sum <= 0) { ans += 1 - sum; sum = 1; } else if (!flag && sum >= 0) { ans += 1 + sum; ...
0
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long a, b; cin >> a >> b; if (a == b) { cout << 0 << endl; continue; } if (a < b) { if ((b - a) % 2 == 1) { cout << 1 << endl; } else { cout << 2 << endl; ...
1
#include<iostream> #include<vector> #include<algorithm> using namespace std; string pls(string a,string b) { string ret; reverse(a.begin(),a.end()); reverse(b.begin(),b.end()); if(a.size()<b.size())swap(a,b); while(b.size() !=a.size() )b+='0'; while(ret.size()!=a.size()+1)ret+='0'; for(int i=0;i < a.size(); i...
0
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; struct Trie { const static int ALPHA_SIZE = 2; char base = 'a'; vector<vector<int> > g; vector<int> pref, words; int nxt = 1; int move_to(int u, int c) { if (g[u][c] == -1) { g[u][c] = nxt++; g.push_back(vector<int>(...
3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t, a, b; cin >> t; vector<int> primeDivisor(5000001), prime_factors(5000001), prefixSum(5000001); for (int i = 2; i < 5000001; i++) { if (primeDivisor[i] != 0) continue; for (int j = i; j < 50000...
4
#include <bits/stdc++.h> const double pi = acos(-1); const int MOD = 1e9 + 7; const int INF = 1e9 + 7; const int MAXN = 1e6 + 5; const double eps = 1e-9; using namespace std; char str[MAXN], ans[MAXN]; int a[MAXN], b[MAXN], ca[MAXN]; int main() { int n, m; scanf("%s", str); n = strlen(str); scanf("%d", &(m)); ...
5
#include <iostream> using namespace std; int main() { int n; while (cin >> n){ if (n % 39 == 0){ cout << "3C" << "39" << endl; } else if (n % 39 < 10){ cout << "3C0" << n % 39 << endl; } else { cout << "3C" << n % 39 << endl; } } return (0); }
0
#include <bits/stdc++.h> using namespace std; char s[25]; int main() { scanf("%s", s); int len = strlen(s); set<string> Set; string p; for (int i = 0; i <= len; ++i) { if (i) p = p + s[i - 1]; for (int j = 0; j < 26; ++j) { string tag = p; tag = tag + (char)(j + 'a'); for (int k = i;...
1
#include <bits/stdc++.h> #pragma warning(disable : 4996) const long long MOD = 998244353; const long long Mod = 998244352; const int maxn = 2e5 + 5; const double Inf = 10000.0; const double PI = acos(-1.0); using namespace std; int bitcount(int x) { return x == 0 ? 0 : bitcount(x / 2) + (x & 1); } int _popcount(int x) ...
1
#include <bits/stdc++.h> using namespace std; const int N = 1e5; int n; string s[N]; unordered_map<string, int> mp; unordered_map<string, bool> u; int main() { ios_base ::sync_with_stdio(false); cin >> n; for (int i = 1; i <= n; ++i) { cin >> s[i]; for (int j = 0; j < (int)s[i].size(); ++j) { string...
2
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 9; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; int aa = 0, da = 0, ab = 0, db = 0; for (int _ = (int)(0); _ < (int)(n); ++_) { int type, a, b; cin >> type >> a >> b; if (type == ...
1
#include <bits/stdc++.h> int main() { char s1[10], s2[10], s3[10]; gets(s1); int m, t1, t2, tm, hr, minn, xh, xm; scanf("%d", &m); s2[0] = s1[0]; s2[1] = s1[1]; s2[2] = '\0'; s3[0] = s1[3]; s3[1] = s1[4]; s3[2] = '\0'; int n1, n2; n1 = atoi(s2); n2 = atoi(s3); if (m > 60) { t1 = m - (60 ...
2
#include <iostream> #include <vector> #include <cstdio> #include <cmath> using namespace std; const double INF = 1e10; int main(){ int n; while(cin>>n,n){ vector<double> x(n),y(n),z(n),r(n); for(int i=0;i<n;++i){ cin>>x[i]>>y[i]>>z[i]>>r[i]; } double edge[100][100]; for(int i=0;i<n;++i){ for(int j=...
0
#include <bits/stdc++.h> using namespace std; long long n, l, k; long long a[1000006]; long long f[1000005]; int nn; long long c[1000005]; long long ans; long long dq; long long s[1000005]; const long long mod = 1e9 + 7; int lowbit(int x) { return x & (-x); } long long sum(int x) { long long ans = 0; for (int i = x...
2
#include <bits/stdc++.h> using namespace std; template <typename T> T gcd(T a, T b) { if (a == 0) return b; return gcd(b % a, a); } template <typename T> T pow(T a, T b, long long m) { T ans = 1; while (b > 0) { if (b % 2 == 1) ans = (ans * a) % m; b /= 2; a = (a * a) % m; } return ans % m; } co...
4
#include<iostream> #include<cstdio> #include<vector> #include<queue> #include<algorithm> #include<cstring> #define MAX_N 10000 using namespace std; typedef pair<int, int> P; const int INF = 1 << 30; int dp[2][MAX_N / 2 + 1][2]; int main() { int n, ans = INF, t[MAX_N + 1] = {}; cin >> n; for (int i = 0; i < 2; i++) {...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 1100; int n, m, w; int dp[maxn][maxn][3]; struct node { int w, b, p; } a[maxn]; int Find(int x) { return a[x].p == x ? x : a[x].p = Find(a[x].p); } bool cmp(node x, node y) { return x.p < y.p; } void upd(int x, int z, int &y) { if (x == -1) return; y ...
2
#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; while (t--) { long long int n, m; cin >> n >> m; long long int prev = 0; long long int mn = m; long long int mx = m; bool flag = fals...
3
#include<bits/stdc++.h> #define int long long using namespace std; int n,res=1; signed main(){ scanf("%lld",&n); while(n--){ int a; scanf("%lld",&a); if(a==0) return puts("0"),0; else if(1000000000000000000/a<res) res=-1; if(res!=-1) res*=a; if(res>1000000000000000000) res=-1; } printf("%lld",res); retur...
0
#include<iostream> #include<algorithm> using namespace std; int main(){ long n,i,a[5000],t,x; while(cin>>n,n){ for(i=0;i<n;i++)cin>>a[i]; x=-100000; for(t=i=0;i<n;i++){ if(t<0)t=a[i];else t+=a[i]; if(x<t)x=t; } cout<<x<<endl; } return 0; }
0
#include <iostream> #include <limits.h> #include <queue> #include <algorithm> #include <map> #include <cstring> #define dprintf(s,...) printf("%s:%d" s,__func__,__LINE__,__VA_ARGS__) using namespace std; typedef pair<int,int> P; typedef long long int ll; int N,K; int S[101],B[101][101]; bool solve(){ for(int...
0
#include<bits/stdc++.h> using namespace std; int main(){ int a,b,c; cin>>a>>b>>c; cout<<a+b+c-max(a,max(b,c))<<endl; return(0); }
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; const long long MOD = 1e9 + 7; const long long LINF = 0x3f3f3f3f3f3f3f3f; const int INF = 1e9 + 7; const double PI = acos(-1.0); const double EPS = 1e-8; int _; using namespace std; int arr[MAXN]; int cnt[1005]; int mat[105][105]; int N; void fill_4...
3
#include <bits/stdc++.h> using namespace std; template <typename T> inline void debug(vector<T> li) { for (auto v : li) { cout << v << " "; } cout << "\n"; } template <typename T> inline void debug(vector<vector<T>> li) { for (auto v1 : li) { for (auto v2 : v1) { cout << v2 << " "; } cout ...
1
#include <bits/stdc++.h> using namespace std; struct apple { int data, no, has; } a[2001011 * 2]; int ff[2001011], father[2001011], dian_sum[2001011], bian_sum[2001011], maxx[2001011], sub_maxx[2001011], n, m, ans; bool cmp1(apple aa, apple bb) { return aa.data < bb.data; } bool cmp2(apple aa, apple bb) { return ...
6
#include <bits/stdc++.h> using namespace std; bool pal(string s, int start, int end) { if (s[start] != s[end]) return 0; else if (start >= end) return 1; else return pal(s, ++start, --end); return 0; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); string merged; cin >...
1
#include <bits/stdc++.h> using namespace std; int main() { string s; map<string, int> m; while(cin >> s) { m[s]++; } string r1, r2; for(auto& p : m) { if(m[r1] < p.second) { r1 = p.first; } if(r2.size() < p.first.size()) { r2 = p.first; ...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, i, k, y; scanf("%d", &n); int x[n]; for (i = 0; i < n; i++) { scanf("%d", &x[i]); scanf("%d", &y); } k = 0; for (i = 0; i < n; i++) { if (x[i] <= 0) k++; } if (k <= 1) printf("Yes\n"); else if (n - k <= 1) printf("...
1
#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; while (t--) { long long int n; cin >> n; long long int a[n]; for (long long int i = 0; i < n; i++) cin >> a[i]; if (n == 1) { c...
3
#include <bits/stdc++.h> using namespace std; int main() { long long t; long long n, x, y, d; cin >> t; while (t--) { cin >> n >> x >> y >> d; if (y != 1 && y != n && abs(y - x) % d != 0 && abs(y - 1) % d != 0 && abs(n - y) % d != 0) { cout << -1 << endl; } else if (abs(y - x) % d == 0...
1
#include <bits/stdc++.h> using namespace std; const long long M = 1e9 + 7; int n, b, k, x; struct A { long long m[105][105]; } a, E; inline A mul(const A& p, const A& q) { A res; for (int i = 0; i < x; i++) for (int j = 0; j < x; j++) { res.m[i][j] = 0; for (int l = 0; l < x; l++) res.m[i]...
5
#include <bits/stdc++.h> using namespace std; int m, n; int ans[150]; int dp[2050][2050]; // S?????????????????£?????? using Set = bitset<12>; int rec(int asked, int answer){ // ??????????????????aked???answer??¨?????????????????? int &res = dp[asked][answer]; if(res != -1) return res; res = m; int ...
0
#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]; int result = 0; for (int i = *max_element(a.begin(), a.end()); i >= 0; --i) { if (i < *max_element(a.begin(), a.end())) for (int j = 0; j < n; ++j) if (a[j...
2
#include <bits/stdc++.h> using namespace std; const long long maxn = 3e5 + 5; const long long mod = 1e9 + 7; const long long inf = 1e9; const long long del = 728729; long long poww(long long a, long long b, long long md) { return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md ...
5
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 2002; const ll MOD = 1e9 + 7; int n, k; char s[N]; ll f[N][N][3]; inline void Add(ll& x, ll y) { (x += y) %= MOD; } void Solve() { f[0][0][0] = 1; for (int i = 1; i <= n; ++i) { for (int j = 0; j <= k; ++j) { Add(f[i][j][0],...
3
#include <bits/stdc++.h> using namespace std; long long a, b, n, x; const int mod = 1e9 + 7; long long ans; long long aced(long long i, long long k) { if (k == 0) return 1; long long tmp = aced(i, k / 2); if (k % 2 == 1) return 1LL * tmp * tmp % mod * i % mod; else return 1LL * tmp * tmp % mod; } int ma...
4
#include <cstdlib> #include <cmath> #include <climits> #include <cfloat> #include <map> #include <utility> #include <set> #include <iostream> #include <memory> #include <string> #include <vector> #include <algorithm> #include <functional> #include <sstream> #include <deque> #include <complex> #include <stack> #include ...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long n, m; cin >> n >> m; long long heights[n]; long long blocks = 0; for (int i = 0; i < (n); i++) { cin >> heights[i]; blocks += heights[i]; } sort(heights, heights + n); long long nec...
2
#include<bits/stdc++.h> using namespace std; int main(){ int n,k; cin>>n>>k; int h[n]; for(int i=0;i<n;i++)cin>>h[i]; sort(h, h+n); int ans=1000000000; for(int i=0;i<n-k+1;i++){ ans=min(ans, h[i+k-1]-h[i]); } cout<<ans<<endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int n, x, k, m; const int MAXN = 200010; long long int a[MAXN]; vector<long long int> maxs; string b[MAXN]; void to2(int a, string &s) { while (a) { s += char(a % 2) + '0'; a /= 2; } reverse(s.begin(), s.end()); } int main() { scanf("%d %d %d", &n, &k, &x); ...
2
#include <bits/stdc++.h> using namespace std; int N, M, Q, B; int init[100010]; vector<int> sets[100010]; long long initsum[100010]; int bigsetID[100010]; int common[350][100010]; bool iselement[100010]; void pre(void) { int i, j, k; for ((i) = 0; (i) < (int)(M); (i)++) for ((j) = 0; (j) < (int)(sets[i].size())...
3
#include<iostream> using namespace std; #define MAX 500 int main(){ int n; int w,h; int map[MAX+1][MAX+1]; int x,y; int s,t; int cnt,max; while(1){ cin>>n; if(n==0) break; cin>>w>>h; for(int i=1;i<=h;i++){ for(int j=1;j<=w;j++){ map[i][j]=0; } } for(int i=0;i<n;i++){ cin>>x>>y; ...
0
#include <bits/stdc++.h> using namespace std; const int dr[4] = {0, 0, -1, 1}, dc[4] = {-1, 1, 0, 0}; class Dijkstra { int N; vector<vector<pair<int, int> > > E; public: Dijkstra(int n) { N = n; E = vector<vector<pair<int, int> > >(N + 1); } void insert(int u, int v, int w) { E[u].push_back(make_pai...
2
#include <bits/stdc++.h> using namespace std; int dx[] = {1, -1, 0, 0}; int dy[] = {0, 0, 1, -1}; int P1 = 1e9 + 7; int P2 = 1e9 + 9; int pw[(int)4e4 + 100], pw2[(int)4e4 + 100]; vector<int> pos[300]; int main() { int n; scanf("%d", &n); int N = n * (n - 1) / 2; if (n == 2) { int k, x; scanf("%d%d", &k,...
2
#include <bits/stdc++.h> using namespace std; set<long long> used; int main() { long long a, b, c; long long x, y, z; long long hc; long long sol, sag; long long res = 0; cin >> a >> b >> x >> y; for (int i = 30; i >= 0; i--) { hc = (1LL << i); c = (a / hc + 1) * hc; z = (x / hc + 1) * hc; ...
3
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 10; const long long inf = -1e18; const long long INF = 1e18; const long long mod = 1e9 + 7; const double PI = acos(-1); string a, b; int l, r, f, ans = 80000, cnt, z[5010]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL), cout.tie(...
1
#include <bits/stdc++.h> using namespace std; int n, m; int iid[500060]; struct node { int w, id; } a[500060]; bool cmp(node x, node y) { return x.w < y.w; } int find(int x, int &len, int &fl) { if (fl == 1) { int l = x, r = n, mid; while (l < r) { mid = (l + r + 1) >> 1; if (a[mid].w - a[x].w <...
4
#include <iostream> using namespace std; int main(void){ int n; cin>>n; cout<<((n/10 == 9 || n%10 == 9)?"Yes":"No")<<endl; }
0
#include <bits/stdc++.h> using namespace std; int c[1 << 22], pre[1 << 22], a[1 << 22], n, m, ans[25], d[25], r, t; int main() { scanf("%d%d", &n, &m); for (int i = 0; i < m; i++) { int u, v; scanf("%d%d", &u, &v); u--; v--; d[u] |= (1 << v); d[v] |= (1 << u); } if (m == n * (n - 1) / 2)...
3
#include <bits/stdc++.h> using namespace std; long long arr[100000]; int main() { long long maxi = 0; int n; cin >> n; for (int i = 0; i < n; i++) { cin >> arr[i]; maxi = max(maxi, arr[i]); } long long left = maxi; long long right = 10000000000LL; while (left < right) { long long midd = (lef...
1
#include <bits/stdc++.h> using namespace std; int main() { long long z1, z2, l, m1, m2, l2; long long B, W; long long n, x, y; cin >> n; cin >> x >> y; z1 = (x - 1) + (y - 1); W = z1; m1 = (n - x) + (n - y); B = m1; if (n >= 2 && x >= 1 && y >= 1 && x <= n && y <= n) if (W < B) cout << "Wh...
1
#include <bits/stdc++.h> using namespace std; const int K = 700; const double eps = 1e-20; double dp[K], p[K]; int main() { int n, k; scanf("%d%d", &n, &k); p[1] = 1; for (int i = 1; i <= n; i++) for (int j = min(i + 1, K - 1); j >= 1; j--) { int t = j * k; dp[j] = (t + k - 1) * dp[j] / (t + k) ...
4
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") const int mod = 1000000007; const int N = 100000 + 10; const int MAGIC = 350; int n, m, q, cnt; vector<int> y[N]; int sz[N], to[N]; int delta[N][MAGIC]; int idx[N]; long long sum[N], col[N], a[N]; bool has[MAGIC][N]; cha...
3
#include<iostream> #include<queue> #include<map> #include<cstring> #include<cstdio> #include<cstring> #include<algorithm> #include<string> #include<cstdio> #include<iostream> using namespace std; #define fr first #define sc second #define INF 100 typedef pair<int,int>Pt; int main(){ unsigned long long r=0,l=0,q,a,b; ...
0
#include <bits/stdc++.h> using namespace std; int result[100005]; int dp[100005][3]; int main() { int length; cin >> length; char c; for (int i = 0; i < length; i++) { cin >> c; result[i] = c - '0'; } dp[0][0] = 1; dp[0][1] = 1; dp[0][2] = 0; for (int i = 1; i < length; i++) { if (result[i...
3