solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; void scan(int &x) { register int c = getchar(); x = 0; int neg = 0; for (; ((c < 48 || c > 57) && c != '-'); c = getchar()) ; if (c == '-') { neg = 1; c = getchar(); } for (; c > 47 && c < 58; c = getchar()) { x = (x << 1) + (x << 3) + c - 48; ...
14
#include <bits/stdc++.h> using namespace std; int main() { long long k, l, kc; cin >> k >> l; kc = k; int i; for (i = 0; k <= l; k *= kc, i++) { if (k == l) { cout << "YES\n" << i; return 0; } } cout << "NO"; return 0; }
2
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f, MAXN = 2e5 + 50; const long long LINF = 0x3f3f3f3f3f3f3f3f, MOD = 1004535809; const double Pi = acos(-1), EPS = 1e-6; void test() { cerr << "\n"; } template <typename T, typename... Args> void test(T x, Args... args) { cerr << x << " "; test(...
18
#include <bits/stdc++.h> using namespace std; template <class T> void read(T &u) { u = 0; char c = getchar(); int flag = 0; while (c < '0' || c > '9') flag |= (c == '-'), c = getchar(); while (c >= '0' && c <= '9') u = (u << 3) + (u << 1) + (c ^ 48), c = getchar(); if (flag) u = -u; } template <class T>...
12
#include <bits/stdc++.h> using namespace std; int main() { int t; scanf("%d", &t); while (t--) { int n; scanf("%d", &n); string s; cin >> s; for (int i = 0; i < n; i++) cout << s[n - 1]; puts(""); } return 0; }
0
#include <bits/stdc++.h> using namespace std; long long n; long long biao[] = { 0, 1, 9, 245, 126565, 54326037, 321837880, 323252721, 754868154, 328083248, 838314395, 220816781, 893672292, 166441208, 251255697, 114256285, 118775501, 482714697, 11784725, 460862131, 55038456...
20
#include <bits/stdc++.h> int64_t gcd(int64_t a, int64_t b, int64_t& x, int64_t& y) { if (a == 0) { x = 0; y = 1; return b; } int64_t x1, y1; int64_t d = gcd(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return d; } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullpt...
11
#include <bits/stdc++.h> using namespace std; using ll = long long; ll mod = 1e9 + 7; void solve() { int n; cin >> n >> mod; vector<ll> a(n + 1); a[1] = 1; for (int i = 2; i <= n; i++) { if (i == 2) { a[i] = 2; } else { a[i] = (a[i] + 2 * a[i - 1] + a[1]) % mod; } for (int j = 2 * ...
11
#include <bits/stdc++.h> using namespace std; int T, x; int main() { cin >> T; while (T--) { cin >> x; int res = x / 2; cout << res << "\n"; } }
0
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; int main() { std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; int t; t = 1; for (int tc = 0; tc < t; tc++) { int n; cin >> n; map<int, int> mp; int arr[2 * n + 1][2 * n + 1]; map<int, pair<int, int...
5
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using pli = pair<ll, int>; using pil = pair<int, ll>; void Solve() { int n; cin >> n; int a[n]; for (int &v : a) cin >> v; int j = 1, len = 1; for (int i = 0; i < n; i++) { j = max(i...
4
#include <bits/stdc++.h> using namespace std; inline int read() { int k = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { k = k * 10 + ch - '0'; ch = getchar(); } return k * f; } set<int> s; map<int, in...
21
#include <bits/stdc++.h> using namespace std; int n; vector<string> all; int cnt[105][205]; string ans = ""; vector<string> ask(int l, int r) { string answer = "vmkdfasdajd"; cout << "? " << l + 1 << " " << r + 1 << endl; vector<string> result; string s; for (int i = l; i <= r; i++) { for (int j = i; j <=...
16
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, x, t2; double ans, s, t1; scanf("%d%d%d", &n, &a, &b); for (int i = 1; i <= n; i++) { scanf("%d", &x); if (a % b == 0) printf("0 "); else { t1 = 1.0 * b / a; t2 = (int)(x / t1); s = 1.0 * t2 * 1.0 / a * 1...
7
#include <bits/stdc++.h> using namespace std; template <class T> T Abs(T x) { return x > 0 ? x : -x; } template <class T> T Max(T a, T b) { return a > b ? a : b; } template <class T> T Min(T a, T b) { return a < b ? a : b; } template <class T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); } bool isVowel(cha...
7
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:256000000") using namespace std; const int maxN = 510000; const int maxK = 37; const double eps = 1e-20; vector<int> g[maxN]; int q; int n = 1; int parent[maxN]; double p[maxN][maxK]; double p2[maxN]; void initVertex(int v) { for (int i = 0; i < maxK; ++i) { ...
19
#include <bits/stdc++.h> using namespace std; int N, C; int A[100010]; int main() { scanf("%d %d", &N, &C); A[0] = -1e9 - 50653; for (int i = 1; i <= N; i++) { scanf("%d", &A[i]); } for (int i = N; i; i--) { if (A[i] - A[i - 1] > C) { printf("%d\n", N + 1 - i); return 0; } } }
0
#include <bits/stdc++.h> using namespace std; const int MAXS = 110000; struct Possibilities { int p, n, i; }; bool operator<(const Possibilities& p1, const Possibilities& p2) { if (p1.p == p2.p) return p1.n < p2.n; return p1.p < p2.p; } set<Possibilities> P; bool found(int p, int n) { Possibilities pp; pp.p =...
12
#include <bits/stdc++.h> using namespace std; int n, k, a[200001]; int main() { scanf("%d%d", &n, &k); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); int l = 0, r = 1000000001; while (r - l > 1) { int m = (l + r) >> 1, cnt = 0; for (int i = 1; i <= n; ++i) if (a[i] >= m) ++cnt; if (cnt >= k)...
1
#include <bits/stdc++.h> using namespace std; using uint = unsigned int; using ll = long long; const int M = 1e9 + 7; const ll MLL = 1e18L + 9; #pragma unused(M) #pragma unused(MLL) template <class... T> void printl(T&&...) {} template <class... T> void printc(T&&...) {} template <class... T> void prints(T&&...) {} tem...
2
#include <bits/stdc++.h> const int N = 1 << 20, MOD = 998244353; int power(int base, int exp) { int res = 1; for (; exp; exp >>= 1) { if (exp & 1) res = (long long)res * base % MOD; base = (long long)base * base % MOD; } return res; } void dft(int a[], int n) { for (int i = 0, j = 0; i < n; ++i) { ...
19
#include <bits/stdc++.h> using namespace std; const int sz = 1e5 + 5; int tc, n, a[sz], b[sz]; int main() { ios_base::sync_with_stdio(false), cin.tie(0); cin >> tc; while (tc--) { cin >> n; b[0] = -INT_MAX; for (int i = 1; i <= n; i++) { cin >> a[i]; b[i] = max(a[i], b[i - 1]); } i...
7
#include <bits/stdc++.h> using namespace std; long long int arr[100001]; int main() { long long int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> arr[i]; } long long int ans = 0; for (int i = 1; i <= n; i++) { if (i == 1) { ans += (arr[i]) * (n - arr[i] + 1); } else if (arr[i] > arr[i...
13
#include <bits/stdc++.h> using namespace std; inline long long read() { long long ans = 0, op = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') op = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { (ans *= 10) += ch - '0'; ch = getchar(); } return ans * op; } co...
18
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; string str; cin >> str; stack<char> st; st.push(str[0]); for (int i = 1; i < n; i++) { char ch = st.top(); if (ch == 'R' && str[i] == 'U') { st.pop(); st.pus...
0
#include <bits/stdc++.h> using namespace std; const int N = 505; int f[N], g[N], fac[N], n, mo; int F[N], G[N][N]; void init() { n = 400; g[1] = F[0] = F[1] = 1; f[1] = 0; fac[0] = 1; for (int i = (int)(1); i <= (int)(n); i++) fac[i] = 1ll * fac[i - 1] * i % mo; G[0][0] = G[1][1] = 1; for (int i = (int)(2...
18
#include <bits/stdc++.h> using namespace std; int main() { int flowers; cin >> flowers; int total = 0; int LowestOdd = 0; while (flowers--) { int petals; cin >> petals; total += petals; if (petals % 2 != 0 && (LowestOdd == 0 || petals < LowestOdd)) { LowestOdd = petals; } } if (t...
4
#include <bits/stdc++.h> int main() { int n, x; scanf("%d", &n); int counts[1000100] = {0}; for (int i = 0; i < n; i++) { scanf("%d", &x); counts[x]++; } int ans = 0; for (int i = 0; i < 1000100; i++) { if (counts[i] == 0) { continue; } counts[i + 1] += counts[i] >> 1; if (co...
7
#include <bits/stdc++.h> using namespace std; const int M = 1e5 + 10; struct TnT { TnT *next[27]; int vis; TnT() : vis(0) { memset(next, 0, sizeof(next)); } }; int k; void build(TnT *root, char s[]) { int len = strlen(s); TnT *p = root; for (int i = 0; i < len; i++) { int id = s[i] - 'a'; if (p->nex...
11
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int n; cin >> n; long long int temp = n; long long int rem = n / 9; if (n % 9 == 0) rem--; temp += rem; cout << temp << endl; } return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; int count = 0; while (t--) { int a, b, c; cin >> a >> b >> c; int k = a + b + c; if (k > 1) count++; } cout << count << endl; }
0
#include <bits/stdc++.h> using namespace std; int main() { int b, d; scanf("%d%d", &b, &d); if (b % d == 1) { printf("3-type\n"); return 0; } if (b % d == d - 1) { printf("11-type\n"); return 0; } int ans = -1, cnt = 0; for (int i = 2; i <= d; i++) if (d % i == 0) { int t = 0; ...
15
#include <bits/stdc++.h> using namespace std; bool common(vector<int> &a, vector<int> &b) { if (a.size() == 0 or b.size() == 0) return 0; int x1 = a[0], y1 = a[1], x2 = b[0], y2 = b[1]; if ((x2 <= x1 and y2 >= x1) or (x2 >= x1 and x2 <= y1)) return 1; return 0; } int main() { int t; cin >> t; while (t--) ...
7
#include <bits/stdc++.h> using namespace std; int main() { int n; double x1, y1, x2, y2; int vx, vy; double x, y; scanf("%d", &n); cin >> x1 >> y1 >> x2 >> y2; double mi = min(x1, x2); double ma = max(x1, x2); x1 = mi; x2 = ma; mi = min(y1, y2); ma = max(y1, y2); y1 = mi; y2 = ma; double l...
15
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; long long pw(long long x, long long y) { long long ret = 1; while (y) { if (y % 2) ret = ret * x % mod; x = x * x % mod; y /= 2; } return ret; } long long n; long long a[300009]; long long pre[300009]; int main() { ios_...
18
#include <bits/stdc++.h> using namespace std; using int64 = long long; constexpr int N = 1e5 + 10; int a[10], b[N]; int main() { for (int i = 0; i < 6; ++i) { scanf("%d", &a[i]); } int n; scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d", &b[i]); } vector<pair<int, int>> diff; for (int i...
11
#include <bits/stdc++.h> using namespace std; template <typename T> std::ostream &operator<<(std::ostream &out, vector<T> &v) { for (typename vector<T>::size_type i = 0; i < v.size(); ++i) out << v[i] << " "; out << "\n"; return out; } template <typename T, typename N> std::ostream &operator<<(std::ostream &o...
7
#include <bits/stdc++.h> using namespace std; int n, m, K; vector<int> gnext[100003]; vector<int> gcost[100003]; vector<int> gtrain[100003]; int train[100003]; int v[100003]; int from[100003]; long long dist[100003]; int main() { scanf("%d%d%d", &n, &m, &K); for (int i = 0; i < m; i++) { int a, b, c; scanf(...
12
#include <bits/stdc++.h> int main() { int i, x, y; scanf("%d", &x); for (i = 0; i < x; i++) { scanf("%d", &y); printf("%d\n", (y % 7) ? (y / 7 + 1) : (y / 7)); } return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int tt; cin >> tt; while (tt--) { int na, nb, nc; cin >> na >> nb >> nc; vector<int> a(na), b(nb), c(nc); for (int i = 0; i < na; i++) { cin >> a[i]; } for (int i = 0; i < nb; i++) { ...
9
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; template <typename A, typename B> istream& operator>>(istream& input, pair<A, B>& x) { input >> x.first >> x.second; return input; } template <typename A> istream& operator>>(istream& input, vector<A>& x) { for (auto& i : x) input >> i; ...
0
#include <bits/stdc++.h> using namespace std; long long v[100010]; int vis[100010]; vector<int> adj[100010]; int id[100010], sz[100010]; int n; void ufinit(int n) { for (int i = 0; i < n; i++) id[i] = i, sz[i] = 1; } int uffind(int i) { if (i == id[i]) return i; return id[i] = uffind(id[i]); } void ufunion(int v,...
11
#include <bits/stdc++.h> using namespace std; int fastio() { ios_base::sync_with_stdio(false); cout << fixed << setprecision(10); cin.tie(nullptr); return 0; } int __fastio = fastio(); template <typename A, typename B> ostream& operator<<(ostream& os, const pair<A, B>& p); template <typename A, typename B> ostr...
14
#include <bits/stdc++.h> using namespace std; int n, m, k; vector<pair<pair<int, int>, int> > v[400010]; long long ans[100010]; void ins(int first, int second, int i) { v[second - first + 2 * n].push_back(make_pair(make_pair(first, second), i)); } void ref(int &first, int &second) { if (first > n) first = 2 * n - f...
10
#include <bits/stdc++.h> using namespace std; int main(void) { int n, m; cin >> n >> m; if (n - 1 > m) cout << -1 << '\n'; else if (m > n * 2 + 2) cout << -1 << '\n'; else { while (n || m) { if (m && n) { if (m > n) { cout << "110"; m -= 2; n--; ...
6
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 69; int a[N], b[N], s[N], to[30], used[30], n, len, tmp_to[30], tmp_used[30], test, last; void print(int val) { if (!val) { cout << "NO\n"; return; } cout << "YES\n"; for (int i = 0; i < n; i++) { if (to[i] != -1) cout << ch...
15
#include <bits/stdc++.h> using namespace std; const long long MAX = 2e5 + 9; const long long INF = 1e12; long long N, K, res, arr[MAX]; map<long long, long long> par, cnt; long long power(long long base, long long exp) { long long res = 1; while (exp > 0) { if (exp % 2 == 1) res = res * base; base = base * ...
10
#include <bits/stdc++.h> using namespace std; int main() { int n, k = 0, j; int t[1000]; cin >> n; for (int i = 0; i < n; i++) { cin >> t[i]; } if (n < 3) cout << 0; else { for (j = 1; j < n - 1; j++) { if (t[j] < t[j - 1] && t[j] < t[j + 1]) k++; else if (t[j] > t[j - 1] &...
0
#include <bits/stdc++.h> using namespace std; bool cmp(const string& a, const string& b) { return (a + b < b + a); } int main() { ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); long long t, n, i, r, x; cin >> n; vector<string> s(n); for (i = 0; i < n; i++) cin >> s[i]; sort(s.begin(), s.end(), ...
9
#include <bits/stdc++.h> using namespace std; int main() { long long x, p; int q; scanf("%lld %d", &x, &q); for (int i = 1; i <= q; i++) { scanf("%lld", &p); long long sum = 0, ans = x, n = x; while (1) { if (p % 2 == 1) { ans = (p + 1) / 2 + sum; break; } else { ...
9
#include <bits/stdc++.h> using namespace std; int Nextint() { char ch = getchar(); while (ch < '0' || ch > '9') ch = getchar(); int x = 0; while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x; } const int maxn = 1010; int N, M, lt, c1[maxn], c2[maxn], cnt, srt[maxn]; in...
18
#include <bits/stdc++.h> using namespace std; int main() { string ai, bi; getline(cin, ai); getline(cin, bi); int j = 0; while (j < ai.length() && ai[j] == '0') j++; string a(ai.begin() + j, ai.end()); j = 0; while (j < bi.length() && bi[j] == '0') j++; string b(bi.begin() + j, bi.end()); if (a.leng...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, s, ans = -1; cin >> n >> s; for (int i = 1; i <= n; i++) { int x, y; cin >> x >> y; if (s * 100 >= x * 100 + y) ans = max(ans, (100 - y) % 100); } cout << ans; }
4
#include <bits/stdc++.h> using namespace std; const int M = (int)1e9 + 7; int add(int a, int b) { a += b; if (a >= M) { return a - M; } if (a < 0) { return a + M; } return a; } int mul(int a, int b) { return a * (long long)b % M; } int pw(int a, int b) { int r = 1; while (b) { if (b & 1) { ...
17
#include <bits/stdc++.h> using namespace std; const int INF = 1 << 30; struct Node { int f, s, pos; Node() {} bool operator<(const Node &n) const { return f > n.f || f == n.f && s > n.s; } }; int main() { int n; scanf("%d", &n); map<int, int> sc; int t; for (int i = 0; i < n; ++i) { scanf("%d", &t);...
5
#include <bits/stdc++.h> using namespace std; int n, lcnt = 0; vector<vector<vector<int>>> g; vector<int> deg; int leaves(int v, int p) { int leaf = v; for (unsigned int i = 0; i < g[v].size(); ++i) { if (g[v][i][0] != p) { g[v][i][2] = leaves(g[v][i][0], v); leaf = g[v][i][2]; } } if (leaf ...
8
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10, maxl = 20; int a[maxn], spp[maxn], spt[maxn][maxl], n; long long int sum[maxn], ans; int func(int i, int j) { return max(make_pair(a[i], i), make_pair(a[j], j)).second; } int get_max(int l, int r) { int an = spp[r - l + 1]; return func(spt[l...
15
#include <bits/stdc++.h> using namespace std; const int maxn = 120005; int n, q, top1, top2; int a[maxn], st1[maxn], st2[maxn]; long long sz[maxn * 4], t[maxn * 4], sum[maxn * 4], tag[maxn * 4], mn[maxn * 4], ans[maxn]; vector<pair<int, int> > v[maxn]; void build(int l, int r, int x) { sz[x] = 1; mn[x] = l; i...
22
#include <bits/stdc++.h> using namespace std; int f(int x, int d) { int res = 0; while (x) { x /= d; res += x; } return res; } bool is(int x) { if (x == 1 || x == 0) return false; if (x == 2) return true; if (x % 2 == 0) return false; for (int i = 3; i * i <= x; i += 2) if (x % i == 0) retur...
2
#include <bits/stdc++.h> using std::unordered_map; using std::vector; unordered_map<long long, int> inv_map; const int MOD = 1e9 + 7; long long inv(long long a) { if (a == 1) return 1LL; if (inv_map.find(a) != inv_map.end()) return inv_map[a]; return inv_map[a] = (inv(MOD % a) * (MOD - MOD / a)) % MOD; } vector<v...
14
#include <bits/stdc++.h> using namespace std; void desperate_optimization(int precision) { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(precision); } const long long MOD = 1e9 + 7; const int N = 1e5; map<int, int> lucky; long lon...
13
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; const long long N = 2e5 + 23; long long n, m, k, x, ans; long long fpow(int b) { long long res = 1, a = 2; while (b > 0) { if (b & 1) (res *= a) %= 1000000009; (a *= a) %= 1000000009; b >>= 1; } return res; } void solve() { cin ...
8
#include <bits/stdc++.h> template <class T> __inline__ __attribute__((always_inline)) T chkmax(T &a, const T b) { if (a < b) a = b; return a; } template <class T> __inline__ __attribute__((always_inline)) T chkmin(T &a, const T b) { if (a > b) a = b; return a; } template <class T> __inline__ __attribute__((alwa...
13
#include <bits/stdc++.h> using namespace std; int n, v[100]; string s[100], c; int def() { string s1, s2, s3; cin >> s1 >> s2; int p = s1.rfind("&") + 1, q = s1.find("*"), v1; if (q < 0) { v1 = 0 - p; q = 1000; } else v1 = (s1.size() - q) - p; s3 = s1.substr(p, q - p); if (s3 == "void") { ...
10
#include <bits/stdc++.h> using namespace std; long long int n, m, ar[1000005], sum, dp[150][3605], t; char s[1000005]; long long int add(long long int x, long long int y) { return (x + y) % 1000000007; } int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); cin >> t; dp[0][0] = 1; for (i...
12
#include <bits/stdc++.h> using namespace std; char x[1000], y[1000], z[1000]; int main(void) { int i; scanf("%s", x); scanf("%s", y); for (i = 0; x[i]; i++) { if (x[i] < y[i]) { puts("-1"); return 0; } if (x[i] == y[i]) z[i] = x[i]; if (x[i] > y[i]) z[i] = y[i]; } puts(z); retu...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; char tab[n][m]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) cin >> tab[i][j]; int i; bool t = true; for (i = 0; i < n; i++) { for (int j = 0; j < m; j++) if (tab[i][j] == 'X') { t = false;...
6
#include <bits/stdc++.h> #pragma comment(linker, "/stack:200000000") using namespace std; const int maxn = 500010; vector<int> G[maxn]; long long sz[maxn], dp[maxn]; pair<long long, long long> q[maxn], a[maxn], b[maxn]; int l, r; long long n, ans; int tot; map<pair<long long, long long>, int> mp; void add(int x, int y)...
19
#include <bits/stdc++.h> using namespace std; char a[110][110]; int main() { int n, k; scanf("%d%d", &n, &k); if (k > (n * n + 1) / 2) { puts("NO"); return 0; } puts("YES"); for (int i = 0; i < n; ++i) { a[i][n] = 0; for (int j = 0; j < n; ++j) { if ((i + j) % 2 || k == 0) { a[...
6
#include <bits/stdc++.h> using namespace std; int main() { long long q, q1; while (cin >> q) { q1 = q; bool flag = false; for (long long i = 2; i * i <= q; i++) { if (q % i == 0) { q /= i; flag = true; break; } } if (flag == false) { cout << "1" << endl ...
6
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 100; const int T = 1e5; int n, m, a[N], L[N], R[N]; int main() { cin >> n >> m; if (n == 1) return printf("0"), 0; for (int i = 1; i <= m; i++) scanf("%d", &a[i]); for (int i = m; i >= 1; i--) { L[i + a[i] + T] = L[i + a[i] + 1 + T] + 1; ...
17
#include <bits/stdc++.h> using namespace std; inline int read() { register int res = 0, c; while (c = getchar(), c < '0' || c > '9') ; do { res = (res * 10) + (c ^ 48); } while (c = getchar(), c >= '0' && c <= '9'); return res; } int s[300010], dp[300010]; map<int, int> R[300010]; int main() { int Q...
18
#include <bits/stdc++.h> using namespace std; long long max(long long a, long long b) { if (a > b) { return a; } return b; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long k; cin >> k; vector<long long> f(6); for (long long i = 0; i < 6; i++) { cin...
21
#include <bits/stdc++.h> using namespace std; int main() { int n; while (cin >> n) { int f[101] = {}; for (int i = 0; i < n; i++) { int tmp; cin >> tmp; f[tmp]++; } int x = 0; for (int i = 0; i <= 100; i++) x += f[i] / 2; cout << x / 2 << endl; } return 0; }
2
#include <bits/stdc++.h> using namespace std; double mx[100005], mn[100005]; long double p[100005], q[100005], ps[100005], qs[100005]; long double get(int i) { return mx[i] + (i > 0 ? ps[i - 1] * qs[i - 1] : 0); } int main() { if (false) { int n = 100; srand(time(NULL)); vector<double> P(n, 0), Q(n, 0); ...
16
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; long long t, w, b; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } int main() { scanf("%I64d%I64d%I64d", &t, &w, &b); long long x = min(w, b); long long gc = gcd(w, b); long long d ...
10
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5; int n; int value[N]; long long mask[N]; int main() { cin >> n; long long sum = 0; for (int i = 1; i <= n; i++) { cin >> value[i] >> mask[i]; sum += value[i]; } if (sum < 0) { for (int i = 1; i <= n; i++) value[i] *= -1; } lon...
19
#include <bits/stdc++.h> using namespace std; string a; string b; int lena; int lenb; vector<pair<int, int>> R; int lookup(int i, int j) { while (b[++i] == a[++j] && i < lenb && j < lena) ; return j - 1; } int lookdown(int i, int j) { while (b[++i] == a[--j] && i < lenb && j >= 0) ; return j + 1; } int ...
12
#include <bits/stdc++.h> using namespace std; const int N = 1505; int a[N]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); int k = 0; for (int i = 1; i <= n; i++) for (int j = i + 1; j <= n; j++) if (a[i] > a[j]) k ^= 1; int m; scanf("%d", &m); for (int i...
10
#include <bits/stdc++.h> using namespace std; int a, b, c, m, w, v; int ans = -1, A, B, C; int exgcd(int a, int b, int &x, int &y) { if (b == 0) return x = 1, y = 0, a; int d = exgcd(b, a % b, x, y), t = y; y = x - a / b * y; x = t; return d; } bool doit0(int a, int b, int c) { int x, y, d = exgcd(a, b, x, ...
16
#include <bits/stdc++.h> using namespace std; int n, mnans = 1e9, inans, tmp; string s, ans, rgb[] = {"RGB", "RBG", "GRB", "BRG", "GBR", "BGR"}; int main() { cin >> n >> s; for (int k = 0; k < 6; k++) { tmp = 0; int in = 0; for (int i = 0; i < n; i++) { if (s[i] != rgb[k][(in) % 3]) tmp++; i...
5
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d; scanf("%*d%*d%d%d%d%d", &a, &b, &c, &d); a -= c; b -= d; if (a < 0) a = -a; if (b < 0) b = -b; puts((a >= 5 || b >= 5 || a + b >= 7) ? "Second" : "First"); }
12
#include <bits/stdc++.h> void fre() { freopen("c://test//output.out", "w", stdout); } template <class T> inline void scand(T &x) { char c; x = 0; while ((c = getchar()) < '0') ; while (c >= '0' && c <= '9') x = x * 10 + (c - 48), c = getchar(); } template <class T> inline void gmax(T &a, T b) { if (b > a)...
11
#include <bits/stdc++.h> using namespace std; int arr[200009]; int main() { ios::sync_with_stdio(false); int n, m, x, i, res = 0; cin >> n >> m; string s; cin >> s; char c; for (i = 0; i < n - 1; i++) { if (s[i + 1] == '.' && s[i] == '.') res++; } for (i = 0; i < m; i++) { cin >> x >> c; x...
8
#include <bits/stdc++.h> using namespace std; const long long MAX = 2 * 100010; long long n; long long link[MAX], l[MAX], mus[MAX], uk = 1; vector<long long> q; int main() { ios::sync_with_stdio(); cin.tie(0); cout.tie(0); cin >> n; q.push_back(0); for (int i = 0; i < n; i++) { long long t, a, x; ci...
8
#include <bits/stdc++.h> using namespace std; vector<int> g[100005]; long long res; void go(int x, int p) { int n = g[x].size(); res += (n * 1LL * (n - 1)) / 2; for (int i = 0; i < n; i++) { if (g[x][i] == p) continue; go(g[x][i], x); } } int main() { ios_base::sync_with_stdio(0); int n; cin >> n;...
5
#include <bits/stdc++.h> using namespace std; int n, m = 256, sa[1000005], y[1000005], u[1000005], v[1000005], o[1000005], r[1000005], h[1000005], T; int a[1000005], sum[1000005], lim[1000005]; char str[1000005]; long long ans; vector<int> vec[1000005]; namespace seg { int val[4000005]; void build(int p, int l, ...
18
#include <bits/stdc++.h> using namespace std; const int INF = 0x3fffffff; const long long _INF = 0x7ffffffffffffffll; const double EPS = 1e-9; const double PI = acos(-1.0); template <class T, class INT> inline T pow(T x, INT y) { T res(1); for (T tt(x); y; y /= 2) { if (y & 1) res *= tt; tt *= tt; } ret...
9
#include <bits/stdc++.h> template <class T> inline T read() { T r = 0, f = 0; char c; while (!isdigit(c = getchar())) f |= (c == '-'); while (isdigit(c)) r = (r << 1) + (r << 3) + (c ^ 48), c = getchar(); return f ? -r : r; } template <class T> inline T min(T a, T b) { return a < b ? a : b; } template <clas...
16
#include <bits/stdc++.h> using namespace std; inline int read() { int k = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { k = k * 10 + ch - '0'; ch = getchar(); } return k * f; } int nedge = 0, p[200010...
15
#include <bits/stdc++.h> int F[100], a, b, c; int main() { scanf("%d%d%d", &a, &b, &c); F[0] = a, F[1] = b; for (int i = 2; i <= c; i++) F[i] = F[i - 1] + F[i - 2]; printf("%d", F[c]); return 0; }
8
#include <bits/stdc++.h> const long long mod = 1e9 + 7; const long long N = 5e5 + 5; using namespace std; long long MOD(long long a, long long b) { if (a < b) a += b; a = a % b; return ((a + b) % b); } long long modpow(long long x, long long n) { long long ans = 1; while (n) { if (n & 1) ans = MOD(ans * x...
10
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int mod = 1e9 + 7; long long n; int main() { cin >> n; long long ans = 0; if (n == 0) ans = 1; while (n) { long long x = n % 16; if (x == 0 || x == 4 || x == 6 || x == 9 || x == 10 || x == 13) { ans++; } else if (x...
12
#include <bits/stdc++.h> using namespace std; struct tree { long long v, id, l, r; } t[1000005]; struct peo { long long b, c; } p[1000005]; bool cmp(const peo &i, const peo &j) { return i.b < j.b; } long long n, m, a[1000005], s, belong[1000005], oldwz[1000005], pold[1000005]; bool cmp2(long long i, long long j) { ...
11
#include <bits/stdc++.h> using namespace std; template <class T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf("%d", &x); } void _R(long long &x) { scanf("%lld", &x); } void _R(double &x) { scanf("%lf", &x); } void _R(char &x) { scanf(" %c", &x); } void _R(char *x) { scanf("%s", x); } void R() {} template <clas...
24
#include<bits/stdc++.h> #define ll long long #define N 200015 #define rep(i,a,n) for (int i=(a);i<=(n);i++) #define per(i,a,n) for (int i=(n);i>=(a);i--) #define inf 0x3f3f3f3f #define infll 0x3f3f3f3f3f3f3f3f #define pb push_back #define mp make_pair #define pii pair<int,int> #define fi first #define se second #define...
19
#include <bits/stdc++.h> #pragma GCC optimize(2, 3, "Ofast") namespace MyMinMax { template <typename T> inline T mn(const T x, const T y) { return x < y ? x : y; } template <typename T> inline T mx(const T x, const T y) { return x > y ? x : y; } template <typename T> inline bool chmin(T &x, const T y) { return (x...
16
#include <bits/stdc++.h> using namespace std; const int MAX = (int)1e6 + 5, p = 998244353; int A[MAX], dig[13]; int e10[] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1755647, 17556470, 175564700, 757402647, 586315999, 871938225, ...
7
#include <bits/stdc++.h> using namespace std; int pos[200005]; int main() { int i, n, t, ans, x; cin >> t; while (t--) { cin >> n; for (i = 0; i <= n; i++) pos[i] = -1; ans = INT_MAX; for (i = 0; i < n; i++) { cin >> x; if (pos[x] == -1) pos[x] = i; else { ans = m...
4
#include <bits/stdc++.h> using namespace std; int main() { int n; long i; cin >> n; for (i = 1000000 - n; i < 1000000; i++) cout << i << " "; return (0); }
4