solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; using ll = long long; const int MAX_N = 2e5 + 9; void fixit(string &s) { string tmp = s; while (tmp.size() > 0 && tmp.back() == ' ') tmp.pop_back(); reverse(tmp.begin(), tmp.end()); while (tmp.size() > 0 && tmp.back() == ' ') tmp.pop_back(); reverse(tmp.begin(), t...
3
#include<bits/stdc++.h> using namespace std; long long e[100002]; int main() { long long a,b,c,d=0,i; cin>>a>>b>>c; for(i=1;i<=a;i++) { cin>>e[i]; if(e[i]<b||e[i]>=c) d++; } cout<<d; cout<<endl; }
0
#include<bits/stdc++.h> using namespace std; int m,n,i,j,ans; int main() { scanf("%d%d",&m,&n); for(j=1;j<=m;j++) for(i=1;i<=n;i++) if(i%10>=2&&i/10>=2&&j==(i%10)*(i/10)) ans++; printf("%d\n",ans); return 0; }
0
#include <bits/stdc++.h> const long long mod = 1e9 + 7; const int x = 1; using namespace std; long long qpow(long long a, long long b) { long long res = 1; while (b) { if (b & 1) res *= a, res %= mod; a *= a; a %= mod; b >>= 1; } return res; } long long isprime(long long n) { int i; if (n ==...
2
#include <iostream> #include <vector> using namespace std; typedef long long ll; ll num_digit(ll n){ ll nd = 0; for(nd = 0; n > 0; ++nd){ n /= 10; } return nd; } ll sn(ll n){ ll ret = 0; while(n > 0){ ret += n % 10; n /= 10; } return ret; } ll f(ll x){ ll ...
0
#include <iostream> using namespace std; int B[102][102]; bool maze = false; void DFS(int Y, int X, int YG, int XG, int C) { if(B[Y][X]!=C || C==0) return; if(Y==YG && X==XG) maze = true; B[Y][X] = 0; DFS(Y-1, X , YG, XG, C); DFS(Y , X+1, YG, XG, C); DFS(Y+1, X , YG, XG, C); DFS(Y , X-1, ...
0
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 200005; int n, m, a[N]; ll b[N], r; int main(){ scanf("%d%d", &n, &m); for(int i = 1; i <= n; i++){ scanf("%d", a + i); if(i > 1){ int x = a[i - 1], y = a[i]; if(x > y) y += m; ...
0
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma") #pragma GCC optimize("unroll-loops") using namespace std; double eps = 1e-12; long long hcf(long long p, long long q) { if (p > q) return hcf(q, p); if (!p) return q; return hcf(q % p,...
4
#include <bits/stdc++.h> using namespace std; const int INF = 2147483647; int n, i, sum, s, tab[105]; vector<int> c; int main() { scanf("%d", &n); sum = 0; s = 0; c.clear(); for (i = 0; i < n; i++) { scanf("%d", &tab[i]); sum += tab[i]; if (i == 0 || tab[i] * 2 <= tab[0]) { s += tab[i]; ...
1
#define _USE_MATH_DEFINES #include <cstdio> #include <cstdlib> #include <iostream> #include <cmath> #include <cstring> #include <algorithm> #include <vector> #include <queue> #include <map> using namespace std; typedef pair<long long int, long long int> P; long long int INF = 1e18; long long int MOD = 1e9 + 7; lon...
0
#include <bits/stdc++.h> using namespace std; int a[3005], b[3005]; long long dp[3005][3005]; int main() { int n; while (~scanf("%d", &n)) { memset(dp, 0, sizeof(dp)); 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 len =...
3
#include <bits/stdc++.h> using namespace std; void Fast_Read_Out() { ios_base::sync_with_stdio(0); cin.tie(), cout.tie(); } void Random() { unsigned int seed; asm("rdtsc" : "=A"(seed)); srand(seed); } unsigned int Time() { unsigned int time = clock() / 1000.00; return time; } const int inf = int(1e9) + 12...
3
#include <iostream> #include <vector> #include <algorithm> using namespace std; #pragma warning (disable: 4996) int N, A[1 << 18]; int minx = (1 << 30), minid = 0; int main() { scanf("%d", &N); for (int i = 1; i <= N; i++) { scanf("%d", &A[i]); if (minx > A[i]) { minx = A[i]; minid = i; } } cout << minid << e...
0
#include<iostream> #include<algorithm> using namespace std; int main() { int S[100000]; int numS; cin >> numS; for (int i = 0; i < numS; i++) { cin >> S[i]; } int numT; int sum = 0; cin >> numT; for (int i = 0; i < numT; i++) { int key; cin >> key; if (*lower_bound(S, S + numS, key) == key) sum++; ...
0
#include <bits/stdc++.h> int min(int a, int b) { if (a > b) return b; else return a; } int main() { int n, m, a[101], b[101][101], i, j, r, sum, x, y; scanf("%d%d", &n, &m); for (i = 0; i < n; i++) scanf("%d", &a[i]); memset(b, 0, sizeof(b)); for (i = 0; i < m; i++) { scanf("%d%d", &x, &y); ...
1
#include <bits/stdc++.h> using namespace std; priority_queue<long long> P; long long abs1(long long x) { if (x < 0) return -x; return x; } long long xx[1002], yy[1002]; int main() { int n; long long x, y; scanf("%d%I64d%I64d", &n, &x, &y); int T = x + y; for (int i = 1; i <= n; i++) scanf("%I64d", &xx[i])...
2
#include <bits/stdc++.h> using namespace std; const int maxN = 3e5 + 5; long long n, a[maxN], k; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k; for (int i = 1; i <= n; ++i) cin >> a[i]; priority_queue<long long> pq; long long Sum = 0; for (int i = n; i >= 2; --i) { Sum...
3
#include <bits/stdc++.h> #define all(A) begin(A), end(A) #define rall(A) rbegin(A), rend(A) #define sz(A) int(A.size()) using namespace std; typedef long long ll; typedef pair <int, int> pii; int m; int get (const string& s) { int n = (int) s.size(); vector <int> z(n); for (int i = 1, l = 0, r = 0; i < n; i+...
0
#include <bits/stdc++.h> using namespace std; const int N = 1e5; struct node { int id; }; node a, b, c; int xr[N], d[N]; int mark[N]; int vis[N]; vector<int> mp[N]; set<pair<int, int> > st; int main() { int n, s, m = 0, k = 0; queue<node> q; ; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d%d",...
3
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m, k; cin >> n >> m >> k; set<int> v[k + 1]; vector<int> in(k + 1, 0); vector<int> out(k + 1, 0); auto add_edge = [&](int a, int b) { if (v[a].find(b) != v[a].end()) return; v[a].insert(b); ...
6
#include <bits/stdc++.h> int main() { int n, m, i; scanf("%d %d", &n, &m); char s[5]; int flag = 0; m = m * n; for (i = 0; i < m; i++) { scanf("%s", &s); if (s[0] == 'C' || s[0] == 'M' || s[0] == 'Y') { flag = 1; } } if (flag == 0) printf("#Black&White\n"); else printf("#Colo...
1
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int n; cin >> n; char ch[100][100]; for (int i = 0; i != n; ++i) { for (int j = 0; j != n; ++j) { cin >> ch[i][j]; } } int flag = 0; int sum = 0; for (int i = 0; i != n; ++i) { int rflag = 0; ...
3
#include <bits/stdc++.h> using namespace std; const long long maxn = 100100, mod = 1e9 + 7, maxs = 321, maxa = 1e6 + 100, maxb = 24; const long long inf = 2e18 + 4; long long max(long long x, long long y) { return (x > y ? x : y); } long long min(long long x, long long y) { return (x < y ? x : y); } lon...
3
#include <bits/stdc++.h> using namespace std; bool f1, f6, f8, f9; int main() { string s; cin >> s; int n = s.size(); string ns = ""; int p = 0; int st = 1; for (int i = 0; i < n; i++) { if (s[i] == '1' && !f1) { f1 = true; } else if (s[i] == '6' && !f6) { f6 = true; } else if (s[i...
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; vector<string> mas(n); for (int i = 0; i < n; ++i) { cin >> mas[i]; } for (int i = 0; i < m; ++i) { string last = ""; for (int j = 0; j < n; ++j) { ...
1
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a, h, x, y; bool flag = false; for (int i = 0; i < n; i++) { cin >> x >> y; if (flag) continue; if (i == 0) h = max(x, y); else { a = max(x, y); if (a <= h) h = a; else { a =...
2
#include <bits/stdc++.h> using namespace std; const int N=505; int A[N][N], D[31][31]; int dp[3][31]; int main() { int n,c; cin >> n >> c; for (int i=0; i<c; i++) { for (int j=0; j<c; j++) { cin >> D[i][j]; } } for (int i=0; i<n; i++) { for (int j=0; j<n; j++) { cin >> A[i][j]; A[i][j]--; } } ...
0
#include <bits/stdc++.h> int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n, k; std::cin >> n >> k; int b = std::sqrt(n), bl = (n + b - 1) / b; std::vector<std::vector<int>> a(n); std::vector<int64_t> sum(n); std::vector<std::vector<int64_t>> pre(bl + 1, std::vector<int64_t>(k +...
4
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const long long maxn = 150; const long long alpha = 29; const long long bsz = 400; const long long maxv = 200; const long long maxlog = 30; void init() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); } int dp[maxn][maxn][maxn][2]; int main...
1
#include<bits/stdc++.h> #pragma GCC optimize("O3") #define maxn 8000 using namespace std; long long mod=1000000007; long long a[maxn]; long long b[maxn]; int n; int p[maxn]; bool vis[maxn]; int inc[maxn]; vector<int> c[maxn]; long long step[maxn]; int main() { scanf("%d",&n); for(int i=1;i<=n;i++) { c[i...
0
#include <bits/stdc++.h> using namespace std; int main() { string s, s1; map<string, int> mp; mp["monday"] = 1; mp["tuesday"] = 2; mp["wednesday"] = 3; mp["thursday"] = 4; mp["friday"] = 5; mp["saturday"] = 6; mp["sunday"] = 7; cin >> s >> s1; int temp = mp[s1] - mp[s]; if (temp >= 0) { if (...
1
#include <bits/stdc++.h> using namespace std; const int N = 2010; int f[N][N]; int a[N]; int n, mod, l, r; int get(int x) { return (x % mod + mod) % mod; } int check(int x) { if (x >= l && x <= r) return 1; return 0; } int main() { ios ::sync_with_stdio(false); cin.tie(0); cin >> n >> mod >> l >> r; for (in...
5
#include <bits/stdc++.h> using namespace std; int father[1000001]; int degree[1000001]; int setCount; int findset(int x) { if (x != father[x]) father[x] = findset(father[x]); return father[x]; } int unionset(int a, int b) { int x = findset(a); int y = findset(b); if (x != y) { father[y] = x; setCount-...
3
#include<bits/stdc++.h> #define rep(i,n) for(int i=0;i<n;i++) #define lint long long using namespace std; int q,m=1000000007; lint x,y,f[99]={0,1,1}; int main(){ scanf("%d",&q); rep(i,96)f[i+3]=f[i+1]+f[i+2]; rep(i,q){ scanf("%lld %lld",&x,&y); if(x>y)swap(x,y); if(y<=2){ printf("1 %d ",y==1?1:x==1?2:4); ...
0
#include <bits/stdc++.h> using namespace std; int a[300005], b[300005], n, name[300005]; bool done[300005]; int main() { cin >> n; for (int i = 0, _e(n); i < _e; i++) cin >> a[i]; for (int i = 0, _e(n); i < _e; i++) cin >> b[i]; for (int i = 0, _e(n); i < _e; i++) name[b[i]] = i + 1; for (int i = 0, _e(n); i ...
3
#include <iostream> using namespace std; int main(){ while(true){ int floor = 1; double vc; cin >> vc; if(cin.eof()) break; for(floor;vc*vc>19.6*(5*(double)floor-5);floor++) ; cout << floor << endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; const int oo = (int)1e9; const double PI = 2 * acos(0.0); const double eps = 1e-9; int pfreq[128], curfreq[128]; int match() { for (int i = 'a'; i < 'z' + 1; ++i) { if (curfreq[i] > pfreq[i]) return 0; } return 1; } int main() { string s, p; cin >> s >> p; i...
3
#include<iostream> #include<stack> using namespace std; char mat[500][500]; int dp[500][500]; int h, w; int solve(){ int ret = -1; for(int i = 0; i < h; i++){ // 長方形の左端、高さを積む stack<pair<int,int> > s; for(int j = 0; j < w; j++){ if(s.empty()){ s.push({j, dp[...
0
#include <bits/stdc++.h> using namespace std; vector<int> v; vector<int>::iterator it; int main() { long long int n, r, i, k = 2, m, p = 1, a, b, flag = 0, j, temp; cin >> n; m = n; if (n == 2) { cout << 1 << endl << 1; return 0; } if (n == 3) { cout << 2 << endl << "1 3"; return 0; } if...
1
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007; long long INF = 1e18; bool comp1(pair<long long, pair<long long, long long> > a, pair<long long, pair<long long, long long> > b) { return a.second.first > b.second.first; } bool comp2(pair<long long, pair<long long, long long> > a, ...
4
#include <bits/stdc++.h> using namespace std; long long val[100005][105]; int n, m; long long modpow(long long x, long long n) { long long res = 1; while (n > 0) { if (n & 1) res = res * x % 1000000007; x = x * x % 1000000007; n >>= 1; } return res; } long long F[100005], R[100005]; void make() { ...
5
#include<bits/stdc++.h> using namespace std; int n, a[500100], f[500100]; char s[500100]; int main() { scanf("%d%s", &n, s + 1); for(int i = 1; i <= n; i++) { a[i] = s[i] - '0'; } for(int i = 3, lp = 0; i <= n; i++) { f[i] = f[i - 1]; if(a[i] && !a[i - 1] && a[i - 2]) { lp = i; for(int j = i - 2; a[j]...
0
#include<bits/stdc++.h> using namespace std; long long a,b; int main() { cin>>a>>b; cout<<a-(b<a)<<endl; }
0
#include <bits/stdc++.h> using namespace std; int main() { int T; cin>>T; for(int i=0;i<T;i++){ int N; int64_t Z=0; cin>>N; vector<pair<int,int64_t>> l; vector<pair<int,int64_t>> r; for(int i=0;i<N;i++){ int a; int64_t b,c; cin>>a>>b>>c; if(b>c){ Z+=c; ...
0
#include <bits/stdc++.h> #pragma comment(linker, "/stack:32000000") using namespace std; const int INF = 2147483647; const long long LLINF = 9223372036854775807LL; const int maxn = 2010; int ti[maxn]; int hi[maxn]; int mi[maxn]; int u[maxn]; int main() { int n, first; scanf("%d%d", &n, &first); for (int i = 0; i ...
1
#include <bits/stdc++.h> using namespace std; const int INF = INT_MAX; const bool debug = true; const long long INFL = LLONG_MAX; const int output_precision = 15; stringstream ss; int X[11000], Y[10100], x, y; int main() { ios_base::sync_with_stdio(0); cout.precision(output_precision); cout << fixed; ss.precisi...
1
#include <bits/stdc++.h> using namespace std; template <class A, class B> A convert(B x) { stringstream ss; ss << x; A ret; ss >> ret; return ret; } const int oo = ~0u >> 2; const double eps = 1e-10; const int mn = 1000, mo = 100000007; const int fx[8][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}, ...
5
#include <bits/stdc++.h> using namespace std; pair<int, int> a[100007]; int val[100007], n, k; map<int, int> id; set<int> S; vector<int> adj[100007]; bool d[100007]; void dfs(int u) { cout << val[u] << " "; d[u] = 1; for (auto v : adj[u]) if (!d[v]) dfs(v); } int main() { cin >> n; for (int i = 1; i <= n;...
3
#include <iostream> #include <string> #include <vector> #include <numeric> using namespace std; int left_to_right(string s) { int n = s[0]-'0'; for (int i=0; i<(int)s.length()/2; i++) { int right = s[2*i+2]-'0'; if (s[2*i+1] == '+') { n += right; } else { ...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 100 + 10, mod = 1e9 + 7, INF = 0x3f3f3f3f; bool e[maxn][maxn]; map<string, int> id; int n, ans, tot, num, cnt[maxn], vis[maxn], a[maxn]; string t; bool dfs(int u, int dep) { for (int v = u + 1; v <= n; ++v) { if (cnt[v] + dep <= ans) return 0; if ...
5
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 5e5; bool viz[1 + N]; int p[1 + N]; vector<int> lev[1 + N]; vector<int> gr[1 + N]; void dfs(int node, int par, int level) { viz[node] = true; p[node] = par; lev[level].push_back(node); for (int vec : gr[node]) if (not viz[vec]...
5
#include <bits/stdc++.h> using namespace std; inline int read() { char c = getchar(); int f = 1; int ans = 0; while (c > '9' || c < '0') { if (c == '-') f = -f; c = getchar(); } while (c <= '9' && c >= '0') { ans = ans * 10 + c - '0'; c = getchar(); } return ans * f; } int a[105], b[105]...
3
#include <bits/stdc++.h> using namespace std; int nowx[1010], nowy[1010], tarx[1010], tary[1010], n; int ansx[20 * 1010], ansy[20 * 1010], cnt = 0; bool ok[1010][1010], tarok[1010][1010]; vector<int> t1, t2; void sol(vector<int> &t) { int d = t.size(); if (d <= 3) return; int nbest = 0, dx = -1, dy = -1; for (i...
5
#include <bits/stdc++.h> using namespace std; using ll = long long; ll mod = 998244353; ll mod_pow(ll x, ll n, ll mod) { ll res = 1; while (n > 0) { if (n & 1) { res = res * x % mod; } x = x * x % mod; n >>= 1; } return res; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); ll...
5
#include <bits/stdc++.h> using namespace std; template <class T> inline void read(T &x) { int f = 0; x = 0; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) f |= (ch == '-'); for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0'; if (f) x = -x; } const int N = 100005; int T[N << 2], ans[N], n, ...
6
#include <bits/stdc++.h> using namespace std; int R, S; char grid[155][155]; bool nispe[155]; pair<int, int> niz[160]; int main(void) { scanf("%d%d", &R, &S); int last = 0; for (int i = 0; i < R; ++i) { scanf("%s", grid[i]); bool pwn = false; for (int j = 0; j < S; ++j) { if (grid[i][j] == 'W' &...
2
#include <bits/stdc++.h> using namespace std; bool subset[1001][1001]; bool isSubsetSum(int set[], int n, int sum) { for (int i = 0; i <= n; i++) subset[0][i] = true; for (int i = 1; i <= sum; i++) subset[i][0] = false; for (int i = 1; i <= sum; i++) { for (int j = 1; j <= n; j++) { subset[i][j] = subse...
2
#include <bits/stdc++.h> using namespace std; long long l[200005], r[200005]; vector<long long> p[30], suml[30], sumr[30]; int main() { long long n, sum = 0; cin >> n; string a, b; cin >> a >> b; a = " " + a; b = " " + b; for (long long i = n; i >= 1; i--) { sum += i * i; } for (long long i = 1; i...
3
/* HARDWORK IS THE KEY TO SUCCESS. RATING IS TEMPORARY , KNOWLEDGE IS PERMANENT.!!!*/ #include <bits/stdc++.h> using namespace std; #define int long long const int mod = 1e9 + 7; const int maxs = 103; const int MAXS = 1500; int a[maxs]; int fact[maxs]; int dp[maxs][maxs][MAXS]; int n,k; void pre() { fact[0] ...
0
#include<iostream> #include<string> #include<algorithm> using namespace std; string S; int main(){ cin>>S; reverse(S.begin(),S.end()); cout<<S<<endl; }
0
#include <bits/stdc++.h> using std::cin; using std::cout; using std::endl; using std::max; using std::min; long long W(long long x1, long long y1, long long x2, long long y2, bool v) { long long ans = 0; if (((x2 - x1 + 1) & 1) == 0 || ((y2 - y1 + 1) & 1) == 0 || ((x1 + y1) & 1)) ans = (x2 - x1 + 1) * (y2 - y1 ...
3
#include <bits/stdc++.h> using namespace std; int n, m, k; int c[2002]; vector<int> vec; int main() { cin >> n >> m >> k; for (int i = 1; i <= k; i++) { c[1]++; c[1 + n]--; vec.push_back(1); } for (int i = 2; i <= n + m + 1; i++) { c[i] += c[i - 1]; if (c[i] == 0) { vec.push_back(i - 1...
3
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int main() { ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0); cout << fixed << setprecision(15); int N; cin >> N; int R = 1; vector<int> ct; for (int p = 2; p * p <= N; p++) { ...
2
#include <bits/stdc++.h> using namespace std; constexpr int inf = 0x3f3f3f3f; int solve(const vector<int>& v) { int n = v.size(); vector<int> dp(n << 8 | 1, -inf); dp[0] = 0; for (int a : v) { auto ndp = dp; ndp[a] = 1; for (int i = 1; i < (int)dp.size(); ++i) { if (dp[i] == -inf) { ...
0
//kruskal tree #include <iostream> #include <iomanip> #include <vector> #include <algorithm> #include <cmath> using namespace std; #define M 9999 int parent[M],a[M],b[M]; pair<double,int>node[M]; int root(int a){return parent[a]==a?a:parent[a]=root(parent[a]);} int unite(int a,int b){ int x=root(a),y=root(b); if(x==y...
0
#include <bits/stdc++.h> using namespace std; void read(int& x) { bool fu = 0; char c; for (c = getchar(); c <= 32; c = getchar()) ; if (c == '-') fu = 1, c = getchar(); for (x = 0; c > 32; c = getchar()) x = x * 10 + c - '0'; if (fu) x = -x; }; char getc() { char c; for (c = getchar(); c <= 32; c =...
4
#include <bits/stdc++.h> using namespace std; int n, k; bool checkSurvive(char f[], char s[], int pos, int flooded) { if (pos < 0) { return false; } if (flooded >= pos) { return false; } if (pos > n - 1) { return true; } if (f[pos] != '-') { return false; } f[pos] = 'a'; bool jump = ...
2
#include <bits/stdc++.h> long long gcd(long long a, long long b) { if (!a) return b; return gcd(b % a, a); } int main() { long long n, a, b, c; scanf("%lld", &n); for (long long i = 1; i * i <= n; i++) if (n % i == 0 && gcd(i, n / i) == 1) { a = i; b = n / i; } printf("%lld %lld\n", a, b...
3
#include <iostream> #include <cstring> using namespace std; int f[7][7][7],N,M; int dx[] ={0,0,-1,1,0,-1,1,-1,1}; int dy[] ={0,-1,0,0,1,-1,-1,1,1}; int dfs(int x, int y, int z, int c,int m,int mz, bool d) { int s=1; int tx=x, ty=y,tz=z; if(d) tx+=dx[m], ty+=dy[m], tz+=mz; else tx-=dx[m], ty-=dy[m], tz-=mz; if(t...
0
#include <bits/stdc++.h> using namespace std; vector<int> get(int n, int m) { if (n == 1) { return vector<int>(1, 1); } vector<int> res; if (m >= (1 << (n - 2))) { res = get(n - 1, m - (1 << (n - 2))); res.push_back(0); } else { res = get(n - 1, m); res.insert(res.begin(), 0); } for (i...
2
#include<bits/stdc++.h> using namespace std; int main(){ char a; cin>>a; if(a=='A') cout<<'T'; if(a=='T') cout<<'A'; if(a=='G') cout<<'C'; if(a=='C') cout<<'G'; }
0
#include <bits/stdc++.h> using namespace std; template <typename T> T gcd(T a, T b) { if (a == 0) return b; return gcd(b % a, a); } template <typename T> T pow(T a, T b, long long m) { T ans = 1; while (b > 0) { if (b % 2 == 1) ans = (ans * a) % m; b /= 2; a = (a * a) % m; } return ans % m; } in...
4
#include <bits/stdc++.h> using namespace std; template <typename T> inline void Read(T &x) { char c = getchar(); bool f = false; for (x = 0; !isdigit(c); c = getchar()) { if (c == '-') { f = true; } } for (; isdigit(c); c = getchar()) { x = x * 10 + c - '0'; } if (f) { x = -x; } } ...
4
// Problem Statement: https://codeforces.com/contest/1474/problem/E/ /** * Author: Ravi Kanth Gojur * Code Forces: ravireddy07 * Code Chef: ravireddy115 * Github: ravireddy07 **/ #include <bits/stdc++.h> #define ll long long int #define ravireddy07 return #define ii(a) scanf("%d", &a) #define ii2(a, b) scanf...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 1e3 + 666; int n, p[maxn][6], len[maxn]; vector<int> rt; int main(void) { cin >> n; for (int i = 0; i < n; ++i) { for (int j = 0; j < 5; ++j) { scanf("%d", &p[i][j]); len[i] += p[i][j] * p[i][j]; } } if (n > 12) cout << 0 << ...
3
#include<iostream> #include<cstring> typedef long long ll; typedef long double ld; using namespace std; ll dx[] = {1, -1, 0, 0}; ll dy[] = { 0,0,1,-1 }; ll W, H; ll cnt; char field[100][100]; void dfs(ll y, ll x) { field[y][x] = '#'; for (ll k = 0; k < 4; k++) { ll ny = y + dy[k]; ll nx = x + dx[k]; if (ny >= 0...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; vector<vector<int> > T(n); for (int i = 0; i < n - 1; ++i) { int a, b; cin >> a >> b; --a; --b; T[a].push_back(b); T[b].push_back(a); } vector<bool> odw(n, false); stack<int>...
3
#include <bits/stdc++.h> using namespace std; int main() { int s, v1, v2, t1, t2; int first, second; cin >> s >> v1 >> v2 >> t1 >> t2; first = s * v1 + 2 * t1; second = s * v2 + 2 * t2; if (first < second) { cout << "First"; } else { if (first == second) cout << "Friendship"; else ...
1
#include <bits/stdc++.h> using namespace std; template <typename T, typename L> bool smax(T& x, L y) { return x < y ? (x = y, true) : false; } template <typename T, typename L> bool smin(T& x, L y) { return y < x ? (x = y, true) : false; } struct node { node *l, *r; int len, pref, suff, val; node() { l = ...
5
#include <bits/stdc++.h> using namespace std; long long modulo(long long base, long long exponent, long long modulus); long long choose(long long n, long long k); long long inverse(long long a, long long m); void build(); void fileio(); long long ncr(long long n, long long r); const int nax = 1e6 + 10; const int LG = l...
4
#include<cstdio> #include<vector> #define MAXN 2005 using namespace std; vector<int> G[MAXN]; int n,k,tot; void dfs(int u,int f,int dep) { if(dep>k) return ; tot++; for(int i=0;i<G[u].size();i++) { int v=G[u][i]; if(v==f) continue; dfs(v,u,dep+1); } } int main() { scanf("%d %d",&n,&k); for(int i=1;i<n;i+...
0
#include <bits/stdc++.h> using namespace std; const int N = 110, M = N * N, MOD = 1000 * 1000 * 1000 + 7; int n, a, s, ans, cnt[N], c[N][N], dp[2][N][M]; int sum(int a, int b) { a += b; if (a >= MOD) a -= MOD; return a; } int main() { ios::sync_with_stdio(false), cin.tie(0); fill(c[0], c[0] + N, 1); for (in...
2
#include <bits/stdc++.h> using namespace std; const int Dx[] = {0, 1, 0, -1}; const int Dy[] = {1, 0, -1, 0}; const int Ex[] = {0, 1, 0, -1, 1, 1, -1, -1}; const int Ey[] = {1, 0, -1, 0, 1, -1, 1, -1}; const int maxn = 2100; int n, A[maxn][maxn]; struct Tpair { int x, y; Tpair(int _x = 0, int _y = 0) { x = _x, y = ...
5
#include <bits/stdc++.h> using namespace std; inline int read() { int ret = 0; char ch = getchar(); while (!isdigit(ch)) ch = getchar(); while (isdigit(ch)) ret = (ret << 1) + (ret << 3) + ch - '0', ch = getchar(); return ret; } const int N = 1e5 + 5; pair<int, int> num[N * 6]; int n, m, ans; int a[8], b[N], ...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 100; const int mod = (int)1e9 + 7; const int maxlog = (int)20; const int P = mod; int n, q, timer; vector<int> g[maxn]; set<int> ans; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cin >> n >> q; while (q--) { int t, x; cin ...
3
#include <bits/stdc++.h> using namespace std; const int MAXH = 1010; int n, k; vector<int> arr; vector<int> ans; int best = -1, bestS0 = 0; int main() { cin >> n >> k; for (int i = 0; i < n; i++) { int x; cin >> x; arr.push_back(x); } for (int s0 = 1; s0 < MAXH; s0++) { int res = 0; for (int...
2
#include<bits/stdc++.h> using namespace std; # define int long long # define pb push_back # define in insert # define endl '\n' int SubArraySum( int arr[] , int n ) { int result = 0; // computing sum of subarray using formula for (int i=0; i<n; i++) result += (arr[i] * (i+1) * (n-i)); // return all subarray ...
3
#include <bits/stdc++.h> using namespace std; int fun(int x) { return (x > 0) ? x : -x; } int main() { int a[21][21], n, m, tt = 1, t = 0; cin >> n >> m; for (int i = 0; i <= n; i++) for (int j = 0; j <= m; j++) a[i][j] = 0; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { cin >> a[i][j...
2
#include <bits/stdc++.h> using namespace std; int main() { long long int i, j = 0, k = 0, len1, len2; string str1, str2; cin >> str1 >> str2; len1 = str1.size(); len2 = str2.size(); for (i = 0; i < len1; i++) { for (j = 0; j < len2; j++) { if (str1[i + j] != str2[j]) break; if (j == len2 - 1...
2
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll mod = 1e9 + 7; const ll N = 1e5 + 5; void fun(string s, int n, int &first, int &second) { for (int i = n - 1; i >= 0; i--) { if (s[i] == '1') { second = (i + 1) * 2; break; } } for (int i = 0; i < n; i++) { if (s[...
2
#include <bits/stdc++.h> const int Mo = (int)1e9; struct Node { int mat[2][2]; int lenx, leny; } B[200005], C[200005], tree[200005 * 4], Ans; int n, m, i, a[200005], len[200005 * 4], add[200005 * 4]; int type, u, l, r, x; inline Node operator+(Node a, Node b) { Node c = a; int i, j; for (i = 0; i < a.lenx; ++...
5
#include <bits/stdc++.h> using namespace std; #define INF INT64_MAX int main() { int n, m; cin >> n >> m; vector<vector<pair<int, long long>>> g( n ); for( int i = 0; i < m; i++ ) { int u, v; long long s; cin >> u >> v >> s; u--; v--; g[u].push_back( make_pair( v, s ) ); g[v].push_back( make_pair( u...
0
#include <bits/stdc++.h> using namespace std; const int M = 100005; int read() { int x = 0, flag = 1; char c; while ((c = getchar()) < '0' || c > '9') if (c == '-') flag = -1; while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); return x * flag; } int n, tot, rt, Min = 0x3f3...
4
#include<bits/stdc++.h> using namespace std; int main(){ int64_t x,k,d; cin >> x >> k >> d; x=llabs(x); int64_t steps=min(k,x/d); k-=steps; x-=d*steps; if(k!=0){ if(k%2==0)cout << x << endl; else cout << d-x << endl; }else cout << x << endl; }
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); long long n, m; cin >> n >> m; vector<long long> a(n + 1, 0); for (int i = 1; i <= n; i++) { cin >> a[i]; } sort(a.begin(), a.end()); for (int i = 1; i <= n; i++) a[i] += a[i - 1]; for (int i = 1; i <= n; ...
3
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5, M = 1e4 + 5, OO = 0x3f3f3f3f; int n, m, sz; vector<int> types; int arr[105]; int vis[110]; int main() { cin >> n >> m; memset(vis, 0, sizeof vis); for (int i = 0; i < m; i++) { cin >> arr[i]; vis[arr[i]]++; } for (int i = 0; i <= 105...
2
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int N = 100001; const int M = 20; const int MOD = 1000000007; const int inf = 1234567890; con...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (i % 2 == 0) { if (i % 4 == 0 && j == 1) { cout << '#'; continue; } else if (i % 4 > 0 && j == m) { cout << '...
1
#include <iostream> #include <cstdio> #include <algorithm> #define N 300002 using namespace std; struct shop{ int l,r; }a[N]; int n,m,i,j=1,d,c[N]; int read() { char c=getchar(); int w=0; while(c<'0'||c>'9') c=getchar(); while(c<='9'&&c>='0'){ w=w*10+c-'0'; c=getchar(); } return w; } int my_comp(const shop &...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long(n); cin >> (n); ; if (n == 1) return puts("1"); else { long long val = 0, ans = 1; for (long long i = 2; i <= n; i++) { val += 4; ans += val; } cout << ans ...
1