solution
stringlengths
53
181k
difficulty
int64
0
13
#include <bits/stdc++.h> using namespace std; const int maxN = 2005; string arr[maxN], dir = "v^><"; int n, m, cnt = 0; int d[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; bool check(int i, int j) { if (i >= 0 and i < n and j >= 0 and j < m) { return 1; } return 0; } int dfs(int u, int v, int dept) { cnt++; ...
7
#include <bits/stdc++.h> using namespace std; void solve() { long long int t, i, j, k, n, x, y, z, r, l, a, c, b, q, T, d, m; cin >> n; long long int first = ceil(double(n) / 3); long long int first1 = (n) / 3; long long int second = (n - first) / 2; if ((first * 1 + (second)*2) == n) cout << first << "...
0
#include <bits/stdc++.h> using namespace std; int days[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; queue<long long> Q; int n, m; char s[10000100]; int main() { cin >> n >> m; int tot = 0; while (scanf("%s", s) != EOF) { ++tot; long long now = 0; int MMM = (s[5] - '0') * 10 + s[6] - '0';...
6
#include <bits/stdc++.h> using namespace std; int c[120]; int n, a, b; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> a >> b; for (int i = 0; i < a; i++) { int t; cin >> t; c[t] = 1; } for (int i = 0; i < b; i++) { int t; cin >> t; c[t] = 2; } fo...
0
#include <bits/stdc++.h> using namespace std; int n, m, a, sume, sumo, sum1, sum2; int main() { scanf("%d %d", &n, &m); for (int i = 0; i < n; i++) { scanf("%d", &a); if (a % 2 == 0) sume++; else sumo++; } for (int i = 0; i < m; i++) { scanf("%d", &a); if (a % 2 == 0) sum1+...
0
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 2; int v[N]; set<int> s; int main() { int n; cin >> n; for (int i = 1; i <= n; ++i) cin >> v[i]; if (v[1] != 0) return cout << 1, 0; int p(0); for (int i = 2; i <= n; ++i) { if (p < v[i] - 1) return cout << i, 0; s.insert(v[i]); w...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, sum1 = 0, sum2 = 0; cin >> n; string str; cin >> str; for (int i = 0; i < n; i++) { sum1 += str[i]; } for (int j = n; j < 2 * n; j++) { sum2 += str[j]; } if (sum1 == sum2) cout << "NO" << endl; else { int more = 0, les...
1
#include <bits/stdc++.h> int main() { int n, p, check = 0; scanf("%d%d", &n, &p); char a[n]; scanf("%s", a); a[-1] = 0; a[-2] = 0; for (int i = n - 1; i >= 0; i--) { for (int z = 1; a[i] + z <= 96 + p; z++) if ((a[i] + z) != a[i - 1] && (a[i] + z) != a[i - 2]) { a[i] = a[i] + z; ...
4
#include <bits/stdc++.h> using namespace std; int main() { int a1, b1, c1, a2, b2, c2; cin >> a1 >> b1 >> c1 >> a2 >> b2 >> c2; if (a1 == 0 && b1 == 0 && c1 != 0 || a2 == 0 && b2 == 0 && c2 != 0) printf("0\n"); else if (a1 * b2 == a2 * b1) { if (b1 * c2 == b2 * c1 && a1 * c2 == a2 * c1) printf("-1...
6
#include <bits/stdc++.h> using namespace std; int main() { long long int n, f; const int b = 2520; float m; cin >> n; m = n / b; f = m; cout << f; return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { int i = 4; int inp; set<int> s; while (i) { i--; cin >> inp; s.insert(inp); } cout << 4 - s.size(); }
0
#include <bits/stdc++.h> using namespace std; int main() { int a, b, s[102]; while (cin >> a >> b) { for (int i = 0; i < a; i++) cin >> s[i]; sort(s, s + a); cout << s[a - b] << endl; } return 0; }
0
#include <bits/stdc++.h> struct point { long double x, y, v; } p[2001], num[2001]; int a[2001], b[2001], c[2001], V[2001]; bool cmp(point a, point b) { return a.v < b.v; } bool same(int x, int y) { return 1ll * (a[x] * c[x]) * (a[y] * a[y] + b[y] * b[y]) == 1ll * (a[y] * c[y]) * (a[x] * a[x] + b[x] * b...
10
#include <bits/stdc++.h> using namespace std; int main() { long long a; cin >> a; while (a % 3 == 0) { a /= 3; } cout << a / 3 + 1; }
4
#include <bits/stdc++.h> using namespace std; void parseArray(long long* A, long long n) { for (long long K = 0; K < n; K++) { cin >> A[K]; } } long long modInverse(long long a, long long b) { return 1 < a ? b - modInverse(b % a, a) * b / a : 1; } long long gcd(long long a, long long b) { return b ? gcd(b, a ...
5
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; bool isprime(long long num) { for (long long i = 2; i * i <= num; ++i) { if (num % i == 0) return false; } return true; } long long gcd(long long a, long long b) { if (b == 0) return a; else return gcd(b, a % b); } long long lc...
1
#include <bits/stdc++.h> using namespace std; template <typename T> bool chkmax(T &x, T y) { return x < y ? x = y, true : false; } template <typename T> bool chkmin(T &x, T y) { return x > y ? x = y, true : false; } int readint() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (...
9
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; int total; long long sum[5005]; string s; int main() { cin >> s; long long temp = s[0] - '0', ans = 0; sum[total++] = temp; for (int i = 2; i < s.size(); i += 2) { if (s[i - 1] == '+') { sum[total++] = sum[total - 1] + s[i] ...
6
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; int id[2][maxn * 4], cnt, n, Q, st; vector<pair<int, int>> V[maxn * 4]; long long dis[maxn]; void Build(int rt, int l, int r, int val) { if (l == r) { id[val][rt] = l; return; } id[val][rt] = ++cnt; int mid = (l + r) >> 1; Build(...
7
#include <bits/stdc++.h> using namespace std; long long i, j, k; struct cmp { bool operator()(long long const& p1, long long const& p2) { return p1 > p2; } }; void Anon_mouS() { string s; cin >> s; map<long long, long long> m; long long n = s.length(); long long ans = 0; for (i = 0; i < n; i++) { m[s[...
3
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } bool cmp(pair<float, long long> p1, pair<float, long long> p2) { if (p1.first == p2.first) { return p1.second < p2.second; } return p1.first > p2.first; } int32_t main() { long long n; c...
2
#include <bits/stdc++.h> using namespace std; long long l, r, k, ans = 0x3f3f3f3f3f3f3f3fll; int Count(int x) { int re = 0; for (; x; x -= x & -x) ++re; return re; } int main() { long long i, j; cin >> l >> r >> k; if (r - l + 1 <= 4) { int _ans; for (i = 1; i < 1 << r - l + 1; i++) if (Count(...
7
#include <bits/stdc++.h> using namespace std; using ll = long long int; using dl = double; const int N = 2e5 + 10; ll aarray[200000 + 10]; ll magic[101][101]; vector<ll> primes; bool prime[1000001]; int main() { ios_base::sync_with_stdio(false); string str; ll i, j, n, m, k, t; char ch1, ch2; str = "v<^>v<^";...
0
#include <bits/stdc++.h> using namespace std; const int sl = 160000; int X[sl], P[sl]; int n, m, K; long long F[sl]; long long pw[sl][20]; long long bw[sl][20]; long long ew[sl][20]; long long tw[sl][20]; int main() { int a, b; long long tres = 0; scanf("%d%d%d", &n, &m, &K); for (int i = 1; i <= n; i++) scanf(...
7
#include <bits/stdc++.h> using namespace std; int t(int a, int b) { int s = 1; for (int i = 0; i < b; i++) { s *= a; } return s; } long long dp[1000000]; int main() { string s; cin >> s; string j; if (s.size() < 5) { cout << 0; return 0; } for (int i = 0; i < s.size() - 4; i++) { str...
2
#include<bits/stdc++.h> // #pragma optimize("-O3") // #pragma GCC optimize("Ofast") // #pragma GCC optimize("unroll-loops") // #pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,avx,mmx,tune=native") using namespace std; #define pb push_back #define mp make_pair #define ff first #define ss second #define INF 1e9 #defin...
7
#include <bits/stdc++.h> using namespace std; int n, m, h, a, b, T[100005], ID[100005], nrout[100005]; vector<int> v[100005], v2[100005]; bool uz[100005]; vector<vector<int> > ans; vector<int> H; void dfs(int nod) { uz[nod] = 1; for (auto it : v[nod]) { if (uz[it]) continue; dfs(it); } H.push_back(nod);...
5
#include <bits/stdc++.h> using namespace std; long long ans; int n, m, T; char a[1001], b[1001]; map<long long, bool> p; inline void init() { scanf("%s", a + 1); n = strlen(a + 1); m = 0; for (int i = 1; i <= n; i++) { while (m > 0 && b[m] == 'k' && a[i] == 'h') m--; if (a[i] == 'u') { b[++m] = 'o...
2
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; inline int addmod(int x) { return x >= mod ? x - mod : x; } inline int submod(int x) { return x < 0 ? x + mod : x; } int fpow(int x, long long y) { int ans = 1; while (y) { if (y & 1) ans = 1ll * ans * x % mod; x = 1ll * x * x % mod; ...
10
#include <bits/stdc++.h> using namespace std; const long long N = 3030; const long long inf = 1e12; long long a[N], b[N], c[N], ans[N][4], n; int main() { ios_base::sync_with_stdio(false); cin >> n; for (long long i = 0; i < (n); ++i) cin >> a[i + 1]; for (long long i = 0; i < (n); ++i) cin >> b[i + 1]; for (...
5
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; const double eps = 1e-8; const int maxn = 30000; int main() { int k; while (cin >> k) { if (k % 2) { cout << -1 << endl; continue; } for (int i = (1); i <= (k / 2); ++i) { if (i % 2 == 0) { for (int j = (...
4
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n; cin >> n; ; long long m; cin >> m; ; vector<string> v(n); for (long long i = 0; i < n; i++) cin >> v[i]; set<char> s; long long ans = 1; for (long long ...
3
#include <bits/stdc++.h> using namespace std; const int c = 100002; int n, rf[c], hol[c], cent, cnt; int si[c], db2[2 * c], maxi, pos, ans[c]; priority_queue<int, vector<int>, greater<int> > q; long long sum; vector<int> sz[c], s[c], csop[c]; bool v[c], v2[c], h[c]; void dfs(int a) { v[a] = true; rf[a] = 1; for (...
11
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j, k; cin >> n; int arr[n]; for (i = 0; i < n; i++) { cin >> arr[i]; } sort(arr, arr + n); reverse(arr, arr + n); if (1 & n) { cout << arr[((n + 1) / 2) - 1]; } else { cout << arr[n / 2]; } return 0; }
0
#include <bits/stdc++.h> using namespace std; struct qry { int o, l, r; } q[100100]; map<int, int> hook, person, mp; struct data { int sz, st, ed; }; bool operator<(data a, data b) { if (a.sz == b.sz) return a.ed > b.ed; return a.sz > b.sz; } set<data> S; data pack(int x, int y, int z) { data tmp; tmp.sz = ...
8
#include <bits/stdc++.h> int main() { int n, a, b; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d%d", &a, &b); if (a == 1 || b == 1 || (a == 2 && b == 2)) printf("YES\n"); else printf("NO\n"); } return 0; }
0
#include <bits/stdc++.h> using namespace std; const int INF = 0x7f7f7f7f; int main() { int n; while (~scanf("%d", &n)) { int t[4]; memset(t, 0, sizeof(t)); vector<int> v[5100]; memset(v, 0, sizeof(v)); for (int i = 1; i <= n; i++) { int x; cin >> x; t[x]++; v[x].push_back...
0
#include <bits/stdc++.h> using namespace std; const double pi = 3.1415926535897; long long n, m, k, ans; int f(long long v) { long long l = k - 1; long long r = n - k; long long sum = v; if (r > v - 1) { sum += (v - 1) * v / 2 + r - (v - 1); } else if (r <= v - 1) { sum += (v - 1 + v - r) * r / 2; }...
3
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e6 + 1; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long t; cin >> t; while (t--) { long long d, m; cin >> d >> m; long long mn = 1; for (; (1 << (mn - 1)) <= d; mn++) ; --mn; ...
4
#include <bits/stdc++.h> using namespace std; vector<long long int> sieve; vector<long long int>* Sieve(int N) { const long long int maxn = N; sieve.resize(maxn); for (long long int(i) = 0; (i) < (maxn); ++(i)) sieve[i] = 1; sieve[1] = 0; sieve[0] = 0; for (long long int(i) = 2; (i) <= (maxn); (i) += (1)) ...
1
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cerr.writ...
1
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void smin(T &a, U b) { if (a > b) a = b; } template <typename T, typename U> inline void smax(T &a, U b) { if (a < b) a = b; } template <typename T> inline void gn(T &first) { char c, sg = 0; while (c = getchar(), (c > '9' ||...
7
#include <bits/stdc++.h> using namespace std; const int N = 2e6 + 5, inf = 1e9 + 7; int n, k, i, j; int dp1[N], dp2[N], m; map<string, int> mp, done; bitset<41> A, mat[41], is; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); int i, j, a, s, cur, ans = 0, cnt = 0; string b; cin >> n >> m; while...
7
#include <bits/stdc++.h> using namespace std; int main() { int a, b, co = 0; cin >> a >> b; for (int i = 1; i * i <= b; i++) { if (b % i == 0 && b / i <= a && i <= a) { if (i == b / i) co--; co += 2; } } printf("%d\n", co); }
1
#include <bits/stdc++.h> using namespace std; int main() { int n, a; cin >> n; vector<pair<int, int> > v(n + 1); for (int i = 1; i < n + 1; i++) { cin >> a; v[i] = make_pair(a, i); } sort(v.begin() + 1, v.end()); for (int i = 1; i <= n / 2; i++) { cout << v[i].second << " " << v[n + 1 - i].sec...
0
#include <bits/stdc++.h> using namespace std; int main() { char a, b, c, d; cin >> a >> b >> c >> d; int ans = max(abs(a - c), abs(b - d)); cout << ans << endl; for (;;) { if (a == c and b == d) break; if (a > c) { cout << "L"; a--; } if (c > a) { cout << "R"; a++; ...
1
#include <bits/stdc++.h> using namespace std; template <typename T> void chkmax(T &x, T y) { x = x > y ? x : y; } template <typename T> void chkmin(T &x, T y) { x = x > y ? y : x; } const int INF = 2139062143; template <typename T> void read(T &x) { x = 0; bool f = 1; char ch; do { ch = getchar(); i...
10
#include <bits/stdc++.h> using namespace std; const long long A = 100000000000000LL, N = 1228228; long long a[N], l, r, c, k, i, j, n, m, o; int check(int c) { j = c, k = 1; for (i = 0; i < c; i++) { while (j < n && a[i] * 2 > a[j]) j++; if (j == n) k = 0; j++; } return k; } int main() { cin >> n;...
4
#include <bits/stdc++.h> using namespace std; template <class T> void splitstr(const string &s, vector<T> &out) { istringstream in(s); out.clear(); copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out)); } template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } static void redirec...
8
#include <bits/stdc++.h> using namespace std; map<string, int> m; void print(int num) { if (num == -1) puts("errtype"); else { printf("void"); while (num--) printf("*"); puts(""); } } int digicalize(string s) { int f, t, i; for (i = 0; s[i] == '&'; i++) ; f = i; for (i = s.size() - 1; ...
5
#include <bits/stdc++.h> const int dx8[] = {1, -1, 0, 0, 1, -1, 1, -1}; const int dy8[] = {0, 0, 1, -1, 1, -1, -1, 1}; const int dx4[] = {1, -1, 0, 0}; const int dy4[] = {0, 0, 1, -1}; using namespace std; void task() { long long a, b; cin >> a >> b; string k, s = "0"; cin >> k; s += k; int n = s.size(); ...
2
#include <bits/stdc++.h> using namespace std; const int MAXN = 300000; map<int, int> mapa; map<pair<int, int>, vector<int>> pos; vector<int> g[MAXN]; int ptr[MAXN]; int used[MAXN]; void euler(int v, vector<int> &res) { used[v] = true; for (; ptr[v] < (int)(g[v]).size();) { ++ptr[v]; int u = g[v][ptr[v] - 1]...
11
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 7; int n, q, tot, dist[maxn], siz[maxn]; vector<int> E[maxn]; map<int, int> Q; int dfs(int x) { dist[x] = tot; Q[tot] = x; tot++; int l = E[x].size() - 1; for (int i = 0; i <= l; i++) { int y = E[x][i]; siz[x] += dfs(y); } if (l ...
4
#include <bits/stdc++.h> using namespace std; double c[101010 * 5][6]; int a[101010], b[101010]; double dp[101010][101]; int main() { for (int i = 0; i < 101010 * 5; i++) { for (int j = 0; j < 6; j++) { if (i == j || j == 0) c[i][j] = 1; else c[i][j] = c[i - 1][j] + c[i - 1][j - 1]; ...
9
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int ar[n]; for (int i = 0; i < n; i++) cin >> ar[i]; int count = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (ar[j] > ar[i]) count++; } cout << count + 1 << endl; count = 0; } return 0...
0
#include <bits/stdc++.h> using namespace std; struct edge { int b, cap, id; edge() {} edge(int b, int cap, int id) : b(b), cap(cap), id(id) {} }; int n; pair<int, int> a[5005]; vector<edge> e[5005]; int cur[5005]; edge par[5005]; int pos[5005], ans[5005]; void dfs(int v) { for (int i = 0; i < e[v].size(); i++) ...
6
#include <bits/stdc++.h> using namespace std; long long mod = 10e9 + 7; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); long long test; cin >> test; while (test--) { long long n, second; cin >> n >> second; long long m = n / 2 + 1; cout << (long long)(floor(second / m)) << en...
0
#include <bits/stdc++.h> using namespace std; struct laptop { long a, b; }; bool compare(laptop const& i, laptop const& j) { return (i.a < j.a); } int main() { long n, i, j; laptop x[100000]; cin >> n; for (i = 0; i < n; i++) cin >> x[i].a >> x[i].b; sort(x, x + n, &compare); if (n == 1) { cout << "Po...
1
#include <bits/stdc++.h> using namespace std; int n, m; int mapp[405][405]; int vis[405]; int v[405]; struct node { int u; int c; node() {} node(int _u, int _c) : c(_c), u(_u) {} }; queue<node> q; int bfs(int t) { int cnt = 0; int pos; node no; no.u = 1; no.c = 0; while (!q.empty()) { q.pop(); ...
4
#include <bits/stdc++.h> using namespace std; string s; long long n; long long ans[2002]; void solve(long long x, long long y, long long st) { if (x >= y) return; long long yo; if (st == 0) yo = 100; else yo = -1; for (long long i = y; i >= x; i--) { if (st == 1) { yo = max(yo, (long long)(s...
3
#include <bits/stdc++.h> using namespace std; int main() { long long a, b; cin >> a >> b; int s; s = 0; while (b != 0) { s = s * 10 + b % 10; b = b / 10; } cout << s + a; }
3
#include <bits/stdc++.h> using namespace std; inline long long isqrt(long long k) { long long r = sqrt(k) + 1; while (r * r > k) r--; return r; } inline long long icbrt(long long k) { long long r = cbrt(k) + 1; while (r * r * r > k) r--; return r; } inline long long minize(long long& a, long long b) { ret...
5
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const int N = 1e7 + 4; int solve() { int n; scanf("%d", &n); int req = 0; int a[n + 1]; for (int i = 1; i < n + 1; i++) scanf("%d", &a[i]), req ^= a[i]; if (n % 2 == 0 and req != 0) { printf("NO\n"); return 0; } printf(...
7
#include <bits/stdc++.h> using namespace std; vector<int> v; int main() { int i, j, k, n, x; long long ans = 0; scanf("%d%d", &n, &x); v.clear(); for (i = 0; i < n; i++) { scanf("%d", &j); v.push_back(j); } sort(v.begin(), v.end()); int sz = v.size(); for (i = 0; i < sz; i++) { if (x <= 1)...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 1000; int a[maxn]; int main() { int n; while (~scanf("%d", &n)) { memset(a, 0, sizeof(a)); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); sort(a + 1, a + 1 + n); int ans = 0; for (int i = 1; i <= n; i++) { if (a[i] == -1) con...
2
#include <bits/stdc++.h> using namespace std; long long int get_need(long long int v) { long long int cur = 1; while ((1LL << cur) < v) cur++; return cur; } int main() { int n; cin >> n; map<long long int, int> mp; vector<long long int> needs(60); vector<long long int> store(60); for (int i = 0; i < n...
7
#include <bits/stdc++.h> using namespace std; inline long long getint() { long long summ = 0, f = 1; char ch; for (ch = getchar(); !isdigit(ch) && ch != '-'; ch = getchar()) ; if (ch == '-') f = -1, ch = getchar(); for (; isdigit(ch); ch = getchar()) summ = (summ << 3) + (summ << 1) + ch - 48; retur...
10
#include <bits/stdc++.h> using namespace std; long long a[300000], ind[300000]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, m; cin >> n >> m; long long a[n + 1][m + 1], ans[n + 1][m + 1]; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> a[i][j];...
4
#include <bits/stdc++.h> using namespace std; namespace io { char ibuf[(1 << 18)], *iS, *iT, obuf[(1 << 18)], *oS = obuf, *oT = oS + (1 << 18) - 1, c, qu[55]; int f, qr; inline void flush(void) { fwrite(obuf, 1, oS - obuf, stdout); oS = obuf; return; } inline char getch(void) { return (iS == iT ? (iT = (iS ...
6
#include <bits/stdc++.h> using namespace std; struct bian { int next, point, w; } b[210000]; int bo[110000], p[110000], n, len, m, u, v, del, pdu, pdv, pd[110000], an0, an1, tot, dp[110000][2][2]; const int mo = 1e9 + 7; void ade(int k1, int k2, int k3) { b[++len] = (bian){p[k1], k2, k3}; p[k1] = len; } void ...
10
#include <bits/stdc++.h> using namespace std; int main() { int x = 0, i; string s; int n; cin >> n; while (n--) { cin >> s; for (i = 0; i < s.length(); i++) { if (s[i] == '+') { x = x + 1; break; } else if (s[i] == '-') { x = x - 1; break; } } } ...
0
#include <bits/stdc++.h> using namespace std; int n, ans, x, y; string s; int main() { cin >> n >> s; for (int i = 0; i < n; ++i) { if (s[i] == 'L') x--; if (s[i] == 'R') x++; if (s[i] == 'U') y++; if (s[i] == 'D') y--; } ans = n - abs(x) - abs(y); cout << ans << '\n'; }
1
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; struct Linear_Basis { long long b[63], nb[63], tot; void init() { tot = 0; memset(b, 0, sizeof(b)); memset(nb, 0, sizeof(nb)); } bool Insert(long long x) { for (int i = 62; i >= 0; i--) { if (x & (1LL << i)) { ...
0
#include <bits/stdc++.h> using namespace std; const int N = (1 << 22) + 5; int n, m, ara[N], has[N], vis[N], M; bool Check(int num, int pos) { return num & (1 << pos); } int Set(int num, int pos) { return num | (1 << pos); } void dfs(int s) { if (vis[s]) return; vis[s] = 1; if (has[s]) dfs(M - s); for (int i = ...
8
#include <bits/stdc++.h> using namespace std; int N, M, K; long long a[100005], c[100005]; pair<long long, long long> inp[100005]; int main() { scanf("%d %d", &N, &M); for (int i = 1; i <= N; i++) { scanf("%lld", a + i); } for (int i = 1; i <= N; i++) { scanf("%lld", c + i); inp[i] = {c[i], i}; } ...
3
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } sort(arr, arr + n); long long sol[n]; int left = 0, right = n / 2; int k = 0; while (left < n / 2) { sol[k++] = arr[right]; sol[k++] = arr[left]; ...
1
#include <bits/stdc++.h> using namespace std; static int aQWEs = []() -> int { ios::sync_with_stdio(false); cin.tie(NULL); return 0; }(); long long int power(long long int a, long long int p, long long int m = 1000000007) { a %= m; long long int val = 1; while (p > 0) { if (p & 1) { ...
5
#include <bits/stdc++.h> using namespace std; const int maxint = -1u >> 1; template <class T> bool get_max(T& a, const T& b) { return b > a ? a = b, 1 : 0; } template <class T> bool get_min(T& a, const T& b) { return b < a ? a = b, 1 : 0; } int main() { int a, b, n, i, c; cin >> a >> b >> n; i = 0; while (i...
4
#include <bits/stdc++.h> using namespace std; const int MOD = (int)1e9 + 9; unordered_map<int, unordered_map<int, int>> segtree; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; int q; cin >> q; int a, t, x; int lf, rf, ans; for (int i = 0; i < q; i++) { cin >> a >> t >> x; ...
6
#include <bits/stdc++.h> using namespace std; int main() { double a, b, c, d; cin >> a >> b >> c >> d; printf("%.10lf", (a * d) / (b * d - (b - a) * (d - c))); }
2
#include <bits/stdc++.h> const int SMALL_LOOKUP_TABLE = 1000; const int BIG_LOOKUP_TABLE = 1000000; const int BIG_INT = (1 << 31) - 1; const int SMALL_INT = BIG_INT + 1; const long long BIG_LL = ((long long)1 << (long long)63) - 1; const long long SMALL_LL = BIG_LL + 1; using namespace std; string replace(string w, str...
2
#include <bits/stdc++.h> using namespace std; bool sortbysec(pair<int64_t, int64_t> a, pair<int64_t, int64_t> b) { return (a.second < b.second); } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; int64_t n, a = 0, b = 0; string s; cin >> n >> s; if (n % 2) return cout << "...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, m; scanf("%d%d", &n, &m); int x, y; for (int i = 0; i < m; i++) { scanf("%d", &x, &y); } for (int i = 0; i < n; i++) { printf("%d", i % 2); } cout << endl; return 0; }
2
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } int ans = 100000; for (int i = 0; i < n - 1; i++) { ans = min(ans, max(a[i], a[i + 1])); } int z = min(a[0], a[n - 1]); cout << min(ans, z); }
1
#include <bits/stdc++.h> using namespace std; const int MAXPRIME = 1000000; const int MAXPRIMECNT = 78498; bool tagPrime[MAXPRIME]; int primeCnt, prime[MAXPRIMECNT]; void initPrime() { tagPrime[0] = tagPrime[1] = true; for (int i = 2; i < MAXPRIME; i++) { if (tagPrime[i]) continue; prime[primeCnt++] = i; ...
9
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; const long double EPS = 1e-11; const long long INFL = 1e16; const int INF = 2e9 + 7; mt19937 rnd((unsigned)chrono::steady_clock::now().time_since_epoch().count()); int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout....
8
#include <bits/stdc++.h> using namespace std; long long int power(long long int x, long long int y) { if (y == 0) return 1; else if (y % 2 == 0) return power(x, y / 2) * power(x, y / 2); else return x * power(x, y / 2) * power(x, y / 2); } long long int binsearch(long long int a[], long long int n, lo...
3
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; if (k > n / 2) { cout << n * (n - 1) / 2; } else { long long a = n * (n - 1) / 2; long long b = (n / 2 - k) * 2 + (n % 2); cout << a - (b * (b - 1) / 2); } return 0; }
2
#include <bits/stdc++.h> using namespace std; int n, m, l, i, j, mas[100001] = {0}, k, d; char ch_1, ch_2, ch_3; int main() { cin >> n >> m; while (true) for (i = 1; i <= n; i++) { if (m < i) { cout << m; return 0; goto iq; } m = m - i; } iq: return 0; }
0
#include <bits/stdc++.h> using namespace std; struct node { long long int u, v, w; node() {} node(long long int _u, long long int _v, long long int _w) { u = _u; v = _v; w = _w; } bool operator<(const node &a) const { return w < a.w; } }; vector<node> e; vector<long long int> station; vector<pair<...
5
#include <bits/stdc++.h> using namespace std; int main() { int t, n, m; scanf("%d", &t); while (t--) { scanf("%d%d", &n, &m); int sum = 0; for (int i = 0; i < n; ++i) { int x; scanf("%d", &x); sum += x; } printf("%d\n", min(sum, m)); } return 0; }
0
#include <bits/stdc++.h> using namespace std; int max(int a, int b) { return a > b ? a : b; } int t, n, k, x[200009], head[200009], tail[200009], head_max[200009]; int main() { scanf("%d", &t); while (t--) { scanf("%d %d", &n, &k); for (int i = 1; i <= n; ++i) scanf("%d", &x[i]); int lowest_y = 1e9 + 1,...
5
#include <bits/stdc++.h> using namespace std; map<long long, vector<long long>> M; bool res[100010]; int main() { long long n; long long k; cin >> n >> k; long long S = 0; for (long long i = 1; i <= n; i++) { long long a; cin >> a; M[a].push_back(i); S += a; } if (S < k) { cout << "-1"...
5
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long MX = 2e5 + 5; inline void norm(long long &a) { a %= mod; (a < 0) && (a += mod); } inline long long modAdd(long long a, long long b) { a %= mod, b %= mod; norm(a), norm(b); return (a + b) % mod; } inline long long modS...
1
#include <bits/stdc++.h> using namespace std; int n, b, d, x, sum, ans; int main() { cin >> n >> b >> d; for (int i = 1; i <= n; i++) { cin >> x; if (x > b) continue; if (sum + x > d) { ans++; sum = 0; } else sum += x; } cout << ans; }
0
#include <bits/stdc++.h> using namespace std; vector<long long int> G[100001]; vector<long long int> changed; long long int visited[100001], level[100001], initial[100001], goal[100001], n, a, b, answer; void init() { ios_base::sync_with_stdio(false); cin.tie(NULL); memset(level, -1, sizeof(level)); memset(...
2
#include <bits/stdc++.h> using namespace std; int a[1001000]; bool vis[1001000], judge[1001000]; int main() { int p, k; cin >> p >> k; long long ans = 1; for (int i = 0; i < p - 1; i++) a[i] = (long long)k * i % p, ans = (ans * p) % 1000000007; a[p - 1] = (long long)(p - 1) * k % p; if (!k) { cout <...
5
#include <bits/stdc++.h> using namespace std; const int MAX = 112345; int n, m, a, b, vis[MAX], dis[MAX]; vector<int> adj[MAX]; queue<int> q; void bfs(int v) { memset(dis, 0, sizeof(dis)); memset(vis, 0, sizeof(dis)); q.push(v); vis[v] = 1; while (!q.empty()) { int top = q.front(); q.pop(); int ta...
3
#include <bits/stdc++.h> using namespace std; int main() { int t; long long n, x, y, d; cin >> t; for (int i = 0; i < t; i++) { cin >> n >> x >> y >> d; if (abs(x - y) % d == 0) { cout << abs(x - y) / d << endl; } else if ((y - 1) % d != 0 && (n - y) % d != 0) { cout << "-1" << endl; ...
2
#include <bits/stdc++.h> using namespace std; const unsigned long long INF = -1; const int M = 1e5 + 5; long long now[M]; int main() { int n, x; scanf("%d%d", &n, &x); long long minn = INF >> 1, loc, dis = INF >> 1; x--; for (int i = 0; i < n; i++) { scanf("%I64d", &now[i]); long long tmp = x - i; ...
4