solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d ", &n); char inp[10000][6]; bool flag = false; for (int i = 0; i < n; i++) scanf("%s", inp[i]); for (int i = 0; i < n; i++) { for (int j = 0; j < 4; j++) { if (inp[i][j] == 'O' && inp[i][j + 1] == 'O' && !flag) { f...
1
#include<stdio.h> #include<vector> #include<algorithm> using namespace std; typedef pair<int, int>pii; vector<pii>pat[100000]; bool flag[100000]; int d[100000]; void dfs(int node, int t) { if (flag[node]) { if (d[node] != t) { printf("No\n"); exit(0); } return; } flag[node] = true; d[node] = t; for ...
0
#include "bits/stdc++.h" using namespace std; #define int long long #define endl '\n' int mod=1e9+7; int mod2=998244353; const int INF=1e9; signed main(){ int h,w,a,b; cin>>h>>w>>a>>b; cout<<h*w-(h/a*a)*(w/b*b)<<endl; } // `.`..`(WNNNNNNMNWWWH9rttwgHM8OtttwwVtttrrtrttrw0rtrtwrrrtrZUAOOrrrXWppHMHyZHpWHMHMkWWVHMN...
0
#include<iostream> #include<cstdio> #include<algorithm> using namespace std; #define MAXN 200000 #define MOD 1000000007 int n,ans,tp; char s[MAXN+1]; char stk[MAXN+1]; int main() { scanf("%d",&n); scanf("%s",s+1); ans=1; if(s[1]=='W'){ printf("0\n");return 0; } stk[++tp]='B';stk[0]='W'; for(int i=2;i<=2*n;i++)...
0
#include <iostream> using namespace std; #define MAX 500000 bool prime_table[MAX]; int main(){ int n, i, j, ans; // make table for (i = 0; i < MAX; i++) { if(i==0||i==1){ prime_table[i] = false; }else{ prime_table[i] = true; } } // find prime for (i = 2; i < MAX; i++) { if(prime_table[i]){ fo...
0
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main(){ ll N,ans=0,mina=1000000,a; cin >> N; for(int i=0;i<N;i++){ cin >> a; if(a<=mina){ ans++; } mina = min(mina,a); } cout << ans << endl; }
0
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 6; char ori[maxn]; bool flag; int main() { scanf("%s", ori + 1); int len = strlen(ori + 1); int l = 1, r = len; int ppos = 0; if (len == 1) { printf("%c\n", ori[l]); return 0; } while (ori[l] == '0') l++; if (ori[r] == '.') r--...
3
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <vector> #include <string> #include <map> #include <set> #include <cassert> #include <queue> using namespace std; #define rep(i,a,n) for (int i=a;i<n;i++) #define per(i,a,n) for (int i=n-1;i>=a;i--) #define pb push_...
0
#include <iostream> using namespace std; int main(){ string s; cin >> s; cout << (s += (s.back() == 's' ? "es" : "s")) << endl; }
0
#include <bits/stdc++.h> int main() { int n, m, i; scanf("%d%d", &n, &m); if (n / m == 0) { for (i = 0; i < m; i++) printf("%d ", n / m); } else { for (i = 0; i < m; i++) { if (i < m - (n % m)) printf("%d ", n / m); else printf("%d ", (n / m) + 1); } } }
1
#include <bits/stdc++.h> using namespace std; int dx[] = {0, 0, 1, -1, 1, 1, -1, -1}; int dy[] = {1, -1, 0, 0, 1, -1, 1, -1}; int a[1000][1000]; int main() { int n; cin >> n; int pre = 0, g; for (int i = 2;; i++) { int x = i + ((i - 1) * i / 2); if (x > n) break; pre = i + 1; g = x; } cout <...
3
#include <bits/stdc++.h> #define int long long using namespace std; const int MOD = 1000000007; signed main() { string S; cin >> S; int cnt = 0; int ans = 0; for( int i = S.size()-1; i >= 0; i-- ){ if( i > 0 && S.at(i) == 'C' && S.at(i-1) == 'B' ){ cnt++; i--; }else if( S.at(i) == 'A' ) ...
0
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; int n; int fn[200005] = {}; int a, b, c; vector<string> st(t); for (int j = 0; j < t; j++) { cin >> n; int rn[n]; for (int i = 0; i < n; i++) { cin >> rn[i]; fn[rn[i]] = i + 1; } string s = "1"; ...
2
#include <bits/stdc++.h> using namespace std; const int N = (int)2e6 + 10; int n, t[N], v[N], root[N]; vector<int> f[N]; int get(int u, int x, int y) { if (t[u] == 1) return (x & y); if (t[u] == 2) return (x | y); return (x ^ y); } int Find(int u) { if (root[u] != u) root[u] = Find(root[u]); return root[u]; }...
4
#include <bits/stdc++.h> using namespace std; inline long long max_(long long a, long long b) { return (a > b) ? a : b; } inline long long min_(long long a, long long b) { return (a < b) ? a : b; } string dict[35]; long long n; string generate(string s) { long long i, n = s.length(); for (i = n - 1; i >= 0 && s[i] ...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 1e3 + 5; inline int _(int x) { return x + maxn; } int n, m; char s[maxn]; char ans[maxn]; char f[maxn][(maxn << 1) + 5]; bool dp[maxn][(maxn << 1) + 5]; int main() { scanf("%d%d", &n, &m); scanf("%s", s); dp[0][_(0)] = 1; for (int i = (0); i < (n); ...
5
#include <bits/stdc++.h> using namespace std; char s[100000 + 10], t[100000 + 10]; int main() { int n; cin >> n >> s; int k = 0; int l = 9; for (int i = 0; i < 10; i++) t[i] = '0'; for (int i = 0; i < n; i++) { if (s[i] == '0') t[0] = '0'; else if (s[i] == '1') t[1] = '0'; else if (s...
1
#include <bits/stdc++.h> using namespace std; const int inf = 10000000; int main() { int n, m; scanf("%d%d", &n, &m); if (m == 3) { if (n == 4) { printf("0 -2\n"); printf("0 2\n"); printf("2 0\n"); printf("1 0\n"); } else if (n == 3) { printf("0 -1\n"); printf("0 1\n");...
4
#include <bits/stdc++.h> using namespace std; inline int read() { int res = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') res = res * 10 + ch - 48, ch = getchar(); return res * f; } const int maxn = 200005; int a...
2
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<n;i++) typedef long long ll; int main(){ int n; cin>>n; vector<int> A(n); rep(i,n) cin>>A[i]; sort(A.begin(),A.end()); if(A[n-1]-A[0]>1){ cout<<"No"; } if(A[n-1]-A[0]==1){ int a=0; rep(i,n...
0
#include <bits/stdc++.h> using namespace std; const int MX = 200005, BITS = 9, S = 1 << BITS, MASK = S - 1, CNT = (MX + S - 1) / S; struct Upd { int pos, val, t; Upd(int pos, int val, int t) : pos(pos), val(val), t(t) {} Upd() {} }; int n, m, q; int a[MX], ord[MX]; int val[MX], whole[CNT], mx[CNT][CNT],...
5
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > vec[2501]; bool visited[50][50]; int subgroup[50][50]; int a[50][50]; int n; void expand(int i, int j, int subgroup_num) { if (i < 0 || j < 0 || i >= n || j >= n) { return; } if (visited[i][j]) { return; } if (a[i][j] == 0) { re...
3
#include <bits/stdc++.h> using namespace std; const int M = 1000 + 10; int main() { int pl, pr, vl, vr, k; cin >> pl >> pr >> vl >> vr >> k; vector<int> candidate; for (int d = 1; d <= 9; d++) { for (int i = 0; i < (1 << d); i++) { int num = 0; for (int r = 0; r < d; r++) { if ((i >> r) ...
4
#include <bits/stdc++.h> using namespace std; const int mx = 1e2 + 9; const int inf = 1e18 + 9; int A[mx][mx], B[mx][mx], freq[mx], fr[mx]; vector<pair<int, int> > vp1, vp2; vector<int> v1, v2; bool sign[mx], sign2[mx]; map<int, int> mp; string s1, s2, s3; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL...
2
#include <bits/stdc++.h> using namespace std; int arr[1000010]; int primes[1000010], minFac[1000010], primesPt; void initPrimes() { memset(minFac, 0, sizeof(minFac)); primesPt = 0; for (int i = 2; i < 1000010; i++) { if (minFac[i] == 0) { minFac[i] = i, primes[primesPt++] = i; } for (int j = 0; ...
5
#include <bits/stdc++.h> using namespace std; const int MAXN = 111111, MAXV = 11111; int LNum[30] = {4, 7, 44, 47, 74, 77, 444, 447, 474, 477, 744, 747, 774, 777, 4444, 4447, 4474, 4477, 4744, 4747, 4774, 4777, 7444, 7447, 7474, 7477, 7744, 7747, 7774, 7777}; int N, ...
5
#include <bits/stdc++.h> using namespace std; const int N = 1005; int dx[] = {0, 1, 0, -1}; int dy[] = {1, 0, -1, 0}; void solve() { long long l, r; cin >> l >> r; cout << "YES" << endl; while (l < r) { cout << l << " " << l + 1 << endl; l += 2; } } int main() { solve(); return 0; }
2
#include <bits/stdc++.h> using namespace std; int vis[30]; bool judge(string s1, string s2) { int i = 0, j = 0; int len1 = s1.size(); int len2 = s2.size(); while (i < len1 || j < len2) { if (i == len1) { if (s2[j] == '*' && j + 1 == len2) { return true; } else return false; }...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 211111; long long n, k, a[maxn], sum[maxn], to[maxn]; int main() { scanf("%lld%lld", &n, &k); bool is1 = 1; for (int i = 1; i <= n; i++) { scanf("%lld", &a[i]); if (a[i] != 1) is1 = 0; sum[i] = sum[i - 1] + a[i]; } int r = 0; for (in...
4
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int a[N]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", &a[i]); sort(a, a + n); n = unique(a, a + n) - a; bool no = true; for (int i = 0; i < n - 1; i++) if (a[i] > a[i + 1] / 2) { no = false; ...
2
#include <bits/stdc++.h> int x[500005], v[500005], a[500005]; double h = 0, t = 1e21, m; int N; int main() { scanf("%d", &N); for (int i = 1; i <= N; ++i) { scanf("%d%d", &x[i], &v[i]); } int mx = x[N] - x[1] + 10; t = x[N] - x[1] + 10; while ((t - h) * 2 / (h + t) >= 1e-11) { m = (h + t) / 2; d...
5
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> std::istream &operator>>(std::istream &i, pair<T, U> &p) { i >> p.first >> p.second; return i; } template <typename T> std::istream &operator>>(std::istream &i, vector<T> &t) { for (auto &v : t) { i >> v; } return i; } templat...
4
#include <bits/stdc++.h> using namespace std; int n, m[111], a[111][111], d[111][111]; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> m[i]; for (int j = 1; j <= m[i]; j++) { cin >> a[i][j]; } } int s; for (int i = 1; i <= n; i++) { int cur = 0; for (int k = 1; k <= n; k...
2
#include <bits/stdc++.h> int mas[5000]; int ind; int n; int n1; int M; int T; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &mas[i]); } n1 = 0; M = 0; T = 0; for (int i = 0; i < n; i++) { M = 0; T = 0; for (int j = i; j < n; j++) { M += mas[j]; T++; ...
2
#include <bits/stdc++.h> const int Inf = 1e9; long long LINF = (long long)4e18; const long long mod = 1e9 + 7; using namespace std; int main() { ios::sync_with_stdio(false); long long p, k; cin >> p >> k; vector<long long> ans; long long q = p; int cnt = 0; for (int(i) = 0; (i) < 1000000; (i)++) { cnt...
4
#include <bits/stdc++.h> namespace Task { const int MAXN = 100000; #define long long long std::multiset<long> setL, setR; int a[MAXN + 1], b[MAXN + 1]; long f[MAXN + 1]; inline void solve() { std::ios::sync_with_stdio(false), std::cin.tie(NULL), std::cout.tie(NULL); register int n; std::cin >> n; fo...
0
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; template <class T> using vec = vector<T>; template <class T> using vvec = vector<vec<T>>; using tp = tuple<ll, ll, ll>; constexpr long long INF = 1LL << 60; constexpr int INF_INT = 1 << 25; constexpr long long MOD = (ll)...
5
#include <bits/stdc++.h> int exp(int x, int y, int p) { int res = 1; while (y) { if (y % 2) res = (res * x % p) % p; x = (x * x) % p; y /= 2; } return res; } int expo(int x, int y) { int res = 1; while (y) { if (y % 2) res = (res * x % ((int)1e9 + 7)) % ((int)1e9 + 7); x = (x * x) % ((in...
2
#include <bits/stdc++.h> using namespace std; class Solution { public: int solve(int n, int r, vector<int>& A, vector<int>& D) { vector<pair<int, int>> POS; vector<pair<int, int>> NEG; for (int i = 0; i < n; ++i) { if (D[i] >= 0) { POS.emplace_back(A[i], D[i]); } else { NEG.em...
6
#include <bits/stdc++.h> using namespace std; vector<pair<long long, int> > H[1000007]; long long n, val[1000005], ans, cnt[1000005]; int S[1000005]; int m, up[1000005], p[1000005], len, b[1000005], mp[1000005]; void prepare() { int i, j; b[1] = 1; for (i = 2; i < 1000005; i++) { if (!b[i]) p[++len] = i; ...
6
#include<cstdio> int main(){char s[10];int i;scanf("%d %s",&i,s);printf("%s",(i<3200)?"red":s);}
0
#include <bits/stdc++.h> using namespace std; int main() { int n, i = 0; cin >> n; while (pow(2, i) <= n) { if (pow(2, i) == n) { cout << "YES"; exit(0); } i++; } cout << "NO"; return 0; }
1
#include <bits/stdc++.h> using namespace std; long long solve(int spt, long long ans, long long e) { if (ans == 0) return 0ll; long long ret; if (spt == 0) { long long v = (1ll << (ans - 1)); if (e <= v) ret = solve(!spt, ans - 1, e) + 1; else ret = solve(spt, ans - 1, e - v) + (1ll << ans...
3
#include <bits/stdc++.h> using namespace std; const int maxN = 1e5 + 5; set<int> org; set<int> star; int pack[maxN]; int N; string s; int val = 0; int cnt = 0; bool works(int t) { star = org; cnt = 0; while (!star.empty()) { ++cnt; if (cnt > val) return false; int l = min(pack[cnt], *star.begin()); ...
5
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (b == 0 || a == 0) return a + b; return gcd(b, a % b); } const int inf = int(1e9); const int mod = inf + 7; void solve() { int n; cin >> n; cout << n / 2 * 3; } int main() { int t = 1; while (t--) solve(); return 0; }
1
#include <bits/stdc++.h> using namespace std; struct teams { string name; int points, score, goals; }; int n; vector<string> tname; vector<teams> t; bool cmp(teams x, teams y) { return x.points > y.points || (x.points == y.points && x.score > y.score) || (x.points == y.points && x.score == y.score && x.g...
1
#include <bits/stdc++.h> using namespace std; const int N = 1e5; int n; struct node { int op; long long l; long long r; } q[N + 5]; int cnt; long long Hash[3 * N + 5]; int len; struct T { int sum; int lazy; } tree[12 * N + 5]; void pushup(int k) { tree[k].sum = tree[k << 1].sum + tree[k << 1 | 1].sum; } void ...
6
#include<iostream> #include<algorithm> #include<set> using lint=long long; using namespace std; int main() { lint N,K; pair<lint,lint> dt[100010]={}; lint fdsum[100010]={}; lint sdsum[100010]={}; cin >> N >> K; for(lint i=0;i<N;i++) cin >> dt[i].second >> dt[i].first; sort(dt,dt+N,greater<pair<lint,lint>>...
0
#include <bits/stdc++.h> using namespace std; long long int b, q, l; int m; long long int a[100001]; int p, n; int c; long long int abso(long long int x) { if (x >= 0) return x; return -x; } int main() { c = 0; scanf("%lld %lld %lld %d", &b, &q, &l, &m); for (int i = 0; i < m; i++) scanf("%lld", &a[i]); n =...
2
#include <bits/stdc++.h> using namespace std; struct station { long long x, price, next_min; station() {} station(long long x_, long long price_) { x = x_, price = price_; } bool operator<(const station &st) const { return x < st.x; } }; long long d, n, m, cur, ans; vector<station> stations; stack<station> curr...
3
#include <bits/stdc++.h> using namespace std; inline void smin(long long &x, long long y) { x = min(x, y); } inline void smax(long long &x, long long y) { x = max(x, y); } const long long N = 45 + 10; long long n, k, m, t[N], s = 0; long long ANS(long long x, long long y) { long long res = 0; for (long long i = 1; ...
2
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9; const long long MAXN = 5 * 1e5; const long long K = 2000; void bye() { cout << '\n'; exit(0); } struct Query { int l, r, id; }; bool operator<(Query a, Query b) { return a.r < b.r; } signed main() { ios::sync_with_stdio(false); cin.tie(N...
4
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k; cin >> n >> k; cout << n + k - n % k; return 0; }
1
#include <bits/stdc++.h> using namespace std; int m, n; vector<int> p; const int MAX = 1000000000; int main() { ios::sync_with_stdio(false); cin >> m >> n; p.resize(n); for (int i = 0; i < n; ++i) { cout << i + 1 << endl; int res; cin >> res; if (!res || res == -2) return 0; p[i] = res; } ...
2
#include <bits/stdc++.h> using namespace std; int a[110]; int main() { int n, m, l, r, i, j; int k = 0; while (~scanf("%d %d", &n, &m)) { memset(a, 0, sizeof(a)); for (i = 1; i <= m; i++) a[i] = i; for (i = 1; i <= n; i++) { scanf("%d %d", &l, &r); for (j = l; j <= r; j++) a[j] = 0; } ...
1
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long INFF = 0x3f3f3f3f3f3f3f3f; const double pi = acos(-1.0); const double eps = 1e-9; const long long mod = 1e9 + 7; int read() { int x = 0, f = 1; char ch = getchar(); while (ch<'0' | ch> '9') { if (ch == '-') f = -1; c...
6
// E. #include <iostream> #include <sstream> #include <algorithm> #include <vector> using namespace std; typedef long long LL; const LL INF = 1LL << 60; struct Edge { int from; int to; int cost; }; int main(int argc, char* argv[]) { int n, m, p; cin >> n >> m >> p; vector<Edge> edges; for (int i = 0; i < m...
0
#include<iostream> using namespace std; int main() { int a, b; cin >> a>> b; cout << a%b << '\n'; }
0
#include <bits/stdc++.h> using namespace std; int main() { cin.sync_with_stdio(false); int n; cin >> n; vector<int> A(n); for (auto i = (0); i < (n); i++) cin >> A[i]; set<long long> PREFIX; long long cur_sum = 0; int ans = 0; for (auto i = (0); i < (n); i++) { cur_sum += A[i]; if (PREFIX.find...
4
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long int x, y; long long int minx = 1e15, miny = 1e15, maxx = -1e15, maxy = -1e15; for (int i = 0; i < n; i++) { cin >> x >> y; minx = min(minx, x); maxx = max(maxx, x); miny = min(miny, y); maxy = max(maxy, y...
2
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; void ingraph(vector<long long> graph[], long long m) { long long x, y; for (long long i = 0; i < m; i++) { cin >> x >> y; x--, y--; graph[x].push_back(y); graph[y].push_back(x); } } long long gcd(long long a, long long ...
1
#include <bits/stdc++.h> using namespace std; const int INF = 2000000000; int n; int c[100100]; int s[100100]; bool f[100100]; int ff[100100]; int sum(int l, int r) { if (l == 0) return s[r]; return s[r] - s[l - 1]; } int main() { ios_base::sync_with_stdio(0); cin >> n; for (int i = 0; i < n; i++) { cin >...
5
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int t; t = 1; while (t--) { int n; cin >> n; string ans1 = "-1"; int ans2 = INT_MIN; unordered_map<string, int> mp; vector<pair<string, int>> vec(n); for (int i = 0...
1
#include <bits/stdc++.h> using namespace std; const int N(20); int n, m, i, j, k, t, x, y, ans1, ans2; int p[N]; int g[N][N]; string s[N]; int get() { string str; cin >> str; for (i = 0; i != n; ++i) if (s[i] == str) return i; } bool check() { for (j = t = 0; j != n; ++j) if (i & (1 << j)) p[t++] = j; ...
2
#include <bits/stdc++.h> using namespace std; bool g[1000][1000]; vector<int> extract_cycle(vector<int>& path) { if (path.size() <= 1) { return vector<int>(); } int v = path[path.size() - 1]; for (int i = path.size() - 2; i >= 0; --i) { if (g[v][path[i]]) { vector<int> cycle(path.size() - i); copy(path...
0
#include <bits/stdc++.h> using namespace std; const int N = 300006; const long long mod = 998244353; vector<int> G[N]; int a[N]; int par[N]; int d[N]; void no() { puts("0"); exit(0); } void dfs(int now, int ppar, int cur_depth) { par[now] = ppar; d[now] = cur_depth; for (int i : G[now]) { if (i == ppar) c...
6
#include <bits/stdc++.h> using namespace std; int main(){ long long int q,h,s,d; cin >> q >> h >> s >> d; long long n; cin >> n; long long qq = min(q*8, min(h*4, min(s*2,d))); cout << (n/2) * qq + (n%2)*(min(4*q, min(2*h,s))) << endl; }
0
#include <bits/stdc++.h> using namespace std; long long dp[205][205][205]; int main() { long long n, k, i, j, l, mx = 0, one, two; string s, w; cin >> n >> k; cin >> s; cin >> w; s = "$" + s; n++; for (i = 0; i < 205; i++) { for (j = 0; j < 205; j++) { for (l = 0; l < 205; l++) { dp[i]...
6
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (int)(n); i++) int main(){ map<string, ll> mp; ll q, c, x; string s; cin >> q; rep(i, q){ cin >> c >> s; auto t = mp.find(s); switch(c){ case 0: ...
0
#include<iostream> #include<cstdio> #include<algorithm> #include<vector> #include<queue> #include<stack> using namespace std; struct data{ int l,r; data():l(0),r(0){} data(int x,int y):l(x),r(y){} friend bool operator<(const data &dt1,const data &dt2){if(dt1.l==dt2.l)return dt1.r>dt2.r;return dt1.l<dt2.l;} }; ve...
0
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; const int N = 4005; template <class T> inline bool rd(T &ret) { char c; int sgn; if (c = getchar(), c == EOF) return 0; while (c != '-' && (c < '0' || c > '9')) c = getchar(); sgn = (c == '-') ? -1 : 1; ret =...
4
#include<bits/stdc++.h> #define pii pair<int,int> #define fi first #define sc second #define pb push_back #define ll long long #define trav(v,x) for(auto v:x) #define all(x) (x).begin(), (x).end() #define VI vector<int> #define VLL vector<ll> using namespace std; const int N = 1e6 + 100; const ll mod = 1e9 + 7; signed...
3
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, k, i, j, x, y; string s, p, q, l; cin >> n; for (long long ii = 0; ii < n; ii++) { cin >> s >> p; x = 0; for (x = 0; x < p.size(); x++) if (p[p.size() - 1 - x] == '1') break; for (i = x, x = 0; i < s.size(); i++, x+...
1
#include <bits/stdc++.h> using namespace std; vector<int> sieve(int n) { vector<int> p(n); for(int i=2; i<n; i++) p[i]=i; for(int i=2; i*i<n; i++) { if(p[i]) { for(int j=i*i; j<n; j+=i) p[j]=0; } } p.erase(remove(p.begin(),p.end(),0),p.end()); return p; } int main() { vector<int> p=sieve(1...
0
#include <bits/stdc++.h> using namespace std; template <typename T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf("%d", &x); } void _R(long long &x) { scanf("%" PRId64, &x); } void _R(double &x) { scanf("%lf", &x); } void _R(char &x) { scanf(" %c", &x); } void _R(char *x) { scanf("%s", x); } void R() {} templat...
4
//?????????????????? //0?????§???????????´???, 1?????§???????????´???, ?????¨??????????????????????????¨?§£????????? #include <iostream> #include <vector> using namespace std; int n, m, a, b, c; vector<int> et[50]; bool dp[50][50][101]; //dp[i][k][j] = ??????a????????????k???????????????j?????§?§??????§???????????? i...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); int n, m, q; cin >> n >> m >> q; vector<vector<int> > moves(q, vector<int>(4)); for (int i = 0; i < q; ++i) { cin >> moves[i][0]; cin >> moves[i][1]; moves[i][1]--; if (moves[i][0] == 3) { cin >> mov...
3
#include <bits/stdc++.h> using namespace std; int i, m, x = 0, n, a[1000], j; int main() { cin >> n; for (i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < n; i++) { m = 1; for (j = i - 1; j >= 0; j--) if (a[j] <= a[j + 1]) ++m; else break; for (j = i + 1; j < n; j++) i...
2
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i)) #define all(x) (x).begin(),(x).end() #define pb push_back #define fi first #define se second #define dbg(x) cout<<#x" = "<<((x))<<endl template<class T,class U> ostream& operator<<(ostream& o, const pa...
0
#include <bits/stdc++.h> #include <algorithm> using namespace std; int main(void){ string s,ts; int a=0,u=0; int n; int vailk= 0; vector<string>kc,codes; while(true) { cin >> n; if(n==0)break; kc=vector<string>(0); for (int i = 0; i < n; i++) { cin>>s...
0
#include<bits/stdc++.h> #define MOD 1000000007 char str[1005]; int dp[1005][1005]; int main() { int n,m; scanf("%d%d",&n,&m); dp[1][1]=1; for(int c=1;c<=n;c++) { scanf("%s",&str[1]); for(int c2=1;str[c2];c2++) if (str[c2]=='.'&&dp[c][c2]==0)dp[c][c2]=(dp[c-1][c2]+dp[c][c2-1])%MOD; } printf...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 1000000 + 10; const int INF = 999999999; struct Order { int st; int ed; } ord[maxn]; Order flow[maxn]; bool cmp(const Order& a, const Order& b) { return a.ed < b.ed; } int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%...
2
#include <bits/stdc++.h> using namespace std; int main() { int x, y; set<int> xs; set<int> ys; set<pair<int, int> > track; for (int i = 0; i < 8; i++) { cin >> x >> y; xs.insert(x); ys.insert(y); track.insert(make_pair(x, y)); } if (xs.size() != 3 || ys.size() != 3) { cout << "ugly"; ...
2
#include <bits/stdc++.h> using namespace std; void FREOPEN() { freopen( "" ".in", "r", stdin); freopen( "" ".out", "w", stdout); } inline double Time() { return (clock() * 1.0) / CLOCKS_PER_SEC; } const int N = 83, inf = 1e9 * 2, MOD = 1e9 + 7; char CH[N]; const long long INF = 1...
4
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0; bool f = 1; char s = getchar(); while ((s < '0' || s > '9') && s > 0) { if (s == '-') f ^= 1; s = getchar(); } while (s >= '0' && s <= '9') x = (x << 1) + (x << 3) + s - '0', s = getchar(); return f ? x : -x; ...
5
#include <bits/stdc++.h> using namespace std; long long int powm(long long int x, long long int y, long long int m = 1000000007) { x = x % m; long long int res = 1; while (y) { if (y & 1) res = res * x; res %= m; y = y >> 1; x = x * x; x %= m; } return res; } long long i...
3
#include <bits/stdc++.h> using namespace std; template <typename T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vector) { for (size_t i = 0; i < vector.size(); ++i) { os << vector[i] << " "; } os << std::endl; return os; } int gcd(int a, int b) { if (b == 0) { return a; } else {...
2
#include <bits/stdc++.h> using namespace std; const int64_t MOD = 1e9+7; void add(int64_t& a, int64_t b){ a = (a+b) % MOD; } int64_t power_mod(int64_t num, int64_t power){ int64_t prod = 1; num %= MOD; while(power > 0){ if(power&1) prod = prod * num % MOD; num = num * num % MOD; ...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, v, sum = 0, t; cin >> n >> v; t = n - v - 1; if (t > 0) { for (int i = 2; i <= t + 1; i++) sum = sum + i; sum = sum + v; cout << sum; } else if (n <= v) { cout << n - 1; } else { cout << v; return 0; } return 0; }
1
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, k; int a, b, c, d; cin >> n >> k; cin >> a >> b >> c >> d; if (n == 4 || (n >= 5 && k <= n)) return cout << -1, 0; vector<int> vec; for (int i = 1; i <= n; i++) if (i ...
2
#include <bits/stdc++.h> using namespace std; int main() { string m, n, p, q; int i; cin >> m >> n; cout << m << " " << n << endl; cin >> i; for (; i > 0; i--) { cin >> p >> q; if (p == m) m = q; else if (p == n) n = q; else if (q == m) m = p; else n = p; cout...
1
#include <bits/stdc++.h> using int64 = long long; const int N = 105; char p[N][N]; int T, n, m, k, x, y; int a[N], r[N]; inline char selcol(char a, char b, char c) { r[0] = r[1] = r[2] = r[3] = 0; r[a - 'a'] = r[b - 'a'] = r[c - 'a'] = 1; if (!r[0]) return 'a'; if (!r[1]) return 'b'; if (!r[2]) return 'c'; ...
4
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; int n; double s[52]; struct point { double x, y; } A, B, P[52]; inline double min(double x, double y) { return x < y ? x : y; } double cross(point O, point A, point B) { return (A.x - O.x) * (B.y - O.y) - (A.y - O.y) * (B.x - O.x); } double dot(...
5
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool chkmin(T &x, T y) { return x > y ? x = y, 1 : 0; } template <typename T> inline bool chkmax(T &x, T y) { return x < y ? x = y, 1 : 0; } template <typename T> inline void read(T &x) { char ch = getchar(); int f = 1; x = 0; while ...
2
#include <bits/stdc++.h> using namespace std; long long int lf, old, nayi; vector<long long int> g[20005]; vector<long long int> v; void go() { cin >> lf >> old >> nayi; long long int a, b, x; vector<long long int> ans(lf + 1, 0), v(lf + 1, 0); for (long long int i = 1; i < lf + 1; i++) { if (i == old) { ...
4
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:667772160") template <class T1> void deb(T1 e1) { cout << e1 << endl; } template <class T1, class T2> void deb(T1 e1, T2 e2) { cout << e1 << " " << e2 << endl; } template <class T1, class T2, class T3> void deb(T1 e1, T2 e2, T3 e3) { co...
5
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; struct Edge { int to, val, next, cost; } edge[300086]; int s, t; int cnt = -1; int head[300086]; queue<int> q; int d[300086]; int cur[300086]; int inq[300086]; int vis[300086]; int costsum; void addEdge(int u, int v, int w, int f) { cnt++; ...
6
#include <bits/stdc++.h> using namespace std; const int maxn = int(2e5) + 100; struct astr_data { int start, num, nid, type; astr_data() { start = num = 0; } bool operator<(const astr_data b) const { if (type != b.type) return (type < b.type); if (nid != b.nid) return (nid < b.nid); return num < b.num...
4
#include <bits/stdc++.h> using namespace std; void print_exp_value(long long sum, int num_values) { int r = sum % num_values; int dec = 0; for (int i = 0; i < 6; i++) { r *= 10; dec = 10 * dec + r / num_values; r = r % num_values; } cout << sum / num_values << "." << dec << endl; } int main() { ...
4
#include <bits/stdc++.h> int main() { int n, x = 0, y = 0, ans = 0; char c[1000000]; scanf("%d\n", &n); scanf("%s", c + 1); for (int i = 1; i <= n; i++) { if (c[i] == 'U') y++; else x++; if (x == y && c[i] == c[i + 1]) ans++; } printf("%d", ans); }
2