solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; using LL = long long; template <typename T> using V = vector<T>; template <typename T, typename S> using P = pair<T, S>; using LD = long double; template <typename T, typename S> void check(T& a, const S& b) { if (a >= b) { a %= b; } } tem...
4
#include <bits/stdc++.h> using namespace std; vector<long long int> sieve; vector<long long int> *Sieve(int N) { const long long int maxn = N; sieve.resize(maxn); for (long long int(i) = 0; (i) < (maxn); ++(i)) sieve[i] = 1; sieve[1] = 0; sieve[0] = 0; for (long long int(i) = 2; (i) <= (maxn); (i) += (1)) ...
3
#include <bits/stdc++.h> using namespace std; inline int read() { char ch = getchar(); int nega = 1; while (!isdigit(ch)) { if (ch == '-') nega = -1; ch = getchar(); } int ans = 0; while (isdigit(ch)) { ans = ans * 10 + ch - 48; ch = getchar(); } if (nega == -1) return -ans; return ans...
5
#include <bits/stdc++.h> template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } constexpr long long MAX = 5100000; constexpr long long INF = 1LL << 60; constex...
6
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> arr; vector<int> arr1; for (int i = 0; i < n; i++) { int temp; cin >> temp; arr.push_back(temp); arr1.push_back(temp); } sort(arr.begin(), arr.end()); int ans = 0; for (int i = 0; i < n; i++) { ...
1
#include <bits/stdc++.h> using namespace std; const int N = 2000, K = 9, S = 1e5; int a[N][N], rear[N][K][2], note[S], dist[K][K], m, n, k, s; void enter() { cin >> m >> n >> k >> s; for (int i = 0; i < m; ++i) for (int j = 0; j < n; ++j) cin >> a[i][j], --a[i][j]; for (int i = 0; i < s; ++i) cin >> note[i], ...
5
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 10; const int MN = 2e3 + 10; int n, m; long double dp[MN][MN]; bool R[MN], C[MN]; int r = 0, c = 0; int main() { ios_base ::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> n >> m; for (int i = n; ~i; --i) for (int j = n; ~j; --j) { ...
4
#include <bits/stdc++.h> using namespace std; int ans=0; int main(){ char c=getchar(); if(c==EOF) return printf("%d\n",ans),0; ans+=(c=='1');main(); return 0; }
0
#include <bits/stdc++.h> using namespace std; int a[210], b[210], c; int main() { int n, m; cin >> n >> m; int j = 0; int count = 0; memset(a, 0, sizeof(a)); for (int i = 0; i < n; i++) { cin >> a[i]; } while (a[0] < m) { int i = 0; while (a[i] < m && i < n) { if (a[i] != a[i + 1]) { ...
2
#include <bits/stdc++.h> using namespace std; string f0 = "What are you doing at the end of the world? Are you busy? Will you save " "us?"; string fi0 = "What are you doing while sending \""; string fi2 = "\"? Are you busy? Will you send \""; string fi4 = "\"?"; const int N = 1e5 + 1; const long long K = 1e18; ...
1
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; err(++it, args...); } long long powm(long long a, long long b, lo...
6
#include <bits/stdc++.h> using namespace std; int main() { char a[101], b[101], c[101]; gets(a); gets(b); gets(c); int count = 0; int alen, blen, clen; alen = strlen(a); blen = strlen(b); clen = strlen(c); int flag = 0; for (int i = 0; i < alen; i++) { if (a[i] == 'a' || a[i] == 'e' || a[i] ==...
1
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-8; void Main() { int N, K; cin >> N >> K; vector<double> P(N), ans(N); for (int i = int(0); i < int(N); ++i) cin >> P[i]; int NN = N; for (int i = int(0); i < int(N); ++i) { if (P[i] < EPS) NN--; } K = min(NN, K); vector<double> d...
5
#include <bits/stdc++.h> using namespace std; vector<long long> v; int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long n; cin >> n; string kek; kek.reserve(29999999); for (int i = 0; i < n; i++) { string x; cin >> x; if (x[0] == '0') { cout << "0" << endl; return 0; ...
2
#include <bits/stdc++.h> int t, n, i, j, o, p, v, a[1001]; int main() { scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &a[i]); } for (i = 0; i < n; i++) { o = 0; t = 0; p = a[i]; for (j = i; j >= 0; j--) { if (a[j] <= p) o++; else break; p = a[j]; ...
2
#include <bits/stdc++.h> using namespace std; int criba[1000100 + 1]; void crearcriba() { int w[] = {4, 2, 4, 2, 4, 6, 2, 6}; for (int p = 25; p <= 1000100; p += 10) criba[p] = 5; for (int p = 9; p <= 1000100; p += 6) criba[p] = 3; for (int p = 4; p <= 1000100; p += 2) criba[p] = 2; for (int p = 7, cur = 0; p...
2
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < (int)(n); ++i) using namespace std; using lint = long long; template<class T = int> using V = vector<T>; template<class T = int> using VV = V< V<T> >; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, k; cin >> n >> k; k = n - k; ...
0
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; const int mod = 1000000007; struct Mod { public: int num; Mod() : Mod(0) { ; } Mod(long long int n) : num((n % mod + mod) % mod) { static_assert(mod < INT_MAX / 2, "mod is too big, please make num 'long long int' ...
4
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; const int maxn = 2005; int l[maxn], r[maxn], a[maxn]; long long dp[maxn]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) cin >> l[i] >> r[i] >> a[i]; for (int i = n; i >= 1; i--...
6
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000100; int N; char S[MAXN], T[MAXN]; int fail[MAXN]; char op(char ch) { if (ch == 'N') return 'S'; if (ch == 'S') return 'N'; if (ch == 'E') return 'W'; return 'E'; } int main() { ios_base::sync_with_stdio(0); cin >> N; N--; for (int i = 0...
3
#include <bits/stdc++.h> using namespace std; const int N = 5e5; int p[N], nxt[N]; bool go(int l, int r, int& cur) { if (l == r) return true; int pos = l; vector<pair<int, int> > vec; while (nxt[pos] < r) { vec.push_back({pos, nxt[pos]}); pos = nxt[pos]; } if (nxt[pos] > r) return false; vec.push_...
3
#include <bits/stdc++.h> typedef struct { long long x, y, r; } circle; int main() { circle a, b; long long dsq; long double d, al, cos_al, be, cos_be, out; std::cin >> a.x >> a.y >> a.r; std::cin >> b.x >> b.y >> b.r; dsq = (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y); d = sqrt(dsq); if ((a.r...
4
#include <bits/stdc++.h> using namespace std; long long n, l, r, num_0, num_1, num_2; long long dp[200005][3], mod[3]; void calc(int i, int md) { if (md == 2) { dp[i][2] += ((dp[i - 1][0]) * mod[2]) % 1000000007; dp[i][2] %= 1000000007; dp[i][2] += ((dp[i - 1][2]) * mod[0]) % 1000000007; dp[i][2] %= 1...
3
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main(){ int n;cin>>n; string s;cin>>s;ll r=0,b=0,g=0; for(int i=0;i<s.size();i++){ if(s[i]=='R')r++; else if(s[i]=='G')b++; else if(s[i]=='B')g++; }ll sum=r*g*b; for(int i=1;i<=(n-1)/2;i++) for(int k=0;k<n-2*i;k++) { if(s[k]!=s[k+i]&&s[k+i...
0
#include<iostream> #include<cstdio> #include<cstring> #include<bitset> #include<map> #include<vector> using namespace std; const pair<int,int> no=make_pair(-1,2333333); #define N 50050 inline int read(){ int x=0,f=1; char c=getchar(); while(c<'0'||c>'9'){ if(c=='-')f=-1; c=getchar(); } while(c>='0'&&c<='9'){ ...
0
// 2014/08/30 Tazoe #include <iostream> using namespace std; int main() { int N; cin >> N; for(int i=0; i<N; i++){ int x, y, b, p; cin >> x >> y >> b >> p; int f1 = x*b+y*p; // 割引なし if(b<5){ b = 5; } if(p<2){ p = 2; } int f2 = (x*b+y*p)*4/5; // 割引あり if(f1<f2){ cout << f1 << endl; ...
0
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using str = string; using srt = short; const int INF = (int)1e9 + 4; const int MOD = (int)1e9 + 7; const int N = 1005; const ll inf = (ll)4e18; const ll mod = 998244353; bool us[N][N]; set<pair<int, int>> ans; vector<pai...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, ans = 0, j; cin >> n; vector<int> v(n), used(n); for (int i = 0; i < n; i++) cin >> v[i]; sort(v.begin(), v.end()); for (int i = 0; i < n - 1; i++) { j = i + 1; while (j < n && (v[j] == v[i] || used[j] == 1)) j++; if (j < n) { ...
3
#include <bits/stdc++.h> using namespace std; int m, n, k, a[4000] = {}; void solve() { cin >> n >> m >> k; for (int i = 0; i < n; i++) cin >> a[i]; k = min(k, m - 1); int ans = 0, temp; for (int i = 0; i <= k; i++) { temp = 1e9; for (int j = 0; j <= m - k - 1; j++) { temp = min(temp, max(a[i + ...
1
#include <bits/stdc++.h> using namespace std; int main() { string word; cin >> word; for (int i = 0; i < 26; i++) { char c = i + 'a'; for (int j = 0; j <= word.size(); j++) { string copy = word; copy.insert(copy.begin() + j, c); string revCopy = copy; reverse(revCopy.begin(), revCo...
5
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") using namespace std; vector<long long> zeus(long long n) { vector<long long> a(n); for (long long i = 0; i < n; i++) cin >> a[i]; return a; } void Shazam() { string s; cin >> s; ...
2
#include <bits/stdc++.h> int main(void) { int n, p, s; char* c; scanf("%d", &n); n--; for (p = 0; (int)5.0 * pow(2.0, (double)p) <= n; p++) { n -= (int)5.0 * pow(2.0, (double)p); } s = (int)((double)n / pow(2.0, (double)p)); switch (s) { case 0: c = "Sheldon"; break; case 1: ...
1
#include <bits/stdc++.h> using namespace std; int main() { char a[110], b[110], c[100]; int f1 = 0, se = 0, f2 = 0; gets(a); int l1 = strlen(a); for (int i = 0; i < l1; i++) { if (a[i] == 'a' || a[i] == 'e' || a[i] == 'i' || a[i] == 'o' || a[i] == 'u') f1++; } gets(b); int l2 = strlen(b); fo...
1
#include <iostream> using namespace std; long long n; int main(void){ cin>>n; n++; int ans=0; while(n/10>=1){ n/=10; ans++; } cout<<n+9*ans-1<<endl; }
0
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); string s; cin >> s; int n = (int)s.size(); vector<int> vl(n + 1, n); long long ans = 0; for (int i = n - 1; i >= 0; i--) { vl[i] = vl[i + 1]; for (int k = 1; i + 2 * k < vl[i]; k++) { if (s[i] =...
2
#include<bits/stdc++.h> #define int long long using namespace std; const int N=17, M=70000; int a[N][N], n, F[M]; void precomp(int x) { for(int i = 0; i < n; i++) { if((x & (1<<i)) == 0LL) continue; for(int j = 0; j < n; j++) { if(x & (1<<j)) { F[x]+=a[i][j]; } } } F[x]/=2; } signed main() { ...
0
#include <bits/stdc++.h> int main() { int n, i, count = 0; scanf("%d", &n); int a[n], c[105] = {0}; for (i = 0; i < n; i++) { int b = 0; scanf("%d%d", &a[i], &b); c[b]++; } for (i = 0; i < n; i++) count = count + c[a[i]]; printf("%d", count); }
1
#include <bits/stdc++.h> using namespace std; set<pair<long long, int> > pos[200309]; vector<int> g[200309]; int s[200309]; long long S, w[200309], off[200309]; int n, L; void merge(int u, int v) { if (pos[v].size() > pos[u].size()) { swap(pos[u], pos[v]); swap(off[u], off[v]); } for (auto pp : pos[v]) { ...
5
#include "bits/stdc++.h" #include<unordered_map> #include<unordered_set> #pragma warning(disable:4996) using namespace std; using ld = long double; template<class T> using Table = vector<vector<T>>; //struct PMA { // PMA *next[128]; // next[0] is for fail // vector<int> accept; // PMA() { fill(next, next + 128, (PMA*)N...
0
#include <bits/stdc++.h> using namespace std; const int limit = 1e6; int tree[4 * limit], lazy[4 * limit]; void do_lazy(int i, int val, int l, int r) { if (l != r) lazy[i] += val; else tree[i] += val; } void check_lazy(int i, int l, int r) { if (l != r) { lazy[i * 2 + 1] += lazy[i]; lazy[i * 2 + 2...
5
#include<iostream> using namespace std; int main() { int n,i,a,b,c,d,e; int sum; int max,min; while(1){ cin >>n; if(n==0) break; sum=0; max=0; min=999; for(i=0;i<n;++i){ cin >>a>>b>>c>>d>>e; sum=a+b+c+e+d; if(sum>max) max=sum; if(sum<min) min=sum; } cout <...
0
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 51 + 51, MOD = 1e9 + 7, mod = 998244353, INF = 2e18; mt19937 Flash_new_51(51515); using vi = vector<long long>; using vp = vector<pair<long long, long long>>; struct Node { long long k, pos, ind; Node() { k = pos = ind = 0; } Node(long long k...
4
#include <bits/stdc++.h> using namespace std; vector<int> adj[100009]; set<int> col[100009]; int c[100009]; int main() { int n, m, a, b, min = INT_MAX; cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> c[i]; if (c[i] < min) min = c[i]; } while (m--) { cin >> a >> b; adj[a].push_back(b); ...
4
#include <bits/stdc++.h> using namespace std; int n, m, head[300010], o = 0, root[300010], id = 0, lc[6000010], rc[6000010], st[6000010], up = 0, dep[300010], siz[6000010]; long long tree[6000010], add[6000010]; struct point { int fa, w; }; int new_node() { int tmp = up ? st[up--] : ++id; ...
4
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); string a, b; cin >> a; cin >> b; long long ci = stoi(a) + stoi(b); string c = to_string(ci); string a1 = "", b1 = "", c1 = ""; for (int i = 0; i < a.length(); i++) { if (a[i] != '0')...
1
#include<iostream> #include<vector> #include<cstdio> #include<string> #include<cstring> #include<algorithm> using namespace std; #define INF (1e10) int n,m,p,a,b; int tic[8]; int di[30][30]; int main(){ double dp[1<<8][30]; while(cin>>n>>m>>p>>a>>b,n|m|p|a|b){ a--;b--; for(int i=0;i<n;i++)cin>>tic[i]; memset(...
0
#include <bits/stdc++.h> using namespace std; const double eps(1e-8); int n, m, len; vector<int> L[1000010]; vector<int> vec[1000010]; vector<int> p[1000010]; int x[1000010], ans[1000010], c[1000010]; int Lowbit(int x) { return x & (-x); } void Update(int pos, int val) { while (pos <= 1000000) { c[pos] += val; ...
5
#include <bits/stdc++.h> using namespace std; template <class T> void dbs(string str, T t) { cerr << str << " : " << t << "\n"; } template <class T, class... S> void dbs(string str, T t, S... s) { int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...); } templat...
5
#include <bits/stdc++.h> using namespace std; const int N = 110; bool a[N][N]; vector<array<pair<int, int>, 3> > ans; void apply(int x, int y, int op) { a[x][y] ^= 1; switch (op) { case 1: a[x - 1][y] ^= 1; a[x][y - 1] ^= 1; ans.push_back({pair<int, int>{x, y}, pair<int, int>{x - 1, y}, ...
1
#include <bits/stdc++.h> inline int read() { register int x = 0; register int y = 1; register char c = std::getchar(); while (c < '0' || c > '9') { if (c == '-') y = 0; c = getchar(); } while (c >= '0' && c <= '9') { x = x * 10 + (c ^ 48); c = getchar(); } return y ? x : -x; } int n, m; ...
2
#include <bits/stdc++.h> using namespace std; void PLAY() { cout << fixed << setprecision(10); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } const int MOD = 1e9 + 7; long long poww(long long b, long long p) { if (p == 0) return 1; long long sq = poww(b, p / 2); sq = (sq * sq) % MOD; if (p % 2 == 1...
3
#include <bits/stdc++.h> using namespace std; map<long long, long long> f; int main() { long long n; scanf("%lld", &n); while (n--) { long long x, v; scanf("%lld", &x); scanf("%lld", &v); f[x] = max(f[x], v); } long long m; scanf("%lld", &m); while (m--) { long long x, v; scanf("%l...
2
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007LL; long long base = 10000007; long long large = 1000000000000000000LL; class AC { public: int sz; vector<int> val, f, last; vector<vector<int> > ch; int sigma_size; int rb; AC(int maxnode, int _sigma_size) { sz = 1; rb = 0; ...
2
#include<bits/stdc++.h> using namespace std; int main(){ int n;cin>>n; cout<<"Christmas"; for (int i=0;i<25-n;i++)cout<<" Eve"; }
0
#include <bits/stdc++.h> const long double pi = 3.141592654; using namespace std; int dx[] = {0, 0, 1, -1, 1, -1, 1, -1}; int dy[] = {1, -1, 0, 0, 1, -1, -1, 1}; bool vis[1000000]; vector<int> vec; const long long N = 1e5 + 5, inf = 2e9, mod = 1e10 + 7; long long fact[1000006], inv[1000006]; vector<vector<int>> graph; ...
3
#include <bits/stdc++.h> using namespace std; const int N = 12; int g[N][N]; int dis[N][N]; void floyd(int n) { memcpy(dis, g, sizeof g); for (int k = 1; k <= n; k++) { for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]); } } ...
5
#include <bits/stdc++.h> using namespace std; bool home = 1; signed realMain(); long long kek; bool acum; time_t bg, nd; signed main() { home = 0; if (home) { freopen("tony_stark", "r", stdin); } else { ios::sync_with_stdio(0); cin.tie(0); } bg = clock(); realMain(); } const long long N = (long ...
6
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; int main() { int a1=0,a2=0; int n; scanf("%d",&n); for(int i=1;i<=n;i++){ int a,b; scanf("%d%d",&a,&b); if(a>a1) a1=a,a2=b; } printf("%d",a1+a2); }
0
#include <bits/stdc++.h> using namespace std; int main() { int t, a, b; cin >> t; while (t--) { cin >> a >> b; cout << 1440 - ((a * 60) + b) << endl; } }
1
#include <bits/stdc++.h> using namespace std; int n, m; long long a = 1, b = 1; int main() { cin >> n >> m; for (int i = 0; i < m; i++) { a *= 2; a %= 1000000009; } a = (a + 1000000009 - 1) % 1000000009; for (int i = 0; i < n; i++) { b *= (a - i); b %= 1000000009; if (b == 0) break; } ...
3
#include <bits/stdc++.h> using namespace std; const int MAXN = 100000 + 50; const int INF = 1 << 30; struct item { int a, b; int cnt; }; bool cmp(const item& a1, const item& a2) { return a1.cnt < a2.cnt; } item itm[200050]; int main() { int n, k; scanf("%d%d", &n, &k); for (int i = 0; i < n; i++) scanf("%d", ...
3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<int> a(n); for (int &i : a) cin >> i; map<int, int> last; vector<int> prev(n); vector<int> w(n); for (int i = 0; i < n; i++) { auto it = last.find(a[i] - 1); if (it !=...
6
#include <bits/stdc++.h> using namespace std; int main() { unsigned long long b; vector<int> a; for (int j = 0; j < 4; j++) { cin >> b; a.push_back(b); } sort(a.begin(), a.end()); if ((a[0] + a[3]) == (a[2] + a[1])) { cout << "YES"; } else if (a[3] == a[0] + a[1] + a[2]) { cout << "YES"; ...
1
#include <bits/stdc++.h> using namespace std; int main() { int t, a, n = 0, p; cin >> t; while (t--) { cin >> a; while (a) { if (a & 1) { n++; a /= 2; } else a /= 2; } p = pow(2.0, n); cout << p << endl; n = 0; } return 0; }
2
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10, M = 3.3e7; int prm[M], tot; void init(int n) { for (int i = 2; i <= n; i++) { if (!prm[i]) prm[++tot] = i; for (int j = 1; j <= tot && i * prm[j] <= n; ++j) { prm[i * prm[j]] = true; if (i % prm[j] == 0) break; } } } struc...
6
#include <bits/stdc++.h> using namespace std; const int MAXN = 300111; int x[MAXN], y[MAXN]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { scanf("%d%d", &x[i], &y[i]); } int k = -1; int sum = 0; for (int i = 0; i < n; i++) { sum += x[i]; if (k < 0 || y[i] > y[k]) k = i; } for...
2
#include<cstdio> #include<cstring> static const int MAX_T = 100000; int N, T; int t[MAX_T + 1]; int main(){ memset(t, 0, sizeof(t)); int l, r; scanf("%d %d", &N, &T); for(int i = 1; i <= N; i++){ scanf("%d %d", &l, &r); t[l]++; t[r]--; } int num = 0, max_num = 0; for(int i = 0; i < T; i++){ num += t[i]; ...
0
#include <bits/stdc++.h> using namespace std; static const double EPS = 1e-9; template <class T> bool INRANGE(T x, T a, T b) { return a <= x && x <= b; } template <class T> void amin(T &a, T v) { if (a > v) a = v; } template <class T> void amax(T &a, T v) { if (a < v) a = v; } int ROUND(double x) { return (int)(x...
2
#include <bits/stdc++.h> using namespace std; struct node { int v1, v2; int x, y; } s[3 * 1005]; int father[3000]; int n, m; int vist[1005], flg1, flg2, ans, xx, yy; int cmp(const node a, const node b) { if (a.y > b.y) return 1; else return 0; } int find(int x) { int root, i = x; while (x != father[...
4
#include <bits/stdc++.h> using namespace std; using lol = long long int; const lol N = 1e6 + 5; const lol modcon = 1e9 + 7, mod = 998244353; const double eps = 1e-7; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int h, w; cin >> h >> w; vector<int> r(h); vector<int> c(w); vector<vector<boo...
2
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 100; const int M = 1 << 13; struct FLIP { int x, y, z; FLIP(int _x = 0, int _y = 0, int _z = 0) { x = _x; y = _y; z = _z; } }; int a[N], n, p[M]; FLIP op[M]; vector<FLIP> flp; void flip(int x, int y, int z) { a[x] ^= 1; a[y] ^= 1; ...
5
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:100000000000000") using namespace std; int n, l[30], m[30], w[30]; int tw[30], P1, P2; map<pair<long long, long long>, pair<long long, long long> > mp; long long best = -(1ll << 58), msk1, msk2; void rec(int p, int msk, long long L, long long M, long long W) { ...
4
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> ostream& operator<<(ostream& o, pair<A, B> a) { return o << a.first << ' ' << a.second; } template <typename A, typename B> istream& operator>>(istream& o, pair<A, B>& a) { return o >> a.first >> a.second; } const int mod = 998244353, a...
3
#include <bits/stdc++.h> using namespace std; int main() { int q; cin >> q; long long int a, b, c; while (q--) { cin >> a >> b >> c; cout << (a + b + c) / 2 << "\n"; } return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { long long a,b,c; cin >> a >> b >> c ; if ((c-a-b)*(c-a-b)>4*a*b && c-a-b>0) {cout << "Yes" << endl;} else {cout <<"No" << endl;} }
0
#include <bits/stdc++.h> int n, s[200010], p; long long k, w[200010], g[200010], a[200010], b[200010], c[200010], d[200010]; long long inf = 0x3f3f3f3f3f3f3f3fll; struct node { long long x, lz, d; } tr[800010]; int ans[200010]; void build(int x = 1, int l = 1, int r = n) { tr[x].x = -inf; if (l == r) return; bu...
5
#include <bits/stdc++.h> using namespace std; int vis[50][50], n; vector<pair<int, int>> pieces; string grid[50], ans[100]; bool check(int dx, int dy) { for (int i = 0; i < pieces.size(); i++) { if (pieces[i].first + dy >= n || pieces[i].first + dy < 0 || pieces[i].second + dx >= n || pieces[i].second + d...
4
#include <bits/stdc++.h> using namespace std; vector<pair<int, int>> a; int getEdge(int u, int v) { return (a[u].first ^ a[v].first) | (a[u].second ^ a[v].second); } int isLess(int x, int y, int z, int xx, int yy, int zz) { if (x < xx) return 1; if (x > xx) return 0; if (y < yy) return 1; if (y > yy) return 0...
4
#include <bits/stdc++.h> using namespace std; const long long N = 100005, mod = 1e9 + 7; const long double pie = 3.14159265358979323846264338327950288419716939937510; long long n, a[55][55]; bool v = 1; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (long long i = 1; i <= n; ++i) { ...
1
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int MAX = 2e5 + 5; int pos[MAX], w[MAX], wa_bit[MAX]; long long w_bit[MAX]; int n, q; inline int add(int a, int b) { a += b; if (a >= MOD) { a -= MOD; } return a; } inline int sub(int a, int b) { a -= b; if (0 > a) { a += M...
3
#include <bits/stdc++.h> using namespace std; int main() { string n; int k; cin >> n; int maxi = 0; vector<string> v(20); for (int i = 0; i < n.length(); i++) { maxi = max(maxi, (int)n[i] - '0'); } cout << maxi << endl; for (int i = 0; i < n.length(); i++) { for (int j = 0; j < ((int)n[i] - '0...
2
#include <bits/stdc++.h> using namespace std; int n; double a[200003]; double b[200003]; void mergesort(double *a, double *b, int n) { int i, i0, i1, iRight, iEnd, width, j; for (width = 1; width < n; width *= 2) for (i = 0; i + width < n; i += width * 2) { i0 = i; i1 = iRight = i + width; iEn...
3
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cerr.writ...
3
#include <bits/stdc++.h> using namespace std; int main() { int N, M, p, A=0, W=0; string S; cin >> N >> M; vector<int> cA(N); vector<int> cW(N); for(int i=0; i<M; i++){ cin >> p >> S; if(S=="AC" && cA.at(p-1)==0){ A++; W += cW.at(p-1); cA.at(p-1) = 1; }else if(c...
0
#include<bits/stdc++.h> using namespace std; #define endl '\n'; typedef long long ll; ll nmax = 1000000000; int main(){ ios::sync_with_stdio(0); cin.tie(0); ll t; cin >> t; while(t--){ ll n; cin >> n; string a; cin >> a; string s = "trygub"; ll count = 0; string ans = ""; for(ll j=0; j<n; j++)...
1
#include <bits/stdc++.h> using namespace std; const double sn = 1e-6; int n; int arr[35]; int res; bool visited[310][310]; bool notAgain[310][310][35][8]; pair<int, int> dirs[8] = {{0, 1}, {1, 1}, {1, 0}, {1, -1}, {0, -1}, {-1, -1}, {-1, 0}, {-1, 1}}; void dfs(int dir, int sx, int sy, int ...
4
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; int n, m, arr[105]; int main() { cin >> n >> m; for (int i = 0; i < n; ++i) cin >> arr[i]; sort(arr, arr + n); int ans = 0, i = n - 1, sum = 0; while (sum < m) { sum += arr[i--]; ans++; if (sum >= m) break; } cout << ans <<...
1
#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, a[100010]; double dp[100010][101]; double nCr[501000][6]; int b[100010]; int main() { cin.tie(0); ios_base::s...
3
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; const vector<int> mods = {998244353, 1000000007, 1000000009}; const long long inf = 3e18; const double pi = acos(-1.0); const double eps = 0.0000001; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template <class... K> using...
4
#include <iostream> #include <iomanip> #include <cmath> using namespace std; int main(){ int n; double x1,y1,x2,y2,x3,y3; cin>>n; for(int i=0;cin>>x1>>y1>>x2>>y2>>x3>>y3||i<n;i++){ double X,Y,L; X= ((y2-y1)*(x1*x1-x3*x3+y1*y1-y3*y3)-(y3-y1)*(x1*x1-x2*x2+y1*y1-y2*y2))/ (2*(x2-x1)*(y3-y1)-2*(y2-y1)...
0
#include <bits/stdc++.h> using namespace std; signed main() { long long t; cin >> t; for (long long wer = 0; wer < t; wer++) { long long n, k; cin >> n >> k; string s; cin >> s; string t = ""; for (long long i = 0; i < (n / 2 - k + 1); i++) { t += '('; } for (long long i = 0;...
1
#include<iostream> #include<vector> using namespace std; int main(){ int K,N;cin>>K>>N; vector<int> A(N); for(int i=0;i<N;i++){ cin>>A[i]; } int m=0; for(int i=0;i<N-1;i++){ m=max(m,A[i+1]-A[i]); } m=max(m,K-A[N-1]+A[0]); cout<<K-m<<endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; const long long INF = 1e12; const long long MOD = 1e9 + 7; long long sq(long long num) { return num * num; } long long mod_pow(long long x, long long n) { if (n == 0) return 1; if (n == 1) return x % MOD; long long res = sq(mod_pow(x, n / 2)); res %= MOD; if (n % ...
2
#include <bits/stdc++.h> using namespace std; const char T[25] = "BERLAND"; bool g[10][10]; struct team { char name[25]; int point; int diff; int score; int miss; } a[10]; int tot; int cmp(struct team x, struct team y) { if (x.point == y.point) { if (x.diff == y.diff) { if (x.score == y.score) ret...
3
#include <bits/stdc++.h> using namespace std; int H[500001]; multiset<int> S; vector<int> G[500001]; int D[500001]; int vis[500001]; int segtree[4000001]; int lazy[4000001]; const int MAX_VAL = 1000000000; int MAX_ID; map<int, int> compres; int timer = 0; void propagate(int L, int R, int i) { if (lazy[i] == 0) return...
1
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, w = 0; char ch = getchar(); while (!isdigit(ch)) w |= ch == '-', ch = getchar(); while (isdigit(ch)) x = (x << 1) + (x << 3) + ch - '0', ch = getchar(); return w ? -x : x; } int n, a[2555][2555], vis[2555], dis[2555], fa[2555], dep[2...
6
#include <bits/stdc++.h> using namespace std; long long ans; int n, m, a[100005], b[100005], c[100005], d[100005], A[100005], e[100005]; bool cmp(int x, int y) { return x > y; } int main() { int i; scanf("%d", &n); for (i = 1; i <= n; i++) { scanf("%d %d %d %d", &a[i], &b[i], &c[i], &d[i]); if (a[i] + b[i...
6
#include <bits/stdc++.h> using namespace std; int main() { long long N,M; cin >> N >> M; if (N >= 2 && M >= 2){ cout << (N-2)*(M-2) << endl; } else if (N == 1 && M == 1){ cout << 1 << endl; } else { cout << N*M-2 << endl; } }
0
#include <bits/stdc++.h> using namespace std; const int N = 200010, mod = 1e9 + 7; int n, a[N], id[N], inv[N], ans = 0; int p[N], mu[N], phi[N], lp; bool pri[N]; vector<int> e[N], E[N]; int fa[N], sz[N], son[N], dep[N], top[N], dfn[N], idx = 0; int s[N], f[N], g[N], ss[N]; int pp[N], len, sta[N], Top = 0; bool flag[N];...
5
#include <bits/stdc++.h> using namespace std; int main() { int t; int n, k; int a[10000]; int b[10000]; cin >> t; while (t--) { int sum = 0, s = 0; cin >> n >> k; for (int j = 0; j < n; j++) { cin >> a[j]; } for (int j = 0; j < n; j++) { cin >> b[j]; } sort(a, a + n);...
2