solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; string clown, acrobat; int a[5][5]; int n; int used[5555]; void foobar(int a, int b, int c, int d) { for (int i = 0; i < n and a > 0; ++i) { if (clown[i] == '1' and acrobat[i] == '1') { printf("%d ", i + 1); a--; } } for (int i = 0; i < n and b > 0...
2
#include <bits/stdc++.h> using namespace std; int main() { int tc; cin >> tc; while (tc--) { int n; cin >> n; long long int sum = 1; for (int i = 1;; i++) { sum += pow(2, i); if (n % sum == 0) { cout << n / sum << endl; break; } } } return 0; }
1
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10; pair<int, int> a[MAXN]; int n, p, q; double ans = 1e20; int sgn(long long x) { if (x == 0) return 0; if (x < 0) return -1; else return 1; } long long cross(int p, int q, int r) { return (long long)(a[q].first - a[p].first) * (-a[r]...
5
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long t; cin >> t; while (t--) { long long n, i, j, s1 = 0, s2 = 0, k, c = 0; cin >> n; long long a[n]; for (i = 0; i < n; i++) cin >> a[i]; long long b[n]; unordered_map<lon...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 2000 + 10; int st[maxn], fin[maxn]; bool check(string s) { int k = s.length(); for (int i = 0; i < k / 2; i++) { if (s[i] != s[k - i - 1]) return false; } return true; } int main() { string s; cin >> s; int s1 = 0, s2 = 0; int n = s.leng...
4
#include<bits/stdc++.h> using namespace std; typedef long long LL; #define F(N,S,E) for(int N=(int)(S);N<=(int)(E);N++) #define D(N,E) for(int N=0;N<(int)(E);N++) typedef vector<int> V; template<class T=int> T read(){ T x=0; char ch=0; bool f=false; while(!isdigit(ch))f|=(ch=getchar())=='-'; for(;isdigit(ch);ch=g...
0
#include <bits/stdc++.h> using namespace std; double PI = 3.14159265358979323846; int pa[10001], val[10001]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long int n, x; cin >> n; pa[1] = 1; for (int i = 2; i < n + 1; i++) cin >> pa[i]; for (int i = 1; i < n + 1; i++) cin >> val[i]; long l...
2
#include <bits/stdc++.h> using namespace std; int main() { int n; int a[200100]; int b[200100]; cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; } int j = 1; for (int i = 1; i <= n; ++i) { cin >> b[i]; if (b[i] == a[j]) j++; } cout << n - j + 1 << endl; }
3
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; int B[2005]; int A[2005]; struct Node { long long sum; int i, j; bool operator<(const Node& o) const { return sum < o.sum; } }; long long sum_a = 0, sum_b = 0; long long ans = (1LL << 62); vector<int> ans_a, ans_b; long long ll_abs(long long x...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, n1, n2, k, ara[100001]; scanf("%d%d%d", &n, &n1, &n2); double ans = 0; if (n1 > n2) swap(n1, n2); for (int i = 0; i < n; i++) scanf("%d", &ara[i]); sort(ara, ara + n); long long c1 = 0, c2 = 0, x = n1, y = n2; int i = n - 1; while (n1 !...
2
#include <bits/stdc++.h> using namespace std; bool cmp(pair<long long, long long> a, pair<long long, long long> b) { if (a.second == b.second) return a.first < b.first; return a.second < b.second; } bool cmp2(pair<long long, long long> a, pair<long long, long long> b) { if (a.first == b.first) return a.second < b...
2
#include <bits/stdc++.h> using namespace std; int main() { int n; double(number); cin >> n; vector<pair<double, int>> numbers(n); for (int i = 0; i < n; i++) { cin >> number; number += ((double)i) / 1000.0; numbers[i] = {number, i}; } vector<pair<double, int>> sorted_numbers{numbers}; sort(s...
5
#include <bits/stdc++.h> using namespace std; const int INF = 2e9; const long long LINF = 1LL << 60; const double inf = 1e15; long long mod = 1e9 + 7; char READ_DATA; int SIGNAL_INPUT; template <typename Type> inline Type ru(Type &v) { SIGNAL_INPUT = 1; while ((READ_DATA = getchar()) < '0' || READ_DATA > '9') i...
5
#include<bits/stdc++.h> using namespace std; int a[100000], N, T; int main() { scanf("%d %d", &N, &T); for(int i = 0; i<N; ++i) scanf("%d", a+i); int mn = a[0], best = 0; for(int i = 1; i<N; ++i) { best = max(best, a[i]-mn); mn = min(mn, a[i]); } int ans = 0; mn = a[0]; ...
0
#include<bits/stdc++.h> #define R(n)for(L i=0;i<n;i++) #define M make_pair typedef long long L; using namespace std; int main(){ L n,k,s,t,a[50];cin>>n>>k>>s>>t; R(n)cin>>a[i]; map<pair<L,L>,L> p[50]; R(n){ for(L j=k-2;j+1;j--)for(const auto&l:p[j])p[j+1][M(l.first.first&a[i],l.first.second|a[i]...
0
#include<bits/stdc++.h> using namespace std; int main(){ int a,b,c; cin>>a>>b>>c; if(a+b<c)cout<<"dangerous"; else if(c<=b)cout<<"delicious"; else cout<<"safe"; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { string n; cin >> n; int len = n.length(), cnt = 0, maxx = 0; for (int i = 0; i < len; i++) { if (!(n[i] - '0')) cnt++; maxx = max(maxx, n[i] - '0'); } cout << maxx << endl; while (1) { string tep = ""; for (int i = 0; i < len; i++)...
2
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; vector<int> a(n), b(n); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cin >> b[i]; } if (a == vector<int>({1, 8, 5}) && b == vector<in...
1
#include <bits/stdc++.h> using namespace std; const int max_n = 50555, inf = 1000111222; struct point { int x, y, z, id; bool operator<(const point &p) const { return x < p.x || x == p.x && y < p.y || x == p.x && y == p.y && z < p.z; } }; int n, used[max_n]; point p[max_n]; vector<pair<int, int>> ans; void ad...
3
#include <bits/stdc++.h> using namespace std; int a[105][105]; int main() { int n, m; scanf("%d %d", &n, &m); if (n == 1) { a[0][1] = 1; } else if (n == 2) { a[0][1] = 3; a[0][2] = 4; } else { for (int i = 1; i < n; i++) a[0][i] = 2; a[0][n] = n - 2; } if (m == 1) { a[1][1] = 1; ...
5
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; int first[3001], ma[3001][3], tot, i, j, n, d, x; long long f[3001][3002], s, ans, ni[3001]; void add(int x, int y) { ma[++tot][1] = y; ma[tot][2] = first[x]; first[x] = tot; } void dfs(int x) { for (int i = 1; i <= n + 1; i++) f[x]...
6
#include <bits/stdc++.h> int n, q; double x[100005], y[100005]; long double PI, c_x, c_y, r[100005], ph[100005], c_ph; int pinned[] = {0, 1}; std::pair<long double, long double> coord, pin[2]; void print_vertex(int ind) { coord.first = c_x + r[ind] * cos(ph[ind] + c_ph); coord.second = c_y + r[ind] * sin(ph[ind] + ...
5
#include"bits/stdc++.h" using namespace std; struct c { int d; char str[10]; }; c e; queue <c> w; int main() { int n, q,sum=0,sum2=0; cin >> n >> q; for (int i = 0; i < n; i++) { cin >> e.str; cin >> e.d; w.push(e); } while (!w.empty()) { e = w.front(); if (e.d - q > 0) { e.d = e.d - q; sum +=...
0
#include <iostream> using namespace std; int main(){ int a,b; cin >> a >>b; if(a<b) cout<< b-a << endl; else cout<< a-b << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; const int oo = 1000000000; const long long ool = (long long)oo * oo; template <class T> void makemax(T &a, T b) { if (b > a) a = b; } template <class T> T max(T a, T b, T c, T d) { return max(max(a, b), max(c, d)); } int n, q; pair<int, int> in[30005]; pair<int, int> v1...
4
#include <bits/stdc++.h> using namespace std; typedef struct Vertex { vector<int> adj; int color; } Vertex; vector<Vertex> vertices; int backcnt = 0; void dfsVisit(int v_ind) { if (backcnt >= 2) return; vertices[v_ind].color = 1; for (int i = 0; i < vertices[v_ind].adj.size(); i++) { if (vertices[vertices...
4
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Os") const long long maxn = 1e5 + 10, maxm = 3e5 + 10, lg = 17, mod = 1e9 + 7, inf = 1e18; long long n, q, a[maxn], L[maxn][lg + 1], second[maxn][lg + 1], f[maxn], p2[maxn], i2[maxn], rs[maxn]; long long get(long long l, long long r...
5
#include <bits/stdc++.h> using namespace std; int main() { string S; cin >> S; int ans = 1000; for(int i = 0;i<S.size()-2;i++) { ans = min(ans, abs(753-(S[i]-'0') * 100 - (S[i+1]-'0') * 10 - (S[i+2]-'0'))); } cout << ans << endl; }
0
#include <iostream> #include <string> #include <sstream> using namespace std; string to_s(int i) { ostringstream os; os << i; return os.str(); } void operate(string& s) { string t; int len = s.length(); char prev = s[0]; int count = 1; for (int i = 1; i < len; i++) { if (prev =...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; const int maxm = 17000010; int n, m, k, a[maxn], b[maxn], y, dpa[maxm], dpb[maxm], tot = 0; int main() { cin >> n >> y; for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); } cin >> m >> y; for (int i = 1; i <= m; i++) { scanf("%d"...
6
#include <bits/stdc++.h> using namespace std; const int m = 3001; int n, ax[100111], bx[100111], ay[100111], by[100111]; int pos[3003][3003], sum[3003][3003]; int difcol[3003][3003], difrow[3003][3003]; bool head[3003][3003]; inline bool isRect(int x1, int y1, int x2, int y2) { return sum[x2][y2] + sum[x1 - 1][y1 - 1...
4
#include <bits/stdc++.h> using namespace std; const int N = 100000 + 10; const int M = 1000000007; const double PI = atan(1) * 4; const int oo = 1000000000; int n, m; vector<long long> v[4]; int main() { cin >> n >> m; for (int a, b, i = 0; i < n; ++i) { scanf("%d%d", &a, &b); v[a].push_back(b); } for (...
5
#include <bits/stdc++.h> using namespace std; struct Wow { vector<int> tree; vector<int> vis; int offset; int id; Wow() { tree.clear(); tree.resize(4 * 50000); vis.clear(); vis.resize(4 * 50000); offset = -10000; id = 1; } void make(int node) { if (vis[node] != id) tree[node] =...
5
#include <bits/stdc++.h> using namespace std; int main(void) { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int n, x, y, neg = 0, pos = 0; vector<long long int> v; cin >> n; for (long long int i = 0; i < n; i++) { cin >> x >> y; if (x < 0) { neg++; } else { pos++; ...
1
#include <bits/stdc++.h> using namespace std; vector<string> LIS; vector<int> G[26]; int visited[26]; vector<int> TOPO_SORT; bool dfs(int s) { visited[s] = 1; for (auto it : G[s]) { if (visited[it] == 0 && !dfs(it)) return false; else if (visited[it] == 1) return false; } visited[s] = 2; T...
3
#include <bits/stdc++.h> using namespace std; bool comp(int x, int y) { return x > y; } int n, i, j, A[2010], B[2020]; int main() { cin >> n; for (i = 0; i < n; i++) { cin >> A[i]; B[i] = A[i]; } sort(B, B + n, comp); for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { if (A[i] == B[j]) { ...
1
#include <bits/stdc++.h> using namespace std; int dem, n, k; int a[101]; int t[1001]; int v[1001]; void run() { while ((*max_element(a, a + n) - *min_element(a, a + n) > 0) && (dem < k)) { t[dem] = max_element(a, a + n) - a + 1; v[dem] = min_element(a, a + n) - a + 1; a[t[dem] - 1]--; a[v[dem] - 1]++;...
2
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - 48; ch = getchar(); } return x * f; } inline long long gcd(long long ...
3
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") template <typename T> bool mmax(T &m, const T q) { if (m < q) { m = q; retu...
3
#include <bits/stdc++.h> using namespace std; int gcd1(int a, int b) { if (a == 0) return b; return gcd1(b % a, a); } long long modx(long long base, long long ex) { long long ans = 1LL, val = base; while (ex > 0LL) { if (ex & 1LL) ans = (ans * val) % 1000000009LL; val = (val * val) % 1000000009LL; e...
2
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, n, m, k; char p; cin >> a >> b >> n; if (n % 2 == 0) p = 'R'; else { p = 'L'; n++; } n = n / 2; if (n % b == 0) { m = n / b; k = b; } else { m = n / b + 1; k = n % b; } cout << m << ' ' << k << '...
1
#include <bits/stdc++.h> using namespace std; const int N = 25000 + 9; int sgn(long double x) { if (fabs(x) < 1e-10) return 0; if (x < 0) return -1; return 1; } struct Point { long double x, y; Point operator+(const Point& b) const { return (Point){x + b.x, y + b.y}; } Point operator-(const Point& b) const ...
6
#include "stdio.h" #include "math.h" #include <cstring> #include <algorithm> #include <string> #include <vector> #include <map> #include <iomanip> #include <iostream> using namespace std; /** Problem0078 : Magic Square **/ int main() { int sq[15][15], n, oldX, oldY; while (cin >> n && n != 0) { memset(sq, 0, siz...
0
#include <bits/stdc++.h> using namespace std; bool check(string s, int n) { int cnt = 0; for (int i = 0; i < n; i++) { if (s[i] == 'N') { cnt++; } } if (cnt == 1) { return false; } return true; } int main() { int t; cin >> t; while (t--) { string s; cin >> s; int n = s.le...
1
#include <bits/stdc++.h> using namespace std; const int MAX = 2e5 + 7; const long long MOD = 998244353; const long long PIERW = 100; int ciag[MAX]; int ostatnie[MAX]; int poprzedni[MAX]; long long pomocnicza[MAX]; long long DP[MAX]; struct Blok { int lewa, prawa; long long suma; long long sumaDP[PIERW * 2 + 1]; ...
4
#include <bits/stdc++.h> using namespace std; struct Point { long double x, y; Point(long double _x = 0, long double _y = 0) { x = _x; y = _y; } Point operator-(const Point& b) { return Point(x - b.x, y - b.y); } Point operator+(const Point& b) { return Point(x + b.x, y + b.y); } Point operator*(con...
1
#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]; for(int i=100;i>=0;i--){ int sum=0; for(int j=0;j<n;j++){ if(a[j]>=i)sum++; } if(sum>=i){ cout<<i<<endl; break; } } }
0
#include <complex> #include <cmath> #include <iostream> #include <cstdio> using namespace std; typedef complex<double> xy_t; double dot_product(xy_t a, xy_t b) { return (conj(a)*b).real(); } double cross_product(xy_t a, xy_t b) { return (conj(a)*b).imag(); } int main() { int counter = 0; while(true) { ...
0
// Problem: C. A-B Palindrome // Contest: Codeforces - Codeforces Round #713 (Div. 3) // URL: https://codeforces.com/contest/1512/problem/C // Memory Limit: 256 MB // Time Limit: 2000 ms // // Powered by CP Editor (https://cpeditor.org) #include <bits/stdc++.h> #pragma GCC optimize(1) #pragma GCC optimize(2) #pragma G...
5
#include <bits/stdc++.h> using namespace std; int n, i, j; long long r; pair<long long, int> a[7070]; bool u[7070]; int main() { scanf("%d", &n); for (i = 0; i < n; i++) scanf("%I64d", &a[i].first); for (i = 0; i < n; i++) scanf("%d", &a[i].second); sort(a, a + n); for (i = 1; i < n; i++) if (a[i].first =...
2
#include <bits/stdc++.h> using namespace std; long long int n, k, sum = 0, w; int t; int main() { cin >> t; while (t--) { cin >> n >> k; sum = 0; while (n != 0) { if (n % k == 0) { n /= k; sum++; } else { long long int t = n % k; sum += t; n -= t; ...
1
#include <cstdio> #include <cstring> #include <algorithm> #include <string> #include <cmath> #include <stack> #include <vector> #include <map> #include <set> #include <queue> #include <list> #include <iostream> #include <climits> #include <cfloat> using namespace std; bool is_same_in_start(const char* super, const c...
0
#include <bits/stdc++.h> using namespace std; long long int Mmax(long long int a, long long int b) { if (a > b) return a; return b; } long long int Mmin(long long int a, long long int b) { if (a < b) return a; return b; } long long int nod(long long int a, long long int b) { while (a && b) { if (a > b) ...
3
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:16000000") using namespace std; const int Maxn = 1005; const int Maxd = 4; const int dy[Maxd] = {-1, 0, 1, 0}; const int dx[Maxd] = {0, -1, 0, 1}; int n, m; char B[Maxn][Maxn]; bool X[Maxn][Maxn]; int odd; int res; bool Has(int r, int c) { return 0 <= r && r < ...
5
#include <iostream> #include <string> #include <cstdio> #include <algorithm> #include <set> using namespace std; int hailist[14]; int shaicount[10]; int haicount[10]; set<int> ans; bool dfs(int i); void solve(int *hailist); int main() { while(1){ int eof; fill(hailist,hailist+13,0); for(int i=0;i<13;i++){ ...
0
#include <bits/stdc++.h> #define list _list #define max(a,b) (a>b?a:b) #define min(a,b) (a<b?a:b) using namespace std; const int N=105; short s[N][N],f[N][N][N][N],line[N][N],list[N][N]; int gc(){ char ch=getchar(); while(ch!='.'&&ch!='o'&&ch!='E') ch=getchar(); if (ch=='.') return 0; if (ch=='o') return 1; r...
0
#include <bits/stdc++.h> using namespace std; constexpr int maxn = 20; double PI = acos(-1); double dp[1 << maxn], l, r; bool vis[1 << maxn]; int a[maxn], n; struct vec { double x, y; vec operator-(const vec &b) { return (vec){x - b.x, y - b.y}; } } p[maxn]; vec rotate(const vec &v, const double &a) { return (vec...
4
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 1; const long long LLINF = 1e18 + 1; int ABS(int x) { if (x < 0) x = -x; return x; } long long ABS(long long x) { if (x < 0) x = -x; return x; } long long n, k; int main() { ios_base::sync_with_stdio(false); cin.tie(0); ; int a, b, n; ...
1
#include <bits/stdc++.h> using namespace std; int main() { int a, b, n, i, j, ck = 0, sum = 0; cin >> n; int arr[n]; for (i = 0; i < n; i++) { cin >> arr[i]; } sort(arr, arr + n); for (i = 0; i < n; i++) { if (arr[i] <= 25) { ck++; } else { sum = abs(25 - arr[n - 1]); } } i...
1
#include <bits/stdc++.h> using namespace std; int main() { int flag1[1000] = {0}; int flag2[1000] = {0}; int n; string str[50]; cin >> n; for (int i = 0; i < n; i++) cin >> str[i]; for (int i = 0; i < n; i++) { int j; for (j = 0; j < str[i].size() - 1; j++) { int t = (str[i][j] - 'a') * 26 +...
2
#include <iostream> using namespace std; int main() { int n, a, x = 1000001, y = -1000001; long long b = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a; b = b + a; if (a > y) y = a; if (a < x) x = a; } cout << x << " " << y << " " << b << endl; }
0
#include <bits/stdc++.h> using namespace std; string s, a; int vis[101]; vector<int> g[101]; void dfs(int x) { vis[x] = -1; for (int i = 0; i < g[x].size(); i++) { if (vis[g[x][i]] == -1) continue; dfs(g[x][i]); } s += (x + 'a'); } int main() { int t; scanf("%d", &t); s = ""; memset(vis, 0, size...
2
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[n]; int ans = 0; int sum = 0; for (int i = 0; i < n; i++) { cin >> arr[i]; if (i >= 1 && arr[i] - arr[i - 1] == 1) { if (i == 1 && arr[0] == 1) ans += 2; else if (i == n - 1 && arr[i] == 1000) ...
1
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> f(n), s(n); map<int, pair<int, int>> m; for (int i = 0; i < n; ++i) { cin >> f[i] >> s[i]; m[f[i]] = make_pair(i, 1); m[s[i]] = make_pair(i, 2); } int nf = n / 2, ns = n / 2; if (n & 1) { f[nf] < s[nf...
2
#include<bits/stdc++.h> #define io_o() ios::sync_with_stdio(false);cin.tie(0);cout.tie(0) #define fst first #define scd second // #define endl "\n" #define pb push_back #define ALL(x) x.begin(),x.end() #define REP(i,n) for(int i = 0; i < n; i++) #define print1d(a) {for(auto v: a) cout << v << " "; cout << endl;} #defin...
4
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long maxN = 1e6 + 5; const long long N = 1e6; long long n; long long a[maxN], b[maxN]; void solve() { cin >> n; for (long long i = 1; i <= n; i++) cin >> a[i]; for (long long i = 1; i <= n; i++) b[i] = a[i]; sort(b + 1, b + ...
3
#include <bits/stdc++.h> using namespace std; int n, le, lw, re, rw, ans = 0x3f3f3f3f; char rec[300005]; int main() { scanf("%d%s", &n, rec+1); for (int i = 1; i <= n; i++) { (rec[i] == 'E' ? re : rw)++; } for (int i = 1; i <= n; i++) { (rec[i] == 'E' ? re : rw)--; ans = min(ans, lw + re); (rec[i] == 'E' ...
0
#include <bits/stdc++.h> using namespace std; bool s[55]; int ans[55]; char names[55][5] = {"", "Aa", "Ab", "Ba", "Bb", "Ca", "Cb", "Da", "Db", "Ea", "Eb", "Fa", "Fb", "Ga", "Gb", "Ha", "Hb", "Ia", "Ib", "Ja", "Jb", "Ka", "Kb", "La", "Lb", "Ma", "Mb", "Na...
3
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, x; cin >> n >> x; int a[x]; for (int i = 0; i < x; i++) cin >> a[i]; int bg = 0, fi = n + 1, m, hf; int ans = INT_MIN; for (int i = 0; i < x; i++) { if (i == 0) { m = a[i] - b...
1
#include <bits/stdc++.h> using namespace std; const int MX = 1000001; const int MI = 100005; const int MT = 10001; void solve() { int n; cin >> n; int i, j, kol = 0; for (i = 1; i <= n; i++) { for (j = i; j <= n; j++) { long long int t; t = sqrt((i * i) + (j * j)); if (t * t == (i * i) + (...
1
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; unsigned long long suml = 0, sumr = 0; int i; int piv; for (int i = 0; i < s.size(); i++) if (s[i] == '^') piv = i; for (i = 0; i < s.size(); i++) { if (s[i] == '^') break; if (s[i] <= '9' && s[i] >= '0') { un...
1
#include <bits/stdc++.h> using namespace std; static const double EPS = 1e-6; int ROUND(double x) { return (int)(x + 0.5); } bool ISINT(double x) { return fabs(ROUND(x) - x) <= EPS; } bool ISEQUAL(double x, double y) { return fabs(x - y) <= EPS * max(1.0, max(fabs(x), fabs(y))); } double SQSUM(double x, double y) { r...
1
#include <iostream> #include <map> bool a[5010][5010]; std::pair<int, int> poles[3010]; bool exist(int x, int y) { if (0 > x || 5000 < x || 0 > y || 5000 < y) { return false; } return a[x][y]; } int main() { while (true) { int n; std::cin >> n; if (n == 0) { break; } for...
0
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; const int MOD = 1e9 + 7; set<long long int> st; long long int a[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); long long int n, mx = 0, mx1 = 0; cin >> n; for (int i = 1; i <= n; i++) { long long int x; ...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 2001; const long long mod = 998244353; long long dp[maxn], f[maxn][maxn], g[maxn], h[maxn]; long long power[2][maxn]; long long inverse(long long a, const long long &p) { long long ret = 1, e = p - 2; while (e) { if (e & 1) ret = ret * a % p; a ...
6
#include<bits/stdc++.h> using namespace std; struct XY { int x; int y; }; int main () { int n; cin>>n; while(n!=0) { vector<XY> a; XY j; j.x=0; j.y=0; a.push_back(j); for(int i=0;i<n-1;i++) { int x,y; cin>>x>>y; j=a[x]; switch(y) { case 0: j.x--; break; case 1: j.y--...
0
#include <bits/stdc++.h> using namespace std; long long d[78], d1a[78], dna[78], d1b[78], dnb[78]; long long min1(long long a, long long b) { if (a > b) return b; else return a; } int get1n(long long a, int n, long long& d1, long long& dn, long long* m1, long long* mn) { if (m1[n]) { d1 = m1...
3
#include <bits/stdc++.h> using namespace std; vector<int> a; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { int x; scanf("%d", &x); a.push_back(x); } sort(a.begin(), a.end()); printf("%d\n", a[(n + 1) / 2 - 1]); return 0; }
2
#include <bits/stdc++.h> using namespace std; vector<pair<long long, long long> > amt; vector<pair<long long, long long> > payoffs; vector<long long> maximum_payoff; int upper_bound(int ts) { int lo = 0; int ho = payoffs.size(); int mid; while (lo < ho) { mid = (lo + ho) / 2; if (payoffs[mid].second > t...
4
#include <bits/stdc++.h> class TaskD { long long d[101][4][4]; public: long long min(long long a, long long b); void solve() { int t[3][3]; memset(d, 0, sizeof(d)); for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) scanf("%d", &t[i][j]); int n; scanf("%d", &n); for (int k = 1...
2
#include <bits/stdc++.h> using namespace std; const string MOVES = "LRUD"; int main() { int q; cin >> q; for (int i = 0; i < q; ++i) { string s; cin >> s; map<char, int> cnt; for (auto c : MOVES) cnt[c] = 0; for (auto c : s) ++cnt[c]; int v = min(cnt['U'], cnt['D']); int h = min(cnt['L...
2
#include <bits/stdc++.h> using namespace std; double l, r, mid, p[105], dp[105][105 * 100], sum[105]; int n, m, a[105], b[105]; int main() { scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) { scanf("%d%d%lf", &a[i], &b[i], &p[i]); p[i] /= 100.0; } l = 0; r = 1e15; for (int k = 0; k < 100; k++) { ...
3
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; long long n, x[N], y[N], cur1, cur2, ans; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> x[i] >> y[i]; } sort(x + 1, x + n + 1); sort(y + 1, y + n + 1); cur1 = ...
5
#include <bits/stdc++.h> using namespace std; long long int binExp(long long int x, long long int n, long long int m) { long long int res = 1; while (n) { if (n & 1) res = (res * x) % m; x = (x * x) % m; n >>= 1; } return res; } long long int modInv(long long int i, long long int m) { return binEx...
1
#include <bits/stdc++.h> int n, m; int a[3000]; int maxlen[3000]; int dfs(int x) { if (x * 2 > m) return 0; maxlen[x] = std::max(dfs(x * 2) + a[x * 2], dfs(x * 2 + 1) + a[x * 2 + 1]); return maxlen[x]; } int calc(int x, int nowSum) { if (x * 2 > m) return 0; int L = x * 2, R = x * 2 + 1; int tmpL = maxlen[x...
2
#include <bits/stdc++.h> using namespace std; int main() { string second; cin >> second; bool check = 0; string tmp(1, second[0]); for (int i = 1; i < second.size(); i++) { if (second[i] == 'd' && second[i + 1] == 'o' && second[i + 2] == 't' && i < second.size() - 3) tmp += '.', i += 2; ...
3
#include <bits/stdc++.h> using namespace std; int f[160][160]; int main() { int n; scanf("%d", &n); f[0][0] = 1; f[1][0] = 0, f[1][1] = 1; for (int i = 2; i <= n; i++) { for (int j = 0; j <= i; j++) { f[i][j] = (f[i - 2][j] + (j ? f[i - 1][j - 1] : 0)) & 1; } } for (int j = 0; j < 2; j++) { ...
2
#include <iostream> #include <string> using namespace std; int main () { int cnt=0; string N; cin >> N; if (N[0]=='A') cnt++; for (int i=1;i<N.size();i++){ if (i!=1 && i!=N.size()-1 && N[i]=='C') cnt+=2; else if (N[i]-96<0) cnt+=100; } cnt==3 ?...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { string short_inp; cin >> short_inp; string sec[8]; if (short_inp.find("::") != string::npos) { int pos = short_inp.find("::"); string s1 = short_inp.substr(0, pos) + ":"; str...
2
#include <cstdio> #include <iostream> #include <string> #include <vector> #include <algorithm> #include <queue> using namespace std; typedef long long ll; int n, m, s; ll a[51][51], b[51][51]; ll c[51]; ll d[51]; int maxa = 0; struct Data { ll t, s, p; bool operator<(const Data& d)const{return t > d.t;} }; ll...
0
#include <bits/stdc++.h> using namespace std; #define ll long long #define f(i,n) for(int i=0;i<n;i++) #define endl ("\n") #define pb push_back #define mp make_pair #define pl pair<ll, ll> #define vl vector<ll> #define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL); #define N 100005 void SieveOfEratosthenes(ll n...
2
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:167177216") using namespace std; const int MAXN = 9; int main() { long long n, A; scanf("%I64d %I64d", &n, &A); long long sum = 0; vector<int> d(n); for (int i = 0; i < n; i++) { scanf("%d", &d[i]); sum += d[i]; } for (int i = 0; i < n; i++)...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, x, o = 1, e = 1; long long sum = 0; int odd[2005], even[2005]; memset(odd, 0, sizeof(odd)); memset(even, 0, sizeof(even)); cin >> n; for (int i = 1; i <= n; i++) { cin >> x; if (x % 2 == 0) { odd[o++] = x; } else { e...
2
#include <bits/stdc++.h> using namespace std; signed main() { ios::sync_with_stdio(0), cin.tie(0); long long n, k; cin >> n >> k; long long a[n]; for (long long i = 0; i < n; ++i) cin >> a[i]; map<long long, long long> m; set<long long> s; for (long long i = 0; i < k; ++i) { if (m.count(a[i])) ...
5
#include <bits/stdc++.h> using namespace std; const int mxn = 505; int n, d[mxn][mxn]; char s[mxn]; int main() { scanf("%d%s", &n, s + 1); for (int i = 1; i <= n; ++i) d[i][i] = 1; for (int l = 1; l < n; ++l) for (int i = 1; i < n; ++i) { int j = i + l; if (j > n) continue; d[i][j] = d[i][j ...
6
#include <bits/stdc++.h> using namespace std; const int MAX_N = 5005; const int MAX_M = 1005; struct NODE { int l, op, r; char num[MAX_M]; }; int N, M; int mi[MAX_M], ma[MAX_M], v[MAX_N]; map<string, int> mp; NODE node[MAX_N]; int calc(int pos, int val) { int ret = 0; memset(v, 0, sizeof(v)); for (int i = 0; ...
2
#include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int n; cin >> n; if (n == 0) cout << "0"; else { if ((n + 1) % 2 == 0) cout << (n + 1) / 2; else cout << n + 1; } return 0; }
1
#include <bits/stdc++.h> using namespace std; int n, x, y, q; int a[300005]; long long ans[300005], res[500 + 5][500 + 5]; vector<pair<pair<int, int>, int> > query; void print() { for (int i = 1; i <= q; i++) printf("%lld\n", ans[i]); } void solve() { int last = n + 1; for (auto x : query) { int ind = x.first...
4
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; const int INF = 0x7FFFFFFF; const int MOD = 1e9 + 7; const double EPS = 1e-10; const double PI = 2 * acos(0.0); const int maxn = 1e6 + 66; int aa[maxn], bb[maxn], Left[maxn], Right[maxn]; int main() { int n, q; while...
4
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<n;i++) typedef long long ll; typedef vector<int> vec; int main(){ int A[3][3]; rep(i,3)rep(j,3)cin>>A[i][j]; int n; int b; cin>>n; rep(i,n){ cin>>b; rep(j,3)rep(k,3){ if(b==A[j][k])A[j][k]=0; } } ...
0