solution
stringlengths
53
181k
difficulty
int64
0
13
#include <bits/stdc++.h> using namespace std; struct ww { int l, ll, a, cov, s, key, sum, k; } a[400010]; int i, j, k, n, m, s, an, t, F; int g[400010], fa[400010], f[400010], huan[400010], se[400010], id[400010], ans[400010]; vector<int> b[400010]; void Dfs(int x) { if (s) return; int i; g[++*g] = x; f[x...
10
#include <bits/stdc++.h> using namespace std; const int bigp = 10000007; int H, Q, N, V, E, p, xc, yc, dg; int hash1[15000005], hash2[15000005]; char st[10]; double ans; void mplus(int S, int E) { int e = S % bigp; while ((hash1[e] != 0) && (hash1[e] != S)) ++e; hash1[e] = S; hash2[e] += E; } int getsize(int S)...
8
#include <bits/stdc++.h> using namespace std; const int N = 1005; int n, m, suc; vector<int> e[N]; int a[N], b[N], fr[N]; long long ATK; int vis[N]; void dfs(int x, int fa, long long ATK) { if (suc) return; for (auto i : e[x]) if (i != fa && a[i] < ATK) { if (vis[i] && vis[x]) continue; if (vis[i]) ...
11
#include <bits/stdc++.h> using namespace std; signed main() { long long t; cin >> t; while (t--) { long long n, i, j, ans = 0; cin >> n; vector<long long> v(n); for (i = 0; i < n; i++) cin >> v[i]; for (i = 0, j = n - 1; i < j;) { if (v[i] >= 0) { v[i + 1] -= v[i]; i++; ...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, m; long long c = 0, x = 0, y = 0, yd = 0, xd = 0, ans = 0; map<int, vector<int> > oc; vector<int> a; scanf("%d %d", &n, &m); scanf("%d", &x); a.push_back(x); for (int i = 1; i < m; ++i) { scanf("%d", &x); a.push_back(x); c += ...
5
#include <bits/stdc++.h> using namespace std; const int N = 333; const int MO = 1e9 + 7; int n, m, a[N], b[N], c[1111][1111], d[1111]; long long f[N][N]; map<int, int> M; map<int, int>::iterator it; int C(int x, int y) { if (x < 0 || y < 0 || x < y) return 0; return c[x][y]; } int fpow(int x, int y = MO - 2) { if...
8
#include <bits/stdc++.h> using namespace std; using ll = long long; const int maxn = 2e5 + 5; int n, x, y; vector<int> adj[maxn]; int deg[maxn]; int dp1[maxn], dp2[maxn]; void dfs(int i, int p) { int sum_dp2 = 0; vector<int> diffs; for (int j : adj[i]) { if (j == p) continue; dfs(j, i); sum_dp2 += dp2...
7
#include <bits/stdc++.h> using namespace std; inline char nc() { static char buf[100000], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++; } inline int read() { register int x = 0, f = 1; register char ch = nc(); while...
7
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); char sym[] = {'A', 'O', 'M', 'H', 'I', 'o', 'T', 'V', 'W', 'U', 'X', 'Y', 'x', 'w', 'v'}; map<char, char> mp; mp['b'] = 'd'; mp['d'] = 'b'; mp['p'] = 'q'; mp['q'] = 'p'...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; if (k > n || (n > 1 && k == 1)) cout << -1; else { if (n == 1) cout << 'a'; else { int a = 1; for (int i = 0; i < n - k + 2; i++) if (a) { cout << 'a'; a = 0; } e...
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; int testcases = 1; cin >> testcases; while (testcases--) { int x, y, z; cin >> x >> y >> z; bool can = true; vector<int> v; v.push_back(x); v.push_back(y); v....
0
#include <bits/stdc++.h> using namespace std; const long long N = 105, MOD = 1e9 + 7; long long n, k; struct mat { long long arr[N][N]; mat operator*(mat b) { mat c = mat(); for (long long i = 0; i < n; i++) { for (long long j = 0; j < n; j++) { for (long long k = 0; k < n; k++) { c....
5
#include <bits/stdc++.h> using namespace std; static int prefix[200000]; static int prefix_len; struct Segment { long long base; Segment(long long base) : base(base) {} virtual int value(long long index) const = 0; }; struct RawValue : public Segment { RawValue(long long base, int val) : Segment(base), val(val)...
4
#include <bits/stdc++.h> using namespace std; void *malloc(size_t size); int main() { long long int y, x, min_x, min_y, max_x, max_y, s; int n, i; cin >> n; for (i = 0; i < n; i++) { cin >> x >> y; if (i == 0) { max_x = min_x = x; max_y = min_y = y; } else { if (x > max_x) { ...
2
#include <bits/stdc++.h> using namespace std; const int L = 22, MAXN = (1 << L); int dp[MAXN], n, a[MAXN]; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; dp[a[i]] = a[i]; } for (int mask = 0; mask < MAXN; mask++) { for...
7
#include <bits/stdc++.h> using namespace std; const int size = 50 + 10; int n, k, aim[size], num[size], ans = -1; int main() { cin >> n >> k; if (k > n) { cout << -1 << endl; return 0; } for (int i = 1; i <= n; i++) cin >> aim[i]; sort(aim + 1, aim + n + 1); num[1] = 0; for (int i = 2; i <= n; i++...
0
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC target("sse4") using namespace std; template <class T> T gcd(T a, T b) { return ((b == 0) ? a : gcd(b, a % b)); } vector<int> g[10]; int deg[10]; int ed[10][10]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; ...
4
#include <bits/stdc++.h> using namespace std; pair<int, int> arr[100000 + 10]; int n, ans[100000 + 10], opt[100000 + 10]; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &opt[i]); for (int i = 0; i <= n; ++i) if (!opt[i]) { int nex = i + 1; for (; nex <= n + 1; ++nex) ...
6
#include <bits/stdc++.h> using namespace std; long long fix(long long cur, long long m) { return ((cur % m) + m) % m; } long long fast_power(long long x, long long y, long long m) { if (y == 0) return 1; long long temp = fast_power(x, y / 2, m); temp = (temp * temp) % m; if (y % 2 != 0) temp = (temp * x) % m; ...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 100; const int maxL = 1e6 + 100; struct Flight { int fr, to, cost; Flight(int a = 0, int b = 0, int c = 0) { fr = a, to = b, cost = c; } }; int N, M, K, L; int used[maxn]; long long pre[maxL], suf[maxL]; vector<Flight> ope[maxL]; void Prepare() { ...
5
#include <bits/stdc++.h> using namespace std; int n, m; int g[1000][1000]; void solve() { m = 3; while (n * 2 >= m * (m + 1)) m++; for (int i = 0; i < m; i++) g[i][0] = 0; for (int i = 0; i < m; i++) { for (int j = i + 1; j < m; j++) { g[i][++g[i][0]] = n; g[j][++g[j][0]] = n; n--; } ...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 1000 + 5; bool u[maxn][maxn]; int main() { vector<pair<int, int>> v(3); for (int i = 0; i < 3; ++i) scanf("%d%d", &v[i].first, &v[i].second); vector<int> o(3); for (int i = 0; i < 3; ++i) o[i] = i; vector<pair<int, int>> ans; do { for (int s...
4
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; template <class c> struct rge { c b, e; }; template <class c> rge<c> range(c i, c j) { return {i, j}; } template <class c> auto dud(c* x) -> decltype(cerr << *x, 0); template <class c> char dud(...); struct debug { template <class c> debug...
5
#include <bits/stdc++.h> using namespace std; bool visited[1010]; vector<int> g[1010]; pair<int, int> v[2010]; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); int i, j, n, k, l, m; cin >> n >> m; for (i = 0; i < n; i++) { cin >> v[i].first; v[i].second = i + 1; } for (i = 0; i < m; i++) ...
3
#include <bits/stdc++.h> using namespace std; inline void add(int &x, int y) { x += y; if (x >= 1000000007) x -= 1000000007; } int u[260], v[260]; map<int, int> mp; int sz; inline int get_id(int x) { if (!mp[x]) mp[x] = (int)mp.size(); return mp[x]; } vector<int> e[260]; void addedge(int u, int v) { e[u].push...
10
#include <bits/stdc++.h> using namespace std; char c, str[1148576], temp[1148576]; int main() { int i, j, k, cnt = 0, flag; while (gets(temp) != NULL) { flag = 0; for (i = 0; temp[i]; ++i) { if (temp[i] != ' ' && temp[i] != '#') break; if (temp[i] == '#') flag = 1; } if (flag == 1 && cnt...
4
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); int n; cin >> n; long long a[n], xr = 0; map<long long, long long> m1, m2; for (int i = 0; i < n; i++) { cin >> a[i]; xr = xr ^ a[i]; if (i % 2 == 0) m1[xr]++; else m2[xr]++;...
4
#include <bits/stdc++.h> using namespace std; long long n, k, cs, cd, mij; string s; int main() { std::srand(std::time(nullptr)); cin >> n >> k; while (1) { cs = 1; cd = n; while (1) { cs = max(1LL, cs - 2 * k); cd = min(n, cd + 2 * k); mij = (cs + cd) / 2LL; if (cd - cs <= 100...
6
#include <bits/stdc++.h> using namespace std; int main() { int n; int f, s; cin >> n; string arr[] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", ...
1
#include <bits/stdc++.h> using namespace std; double fib(double x, double z); string bn(long long x); string kok(long long x); long long kok(string x); long long bn(string x); long long po(long long x, long long y, long long mod); int main() { ios::sync_with_stdio(false); cin.tie(0); vector<int> x, zz; map<int,...
3
#include <bits/stdc++.h> using namespace std; int const N = 5e5 + 20, INF = 1e9; int n, m, a[N], val[N << 2], mn[N << 2], ans[N]; pair<int, int> q[N]; vector<int> v[N]; map<int, int> last; void build(int v = 1, int b = 0, int e = n) { if (b == e - 1) { val[v] = INF; mn[v] = INF; return; } int mid = b ...
6
#include <bits/stdc++.h> using namespace std; string sy; int com(string s1, string s2) { if (s1.size() != s2.size()) return 0; for (int i = 0; i < s1.size(); i++) { if (s1[i] != s2[i]) return 0; } return 1; } int pr(int st, int en, string s1) { int st1 = 0, en1 = 0; for (int i = 0; i < s1.size(); i++) {...
6
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (a == 0) return b; else { return gcd(b % a, a); } } int main() { long long t; cin >> t; for (long long i = 0; i < t; ++i) { long long n; cin >> n; cout << (4 * n) / gcd(n + 1, 4 * n) + 1 << endl; ...
2
#include <bits/stdc++.h> using namespace std; bool isPal(string); int main() { string str; cin >> str; string ans = ""; vector<char> ma(str.size(), 'a'); char maxi = 'a'; for (int i = str.size() - 1; i >= 0; i--) { maxi = max(maxi, str[i]); ma[i] = maxi; } for (int i = 0; i < str.size(); i++) { ...
1
#include <bits/stdc++.h> using namespace std; template <typename T> T gcd(T x, T y) { if (x < y) swap(x, y); while (y > 0) { T f = x % y; x = y; y = f; } return x; } const int maxn = 100007; int BLOCKSIZE = 350; set<int> s[maxn]; int a[maxn]; int nxt[maxn]; int prv[maxn]; int n, m; long long b[maxn]...
9
#include <bits/stdc++.h> using namespace std; const long long fx[] = {+1, -1, +0, +0}; const long long fy[] = {+0, +0, +1, -1}; const long long N = 1e6 + 5, K = 20, mod = 1000000007, MOD = 1000000007, INF = LLONG_MAX / 2; long long CeilIndex(std::vector<long long>& v, long long l, long long r, ...
3
#include <bits/stdc++.h> using namespace std; const long long int N = 1e6 + 5, mod = 998244353, bit = 60; long long int solve(long long int n) { set<long long int> ms; for (int i = 0; i <= n; i++) { for (int j = 0; j + i <= n; j++) { for (int k = 0; k + j + i <= n; k++) { int l = n - (k + j + i); ...
6
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; string a[1000], b[1000]; for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; } for (int i = 0; i < m; i++) { string cmd, ip, tip; cin >> cmd >> ip; for (int i = 0; i < ip.size() - 1; i++) tip += ip[i]; for...
0
#include <bits/stdc++.h> using namespace std; const long long N = 1e6; long long a[N]; signed main() { long long T; cin >> T; while (T--) { long long n; cin >> n; string stl, str; cin >> stl >> str; bool f = 0; for (long long i = 0; i < n; i++) { if (stl[i] == '1' && str[i] == '1') f...
0
#include <bits/stdc++.h> using namespace std; const int oo = 0x3f3f3f3f; const int maxn = 1e4, max_num = 1e5; int fpm(long long b, long long e, const int &m) { long long t = 1; for (; e; e >>= 1, (b *= b) %= m) if (e & 1) (t *= b) %= m; return t; } int gcd(int first, int second) { while (second) second ^= f...
9
#include <bits/stdc++.h> using namespace std; int can[1010][1010], f[1010][1010][2], a[1010]; inline int read() { char c = getchar(); int x = 0, flag = 1; while (!isdigit(c)) { if (c == '-') flag = -1; c = getchar(); } while (isdigit(c)) x = x * 10 + c - '0', c = getchar(); return x * flag; } int gg...
6
#include <bits/stdc++.h> using namespace std; int mp[8000010]; vector<int> vec; int iCnt = 1; void compress() { sort(vec.begin(), vec.end()); iCnt = 1; for (int i = 0; i < vec.size(); i++) { mp[vec[i]] = iCnt; iCnt += 3; } } pair<int, int> pArr[8000010]; bool nisi[8000010]; int lineSweepArr[8000010]; vo...
4
#include <bits/stdc++.h> using namespace std; const int N = 100009; int sol, qs[N], qe[N], sorted[N], ans[N], a[N], s, e; unordered_map<int, int> freq; void add(int el) { sol -= !(freq[el] ^ el); freq[el]++; sol += !(freq[el] ^ el); } void remove(int el) { sol -= !(freq[el] ^ el); freq[el]--; sol += !(freq[...
5
#include <bits/stdc++.h> using namespace std; int main() { int a, n, m, cs; cin >> n >> m; if (n & 1) { cs = (n + 1) / 2; if (m >= cs) a = m - 1; else a = m + 1; } else { cs = n / 2; if (m > cs) a = m - 1; else a = m + 1; } if (n == 1) a = 1; cout << a; re...
2
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; const long long inf = 2147383647; const double pi = 2 * acos(0.0); const double eps = 1e-9; struct debugger { template <typename T> debugger& operator,(const T& v) { cerr << v << " "; return *this; } } dbg; inline long long gcd(long ...
2
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double eps = 1e-9; const int mod = 1e9 + 7; const long long INF = 1e12 + 1; const int N = 2e5 + 9; int n, mx; int a[N]; bool b[N]; vector<int> v; int main() { ios_base ::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n; for (in...
7
#include <bits/stdc++.h> using namespace std; long long int n, k, v, m, ans, sum, sum1, l, r, mx = -1111111111, mn = 9999999999, mnn = 9, mxx = -1, c, z, x, y, a[555555], d[1555555], t[1111111]; long double w; string s, sos, ss, str; char ch[111][111], chel, cha; bool used[1111111]; int main() { ios_base::syn...
1
#include <bits/stdc++.h> using namespace std; const double PI = 3.141592653589793238462643383279502884197169399375105820974944; int startwithone(char str[][105], int n) { int ans = 0; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) if ((i + j) % 2 && str[i][j] == '1') ans++; else...
3
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; int in() { int x; cin >> x; return x; } long long lin() { long long x; cin >> x; return x; } template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chm...
1
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { int n; cin >> n; string s; cin >...
4
#include <bits/stdc++.h> using namespace std; int main() { int ar[3000], Max[3000][2], Min; int b, n, c = 0; cin >> n >> b; int ans = b; Max[0][0] = -1; for (int i = 0; i < n; i++) { cin >> ar[i]; if (ar[i] >= Max[c][0]) { if (i == 0) Max[c][0] = ar[i]; else Max[++c][0] =...
3
#include <bits/stdc++.h> using namespace std; int main() { cout << "2000\n"; for (int i = 1; i <= 1000; ++i) cout << i << " 1" << " " << i << " 2" << '\n'; for (int i = 1000; i > 0; --i) cout << i << " 1" << " " << i << " 2" << '\n'; return 0; }
4
#include <bits/stdc++.h> using namespace std; struct st { int wei, zhi; }; long long p = 3332227, q = 10000007, p1 = 2, q1 = 1000000007, p2 = 7766332, q2 = 99999997, now1 = 1, now2 = 1, now3 = 1; string s, t; int sum2, j, len, m, ha[30], ha1[30], ha2[30], i, sum, sum1, ke[20000][4], fangan[30], e, hj[20...
7
#include <bits/stdc++.h> using namespace std; inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; } const int nINF = 1 << 31; const int MAXN = 2010; const int INF = 1000000000; class node { public: int v, f, couple; pair<int, int> w; node(int V, pair<int, int> W, int F, int CC) { v = V; w = W...
9
#include <bits/stdc++.h> using namespace std; const int P = 1e9 + 7, INF = 0x3f3f3f3f; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long qpow(long long a, long long n) { long long r = 1 % P; for (a %= P; n; a = a * a % P, n >>= 1) if (n & 1) r = r * a % P; return r; } long lo...
8
#include <bits/stdc++.h> using namespace std; int n, f[100001], nast[100001]; int find(int i) { return f[i] == i ? i : f[i] = find(f[i]); } void uni(int a, int b) { f[find(a)] = find(b); } int main() { scanf("%d", &n); if (n & 1) { printf("-1\n"); return 0; } for (int i = 0; i < n; i++) f[i] = i; for ...
10
#include <bits/stdc++.h> using namespace std; long long f1, v, sum, d[2][2005], c[2], to[2005][2005], g[2005][2005][2], P[2005][2005], val[2005][2005], r[2005]; struct lsh { int pos; long long x; } l[2005]; bool vst[2005][2005][2]; inline bool cmp(lsh aa, lsh bb) { return aa.x < bb.x; } int s, t, i, j, cnt, n, ...
10
#include <bits/stdc++.h> using namespace std; const long long INF = 1000 * 1000 * 1000; struct rib { long long b, u, c, f; size_t back; }; void add_rib(vector<vector<rib> >& g, long long a, long long b, long long u, long long c) { rib r1 = {b, u, c, 0, g[b].size()}; rib r2 = {a, 0, -c, 0, g[a].size...
8
#include <bits/stdc++.h> using namespace std; int main() { int n, k; vector<int> arr; scanf("%d%d", &n, &k); int x; map<int, int> mymap; for (int i = 0; i < n; i++) { scanf("%d", &x); if (mymap.find(x) != mymap.end() && mymap[x] == 1) continue; if (arr.size() < k) { arr.push_back(x); ...
1
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cout.tie(0); cin.tie(0); int n, m, q, c = 0; double x; cin >> n >> m >> x; string t, a[n]; map<char, int> v; vector<pair<int, int> > si; vector<double> all(26, INT_MAX); bool f = false; for (int i = 0; i < n; i++...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, k, b = 0, i, j, m, ans = 0; scanf("%d %d", &n, &k); bool prime[n + 1]; int primes[n]; memset(prime, true, sizeof(prime)); for (i = 2; i <= n; i++) { if (prime[i] == true) { primes[b] = i; b++; for (int j = i * 2; j <= n;...
1
#include <bits/stdc++.h> using namespace std; int a[200008], sign[200008]; int b[200008]; int main() { int n; scanf("%d", &n); int t; memset(a, 0, sizeof(a)); memset(sign, 0, sizeof(sign)); for (int i = 0; i < n; i++) { scanf("%d", &t); int k = t; int time = 0; b[i] = t; while (k) { ...
5
#include <bits/stdc++.h> using namespace std; const int d1[4][2] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}}; const int d2[4][2] = {{1, 1}, {-1, 1}, {-1, -1}, {1, -1}}; const int d3[4][2] = {{0, 0}, {-1, 0}, {-1, -1}, {0, -1}}; const int N = 200005; int n, m, top, ok[4]; map<int, int> mn, mx; struct P { int x, y; P() {} ...
9
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a; int ara[a]; for (int i = 0; i < a; i++) { cin >> ara[i]; } sort(ara, ara + a); for (int i = 0; i < a / 2; i++) { cout << ara[i] << " " << ara[a - i - 1] << " "; } if (a % 2 == 1) { cout << ara[a / 2] << " ";...
1
#include <bits/stdc++.h> using namespace std; inline double MTD(const double minutes) { return minutes / 60; } inline double rad(const double deg) { return (deg * (long double)acos(-1.0) / 180.0); } inline double deg(double rad) { if (rad < 0) rad += 2 * (long double)acos(-1.0); return (rad * 180) / (long double)...
3
#include <bits/stdc++.h> using namespace std; const double INF = 1000000000; const double EPS = 0.0000000001; int Nr(vector<double>& st, double a) { int n = st.size(); double il = (double)n * a - 10.0 * st[n - 1]; int odp = st[n - 1]; while (il >= 10.0) { il -= 10.0; ++odp; } return odp; } int main(...
5
#include <bits/stdc++.h> using namespace std; int arr[1005][1005]; int main() { int n; cin >> n; if (n == 4) { printf("-1\n"); return 0; } int m = n; if (!(n & 1)) n--; for (int i = 2; i <= n; i += 2) { arr[1][i] = 1; if (i + 1 <= n) { arr[i][i + 1] = 1; arr[i + 1][1] = 1; ...
7
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 2; vector<pair<int, int>> v[N]; int in_deg[N], maxi = 0, cnt = 0, n, first = 0; queue<pair<int, int>> q; void toplogical() { while (!q.empty()) { int x = q.front().first, lvl = q.front().second; if (lvl == n - 1) { first = 1; break;...
5
#include <bits/stdc++.h> using namespace std; void cnm() { while (1) printf("cnm!!n"); } const int N = 100 + 5; char a[N][N]; const char (*s)[N]; const char S5[][N] = {">...v", "v.<..", "..^..", ">....", "..^.<"}; const char S3[][N] = {">vv", "^<.", "^.<"}; void gen() { int i, j; for (i = 0; i < (100); ++i) f...
8
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10, N = 2e5; int a[maxn], b[maxn], val[maxn]; struct bit { int c[maxn]; void up(int x, int v) { for (; x <= N; x += x & -x) c[x] += v; } int qu(int x) { int cat = 0; for (; x; x -= x & -x) cat += c[x]; return cat; } } T1, T2;...
6
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:136777216") using namespace std; int bits(int x) { return x == 0 ? 0 : 1 + bits(x & (x - 1)); } const double PI = acos(-1.0); const double eps = 1e-9; const int INF = 1000000000; string nextString() { char buf[1000000]; scanf("%s", buf); return buf; } int d...
5
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; for (int i = 0; i <= n / 1234567; i++) { for (int j = 0; j <= n / 123456; j++) { if (1234567 * i + 123456 * j <= n) { long long x = n - (1234567 * i + 123456 * j); if (x % 1234 == 0) { cout <<...
2
#include <bits/stdc++.h> using namespace std; const int N = 10; vector<int> ld[N * N + 10]; double f[N * N + 10][2]; int id(int x, int y) { if (x & 1) return 10 * x + 10 - y; else return 10 * x + y + 1; } int main() { f[1][0] = f[1][1] = 0; for (int i = 2; i <= 7; ++i) f[i][0] = f[i][1] = 6; for (int ...
7
#include <bits/stdc++.h> using namespace std; long long i, j, x, y, z, ans, c, d, n, k; bool fun(long long v) { z = 0; y = 1; while (v) { z += v; v /= k; if (z >= n) return true; } return false; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> k; long...
3
#include <bits/stdc++.h> double p[23], mat[485][485], ans[485]; int l[23][23], pos[485], t[23][23]; int main() { int i, j, k, n, m, a, b, x, y, o = 0; double tmp; scanf("%d%d%d%d", &n, &m, &a, &b); for (i = 1; i <= m; i++) { scanf("%d%d", &x, &y); l[x][++l[x][0]] = y; l[y][++l[y][0]] = x; } for ...
9
#include <bits/stdc++.h> using namespace std; const int N = 100000 + 5; int s[N]; int main() { int n, k, a; cin >> n >> k; for (int i = 0; i < n; ++i) { cin >> a; s[i % k] += a; } int st = 0; for (int i = 0; i < k; ++i) { if (s[st] > s[i]) st = i; } cout << st + 1; }
2
#include <bits/stdc++.h> using namespace std; const int N = 10010; int n; pair<int, int> tab[N]; int main() { int t; scanf("%d %d", &n, &t); for (int i = 0; i < (n); ++i) { scanf("%d %d", &tab[i].first, &tab[i].second); } sort(tab, tab + n); int res = 2; for (int i = 0; i < (n - 1); ++i) { double ...
2
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; int n, k, cnt, a[2010], f[2010][(1 << 11) + 5]; int main() { scanf("%d%d", &n, &k); cnt = 1 << k; f[0][0] = 1; for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); for (int j = 0; j <= cnt; j += 2) { if (a[i] == 2 || a[i] == 0) {...
6
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << 6 * n * (n - 1) + 1; return 0; }
2
#include <bits/stdc++.h> using namespace std; const int MAXN = 100000 + 86; vector<int> f[MAXN]; double dfs(int d, int r, int p) { double tot = 1.0 / d; for (int i = 0; i < (int)f[r].size(); ++i) { if (f[r][i] == p) continue; tot += dfs(d + 1, f[r][i], r); } return tot; } int main() { int n; int a, ...
7
#include<bits/stdc++.h> using namespace std; int main(){ int v; cin>>v; while (v--){ int n; cin>>n; int dem1[1000],dem2[1000],hoa[1000]; for (int i=1; i<=n; i++) { dem1[i]=(n-1)/2; dem2[i]=dem1[i]; hoa[i]=n-1-dem1[i]-dem2[i]; } for (int i=1; i<n; i++) { int t=1; for (int j=1; j<=dem1[i]; j++) { ...
3
#include <bits/stdc++.h> using namespace std; const int MAXN = (1 << 6); int cmp[MAXN][MAXN]; int tab[MAXN]; int n; void read() { for (int i = 0; i < MAXN; i++) for (int j = 0; j < MAXN; j++) cmp[i][j] = 0; scanf("%d", &n); for (int i = 0; i < n * (n - 1) / 2 - 1; i++) { int x, y; scanf("%d%d", &x, &y...
2
#include <bits/stdc++.h> using namespace std; const int N = 100005; int a[N]; int main() { int t; scanf("%d", &t); while (t--) { int n; scanf("%d", &n); int res = 0; for (int i = 1; i <= n; ++i) scanf("%d", &a[i]), res ^= a[i]; if (res == 0) { puts("DRAW"); } else { int s = 0, ...
5
#include <bits/stdc++.h> using namespace std; long long t, a, b, c, d; signed main() { scanf("%lld", &t); while (t--) { scanf("%lld%lld%lld%lld", &a, &b, &c, &d); long long qwq = (a & 1) + (b & 1) + (c & 1) + (d & 1); if ((qwq > 1 && !min(a, min(b, c))) || qwq == 2) puts("No"); else puts...
1
#include <bits/stdc++.h> using namespace std; int id[20] = {0, 1, 2}; int neg[20], n2[20]; double a[20], b[20], ans[20]; int cnt = 0; string fuck[] = {"x^y^z", "x^z^y", "(x^y)^z", "(x^z)^y", "y^x^z", "y^z^x", "(y^x)^z", "(y^z)^x", "z^x^y", "z^y^x", "(z^x)^y", "(z^y)^x"}; struct data { ...
8
#include <bits/stdc++.h> int parent_digit(int arr[][7], int i) { int j1, j2, counter, c; counter = 0; for (j1 = 0; j1 < 10; j1++) { c = 0; for (j2 = 0; j2 < 7; j2++) { if (arr[j1][j2] - arr[i][j2] == -1) { c = -1; break; } } if (c != -1) { counter += 1; } } ...
1
#include <bits/stdc++.h> using namespace std; const long long int mod = 998244353; const long double error = 2e-6; const long double PI = acosl(-1); mt19937 rng((unsigned)chrono::system_clock::now().time_since_epoch().count()); inline long long int MOD(long long int x, long long int m = mod) { long long int y = x % m...
11
#include <bits/stdc++.h> #include <unordered_map> using namespace std; typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<ll> vll; typedef pair<int, int> ii; typedef pair<int, ii> iii; typedef vector<ii> vii; typedef set<int> si; typedef map<string, int...
2
#include <bits/stdc++.h> using namespace std; long long read() { long long a = 0, b = getchar(), c = 1; while (!isdigit(b)) c = b == '-' ? -1 : 1, b = getchar(); while (isdigit(b)) a = a * 10 + b - '0', b = getchar(); return a * c; } const int N = 1e6 + 5; long long n, r1, r2, r3, d, a[N], p1[N], p2[N], dp[N]; ...
7
#include <bits/stdc++.h> using namespace std; int n; double ans = 0; double len = 0; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { double p; scanf("%lf", &p); ans += p * (2 * len + 1); len = (len + 1) * p; } printf("%.10lf\n", ans); return 0; }
6
#include <bits/stdc++.h> using namespace std; long long m0 = 0, m1 = 0; vector<long long> v0, v1, v2; int main() { long long q, n, i, j, cnt = 0, l, r, one = 0, zero = 0, even = 0, odd = 0, total = 0; string s; cin >> n >> q; cin >> s; v0.push_back(0); v1.push_back(0); long long p ...
4
#include <bits/stdc++.h> using namespace std; int num[5010]; vector<int> ve; int main() { int n; while (cin >> n) { int maxvar = 0; memset(num, 0, sizeof(num)); ve.clear(); for (int i = 0; i < n; ++i) { int x; cin >> x; ++num[x]; maxvar = max(maxvar, x); } for (int i ...
1
#include <bits/stdc++.h> int dx[] = {-1, -1, -1, 0, 1, 1, 1, 0}; int dy[] = {-1, 0, 1, 1, 1, 0, -1, -1}; using namespace std; long long power(long long a, long long p, long long M) { long long r = 1; a = a % M; while (p > 0) { if (p % 2) r = (r * a) % M; a = (a * a) % M; p /= 2; } return r; } long...
4
#include <bits/stdc++.h> using namespace std; struct SNM { vector<SNM*> trgs; vector<SNM*> rv_trgs; int stype; bool asgn; bool used; void asgnN() { if (asgn) return; asgn = true; for (vector<SNM*>::iterator i = trgs.begin(); i != trgs.end(); i++) { (*i)->asgnN(); } } void usedN() {...
4
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); char s[1000], a[1000]; int l, k = 0, x, cnt = 0; scanf("%[^\n]s", &s[0]); l = strlen(s); for (int i = 0; i < l; i++) { if (s[i] >= 97 && s[i] <= 122) { a[k] = s[i]; k++; } } ...
0
#include <bits/stdc++.h> using namespace std; int n, m; bool can[30][30]; int sx, sy; struct state { int x, y, st; }; int x[10], y[10], w[10], mp[10]; int tot = 0; int bx[10], by[10]; int btot = 0; int dp[30][30][256]; int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; int sum[256]; int main() { scanf("%d %d\n", &...
9
#include <bits/stdc++.h> using namespace std; int main() { int a; cin >> a; if (a % 2 == 0) { cout << "0" << endl; return 0; } cout << "1" << endl; }
0
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int i, n, flag = 0; cin >> n; vector<int> a(n); for (i = 0; i < n; i++) { cin >> a[i]; if (i && a[i] >= a[i - 1]) flag = 1; } if (flag) cout << "YES" << endl; else cout << ...
0
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:100000000000,100000000000") using namespace std; const double eps = 1E-9; const double Exp = 2.718281828459045; const double Pi = 3.1415926535897932; const int NMAX = 100000 + 5; const int MMAX = 300 + 5; const int INF = 1000000000; const int BASE = 1000000007; t...
7
#include <bits/stdc++.h> using namespace std; int i, j, m, n, p, k, l, ans[300005]; struct Node { int a[5]; void read() { int i; for (i = 0; i < 5; ++i) scanf("%d", &a[i]); } } A[300005]; int main() { scanf("%d", &n); for (i = 1; i <= n; ++i) A[i].read(); if (n >= 100) printf("%d\n", 0); else ...
4