solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; int n; long double w, u, v; vector<pair<long double, long double> > cood; bool nostop() { bool r1 = 1, r2 = 1; for (auto it : cood) { long double t1 = it.second / u; long double t2 = it.first / v; if (t1 > t2 || t1 < 0) return 0; } return 1; } int lowest...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, h, q; scanf("%d %d %d", &n, &h, &q); vector<int> v(n + 1, h); for (int i = 0; i < q; i++) { int l, r, x; scanf("%d %d %d", &l, &r, &x); for (int j = l; j <= r; j++) v[j] = min(v[j], x); } long long ans = 0; for (auto x : v) ans ...
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int t; cin >> t; while (t--) { long long int n; cin >> n; long long int a[n + 1]; for (long long int i = 1; i <= n; i++) { cin >> a[i]; } long long int ans = 0; ...
4
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<vector<unsigned long long> > arr(n); for (int i = 0; i < n; ++i) { arr[i] = vector<unsigned long long>(n); } int zi, zj; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ...
2
#include <bits/stdc++.h> using namespace std; string s; int main() { cin >> s; int t = (s.size() - 1) / 2 + 1; bool ok = 1; if (s.size() % 2 == 1) { for (int i = 1; i < s.size(); i++) if (s[i] == '1') { ok = 0; } } else ok = 0; cout << t - ok; return 0; }
1
#include <bits/stdc++.h> using namespace std; struct P { double x, y; void scan() { scanf("%lf %lf", &x, &y); } double dis(P& a) { return hypot(x - a.x, y - a.y); } } a, b, c; double ab, bc, ac, tb, tc, l, r, lm, rm; double cal(double k) { P u = (P){k * b.x + (1 - k) * c.x, k * b.y + (1 - k) * c.y}; double au...
4
#include <bits/stdc++.h> using namespace std; int n,c[10][10]; signed main() { ios::sync_with_stdio(false); cin>>n; for(int i=1;i<=n;i++){ int x=i%10,p=i,y=0; while(p!=0){ y=p%10; p/=10; } c[x][y]++; } int ans=0; for(int i=1;i<=9;i++){ for(int j=1;j<=9;j++){ ans+=c[i][j]*c[j][i]; } } cout...
0
#include <bits/stdc++.h> using namespace std; inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;} template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();} template<class T> inline T sqr(T x) {return x*x;} typedef vector<int> vi; typedef vector<vi> vvi; typed...
0
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 100; const long long mod = 1e9 + 7; vector<pair<long long, long long> > a[N]; long long rev[N], f[N]; void check(long long x) { for (long long i = 0; i < a[x].size(); i++) { long long tmp = x; while (tmp % a[x][i].first == 0) { tmp ...
5
// C - Bugged #include <bits/stdc++.h> using namespace std; int main(){ int N; cin>>N; int sumS = 0; int minS = INT_MAX; for(int i=1; i<=N; ++i){ int s; cin>>s; sumS += s; if(s%10) minS = min(minS, s); } if(sumS%10==0) sumS = max(0, sumS - minS); cout<< sumS <<endl; }
0
#include <bits/stdc++.h> struct P { long long int x; long long int y; }; struct Seg { P a; P b; }; bool isEqual(P const &a, P const &b) { return a.x == b.x && a.y == b.y; } bool hasCommonPoint(Seg const &one, Seg const &two) { return isEqual(one.a, two.a) || isEqual(one.a, two.b) || isEqual(one.b, tw...
2
#include <bits/stdc++.h> using namespace std; int main() { int i, j; int a, b, c, d; cin >> a >> b >> c >> d; for (i = 0; i < 10000; i++) { for (j = 0; j < 10000; j++) { if (b + a * i == d + c * j) { cout << b + a * i << endl; return 0; } } } cout << "-1" << endl; retur...
1
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; int even = 0, odd = 0; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] % 2 == 0) { even++; } else { odd++; } } if (odd % 2 == 0) { cout << even << "\n"; } else { cout << odd << "...
1
#include <bits/stdc++.h> using namespace std; int main() { int map[100][100]; int n, m, k; cin >> n >> m >> k; int crossx[26]; int crossy[26]; char c; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> c; if (c == '#') map[i][j] = 0; else if (c >= 'a' && c <= ...
6
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; vector<long long> v(n); long long ans = 0; long long prev = 0; for (long long i = 0; i < n; i++) { cin >> v[i]; ans += abs(v[i] - prev); prev = v[i]; } ans += n - 1 + n; cout << ans << "\n"; return 0; }
2
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, i = 1; cin >> a >> b; for (long long i = 2; i <= 6000000; i++) { if (a <= i / 2 && b <= i / 3 && a + b <= (i / 2 + i / 3 - i / 6)) { cout << i; return 0; } } }
3
#include <bits/stdc++.h> using namespace std; int main() { long long int n, i; cin >> n; long long int a[n]; for (i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); long long int s1 = 0, s = 0; for (i = 0; i < n; i++) s += a[i]; if (n == 1) s1 = s; else s1 = 2 * s; for (i = 0; i < (n - 2); i++)...
3
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); std::vector<int> tiempo(n, 0); for (int i = 0; i < n; i++) { scanf("%d", &tiempo[i]); } int T; std::sort(tiempo.begin(), tiempo.end()); scanf("%d", &T); int counter = 0; for (int j = 0; j < n; j++) { int save ...
2
#include <bits/stdc++.h> using namespace std; using namespace std::chrono; template <typename A> ostream &operator<<(ostream &cout, vector<A> const &v); template <typename A, typename B> ostream &operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.first << ", " << p.second << ")"; } template <typ...
3
#include <bits/stdc++.h> using namespace std; const int N = 200010; vector<int> G[N], to[N]; int n, m; int Ex[N], Ey[N], fa[N]; int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); } int deg[N]; void DFS(int o, int f) { for (int v : G[o]) { if (v == f) continue; DFS(v, o); if (deg[v]) to[v...
4
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 500; int n; ll f[maxn + 1][maxn + 1][maxn + 1], ans = 1e18; ll s[maxn + 10][maxn + 10], t[maxn + 10][maxn + 10], a[maxn + 10][maxn + 10]; void upd(ll &x, ll y) { x = min(x, y); } int main() { scanf("%d", &n); for (int i = 1; i <= ...
0
#include <bits/stdc++.h> using namespace std; int c[1005]; int main() { int t; scanf("%d", &t); while (t--) { int n, m; scanf("%d%d", &n, &m); int cnt = 0; memset(c, 0, sizeof(c)); for (int i = 1; i <= n; i++) { int x; scanf("%d", &x); if (c[x] == 0) c[x] = 1; } for (...
1
#include <bits/stdc++.h> using namespace std; double dp[205][205][205]; struct node { double p; int v; int i; } a[205]; bool cmp(node a, node b) { return a.v > b.v; } int main() { int n, l, kk; scanf("%d %d %d", &n, &l, &kk); for (int i = 0; i < n; i++) { scanf("%lf", &a[i].p); a[i].i = i; a[i]....
2
#include<bits/stdc++.h> // Created by kobortor On 01:26:04 on 04-12-2020 using namespace std; #define allof(x) (x).begin(), (x).end() typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; struct point { ll x, y; point () : x(0), y(0) {} point (ll _x, ll _y) : x(_x), y(_y) {} }; ...
5
#include <bits/stdc++.h> const long long mod = 1000000007; using namespace std; const long long N = 100005; long long last[N]; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long q, id = 1; cin >> q; memset(last, -1, sizeof(last)); while (q--) { long long x, y, ans = 0; cin >...
2
#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 % m) * (a % m)) % m; b /= 2; a = ((a % m) * (a % m)) % m; ...
4
#include <bits/stdc++.h> using namespace std; string t; int N; const int tam = 3e5 + 9; long long mod1 = 1e9 + 7, mod2 = 1e9 + 9; long long p1 = 37, p2 = 41, shut1 = 0, shut2 = 0; long long v1[tam], v2[tam], po1[tam], po2[tam]; struct trie { list<pair<string, int> > m; } tr[tam]; long long exp(long long b, long long ...
5
#include <bits/stdc++.h> using namespace std; const int sz = 1e5 + 10, sz2 = 200, bl = 510; int n, m; int q[sz2][sz], fi[sz2][sz], la[sz2][sz], to[sz], ma[sz2], add[sz2]; int l, r; int ar[sz]; void ins(int nu, int p, int va) { if (q[nu][p]) { to[va] = fi[nu][p], fi[nu][p] = va; } else { fi[nu][p] = va, la[n...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 105000; struct Edge { int nex, y; } e[maxn * 2]; int lis[maxn], cnt; vector<int> V[maxn]; int n, m, top, tim, tot, ans; int belong[maxn], st[maxn], dfn[maxn], low[maxn], f[maxn]; bool flag, instack[maxn], v[maxn]; inline void addedge(int x, int y) { e[+...
2
#include <bits/stdc++.h> using namespace std; const long long MOD = 998244353; const long long INF = 1e10; using Graph = vector<vector<long long>>; char solve(char a) { if (a == '9') a = '1'; else a++; return a; } signed main() { long long T; cin >> T; for (long long t = 0; t < (long long)(T); t++) ...
4
#include <bits/stdc++.h> inline int zs(int a) { if (a < 2) return 0; for (register int i = 2; i * i <= a; i++) { if (a % i == 0) return 0; } return 1; } int f[1005], num, ans, n, k; int main() { scanf("%d %d", &n, &k); for (register int i = 2; i <= n; i++) { if (zs(i)) f[++num] = i; } for (regis...
1
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const int N = 100010; int main(void) { int n, s; cin >> n >> s; s *= 100; int resp = -1; for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; int k = x * 100 + y; int diff = s - k; if (diff < 0) continue; res...
1
#include <bits/stdc++.h> using namespace std; int main() { long long n, x; cin >> n; x = 1; while (x < n) { n -= x; x++; } cout << n; return 0; }
1
#include <bits/stdc++.h> using namespace std; struct ppap { int x, y, l, r; friend bool operator<(ppap x, ppap y) { return x.l < y.l; } }; multiset<ppap> s; const int N = 1000010; int n, m, tot, to[2000010], nxt[2000010], R[2000010], head[500010][2], L[500010][2]; void add(int x, int y, int opt, int r) { to[+...
6
#include <bits/stdc++.h> using namespace std; int n; int vec[100011]; int pila[100011], top = 0; int main() { scanf("%d", &n); int sol = 0; pila[top = 0] = -1; for (int i = 0; i < n; i++) { scanf("%d", &vec[i]); while (top > 0 && vec[pila[top]] < vec[i]) { sol = max(sol, vec[i] ^ vec[pila[top]]); ...
4
#include <bits/stdc++.h> using namespace std; pair<int, int> solve(long long s, int n) { long long state, x, y, row; state = x = y = 0; for (int i = 2 * n - 2; i >= 0; i -= 2) { row = 4 * state | (s >> i) & 3; x = (x << 1) | (0x936C >> row) & 1; y = (y << 1) | (0x39C6 >> row) & 1; state = (0x3E6B9...
2
#include <bits/stdc++.h> int main() { int y, a, b, c, d; scanf("%d", &y); while (1) { y = y + 1; int a = y / 1000; int b = y / 100 % 10; int c = y / 10 % 10; int d = y % 10; if (a != b && a != c && a != d && b != c && b != d && c != d) { break; } } printf("%d\n", y); }
1
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,a,b) for(int i=a;i>=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() #pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long lo...
0
#include <bits/stdc++.h> using namespace std; map<string, int> NameSet; int NameSetLen, A[1010], B[1010], n, m, K; struct Block { vector<int> Peo, Key, Room; void Check() { sort(Peo.begin(), Peo.end()); sort(Key.begin(), Key.end()); sort(Room.begin(), Room.end()); } }; bool operator==(Block A, Block B...
6
#include <bits/stdc++.h> using namespace std; int main() { vector<int> b1; int a2[203], b2[203], a, b, c; cin >> a >> b; for (int i = 0; i < a; i++) { cin >> c; a2[i] = c; } for (int i = 0; i < b; i++) { cin >> c; b1.push_back(-c); b2[i] = c; } sort(b1.begin(), b1.end()); int j = 0...
1
#include <bits/stdc++.h> using namespace std; int main() { int n = 0; scanf("%d", &n); if (n % 2) printf("-1\n"); else while (n) printf("%d ", n--); return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int a[1000] = {}, save[200] = {}; transform(s.begin(), s.end(), s.begin(), ::tolower); for (int i = 0; i < s.length(); i += 2) { if (s[i] != s[i + 1]) { if (save[s[i + 1]] > 0) save[s[i + 1]]-...
1
#include <bits/stdc++.h> using namespace std; int n; int a[300005]; int nxt[300005]; long long dp[300005]; map<int, int> nxtX[300005]; void solve() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } for (int i = 0; i < n + 2; i++) { nxt[i] = -1; nxtX[i].clear(); dp[i] = 0; ...
4
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; bool b = 0; for (int i = 0; i < s.length(); i++) { if (s.at(i) == 'H' || s.at(i) == 'Q' || s.at(i) == '9') { b = 1; cout << "YES"; break; } } if (b == 0) cout << "NO"; return 0; }
1
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; const int INF = 1e9 + 10; struct SegTree { int n; vector<pair<int, int>> d; void init(int _n) { n = _n; d.assign(4 * n + 1, {INF, 0}); } void update(int id, int l, int r, int u, int v, pair<int, int> val) { ...
6
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair<int, ll> P; const int INF = (1<<30); const ll INFLL = (1ll<<60); const ll MOD = (ll)(1e9+7); #define l_ength size void mul_mod(ll& a, ll b){ a *= b; a %= MOD; } void add_mod(ll& a, ll b){ a = (a<MOD)?a:(a-MOD); b = (b<MOD)?b:(b-MOD)...
0
#include <bits/stdc++.h> int main(void) { int n, i; long long a[50001] = {0}, average = 0, ans = 0, d, b[50001] = {0}; scanf("%d", &n); i = 1; while (i <= n) scanf("%I64d", a + i), b[i] = a[i], average += a[i++]; average /= n; for (i = 1; i < n; i++) { d = a[i] - average; a[i + 1] += d; if (d ...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5+10; int n; int h[maxn], a[maxn]; long long loga[maxn]; long long dp[maxn]; void update(int x, long long val) { for (x++; x < maxn; x += x & -x) loga[x] = max(loga[x], val); } long long query(int x) { long long out = 0; for (x++; x > 0; x -= x ...
0
#include <bits/stdc++.h> using namespace std; const int di[] = {-1, 0, 1, 0}; const int dj[] = {0, 1, 0, -1}; const long long MOD = 1e9 + 7; const long long INF = 1e9; const double EPS = 1e-5; int n, start, x; vector<int> num, nxt; unsigned int Random() { unsigned int r = rand(); r *= 12387; r += rand(); return...
2
#include <iostream> using namespace std; int main(void) { int x; cin>>x; cout<<x/3600<<":"<<x%3600/60<<":"<<x%60<<endl; return 0; }
0
#include <bits/stdc++.h> const int N = 100 + 10; int arr[N]; int main() { int n, m; while (~scanf("%d%d", &n, &m)) { int t = n / m; for (int i = 0; i < m; ++i) arr[i] = t; int num = n - t * m; for (int i = 0; i < num; ++i) arr[i]++; bool first = true; for (int i = 0; i < m; ++i) { if (...
1
#include <bits/stdc++.h> using namespace std; const int MAXN = 1100, INF = 1000000007; int a, b, c, l; long long ans, temp; long long C(long long x) { if (x < 2) return 0; return x * (x - 1) / 2; } int main() { cin >> a >> b >> c >> l; ans = 0; for (int i = 0; i <= l; i++) { int s = a + b + c + i, limit =...
1
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool upmin(T &x, T y) { return y <= x ? x = y, 1 : 0; } template <typename T> inline bool upmax(T &x, T y) { return x <= y ? x = y, 1 : 0; } const long double eps = 1e-9; const long double pi = acos(-1); const int oo = 1 << 30; const long lo...
4
#include <bits/stdc++.h> using namespace std; void err(istream_iterator<string> it) { cerr << endl; } template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << "[ " << *it << " = " << a << " ] "; err(++it, args...); } void test(int T) { int h, m, s, t1, t2; cin >...
2
#include <bits/stdc++.h> using namespace std; int n, m; long long dp[(1 << 19)][20]; int lowbit[(1 << 19)]; bool G[20][20]; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n >> m; for (int i = 1; i < (1 << 19); ++i) { int j; for (j = 0;; ++j) { if ((i & (1 << j))) { bre...
4
#include <iostream> #define r(i,n) for(int i=0;i<n;i++) using namespace std; int main(){ string s; while(cin>>s){ int a=0,b=0; r(i,s.size()-2){ if(s[i]=='J'&&s[i+1]=='O'&&s[i+2]=='I')a++; if(s[i]=='I'&&s[i+1]=='O'&&s[i+2]=='I')b++; } cout<<a<<endl<<b<<endl; } }
0
#include <bits/stdc++.h> using namespace std; int main() { int n, k, count = 0; cin >> n >> k; int y[n]; for (int i = 0; i < n; i++) { cin >> y[i]; if (y[i] + k <= 5) { count++; } } cout << (count / 3); return 0; }
1
#include <bits/stdc++.h> using namespace std; int p, nr, i, j; int put(int x, int y) { int rez = 1; while (y > 0) if (y % 2 == 0) { x *= x; x %= p; y /= 2; } else { rez *= x; rez %= p; --y; } return (rez); } int main(void) { cin >> p; for (i = 1; i < p; ++i) { ...
1
#include <bits/stdc++.h> using namespace std; template <typename T, typename T1> T amax(T &a, T1 b) { if (b > a) a = b; return a; } template <typename T, typename T1> T amin(T &a, T1 b) { if (b < a) a = b; return a; } void dfs(vector<long long> adj[], long long i, vector<bool> &visited) { if (visited[i]) retu...
3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, k; cin >> n >> k; string s; cin >> s; char ch = 'a'; long long sum = 0; while (sum < k) { for (int i = 0; i < n && sum < k; ++i) { if (s[i] == ch) { ++sum; ...
3
#include<stdio.h> int main(void) { int dp[1000]={0}; int n,i; scanf("%d",&n); dp[0]=1; dp[1]=1; for(i=2;i!=n+1;i++){ dp[i]=dp[i-1]+dp[i-2]; } printf("%d\n",dp[n]); }
0
#include<iostream> using namespace std; int main(){ int a,b; cin>>a>>b; cout<<a*b<<" "<<a+b+a+b<<endl; }
0
#include <bits/stdc++.h> using namespace std; int ln[205][3], n, m, fi[205], c[1050 * 2][3], h[205], li[205], ss = 1, st = 0, ans; bool b[1050 * 2], d[205]; int Ans[205], S, T, sg[205]; inline int Read() { int x = 0; char y; do y = getchar(); while...
5
#include<iostream> #include<queue> using namespace std; #define rep(i, n) for (int i = 0 ;i < int(n); ++i) struct edge{int to, len, den;}; vector<edge> ed[111]; int ee[111][111]; int main() { int n, m, l; for (;;) { cin >> n >> m >> l; if (n == 0 && m == 0 && l == 0) break; rep (i, 111) ed[i].clear...
0
#include <bits/stdc++.h> using namespace std; class point { public: double x, y; point() {} point(double a, double b) { x = a; y = b; } double dis(point a) { return (a.x - x) * (a.x - x) + (a.y - y) * (a.y - y); } double tri(point a, point b) { a.x -= x; b.x -= x; a.y -= y; b.y -= y...
2
#include <bits/stdc++.h> using namespace std; const long long INF = 1e6 + 5; const long long MAX = 1e7 + 5; const double pi = 3.14159265359; bitset<10000007> bs; vector<long long> prims; void sieve(long long n) { bs.set(); bs[0] = 0; bs[1] = 0; for (long long i = 2; i < n; i++) { if (bs[i]) { prims.pu...
3
#include <bits/stdc++.h> using namespace std; void RI() {} template <typename... T> void RI(int& head, T&... tail) { scanf("%d", &head); RI(tail...); } const int N = 110; int n, m; char s[3][N]; bool vis[3][N]; bool ok(int x, int y) { if (x < 0 || x >= 3) return 0; if (y >= n) return 1; char c = s[x][y]; re...
2
#include <bits/stdc++.h> using namespace std; struct candy { int t; int h, m; bool eat; }; candy c[2005]; int n, x; bool cmp(candy a, candy b) { if (a.m == b.m) return a.h > b.h; else return a.m > b.m; } int solve(int which) { for (int i = 0; i < n; i++) c[i].eat = false; int status = which, energ...
1
#include <cstdio> #include <iostream> #include <algorithm> using namespace std; int f[120][120],s[10000],sp,dis[120]; bool b[120]; const int maxdis=1000000000; int main(){ int n,m; while(scanf("%d%d",&n,&m)==2){ if(n==0&&m==0) break; int i,j,k; for(i=1;i<=n;i++){ for(j=1;j<=n;j++) f[i][j]=0; } int v1,v2,...
0
#include <bits/stdc++.h> using namespace std; const int N = 1505; int a[N], b[N], c[N * N]; struct node { int l, r; node(int x, int y) { l = x, r = y; } }; vector<node> v[N * N / 2]; int n; int main() { std::ios::sync_with_stdio(false); ; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; b[i] = ...
6
#include <bits/stdc++.h> using namespace std; long long n, k, ans = 1; int main() { scanf("%lld %lld", &n, &k); if (k >= 2) ans += n * (n - 1) / 2; if (k >= 3) ans += 2 * n * (n - 1) * (n - 2) / 6; if (k >= 4) ans += 9 * n * (n - 1) * (n - 2) * (n - 3) / 24; printf("%lld\n", ans); }
4
#include<bits/stdc++.h> #define int long long using namespace std; signed main() { int H, W, Cy, Cx, Dy, Dx; cin >> H >> W >> Cy >> Cx >> Dy >> Dx; --Dy, --Dx, --Cy, --Cx; vector<string> S(H); for (auto& s : S) cin >> s; const int inf = 1e18; vector<vector<int>> g(H, vector<int> (W, inf)); deque<pair...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) cout << i % 2; return 0; }
2
#include <bits/stdc++.h> using namespace std; const int MAXN = 100002; int main() { int vec[MAXN]; int sort1[MAXN]; int sort2[MAXN]; int n; scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d", &vec[i]); sort1[i] = sort2[i] = vec[i]; } if (n <= 2) { printf("-1\n"); return 0; } s...
2
#include <bits/stdc++.h> using namespace std; const int N = 100005; vector<int> e[N]; int n, ans, f[N][2], g[N][2]; void dfs1(int x, int fa) { f[x][0] = 0; f[x][1] = 0; int d = e[x].size() - (fa != 0); for (auto i : e[x]) if (i != fa) { dfs1(i, x); f[x][0] = max(f[x][0], max(f[i][0], f[i][1]) - ...
4
#include <bits/stdc++.h> using namespace std; int main() { long n; cin >> n; int m = 0; while (n > 2) { int x = log2(n); n -= pow(2, x); if (n == 0) m--; m++; } cout << m + 1; }
1
#include <bits/stdc++.h> using namespace std; const int M = 500000; int n, m, t; int a[M], ans[M]; struct edge { int u, next, last; } e[M]; void add(int u, int v) { t++; e[t].u = v; e[t].next = e[u].last; e[u].last = t; } int main() { int x, y; t = 0; priority_queue<int> q; scanf("%d%d", &n, &m); fo...
5
#include<bits/stdc++.h> using namespace std; #define INF 100000000 int po[8]; int t; int result; vector<int> ans; vector<int> anss; int Stoi(string s){ if(s == "") return 0; else{ int res = 0; int n = (int)s.size(); n--; for(int i = 0; i < s.size(); i++){ res += (in...
0
#include <bits/stdc++.h> using namespace std; long long N, K; long long f[15]; int count(long long x, long long k) { if (x > k) return 0; return 1 + count(10 * x + 4, k) + count(10 * x + 7, k); } bool check(long long x) { if (x == 0) return false; while (x) { long long r = x % 10; if (r != 4 && r != 7) ...
5
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; int ans[12 * MAXN]; int a[MAXN], b[MAXN], prime[MAXN], k = 0; void ini() { memset(prime, 0, sizeof(prime)); for (int i = 2; i < MAXN; i++) if (!prime[i]) { for (int j = i + i; j < MAXN; j += i) prime[j] = 1; } } void solve(int i, ...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, l, r, ql, qr; cin >> n >> l >> r >> ql >> qr; int w[n]; int sum = 0; for (int i = 0; i < n; i++) { cin >> w[i]; sum += w[i]; } int cur = 0; int ans = 2000000000; for (int i = 0; i <= n; i++) { int k = l * cur + r * (sum - cu...
1
#include <bits/stdc++.h> using namespace std; int main() { string s; int ren=0; cin >> s; vector<int> ans(s.size()); for(int i=0;i<s.size();i++) { ren++; if(s[i]=='L') { if(ren%2==0) ans[i-ren]++; else ans[i-ren+1]++; } if(i+1==s.size()) continue; if(s[i]=='R'&&s[i+1]=='L') {...
0
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-9; const long long mod = 1e9 + 7; const int max_n = 1000100; bool vis[100100] = {0}; int par[100100]; vector<int> g[100100]; bool ok; void dfs(int x) { vis[x] = 1; for (int i = 0; i < g[x].size(); i++) { if (!vis[g[x][i]]) { par[g[x][i]] ...
5
#include <bits/stdc++.h> using namespace std; long long n, m, k, mod = 1e9 + 7; long long power(long long x, long long n) { if (n == 0) return 1; long long p = power(x, n / 2); p = (p * p) % mod; if (n % 2) return (p * x) % mod; return p; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); c...
2
#include <iostream> #include <map> #include <vector> #include <string> #include <algorithm> using namespace std; int main(){ map<string,vector<int> > m; map<string,vector<int> >::iterator it; vector<int>::iterator itv; string s;int a; while(cin>>s){ cin>>a; m[s].push_back(a); } for(it=m.begin();it!=m.end();i...
0
#include <bits/stdc++.h> int main() { int i, q[100], b, c; scanf("%d", &b); for (i = 0; i < b; i++) { scanf("%d", &q[i]); if (q[i] == 1) c = 0; } if (c == 0) printf("HARD"); else printf("EASY"); return 0; }
1
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:256000000") using namespace std; long long mulmod(long long a, long long b, long long MOD) { if (b == 0) return 0; long long res = mulmod(a, b >> 1, MOD); res += res; res %= MOD; return (b & 1) ? (a + res) % MOD : res; } int gcd(int a, int b) { while ...
1
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-8; const double PI = acos(-1.0); int popcount(int n) { return __builtin_popcount(n); } int popcount(long long n) { return __builtin_popcountll(n); } template <class T> int SIZE(T a) { return a.size(); } template <class T> string IntToString(T num) { ...
6
#include <bits/stdc++.h> using namespace std; long long power(long long n) { long long res = 1ll; long long m = 2ll; while (n > 0) { if (n & 1) res = (res * m) % 1000000007; m = (m * m) % 1000000007; n = n >> 1; } return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout....
4
#include<iostream> #include<vector> #include<algorithm> #include<utility> #include<string> #include<cmath> #include<cstring> #include<queue> #include<map> #include<climits> #include<set> #include<tuple> #include<stack> using namespace std; typedef pair<int, int> pii; typedef long long int ll; typedef pair<ll, ll> pll...
0
#include <bits/stdc++.h> using namespace std; long long a[200002], b[200002], c[200002]; int n; long long temp; long long f(long long x) { if (c[x] != 0) { return c[x]; } long long xx = x; if (b[x] == 1) { c[x] = -1; return -1; } b[x] = 1; long long y = a[x]; x += a[x]; if (x > n) { c[...
4
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int hf = 999983; const int N = 1e6; vector<int> g[N]; int W[N], D[N]; multiset<pair<int, long long> > dp[N]; multiset<pair<int, long long> >::iterator its, its2; void dfs(int u, int p) { for (int i = 0; i < g[u].size(); i++) { int v = g[...
2
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:17000000") const double eps = 1e-9; const double inf = 1e+9; int n; string s; string q[100009]; long long mod = 1000000007; vector<long long> a(10); vector<long long> d(10); int main() { cin >> s >> n; for (int i = 0; i < n; i++) { ci...
3
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; if (n % 7 >= 2 && n % 7 <= 5) { cout << (n / 7) * 2 << " " << (n / 7) * 2 + 2; } else if (n % 7 == 6) { cout << (n / 7) * 2 + 1 << " " << (n / 7) * 2 + 2; } else if (n % 7 == 1) { cout << (n / 7) * 2 << " " << (n...
1
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double eps = 1e-11; template <class T> inline void ckmin(T &a, T b) { a = min(a, b); } template <class T> inline void ckmax(T &a, T b) { a = max(a, b); } template <class T> inline T sqr(T x) { return x * x; } using uint = unsigned i...
5
#include <bits/stdc++.h> using namespace std; const int INF = 1000000007; const long long MOD = 1000000007; void solve_test() { int n; cin >> n; vector<int> arr(n); vector<int> ct(101); for (int i = 0; i < n; i++) { cin >> arr[i]; ct[arr[i]]++; } int max_val = -1; int max_freq = -1; for (int i...
4
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3f; const int MOD = 1e9 + 7; template <typename S, typename T> inline bool Min(S &a, const T &b) { return a > b ? a = b, true : false; } template <typename S, typename T> inline bool Max(S &a, const T &b) ...
2
#include <bits/stdc++.h> using namespace std; struct edge { int a, b, c; edge(int _a = 0, int _b = 0, int _c = 0) : a(_a), b(_b), c(_c) {} int operator<(const edge &e) const { if (a == e.a) { return b < e.b; } return a < e.a; } }; const int MAXN = 200000; vector<edge> ve[MAXN + 10]; int S[MAXN...
5
#include <bits/stdc++.h> const int N = 10; int n, L, ALL; int a[N]; int f[32][324]; inline int min(const int x, const int y) {return x < y ? x : y;} inline int max(const int x, const int y) {return x < y ? y : x;} long double solve() { int i, j, k, c, to, len = n * L + L; memset(f, 0, sizeof f), f[0][(n + 1) * a[...
0
#include <bits/stdc++.h> using namespace std; template <typename... T> void read(T&... args) { ((cin >> args), ...); } template <typename... T> void write(T&&... args) { ((cout << args << " "), ...); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; string s;...
3