solution
stringlengths
52
181k
difficulty
int64
0
6
#include <iostream> using namespace std; int main(){ int n, m, c, ans, tmp; int a, b[21]; cin >> n >> m >> c; for (int i = 0; i < m; ++i) cin >> b[i]; ans = 0; for (int i = 0; i < n; ++i){ tmp = c; for (int j = 0; j < m; ++j){ cin >> a; tmp += a*b[j]; } if (tmp > 0) ans++; } cout << ans; }
0
#include<bits/stdc++.h> #define N 200005 using namespace std; int a[N],i,j,k,l,s,n,m,Last,b[N]; long long ans; int main() { scanf("%d",&n); for (i=1;i<=n;i++) scanf("%d",&a[i]); for (i=1;i<=n;i++) if (a[i]>=i) return puts("-1"),0; for (i=1;i<=n;i++) if (a[i]-a[i-1]>=2) return puts("-1"),0; for (i=n;...
0
#include <bits/stdc++.h> using namespace std; long long a[2 * 65]; long long cp[2 * 65]; long long power[2 * 65]; long long encode(long long x) { return x + 64; } long long decode64(long long x) { return x - 64; } long long convToBinary(long long n) { string s = ""; long long ans = 0; while (n) { if (n % 2 ==...
2
#include <bits/stdc++.h> using namespace std; const int mod = 1000000009; map<pair<int, int>, int> in, id; set<int> S; int X[100010], Y[100010]; bool check(pair<int, int> P) { int x = P.first, y = P.second + 1; for (int dx = x - 1; dx <= x + 1; dx++) { if (in.count(make_pair(dx, y)) && in[make_pair(dx, y)] == 1...
2
//#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <vector> #include <algorithm> #include <string> #include <cmath> #include <set> #include <bitset> #include <queue> #include <tuple> #include <map> #include <random> #include <chrono> using namespace std; #define fastInp cin.tie(0); cout.tie(0); #define sq...
5
#include <bits/stdc++.h> #define int long long #define ff first #define ss second #define ll long long #define ld long double #define pb push_back #define eb emplace_back #define mp make_pair #define mt make_tuple #define pii pair<int, int> #define pll pair<ll,ll> #define vi vector<int> #define vl vector<ll> #define vi...
3
#include <bits/stdc++.h> int main() { int n, k, x; std::cin >> n >> k >> x; int ans = k * x; for (int i = 0; i < n - k; i++) { int temp; std::cin >> temp; ans += temp; } std::cout << ans << '\n'; }
1
#include <bits/stdc++.h> using namespace std; int n; int a[510]; vector<pair<int, int> > edges; vector<int> leaf, nonleaf; int d = 0; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) { if (a[i] == 1) leaf.push_back(i); else nonleaf.pus...
4
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; ll INF = LLONG_MAX; using vi = vector<int>; using vll = vector<ll>; using pii = pair<int, int>; namespace output { void pr(int x) { cout << x; } void pr(long x) { cout << x; } void pr(ll x) { cout << x; } void pr(unsigned x) { c...
4
#include <bits/stdc++.h> using namespace std; struct timer { time_t start; timer() { start = clock(); } ~timer() { cerr << 1. * (clock() - start) / CLOCKS_PER_SEC << " secs" << endl; } }; int n, s[100010], K; vector<pair<int, int> > event[100010]; struct segtree { int l, r; segtree *cl, *cr; int val, ...
5
#include<bits/stdc++.h> #define REP(i,s,n) for(int i=s;i<n;i++) #define rep(i,n) REP(i,0,n) #define EPS (1e-7) #define COUNTER_CLOCKWISE 1 #define CLOCKWISE -1 #define ONLINE_BACK 2 #define ONLINE_FRONT -2 #define ON_SEGMENT 0 #define equals(a,b) (fabs((a)-(b)) < EPS) using namespace std; class Point{ public: dou...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 9; const int M = 200; const int MOD = 998244353; int N, dp[maxn][M + 9][2]; inline void Mod(int &x) { if (x >= MOD) x -= MOD; if (x < 0) x += MOD; } void upd(int i, int val) { Mod(dp[i][val][0] = dp[i - 1][val - 1][0] + dp[i - 1][val - 1][1])...
1
#include <bits/stdc++.h> using namespace std; void re() {} template <typename T, typename... args> void re(T &x, args &...tail) { cin >> x; re(tail...); } void pr() {} template <typename T> void pr(const T &x) { cout << x; } template <typename T, typename... args> void pr(const T &x, const args &...tail) { cout...
1
#include <bits/stdc++.h> using namespace std; char s[100005]; int mod = 1000000007; long long a[2005][4005]; long long b[2005][4005]; int main() { int n, m; scanf("%d%d", &n, &m); scanf("%s", s); int mn = 0; int sum = 0; for (int i = 0; i < m; i++) { if (s[i] == '(') sum++; else sum--; ...
3
#include <bits/stdc++.h> using pii = std::pair<int, int>; using pll = std::pair<long long, long long>; int main() { std::ios::sync_with_stdio(false); int t; std::cin >> t; while (t--) { long long a, b, c; std::cin >> a >> b >> c; long long s = a + b + c; long long t = (s + 1) / 2; if (std::m...
1
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; map<long long, long long> m; int a[n]; for (long long i = 0; i < n; i++) { cin >> a[i]; m[a[i]] = i + 1; } int b[n]; int l = 1, r = n; int ans[n]; for (long long i = 0; i < n; i++) { cin >> b[i]; int pos = m[...
2
#include <bits/stdc++.h> using namespace std; const long long int INF = (1LL << 58); const bool DEBUG = 0; const int NODES_LIMIT = 100005; int nodes, edges; std::vector<int> adj[2][NODES_LIMIT]; bool vis[NODES_LIMIT]; int color[NODES_LIMIT], globalColor = 1; int componentSize[NODES_LIMIT]; bool hasCycle[NODES_LIMIT]; i...
2
#include<bits/stdc++.h> #define N 100 using namespace std; int main() { int n,p[N+1],m[N+1][N+1]; cin>>n; for (int i=1;i<=n;i++) cin>>p[i-1]>>p[i]; for (int i=1;i<=n;i++) m[i][i]=0; for (int l=2;l<=n;l++) { for (int i=1;i<=n-l+1;i++) { int j=i+l-1; m[i][j]=(1<<21); for (int k=i;k<=j-1;...
0
#include <iostream> using namespace std; int main() { int N; cin>>N; int dt=0,dx=0,dy=0; bool f=true; for (int i=0; i<N; i++) { int t,x,y; cin>>t>>x>>y; dt=abs(t-dt),dx=abs(x-dx),dy=abs(y-dy); if (dt<dx+dy || (abs(dx+dy-dt))%2!=0) { f=false; } } cout<<(f?"Yes":"No")<<endl; ret...
0
#include <bits/stdc++.h> using namespace std; pair<int, int> d[1000000], f[1000000]; int lastt, cur, n, i, j, k, ans, num, last, x, l; int g1[1000][1000], g[1000][1000]; int fix[1000000], c[1000000], h[1000000]; queue<int> q[4]; int main() { cin >> n; for (i = 1; i <= n; i++) cin >> c[i]; for (i = 1; i <= n; i++)...
1
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int hr = s[0] - '0'; hr = hr * 10 + s[1] - '0'; if (hr >= 12) hr -= 12; int min = s[3] - '0'; min = min * 10 + s[4] - '0'; double b = min * 6; double a = ((double)hr + (double)min / 60) * 30; printf("%.9lf %.9lf", a, b); ...
2
#include <bits/stdc++.h> using namespace std; int va, vb, vc; int A, B, C; vector<int> as, bs, cs; bool dp[33][2][11][11][11]; struct state { int L, c, A, B, C, aa, bb, cc; state() {} state(int L, int c, int A, int B, int C, int aa, int bb, int cc) : L(L), c(c), A(A), B(B), C(C), aa(aa), bb(bb), cc(cc) {} }...
5
#include <bits/stdc++.h> using namespace std; const int MAXN = 4e5 + 5; struct Edge { int v, nxt; Edge() {} Edge(int _v, int _nxt) : v(_v), nxt(_nxt) {} }; Edge E[MAXN * 2]; int head[MAXN], ans[MAXN], sub[MAXN], mxsub[MAXN]; int tot = 0, fuc, n, x, y; void addedge(int u, int v) { E[tot] = Edge(v, head[u]); he...
3
#include <bits/stdc++.h> using namespace std; const int N = 211111; int a[N]; double weakness(double x, int n) { double sum = 0; double last_min = 0; double last_max = 0; double ans_min = 0; double ans_max = 0; for (int i = 0; i < n; i++) { sum += a[i] - x; ans_max = max(ans_max, sum - last_min); ...
5
#include <bits/stdc++.h> using namespace std; int n; int main() { multiset<int> Q; cin >> n; long long ans = 0; long long times = 0; bool b = false; int count = 0; for (int i = 0; i < n; i++) { int x; cin >> x; if (Q.size() == 0 || (*Q.begin()) > x) { Q.insert(x); } else { ans ...
4
#include <bits/stdc++.h> using namespace std; int visited[200005], par[200005]; int a[200005]; int n, cur_max; int main() { scanf("%d", &n); for (int i = 1; i < n; i++) scanf("%d", &a[i]); cur_max = n; if (a[1] == cur_max) cur_max--; visited[a[1]] = 1; for (int i = 2; i < n; i++) { if (visited[a[i]]) { ...
6
#include <bits/stdc++.h> using namespace std; constexpr long long int MOD = 998244353; constexpr double EPS = 1e-12; long long int N, M, K, T, H, W, L, R; class Add_Segment_Tree { vector<long long int> v; long long int ret; int num; long long int Update(int place) { if (place >= v.size() / 2) { return...
2
#include <cstdlib> #include <cmath> #include <climits> #include <cfloat> #include <map> //#include <utility> #include <set> #include <iostream> //#include <memory> #include <string> #include <vector> #include <algorithm> //#include <functional> #include <sstream> //#include <deque> #include <complex> #include <stack> #...
0
#include <bits/stdc++.h> using namespace std; int a[100005]; vector<int> cut; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, x, y; string s; cin >> n >> x >> y >> s; s = '1' + s; int cnt = 0; for (int i = 0; i < int(n); ++i) if (s[i] == '1' && s[i + 1] == '0')...
3
#include <bits/stdc++.h> using namespace std; bool query(int x, int y) { printf("? %d %d\n", x, y); fflush(stdout); char str[5]; scanf("%s", str); return str[0] == 'x'; } int main() { char str[10]; while (scanf("%s", str)) { if (str[0] != 's') break; int l = 1, r = 0; while (!query(l, 2 * l)) ...
4
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <string> #include <sstream> #include <complex> #include <vector> #include <list> #include <queue> #include <deque> #include <stack> #include <map> #include <set> #include <iomanip> using namespace std; typedef long...
0
#include <iostream> using namespace std; int n, m; int w[100][100]; int p[50][50]; int b; bool input() { cin >> n >> m; if (!n && !m) { return false; } for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { cin >> w[i][j]; } } for (int i = 0; i < m; ++i) { for (int j = 0; j < m; ...
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 100 * 1000 + 17; string s, x; int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> s; reverse(s.begin(), s.end()); while (s.size() and s.back() == '0') s.pop_back(); reverse(s.begin(), s.end()); while (s.size()) { i...
1
#include <bits/stdc++.h> using namespace std; struct wie { long long s, pref, suf; }; vector<vector<wie> > T(17); int l, size; wie Merge(wie a, wie b, int wlk) { wie wyn; wyn.s = a.s + b.s; wyn.s -= (1 + a.suf) * a.suf / 2; wyn.s -= (1 + b.pref) * b.pref / 2; wyn.s += (1 + (a.suf + b.pref)) * (a.suf + b.pre...
5
#include <iostream> #include <vector> #include <map> using namespace std; int main() { while(true) { int W, Q; cin >> W >> Q; if(!W && !Q) break; vector<bool> wall(W+1, true); wall[W] = false; map<int, pair<int, int> > catpos; while(Q--) { char c; cin >> c; if(c == 's') { int id, w; c...
0
#include <bits/stdc++.h> using namespace std; int d[305], deg[1005]; vector<pair<int, int> > vec; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) cin >> d[i]; int l = 1, r = n, q = d[n] + 1, lst = 0; for (int i = 1; i <= q; i++) { if (l <= r && q - i + deg[i] == d[r]) { lst = 1; r--...
4
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:128000000") long long n, k; vector<vector<pair<int, int> > > upstream, downstream; vector<pair<int, int> > totalup, totaldown; vector<int> allnumbers; vector<int> digits; void generate_upstream(int pos, int value, vector<pair<int, int> > &a) ...
5
#include <bits/stdc++.h> using namespace std; const int M = 8 * 9 * 5 * 7 * 11 * 13; long long a, b; int d[M + 1]; queue<int> Q; void Q_add(int t, int ds) { if (0 <= t && t <= M) { if (d[t] == -1) { d[t] = ds; Q.push(t); } } } long long f(int s, int t, int k) { for (int i = 0; i < M + 1; i++) ...
3
#include <iostream> #include <cstdio> using namespace std; int main() { int N, M; int sum_N = 0, sum_M = 0, c = 0; while (scanf("%d,%d ", &N, &M) == 2) { sum_N += N * M, sum_M += M; c++; } printf("%d\n%d\n", sum_N, (int)((double)sum_M / c + 0.5)); return 0; }
0
#include <iostream> #include <algorithm> using namespace std; int n,m,c,p,ans; int l[123456]; pair<int,int> wc[123456]; int main() { cin>>n>>m>>c; for(int i=1;i<=c;i++)cin>>l[i]; for(int i=0;i<n;i++){ cin>>wc[i].second>>wc[i].first; wc[i].first=1000-wc[i].first; } sort(wc,wc+n); for(int i=0;i<n&&p<m;i++){ i...
0
#include <bits/stdc++.h> using namespace std; char park[2007][2007]; int res[2007]; int n, m, k; bool check(int x) { return (x >= 0 && x < m); } int main() { cin.sync_with_stdio(0); cout.sync_with_stdio(0); cin >> n >> m >> k; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) cin >> park[i][j]; for ...
2
#include <iostream> #define r(i,n) for(int i=0;i<n;i++) using namespace std; int a; string s[12]; void dfs(int y,int x){ s[y][x]='0'; if(y+1<12&&s[y+1][x]=='1')dfs(y+1,x); if(y-1>=0&&s[y-1][x]=='1')dfs(y-1,x); if(x+1<12&&s[y][x+1]=='1')dfs(y,x+1); if(x-1>=0&&s[y][x-1]=='1')dfs(y,x-1); } int main(){ while(ci...
0
#include <bits/stdc++.h> using namespace std; void seif() { std::ios_base::sync_with_stdio(0); } int main() { seif(); int n; cin >> n; if (n <= 10) cout << 0; else if (n < 20) cout << 4; else if (n == 20) cout << 15; else if (n == 21) cout << 4; else cout << 0; return 0; }
1
#include <bits/stdc++.h> using namespace std; int n, m, k, x, y, buf[100001], pat[100001]; vector<int> vec[100001], ex, t; bool check(long double pos) { for (int i = 1; i <= n; i++) buf[i] = vec[i].size(), pat[i] = ceil(buf[i] * pos); queue<int> s; for (int i : ex) s.push(i), buf[i] = 1e7; while (!s.empty()...
4
#include <bits/stdc++.h> using namespace std; long long n; bool solve(long long a) { long long curr = n; long long cnt = 0; while (curr != 0) { cnt += min(curr, a); curr -= min(curr, a); curr -= curr / 10; } if (n % 2 == 0) if (cnt >= n / 2) return 1; if (n % 2 == 1) if (cnt > n / 2) ret...
3
#include <bits/stdc++.h> using namespace std; const int MAX_N = 2 * 1e6 + 7; const int INF = 1e9 + 7; const int MOD = 1e9 + 7; const int LOG = 22; long long a[MAX_N]; bool seen[MAX_N]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { long long n; cin ...
2
#include <bits/stdc++.h> using namespace std; template <typename T> void out(T x) { cout << x << endl; exit(0); } const long long mod = 1e9 + 7; const int maxn = 5152; long long n, a, b; int dp[maxn][maxn]; string s; long long f[maxn]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ...
6
#include<iostream> #include<vector> #include<cmath> #include<algorithm> #include<numeric> using namespace std; const double PI = 3.14159265358979; class Point { public: double x, y; Point(double x = 0.0, double y = 0.0) :x(x), y(y) {} }; class Wind { public: double w, a; }; bool include(double angle...
0
#include <bits/stdc++.h> using namespace std; long long modx(long long Base, long long exponent) { long long ans = 1; if (Base == 1) return Base; while (exponent) { if (exponent & 1) ans = (ans * Base) % 1000000007; Base = (Base * Base) % 1000000007; exponent = exponent >> 1; } return ans; } long ...
3
#include <bits/stdc++.h> using namespace std; ostream& operator<<(ostream& cerr, vector<long long> aux) { cerr << "["; for (auto e : aux) cerr << e << ' '; cerr << "]"; return cerr; } const int maxN = 200011; struct analyzer { long long sum = 0; int base = maxN; long long up[maxN * 2], down[maxN * 2]; v...
6
#include <bits/stdc++.h> using namespace std; long long p(long long a, long long b) { long long rez = 1; while (b != 0) { if (b % 2) { rez *= a; rez %= 998244353; } a = a * a; a %= 998244353; b /= 2; } return rez; } long long inv_mod(long long a) { return p(a, 998244353 - 2); } l...
5
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; struct node { int l; int r; int id; } a[N]; struct tree { int l; int r; int id; } b[N]; int num[N], ans[N]; bool cmp1(node a, node b) { if (a.l == b.l) return a.r < b.r; return a.l < b.l; } bool cmp2(tree a, tree b) { if (a.l == b.l)...
3
#include <bits/stdc++.h> using namespace std; int n; unordered_set<int> g[200005]; bool gone[200005]; void dfs1(int u, int p) { printf("%d\n", u); gone[u] = true; for (auto v : g[u]) { if (v == p) continue; dfs1(v, u); } } void dfs(int u, int p) { if (gone[u]) return; for (auto itr = g[u].begin(); i...
2
#include <bits/stdc++.h> using namespace std; int n, k; int main() { scanf("%d%d", &n, &k); if (k >= (n * (n - 1)) / 2) puts("no solution"); else { for (int i = 0, t = 1; t <= n; t++) printf("%d %d\n", i, t); } return 0; }
1
#include <bits/stdc++.h> #pragma G++ optimize(2) using namespace std; inline long long read() { char ch = ' ', last; long long ans = 0; while (ch < '0' || ch > '9') last = ch, ch = getchar(); while (ch >= '0' && ch <= '9') ans = ans * 10 + int(ch - '0'), ch = getchar(); if (last == '-') return -ans; return ...
4
#include <bits/stdc++.h> using namespace std; bool vis[1005][1005]; char str[1005][1005]; int n, m; queue<pair<int, int> > q; void bfs(int sx, int sy) { vis[sx][sy] = 1; q.push(pair<int, int>(sx, sy)); while (!q.empty()) { pair<int, int> t = q.front(); q.pop(); int x = t.first, y = t.second; if (x...
2
#include <bits/stdc++.h> using namespace std; template <typename T> vector<T>& operator--(vector<T>& v) { for (auto& i : v) --i; return v; } template <typename T> vector<T>& operator++(vector<T>& v) { for (auto& i : v) ++i; return v; } template <typename T> istream& operator>>(istream& is, vector<T>& v) { for...
5
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const long long INF = 1e18; const int M = 1e9 + 7; const int maxn = 3e5; char s[maxn], t[maxn]; signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(10); int T; cin >> T; while (T--)...
6
#include <bits/stdc++.h> using namespace std; using ll = int64_t; int sum(const vector<vector<int>>& s, int x0, int y0, int x1, int y1) { if (y0 > y1 || x0 > x1) return 0; int result = 0; for (int i = x0; i <= x1; i++) { result += s[i][y1]; if (y0) result -= s[i][y0 - 1]; } return result; } int main()...
3
#include <bits/stdc++.h> using namespace std; int main() { string S; cin >> S; for (char c = 'a'; c <= 'z'; c++) { if (count(S.begin(), S.end(), c) % 2 == 1) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; }
0
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > path[200005]; string s; int a[200005], b[200005], f[200005], ff[200005], n, ans; int r1() { if (!b[n]) return -1; if (b[n] != 1) for (int i = n - 1;; i--) { if (b[i] != b[i + 1] - 1) return -1; if (b[i] == 1) break; } for (i...
1
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_string(const string...
2
#include<iostream> #include<string> #include<algorithm> using namespace std; int main(){ string str; getline(cin, str); transform(str.begin(), str.end(), str.begin(), ::toupper); cout << str << endl; }
0
#include <bits/stdc++.h> using namespace std; bool is_prime(int b) { for (int i{2}; i < (b / 2) + 1; ++i) { if (b % i == 0) { return false; } } return true; } void solve() { int a, b; cin >> a >> b; if (!is_prime(b)) { cout << "NO"; return; } for (int i{a + 1}; i < b; ++i) { if...
1
#include <bits/stdc++.h> using namespace std; const int N = 1000100; const int MOD = 1000000007; vector<long long> al[N], sum[N]; vector<pair<int, int> > adj[N]; pair<int, int> p[N]; int cnt(int u, long long ls) { return upper_bound(al[u].begin(), al[u].end(), ls) - al[u].begin(); } long long hp(int u, long long h, l...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, m, q; cin >> n >> m >> q; int arr[n][m]; int mx = 0; int temp; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> arr[i][j]; } } int p, l; int row[n]; for (int i = 0; i < n; i++) { row[i] = 0; int...
2
#include <iostream> #include <vector> #include <map> #include <set> #include <queue> #include <string> #include <iomanip> #include <algorithm> #include <cmath> #include <stdio.h> using namespace std; #define int long long int MOD = 1000000007; signed main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N...
0
#include <bits/stdc++.h> using namespace std; void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cout << *it << " = " << a << endl; err(++it, args...); } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(N...
4
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, k; cin >> k >> n; if ((long long)n * (n - 1) < k) { cout << "NO\n"; return 0; } cout << "YES\n"; int a = 1, b = 2; for (int i = 0; i < k; ++i) { cout << a << ' ' << b << '\n'; swap(a,...
5
#include <bits/stdc++.h> using namespace std; long long X, D, N, r, cnt; long long A[200010], L[200010], R[200010], res[200010]; map<long long, bool> seen; map<long long, vector<pair<long long, long long>>> M; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N >> X >> D; if(D == 0 && X == ...
0
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); const double eps = 1e-9; const int inf = 2000000000; const long long infLL = 9000000000000000000; inline bool checkBit(long long n, int i) { return n & (1LL << i); } inline long long setBit(long long n, int i) { return n | (1LL << i); ; } inl...
4
#include <bits/stdc++.h> long m[100001]; int main() { long n, p, a, i; scanf("%ld", &n); p = 0; for (i = 1; i <= n; i++) scanf("%ld", &m[i]); p = 0; for (i = n; i > 1; i--) { if (m[i - 1] > m[i]) { p = i - 1; break; } } printf("%ld", p); return 0; }
2
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; char s[n][m]; int a[n][m], t = 0; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) a[i][j] = 0; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) cin >> s[i][j]; for (int i = 0; i < n; i++) { for (...
2
#include <bits/stdc++.h> int ri() { int n; scanf("%d", &n); return n; } int main() { int n = ri(); std::string s; std::cin >> s; int q = ri(); for (int i = 0; i < q; i++) { int k = ri(); std::deque<std::pair<int, int> > ds; int64_t sum = 0; int added = 0; int64_t res = 0; for (int j = 0; j < n; ...
0
#include <iostream> using namespace std; int A,B,C; int beki(int n){ int count = 0; while(n%2==0){ count++; n /= 2; } return count; } int main(){ cin >> A >> B >> C; if(A%2==1 || B%2==1 || C%2==1) cout << 0 << endl; else if(A==B && B==C) cout << -1 << endl; else{ int ans = 1e9; cout << min(beki(A+B),...
0
#include <bits/stdc++.h> using namespace std; long long ans = 0; long long dd(long long x, long long y, long long z) { return (x - y) * (x - y) + (y - z) * (y - z) + (z - x) * (z - x); } void gao(const vector<int>& vr, const vector<int>& vg, const vector<int>& vb, int r, int g, int b) { for (auto v : vr) {...
2
#include <bits/stdc++.h> using namespace std; int main() { string S, T, U; cin >> S >> T >> U; cout << S.at(0) << T.at(1) << U.at(2); }
0
#include<bits/stdc++.h> using namespace std; #define i64 long long int #define ran 101111 i64 pos[ran], cnt[ran], s; int n; int o[ran], lo; i64 AB(i64 x){return x>=0?x:-x;} int main(){ ios::sync_with_stdio(false); cin >> n >> s; for(int i=0; i<n; i++) cin >> pos[i] >> cnt[i]; int L = 0, R = n-1; i64 totLef = cnt...
0
#include <bits/stdc++.h> using namespace std; int main() { int tttt; cin >> tttt; for (int loop = 0; loop < (tttt); ++loop) { string s, t; cin >> s >> t; int n = s.size(); int m = t.size(); int flag = 0; int now = 0; for (int i = 0; i < (n); ++i) { if (now == m) break; if (...
5
#include <bits/stdc++.h> using namespace std; int n, cnt = -1, h, hx; int main() { cin >> n; while (n--) { cin >> h; if (hx > h) { cnt += hx - h; hx = h; } cnt += h - hx; hx = h; cnt += 2; } cout << cnt; }
2
#include <bits/stdc++.h> using namespace std; struct zxc { long long ces, doz, aql; }; long long n, ans, used[100001]; zxc a[100001]; vector<long long> g; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i].aql >> a[i].doz >> a[i].ces; } for (int i = 0; i < n; i++) { if (used[i]) continue...
3
#include <bits/stdc++.h> using namespace std; int main() { long long int n, t; cin >> t; while (t--) { cin >> n; vector<long long int> v(n); for (long long int i = 0; i < n; i++) { cin >> v[i]; } if (n == 2) { cout << 0 << endl; } else { sort(v.begin(), v.end()); lo...
1
#include <bits/stdc++.h> using namespace std; vector<int> ans; const int n = 8; bitset<8> my; int f(int a, int b) { int rez = 1; if (b == 0) return 1; while (b--) { rez = ((rez * a) % 1000003); } return rez; } void f2(int a) { int k = 7; unsigned i, j = 1 << 8 - 1; for (i = 0; i < 8; ++i) { my[i...
3
#include <bits/stdc++.h> using namespace std; void solve() { long long p, q; cin >> p >> q; vector<long long> factors; long long temp = q; for (int i = 2; i * i <= temp; i++) { if (temp % i == 0) { while (temp % i == 0) { temp /= i; } factors.push_back(i); } } if (temp > ...
3
#include <bits/stdc++.h> using namespace std; const int M = 1000000007; const int MM = 998244353; const long double PI = acos(-1); long long power(long long b, long long e, long long m) { if (e == 0) return 1; if (e & 1) return b * power(b * b % m, e / 2, m) % m; return power(b * b % m, e / 2, m); } long long pow...
6
#include<iostream> #include<string> using namespace std; int main (){ string n; int i; for(i=0;i<=2;i++){ cin>>n; cout<<n.substr(i,1);} }
0
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef complex<double> Vec; ll N, K; vector<ll> A; ll Sum; set<ll> Divs; ll R; int main() { cin >> N >> K; A.resize(N); for (ll i = 0; i < N; ++i) { cin >> A[i]; Sum += A[i]; } for (ll i = 1; i * i <= Sum; ++i) { if (Sum % i =...
0
#include <bits/stdc++.h> using namespace std; long long read() { long long x = 0, w = 1; char ch = getchar(); while (!isdigit(ch)) w = ch == '-' ? -1 : 1, ch = getchar(); while (isdigit(ch)) { x = x * 10 + ch - '0'; ch = getchar(); } return x * w; } const int Max_n = 1e5 + 5; int n, K; long long ans...
1
#include <bits/stdc++.h> using namespace std; pair<int, int> a[10000]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; a[i] = make_pair(x, y); } sort(a, a + n); int cur = -1; for (int i = 0; i < n; i++) { if (a[i].second >= cur) { cur = a[i].secon...
1
#include <bits/stdc++.h> using namespace std; char s[5010]; int dp[5010]; int ans = 0; signed main() { std::ios::sync_with_stdio(false); cin >> s + 1; int n = strlen(s + 1); for (int i = 1; i <= n; i++) { int ff = 0; int dd = 0; int pp = 0; if (s[i] == ')') dp[i] = -1, pp++; else { ...
1
#include<iostream> #include<cstdio> #include<map> #include<string> using namespace std; int main() { int a=0,b=0; map<int,int> p,n; string in; while(getline(cin,in)) { if(in=="") break; int cnt=0; a=0; b=0; while(in[cnt]!=',') { a*=10; a+=in[cnt]-'0'; cnt++; } cnt++; for(int i = cnt; i < ...
0
#include <bits/stdc++.h> using namespace std; const bool debug = 0; inline void read(int &x) { char ch; bool flag = false; for (ch = getchar(); !isdigit(ch); ch = getchar()) if (ch == '-') flag = true; for (x = 0; isdigit(ch); x = x * 10 + ch - '0', ch = getchar()) ; x = flag ? -x : x; } inline void w...
1
#include <bits/stdc++.h> using namespace std; int n; int a[10]; vector<string> res; vector<int> fields; int b[10]; void gao(const char* s, int len) { int depth = (int)fields.size(); if ((4 - depth) * 3 < len) { return; } if (depth == 4) { if (len == 0) { char buf[1024]; sprintf(buf, "%d.%d.%...
3
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; int add(int a, int b) { return (a + b) % MOD; } int sub(int a, int b) { return (a - b + MOD) % MOD; } int mul(int a, int b) { return ((long long)a * b) % MOD; } int inv(int a) { int b = 1; for (int i = 0; (1 << i) <= (MOD - 2); i++) { if (...
6
#include <bits/stdc++.h> using namespace std; const int INF = 1000000001; int a[5010]; int dfs(int l, int r, int now) { int i, ans = 0; int h = INF; if (l == r) return 0; for (i = l; i < r; i++) h = min(h, a[i]); ans += h - now; int L = l; for (i = l; i < r; i++) { if (a[i] == h) { ans += dfs(L,...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 200; char str[maxn + 5]; int n; bool ok(int a, int b) { int x = 0, y = 0; for (int i = a; i <= b; i++) { if (str[i] == 'U') { x--; } else if (str[i] == 'D') { x++; } else if (str[i] == 'L') { y--; } else if (str[i] == '...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; long long n, m, k, p[maxn], cur, lst, nww, ans; int main() { scanf("%lld%lld%lld", &n, &m, &k); for (int i = 1; i <= m; i++) scanf("%lld", p + i); cur = 1; while (cur <= m) { lst = cur - 1; nww = (p[cur] - lst + k - 1) / k; for (...
1
#include <bits/stdc++.h> using namespace std; int32_t main() { long long int n; cin >> n; long long int a[n]; for (long long int i = 0; i < n; i++) { cin >> a[i]; } long long int c = 0, m = 0; for (long long int i = 0; i < n; i++) { if (a[i] == 0) { c++; m = max(m, c); } else { ...
2
#include <bits/stdc++.h> #pragma warning(disable : 4996) const long long MOD = 1000000007; using namespace std; int dp[205][205][205]; char str0[205]; char str1[5]; void solve() { int n, K; scanf("%d%d%s%s", &n, &K, str0, str1); int i, j, k; for (i = 0; i <= n; i++) { for (j = 0; j <= n; j++) { for (k...
6
#include <bits/stdc++.h> using namespace std; int n, uno, beg, imp[1000010]; void magic() { cout << "("; if (uno != -1 && uno != 0) { for (int(i) = (int)(0); (i) < (int)(uno); (i)++) { cout << "("; } cout << imp[0] << "->"; for (int(i) = (int)(1); (i) < (int)(uno); (i)++) { cout << imp[i...
5