solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; int a[n]; int ans = 0; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) { int cnt = 0; for (int j = 0; j < n; j++) { if (a[j] >= i) cnt++; } if (cnt >= i) { if (i > ans) ans = i; ...
1
#include <bits/stdc++.h> const double Pi = acos(-1.0); using namespace std; const int maxN = 1000005; const long long mod = 1000000007; int n, k; long long fact[maxN]; long long dp[maxN], sum[maxN]; long long exp(long long x, long long p) { long long res = 1; while (p) { if (p & 1) res = (res * x) % mod; x ...
3
#include <bits/stdc++.h> using namespace std; const int N = 400010; int n, m, h, t, i; int deg[N], ss[N], ff[N], pred[N], last[N], used[N]; int main() { scanf("%d %d %d %d", &n, &m, &h, &t); for (i = 0; i < m; i++) scanf("%d %d", ss + i, ff + i); for (i = 0; i < m; i++) { ss[i + m] = ff[i]; ff[i + m] = ss...
2
// Verified @ GRL_3_A #include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<double, double> pdd; const ull mod = 1e9 + 7; #define REP(i,n) for(int i=0;i<(int)n;++i) //debug #define dump(x) cerr << #x << ...
0
#include<iomanip> #include<limits> #include<thread> #include<utility> #include<iostream> #include<string> #include<algorithm> #include<set> #include<map> #include<vector> #include<stack> #include<queue> #include<cmath> #include<numeric> #include<cassert> #include<random> #include<chrono> #include<unordered_map> #includ...
0
#include <bits/stdc++.h> using namespace std; template <typename TH> void debug_vars(const char* data, TH head) { cerr << data << "=" << head << "\n"; } template <typename TH, typename... TA> void debug_vars(const char* data, TH head, TA... tail) { while (*data != ',') cerr << *data++; cerr << "=" << head << ",";...
5
#include<iostream> #include<cstdio> using namespace std; int n,tot,tmp; int main(){ cin>>n; for(int i=1;i<=n;i++){ cin>>tmp; if((i&1) && (tmp&1))tot++; }cout<<tot; return 0; }
0
#include <bits/stdc++.h> const int MAXN = 100000; int hash[26], val[MAXN + 1], state[MAXN + 1]; inline bool cmp(int a, int b) { return hash[a] > hash[b]; } int main() { static char str[MAXN + 1]; int k; scanf("%s%d", str, &k); int n = strlen(str); for (int i = 0; i < n; ++i) { ++hash[str[i] - 'a']; } ...
1
#include <bits/stdc++.h> #define For(i, a, b) for (int i = a; i <= b; i++) using namespace std; const int mod = 1000000000 + 7, MAXN = 200000 + 5; int val[MAXN], lastF[MAXN]; int main(){ int n; scanf("%d", &n); val[0] = 1; For(i, 1, n){ int k; scanf("%d", &k); val[i] = val[i - 1]...
0
#include <bits/stdc++.h> using namespace std; int main() { char str[1111]; int r, c, count = 0; cin >> r >> c; for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { cin >> str[j]; } } c++; for (int i = 0; i < c - 1; i++) { if (str[i] == 'B' and str[i + 1] != 'B') count++; } cou...
4
#include <iostream> #include <queue> using namespace std; int main() { int n,to=0,ar[101];cin>>n; for (int i=0;i<n;i++) {cin>>ar[i];} for (int i=1;i<n;i++) { if (ar[i]<ar[i-1]) { to+=ar[i-1]-ar[i]; } } cout<<to+ar[n-1]<<"\n"; return 0; }
0
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0; i < (int)(n); ++i) using ll = long long; const ll INF = 1e18; using ld = double; using P = complex<ld>; using G = vector<P>; const ld pi = acos(-1); const ld eps = 1e-10; ld cross(const P& a, const P& b) { return a.real()*b.imag() - a.imag...
0
#include <bits/stdc++.h> using namespace std; long long rev(long long num) { long long res; stringstream second, s1; string str; second << num; second >> str; string tem; tem = str; for (int i = str.size() - 1; i >= 0; i--) { tem += str[i]; } s1 << tem; s1 >> res; return res; } int main() { ...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 1000 * 2 + 5; const long long inf = 9223372036854775807; int n, a[maxn][maxn], mark[maxn]; vector<int> adj[maxn], radj[maxn]; void sfd(int v) { mark[v] = 1; for (auto u : radj[v]) { if (mark[u] == 0) { sfd(u); } } } void dfs(int v) { m...
3
#include <bits/stdc++.h> using namespace std; template <class T> ostream& operator<<(ostream& os, vector<T> V) { for (auto v : V) os << v << " "; return cout << ""; } template <class T> ostream& operator<<(ostream& os, set<T> S) { for (auto s : S) os << s << " "; return cout << ""; } template <class L, class R>...
3
#include <bits/stdc++.h> using namespace std; const long long N = 4e5 + 10; long long n, q, a[N], l, r, type, x, y, HL[19], HR[19], pw[N][19], nxt[N][19]; void build(long long id, long long L, long long R) { long long mid = (L + R) / 2; if (R - L == 1) { for (long long i = 0; i < 10; i++) { long long q = ...
6
#include <bits/stdc++.h> using namespace std; long long int modulo = 1000003; int main() { string s; cin >> s; if (s[int(s.size()) - 1] == '*' or s[int(s.size()) - 1] == '/' or s[int(s.size()) - 1] == '+' or s[int(s.size()) - 1] == '-') { cout << 0 << endl; exit(0); } for (int i = 0; i < int(s.s...
4
#include<iostream> #include<iomanip> #include<string> #include<algorithm> #include<cmath> using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);i++) #define REP(i,n) for(int i=0;i<(n);i++) #define PII pair<int,int> #define EPS (1e-10) #define equals(a,b) (fabs((a)-(b))<EPS) #define MP make_pair class Point; clas...
0
#include <bits/stdc++.h> using namespace std; const int infint = INT_MAX; const long long infll = LLONG_MAX; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; long long sum = 0; vector<long long> arr(n), cp(n); int nzero = -1; for (int i = 0; i < n; i++) { cin...
3
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") using namespace std; using ll = long long; using ld = long double; using db = double; using str = string; using pi = pair<int, int>; using pl = pair<ll, ll>; using pd = pair<db, db>; using vi = vector<int>; using vb = vector<bool>...
3
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll N = 1e6 + 10; vector<ll> f[N]; void add(ll i, ll first) { for (; i < N; i |= i + 1) { f[i].push_back(first); } } void build() { for (ll i = 0; i < N; ++i) { sort(f[i].begin(), f[i].end()); } } ll query(ll i, ll first) { ll s ...
5
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll inf = LONG_LONG_MAX; const ll N = 1e5 + 5; ll p[N]; ll c[N]; vector<ll> adj[N]; vector<ll> v; void dfs(ll node, ll par) { ll valid = (p[node] != (-1) and c[node]); for (ll i : adj[node]) { if (c[i] == 0) { valid = 0; } df...
3
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 10; const double eps = 1e-8; char a[MAXN], b[MAXN]; int c1[MAXN], c2[MAXN]; int main() { scanf("%s %s", a + 1, b + 1); int lena = strlen(a + 1); int lenb = strlen(b + 1); int max_len = 0; int j = 1, i; for (i = 1; i <= lena; i++) { if ...
4
#include <bits/stdc++.h> using namespace std; int length(char word[]) { for (int i = 0; i < 100; i++) { if (word[i] == '\0') { return i; } } return 100; } int length(int adad) { int i = 0; while (adad >= 1) { adad /= 10; i++; } return i; } int reverse(int adad) { int reversed = 0; ...
2
#include <bits/stdc++.h> using namespace std; inline void file() { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); } int arr2[100][100]; void solve() {} bool check(int p, int q, int n, int m) { for (int j = 0; j < m; j++) { if (arr2[p][j] == 1) return true; } for (int j = 0; j < n; j...
2
#include <bits/stdc++.h> using namespace std; struct node { int a, b, c, d; node() {} node(int A, int B, int C, int D) { a = A, b = B, c = C, d = D; } } ans[500005]; vector<int> G[2][500005]; int n, cnt; int f[500005]; int fa[2][500005]; void dfs(int u, int k) { for (int i = 0; i < G[k][u].size(); i++) { in...
5
#include <bits/stdc++.h> using namespace std; long long int s, m, k, nr1, nr2, n, i, Apa[30], Ap[30][30], j, l, mx; char sir[10000], a, b, aux; int main() { cin >> n; for (j = 0; j < n; j++) { cin >> sir; l = strlen(sir); k = 1; nr1 = 1; a = sir[0]; for (i = 1; i < l; i++) { if (sir[i]...
1
#include <bits/stdc++.h> using namespace std; int main(void) { int n; cin >> n; while (n--) { string s; cin >> s; int ans = 0; map<pair<int, int>, set<char> > m; pair<int, int> pos = {0, 0}; for (auto e : s) { if (m[pos].find(e) != m[pos].end()) { if (e == 'N') pos.second++; ...
3
#include <string> #include <cstdio> int main(){ std::string s; for(int c;~(c=getchar());){ if(c=='B')s.pop_back(); else s.push_back(c); } printf(s.c_str()); }
0
#include <bits/stdc++.h> using namespace std; long long int n, r, av; bool cmp(const pair<int, int> &p1, const pair<int, int> &p2) { if (p1.second < p2.second) return 1; else if (p1.second == p2.second) { return p2.first > p1.first; } return 0; } int main() { ios_base::sync_with_stdio(false); cin.ti...
3
#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <climits> #include <cfloat> #include <ctime> #include <cassert> #include <map> #include <utility> #include <set> #include <iostream> #include <memory> #include <string> #include <vector> #include <algorithm> #include <functional> #include...
0
#include <bits/stdc++.h> using namespace std; long long maxn = 0, minn = 1e18; long long tot; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } void js(long long x) { if (x <= 0 || x > tot) return; long long gg = gcd(x, tot); long long tmp = tot / gg; maxn = max(maxn, tmp); minn = min(...
4
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; long long int p, k; cin >> p >> k; vector<long long int> out; long long int a = p, b; do { b = ((a % k) + k) % k; a = (b - a) / k; out.push_back(b); } while (a != 0); ...
4
#include <string> #include <vector> #include <sstream> #include <iostream> #include <algorithm> #include <map> #include <list> #include <set> #include <numeric> #include <queue> #include <stack> #include <cstdio> #include <cmath> #include <cstdlib> #include <cctype> #include <cstring> #include <climits> #include <cfloa...
0
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > vec[((int)1e5 + 5)]; vector<int> ans[2]; int col[((int)1e5 + 5)], vis[((int)1e5 + 5)]; bool dfs(int n, int c) { vis[n] = 1; ans[c].push_back(n); col[n] = c; for (auto p : vec[n]) { int a = p.first, b = p.second; b = b ^ c; if (!vi...
2
#include <bits/stdc++.h> using namespace std; long long int MOD = 1000000007; long long int MX = 1000000000000000; long long int t, n, k; long long int a[200]; long long int rep[200]; long long int res[200]; int main() { ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); cin >> t; while (t--) { cin >...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; const int mod = 1e9 + 7; const int inf = 0x3fffffff; int father[maxn], cnt[maxn]; int k[maxn], l[maxn]; int n, m; void initial() { for (int i = 1; i <= maxn; i++) father[i] = i; } int findFather(int x) { int a = x; while (x != father[x]) x =...
5
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-9; const double PI = 3.141592653589793238462; map<long long, long long> x, y; map<pair<long long, long long>, long long> pts; int main() { int n; cin >> n; long long ans = 0; long long xi, yi; for (int i = 0; i < n; i++) { cin >> xi >> yi...
1
#include <bits/stdc++.h> using namespace std; using lint = long long; using pi = pair<int, int>; const int MAXN = 500005; const int mod = 998244353; int n, a[MAXN]; vector<lint> solve(){ vector<lint> dap; dap.push_back(0); dap.push_back(0); vector<pi> stk; for(int i=1; i<n; i++){ int flr = 0; if(a[i-1] < a[i...
0
#include <bits/stdc++.h> using namespace std; long long a[100007], k; const long long MOD = 1e9 + 7; long long fastpow(long long x, long long y) { if (!y) return 1; long long recurse = fastpow(x, y / 2); if (y % 2) return ((recurse * recurse) % MOD * x) % MOD; return (recurse * recurse) % MOD; } long long inv(l...
5
#include <bits/stdc++.h> using namespace std; const int MAX = 1e6 + 5; const int mod = 1e9 + 7; const long double pi = acos(-1); mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); vector<long long> seg, a; long long build(int idx, int l, int r) { if (l == r) { seg[idx] = a[l]; return seg[idx...
3
#include <bits/stdc++.h> using namespace std; const long long mx = 10000007; const long long mod = 1e9 + 7; const double pi = acos(-1); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; long long n, k; cin >> n >> k; vector<pair<long long, long long>> v; for (long long i = 0; i < n; i++) { ...
2
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; bool ok; int n, num[3], rt, c[3][N], u, v; vector<int> E[N], f; int ans[N]; void dfs(int x, int fa) { f.push_back(x); for (int v : E[x]) { if (v == fa) continue; dfs(v, x); } } long long solve(int x) { f.push_back(0); dfs(x, -1); ...
4
#include <bits/stdc++.h> using namespace std; void ga(int N, int *A) { for (int i(0); i < N; i++) scanf("%d", A + i); } int S[(1 << 18)], dp[(1 << 18)][2], N; int dyn(int u, bool x) { if (u == N) return x ? S[N - 1] : 0; int &v = dp[u][x]; if (~v) return v; if (!x) return v = dyn(u + 1, 1); return v = max(S...
5
#include <bits/stdc++.h> using namespace std; inline int read() { int num = 0, k = 1; char ch = getchar(); while (ch > '9' || ch < '0') { if (ch == '-') k = -1; ch = getchar(); } while (ch <= '9' && ch >= '0') { num *= 10, num += ch - 48, ch = getchar(); } return num * k; } struct point { lo...
4
#include <bits/stdc++.h> using namespace std; int main() { char s[105]; cin >> s + 1; int n = strlen(s + 1); bool ans = 0; for (int i = 1; i <= n; i++) if (isalpha(s[i]) && isalpha(s[i - 1]) && isalpha(s[i + 1]) && s[i] != s[i - 1] && s[i] != s[i + 1] && s[i - 1] != s[i + 1]) ans = 1; cout...
1
#include <iostream> #include <algorithm> using namespace std; struct block { int wt, st; long long val; bool operator < (const block &b) const { return wt+st < b.wt+b.st; } }; int n; block a[1010]; long long dp[20010]; long long o = 0; int main () { cin >> n; for (int i=0; i<n; i++) { cin >> a[i].wt >> a[i].s...
0
#include <iostream> #include <cmath> #include <map> #include <string> #include <queue> using namespace std; static const int LIMIT = 100; static const int N = 4; static const char dir[4] = {'r', 'l', 'u', 'd'}; static const int dx[4] = {0, -1, 0, 1}; static const int dy[4] = {1, 0, -1, 0}; int MD[N*N][N*N]; class P...
0
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define fr(i,n) for(int i=0;i++<n;) int main(){ int n,m,a,b,c[55]={}; cin>>n>>m; fr(i,2*m){ cin>>a; c[a]++; } fr(i,n) cout<<c[i]<<endl; }
0
#include <bits/stdc++.h> int main() { char a[15], b[15]; int M[12], m1, m2, m3, i; gets(a); gets(b); if (strcmp(a, "monday") == 0) m1 = 1; if (strcmp(a, "tuesday") == 0) m1 = 2; if (strcmp(a, "wednesday") == 0) m1 = 3; if (strcmp(a, "thursday") == 0) m1 = 4; if (strcmp(a, "friday") == 0) m1 = 5; if ...
1
#include <bits/stdc++.h> using namespace std; string f1, f2; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { int x, y, r; cin >> x >> y >> r; if (i) f1 += "+"; if (i) f1 += "(" + to_string(x / 2) + "*(2-abs(((0-abs((t-" + to_string(i - 1) + ")))+abs((t-" + to_string(i...
3
#include <bits/stdc++.h> using namespace std; struct Node { int l; int id; } node[1100]; bool cmp1(const Node &a, const Node &b) { return a.l > b.l; } bool cmp2(const Node &a, const Node &b) { return a.id < b.id; } int n, k; int zuo[110][110]; inline int ABS(int a) { if (a < 0) return -a; return a; } int main()...
2
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; map<string, int> mp; long long ans = 0; for(int i = 0; i < n; i++){ string s; cin >> s; sort(s.begin(), s.end()); ans += mp[s]; mp[s]++; } cout << ans << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n, p, m, a, b, c, d, e, sum = 0, l = -1000000; string name, max; cin >> n; for (int i = 0; i < n; i++) { cin >> name; cin >> p >> m >> a >> b >> c >> d >> e; sum = (p * 100) - (m * 50) + a + b + c + d + e; if (sum > l) { max = ...
1
#include <bits/stdc++.h> using namespace std; int main() { int T; cin >> T; while (T--) { int x, y, a, b; cin >> x >> y >> a >> b; int t; if ((x - y) % (a + b) == 0) cout << abs((x - y) / (a + b)) << endl; else cout << "-1" << endl; } }
1
#include <bits/stdc++.h> using namespace std; int main() { int sum = 0; map<int, int> a; for (int i = 0; i < 5; i++) { int l; cin >> l; a[l]++; if (a[l] > 3) a[l] = 3; sum += l; } int max = 0; map<int, int>::iterator it; for (it = a.begin(); it != a.end(); it++) if (max < it->first...
1
#include <bits/stdc++.h> using namespace std; const int N = 2005; int step[N]; int main() { int n, k, x; while (~scanf("%d%d", &n, &k)) { memset(step, 0, sizeof(step)); set<int> s; for (int i = 0; i < k; i++) { scanf("%d", &x); s.insert(x); } queue<int> q; q.push(0); bool fla...
3
#include <iostream> using namespace std; int w[1000]; int m; int n; bool kuwa(int s) { int t = s; int l = m; for(int i = 0; i < n; i++) { if (t - w[i] >= 0) { t -= w[i]; }else{ t = s; l --; i --; if (l <= 0) { return false; } } } return true; } int bi...
0
#include <bits/stdc++.h> using namespace std; void Solve() { long long a, b, c; cin >> a >> b; c = abs(a - b); cout << c / 5 + (c % 5) / 2 + (c % 5) % 2 << endl; } int main() { int _; for (cin >> _; _--;) Solve(); }
1
#include <bits/stdc++.h> using namespace std; int n, p[200005]; int ans[200005]; queue<int> q; int main() { int Q; cin >> Q; while (Q--) { memset(ans, 0, sizeof(ans)); cin >> n; for (int i = 1; i <= n; i++) cin >> p[i]; for (int i = 1; i <= n; i++) { if (ans[i]) continue; int step = 1;...
2
#include <bits/stdc++.h> using namespace std; const int MOD7 = 1000000000 + 7; const int MOD9 = 1000000000 + 9; int main() { int t = ({ int x; scanf("%d", &x); x; }); for (int _ = (0); _ < (t); _ += (1)) { int n = ({ int x; scanf("%d", &x); x; }); string a, b; cin >> ...
6
#include <iostream> #include <vector> using namespace std; int n, k; string str; int nxt[26]; vector<int> v[26]; int bit[200005]; inline void add(int i, int x){ i++; while(i<200005){ bit[i]+=x; i+=i&-i; } } inline int sum(int i){ i++; int ret=0; while(i){ ret+=bit[i]; i-=i&-i; } return ...
0
#include <bits/stdc++.h> using namespace std; long long n; long long H; long long d[1000001]; long long pre[1000001]; int id_minx = -1; long long R = 0; int main() { cin >> H >> n; long long sum = 0; for (int i = 1; i <= n; i++) { scanf("%I64d", &d[i]); pre[i] += pre[i - 1]; pre[i] += d[i]; if (id...
5
#include <cmath> #include <cstdio> #include <string> #include <cstring> #include <iostream> #include <algorithm> using namespace std; typedef long long ll; const int M=45; const int N=1e3+5; int n,m,lim,tmp[M]; ll X[N],Y[N]; template <typename _Tp> inline void IN(_Tp&x) { char ch;bool flag=0;x=0; while(ch=getchar()...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int x = n / 4; int rem = n % 4; for (int i = 0; i < x; i++) { cout << "abcd"; } if (rem == 1) cout << "a"; else if (rem == 2) cout << "ab"; else if (rem == 3) cout << "abc"; return 0; }
2
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { string s[9]; for (int i = 0; i < 9; i++) cin >> s[i]; for (int i = 0; i < 9; i++) { for (int j = 0; j < 9; j++) { if (s[i][j] == '2') s[i][j] = '1'; ...
4
#include <bits/stdc++.h> int n, i; using namespace std; int main() { cin >> n; for (int j = 0; j < n; j++) { cin >> i; if (i == 1) { cout << "HARD\n"; return 0; } } cout << "EASY\n"; return 0; }
1
#include <bits/stdc++.h> using namespace std; char _; const int maxN = 2000 + 5; const int mod = 1000 * 1000 * 1000 + 7; const int base = 701; const int SQ = 600; const int maxL = 20; pair<int, int> a[maxN]; long long dis(pair<int, int> p, pair<int, int> q) { int dx = p.first - q.first; int dy = p.second - q.second...
3
#include<iostream> using namespace std; int main(){ int n; cin >> n; int ma[105][105]={{}}; int i,j; long long o=0; for(i=0;i<n;i++){ for(j=0;j<n;j++){ cin >> ma[i][j]; } } for(i=0;i<n;i++){ for(j=i;j<n;j++){ o+=min(ma[i][j],ma[j][i]); } } cout << o << endl; }
0
#include <bits/stdc++.h> using namespace std; const int MX = (1 << 20); int cnt(char ch) { if (islower(ch)) return ch - 'a' + 1; if (isupper(ch)) return ch - 'A' + 27; if (isdigit(ch)) return ch - '0' + 53; } int hashy(char a, char b) { int let1 = cnt(a), let2 = cnt(b); return (let1 - 1) * 62 + let2; } vector...
4
#include<iostream> #include<string> using namespace std; int main() { string s,result; cin >> s; s.insert(s.begin() + 4,' '); cout << s << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int n; double d; struct station { int x; int y; double refill; int dist(const station& other) { return abs(other.x - x) + abs(other.y - y); } }; struct state { int idx; double dist; }; auto cmp = [](const state& l, const state& r) { return l.dist > r.dist; }; pr...
2
#include <bits/stdc++.h> using namespace std; int main() { int Soma = 0; bool K = false; int Soma2 = 0; int N, i; string S; scanf("%d", &N); cin >> S; for (i = 0; i < N / 2; i++) { if (S[i] == '4') { Soma += 4; } else { if (S[i] == '7') { Soma += 7; } else { K =...
1
#include <bits/stdc++.h> using namespace std; const long long maxn = 5e3 + 10; long long sumb[maxn], N; signed main() { ios::sync_with_stdio(false); cin.tie(0); string str; cin >> str; N = str.size(); for (register long long i = 1; i <= N; ++i) { sumb[i] = sumb[i - 1] + (str[i - 1] == 'b'); } long l...
2
#include <bits/stdc++.h> using namespace std; inline long long pow(long long x, long long y, long long p) { long long t = 1; for (; y; y >>= 1, x = x * x % p) if (y & 1) t = t * x % p; return t; } struct Node { int a, b, c; bool operator<(const Node& o) const { if (a == o.a) return b > o.b; return...
4
#include <bits/stdc++.h> using namespace std; long long int n, k, i; int main(void) { scanf("%I64d %I64d", &n, &k); float lim = sqrt(n); std::vector<long long int> v; for (i = 1; i <= lim; ++i) { if (n % i == 0) v.push_back(i); } long long int q = v.size(); if (n == 1) { switch (k) { case 1:...
1
#include <bits/stdc++.h> using namespace std; long long int ll_max(long long int a, long long int b, long long int c) { return max(a, max(b, c)); } int int_max(int a, int b, int c) { return max(a, max(b, c)); } long long int ll_min(long long int a, long long int b, long long int c) { return min(a, min(b, c)); } int...
1
#include <bits/stdc++.h> using namespace std; const int MAXN = 1003; const long long MOD = 1000000007; const int M = 2 * 2 * 2 * 3 * 3 * 5 * 7; int getID(int nd, int rem) { return nd * M + rem; } int n, k[MAXN]; int edge[MAXN * M]; int to[11]; bool vis[MAXN * M]; int dp[MAXN * M]; void mark(int nd) { vis[nd] = true; ...
6
#include <bits/stdc++.h> using namespace std; const int N = 5e3; const long long int LINF = (long long int)1e18; int n, s, t; long long int x[N + 1]; long long int a[N + 1]; long long int b[N + 1]; long long int c[N + 1]; long long int d[N + 1]; long long int dist[N + 1][N + 1]; int nxt[N + 1]; void all_distance() { ...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, res = 0; scanf("%d", &n); for (int i = 1; i < n; ++i) { for (int j = i + 1; j <= n; j += 2) { ++res; } } printf("%d\n", res); for (int i = 1; i < n; ++i) { for (int j = i + 1; j <= n; j += 2) { printf("%d %d\n", i, j);...
5
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double //#define TEST int cnt1(int a) { int cnt = 0; while (a) { a /= 2; ++cnt; } return cnt; } signed main() { int n; cin >> n; vector<ll> a(n); int tmp = 0; vector<int> op; for (int i = 0; i < n; ++i) { cin >> a[i];...
0
// Undone #include <bits/stdc++.h> #define int long long #define double long double #define INF 1e18 #define MOD 1000000007 using namespace std; signed main() { int N; string S; cin >> N >> S; int x = 0, y = 0; for (int i = 0; i < N; i++) { char c = S[i]; if ('A' <= c && c <= 'M') { x++; } el...
0
#include <bits/stdc++.h> using namespace std; int n; int m = 2; int main() { cin >> n; while (n > 1) { if (n % m != 0) { m++; } else { cout << n << " "; n /= m; } } cout << "1" << endl; return 0; }
2
#include <bits/stdc++.h> typedef long long LL; const int N = 8100, M = 210, p = 998244353, G = 3, invG = (p + 1) / 3; int A[N << 2], B[N << 2], fac[N], inv[N], rev[N << 2], f[N][M], n, m; int add(int x, int y) { return x + y >= p ? x + y - p : x + y; } int sub(int x, int y) { return x - y < 0 ? x - y + p : x - y; } ...
0
#include <bits/stdc++.h> using namespace std; int main() { long long n, m; cin >> m >> n; int ss[35] = {}; for (int i = 0; i < n; i++) { cout << 1 << endl; string s; cin >> s; if (s == "1") { ss[i] = 1; } else { ss[i] = -1; } } long long r = 1; while (r <= m) r <<= 1; ...
2
#include <bits/stdc++.h> int main() { long long int n; int pos = 0, k = 0; scanf("%lld", &n); char s[n]; int x, y; scanf("%s", s); if (n == 1 || n == 0) { pos = -1; } for (int i = 0; i < n - 1; i++) { x = s[i]; y = s[i + 1]; if (x > y) { pos = i; break; } else pos...
1
#include <bits/stdc++.h> using namespace std; signed long long n; char ch[5005][5005] = {'0'}; signed long long vis[5005] = {0}; void dfs(signed long long s, signed long long x) { vis[s] = 1; for (signed long long i = 1; i <= n; i++) { if (ch[s][i] == '1') { if (ch[i][x] == '1') { cout << x << " "...
3
#include <bits/stdc++.h> using namespace std; vector<pair<string, long long> > v; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long a = 0, b = 0, c, d, e, f = 0, l, g, m, n, k, i, j, t, p, q; t = 1; while (t--) { cin >> n >> m >> p; for (i = 0; i < n; i++) { ...
3
#include <bits/stdc++.h> using namespace std; long long inp[300009]; long long arr[300009]; struct node { int si, ei; int lf, md, rg; node(int sii, int eii, int lff = 0, int mdd = 0, int rgg = 0) { si = sii; ei = eii; lf = lff, rg = rgg, md = mdd; } node() { si = ei = lf = md = rg = 0; } }; struct...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 1007; int n, a[maxn], b[maxn], ans[maxn]; long long solve(int x) { long long ans = a[x]; b[x] = a[x]; int i = x - 1, j = x + 1; while (i >= 1) { b[i] = min(a[i], b[i + 1]); ans += b[i]; i--; } while (j <= n) { b[j] = min(a[j], b[...
3
#include <bits/stdc++.h> using namespace std; using uint = unsigned int; using ll = long long; using ld = long double; using ull = unsigned long long; using pii = pair<int, int>; using pll = pair<ll, ll>; void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { ...
6
#include <bits/stdc++.h> using namespace std; vector<int> v1, v2, v3; vector<int> pos[26]; int f[251][251][251]; bool used[251][251][251]; string st, op, ch; int n, q, x; inline void check(int x, int y, int z) { if (x < 0 || y < 0 || z < 0) return; if (used[x][y][z]) return; f[x][y][z] = n + 1; if (x > 0) { ...
2
#include <bits/stdc++.h> using namespace std; int main() { string table; string hand; getline(cin, table, '\n'); transform(table.begin(), table.end(), table.begin(), ::tolower); getline(cin, hand, '\n'); transform(hand.begin(), hand.end(), hand.begin(), ::tolower); if (hand.find(table[0]) != -1 || hand.fi...
1
#include <bits/stdc++.h> using namespace std; bool used[100001]; vector<int> seq; int g[100001]; map<int, int> mp; void dfs(int v) { used[v] = true; int to = g[v]; if (!used[to]) dfs(to); seq.emplace_back(v + 1); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<pair<int...
3
#include <bits/stdc++.h> using namespace std; int main() { int i; int TUX; cin >> TUX; int FOO = 0; int BAR = 0; int BAZ = 0; int QUZ = 1; for (i = 0; i < TUX; i++) { int PUR; cin >> PUR; FOO = FOO + PUR; BAR = BAR + 1; if (max(FOO * QUZ, BAR * BAZ) == FOO * QUZ) { BAZ = FOO; ...
3
#include <bits/stdc++.h> using namespace std; int main() { int k,t; cin >> k >> t; vector<int> a(t); for (int i=0;i<t;i++) cin >> a[i]; sort(a.begin(),a.end()); int s=0; for (int i=0;i<t-1;i++) s+=a[i]; cout << max(0,a[t-1]-s-1) << endl; }
0
#include <bits/stdc++.h> using namespace std; const int nm = 210; int n, a[nm][nm], m; int deg[nm], tp[nm], ntp; vector<pair<int, int> > kq; int ori[nm][nm], used[nm][nm]; void dfs(int i) { tp[i] = ntp; for (int j = 1; j <= n; ++j) { if (!tp[j] && a[i][j] > 0) dfs(j); } } void solve() { cin >> n >> m; mem...
5
#include <bits/stdc++.h> using namespace std; int main(){ string s,t,u; int A,B; cin>>s>>t>>A>>B>>u; if(u==s)--A;else --B; cout<<A<<" "<<B; }
0
#include <bits/stdc++.h> using vi = std::vector<long long int>; using vvi = std::vector<vi>; using pii = std::pair<long long int, long long int>; using vpii = std::vector<pii>; using vvpii = std::vector<vpii>; using namespace std; const long long int N = 2e6 + 10; const long long int inf = 1e18 + 10; const long double ...
6
#include<bits/stdc++.h> #define INF 0x3f3f3f3f #define rep(i,n)for(int i=0;i<(n);i++) using namespace std; typedef pair<int, int>P; int c[6], cost[110][1 << 6], m, n, k, d; struct st { int a, b, c; }v[600]; int num(string s) { if (s == "H")return m + n; if (s == "D")return m + n + 1; if (s[0] == 'C')return s[1] - ...
0