solution
stringlengths
53
181k
difficulty
int64
0
27
// AB NAHI HO RHI CPP......... //****************************************** #include<bits/stdc++.h> //***************************** ******** using namespace std ; //*********** * ******** ******** typedef long long int ll; //************ ...
0
#include <bits/stdc++.h> int main() { static char s[1005]; int N; scanf("%d\n", &N); scanf("%s", &(s[1])); static int sum[1005]; sum[0] = 0; int i; for (i = 1; i <= N; i++) { sum[i] = sum[i - 1] + (s[i] == 'H' ? 1 : 0); } int j, res, temp; res = 1000000000; int cnt = N - sum[N]; if ((cnt =...
8
#include <bits/stdc++.h> using namespace std; int mark[6000000]; int main(int argc, char const *argv[]) { int n, m; while (scanf("%d%d", &n, &m) != EOF) { memset(mark, 0, sizeof(mark)); for (int i = 1; i <= n; i++) { mark[2 * i]++; } for (int i = 1; i <= m; i++) { mark[3 * i]++; } ...
8
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int MAX = 200005; int arr[MAX]; double pref[MAX]; double pref2[MAX]; double rec[MAX]; pair<double, double> first(pair<double, double> a, pair<double, double> b) { double x = ((double)(b.second - a.second)) / (a.first - b.first); double ...
16
#include <bits/stdc++.h> using namespace std; long long n, m, k, a, b, c, q = 10000000, d, e, A, B, l, r, w, h, mx, mn = 10000000, t; long long X, Y; vector<string> vs, v1, v2; string s1, qs, s2, s, alph = "abcdefgihjklmnopqrstubwxyz"; char ch; int main() { cin >> t; while (t--) { ci...
3
#include <bits/stdc++.h> using namespace std; const long long inf = 0x3f3f3f3f3f3f3f3f; const int oo = 0x3f; long long s, x; void readf() { cin >> s >> x; } void solve() { long long k; k = s - x; if (k % 2 == 1) { cout << 0; exit(0); } k /= 2; long long ans = 1; for (int i = 0; i <= 40; ++i) i...
9
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> h[500], hv[500]; bool hur[500]; int par[500], parv[500]; bool eler[500]; bool dfs(int p) { eler[p] = 1; for (int q : h[p]) { if ((parv[q] < 0) || ((!eler[parv[q]]) && (dfs(parv[q])))) { par[p] = q; parv[q] = p; return 1; }...
14
#include <bits/stdc++.h> using namespace std; int main() { int t, i; long n, d, arr[2]; cin >> t; while (t--) { cin >> n; i = 0; for (d = 2; d * d < n && i < 2; d++) { if (n % d == 0) { arr[i++] = d; n /= d; } } if (i == 2) cout << "YES\n" << arr[0] << ' ' <...
5
#include <bits/stdc++.h> using namespace std; long long int ar[100009]; int main() { long long int a, b, c, i, j, j1, k; cin >> a >> b >> c; for (i = 1; i <= a; i++) { cin >> ar[i]; } sort(ar + 1, ar + a + 1); j = (ar[c + 1] - ar[c]); cout << j; }
0
#include <bits/stdc++.h> using namespace std; const int maxn = 1e2 + 10; int a[maxn], even[maxn], odd[maxn]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i += 2) odd[i / 2 + 1] = i; for (int i = 2; i <= n; i += 2) even[i / 2] = i; for (int i = 1; i <= n / 2; i++) scanf("%d", &a[i]); sort(a +...
3
#include <bits/stdc++.h> using namespace std; int ans; set<int> nxt; set<int>::iterator it; queue<int> f[3], p[3]; queue<string> faltu[3]; string from[4 * 100005]; int to[4 * 100005]; int tonum(string &s) { if (s[0] == '0') return -1; int ret = 0, x = 0; while (x < s.size()) { if (s[x] < '0' || s[x] > '9') re...
14
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; const int MAX = 1e5 + 10; class Edge { public: int s, e; int w; Edge(int s, int e, int w) : s(s), e(e), w(w) {} }; class MaxQ { public: deque<int> q; void add(int e) { while (!q.empty() && q.back() < e) q.pop_back(); q.push_back(...
16
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; const long long MOD = 1e9 + 7; int n, k; bool col[N]; vector<int> g[N]; int get(int i) { if (i >= n) return i - n; return i; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; cin >> n >> k; string s, t; cin...
6
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const int maxn = 20005; int t[maxn]; int sum[maxn]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", &t[i]); int maxsum = -inf; for (int i = 3; i <= n; i++) if (n % i == 0) { int l = n / i; for (int ...
5
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; for (int i = 0; i < s.size(); i++) s[i] = s[i] - '0'; int ok = 1, i, j; for (i = 0, j = s.size() - 1; i <= j; i++, j--) { if (s[i] == 1 || s[j] == 1) ok = 0; if (s[i] == 2 || s[j] == 2) ok = 0; if (s[i] == 3 && s[j] != ...
11
#include <bits/stdc++.h> using namespace std; int main() { int edge = 0, m, n, x; cin >> m >> n; for (int i = 1; i <= m; i++) for (int j = 1; j <= n; j++) { cin >> x; if (!x) continue; if (i == 1 || i == m || j == 1 || j == n) edge = 1; } cout << (edge ? 2 : 4) << endl; }
2
#include <bits/stdc++.h> using namespace std; int N; int sz[100005], dist[100005], temp[100005], another[100005]; vector<int> graph[100005]; void dfs(int n, int p) { sz[n] = 1; for (int e : graph[n]) { if (e != p) { dist[e] = dist[n] + 1; dfs(e, n); sz[n] += sz[e]; } } } bool chk(int n) ...
16
#include <bits/stdc++.h> inline int getint() { int x = 0, p = 1; char c = getchar(); while (c <= 32) c = getchar(); if (c == 45) p = -p, c = getchar(); while (c > 32) x = x * 10 + c - 48, c = getchar(); return x * p; } using namespace std; const int mod = 1e9 + 7; inline void reduce(int &x) { x += x >> 31 &...
19
#include <bits/stdc++.h> using namespace std; long long t, n, x, y, m, k, a[100005], b[100005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> x >> y; string s; cin >> s; int ans = 0; int cnt = 1; for (int i = n - 1; cnt <= x; i--, cnt++) { if (cnt == y + 1) { if (s[i] == '...
3
#include <bits/stdc++.h> using namespace std; int TC, w[260]; double mean; int main() { srand(1879); int i; scanf("%d", &TC); while (TC--) { mean = 0.0; for (i = 1; i <= 250; i++) { scanf("%d", &w[i]); mean += w[i]; } mean /= 250; double res = 0.0; for (i = 1; i <= 250; i++) ...
13
#include <bits/stdc++.h> using namespace std; struct IO { IO() { ios::sync_with_stdio(0); cin.tie(0); } } io; using ll = long long; using db = long double; using pi = pair<ll, ll>; using mi = map<ll, ll>; const ll mod = 1e9 + 7; const ll INF = 0x3f3f3f3f; ll qpow(ll a, ll b, ll MOD = mod) { for (ll ans = ...
18
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7; const long long mod = 1e9 + 7; const int inf = 0x3f3f3f3f; const double eps = 1e-9; char s[N]; int main() { scanf("%s", s); int l, r, ans, i; int len = strlen(s); for (l = 0; l <= len - 2; l++) { if (s[l] == s[l + 1]) break; } for (r =...
8
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const int maxn = 200005; const long long inf = 1LL << 60; inline int read() { int res, ok = 1; char ch; for (ch = getchar(); ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') ok = -1; res = ch - '0'; for (ch = getchar(); ch >=...
24
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); long long i, j, k; long long n, m; cin >> n >> m; long long grid[1001][1001]; for (i = (0); i < (n); i++) for (j = (0); j < (m); j++) cin >> grid[i][j]; vector<vector<long long> > rows(n), cols(m...
8
#include <bits/stdc++.h> using namespace std; int bigmod(int b, int p, int mod) { if (!p) return 1ll; int ret = bigmod(b, p / 2, mod); ret = (ret * 1ll * ret) % mod; if (p & 1) ret = (ret * 1ll * b) % mod; return ret; } bool pr(int n) { for (int i = 2; i * i <= n; i++) if (!(n % i)) return 0; return 1...
15
#include <bits/stdc++.h> using namespace std; const int N = 200005; int n, m, k; int c[N]; map<int, int> cnt; vector<int> adj[N]; int mark[N]; void dfs(int u) { mark[u] = 1; cnt[c[u]]++; for (auto v : adj[u]) if (!mark[v]) dfs(v); } int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); scanf("%d %d ...
8
#include <bits/stdc++.h> using namespace std; const long maxn = 1e5 + 5; long a[maxn]; long n, q; long dv[25]; int main() { scanf("%ld", &n); for (q = 1; q <= n; q++) scanf("%ld", &a[q]); dv[0] = 1; for (long j = 1; j <= 20; j++) dv[j] = dv[j - 1] * 2; long long answer = 0; for (long it = 1; it < n; it++) {...
2
#include <bits/stdc++.h> using namespace std; int N, K, V; int a[5001]; int modK(int n) { return ((n % K) + K) % K; } enum dpVal { notSet, yes, no }; dpVal dp[5001][5001] = {notSet}; bool choice[5001][5001]; void f() { for (int k = 0; k < K; ++k) dp[N][k] = k ? no : yes; for (int i = N - 1; i >= 0; --i) for (in...
16
#include <bits/stdc++.h> using namespace std; const int T = 105; int p[T]; long long ans; int n, k; int get() { int cur = 0; for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) if (p[i] > p[j]) cur++; return cur; } void DFS(int step) { if (step == k) { ans += get(); return; } for (...
10
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n == 1 || n == 2) cout << "-1" << endl; else if (n == 3) cout << "210" << endl; else { cout << "1"; for (int i = 0; i < n - 4; i++) cout << "0"; if ((n % 6) == 0) cout << "170"; else if ((n % 6) == 1)...
6
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; while (n--) { int a; cin >> a; vector<int> v; for (int i = 1; i <= sqrt(a); ++i) { v.push_back(i); v.push_back(a / i); } vector<int> t; t.push_back(v[0]); for (int i = 1; i < v.size(); ++i) { ...
6
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, p[N]; vector<long long> v; bool vis[N]; int main() { memset(vis, 0, sizeof(vis)); scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", p + i); for (int i = 1; i <= n; i++) { long long cnt = 1; if (vis[i]) continue; vis[...
7
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; const int mod = (int)1e+9 + 7; const double pi = acos(-1.); const int maxn = 100100; bool us[maxn], pm[maxn], now[maxn]; vector<int> rb[maxn]; set<int> st[maxn]; long long cnt1, cnt2; int tim[maxn], nx[maxn], pr[maxn]; bool t = 0; void dfs(int u) { ...
12
#include <bits/stdc++.h> using namespace std; pair<pair<long long, long long>, pair<long long, long long> > a[100010]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { a[i].first.first = i; a[i].first.second = 0; cin >> a[i].second.first; cin >> a[i].second.second; } while (true) { ...
15
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; void solve() { unsigned long long n; cin >> n; string s; cin >> s; vector<unsigned long long> dp(4); dp[0] = 1; for (auto x : s) { if (x == '?') { dp[3] = (dp[3] * 3 + dp[2]) % 1000000007; dp[2] = (dp[2] * 3 + dp[1])...
12
#include<bits/stdc++.h> using namespace std; const int N=100+50; const int mod=1e9+7; using ll=long long; int read(){ int k=0,sig=1; char c=getchar(); while(!isdigit(c)){ if(c=='-') sig*=-1; c=getchar(); } while(isdigit(c)){ k=(k<<3)+(k<<1)+c-'0'; c=getchar(); ...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j, k = -1, t, len, ln, rn; string line, ss = "::", left, right, mid; cin >> n; bool first; for (t = 0; t < n; ++t) { cin >> line; k = -1; for (i = 0; i < line.length() - 1; ++i) { if (line.compare(i, 2, ss) == 0) { ...
7
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 7; const int MX = 4e6 + 7; bool check(int h, int m) { vector<int> d; while (h) { d.push_back(h % 10); h /= 10; } while (m) { d.push_back(m % 10); m /= 10; } for (int x : d) { if (x == 7) return true; } retu...
1
#include <bits/stdc++.h> using namespace std; int main() { long long n, k, i, j, l, m; cin >> n >> k; int a[n][n]; l = 0; m = 0; for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { if (i == l && j == m) { cout << k << " "; l++; m++; } else cout << 0 << " "; ...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, first, sec, c = 0; cin >> n; vector<int> v; vector<int> u; while (n--) { cin >> a >> b; v.push_back(a); u.push_back(b); } for (int i = 0; i < v.size(); i++) { for (int j = 0; j < u.size(); j++) { if (v[i] == u[j]...
0
#include <bits/stdc++.h> using namespace std; pair<long long, pair<long long, long long> > gcd(long long a, long long b) { if (a == 0) return make_pair(b, make_pair(0, 1)); else { pair<long long, pair<long long, long long> > x = gcd(b % a, a); return make_pair( x.first, make_pair(x.secon...
10
#include <bits/stdc++.h> using namespace std; const double esp = 1e-5; int n, m, k; int ki[100010], ik[100010]; int main(int argc, char *argv[]) { while (scanf("%d%d%d", &n, &m, &k) != EOF) { int u; for (int i = 1; i <= n; ++i) { scanf("%d", &u); ki[u] = i; ik[i] = u; } long long ans...
8
#include <bits/stdc++.h> using namespace std; void solve() { long long n1, n2; cin >> n1 >> n2; string a = to_string(n1); string b = to_string(n2); string ans = ""; long long i = a.size() - 1; long long j = b.size() - 1; while (i >= 0 and j >= 0) { if (a[i] <= b[j]) { ans.push_back('0' + (b[j]...
4
#include <bits/stdc++.h> using namespace std; int freq[105], dupfreq[105], food[105]; int main() { int n, m; cin >> n >> m; for (int i = 1; i <= 100; i++) freq[i] = 0; for (int i = 0; i < m; i++) { cin >> food[i]; freq[food[i]]++; } int maxdays = floor(m / n); while (maxdays > 0) { int tempn =...
4
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; int n; long long b[100000], a[100000]; vector<pair<int, int> > adj[100000]; long long dfs(int u) { long long ret = b[u] - a[u]; for (auto v : adj[u]) { long long res = dfs(v.first); if (res < 0) { res = -res; if (res > INF...
15
#include <bits/stdc++.h> using namespace std; const int maxn = 2005, MOD = 7 + 1e9; const int Max_N = 1 << 21; int x[Max_N]; long long bigger[32], smaller[32]; void Divide(int L, int R, int dep) { if (L == R) return; int M = (L + R) >> 1; Divide(L, M, dep + 1); Divide(M + 1, R, dep + 1); for (int i = M + 1; i...
13
#include <bits/stdc++.h> using namespace std; template <class T> void test(T a) { cout << a << endl; } template <class T, class T2> void test(T a, T2 b) { cout << a << " " << b << endl; } template <class T, class T2, class T3> void test(T a, T2 b, T3 c) { cout << a << " " << b << " " << c << endl; } int T; void t...
12
#include <bits/stdc++.h> using namespace std; const int INF = 2147483647; const long long LLINF = 9223372036854775807LL; int rev(int x) { int ans = 0; for (int i = 0; i < 8; ++i) { ans <<= 1; ans |= x & 1; x >>= 1; } return ans; } int main() { string s; getline(cin, s); int prev = 0; for (in...
5
#include <bits/stdc++.h> using namespace std; const long long MAXN = 2 * 1e5 + 100; long long n, m, ans[MAXN], now, fa[MAXN]; long long si[MAXN], cnt; struct node { long long u, v, w; } sh[MAXN]; struct query { long long num, wh; } q[MAXN]; bool cmp(node a, node b) { return a.w < b.w; } bool cmp1(query a, query b) ...
10
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; int n, len, vis[30], to[30], from[30], vis2[30], ans[maxn], cnt; bool flag = true; char s[maxn]; int main() { for (int i = 0; i < 26; i++) from[i] = to[i] = -1; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%s", s + 1); len = ...
12
#include <bits/stdc++.h> using namespace std; void read() { return; } void print() { return; } template <typename T1, typename... T2> void read(T1 &x, T2 &...args) { ((cin >> x), read(args...)); } template <typename T1, typename... T2> void print(T1 x, T2... args) { ((cout << x << ' '), print(args...)); } template ...
10
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; signed main() { ios::sync_with_stdio(false); cin.tie(0); //e long long k, l, r, t, x, y; cin >> k >> l >> r >> t >> x >> y; k -= l; r -= l; if (y >= x) { long long itr = 0; long long cur = k; long long cnt = 0; for (;...
14
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; int a[10010][4]; int main() { int n, k, cnt = 1; int i, j; for (i = 0; i < 10010; i++) { for (j = 0; j < 3; j++) a[i][j] = cnt++; a[i][j] = ++cnt; cnt += 2; } while (scanf("%d%d", &n, &k) != EOF) { cout << 1ll * a[n ...
11
#include <bits/stdc++.h> using namespace std; long long int mod = 1e9 + 7; template <typename T, typename... Args> void debug(T t, Args... args) { return; } const int N = 1505; char g[N][N]; pair<int, int> vis[N][N]; bool dfs(int x, int y, int n, int m) { if (g[(x % n + n) % n][(y % m + m) % m] == '#') return 0; ...
12
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int result = 0; while (n != 0) { if (n % 100 == 0) n = n - 100; else if (n % 20 == 0) n = n - 20; else if (n % 10 == 0) n = n - 10; else if (n % 5 == 0) n = n - 5; else n = n - 1; re...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; if (n < 3 * k) { cout << -1 << endl; } else { vector<int> ans(n, 0); if (k % 2 == 0) { for (int i = 0; i < k; i++) { if (i % 2 == 0) { ans[3 * i] = i + 1; ans[3 * i + 1] = i + 1; ...
7
#include <bits/stdc++.h> using namespace std; long long modexpo(long long a, long long b) { long long res = 1LL; while (b > 0) { if (b & 1) res = (res * a) % 1000000007; a = (a * a) % 1000000007; b >>= 1; } return res; } int main() { vector<int> a(3); cin >> a[0] >> a[1] >> a[2]; vector<int> i...
6
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fLL; const int dx[] = {-1, 1, 0, 0, -1, -1, 1, 1}; const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1}; const int maxn = 1e3 + 5; const int maxx = 1e5 + 100; const double EPS = 1e-9; const int MOD = 1000000007; te...
3
#include <bits/stdc++.h> using namespace std; unsigned long long int mod = 1e9 + 7; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int k, l, n; cin >> k; string second; cin >> second; l = second.length(); vector<int> v, back(2e6, 0), fwd(2e6, 0); v.push_back(0); for (int i = 0; i < l;...
8
#include <bits/stdc++.h> using namespace std; int n, a, c[101], ans; int main() { cin >> n; while (n--) { cin >> a; c[a]++; if (c[a] % 2 == 0) ans++; } cout << ans / 2; }
2
#include <bits/stdc++.h> using namespace std; long long f[3000]; int main() { int n, a[10000], i, j, k = 0, cand, sum = 0; memset(f, 0, sizeof(f)); cin >> n >> cand; for (i = 0; i < n - 1; i++) { cin >> a[i]; f[a[i]]++; } sort(a, a + n - 1); while (a[n - 2] >= cand) { a[n - 2]--; cand++; ...
4
#include <bits/stdc++.h> const int N = 200 + 10, V = 2 * N, E = V * V, INF = 0x3f3f3f3f; int arc[V], adj[V], to[E], next[E], cap[E], cnt, s, t, ss, tt; inline void link(int a, int b, int c) { to[cnt] = b, next[cnt] = adj[a], cap[cnt] = c, adj[a] = cnt++; to[cnt] = a, next[cnt] = adj[b], cap[cnt] = 0, adj[b] = cnt++...
22
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; const int mod = 1e9 + 7; const int huge = 1e12; int fx, fy, ix, iy; int dx[] = {0, 1, 0, -1}; int dy[] = {1, 0, -1, 0}; int dis[N], a[N]; signed main() { ios::sync_with_stdio(0); cin.tie(0); ; int t; cin >> t; while (t--) { int n; ...
3
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; const long double EPS = 1e-18; const long double PI = 2 * acos(0.00); long long n, c, d; long double angle[N]; long double getangle(long double x, long double y) { if (x == 0) { if (y > 0) return PI / 2; return 3 * PI / 2; } if (y == 0)...
19
#include <bits/stdc++.h> long long dx[4] = {0, -1, 0, 1}; long long dy[4] = {1, 0, -1, 0}; using namespace std; class pa3 { public: long long x, y, z; pa3(long long x = 0, long long y = 0, long long z = 0) : x(x), y(y), z(z) {} bool operator<(const pa3 &p) const { if (x != p.x) return x < p.x; if (y != p...
9
#include <bits/stdc++.h> using namespace std; int num[1001000], flag[1001000]; int main() { int n, k, a[5010]; scanf("%d %d", &n, &k); int maxn = 0; for (int i = 0; i < n; i++) { scanf("%d", &a[i]); if (a[i] > maxn) maxn = a[i]; } memset(num, 0, sizeof(num)); for (int i = 0; i < n; i++) { for ...
16
#include <bits/stdc++.h> using namespace std; int main() { int a, t, n, m, o, p; cin >> n; while (n--) { string s; cin >> s; a = s.size(); int cnt = 0; int cnt2 = 0; p = 0; for (int i = 0; i < a; i++) { if (s[i] == '0' && cnt == 1) { cnt2++; } else if (s[i] == '1' &...
0
#include <bits/stdc++.h> const int N = 1000001; using namespace std; long long int fen[N]; void up(int ind, long long int val) { while (ind < N) { fen[ind] += val; ind += ind & (-ind); } } long long int q(int ind) { long long int s = 0; while (ind) { s += fen[ind]; ind -= ind & (-ind); } ret...
12
#include <bits/stdc++.h> using namespace std; int main() { char a[108]; char b[108]; while (scanf("%s", &a) != EOF) { int n, i; n = strlen(a); b[0] = a[0]; int j = 1, esp = 0; for (i = 1; i < n; i++) { if (a[i] == 'd' && a[i + 1] == 'o' && a[i + 2] == 't' && i + 2 < n - 1) { b[j+...
5
#include <bits/stdc++.h> using namespace std; const int N = (int)1e3 + 10; int t, a[N][N]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> t; while (t--) { int n, m; cin >> n >> m; bool logic = false; for (int i = 1; i <= n; i++) { cin >> a[0][0] >> a...
1
#include <bits/stdc++.h> using namespace std; long long p[15][5], c[15][5], pi[15]; long long d1, d2, d3, d1c, d2c, d3c, pd; int main() { p[1][1] = 1; p[1][2] = 2; p[1][3] = 3; p[2][1] = 1; p[2][2] = 3; p[2][3] = 2; p[3][1] = 2; p[3][2] = 1; p[3][3] = 3; p[4][1] = 2; p[4][2] = 3; p[4][3] = 1; ...
12
#include <bits/stdc++.h> using namespace std; int main() { int n; string str; cin >> n; if (n > 26) { cout << "-1"; return 0; } cin >> str; sort(str.begin(), str.end()); int sum = 0; for (int x = 1; x < n; x++) { if (str[x - 1] == str[x]) sum++; } cout << sum; return 0; }
2
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int a[10] = {2, 7, 2, 3, 3, 4, 2, 5, 1, 2}; cout << a[s[0] - '0'] * a[s[1] - '0']; return 0; }
3
#include <bits/stdc++.h> using namespace std; const int dx[9] = {0, 0, -1, 1, -1, -1, 1, 1, 0}; const int dy[9] = {-1, 1, 0, 0, -1, 1, -1, 1, 0}; const long long MOD = 998244353; const int N = 1e5 + 10; int n; string va[N]; long long fac[N]; long long qsm(long long x, long long y) { long long res = 1; while (y) { ...
16
#include <bits/stdc++.h> const long long N = 200, mu = 1ll << 32; long long inv[N], c[N], Ans, n, p, q; void exgcd(long long a, long long b, long long &x, long long &y) { if (!b) { x = 1, y = 0; return; } exgcd(b, a % b, x, y); long long t = x; x = y, y = t - a / b * y; } signed main() { for (long l...
21
#include <bits/stdc++.h> using namespace std; int main() { long long int n, A, sum = 0, i; cin >> n >> A; long long int arr[n]; for (i = 0; i < n; i++) { cin >> arr[i]; sum += arr[i]; } for (i = 0; i < n; i++) { cout << max(0LL, A - (sum - arr[i]) - 1) + max(0LL, n - 1 + arr[i] - A) << ...
8
#include <bits/stdc++.h> using namespace std; int main() { int x; string s; cin >> x; cin >> s; cin >> s; if (s == "month") { int ans = 0; if (x <= 29) ans += 1; if (x <= 30) ans += 4; if (x <= 31) ans += 7; cout << ans; } if (s == "week") { x = (x - 5 + 7) % 7 + 1; int ans =...
1
#include <bits/stdc++.h> int main() { int t, s, x; scanf("%i%i%i", &t, &s, &x); if (((x - t) % s == 0 || (x - t - 1) % s == 0) && x != t + 1 && x >= t) printf("YES"); else printf("NO"); return 0 - 0 - 0; }
1
#include <bits/stdc++.h> using namespace std; const int MAXN = 200005; const long long MOD = 998244353; int n, k; long long f[MAXN], r[MAXN]; long long mpow(long long bs, long long ep) { long long ret = 1; while (ep) { if (ep & 1) { ret = ret * bs % MOD; } bs = bs * bs % MOD; ep >>= 1; } r...
15
#include <bits/stdc++.h> using namespace std; long long zero = 0; long long fexp(long long a, long long b) { long long ans = 1; while (b) { if (b & 1) ans = ans * a % 998244353; b /= 2; a = a * a % 998244353; } return ans; } long long modmulti(long long a, long long b) { return ((a % 998244353) * ...
9
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long dp[2005][2005][2][2]; long long m, d; long long n; string a, b; vector<long long> digits; long long calc(long long i, long long j, long long ok, long long hasd) { if (dp[i][j][ok][hasd] != -1) return dp[i][j][ok][hasd]; if (i == ...
14
#include <bits/stdc++.h> using namespace std; int k, n, give[2005]; set<int> mem; int initscore(int pos) { set<int> scores = mem; int prev = *mem.begin(); scores.erase(prev); for (int i = pos + 1; i < k; i++) { prev += give[i]; scores.erase(prev); } prev = *mem.begin(); for (int i = pos - 1; i >= ...
9
#include <bits/stdc++.h> using namespace std; int n; int fun(int m) { m = n; int sum = 0; int q = -1; int s = 0; bool is = 0, ok = 0; while (m) { int p = 0; int r = m; while (m / 3) { m /= 3; p++; } if (s == 0) { s = p; } if (q == -1) { q = p; } else {...
5
#include <bits/stdc++.h> using namespace std; using INT = long long; int main() { INT k, d, t; cin >> k >> d >> t; t *= 2; INT T = (k + d - 1) / d * d; INT ans = t / (T + k) * T * 2; t %= (T + k); if (t <= 2 * k) ans += t; else ans += 2 * (k + (t - k * 2)); if (ans % 2 == 0) cout << ans / ...
9
#include <bits/stdc++.h> using namespace std; const long long INF = 1001001001; const long long LINF = 1001001001001001001; const long long MOD = 998244353; void solve() { long long w, h; cin >> w >> h; long long k; cin >> k; vector<long long> hor1(k); for (long long i = 0; i < (long long)(k); i++) cin >> h...
2
#include <bits/stdc++.h> using namespace std; const long long FASTIO = []() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); return 0; }(); signed main() { long long n; cin >> n; set<long long> b, c; vector<long long> a(n + 2); map<long long, long long> m; a[0] = 1e9; long long f = 0; for (lo...
7
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long ax = 0, ay = 0; for (int i = 0; i < 2 * n; i++) { long long x, y; cin >> x >> y; ax += x; ay += y; } cout << (ax / n) << " " << (ay / n) << '\n'; }
4
#include <bits/stdc++.h> using namespace std; const int N = 1000005; int x[N], y[N], ord[N]; int sq = 0; bool cmp(int a, int b) { int ba = x[a] / sq; int bb = x[b] / sq; if (ba == bb) { if (ba & 1) { return y[a] < y[b]; } else { return y[a] > y[b]; } } else { return ba < bb; } } in...
13
#include <bits/stdc++.h> using namespace std; int k, n; string s, t; string diff; int main() { cin >> k; while (--k >= 0) { cin >> n; cin >> s >> t; diff.clear(); for (int i = 0; i < n; ++i) if (s[i] != t[i]) diff += s[i], diff += t[i]; if (diff.size() == 4 && diff[0] == diff[2] && diff[1]...
2
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; const int N = 1000005; long long fac[N], ifac[N], inv[N]; void pre() { fac[0] = ifac[0] = 1; fac[1] = ifac[1] = inv[1] = 1; for (int n = 2; n < N; n++) { fac[n] = fac[n - 1] * n % mod; inv[n] = inv[mod % n] * (mod - (mod / n)) ...
17
#include <bits/stdc++.h> using namespace std; char line[100001]; int dp[100001], f[100001]; int n; string s; stack<pair<int, int> > st; int main() { memset(dp, -1, sizeof(dp)); memset(f, -1, sizeof(f)); memset(line, 0, sizeof(line)); scanf("%s", line); s = line; n = (int)s.size(); for (int i = 0; i < n; +...
9
#include <bits/stdc++.h> using namespace std; const long long inf = 0x3f3f3f3f3f3f3f3f; long long f, T, t0, a1, t1, p1, a2, t2, p2, res = inf; inline void solve() { for (long long n1 = 0; n1 <= 10000000; ++n1) { long long x1 = n1 * a1; if (x1 * t1 > T) break; if (x1 >= f) { res = min(res, p1 * n1); ...
15
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << n + n / 2 << endl; for (int i = 2; i <= n; i += 2) cout << i << " "; for (int i = 1; i <= n; i += 2) cout << i << " "; for (int j = 2; j <= n; j += 2) cout << j << " "; return 0; }
8
#include <bits/stdc++.h> const int maxn = 1020; using namespace std; char s[maxn][maxn]; bool al[30]; int siz[maxn]; int main() { int n, num = 0; cin >> n; for (int i = 0; i < n; i++) { memset(al, false, sizeof(al)); cin >> s[i]; for (int j = 0; s[i][j]; j++) { al[s[i][j] - 'a'] = true; } ...
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); double n, r; cin >> n >> r; double angle = (acos(-1.0) / n); cout << fixed << setprecision(10) << (r * sin(angle)) / (1 - sin(angle)) << "\n"; return 0; }
4
#include <bits/stdc++.h> using namespace std; vector<string> v(50); int n, m; bool val(char c, int t) { if (t == 1) return ('0' <= c && c <= '9'); if (t == 2) return ('a' <= c && c <= 'z'); return (c == '#' || c == '*' || c == '&'); } int buscar(int pos, int t) { if (val(v[pos][0], t)) return 0; for (int i = ...
7
#include <bits/stdc++.h> using namespace std; int main() { int n, c = 0; char arr[105][105]; cin >> n; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) cin >> arr[i][j]; for (int i = 0; i <= n; i++) arr[i][0] = 'x'; for (int j = 0; j <= n; j++) arr[0][j] = 'x'; for (int i = 0; i <= n; i++) ar...
2
#include <bits/stdc++.h> const int N = (int)5e5 + 5; int n, t, last; char s[N]; int q[N]; int work(int cnt) { int tlast = n - 1, res = 0; for (int i = 0; i < n; i++) { if (i > last && cnt >= 0) { tlast = i - 1; break; } q[i] = 1; if (cnt < 0) q[i]++; if (s[i] == 'H') cnt--; if (s...
15
#include <bits/stdc++.h> using namespace std; const int maxn = 1e3 + 5; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, h; cin >> n >> h; multiset<long long> st; long long ans = 0; for (int i = 0; i < n; i++) { long long l = h; int x; cin >> x; st.insert(x...
5
#include <bits/stdc++.h> using namespace std; const int MAX_N = 5e3 + 5; const int MAX_M = 1e6 + 5; int n, k, a[MAX_N]; int pairs[MAX_M], vis[MAX_M]; int main() { scanf("%d%d", &n, &k); for (int i = 0; i < n; ++i) { scanf("%d", &a[i]); } sort(a, a + n); for (int i = 0; i < n; ++i) { for (int j = i + 1...
16