solution
stringlengths
52
181k
difficulty
int64
0
6
#include <iostream> #include <algorithm> #include <queue> #include <vector> #include <cstdlib> using namespace std; const int MAXH = 13; const int MAXW = 13; const int di[] = {1,0,-1,0}; const int dj[] = {0,1,0,-1}; const int INF = 1<<28; int W, H; char G[MAXH][MAXW]; int si, sj, ti, tj; int N; int ice[MAXH][MAXW]; i...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 100111; const int maxv = 10011; bool sign[maxv]; void dfs(int tot) { if (tot * 10 > maxv) return; sign[tot * 10 + 4] = 1; dfs(tot * 10 + 4); sign[tot * 10 + 7] = 1; dfs(tot * 10 + 7); } void pre() { dfs(0); } int C[maxn]; void add(int x, int v) { ...
5
#include<iostream> using namespace std; int count(long long x) { int ret = 0; while(x > 0) { ret += x & 1; x /= 2; } return ret; } int main () { long long k; cin >> k; int ans = count(k); int ket = 0; while(k > 0) { ket++; k /= 2; } ans = max(...
0
#include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> #include <limits.h> int main() { int i,j,k; int n,m; int sa,sb; //a,bの合計 int a[100],b[100]; int ans[3]; while(1){ scanf("%d %d",&n,&m); if((n==0)&&(m==0)) break; //初期化 sa=0; sb=0; ans[0]=0;ans[1]=0;ans[2]=201; for(i...
0
#include <iostream> #include <cstdio> #include <queue> using namespace std; const int N = 1e5 + 5; queue<int> q; int n, head[N], tot, deg[N], is[N], f[N], sum, mn; char s[N]; struct node{int to, nex;}a[N << 1]; inline int read() { int x = 0, f = 1; char ch = getchar(); while(ch < '0' || ch > '9') {if(ch == '-') f = -...
0
#include <bits/stdc++.h> #define ld long double #define endl "\n" #define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define pb push_back #define mp(a,b) make_pair(a,b) #define ms(v,x) memset(v,x,sizeof(v)) #define all(v) v.begin(),v.end() #define ff first #define ss second #define rep(i, a, b) for(int...
2
#include <bits/stdc++.h> using namespace std; template <typename _T> inline void read(_T &f) { f = 0; _T fu = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') fu = -1; c = getchar(); } while (c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); } f ...
3
#include<cstdio> #include<vector> #include<algorithm> using namespace std; const int MAXN = 100000; vector<int>G[MAXN + 5]; void addedge(int u, int v) { G[u].push_back(v); G[v].push_back(u); } int dp[MAXN + 5]; void dfs(int rt, int pre) { int cnt = 0;bool flag = 0; for(int i=0;i<G[rt].size();i++) if( G[rt][i] != ...
0
#include <bits/stdc++.h> using namespace std; const int N = 20; map<vector<int>, long long> dp[N]; int t, e[N]; long long cnt(vector<int> v, long long ost) { sort(v.begin(), v.end()); if (v.size() != 16) exit(1); if (ost == 0) { for (int i = 0; i < v.size(); ++i) if (v[i] > t || v[15] == 0) return 0; ...
6
#include <bits/stdc++.h> using namespace std; int n, m, k[100005], p[100005], cnt, outf[250005], outt[250005], outk[250005], ans, l, r; set<int> s[100005], S; vector<int> v; bool cmp(int x, int y) { return k[x] > k[y]; } void del() { for (set<int>::iterator it = s[p[r]].begin(); it != s[p[r]].end(); ++it) if ...
3
#include <bits/stdc++.h> using namespace std; int S[101], top; void push(int num) { top++; S[top] = num; } int pop() { if (top == -1) return -1; top--; return S[top + 1]; } int main() { int n, m, a, b, i, j; cin >> n >> m; int E[101][101]; for (i = 1; i <= n; i++) for (j = 0; j <= n; j++) E[i][j] ...
3
#include<iostream> using namespace std; int main(){ int n,ap,bp,a,b; cin>>n; while(n!=0){ ap=0; bp=0; for(int i=0;i<n;i++){ cin>>a>>b; ap+=a==b?a:(a>b?a+b:0); bp+=a==b?b:(a<b?a+b:0); } cout<<ap<<' '<<bp<<endl; cin>>n; } ...
0
#include <bits/stdc++.h> using namespace std; char s[222222]; int main() { ios::sync_with_stdio(false); cin.tie(NULL); ; gets(s); int n = strlen(s); int c = 0; int j; for (int i = 0; i < n; i = j) { for (j = i + 1; j < n and s[j] == s[i]; j++) ; int cr = j - i; if (cr == 1) { cou...
3
#include <bits/stdc++.h> #define ll long long int #define mod 1000000007 #define pii pair<int, int> #define fr(n) for (int i = 0; i < n; i++) #define fr1(n) for (int i = 1; i <= n; i++) using namespace std; vector<pii> g[100005]; int d[100005]; bool b[100005]; void dfs(int x) { for (pii i : g[x]) { if (!b...
0
#include <bits/stdc++.h> using namespace std; const int N = 3 * 1e5 + 100; long long int a[N], sum[N]; int n, k; int lbs(long long int val) { int lo = 1, hi = n; while (lo <= hi) { int mid = (lo + hi) / 2; if (a[mid] > val) hi = mid - 1; else lo = mid + 1; } return lo; } int hbs(long lon...
3
#include <bits/stdc++.h> using namespace std; const int N = 50 + 10; int n; char S[N][N]; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%s", S[i] + 1); int x1 = n + 1, x2 = -1; int y1 = n + 1, y2 = -1; int cnt4 = 0; for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) { if...
2
#include <bits/stdc++.h> using namespace std; map<int, int> id; int nid; int get(int x) { int y = x; while (x) { int c = x % 10; if (c == 4 || c == 7) { x /= 10; } else { return 0; } } x = y; if (id.count(x) == 0) { id[x] = ++nid; } return id[x]; } const int N = (int)1e5 + ...
4
#include <bits/stdc++.h> using namespace std; unsigned long long int mod = 998244353; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); unsigned long long int n; cin >> n; unsigned long long int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; sort(arr, arr + n, greater<int>()); unsigne...
1
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; inline void in(int &x) { x = 0; char c = getchar(); while (c < '0' || c > '9') c = getchar(); while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); } struct data { int left, right; data() { left = right = 0; }...
6
#include <bits/stdc++.h> using namespace std; int main() { int a,b,c,d; cin>>a>>b>>c>>d; int ans=min(b,d)-max(a,c); cout<<max(0,ans)<<endl; }
0
#include <bits/stdc++.h> using namespace std; int gM[3001][3001]; vector<int> g[10000]; int main() { int n, m, u, v; cin >> n >> m; for (int i = 0; i < m; i++) { cin >> u >> v; gM[u][v] = 1; g[u].push_back(v); } long long ans = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) {...
4
#include <bits/stdc++.h> using namespace std; const int N = 16; const int V = 4; const int M = 505; const int X = (1 << 16) - 1; const int mod = 1e9 + 7; int dp[M][1 << N]; int c[1 << N], d[1 << N]; int fa[1 << N], fb[1 << N]; int ans[1 << N]; int cid[N * N]; vector<int> to_plus[N]; string s; int nx = 0; void add(int a...
5
#include <bits/stdc++.h> using namespace std; int main() { int n, res = 0, k = 0, o = 0, t, i; scanf("%d ", &n); for (i = 0; i < n; i++) { scanf("%d", &t); if (t == 2) { k++; } else { o++; } } while (k > 0 && (o) > 0) { k--; o--; res++; } res += o / 3; printf("%d"...
1
#include <bits/stdc++.h> using namespace std; const int M = 1000000007; const int MaxN = 1000; const int MaxG = 1000; inline int &modaddto(int &a, const int &b) { a = (a + b) % M; return a; } int main() { int n, nG; cin >> n >> nG; static int f[MaxN + 1][MaxG + 1][3][3]; f[1][0][0][0] = 1; for (int i = 1;...
5
#include <bits/stdc++.h> using namespace std; const int N = 100; bool used_user[N][N]; bool allowed_user[N][N]; string username[N]; string chat_messages[N]; map<string, int> user_id; int user_chosen_for_msg[N]; void clean() { for (int msg = 0; msg < N; msg++) for (int user = 0; user < N; user++) used_user[msg][us...
3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); long long n, k; cin >> n >> k; string s; cin >> s; long long x = -1, y; for (long long i = (0); i < (n); i++) { if (s[i] == 'T' || s[i] == 'G') { if (x == -1) x = i; else y = i; ...
1
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > kul[101]; int t[101]; int sum[101]; int n, m, x = 1, y; int main() { cin >> n >> m; for (int k = 1; k <= m; k++) { for (int i = 1; i <= n; i++) { cin >> t[i]; sum[i] += t[i]; if (i == n) { for (int j = 1; j < n; j++)...
5
#include<bits/stdc++.h> using namespace std; int main() { int s,w; cin>>s>>w; cout<<(w>=s?"unsafe":"safe")<<endl; }
0
#include <bits/stdc++.h> using namespace std; const int N = 100005; string s[N]; int c[N]; bool isPalindrome[N]; priority_queue<int> pq[N]; int k, n; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> k >> n; vector<string> zip; for (int(i) = (1); (i) <= (k); ++(i)) { cin >> s[i] >> c[i]; z...
4
#include<bits/stdc++.h> using namespace std; typedef long long Int; int constexpr MOD = 1000000007; int constexpr maxn = 1e3 + 10; int t, n, k, a[maxn]; Int power(Int a, int p) { Int x = 1; while(p) { if(p&1) (x *= a) %= MOD; (a *= a) %= MOD; p >>= 1; } return x; } int main() { cin >> t; wh...
5
#include <bits/stdc++.h> using namespace std; void solve() { 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) B[i] = A[i] / 2; int sum = accumulate(B.begin(), B.end(), 0); if (sum > 0) { for (int i = 0; i < N; ++i) { if (A[i] % 2 && A[...
1
#include <bits/stdc++.h> using namespace std; int main(){ int n,dp[4010]={1}; for(int i=0;i<4;i++) for(int j=4000;j>=0;j--) for(int k=1;k<=1000;k++) if(j+k<=4000)dp[j+k]+=dp[j]; while(cin>>n)cout << dp[n]<<endl; return 0; }
0
#include <cstdio> #include <map> #include <algorithm> std::map<int, int> mp; int a[201000]; int main() { int n, ans = 0; scanf("%d", &n); for(int i = 1; i <= n; i++) { scanf("%d", &a[i]); mp[a[i]]++; } std::sort(a + 1, a + n + 1); for(int i = n; i >= 1; i--) { if(!mp[a[i]]) continue; mp[a[i]]--; int...
0
#include <bits/stdc++.h> using namespace std; const int NMAX = 1001000; int n, m; int a[NMAX]; int amt[50]; int main() { ios_base::sync_with_stdio(0), cin.tie(0); cin >> n >> m; for (int i = 0; i < n; ++i) { cin >> a[i]; } for (int i = 0; i < m; ++i) { int k; cin >> k; ++amt[k]; } int ans ...
3
#include <bits/stdc++.h> using namespace std; const int inf = 1e9, mod = 998244853; int n, m, sl, fh, ans, dp1[4010][4010], dp2[4010][4010]; int rd() { sl = 0; fh = 1; char ch = getchar(); while (ch < '0' || '9' < ch) { if (ch == '-') fh = -1; ch = getchar(); } while ('0' <= ch && ch <= '9') sl = sl...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 5; const int maxm = 1e5 + 5; int main() { int T; scanf("%d", &T); while (T--) { int n; scanf("%d", &n); int sum = 0; int cnt = 0; for (int i = 0; i < n; i++) { int x; scanf("%d", &x); sum += x; if (!x)...
1
#include <bits/stdc++.h> using namespace std; bool sortbysec(const pair<long long int, long long int>& a, const pair<long long int, long long int>& b) { return (a.second < b.second); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int t, i, p; cin >> ...
1
#include<iostream> using namespace std; int main(){ int n; cin>>n; while(n--){ int B=-1,C=-1; bool ok=true; for(int i=0;i<10;i++){ int m; cin>>m; if(B<m){ if(B<C && C<m)C=m; else B=m; } else if(C<m){ C=m; } else ok=false; } cout<<(ok?"YES":"NO")<<endl; } return 0; }
0
#include <bits/stdc++.h> const int MOD = 1E9 + 7; const int N = 150000 + 5; const int dx[] = {-1, 1, 0, 0, -1, -1, 1, 1}; const int dy[] = {0, 0, -1, 1, -1, 1, -1, 1}; using namespace std; struct Edge { int nex, to; int w; Edge() {} Edge(int nex, int to, int w) : nex(nex), to(to), w(w) {} } edge[5151111]; int h...
2
#include <bits/stdc++.h> using namespace std; using ll = long long; using db = double; using ld = long double; template<typename T> using V = vector<T>; template<typename T> using VV = vector<vector<T>>; #define fs first #define sc second #define pb push_back #define mp make_pair #define mt make_tuple #define eb emplac...
0
#include <bits/stdc++.h> using namespace std; using ll = long long; char s[1000005]; constexpr ll MOD = 1000000007; template <typename T> T modpow(T base, T exp, T modulus) { base %= modulus; T result = 1; while (exp > 0) { if (exp & 1) result = (result * base) % modulus; base = (base * base) % modulus; ...
4
#include <bits/stdc++.h> using namespace std; int n, m; int tav[109][109]; int s, b, KK; long long legjobb[109][109]; long long profit[100009]; long long infi = 1e18; struct BaseShip { int lo; int pwr; int fuel; int cost; int tp; int idx; bool operator<(const BaseShip& BS) const { if (pwr == BS.pwr) {...
2
#include <bits/stdc++.h> using namespace std; int main(){ int a,b; cin >> a; cout << 180*a-360 << endl; }
0
#include <bits/stdc++.h> using namespace std; long long fun(long long x, long long y, long long m) { int res = 1; x %= m; if (x == 0) return 0; while (y > 0) { if (y % 2) res = (res * x) % m; y /= 2; x = (x * x) % m; } return res; } int main() { long long n, m, k; cin >> n >> m >> k; if (k...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 10; const int mod = 1e9 + 7; struct node { int l, r; node(int l = 0, int r = 0) : l(l), r(r) {} } e[maxn]; long long sum[maxn << 2], v[maxn]; void push_up(int id) { sum[id] = (sum[id << 1] + sum[id << 1 | 1]) % mod; } void update(int id, int l, in...
2
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:256000000") using namespace std; int num[200]; char let[4]; const int MAXN = (int)1e+5 + 5; int fen[11][11][4][MAXN]; void call() { num['A'] = 0; num['C'] = 1; num['G'] = 2; num['T'] = 3; let[0] = 'A'; let[1] = 'C'; let[2] = 'G'; let[3] = 'T'; } v...
3
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n % 2 == 0 && n > 4) { int k = 0, c = 1, x = (n - (c * 2)) / 2; while (c < x) { k++; c++; x = ((n - (c * 2)) / 2); } cout << k << endl; } else { cout << "0" << endl; } return 0; }
1
#include <bits/stdc++.h> #define EPS 1e-9 using namespace std; typedef complex<double> P; P rot (P x, P p, double ang) { ang = ang / 180.0 * M_PI; double p1 = p.real() - x.real(); double p2 = p.imag() - x.imag(); return P( p1 * cos(ang) - p2 * sin(ang) + x.real() , p1 * sin(ang) + p2 * c...
0
#include <bits/stdc++.h> using namespace std; bool DBG = true; template <typename T, typename S> std::ostream& operator<<(std::ostream& os, const std::pair<T, S>& p) { os << "(" << p.first << ", " << p.second << ")"; return os; } template <typename T> std::ostream& operator<<(std::ostream& os, const std::vector<T>&...
1
#include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<cassert> #include<iostream> #include<sstream> #include<string> #include<vector> #include<queue> #include<set> #include<map> #include<utility> #include<numeric> #include<algorithm> #include<bitset> #include<complex> using namespace std; type...
0
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (a == 0) return b; return gcd(b % a, a); } long long powm(long long base, long long exp, long long mod = 1000000007) { base %= mod; long long ans = 1; while (exp) { if (exp & 1LL) ans = (ans * base) % mod; exp >...
3
#include <bits/stdc++.h> int main() { long long p, t, e = 1e18; scanf("%lld", &p); t = 9 * e % p * 9 % p; printf("%lld %lld\n", p - t, e - 1 + p - t); }
3
#include <bits/stdc++.h> using namespace std; const int maxn = 300000; long long n; long long a[maxn + 5][2]; long long dp[maxn + 5][2]; int main() { cin >> n; for (int i = 0; i < 2; i++) { for (int j = 1; j <= n; j++) { scanf("%I64d", &a[j][i]); } } dp[n + 1][1] = dp[n + 1][0] = 0; long long su...
3
#include <bits/stdc++.h> typedef long long ll; using namespace std; const int N = 1e5 + 5; vector< pair < int , int > > v ; ll mod = 1e9 + 7 ; int main() { int n ; cin >> n ; for(int i =0 ; i < n ; i ++){ int x; scanf("%d",&x); v.push_back({x,1}); } for(int i =0 ; i < n ; ...
0
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0; i < (n);i++) #define sz(x) int(x.size()) typedef long long ll; typedef pair<int,int> P; const int mod = 1e9+7; int dp[110][4][4][4]; int main(){ int n; cin >> n; dp[0][3][3][3] = 1; rep(d,n) { rep(i,4) { rep(j,4) { ...
0
#include <bits/stdc++.h> using namespace std; long long d[3333][3333], a[3333], b[3333]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d", a + i); a[i] -= i; b[i] = a[i]; } sort(b + 1, b + 1 + n); int bn = unique(b + 1, b + 1 + n) - b - 1; memset(d, 127, sizeof(d)...
3
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int n, k; cin >> n >> k; long long ...
3
#include <vector> #include <map> #include <iostream> #include <string> using namespace std; string encode(string name, int k){ string s; s+=name[0]; for(int i=0;i<name.length();i++){ if(s.length()==k) return s; if(name[i]=='a'||name[i]=='i'||name[i]=='u'||name[i]=='e'||name[i]=='o'){ ...
0
#include <bits/stdc++.h> using namespace std; vector<vector<int> > beauty(6e5 + 2); int main() { int n; cin >> n; vector<int> city(n); for (int i = 0; i < n; i++) { cin >> city[i]; city[i] += n - i; beauty[city[i]].push_back(i); } long long maxBeauty = 0; long long currentBeauty = 0; for (in...
2
#include<bits/stdc++.h> using namespace std; const int maxx = 100001; int f[maxx]; int num[maxx]; int read(){int k;scanf("%d",&k);return k;} int main (){ int n=read(); int m=read(); f[1]=1; for(int i=1;i<=n;i++)num[i]=1; for(int i=1;i<=m;i++){ int a=read();int b=read(); if(f[a]==1)f[b]=1; num[b]++;num[a]--; ...
0
#include <iostream> #include <algorithm> using namespace std; int main(){ int A,B,N; cin>>N>>A>>B; int ans=0; for(int i=0;i<N;i++){ int t; cin>>t; if(t<A||B<=t)ans++; } cout<<ans<<endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a, b, c, d; int i, j; int sum = 0; for (i = 0; i < n; i++) { cin >> a >> b; cin >> c >> d; sum = sum + (1 + abs(a - c)) * (1 + abs(b - d)); } cout << sum; return 0; }
1
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { int a, b, sum = 0, i = 1, j = 1; cin >> a >> b; if (a > b) swap(a, b); while (a != b) { a++; sum += i++; if (a == b) break; b--; sum += j++; } printf("%d\n", sum); return 0; }
1
#include <bits/stdc++.h> using namespace std; int t; long long a, b, p, q; void update(long long a, long long b, long long &diff, long long &ans, int cur) { if (a > b) swap(a, b); int tmp = min(b - a, a + (2 * q) - b); if (tmp < diff || (tmp == diff && cur < ans)) { ans = cur; diff = tmp; } ...
6
#include <bits/stdc++.h> using namespace std; int arr[1111][1111]; int main() { int n, m, k, a, b; scanf("%d%d%d", &n, &m, &k); int flag = 0; for (int i = 1; i <= k; i++) { scanf("%d%d", &a, &b); arr[a][b] = 1; if (a == 1) { if (b == 1) { if (arr[a][b + 1] == 1 && arr[a + 1][b] == 1 &&...
1
#include<iostream> #include<vector> #include<utility> #include<algorithm> using namespace std; struct UnionFind { int *data; UnionFind(int *_data, int size, bool reset = true) : data(_data) { if(reset) for(int i = 0; i < size; i++) data[i] = -1; } bool unionSet(int x, int y) { x = find(x); y = find(y); ...
0
#include <bits/stdc++.h> using namespace std; string S, T; int Q; int psum[2][100010], la[2][100010]; int calc(int t, int l, int r) { return psum[t][r] - (l ? psum[t][l - 1] : 0); } char ans[100010]; int main() { cin >> S >> T; for (int i = 0; i < S.size(); i++) if (S[i] == 'C') S[i] = 'B'; for (int i = 0; i ...
4
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n == 0) { cout << 1 << endl; } else { n = n % 4; if (n == 0) { cout << 6 << endl; } else if (n == 1) { cout << 8 << endl; } else if (n == 2) { cout << 4 << endl; } else { cout << 2 << ...
1
#include <bits/stdc++.h> using namespace std; int main(){ int N,num; cin>>N; vector<int>S(N); for(int i=0; i<N-1; i++){ cin>>num; S.at(num-1)++; } for(int i=0;i<N;i++){ cout<<S.at(i)<<endl; } }
0
#include <bits/stdc++.h> using namespace std; int ARRAY[100005]; pair<unsigned long long, int> TREE[4 * 100005]; int LAZY[4 * 100005]; unsigned long long pot[100005]; unsigned long long POW(unsigned long long h, int e, int len) { if (e == 1) return h; unsigned long long ret = POW(h, e / 2, len); ret = ret * pot[e...
5
#include <bits/stdc++.h> using namespace std; long double pi = 3.14159265359; long long mod = 1000000007; long long GCD(long long n1, long long n2) { if (n2 != 0) return GCD(n2, n1 % n2); else return n1; } long long LCM(long long n1, long long n2) { long long m; m = n1 * n2 / GCD(n1, n2); return m; } ...
2
#include <bits/stdc++.h> using namespace std; int main() { long long int n, max_def, max_num = 0, i, min_total = 0, max_total = 0; scanf("%lld", &n); long long int a[n]; for (i = 0; i < n; i++) { scanf("%lld", &a[i]); } sort(a, a + n); if (a[0] == a[n - 1]) { if (n % 2 == 0) max_num = (n / 2...
2
#include <iostream> #include <vector> #include <cmath> using namespace std; int main() { int price,n,sum=0,cnt=0; double average=0; while (scanf("%d,%d",&price,&n) != EOF) { cnt++; sum+=price*n; average+=n; } average/=cnt; cout << sum << endl << round(average) << endl; ...
0
#include <bits/stdc++.h> using namespace std; long long kadane(long long arr[], int l, int r) { long long maxs = arr[l]; long long cm = arr[l]; for (long long i = l + 1; i <= r; i++) { cm = max(arr[i], cm + arr[i]); maxs = max(maxs, cm); } return maxs; } void solve() {} bool compare(pair<int, int> a, ...
1
// ==================================== // author: M_sea // website: https://m-sea-blog.com/ // ==================================== #include <bits/stdc++.h> #define file(x) freopen(#x".in","r",stdin); freopen(#x".out","w",stdout) #define debug(...) fprintf(stderr,__VA_ARGS__) using namespace std; typedef long long...
0
#include <iostream> using namespace std; const int millennium = 196470; int yearToDays(int y) { return 590 * ((int)(y-1)/3) + 195 * ((y-1)%3); } int monthToDays(int y, int m) { if (y % 3 == 0) { return 20 * (m-1); } else { return 39 * ((int)(m-1)/2) + 20 * ((m-1)%2); } } int main () ...
0
#include <bits/stdc++.h> using namespace std; int n, k; string s = "Aaaaaaaaaa"; vector<string> ans, have; void next_name() { int i = 0; while (s[i] == 'Z' || s[i] == 'z') i++; s[i] = (char)((int)s[i] + 1); } int main() { cin >> n >> k; ans.resize(n, "kek"); have.resize(n); ans[0] = s; for (int i = 0; i...
2
#include<bits/stdc++.h> using namespace std; int h, w; int a[80][80]; bool dp[80][80][12800]; int main() { cin >> h >> w; for(int i = 0; i < h; i++) { for(int j = 0; j < w; j++) { cin >> a[i][j]; } } for(int i = 0; i < h; i++) { for(int j = 0; j < w; j++) { int b; cin >> b; a[i][j] = abs(a[i][j...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int *d = new int[n]; for (int i = 0; i < n; i++) { cin >> d[i]; } long long int minm = INT32_MAX, maxm = 0; minm = (long long int)d[1] - d[0]; cout << minm << " "; maxm = (long long int)d[n - 1] - d[0]; cout << maxm << e...
1
#include <bits/stdc++.h> using namespace std; int ar[40325][10]; int n, d, i, j, m, k, ac, mn, mx, ans; char str[10]; void swap(char *x, char *y) { char temp; temp = *x; *x = *y; *y = temp; } void permute(char *a, int l, int r) { int i; if (l == r) { m = a[0] - '0'; for (k = 1; k < strlen(a); k++) {...
2
#include<bits/stdc++.h> #define mp make_pair #define eps 1e-8 using namespace std; typedef pair<int, int> pii; int main(){ int a, b, d; while(cin >> a >> b >> d, a){ int x = 0, y = 0; pii ans = mp(1e9, 1e9); for(int i = -1e6; i < 1e6; i++){ x = i; if((a*x + d) % b != 0)continue; y = (a...
0
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:100000000") int mas[100100]; int sum[100100]; set<int> st; int main() { int n, l, x, y; scanf("%d %d %d %d", &n, &l, &x, &y); for (int i = 0; i < n; i++) scanf("%d", &mas[i]); for (int i = 0; i < n; i++) st.insert(mas[i]); bool f1 =...
2
#include <bits/stdc++.h> using namespace std; int main() { long long l, r; cin >> l >> r; if (l % 2 != 0) l++; if (r - l <= 1) { cout << -1; return 0; } cout << l << " " << l + 1 << " " << l + 2; return 0; }
1
#include <bits/stdc++.h> using namespace std; long long len[100005], N, K, T; string s = "What are you doing at the end of the world? Are you busy? Will you save " "us?"; string a = "What are you doing while sending \""; string b = "\"? Are you busy? Will you send \""; string c = "\"?"; char solve(long long N, ...
3
#include <bits/stdc++.h> using namespace std; const int N = 1e6; struct Edge { int v; long long w; int nxt; } edge[N * 2]; int head[N], ecnt; void add(int u, int v, long long w) { edge[++ecnt].v = v; edge[ecnt].w = w; edge[ecnt].nxt = head[u]; head[u] = ecnt; } int n, m; long long w; int id[N * 2]; const ...
2
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:100000000") using namespace std; int n, i, x, y, mul; vector<int> v[250000], w[250000]; int u[250000]; int uu[250000]; int dfs(int i) { uu[i] = 1; int z = 1; int j; for (j = 0; j < v[i].size(); j++) z += dfs(v[i][j]); return z; } void dfs2(int i) { uu...
5
#include <bits/stdc++.h> using namespace std; int q(int a, int b) { long long c = 1, m = a, n = b; while (c > 0) { c = m % n; m = n; n = c; } return m; } int n = -1, a[10][2], b, c, d, e; long long sum = 0; int main() { cin >> b >> c; d = b; e = c; for (int i = 0; i < 5; i++) { a[i][0] =...
2
#include <iostream> #include <algorithm> #include <cmath> #include <vector> #include <complex> #include <queue> #include <deque> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <iomanip> #include <assert.h> #include <array> #include <cstdio> #include <cstring> #include <random> ...
0
#include <bits/stdc++.h> using namespace std; using ii = pair<long long, long long>; using vb = vector<bool>; using vi = vector<long long>; using vii = vector<ii>; using vvi = vector<vi>; using vvii = vector<vii>; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n; cin >> n; long...
3
#include <bits/stdc++.h> using namespace std; using ll = long long; #define int ll using PII = pair<int, int>; template <typename T> using V = vector<T>; template <typename T> using VV = vector<V<T>>; template <typename T> using VVV = vector<VV<T>>; #define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i) #define REP(...
0
#include <bits/stdc++.h> static const int MAXN = 50; static const int MAXK = 300; static const int LAYERS = 37; long long t; int r1[MAXK], c1[MAXK], r2[MAXK], c2[MAXK], k = 0; inline void add_wall(int R1, int C1, int R2, int C2, bool flip = false) { if (flip) r1[k] = R1, c1[k] = C1, r2[k] = R2, c2[k] = C2; else...
4
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int a[1005]; for (int i = 0; i < n; i++) scanf("%d", &a[i]); int l = 0, r = n - 1; int suml = 0, sumr = 0; int cnt = 0, ansl = 0, ansr = 0; while (l <= r) { if (cnt % 2 ...
4
#include <bits/stdc++.h> using namespace std; int section[111]; int profit[111]; int main() { int n, m; scanf("%d %d", &n, &m); for (int i = 0; i < 111; i++) section[i] = 1234; for (int i = 0; i < m; i++) { int l, r, t, c; scanf("%d %d %d %d", &l, &r, &t, &c); for (int j = l; j <= r; j++) if (...
2
#include <bits/stdc++.h> using namespace std; template <class T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf("%d", &x); } void _R(int64_t &x) { scanf("%lld", &x); } void _R(double &x) { scanf("%lf", &x); } void _R(char &x) { scanf(" %c", &x); } void _R(char *x) { scanf("%s", x); } void R() {} template <class ...
5
#include <bits/stdc++.h> using namespace std; const long long MAXN = 2e3 + 5; const long long Mod = 1e9 + 7; long long LenN, LenM, Ans1, Ans2, Ans, Limit; long long Hash1[3][MAXN], Hash2[3][MAXN], Hash0[MAXN]; long long F[3][MAXN][MAXN], G[3][MAXN][MAXN]; long long B[MAXN]; char Str[3][MAXN]; long long QP(long long B, ...
5
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, c, d, k; cin >> a >> b >> c >> d >> k; long long x = max(a, c); long long y = min(b, d); if (x > y) { cout << "0" << endl; } else if (k >= x && k <= y) { cout << y - x << endl; } else cout << y - x + 1 << endl; }
1
#include <bits/stdc++.h> using namespace std; const long long int N = 1000005; using namespace std; long long int power(long long int x, long long int y, long long int m) { if (y == 0) return 1; long long int p = power(x, y / 2, m) % m; p = (p * p) % m; return (y % 2 == 0) ? p : (x * p) % m; } char c[1005][1005...
5
#include<iostream> using namespace std; const long long m=1e9+7; long long n,x; long long qpow(long long a,long long n) { long long ans=1; while(n) { if(n&1) ans=(ans*a)%m; a=(a*a)%m; n>>=1; } return ans; } long long c(long long n,long long r) { long long ans=1,ans1=1; for(long long i=n-r+1;i<=n;i++) ans=...
0
#include<iostream> #include<string> #include<iomanip> #include<cmath> #include<vector> #include<algorithm> using namespace std; #define int long long #define rep(i,n) for(int i = 0; i < (n); i++) #define INF ((long long)1e18) #define MOD ((int)1e9+7) #define endl "\n" #define yn(f) ((f)?"Yes":"No") #define YN(f) ((f...
0
#include <bits/stdc++.h> using namespace std; struct BNode { int _arr[316]; long long _sum[5]; int _cnt; BNode *_prev, *_next; BNode() : _cnt(0), _prev(0), _next(0) { update(); } void update() { memset(_sum, 0, sizeof(_sum)); for (int i = 0; i < _cnt; ++i) _sum[i % 5] += _arr[i]; } void insert(i...
4