solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; template <class T> inline T lowbit(T x) { return x & (-x); } double delta(int x) { return sqrt(1.0 + 8.0 * x); } int main(void) { int a00, a01, a10, a11; cin >> a00 >> a01 >> a10 >> a11; int n = (1 + delta(a00)) / 2 + 0.5, m = (1 + delta(a11)) / 2 + 0.5; bool flag...
2
#include <bits/stdc++.h> using namespace std; int home[100007]; int away[100007]; void vin(vector<long long> &v, int n) { long long temp; while (n--) { cin >> temp; v.push_back(temp); } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long n, m; cin >> n >> m; vector<long long> v; ...
2
#include <bits/stdc++.h> using namespace std; const int N = 1000000; int n; int p[N << 1]; int main() { scanf("%d", &n); for (int i = 0; i < n; ++i) p[i] = i; int l = 0; for (int k = 2; k <= n; ++k) { int first = p[l]; for (int i = l + k; i < l + n; i += k) swap(first, p[i]); p[l + n] = first; +...
2
#include <bits/stdc++.h> int main() { int n, x[110], y[110], i, j, k, l, max = 0, x1, x2; scanf("%i", &n); for (i = 0; i < n; i++) { scanf("%i%i", &x[i], &y[i]); } for (i = 0; i < n - 1; i++) { x1 = x[i] + y[i]; for (j = i + 1; j < n; j++) { if (x[j] == x1 && x[j] + y[j] == x[i]) { p...
1
#include <bits/stdc++.h> #pragma GCC optimize "trapv" long long int power(long long int x, long long int b) { long long int p = 1; while (b > 0) { if (b & 1) { p = p * x; p %= 998244353; } b >>= 1; x *= x; x %= 998244353; } return p % 998244353; } using namespace std; struct ppp ...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, v1, v2, t1, t2, s, f; cin >> n >> v1 >> v2 >> t1 >> t2; f = 2 * t1 + n * v1; s = 2 * t2 + n * v2; if (f < s) cout << "First"; else if (s < f) cout << "Second"; else cout << "Friendship"; }
1
#include <bits/stdc++.h> using namespace std; using ll = long long; ll power(ll x, ll y); const ll MOD = 1000003; ll convert(string s) { ll ans = 0; ll n = s.size(); reverse(s.begin(), s.end()); for (ll i = 0; i < n; i++) { if (s[i] == '1') ans = ans + power(2, i); ans = ans % MOD; } return ans; } i...
2
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; const long long MOD = 1e9 + 7; long long n, a[N], l, r, mn = 1e18, t1, t2, ans; long long check(long long x) { long long len = 0; for (int i = 1; i <= n; i++) { len += abs(x - a[i] + 1); } return len; } int main() { scanf("%I64d", &n); ...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; char a[n]; for (int i = 0; i < n; ++i) { cin >> a[i]; } if (n == 1) { if (k == 1) { a[0] = '0'; } } else { if ((k > 0) && a[0] != '1') { a[0] = '1'; --k; } for (int i = 1; ((i < n)...
2
#include<bits/stdc++.h> using namespace std; #define LL long long int main() { ios::sync_with_stdio(0), cin.tie(0); int n, ans = 0; string s; cin >> n >> s; for(int i = 1; i < n; i++) { int d = 1; for(int j = 0; i + j < n; j++) { if(s[j] == s[i+j]) ans = max(ans, min(i, d...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); int v[n]; for (int i = 0; i < n; i++) scanf("%d", v + i); int zero[n]; int left = 2 * 1e9 + 1; for (int i = n - 1; i >= 0; i--) { if (v[i] == 0) left = i; zero[i] = left - i; } int right = -2 * 1e9 - 1; for (i...
2
#include <iostream> #include <algorithm> #include <string> #include <sstream> using namespace std; double x[4], y[4]; bool solve() { if(x[0] > x[1]) swap(x[0], x[1]); if(y[0] > y[1]) swap(y[0], y[1]); if(x[2] > x[3]) swap(x[2], x[3]); if(y[2] > y[3]) swap(y[2], y[3]); if(x[1] < x[2]) return false; if(y[1]...
0
#include <bits/stdc++.h> using namespace std; long long mod = 998244353; char ch[100001]; int main() { scanf("%s", ch); string s = ch; char x = 'a'; int r = 0, cnt = 0, can = 0; while (r < (int)s.size()) { if (s[r] <= x) { cnt++; s[r] = x; x++; if (x > 'z') x--; } if (cnt =...
3
#include <bits/stdc++.h> using namespace std; const int inft = 1000000009; const int mod = 1000000007; const int MAXN = 3006; char s[MAXN][MAXN]; int DP[MAXN][MAXN][2]; int solve() { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < (n); ++i) scanf("%s", s[i]); if (s[0][1] == '#' || s[1][0] == '#') return 0;...
4
#include <bits/stdc++.h> using namespace std; int n, m; long long a[100001]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%I64d", &a[i]); scanf("%d", &m); int Left = 1; for (; m--;) { int x, y; scanf("%d%d", &x, &y); while (Left < x) { a[Left + 1] = max(a[Left + 1], a[Le...
1
#include <bits/stdc++.h> using namespace std; const int INF = 0x7FFFFFFF; const long long LINF = 0x7FFFFFFFFFFFFF; void guan() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } const long long mod = 998244353; const int maxn = 1010101; char s[1111]; char ts[1111]; const int N = 111; long long a[N][N...
6
#include <bits/stdc++.h> using namespace std; const int N = 1005; int n, x, y, z; int A[N], a; int B[N], b; int r, u, v; void qry(int* A, int a) { if (!a) { z = 0; return; } printf("? %d ", a); for (int i = 0; i < a; i++) printf("%d%c", A[i], " \n"[i == a - 1]); fflush(stdout); scanf("%d", &z); } vo...
5
#include <bits/stdc++.h> using namespace std; unsigned long long choose[110][51]; unsigned long long difficulty; int bits[1100]; int bc; void convert(unsigned long long dd) { while (dd) { bits[bc++] = dd % 6; dd /= 6; } } void solve() { scanf("%llu", &difficulty); convert(difficulty); int size = 1 + 2...
4
#include <iostream> using namespace std; double f(double x1, double y1, double x2, double y2, double xp, double yp) { return (y2 - y1) * xp + (-x2 + x1) * yp - x1 * (y2 - y1) + y1 * (x2 - x1); } int main(void) { double x1, y1, x2, y2, x3, y3, xp, yp; double a, b, c; while(cin >> x1 >> y1 >> x2 >> y2 ...
0
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; using vi = vector<ll>; using vs = vector<string>; using ii = pair<ll, ll>; using ss = pair<string, string>; using ldld = pair<ld, ld>; template <typename X> istream& operator>>(istream& stream, ve...
1
#include <bits/stdc++.h> using namespace std; using ll = long long; const int inf = 1e9; ll n, m, k; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int sc; cin >> n >> m >> k >> sc; vector<pair<pair<ll, ll>, pair<ll, ll>>> dp(n + 1); vector<pair<ll, ll>> tr(n + 1, {1e9, -1e9}); for (int ...
4
#include <bits/stdc++.h> using namespace std; long long modpow(long long x, long long y, long long m) { if (x >= m) x %= m; if (y == 0) return 1 % m; long long z = modpow(x, y >> 1, m); z = z * z % m; if (y & 1) z = z * x % m; return z; } long long tower(long long x, long long y, long long m) { if (x >= m...
4
#include <bits/stdc++.h> using namespace std; const long long N = 11234; void scan(long long &n) { scanf("%lld", &n); } void scan(long long &n, long long &m) { scanf("%lld%lld", &n, &m); } void scan(vector<long long> &v) { long long n = v.size(); for (long long i = 0; i < n; i++) scanf("%lld", &v[i]); } vector<long...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, m; while (scanf("%d%d", &m, &n) != EOF) { double ans = 0; for (int i = m; i >= 1; i--) { ans += (pow(1.0 * i / m, n) - pow(1.0 * (i - 1) / m, n)) * i; } printf("%.4lf\n", ans); } return 0; }
3
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define en "\n"; #define all(x) (x).begin(), (x).end() ll mod = 1000000007; //ull n = 1e8; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll t; cin >> t; //cout<<"as.size()"<<en; ...
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...
1
#include<stdio.h> #include<iostream> using namespace std; int main() { long double a,b; cin>>a>>b; cout<<(long long)(a*b)<<endl; }
0
#include <bits/stdc++.h> using namespace std; const int maxn = 1000 + 5; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int main() { int n, a, b; vector<int> v; cin >> n; cin >> a; v.push_back(a); for (int i = 1; i < n; i++) { cin >> b; v.push_back(b); if (a < b) swap(a, b); a ...
1
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") const int maxn = 1e5 + 10, N = 3e6, SQ = 1000, base = 800287, mod = 1e9 + 7, INF = 1e9 + 10, lg = 22; const long double eps = 1e-4; int n, m, q; unordered_map<int, int> par[maxn], res[maxn]; inline int root(int v, int x) { return (p...
4
#include <bits/stdc++.h> using namespace std; const long long mod = 1e18; const double eps = 1e-10; const int inf = 0x3f3f3f3f; const int mif = 0xcfcfcfcf; const double PI = 3.14159265358979323846264338; long long mul_mod(long long first, long long second) { long long t = 0; while (second) { if (second & 1) t =...
2
#include <bits/stdc++.h> using namespace std; const int Maxn = 55; const int inf = 2147483647; const double pi = acos(-1.0); int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0',...
4
#include <bits/stdc++.h> using namespace std; char tmp[400005]; vector<string> ans; string s; bool canprint; bool check(string n) { int pos = n.find('.'); if (pos == n.size() - 1) return false; if (pos > 8 || pos == 0 || n.size() - pos - 1 > 3) return false; return true; } int main() { scanf("%s", tmp); s =...
2
#include <bits/stdc++.h> using namespace std; struct __s { __s() { if (1) { ios_base::Init i; cin.sync_with_stdio(0); cin.tie(0); } } ~__s() { if (!1) fprintf(stderr, "Execution time: %.3lf s.\n", (double)clock() / CLOCKS_PER_SEC); long long n; cin >> n; ...
5
#include <bits/stdc++.h> using namespace std; template <int MOD = 998244353> struct mint { int value; static const int MOD_value = MOD; mint(long long v = 0) { value = v % MOD; if (value < 0) value += MOD; } mint(long long a, long long b) : value(0) { *this += a; *this /= b; } friend mint ...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j, k, f; string s; char cap[15] = {'A', 'H', 'I', 'M', 'O', 'T', 'U', 'V', 'W', 'X', 'Y', 'o', 'v', 'w', 'x'}; cin >> s; i = 0; j = s.length() - 1; while (i <= j) { if (s[i] == s[j]) { for (k = 0; k < 15; k++)...
2
#include <cstdio> #include <iostream> #include <sstream> #include <fstream> #include <iomanip> #include <algorithm> #include <cmath> #include <string> #include <vector> #include <list> #include <queue> #include <stack> #include <set> #include <map> #include <bitset> #include <numeric> #include <climits> #include <cfloa...
0
#include <bits/stdc++.h> using namespace std; int main() { int A,B,C,K; cin>>A>>B>>C>>K; int kai=0; while(A>=B){ B=B*2; kai++; } while(B>=C){ C=C*2; kai++; } if(kai<=K) cout<<"Yes"<<endl; else cout<<"No"<<endl; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n, sum = 0, ca = 0, cb = 0; cin >> n; for (int i = 0; i < n; ++i) { int x; cin >> x; if (x == 100) ++ca; else ++cb; sum += x; } if (sum % 2 == 1) cout << "NO\n"; else { bool ok = 0; for (int i = 0; i <...
1
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 69, base = 1024 * 1024, mod = 1e9 + 7; int n; tuple<int, int, int, int> pref[N]; tuple<int, int, int, int> suma(tuple<int, int, int, int> a, tuple<int, int, int, int> b) { tuple<int, int, int, int> re; get<0>(a) =...
3
#include <iostream> #include <cstdlib> #include <string> #include <cmath> #include <algorithm> using namespace std; #define rep(i, n) for(int i = 0; i < n; i++) const int INF = 1 << 29; int t[1000]; int l[1000]; int main(){ int n,m; while(cin >> n >> m && (n || m)){ rep(i, n){ cin >> t[i]; } re...
0
#include <bits/stdc++.h> using namespace std; void start() { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); } int main() { int n; cin >> n; string s; cin >> s; int a[10]; for (int i = 0; i < 10; i++) a[i] = 0; for (int i = 0; i < n; i++) for (int j = 2; j <= (s[i] - '0'); j+...
1
#include <bits/stdc++.h> using namespace std; unsigned long long int n, a[11111], m, ans, ans1, b[11111], leaf, jolt, flar, umbr, glac, sylv; bool used[11111]; vector<int> v; int main() { string s; cin >> n; cin >> s; if (s.size() == 8) { cout << "vaporeon"; return 0; } if (s.size() == 6) { ...
1
#include <bits/stdc++.h> int n, t; int main() { scanf("%d", &n); n == 1 << (t = log2(n)) ? puts("YES") : puts("NO"); }
1
#include <bits/stdc++.h> using namespace std; int pos[500005][25], arr[500005], fa[500005][25], bit[500005]; inline int calc(int x, int y) { if (arr[x] <= arr[y]) return x; return y; } inline int query(int l, int r) { int len = bit[r - l + 1]; return calc(pos[l][len], pos[r - (1 << len) + 1][len]); } int main()...
2
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main(){ int n; cin>>n; vector<int> a(n); priority_queue<int> q; ll extra=0,ans=0; for(int i=0;i<n;i++) cin>>a[i]; for(int i=0;i<n;i++){ int b; cin>>b; if(a[i]<b) ans++,extra+=b-a[i]; else ...
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 123; int neg = 0; int pos = 0; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { pair<int, int> p; cin >> p.first >> p.second; if (p.first > 0) pos++; else neg++; } if (pos <= 1 || neg <= 1) { cout <...
1
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e9; const int mod = inf + 7; const double eps = 1e-9; const double pi = acos(-1.0); const int maxn = (int)1e5 + 11; string second; int main() { getline(cin, second); if (second[0] == '#') { cout << -1 << endl; return 0; } vector<int> an...
1
#include <bits/stdc++.h> const int maxn = 1e5 + 10; const int N = 5e2 + 10; using namespace std; long long gcd(long long p, long long q) { return q == 0 ? p : gcd(q, p % q); } long long qpow(long long p, long long q) { long long f = 1; while (q) { if (q & 1) f = f * p % 1000000007; p = p * p % 1000000007; ...
3
#include <bits/stdc++.h> using namespace std; vector<int> e[50001]; bool xet[50001]; int cha[50001]; int n, r1, r2; void dfs(int u) { xet[u] = true; for (int i = 0; i < e[u].size(); i++) { int v = e[u][i]; if (!xet[v]) { cha[v] = u; dfs(v); } } } int main() { scanf("%d%d%d", &n, &r1, &r2...
4
#include <bits/stdc++.h> using namespace std; const int N = 100100; const long long Inf = 3000000000000000000ll; int n; long long x[N] = {}, y[N] = {}, z[N] = {}, mx, my, mz; long long m1[4] = {}, m2[4] = {}, v[4] = {}; void init() { scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%I64d%I64d%I64d", x + i, y + ...
5
#include <bits/stdc++.h> int n, m, q; int grid[100][100]; int base[100][100]; int cross[100][100][100]; int fp[50][50][50][50]; int sp[50][50][50][50]; int main() { scanf("%d%d%d", &n, &m, &q); for (int i = 0; i <= n + 1; i++) for (int j = 0; j <= m + 1; j++) grid[i][j] = 1; for (int i = 1; i <= n; i++) { ...
2
#include <bits/stdc++.h> using namespace std; bool comp(pair<int, int> a, pair<int, int> b) { return (a.first > b.first); } struct mycomp { bool operator()(const int& a, const int& b) const { return (a > b); } }; int main() { int n, s; cin >> n >> s; map<int, int, mycomp> m1; map<int, int> m2; int q, p; s...
2
#include <bits/stdc++.h> using namespace std; const int N = 5009, MOD = 998244353; template <unsigned _MOD_> struct modint { static const int MOD = _MOD_; int v; modint(int _v = 0) { v = _v % MOD; if (v < 0) v += MOD; } explicit operator int() const { return v; } static int mod_inv(int a) { int ...
6
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > upd; struct query { int l, r, t, id, ans; query() {} query(int _l, int _r, int _t, int _id) { l = _l; r = _r; t = _t; id = _id; } }; vector<query> que; stack<pair<int, int> > S; vector<int> V; int M[1005][105]; int sz[1005]; i...
6
#include <bits/stdc++.h> using namespace std; int n, m; int st[1005], ed[1005], wei[1005], hp[1005], val[1005]; vector<int> lk[1005]; int dp[505][1005]; int sub[1005]; int func(int id, int L) { if (L > hp[id]) L = hp[id]; if (dp[id][L] != -1) return dp[id][L]; for (int i = (st[id] + 1); i <= (ed[id]); i++) { ...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int a[maxn], dp[maxn], n; int lis() { int len = 1; dp[1] = a[1]; for (int i = 2; i <= n; i++) { if (a[i] >= dp[len]) { dp[++len] = a[i]; } else { int pos = upper_bound(dp + 1, dp + len + 1, a[i]) - dp; dp[pos] = a[i...
5
#include <bits/stdc++.h> using namespace std; /*{{{*/ //template #define rep(i,n) for(int i=0;i<n;i++) constexpr int INF = numeric_limits<int>::max()/2; constexpr long long LINF = numeric_limits<long long>::max()/3; #define mp make_pair #define pb push_back #define eb emplace_back #define fi first #define se second #d...
0
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; const int MOD = 1000000007; vector<pii> ree; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; for (int i = (0); i < (n); i++) { int x, v; cin >> x >> v; ree.push_back({x + ...
2
#include <bits/stdc++.h> using namespace std; const long long MOD = (long long)1e9 + 7; const int N = 5 * (int)1e5 + 100; long long n, m, k; unsigned long long p2[N], c[N]; class UFDS { public: vector<long long> p, rank; UFDS(int n) { rank.assign(n, 0); p.assign(n, 0); for (int i = 0; i < n; i++) p[i] ...
5
#include <bits/stdc++.h> using ul = std::uint32_t; using li = std::int32_t; using ull = std::uint64_t; using ll = std::int64_t; using vul = std::vector<ul>; using vvul = std::vector<vul>; using vb = std::vector<bool>; using vvb = std::vector<vb>; using vvvb = std::vector<vvb>; using vull = std::vector<ull>; using vvull...
5
#include <bits/stdc++.h> using namespace std; const int inf = 1000000000; bool cmp(pair<int, int> a, pair<int, int> b) { return a.second < b.second; } int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; stack<int> s; int a[n + 1], b[m]; long long ans = 0; for (int i = 1; i <= n; i...
3
#include <map> #include <set> #include <list> #include <cmath> #include <deque> #include <queue> #include <stack> #include <cstdio> #include <string> #include <vector> #include <complex> #include <cstdlib> #include <cstring> #include <iomanip> #include <numeric> #include <utility> #include <iostream> #include <algorith...
0
#include <bits/stdc++.h> using namespace std; long long int pow(long long int x, long long int y, long long int m) { long long int res = 1; x = x % m; while (y > 0) { if (y & 1) res = ((res % m) * (x % m)) % m; y = y >> 1; x = ((x % m) * (x % m)) % m; } return res % m; } template <typename Arg1> v...
3
#include <bits/stdc++.h> using namespace std; int main() { long long int n, i, j, k, l; cin >> n; while (n--) { long long int n1, k1; cin >> n1 >> k1; string s; cin >> s; sort(s.begin(), s.end()); if (s[0] != s[k1 - 1]) { cout << s[k1 - 1] << "\n"; } else { cout << s[0]; ...
3
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { cin.tie(0), cout.tie(0), ios::sync_with_stdio(0); int n, a, b; cin >> n >> a >> b; string str; cin >> str; str.push_back('*'); int cnt = 0; int ans = 0; for (auto i : str) { if (i == '.') { ++cnt; } else { ...
2
#include <bits/stdc++.h> using namespace std; const long long zero = 0; const double PI = 3.14159265358979323846; void solve() { long long n, m; string s; cin >> n; long long a, b; if (n % 2 == 0) { b = 4; a = b + n; } else { b = 9; a = b + n; } cout << a << " " << b; } int32_t main() { ...
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; string s, s2 = ""; cin >> n >> k >> s; for (int i = 0; i < n; i++) { if (k == 0) { s2.push_back(s[i]); } else if (i == 0 && s[i] == '1' && n > 1 || s[i] == '0') { s2.push...
2
#include <bits/stdc++.h> using namespace std; double pi = 3.14159265358979; struct pt { double x; double y; }; struct line { double a; double b; double c; }; line to(pt a, pt b) { line l; l.a = (b.y - a.y); l.b = (a.x - b.x); l.c = (-a.x * l.a - a.y * l.b); return l; } pt perec(line l1, line l2) { ...
4
#include <bits/stdc++.h> using namespace std; int n; int t[60], v[60]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &t[i]); for (int i = 1; i <= n; i++) scanf("%d", &v[i]); int nrOfStonesTakenAway = 0; for (int i = 1; i <= n; i++) { if (t[i] > v[i]) nrOfStonesTakenAway += (t[i] -...
1
#include <bits/stdc++.h> using namespace std; vector<pair<double, int> > B[2]; const double yy = 100000 - 0.000001; int hl, hr, n; int debug; int getscore(int ud, double pos, double t) { int ret = 0, flag, cnt; { vector<pair<double, int> > tmp = B[ud]; for (double tp = pos; tp < yy; tp += t + t) { tmp...
3
#include <bits/stdc++.h> using namespace std; long long n, k; vector<long long> perm; bool used[20]; string hf = "4"; int ans; bool ish(long long q) { while (q > 0) { if (q % 10 != 4 && q % 10 != 7) return false; q /= 10; } return true; } long long ltoa() { long long ten = 1; long long ta = 0; for (...
5
#include <bits/stdc++.h> using namespace std; int gi() { int x = 0, w = 1; char ch = getchar(); while ((ch < '0' || ch > '9') && ch != '-') ch = getchar(); if (ch == '-') w = 0, ch = getchar(); while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar(); return w ? x : -x; } const ...
4
#include <bits/stdc++.h> using namespace std; int n, k; string s; int puede[1001][2001]; char letra[1001][2001]; char sol[1001]; void genera(int j) { for (int i = n; i >= 1; i--) { sol[i] = letra[i][j]; if (sol[i] == 'W') j--; else if (sol[i] == 'L') j++; } for (int i = 1; i <= n; i++) cou...
5
#include <bits/stdc++.h> using ld = long double; const ld EPS = 1e-12; const ld PI = acos((ld)-1); inline bool equ(const ld& a, const ld& b) { return std::abs(a - b) < EPS; } struct vec { public: ld x, y; bool operator==(const vec& o) const { return equ(x, o.x) && equ(y, o.y); } vec& operator+=(const vec& o) { r...
2
#include<iostream> using namespace std; int main(){ int a,b,c,d,e,f; int g,h,i,j,k,l; cin >> a >> b >> c >> d >> e >> f; cin >> g >> h >> i >> j >> k >> l; for(int i=0; !(a==g && b==h); i++){ if(d==h || c==h){ int tmp = a; a = d; d = f; f...
0
#include <bits/stdc++.h> using namespace std; int a, b; int main() { scanf("%d%d", &a, &b); for (int i = 1;; i++) { if (a < i) { printf("Vladik"); return 0; } a -= i; i++; if (b < i) { printf("Valera"); return 0; } b -= i; } return 0; }
1
#include<iostream> #include<vector> #include<queue> using namespace std; int main(){ //sanbeki int sanbeki[16]; int i; sanbeki[0]=1; for(i=1; i<=15; i++){ sanbeki[i] = 3*sanbeki[i-1]; } //input nm int n,m; cin >> n >> m; while(n!=0){ //input start int st...
0
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template <typename T> istream &operator>>(istream &in, vector<T> &v) { for (auto &x : v) in >> x; return in; } template <typename T> ostream &operator<<(ostream &out, const vector<T> &v) { for (auto ...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 1005; int n, a[maxn], b[maxn], tot = 0, x, y; struct node { int a, b, c, d; node(){}; node(int aa, int bb, int cc, int dd) { a = aa; b = bb; c = cc; d = dd; } } ans[maxn]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++...
6
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; for (int w = 1; w <= t; w++) { long long int n, sum = 0, max = 2, f = 0, c = 2; cin >> n; vector<int> v(n); for (int i = 0; i < n; i++) { cin >> v[i]; } ...
2
#include<iostream> #include<fstream> #include<sstream> #include<cstdio> #include<vector> #include<list> #include<stack> #include<queue> #include<deque> #include<map> #include<set> #include<algorithm> #include<cmath> #include<string> #include<cstring> #include<cstdlib> #include<climits> #include<utility> #include<cctype...
0
#include <bits/stdc++.h> using namespace std; int main() { long a, b, n, x, y, v; double mn = INT_MAX, time; cin >> a >> b >> n; while (n--) { cin >> x >> y >> v; time = (double)(sqrt(pow(x - a, 2) + pow(y - b, 2))) / v; mn = min(mn, time); } cout << fixed << setprecision(20) << mn << endl; }
1
#include <bits/stdc++.h> using namespace std; long long q, n, c[30], r, a[100001]; string s; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> s; for (int i = 0; i < n; i++) { if (s[i] == ')') { c[1]--; if (c[1] < 0) c[2] += 2; } else c[1]++; } if (c[1] != 0) c...
1
#include <cstdio> int main() { int year, month, day; while (~scanf("%d %d %d", &year, &month, &day)) { if (year < 1868 || (year == 1868 && (month < 9 || (month == 9 && day < 8)))) printf("pre-meiji\n"); else if (year < 1912 || (year == 1912 && (month < 7 || (month == 7 && day < 30)))) printf("m...
0
#include <iostream> using namespace std; int main() { int a,b,c; while(cin >> a >> b >> c){ if(a + b < 16) cout << "YES" << endl; else if(a + b > 16) cout << "NO" << endl; else if(c <= 4) cout << "NO" << endl; else cout << "YES" << endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long INF = 5e18; const long double pi = acos(-1.0); mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); } long long lcm(long long a, ...
4
#include <bits/stdc++.h> using namespace std; long long start, n, init; void kezd(long long l, long long r, long long dex, bool up) { if (l == r) { return; } long long m = (l + r - 1) / 2; start = max(start, dex + m * (up ? 1ll : -1ll)); kezd(m + 1, r, dex + m * (up ? 1l : -1ll), !up); } void lep(long lon...
1
#include <bits/stdc++.h> using namespace std; char input[5002]; char tmpstr[5002]; long long int calculate(char* str, int x, int y) { long long int tmp, result; result = tmp = 0; for (int i = x; i <= y;) { if (tmp == 0) tmp = atol(str + i); else tmp *= atol(str + i); while (str[i] != '*' &...
5
#include <bits/stdc++.h> using namespace std; int main() { string borze_code; cin >> borze_code; for (auto i = 0; i < borze_code.size(); i++) { if (borze_code[i] == '.' && (borze_code[i + 1] == '-' || (borze_code[i + 1] == '\0' || (borze_code[i + 1] == '.')))) { cout << 0; } else if...
2
#include <bits/stdc++.h> template <class T> int getbit(T s, int i) { return (s >> i) & 1; } template <class T> T onbit(T s, int i) { return s | (T(1) << i); } template <class T> T offbit(T s, int i) { return s & (~(T(1) << i)); } template <class T> int cntbit(T s) { return __builtin_popcount(s); } template <cla...
2
#include <bits/stdc++.h> using namespace std; inline long long read() { long long nm = 0; bool fh = true; char cw = getchar(); for (; !isdigit(cw); cw = getchar()) fh ^= (cw == '-'); for (; isdigit(cw); cw = getchar()) nm = nm * 10 + (cw - '0'); return fh ? nm : -nm; } multiset<int> S; set<pair<int, int> > ...
5
#include <iostream> #include <string> #include <algorithm> using namespace std; int main() { int score[4],a,b,total=0; for(int i=0;i<4;i++){ cin>>score[i]; } sort(score,score+4); for(int i=0;i<3;i++){ total+=score[3-i]; } cin>>a>>b; total+=max(a,b); cout<<total<<endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; const long long N = 2e6 + 5, inf = 1e9 + 7; long long n, k, i, j; long long A[N]; long long in[N], f[N]; inline long long expo(long long n, long long k, long long p = inf) { if (k < 0) { n = expo(n, inf - 2); k = -k; } long long r = 1; for (; k; k >>= 1) { ...
4
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int n; cin >> n; if (n % 2 == 0) cout << "NO" << endl; else { cout << "YES" << endl; if (n == 1) { cout << "1" << " " << "2" << endl; } else if (n == 3) { cout << "1" ...
3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); long long r, g; cin >> r >> g; long long dp[r + 1][2]; memset(dp, 0, sizeof(dp)); dp[0][0] = 1; long long temp = r + g; double k = -1 + sqrt(1.0 + 8.0 * (double)(temp)); k = k / 2.0; ...
4
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; const int N = 1e5 + 5; long long pref_sum[N], suff_sum[N]; long long a[N]; long long p, n, d; long long b; int first_instructor(long long students) { int ans = 0; long long debt = 0LL; for (int i = 0; i < (n + 1) / 2; ++i) { if (a[i] < b + deb...
4
#include <bits/stdc++.h> using namespace std; int n, m; bitset<2010> g[2010]; long long f[2010][2010]; map<long long, int> cnt; long long calc(int n) { long long ans = 0; for (int i = 0; i <= n; i++) ans = (ans + f[n][i]) % 1000000007LL; return ans; } long long solve(int n, int m) { long long ans = 1LL; int k...
5
#include<bits/stdc++.h> #ifndef LOCAL #define cerr if(false)cerr #endif // LOCAL using namespace std; using ll = long long; const int N = 1e6 + 66; const int inf = 1e9 + 123; int a[N], last[N]; vector<int>pos[N]; int dp[N][2], n; int solve(int i, int t) { if (i <= 0) return 0; if (~dp[i][t]) return dp[i][t]; if ...
5
#include <bits/stdc++.h> using namespace std; const int N = 200005; const int G = N; set<pair<int, int> > S; set<int> a[N]; int ans[N]; bool was[N]; vector<int> C[G + G]; int n, m; bool solve() { while (!S.empty()) { int idx = S.begin()->second; if (a[idx].empty()) { cerr << "fail " << idx << endl; ...
3
#include <bits/stdc++.h> using namespace std; bool fun(int a, int b) { long double s = (long double)a * b, x = 100000; long double t = x * x * x; while (abs(t - s) > 0.5) { x -= (t - s) / (3 * x * x); t = x * x * x; } long long c = (long long)x; if (c * c * c != (long long)a * b) return 0; if (a %...
3