solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, c, cnt = 0; cin >> a >> b >> c; while (1) { if (a >= 1 && b >= 2 && c >= 4) { cnt++; a--; b -= 2; c -= 4; } else break; } cout << cnt * 7 << endl; }
0
#include <bits/stdc++.h> using namespace std; char p[100100]; char a[11] = {'W', 'Y', 'X', 'V', 'U', 'A', 'H', 'I', 'M', 'O', 'T'}; bool check(char ch) { int i; for (i = 0; i < 11; i++) if (ch == a[i]) return true; return false; } int main() { scanf("%s", p); int len = strlen(p); int i = 0, j = len - 1;...
2
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; const int inf = 1000000007; const long long linf = 1000000000000000001LL; const unsigned long long ulinf = (1ULL << 63) - 10ULL; const double eps = 0.000001; const double pi = 3.14159265358979323846; template <class T> T...
9
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; using vi = vector<int>; using vvi = vector<vi>; const int INF = 2e9 + 5; int dist(pii &a, pii &b) { return abs(a.first - b.first) + abs(a.second - b.second); } int get_2p(pii &a, pii &b, pii...
13
#include <bits/stdc++.h> using namespace std; long long int arr[51][51]; long long int n; long long int val[4]; long long int ask(long long int x1, long long int y1, long long int x2, long long int y2) { cout << "? " << x1 << " " << y1 << " " << x2 << " " << y2 << "\n"; cout << flush; long long ...
16
#include <bits/stdc++.h> using namespace std; template <typename T> inline T ABS(T a) { return a > 0 ? a : -a; } template <typename T> inline T MIN(T a, T b) { return a < b ? a : b; } template <typename T> inline T MAX(T a, T b) { return a > b ? a : b; } template <typename T> inline T CHKMIN(T &a, T b) { if (a ...
1
#include <bits/stdc++.h> using namespace std; long long n, k, s; int main() { scanf("%lld%lld%lld", &n, &k, &s); if ((n - 1) * k < s) { printf("NO\n"); return 0; } else if (k > s) { printf("NO\n"); return 0; } printf("YES\n"); long long sum = s; int flag = 0; long long now = 1; long lo...
8
#include <bits/stdc++.h> using namespace std; int N, K; unsigned long long L[1005], R[1005]; double dp[2][1005], p[1005]; unsigned long long Ans(unsigned long long n) { unsigned long long ans = 0; unsigned long long t = 1; for (int i = 1; i <= n; i++) { ans += t; t *= 10; } return ans; } unsigned long...
12
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; long long mod = 1e9 + 7; long long fact[N]; long long power(long long b, long long n) { if (!n) return 1; if (n & 1) return b * power(b, n - 1) % mod; long long res = power(b, n / 2); return res * res % mod; } long long inv(long long x) { ret...
12
#include <bits/stdc++.h> int main() { int n; scanf("%d", &n); int t, x, y, ax = 0, atot = 0, bx = 0, btot = 0; for (int i = 1; i <= n; i++) { scanf("%d%d%d", &t, &x, &y); if (t == 1) { ax = ax + x; atot = atot + x + y; } else if (t == 2) { bx = bx + x; btot = btot + x + y; ...
0
#include <bits/stdc++.h> using namespace std; long long pt[5][1005]; bool ar[10005]; inline long long sq(long long x) { return x * x; } inline long long dis(int i, int j) { return sq(pt[0][i] - pt[0][j]) + sq(pt[1][i] - pt[1][j]) + sq(pt[2][i] - pt[2][j]) + sq(pt[3][i] - pt[3][j]) + sq(pt[4][i] - pt...
9
#include <bits/stdc++.h> using namespace std; void swap(char &a, char &b) { char t = a; a = b; b = t; } void rotateAmulet(string &amulet) { swap(amulet[0], amulet[1]); swap(amulet[2], amulet[0]); swap(amulet[3], amulet[2]); } int main() { int n; cin >> n; map<string, bool> exists; string amulet; s...
5
#include <bits/stdc++.h> using namespace std; const int NN = 500100; pair<int, pair<int, int> > p[NN]; multiset<pair<int, int> > st; int main() { int t; scanf("%d", &t); while (t--) { int n, m, c, c0; scanf("%d%d%d%d", &n, &m, &c, &c0); for (int i = 1; i <= n; i++) scanf("%d%d%d", &p[i].first, &...
19
#include <bits/stdc++.h> using namespace std; int main() { long long int a, b, part1, part2, mod = 1000000007; cin >> a >> b; part1 = ((((a + 1) * a / 2) % mod) * b % mod + a) % mod; part2 = (b * (b - 1) / 2) % mod; cout << (part1 * part2) % mod; return 0; }
8
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, m, k, l; cin >> a >> b >> m; if (a >= m || b >= m) cout << 0; else { long long sum = a + b; if (sum > a || sum > b) { k = 0; if (a < 0) { l = -a / b; a = a + l * b; k += l; } else if ...
8
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; int cnt = 0; for (int i = 1; i <= n; ++i) { n -= i; cnt++; } cout << cnt << endl; for (int i = 1; i <= cnt - 1; ++i) { cout << i << " "; } cout << cnt + n; } int main() { ios_base::sync_with_stdio(false); cin...
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long n, ans = 0; cin >> n; long long a[n]; for (long long i = 0; i < n; i++) { cin >> a[i]; if (a[i] == 1) ans++; } for (long long i = 1; i <= n - 2; i++) { if (a[i] =...
1
#include <bits/stdc++.h> long long shouldendl = 1; long long INF = (long long)(1e16 + 7); long long MOD = (long long)(1e9 + 7); using namespace std; long long modInverse(long long a) { long long m = MOD, m0 = m, y = 0, x = 1; if (m == 1) return 0; while (a > 1) { long long q = a / m, t = m; m = a % m, a =...
9
#include <bits/stdc++.h> #pragma GCC target("avx2") #pragma GCC optimize("O3") using namespace std; const int mod = 1e9 + 7; const int inf = 1e9; const int maxn = 2e5 + 100; const int LOG = 21; vector<int> g[maxn]; vector<int> col(maxn, 0), depth(maxn); vector<int> e, L(maxn), R(maxn); int dp[LOG][maxn]; int p[maxn]; v...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, mn = 2e9, mx = -2e9; cin >> n; pair<int, int> arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i].first >> arr[i].second; mn = min(mn, arr[i].first); mx = max(mx, arr[i].second); } for (int i = 0; i < n; i++) { if (arr[i].firs...
3
#include <bits/stdc++.h> using namespace std; const int n = 4; long long a[5], x[5], res = 1e19, tmp, y[5]; char f[5]; bool d = false, kt = false; void nhap() { for (int i = (1); i <= (4); ++i) { cin >> a[i]; if (a[i] == 0) d = true; } for (int i = (1); i <= (4); ++i) x[i] = i; for (int i = (1); i <= (3...
8
#include <bits/stdc++.h> using namespace std; long long fact(long long n) { long long f = 1; for (long long i = 1; i <= n; i++) { f = (f * i) % 1000000007; } return f; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n; cin >> n; long long r = fact(n);...
7
#include <bits/stdc++.h> using ll = long long; int const nmax = 100000; int const kmax = 20; int v[1 + nmax]; int dp[(1 << kmax)][1 + kmax]; int dp2[(1 << kmax)][1 + kmax]; int main() { std::ios::sync_with_stdio(0); std::cin.tie(0); int n, m; std::cin >> n >> m; std::string s[1 + kmax]; for (int i = 0; i < ...
18
#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...
11
#include <bits/stdc++.h> using namespace std; long long int min(long long int a, long long int b) { return (a < b) ? a : b; } long long int max(long long int a, long long int b) { return (a > b) ? a : b; } long long int fp(long long int a, long long int b) { if (b == 0) return 1; long long int x = fp(a, b / 2); x...
5
#include <bits/stdc++.h> using namespace std; int main() { std ::ios_base ::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL); long long n, k; cin >> n >> k; if (k > (n * (n - 1)) / 2) { cout << "Impossible" << endl; return 0; } vector<long long> a(300001, 0); for (int i = 2; i < 300001; ++i...
10
#include <bits/stdc++.h> using namespace std; long long a[200002], sum; long long v1[200002], v2[200002]; int main() { long long n, q; cin >> q; for (int t = 1; t <= q; t++) { cin >> n; sum = 0; for (int i = 0; i < n; i++) { cin >> a[i]; if (i % 2 == 0) sum += a[i]; } for (int i = ...
8
#include <bits/stdc++.h> using namespace std; int main() { int n, t; cin >> n >> t; if (t == 10 && n == 1) cout << "-1"; else if (t == 10) { cout << "1"; for (int i = 0; i < n - 1; i++) cout << 0; } else { for (int i = 0; i < n; i++) cout << t; } }
2
#include <bits/stdc++.h> using namespace std; int a, b, c, ans; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; cin >> a >> b >> c; for (int i = 1; i <= a; i++) if (2 * i <= b && 4 * i <= c) ans = max(ans, 7 * i); for (int i = 2; i <= b; i += 2) if (2 * i <= c && i / 2 <= a) ans =...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, m, i, j, a; cin >> n; cin >> m; int min1[n]; for (i = 0; i < n; i++) { cin >> a; min1[i] = a; for (j = 1; j < m; j++) { cin >> a; if (a < min1[i]) min1[i] = a; } } a = min1[0]; for (i = 1; i < n; i++) { if ...
2
#include <bits/stdc++.h> using namespace std; int second[100010 * 4]; int first[100010 * 4]; int arr[100010]; int n; void update(int x, int val, int c = 1, int b = 1, int e = n) { if (b == e) { if (val > 0) { first[c] = 1; second[c] = 0; } else { first[c] = 0; second[c] = 1; } ...
14
#include <bits/stdc++.h> using namespace std; int n, m, k; bool debug = false; int W; struct company { long long w, a, c; bool operator<(const company b) const { return c * b.w < b.c * w; } } coms[500005]; int main() { scanf("%d%d%d", &n, &m, &W); for (int i = 0; i < m; i++) scanf("%I64d", &coms[i].w); for (i...
20
#include <bits/stdc++.h> using namespace std; bool cmp(pair<long long, long long> a, pair<long long, long long> b) { long long as = a.first + a.second; long long bs = b.first + b.second; if (as == bs) { return a < b; } else { return (as < bs); } } int main() { ios_base::sync_with_stdio(false); lon...
9
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> void ckmin(T1 &a, T2 b) { if (a > b) a = b; } template <typename T1, typename T2> void ckmax(T1 &a, T2 b) { if (a < b) a = b; } int read() { int x = 0, f = 0; char ch = getchar(); while (!isdigit(ch)) f |= ch == '-', ch = getcha...
22
#include <bits/stdc++.h> using namespace std; int Pow(int N, int Mod) { if (!N) return 1; int T = Pow(N / 2, Mod); T = (long long)T * T % Mod; if (N & 1) T = T * 2 % Mod; return T; } int main() { int M, N; scanf("%d%d", &M, &N); if ((M + N) & 1) { printf("0\n"); return 0; } if (M == 1 || N =...
17
#include <bits/stdc++.h> using namespace std; int lol(long int a) { int sum = 1, sum2 = 2, c = 0; while (1) { if (sum > a) return c; else { a -= sum; sum += sum2; sum2++; c++; } } } int main() { long int a; cin >> a; cout << lol(a) << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main(void) { ios_base::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL); int n; cin >> n; int x = n * 2; for (int t = 0; t <= n; t++) { for (int i = 1; i <= x; i++) { cout << " "; } cout << 0; x -= 2; if (t > 0) { for (in...
2
#include <bits/stdc++.h> using namespace std; int fact[100005]; int invfact[100005]; bool prime[100005]; vector<long long> divisor[100005]; long long pw(long long a, long long b) { long long res = 1; while (b) { if (b & 1ll) { res = res * a % 1000000007; } b >>= 1; a = a * a % 1000000007; } ...
5
#include <bits/stdc++.h> using namespace std; typedef long long int ll; #define int ll #define fast(); ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define tests() int _t; cin>>_t; while(_t--) #define test int t = 1; #define tests int t; cin >> t; #define endl '\n' #define sz(x) ll((x).size()) #define F first...
1
#include <bits/stdc++.h> using namespace std; int a[500002]; int b[500002]; int ssl[500002]; int ssp[500002]; int z[500002]; int n; long long int p = 0; long long int s = 0; void qs(int a[], int b[], int l, int r) { int i = l, j = r, tmp, p = a[(l + r) / 2]; while (i <= j) { while (a[i] < p) i++; while (a[j...
17
#include <bits/stdc++.h> template <class T1, class T2> inline bool cmin(T1 &a, const T2 &b) { return b < a ? (a = b, true) : false; } template <class T1, class T2> inline bool cmax(T1 &a, const T2 &b) { return a < b ? (a = b, true) : false; } template <class Type> Type read() { Type a; bool b; unsigned char c...
14
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> inline ostream& operator<<(ostream& out, const pair<T1, T2>& v) { return out << v.first << ' ' << v.second; } template <typename T> inline ostream& operator<<(ostream& out, const vector<T>& v) { for (const T& x : v) out << x << ' '; ...
8
#include <bits/stdc++.h> using namespace std; char s[100] = "AHIMOTUVWXY"; char t[1000100]; char in(char c) { for (int i = 0; s[i]; i++) if (c == s[i]) return true; return false; } bool solve() { int len = strlen(t); for (int i = 0, j = len - 1; i < j; i++, j--) if (t[i] != t[j]) return false; for (in...
2
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1); const int N = (int)1e6 + 7, mod = 1000000007; int n, t = 1; int main() { cin >> n; if (n % 2) printf("%d ", t); t += n % 2; for (int i = n % 2; i < n; i += 2) { printf("%d %d ", t + 1, t); t += 2; } return 0; }
9
#include <bits/stdc++.h> using namespace std; int main() { char x[200], y[200]; while (scanf("%s %s", x, y) != EOF) { int num = strlen(x); int flag = 0; for (int number1 = 0; number1 < num; number1++) { if (y[number1] - x[number1] >= 2) { flag = 1; x[number1] = x[number1] + 1; ...
8
#include <bits/stdc++.h> using namespace std; const int N = 110; const int M = 45; const int zer = 22; const int mod = 1e9 + 7; int n, k; int f[N][M]; vector<int> g[N]; int w[N][2]; void dfs_solve(int v, int p) { if (p) g[v].erase(find(g[v].begin(), g[v].end(), p)); for (int s : g[v]) { dfs_solve(s, v); } f...
17
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 5; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; int h; int num[maxn]; int main() { scanf("%d", &h); num[0] = 0; for (int i = 1; i <= h + 1; i++) scanf("%d", &num[i]); int flag = 1; for (int i = 1; i <= h; i++) { if (num[i] > 1 &&...
7
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; inline void relax(long long& a, long long b) { a = max(a, b); } long long ceil(long long a, long long b) { return (a + b - 1) / b; } long long f(long long n, long long k, long long r) { k -= r; if (k < 0) return -1; long long res = -1; if...
18
#include <bits/stdc++.h> using namespace std; int p[300005]; int f[300005]; void swapp(int x, int y) { int v1 = p[x]; int v2 = p[y]; p[x] = v2; p[y] = v1; f[v1] = y; f[v2] = x; } int cnt; vector<pair<int, int> > ans; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int n; cin >> n; ...
9
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:66777216") using namespace std; const int N = 100000 + 5; int n, m; char c[10]; bool possible = true; vector<vector<int> > l(N); vector<vector<int> > r(N); int go[N][2]; int p[N]; int dfs(int v, int ma) { if (!possible) return -1; int q = 1; if (((int)((l[v...
16
#include <bits/stdc++.h> using namespace std; const int maxn = 200005; long long h[maxn][27]; char s[maxn]; long long a[27], b[27]; long long sum[maxn]; const int base = 131; const int mod = 1e9 + 7; int n; void init() { for (int i = 1; i <= n; i++) { for (int j = 1; j <= 26; j++) { h[i][j] = ((h[...
15
#include <bits/stdc++.h> using namespace std; int main() { long int n; cin >> n; long int s = sqrt(n); if (n == s * s) cout << s << " " << s; else { for (int i = s + 1; i <= n; i++) { if (n % i == 0) { cout << n / i << " " << i << endl; break; } } } }
0
#include <bits/stdc++.h> using namespace std; int horas[2000], n, h, l, r, maxim = -1; int good[2000][2000]; int maximo(int horaActual, int dia) { if (dia == n) return 0; if (good[dia][horaActual] != -1) return good[dia][horaActual]; if (horaActual < l || horaActual > r) { int a = max(maximo((horaActual + hor...
9
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 1; int n; unsigned long long a[N]; map<unsigned long long, bool> mp; deque<unsigned long long> list_ans; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; mp[a[i]] = true; } for (int i = 1; i <= n; i++) { unsigned lon...
6
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; const int N = 200005; const double PI = 4 * atan(1); const long long MAX = 9223372036854775807; int dx[] = {1, -1, 0, 0, 1, -1, 1, -1}; int dy[] = {0, 0, 1, -1, 1, 1, -1, -1}; long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a...
9
#include <bits/stdc++.h> using namespace std; using ll = long long; const long long mod = 998244353; const long long N = 505; long long fact[N], infact[N]; long long mpow(long long x, long long k) { long long res = 1; while (k) { if (k & 1) res = (ll)res * x % mod; x = (ll)x * x % mod; k >>= 1; } re...
13
#include <bits/stdc++.h> using namespace std; template <typename T> inline T gcd(T a, T b) { while (b) swap(a %= b, b); return a; } long double e = 2.7182818284590452353602874713526624; long double PI = acos(-1); long double PIjane = sqrt(2) + sqrt(3); long double eps = 1e-10; const int T = 1 << 20; const int INF =...
14
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> v(n); for (int i = 0; i < n; i++) { cin >> v[i]; } sort(v.begin(), v.end()); multiset<int> s; for (int i = 0; i < n; i++) { if (i == 0) { s.insert(1); continue; } if (v[i] == 0) { s....
6
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); string a; int n, s[102031]; memset(s, 0, sizeof s); cin >> a >> n; for (int i = 1; i <= n; i++) { int x; cin >> x; x--; s[x]++; } for (int i = 1; i < a.size() / 2; i++) s[i] += s[i ...
6
#include <bits/stdc++.h> using namespace std; bool cmp(pair<int, int> a, pair<int, int> b) { return a.second < b.second && a.first << b.first; } long long bigmod(int b, int p, int m) { if (p == 0) return 1; if (p % 2 == 0) { long long temp = bigmod(b, p / 2, m); return (temp * temp) % m; } return (big...
5
#include <bits/stdc++.h> using namespace std; int main() { long n, k, t; cin >> n >> k >> t; if (t <= k) { cout << t; } else if (t <= n) { cout << k; } else { cout << k - (t - n); } }
0
#include <bits/stdc++.h> using namespace std; char field[100][100]; int okv[100][100], okh[100][100], sum[100][100]; int main() { int n, k, s; cin >> n >> s; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> field[i][j]; } getchar(); } for (int i = 0; i < n; i++) { for (...
5
#include <bits/stdc++.h> using namespace std; class SegTree { private: vector<int> segt, a; int n; int left(int si) { return si * 2; } int right(int si) { return si * 2 + 1; } int getMid(int ss, int se) { return (ss + (se - ss) / 2); } void build(int ss, int se, int si) { if (ss == se) { segt[si]...
10
#include <bits/stdc++.h> using namespace std; int main() { int i, l, u; char str[101]; istringstream iss(); u = l = 0; while (!cin.eof()) { cin.getline(str, 102); if (str[0] == '+') { u++; continue; } if (str[0] == '-') { u--; continue; } for (i = 0; i < strlen(...
2
#include <bits/stdc++.h> using namespace std; const int M = 1e9 + 7; const int maxn = 200100; int a[maxn]; bool cmp(int x, int y) { return x > y; } struct node { int op; int id; } line[maxn]; int num[maxn]; int C[maxn]; int main() { int n, m; while (scanf("%d%d", &n, &m) != EOF) { for (int i = 1; i <= n; i+...
9
#include <bits/stdc++.h> using namespace std; const int N = 100010; long long R() { long long ans = 0, f = 1; char c = getchar(); for (; c < '0' || c > '9'; c = getchar()) if (c == '-') f = -1; for (; c >= '0' && c <= '9'; c = getchar()) ans = ans * 10 + c - '0'; return ans * f; } int n, a[N]; bool Work()...
7
#include <bits/stdc++.h> using namespace std; const int lx = 3e5 + 123; const long long int mod = 998244353; void solve() { long long int n, i, j, a, b, c; string s; cin >> n >> s; long long int sum = 0; char c1 = s[0], c2 = s[n - 1]; for (i = 1, a = 1; i < n; i++) { a++; if (s[i] != c1) break; } ...
5
#include <bits/stdc++.h> using namespace std; int main() { int m, n; cin >> n >> m; vector<bool> v(n, true); string str, tmp; int t; while (m--) { cin >> tmp >> tmp >> str >> tmp >> t; t--; if (str == "right") { for (int i = t; i >= 0; i--) v[i] = false; } else { for (int i = t; ...
5
#include <bits/stdc++.h> using namespace std; template <typename T> void maxtt(T& t1, T t2) { t1 = max(t1, t2); } template <typename T> void mintt(T& t1, T t2) { t1 = min(t1, t2); } bool debug = 0; int n, m, k; int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; string direc = "URDL"; long long ln, lk, lm; void etp(b...
19
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; const double PI = acos(-1); const int INF = 0x3f3f3f3f; const int MAXN = 1000000 + 10; int n, m; int vis[MAXN]; int head[MAXN], head2[MAXN]; struct node { int to; int nxt; } e[MAXN], e2[MAXN]; int tot; void add(int x, int y) { e[tot].nxt = hea...
16
#include <bits/stdc++.h> using namespace std; template <class T> T sqr(T x) { return x * x; } int main() { int x1, y1, z1, x2, y2, z2; cin >> x1 >> y1 >> z1 >> x2 >> y2 >> z2; if (x1 != x2 && y1 != y2 && z1 != z2) cout << "NO" << endl; else cout << "YES" << endl; return 0; }
3
#include <bits/stdc++.h> using namespace std; int main() { int t; int n; string s; cin >> t; while (t) { cin >> n; cin >> s; bool flag = 0; int m = n - 1; int i = 0; while (i < m) { if (s[i] - 1 != s[m] - 1 && s[i] + 1 != s[m] + 1 && s[i] + 1 != s[m] - 1 && s[i] - 1 != ...
2
#include <bits/stdc++.h> using namespace std; struct trie_node { int z = -1, s = -1, leaf = 0; trie_node() {} }; vector<int> kk; long long res; class trie { public: vector<trie_node> tr; trie() { tr.resize(1); } void add(vector<int> &t) { int v = 0; for (int i = 0; i < 30; i++) { tr[v].leaf++; ...
13
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:60777216") using namespace std; int n, k; int x[111111]; int y[111111]; long long r[111111]; multiset<int> s; void solve(long long mult) { vector<int> v1, v2; for (multiset<int>::iterator it = s.begin(); it != s.end(); ++it) v1.push_back(*it), v2.push_bac...
18
#include <bits/stdc++.h> using namespace std; long long n, mx, ans; pair<long long, long long> a[100005]; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i].first; cin >> a[i].second; } sort(a, a + n); for (int i = 0; i < n; i++) { mx = max(mx, a[i].second); if (a[i].second < mx)...
7
#include <bits/stdc++.h> using namespace std; void cal_div(int n, vector<int> &resp) { int i = 1; while (i * i < n) { if (!(n % i)) { resp.push_back(i), resp.push_back(n / i); } ++i; } if (n == i * i) { resp.push_back(i); } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); i...
3
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 1; int n, a[N], b[N], x, z, m; int main() { scanf("%d%d%d%d", &x, &z, &n, &m); for (int i = 1; i <= x; i++) { cin >> a[i]; } for (int i = 1; i <= z; i++) { cin >> b[i]; } if (a[n] < b[z - m + 1]) { puts("YES"); return 0; } ...
1
#include <bits/stdc++.h> using namespace std; struct Edge { int a, b; Edge() {} Edge(int a, int b) : a(a), b(b) {} int other(int x) { return x == a ? b : a; } }; int depths[600024]; int flips[600024]; int totflips; int n; vector<list<Edge> > adj; void dfs(int v, int p) { for (list<Edge>::iterator it = adj[v]....
9
#include <bits/stdc++.h> using namespace std; int main() { long long ww, hh; int a; double alpha; cin >> ww >> hh >> a; if (ww < hh) swap(ww, hh); double w = ww, h = hh; if (a > 90) a = 180 - a; if (a == 90) { double s = pow(min(ww, hh), 2); printf("%.9lf\n", s); return 0; } else if (a == ...
12
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 3, M = 4e5 + 3; int he[N], to[M], len[M], ne[M], st[N], w[N], tp, b[N]; long long f[N], p[N], q[N], s[N], o[N], ans2; int getc(int x, int y) { if (b[x]) return x; b[x] = 2; for (int i = he[x], j, k; i; i = ne[i]) if ((j = to[i]) != y) { k...
17
#include <bits/stdc++.h> using namespace std; const int dx[] = {0, 1, -1, 0, 1, -1, -1, 1}; const int dy[] = {-1, 0, 0, 1, 1, 1, -1, -1}; const long long int MOD = 0; const long long int N = 0; int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long int n, x, y, xx, yy; char op; vector<pair<long long...
9
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; vector<bool> used(n + 10); int res = 1; while (n--) { int t; cin >> t; if (!used[t]) used[t] = 1; else res++; } cout << res << endl; re...
5
#include <bits/stdc++.h> using namespace std; int main() { long long int numStd, sum = 0, j = 1, cont = 0; bool flag = 1; scanf("%lld", &numStd); long long int stdA[numStd]; long long int stdB[numStd]; long long int qtdA[6] = {0}; long long int qtdB[6] = {0}; for (long long int i = 0; i < numStd; i++) {...
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); long a, b, c, n; cin >> a >> b >> c; cin >> n; long temp, ans = 0; for (long i = 0; i < n; i++) { cin >> temp; if (temp <= b || temp >= c) continue; else ans++; } cout << ans << endl; r...
0
#include<bits/stdc++.h> #define inf 1e18 #define ll long long #define MAX 1000001 const ll N = 1e5+7; const ll mod = 1e18; using namespace std; int n,k; int main(){ int t;cin>>t; while(t--){ string s; cin>>n>>k; cin>>s; int f=1,ans=0,p=0; int len=s.length(); while(p<=s.length()){ if(s[p]=='.'){ p++...
3
#include <bits/stdc++.h> #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize("Ofast") using namespace std; namespace ywy { inline int get() { int n = 0; char c; while ((c = getchar()) || 23333) if (c >= '0' && c <= '9') break; n = c - '0'; while ((c = getchar()) || 23333) { if (c >= '...
20
#include <bits/stdc++.h> using namespace std; int a[55][5], s[110]; int tonghang[55], dem0hang[55], d[110]; int n, ln, nn; int coketqua; int tong; void tim(int i, int j) { int k, x, kt; if (coketqua == 1) { return; } if (j == 3) { if (tong != tonghang[i]) { return; } j = 1; i = i + 1; ...
0
#include <bits/stdc++.h> using namespace std; template <class T, class U> void maximize(T &x, U y) { if (x < y) x = y; } template <class T, class U> void minimize(T &x, U y) { if (x > y) x = y; } template <class T> T Abs(T x) { return (x < 0 ? -x : x); } template <class T> T safe_sqrt(T x) { return sqrt(max(x, ...
11
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 7; const int M = N; const int inf = 1e9 + 9; const long long base = 1e18; const double pi = acos(-1); const double ep = 1e-9; int a[N]; vector<pair<int, int> > b; int n; bool check(int x) { while (x > 0) { int r = x % 10; if (r != 4 && r != 7) ...
12
#include <bits/stdc++.h> using namespace std; long long n, x, y; long long mod = 1000000007; vector<long long> vec; vector<long long> mult(vector<long long> a, vector<long long> b) { vector<long long> res; res.push_back(a[0] * b[0] + a[1] * b[2]); res[0] %= mod; res[0] += mod; res[0] %= mod; res.push_back(a...
5
#include <bits/stdc++.h> using namespace std; int main() { int n4 = 0, n7 = 0; string s; cin >> s; for (int i = 0; i < s.length(); i++) { if (s[i] == '4') n4++; if (s[i] == '7') n7++; } if (n4 == 0 && n7 == 0) { cout << "-1" << endl; return 0; } if (n4 > n7) { cout << "4" << endl; ...
2
#include <bits/stdc++.h> using namespace std; int n, m; char mp[3010][3010]; int f[3010][3010]; int get(int sx, int sy, int ex, int ey) { memset(f, 0, sizeof(f)); f[sx][sy] = 1; if (mp[sx][sy] == '#') return 0; for (int i = sx; i <= ex; i++) for (int j = sy; j <= ey; j++) { if (i == sx && j == sy) con...
17
#include <bits/stdc++.h> using namespace std; const int INF = (unsigned)-1 >> 1; const long long inf = (unsigned long long)-1 >> 1; template <class T> void rd(T &a) { a = 0; char c; while (c = getchar(), !isdigit(c)) ; do a = a * 10 + (c ^ 48); while (c = getchar(), isdigit(c)); } template <class T> void ...
8
#include <bits/stdc++.h> using namespace std; int const inf = 1000 * 1000 * 1000; long long const inf64 = 1ll * inf * inf; int n; vector<vector<int> > g; vector<int> cn, dp; void dfs(int v, int par = -1) { cn[v] = 1; for (int to : g[v]) { if (to == par) continue; dfs(to, v); cn[v] += cn[to]; } if (c...
15
#include <bits/stdc++.h> using namespace std; long long n, l, r; long long len; long long length; long long tab[60]; long long dig(long long x) { long long res; for (int i = 1; i <= 52; i++) { if (tab[i] > x) { res = tab[i] - 1; break; } } return res; } long long solve(long long l1, long lon...
8
#include <bits/stdc++.h> using namespace std; int T; int n, m; int a[111111], ans[111111], b[111111]; int main() { scanf("%d", &n); int lst = 1; for (int i = 2; i <= n; i++) { printf("? %d %d\n\n", lst, i); cout.flush(); int t1, t2; scanf("%d", &t1); printf("? %d %d\n\n", i, lst); cout.flu...
8
#include <bits/stdc++.h> using namespace std; struct BIT { int n; vector<long long> t; BIT() {} BIT(int _n) : n(_n + 1), t(_n + 1) {} void add(int k, long long val) { k++; while (k < n) { t[k] += val; k += (k & -k); } } long long sum(int k) { long long r = 0; while (k > 0) ...
15
#include <bits/stdc++.h> using namespace std; int read() { int x = 0; bool flg = false; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') flg = true; for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch ^ 48); if (flg) x = -x; return x; } int n, a[1000010], b[100001...
13
#include <bits/stdc++.h> using namespace std; void NITRO() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } const long long N = 1e+5 + 7; const long long MOD = 1e+9 + 7; const long long INF = 1e+9 + 12345678; int a[111]; void SOLVE() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> ...
0
#include <bits/stdc++.h> using namespace std; int n; int x[1005], y[1005]; int a[1005], b[1005]; map<pair<int, int>, int> mp; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d %d", x + i, y + i); mp[{x[i], y[i]}] = 1; } for (int i = 1; i <= n; ++i) { scanf("%d %d", a + i, b + i)...
4