solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; const int mod = int(1e9) + 7; int n, k, d; int dp[102][2]; void add(int &a, int b) { a += b; if (a >= mod) a -= mod; } int main() { cin >> n >> k >> d; dp[0][0] = 1; for (int i = 1; i <= n; i++) { for (int j = 1; j <= k; j++) { if (i - j < 0) break; ...
8
#include <bits/stdc++.h> using namespace std; int main() { long long int n, j, a, b; cin >> n; j = 1; while (j <= n) { cin >> a >> b; cout << b + (9 * (a - 1)) << endl; j++; } }
2
#include <bits/stdc++.h> using namespace std; const int maxn = 200005; char s[maxn]; int vis[maxn]; queue<int> q; int main() { int n, k; scanf("%d%d%s", &n, &k, s); memset(vis, -1, sizeof(vis)); for (int i = 0; i < n; i++) { if (s[i] != s[(i - 1 + n) % n] && s[i] != s[(i + 1) % n]) ; else q....
15
#include <bits/stdc++.h> using namespace std; int n, d, mod, ans, tr[15]; int f[1005], inv[15]; int g[15][1005]; int main() { scanf("%d%d%d", &n, &d, &mod); if (n == 1) return puts("1"), 0; for (int i = (int)(0); i <= (int)(d); i++) g[i][i] = 1; f[1] = inv[0] = inv[1] = 1; for (int i = (int)(2); i <= (int)(d)...
19
#include <bits/stdc++.h> using namespace std; void run() { int n; cin >> n; string s; cin >> s; int a(0), d(0), x((n + 1) / 2); for (int i = 0; i < s.size(); i++) { if (s[i] == 'A') a++; else d++; if (a > x || d > x) { if (a > d) cout << "Anton" << endl; else ...
0
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0; char ch = getchar(); bool d = 1; for (; !isdigit(ch); ch = getchar()) if (ch == '-') d = 0; for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0'; return d ? x : -x; } inline void write(long long x) { if (x < ...
19
#include <bits/stdc++.h> using namespace std; int main() { int n, r = 0; char s[200000]; cin >> n >> s; int a = 0, f = 0, i = 0; for (int j = 0; j < n; ++j) { if (s[j] == 'A') ++a; else if (s[j] == 'F') ++f; else if (s[j] == 'I') ++i; } if (i > 0) { cout << (i == 1 ? 1 : ...
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int a[4]; int sum = 0; for (int i = 0; i < 4; i++) { cin >> a[i]; sum += a[i]; } if (sum % 2) { cout << "NO"; return 0; } else { sort(a, a + 4); if (a[0] ...
0
#include <bits/stdc++.h> using namespace std; const int MOD = 32768, N = 109; char ch; string s[N], t; int ans, v, f[MOD + 9], num, p, pos; int ex(); int gt() { int ret = 0; if (t[pos] == 'n') return pos++, v; if (t[pos] == 'f') return pos += 2, ret = f[ex()], pos++, ret; while (t[pos] >= '0' && t[pos] <= '9') ...
16
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; string s; cin >> s; int ind = n; for (int i = 1; i < n; i++) { for (int j = 0; j < n; j++) { if (j + i == n) { ind = i; break; } if (s[j] != s[i + j]) { break; } } ...
5
#include<bits/stdc++.h> using namespace std; typedef long long int ll; #define rem 1000000007 #define rem1 998244353 int main() { ll t; cin>>t; while(t--) { ll i,j,k,n,m; string str; cin>>str; cout<<str.length()<<"\n"; } }
0
#include <bits/stdc++.h> using namespace std; int n, m; char str[300005]; vector<int> G[300005]; int color[300005], dp[300005][26]; deque<int> order; bool dfs_visit(int v) { color[v] = 1; bool f = true; for (int i = 0; i < G[v].size(); i++) { int to = G[v][i]; if (color[to] == 1) return false; if (col...
9
#include <bits/stdc++.h> int caseno = 1; using namespace std; typedef unsigned long long ULL; typedef unsigned long long uint64; typedef long long LL; typedef long long int64; template <class T> inline void checkmax(T &a, T b) { if (b > a) a = b; } template <class T> inline void checkmin(T &a, T b) { if (b < a) a =...
0
#include <bits/stdc++.h> using namespace std; int rev(int k, int siz) { int sol = 0, log = log2(siz) - 1; while (k) { if (k & 1) sol += 1 << log; k >>= 1; log--; } return sol; } long long pow_mod(long long a, long long b) { long long ret = 1; a %= 7340033; for (; b > 0; b >>= 1) { if (b % ...
15
#include <bits/stdc++.h> using namespace std; int divid(long n) { long maxn = -1, a; while (n) { a = n % 10; n /= 10; maxn = maxn > a ? maxn : a; } return maxn; } int main() { long n; int T = 0; scanf("%d", &n); while (n != 0) { n -= divid(n); T++; } printf("%d\n", T); }
3
#include <bits/stdc++.h> using namespace std; using ll = long long; ll power(ll n, ll p) { ll ans = 1; for (ll i = 0; i < p; i++) { ans *= n; } return ans; } int main() { int t; cin >> t; while (t--) { ll n; cin >> n; ll arr[n + 1]; for (int i = 0; i < n; i++) { cin >> arr[i]; ...
10
#include <bits/stdc++.h> using namespace std; const int N = 3009; inline long long read() { long long res = 0, w = 1; char c = getchar(); while (!isdigit(c)) { if (c == '-') w = -1; c = getchar(); } while (isdigit(c)) { res = res * 10 + c - 48; c = getchar(); } return res * w; } int T, n, ...
19
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<long long> v(n); for (int i = 0; i < n; ++i) cin >> v[i]; vector<pair<int, long long>> best(n); int ind = n - k; long long cur = 0; while (ind < n) cur += v[ind++]; best[n - k] = {n - k, cur}; ind = n - 1; f...
7
#include <bits/stdc++.h> using namespace std; int n; char s[10000]; int main() { cin.tie(NULL); cout.tie(NULL); scanf("%d", &n); int cnt, now; for (int i = 0; i < n; i++) s[i] = '0'; printf("? %s\n", s); fflush(stdout); scanf("%d", &cnt); s[0] = '1'; printf("? %s\n", s); fflush(stdout); scanf("%...
12
#include <bits/stdc++.h> using namespace std; int fact(int N) { int res = 1; for (int i = 2; i <= N; i++) { res = ((long long)res * i) % 1000000007; } return res; } int mmul(int x, int y) { return ((long long)x * y) % 1000000007; } int memo[1000][1000]; int solve(int X, int Y) { if (X == 0) return fact(Y)...
15
#include <bits/stdc++.h> using namespace std; int a[1001][1001], l[1001][1001], r[1001][1001], t[1001][1001], b[1001][1001]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> a[i][j]; } } ...
4
#include <bits/stdc++.h> using namespace std; int n, m; map<int, vector<int> > x; vector<int> un; vector<vector<pair<int, int> > > I; int getFir(const vector<pair<int, int> > &V, int from) { int l = 0, r = int(V.size()) - 1; int res = -1; while (l <= r) { int m = l + r >> 1; if (from <= V[m].second) { ...
17
#include <bits/stdc++.h> using namespace std; int mat[510][510], sum[510][510]; int n, m; bool ok(int x, int y) { if (x >= 0 && x < n && y >= 0 && y < m) return true; return false; } int main() { scanf("%d %d", &n, &m); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) scanf("%d", &mat[i][j]); memse...
11
#include <bits/stdc++.h> using namespace std; int a, b, n, c; bool t = false; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { cin >> a >> b; if (b != a) return cout << "rated", 0; else { if (i != 0) { if (a > c) t = true; c = a; } else { c = a; ...
1
#include <bits/stdc++.h> using namespace std; int main() { long long int n, x, temp, count = 0, flag; cin >> n >> x; if (n >= x) { temp = x; flag = 0; } else { temp = n; flag = 1; } while (temp > flag) { if ((x % temp) == 0 && (temp * n) >= x) { count++; } temp--; } cou...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, r; cin >> n >> r; vector<int> a(n), b(n); for (int i = 0; i < n; i++) cin >> a[i] >> b[i]; int cnt = 0; vector<bool> used(n, false); while (true) { int max_i = -1; int max_b = -500; for (int i = 0; i < n; i++) { if (used[i...
13
#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; } lo...
11
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; set<vector<int>> cnt; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; int dn = 0, dm = 0, cn = n, cm = m; --cn, --cm; while (cn) cn /= 7, ++dn; dn = max(1, dn); while (cm) cm /= 7...
9
#include <bits/stdc++.h> using namespace std; void solve(int test) { long long x, y, a, b; cin >> x >> y >> a >> b; long long d = a * (y - x); if (d % (a + b) != 0) cout << "-1\n"; else { d /= (a + b); if (d % a == 0 && (y - x - d) % b == 0 && d / a == (y - x - d) / b) cout << d / a << "\n";...
0
#include <bits/stdc++.h> using namespace std; const int N = int(3e5), mod = int(1e9) + 7; int a, h, w; long long phi(int n) { long long m = n; for (int i = 2; 1ll * i * i <= n; i++) { if (n % i == 0) { while (n % i == 0) { n /= i; } m -= m / i; } } if (n > 1) m -= m / n; retu...
19
#include <bits/stdc++.h> using namespace std; int a[110][310]; int b[110][110]; int c[10010]; int reach[110]; bool used[100010]; int getPos(int t, int i) { int j = a[i][0] - 1; int pos = 0; if (t >= a[i][2 + 3 * j]) return a[i][3 + 3 * j]; while (t < a[i][2 + 3 * j]) j--; if (j < 0) pos = a[i][1] * t; e...
15
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > v; long long a[100001]; int main() { int n, k, ans = 1, l = 0; cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; int pd = 0; for (int i = 1; i < n; i++) { if (a[i] != a[i + 1]) pd++; else ans = max(pd + 1, ans), p...
2
#include <bits/stdc++.h> using namespace std; struct node { int x, id; bool operator<(const node &a) const { return x < a.x; } }; set<node> v; int a[400005]; bool b[400005]; int main() { int n, m; scanf("%d%d", &n, &m); { int cnt = 0; int l, r, rr; scanf("%d%d", &l, &r); rr = r; a[++cnt] =...
9
#include <bits/stdc++.h> using namespace std; string name[24] = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "B", "H", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "B", "H"}; string inp[3]; int dist[2]; int getDist(string a, string b) { int i, j; ...
4
#include <bits/stdc++.h> using namespace std; int num(string s) { if (s == "S") return 0; if (s == "M") return 1; if (s == "L") return 2; if (s == "XL") return 3; if (s == "XXL") return 4; if (s == "XXXL") return 5; return -1; } string st(int nv) { if (nv == 0) return "S"; if (nv == 1) return "M"; i...
10
#include <bits/stdc++.h> using namespace std; long long fastpow(long long a, long long b, long long m = (long long)(1e9 + 7)) { long long res = 1; a %= m; while (b > 0) { if (b & 1) res = (res * a) % m; a = (a * a) % m; b >>= 1; } return res; } vector<long long> prefix_function(v...
11
#include <bits/stdc++.h> using namespace std; long long n, t, i, a[200000], m, k; vector<long long> v; string s; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> t; while (t--) { cin >> n >> k; for (i = 0; i < n; i++) { cin >> a[i]; }; m = a[0]; for (i =...
0
#include <bits/stdc++.h> using namespace std; inline int in() { int32_t x; scanf("%d", &x); return x; } inline string getStr() { char ch[1000000]; scanf("%s", ch); return ch; } inline char getCh() { char ch; scanf(" %c", &ch); return ch; } template <class P, class Q> inline P smin(P &a, Q b) { if (b...
15
#include <bits/stdc++.h> using namespace std; int main() { string s1, s2; cin >> s1 >> s2; transform(s1.begin(), s1.end(), s1.begin(), ::tolower); transform(s2.begin(), s2.end(), s2.begin(), ::tolower); if (s1 == s2) cout << "0"; else if (s1 > s2) cout << "1"; else cout << "-1"; }
0
#include <bits/stdc++.h> const int INF = 0x3f3f3f3f; using namespace std; int a[105]; int main() { ios::sync_with_stdio(false); int n; while (cin >> n) { memset(a, 0, sizeof a); int ans = 0; for (int i = 0; i < n; i++) { int cur; cin >> cur; a[cur]++; if (a[cur] >= 4) { ...
2
#include <bits/stdc++.h> using namespace std; struct Position { int p; int cost; } pos, pre, now; int cnt[200005]; int cost[200005]; int father[200005]; int n, m; int x, y; int k; int path[200005]; vector<vector<int>> edge; int s, e; queue<Position> q; int len; int main() { int n, m; cin >> n >> m; for (int i...
9
#include <bits/stdc++.h> const int mod = 1e9 + 7; long long int power(long long int a, long long int b) { long long int r = 1; for (; b; b >>= 1) { if (b & 1) r = r * a % mod; a = a * a % mod; } return r; } using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int t; cin ...
0
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; const int MOD = 1e9 + 7; char s[N]; int dp[N][2][2]; void add(int &x, int y) { x += y; if (x >= MOD) x -= MOD; } int main() { scanf("%s", s + 1); int n = strlen(s + 1); dp[0][0][0] = 1; dp[0][0][1] = 1; for (int i = 1; i <= n; i++) { ...
11
#include <bits/stdc++.h> using namespace std; long ma = 10000000; bool a[10000001]; void c_p_c() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int32_t main() { c_p_c(); long long k; cin >> k; vector<pair<long, pair<long, long> > > a; for (long t = 0; t < k; t++) { long long n; cin >...
6
#include <bits/stdc++.h> using namespace std; int n; long long a, x, y, m; int k[5005]; int ind[5005]; vector<int> problems[5005]; pair<int, int> ans[200001]; int main() { int i, j; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d%I64d%I64d%I64d%I64d", &k[i], &a, &x, &y, &m); problems[i].push_back(a);...
8
#include <bits/stdc++.h> using namespace std; int main() { const int x = 1000; int a[x], b[x], e = 0; string h, r, m; cin >> h >> r >> m; for (int i = 0; i < x; i++) { a[i] = 0; b[i] = 0; } for (int i = 0; i < h.size(); i++) { a[h[i]]++; } for (int i = 0; i < r.size(); i++) { a[r[i]]++...
0
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int t, c; cin >> t; string n; vector<pair<string, int>> events; vector<string> names; map<string, int> points; for (int i = 0; i < t; i++) { cin >> n >> c; events.push_back({n, c}); if (p...
7
#include <bits/stdc++.h> using namespace std; ostream &operator<<(ostream &out, string str) { for (char c : str) out << c; return out; } template <class L, class R> ostream &operator<<(ostream &out, pair<L, R> p) { return out << "(" << p.first << ", " << p.second << ")"; } template <class T> auto operator<<(ostre...
16
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { int T, n; cin >> T; while (T--) { cin >> n; int count = 0; int sum = 0; for (int i = 0; i < n; i++) { int cur; cin >> cur; sum += cur; if (cur == 0) { count++; sum++; ...
0
#include <bits/stdc++.h> using namespace std; long long result[1000001][21], t[2][21], d[1000001], done[1000001], tsnt[1000001], mod = 1e9 + 7; vector<long long> prime; void dp() { t[0][0] = result[0][0] = 1; for (long long i = 1; i <= 20; i++) t[0][i] = t[0][i - 1] + 2, result[0][i] = 2; for (long long i...
17
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long a, b, c, ans; scanf("%I64d%I64d%I64d", &a, &b, &c); ans = a + b + c - 1; cout << ans << endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; vector<int> g[100006]; vector<int> located[100006]; int parent[100006], level[100006], visited[100006]; int ancestor[100006][18]; vector<int> st[100006][18]; void dfs(int u) { visited[u] = 1; for (int i = 0; i < g[u].size(); i++) { int v = g[u][i]; if (visited[v...
14
#include <bits/stdc++.h> using namespace std; using namespace std; const long long MOD = 1e9 + 7; const long long EPS = 1e-9; const long long N = 1005; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, k; cin >> n >> k; if (k > (n - k + 1)) { k = n - k + 1; } long long ans...
2
#include <bits/stdc++.h> using namespace std; const int N = 4e5 + 5; int n, target[N], pre[N], last[N], tot = 0; void add(int u, int v) { target[++tot] = v; pre[tot] = last[u]; last[u] = tot; } int dep[N]; void dfs(int u, int fa) { for (int ptr = last[u]; ptr; ptr = pre[ptr]) { if (target[ptr] == fa) contin...
13
#include <bits/stdc++.h> using namespace std; int main() { long long int q; cin >> q; while (q--) { long long int n; cin >> n; long long int i; long long int a[n]; long double sum = 0; for (i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } long double z; z = sum / (l...
0
#include <bits/stdc++.h> using namespace std; int sum[100][100]; int g[100][100]; int main() { int n, m, a, b; cin >> n >> m; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { cin >> g[i][j]; sum[i][j] = g[i][j] + sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1]; } cin >> a >> b; ...
4
#include <bits/stdc++.h> using namespace std; inline int qr() { int ret = 0, f = 0, c = getchar(); while (!isdigit(c)) f |= c == 45, c = getchar(); while (isdigit(c)) ret = ret * 10 + c - 48, c = getchar(); return f ? -ret : ret; } const int maxn = 1e5 + 5; const int inf = 0x3f3f3f3f; int r[maxn], siz[maxn], st...
22
#include<bits/stdc++.h> using namespace std; #define rep(i, a, n) for(int i=(a); i<(n); ++i) #define per(i, a, n) for(int i=(a); i>(n); --i) #define pb emplace_back #define mp make_pair #define clr(a, b) memset(a, b, sizeof(a)) #define all(x) (x).begin(),(x).end() #define lowbit(x) (x & -x) #define fi first #define se...
17
#include <bits/stdc++.h> using namespace std; long long int MOD = 1000000007; long long int mod(long long int x) { return (x % MOD + MOD) % MOD; } long long int pow1(long long int x, long long int y) { if (y == 0) { return 1; } long long int t = pow1(x, y / 2); if (y % 2 == 0) { return mod(t * t); } e...
9
#include <bits/stdc++.h> using namespace std; const long double Pi = 3.14159265358979323846264338327950288419716939937510; int n, x; vector<long double> r; long double res; double sq(long double r) { return Pi * r * r; } int main() { cin >> n; for (int i = 0; i < (n); ++i) { cin >> x; r.push_back(x); } ...
2
#include <bits/stdc++.h> using namespace std; long long Com(long long n, long long r) { if (r < 0 || r > n) return 0; long long res = 1, i = 0; while (i < r) ++i, res *= n - i + 1, res /= i; return res; } int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m, t, f, s; long long ans = 0; cin >> n ...
6
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; unsigned long long ans = 1, sum = 0, num = 0; cin >> num; for (long long i = 2; i <= num; i++) { ans *= i; } sum = (num * (num / 2)); cout << ans / sum << '\n'; return 0; }
5
#include <bits/stdc++.h> using namespace std; struct event { int y, i, type; event() {} event(int y, int i, int type) : y(y), i(i), type(type) {} bool operator<(const event &e) const { if (y != e.y) return y > e.y; return type < e.type; } }; struct seg { int mx, l, r, f; seg() {} seg(int mx, int...
17
#include<bits/stdc++.h> using namespace std; int read(){ int a = 0; char c = getchar(); bool f = 0; while(!isdigit(c)){f = c == '-'; c = getchar();} while(isdigit(c)){a = a * 10 + c - 48; c = getchar();} return f ? -a : a; } int cnt[23] , l[23] , r[23] , T , N , A , B , pos[23]; string s , alphabet = "acdefhijklmno...
27
#include <bits/stdc++.h> using namespace std; const int INF = (1 << 30) - 1; const int DIRX[] = {-1, 0, 0, 1, -1, -1, 1, 1}, DIRY[] = {0, -1, 1, 0, -1, 1, -1, 1}; const double ERR = 1e-9, PI = (2 * acos(0.0)); template <class T> inline int size(T& t) { return (int)t.size(); } template <class T> inline T MIN...
10
#include <bits/stdc++.h> using ll = long long; int main() { int n; std::cin >> n; std::vector<int> v{ 0b1, 0b110, 0b11100, 0b1111000, 0b111110000, 0b11111100000, 0b1111111000000, 0b111111110000000, }; for (size_t i{v.size()}; 0 < i--;) { if (n % v[i] == 0) { std::...
2
#include <bits/stdc++.h> using namespace std; long long n, m, apple, money, i; string s[51]; int main() { cin >> n >> m; m /= 2; for (i = 1; i <= n; i++) cin >> s[i]; for (i = n; i >= 1; i--) { apple *= 2; if (s[i] == "halfplus") apple++; money += apple; } money *= m; cout << money; return 0...
4
#include <bits/stdc++.h> using namespace std; int p[16] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53}; int factormask[59], dp[101][66000], b[101][66000]; vector<int> b_out; int N; int a[101]; void factor() { memset(dp, -1, sizeof dp); for (int j = 2; j < 59; j++) { int mask = 0; for (int i ...
12
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; int p[n]; for (int i = 0; i < n; i++) { cin >> p[i]; } int c[n]; for (int i = 0; i < n; i++) { cin >> c[i]; } if (k == 0) { for (int i = 0; i < n; i++) {...
6
#include <bits/stdc++.h> using namespace std; inline void wait(double seconds) { double endtime = clock() + (seconds * CLOCKS_PER_SEC); while (clock() < endtime) { ; } } template <class T> inline T fastIn() { register char c = 0; register T a = 0; bool neg = false; while (c < 33) c = getchar(); whil...
12
#include <bits/stdc++.h> using namespace std; char s[1000000]; int main() { int N; scanf("%d%s", &N, &s); int a = 0; int f = 0; int i = 0; for (int j = 0; j < N; j++) { if (s[j] == 'A') a++; if (s[j] == 'I') i++; if (s[j] == 'F') f++; } int res = 0; for (int j = 0; j < N; j++) if ((s[j...
2
#include <bits/stdc++.h> using namespace std; inline long long read() { char i = getchar(); long long f = 1, res = 0; while (i < '0' || i > '9') { if (i == '-') f = -1; i = getchar(); } while (i >= '0' && i <= '9') { res = res * 10 + i - '0'; i = getchar(); } return res * f; } const int N ...
23
#include <bits/stdc++.h> using namespace std; int main() { int n, count = 0; cin >> n; int a[10005][2]; for (int i = 0; i < n; i++) { cin >> a[i][0] >> a[i][1]; } for (int i = 0; i < n; i++) { for (int j = (i + 1); j < n; j++) { for (int k = (j + 1); k < n; k++) { int total = ...
11
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int a, b; cin >> a >> b; string prawdopodobienstwo[7] = {"0/0", "1/1", "5/6", "2/3", "1/2", "1/3", "1/6"}; cout << prawdopodobienstwo[max(a, b)]; }
0
#include <bits/stdc++.h> using namespace std; using ll = long long; void solve() { ll n, m, x, y, cost = 0; cin >> n >> m >> x >> y; char ar[n][m]; for (ll i = 0; i < n; i++) { for (ll j = 0; j < m; j++) cin >> ar[i][j]; } if (m == 1) { for (ll i = 0; i < n; i++) { if (ar[i][0] == '.') cost +=...
2
#include <bits/stdc++.h> inline int getInt() { int s; scanf("%d", &s); return s; } using namespace std; int win[2][7000]; int lose[2][7000]; int main() { const int n = getInt(); vector<vector<int> > v(2); for (int i = 0; i < (int)(2); i++) { const int k = getInt(); v[i] = vector<int>(k); for (in...
12
#include <bits/stdc++.h> using namespace std; const int MX = 10005; const double EPS = 1e-8; struct Point { double x, y; }; Point operator+(Point a, Point b) { a.x += b.x; a.y += b.y; return a; } Point operator*(Point a, double k) { a.x *= k; a.y *= k; return a; } Point operator-(Point a, Point b) { a.x...
27
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 11; int dp[maxn]; int n, ans; string a, b; bool yes(int i, int j) { bool ok = 1; ok &= a[i] != b[i]; ok &= a[j] != b[j]; ok &= a[i] != a[j]; return ok; } void go() { for (int i = 0; i < n; i++) { ans++; if (i and yes(i - 1, i)) ...
5
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 7; inline long long int add(long long int p, long long int q) { return p + q >= mod ? p + q - mod : p + q; } inline long long int sub(long long int p, long long int q) { return p - q < 0 ? p - q + mod : p - q; } inline long long int mul(l...
12
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; unsigned long long g = 1; for (int a = 0; a < (3 * n); a++) { g = (g * 3) % 1000000007; } unsigned long long k = 1; for (int e = 0; e < n; e++) k = (k * 7) % 1000000007; g = (g - k + 1000000007) % 1000000007; cout << g % 1...
7
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; long double a[100005]; int N, U; int search(long double x) { int l = 0, r = N; int m = 0; while (l < r) { m = (l + r) / 2; if (x >= a[m]) { l = m + 1; } else r = m; } if (N == l) return N - 1; return l - 1; } i...
8
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); ios_base::sync_with_stdio(false); int i, j, k; int n, m, q; vector<int> v; cin >> n >> k; m = n / k; bool used[100] = {}; int a[100]; for (i = (int)(0); i < (int)(n); i++) cin >> a[i]; cin >> q; for (i = (int)(0); i < (int)(q...
11
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int* arr = new int[n]; for (int i = 0; i < n; i++) cin >> arr[i]; int* dp1 = new int[n]; for (int i = 1; i < n; i++) dp1[i] = abs(arr[i - 1] - arr[i]); long long* dp2 = new long long[n]; dp2[0] = 0; for (int i = 1; i < n; i++)...
8
#include <bits/stdc++.h> using namespace std; template <class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2>& p) { out << p.first << ' ' << p.second; } template <class T> istream& operator>>(istream& in, vector<T>& v) { for (auto& x : v) in >> x; return in; } template <class T> ostream& operator<<(o...
0
#include <bits/stdc++.h> using namespace std; int n, x, dis[110]; struct mat { long long _[110][110]; int r, c; } M, A, B, C, I; mat operator*(mat &A, mat &B) { memset(C._, 0, sizeof C._); for (int i = 0; i <= 101; i++) for (int j = 0; j <= 101; j++) for (int k = 0; k <= 101; k++) { long long ...
14
#include <bits/stdc++.h> using namespace std; int main() { string name1, name2, names[10001][2]; cin >> name1; cin >> name2; int n, i, j; cin >> n; for (i = 0; i < n; i++) { for (j = 0; j < 2; j++) { cin >> names[i][j]; } } cout << name1 << " " << name2 << "\n"; for (i = 0; i < n; i++) {...
1
#include <bits/stdc++.h> using namespace std; long long int dp[101]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int p, y, n, i, j; cin >> p >> y; while (y > p) { n = sqrt(y); for (i = 2; i <= n; i++) if (y % i == 0) break; if (i == n + 1) { cout << y; return 0;...
6
#include <bits/stdc++.h> using namespace std; vector<int> KMP(string S, string K) { vector<int> T(K.size() + 1, -1); for (int i = 1; i <= K.size(); i++) { int pos = T[i - 1]; while (pos != -1 && K[pos] != K[i - 1]) pos = T[pos]; T[i] = pos + 1; } vector<int> matches; for (int sp = 0, kp = 0; sp < ...
12
#include <bits/stdc++.h> using namespace std; vector<int> g1[3010], g2[3010]; struct query { int st, k, id; query(int _st = 0, int _k = 0, int _id = 0) : st(_st), k(_k), id(_id) {} }; vector<query> op[3010]; int n, m, q; bool vis[3010]; int nex[3010][13]; int ans[500100]; void dfs1(int u) { vis[u] = true; for (...
19
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3f; template <typename T, typename T2> inline void _max(T &a, T2 b) { a = max((T)a, (T)b); } template <typename T, typename T2> inline void _min(T &a, T2 b) { a = min((T)a, (T)b); } const int MAX = 3e5 +...
13
#include <bits/stdc++.h> using namespace std; const int N = 505; const int INF = 1e9 + 10; int a[N][N], x[N * N], y[N * N], t[N * N]; int main() { int n, m, k, q; scanf("%d%d%d%d", &n, &m, &k, &q); for (int i = 0; i < q; i++) scanf("%d%d%d", &x[i], &y[i], &t[i]); int l = 0, r = INF, ret = INF; while (l <= r) ...
11
#include <bits/stdc++.h> using namespace std; double pi = 3.14159265358979323846; bool sortbysec(const pair<long long int, long long int> &a, const pair<long long int, long long int> &b) { if (a.first == b.first) return (a.second < b.second); return (a.first < b.first); } long long int fpower(long lo...
0
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 10; long long n, k, a[N], ans = 0; map<long long, vector<long long> > mp; vector<long long> dota(N, 0); signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin >> n >> k; for (long long i = 0; i < n; i++) { ...
9
#include <bits/stdc++.h> using namespace std; const int MAXN = 3e5 + 5, Mod1 = 1e9 + 7, Mod2 = 998244353; char buf[1 << 12], *pp1 = buf, *pp2 = buf, nc; int ny; inline char gc() { return getchar(); } inline int read() { int x = 0; for (ny = 1; nc = gc(), (nc < 48 || nc > 57) && nc != EOF;) if (nc == 45) ny = -1...
22
#include <bits/stdc++.h> using namespace std; const int N = (int)2e6 + 10; const int inf = (int)2e9; char str[N]; long long rev, altr; int main() { int n; scanf("%d %lld %lld", &n, &rev, &altr); scanf("%s", &str); long long seg = 0; char last = '1'; for (int i = 0; i < n; i++) { if (str[i] == '0' && las...
7
#include <bits/stdc++.h> using namespace std; int pre[2010]; int find(int x) { if (pre[x] == -1) { return x; } return pre[x] = find(pre[x]); } int main() { ios_base::sync_with_stdio(false); cin.tie(); int n, m, k, i, j; memset(pre, -1, sizeof(pre)); scanf("%d%d%d", &n, &m, &k); int x, y; for (i ...
8
#include <bits/stdc++.h> using namespace std; const int INF = (1LL << 31) - 1; using namespace std; int i, j, k, l, n, m, q, d; int ar[105]; int dp[10001][101], dpn[10001][101]; int rec(int tar, int num) { int a, b; if (tar > 10000) return 0; if (num == n - 1) { if (tar >= 1 && tar <= l) { ar[num] = tar...
7
#include <bits/stdc++.h> using namespace std; const int MAXN = 200005; int n, k, a, b, q, t, A, B, BITA[MAXN], BITB[MAXN], tot[MAXN]; int query1(int index) { if (index >= MAXN) index = MAXN - 1; int sum = 0; for (; index > 0; index -= index & -index) sum += BITA[index]; return sum; } void set1(int index, int va...
9
#include <bits/stdc++.h> inline long long rd() { long long _x = 0; int _ch = getchar(), _f = 1; for (; !isdigit(_ch) && (_ch != '-') && (_ch != EOF); _ch = getchar()) ; if (_ch == '-') { _f = 0; _ch = getchar(); } for (; isdigit(_ch); _ch = getchar()) _x = _x * 10 + _ch - '0'; return _f ? _x :...
20
#include <bits/stdc++.h> using namespace std; int main() { string str; cin >> str; int a; a = str.length(); str[0] = toupper(str[0]); cout << str; }
0