solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
const int n = s.size();
int ans = 0, cnt = 0;
int st = 0;
while (st < n && s[st] == 'F') {
st += 1;
cnt += 1;
}
for (int i = st; i < n; ++i) {
if (s[i] == 'F') {
ans = max(i - cnt, ans + 1);
cnt += 1;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int A, B, K;
cin >> A >> B >> K;
for (int i = A; i <= B; i++) {
if (i < A + K || B - K < i) cout << i << endl;
}
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
const int INF = 1e9 + 7;
int n, q;
int a[MAXN];
int d[MAXN];
int le[MAXN];
int ri[MAXN];
long long solve(int qa, int qb) {
if (qa == qb) return 0;
int ls, rs;
long long ret = 0;
qb--;
for (int i = qa; i <= qb; i++) {
ls = max(le[i], qa... | 4 |
#include <bits/stdc++.h>
const int N = 1e5 + 7;
using namespace std;
struct node {
int a, b, lazy;
long long sum, cnt;
node *l, *r;
} tree[N + N];
int pos;
node *build(int a, int b) {
node *root = &tree[++pos];
root->a = a;
root->b = b;
if (root->a == root->b) {
root->lazy = root->a;
return root;
... | 3 |
#include <bits/stdc++.h>
int comp(const void* elem1, const void* elem2) {
int f = *((int*)elem1);
int s = *((int*)elem2);
if (f > s) return 1;
if (f < s) return -1;
return 0;
}
int main() {
int n, l, r;
scanf("%d %d %d", &n, &l, &r);
--l;
--r;
int hamisi[2][n];
for (int i = 0; i < n; i++) {
sc... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<pair<pair<int, int>, pair<int, int> > > ans;
int cnt = 0;
map<pair<pair<int, int>, pair<int, int> >, int> mp;
int send_query(int x1, int y1, int x2, int y2) {
if (mp.find(pair<pair<int, int>, pair<int, int> >(
pair<int, int>(x1, y1), pair<int, int>... | 2 |
#include <bits/stdc++.h>
using namespace std;
inline long long int modadd(long long int n, long long int m,
long long int p = 1000000007) {
return ((n + m) % p + p) % p;
}
inline long long int modsub(long long int n, long long int m,
long long int p = 1000000007... | 5 |
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <iomanip>
using namespace std;
#define pi 3.1415926... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
scanf("%d", &n);
int a[n];
for (int i = 0; i < ((int)n); i++) scanf("%d", &a[i]);
sort(a, a + n);
scanf("%d", &m);
int b[m];
for (int i = 0; i < ((int)m); i++) scanf("%d", &b[i]);
sort(b, b + m);
int i = 0, j = 0, ans = 0;
while ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
long long a[maxn];
int main() {
int n;
while (~scanf("%d", &n)) {
for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
long long x, f;
scanf("%lld%lld", &x, &f);
long long ans = 0;
for (int i = 1; i <= n; ++i) {
ans += ... | 6 |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define X first
#define Y second
const int N = 2e5 + 1;
typedef pair<int,int> ii;
vector<ii> g[N];
int h[N];
ll f[N];
ll l[N], r[N];
ll dfs(int u,int p,ll v) {
if (h[u]) {
if (h[u] % 2 == h[p] % 2) {
ll... | 0 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long a, b, c, d;
cin >> a >> b >> c >> d;
if (a > b * c) {
cout << "-1\n";
return;
}
long long k = a / (b * d);
cout << (a * (k + 1)) - ((k * (k + 1)) / 2) * b * d << "\n";
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int tt, i, n, j, x, y;
cin >> n;
string s;
cin >> s;
if (n == 1) {
cout << "Yes";
return 0;
}
vector<int> v(26, 0);
for (i = 0; i < n; i++) {
if (v[s[i] - 'a'] == 1) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int arr[3001];
memset(arr, 0, sizeof(arr));
int n;
cin >> n;
int l = n;
long int count = 0;
int i = 0;
while (n--) {
cin >> arr[i++];
}
sort(arr, arr + l);
i = 0;
for (; i < l - 1; i++) {
if (arr[i + 1] <= arr[i]) {
count =... | 2 |
#include <bits/stdc++.h>
using namespace std;
int const N = (1e5) + 5;
char str[N];
int main() {
int n, k;
int max_length = 0, cur_length;
cin >> n >> k;
scanf("%s", str);
int counter = 0, it = -1;
for (int i = 0; i < n; ++i) {
while (it < n && counter <= k) {
it++;
counter += (str[it] == 'b... | 3 |
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
using namespace std;
struct Node{
int key;
Node*left,*right,*parent;
};
Node *root, *NIL;
void insert(int k){
Node *y=NIL;
Node *x=root;
Node *z;
z=(Node*)malloc(sizeof(Node));
z->key=k;
z->left=NIL;
z->right=NIL;
while(x!=NIL){
... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct A {
int val, pos;
};
bool cmp(A a, A b) { return a.val > b.val; }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
int n;
int m;
while (cin >> n) {
A arr[105];
queue<pair<int, int> > q;
for (int i = 1; i <= n; i++) {
... | 2 |
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
using namespace std;
int main()
{
int T;
cin >> T;
for(int tc=1;tc<=T;++tc){
int n,k;
long long int ans = 0;
cin >> n >> k;
vector<int> house(n);
vector<int> diff(n-1);
for(int i = 0; i < n; ++i){
cin >> h... | 0 |
#include <bits/stdc++.h>
using namespace std;
#define sz(v) ((int)(v).size())
const int MAXN = 10000005;
const int mod = 998244353;
using lint = long long;
lint ipow(lint x, lint p){
lint ret = 1, piv = x;
while(p){
if(p & 1) ret = ret * piv % mod;
piv = piv * piv % mod;
p >>= 1;
}
return ret;
}
lint fact[MA... | 0 |
#include <bits/stdc++.h>
using namespace std;
bool isPrime(int n) {
int sq = sqrt(n);
for (int i = 2; i <= sq; i++)
if (n % i == 0) return false;
return true;
}
int main() {
int n;
cin >> n;
for (int i = n; i >= 0; i--) {
if (isPrime(i)) {
if (i == n) {
cout << 1 << endl << n;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
istream& in = cin;
int n, a, b;
pair<long long, long long> d[200010];
bool mark[200010];
void input() {
in >> n >> a >> b;
for (int i = 1; i <= n; ++i) in >> d[i].first >> d[i].second;
}
int main() {
int TEST_CASE = 1;
while (TEST_CASE-- > 0) {
input();
if (... | 5 |
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#incl... | 0 |
#include "bits/stdc++.h"
using namespace std;
#define int long long
int mod=1e9+7;
const int N_MAX=1e5*2+1;
signed main(){
int n;
cin>>n;
vector<double> a(n);
for(int i=0;i<n;i++)cin>>a[i];
vector<vector<double> > dp(n+1,vector<double>(N_MAX,1e9));
for(int i=1;i<N_MAX;i++){
dp[0][i]=abs(a[0]-i)/a[0];
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
vector<string> grid(2);
cin >> grid[0] >> grid[1];
vector<vector<int>> ccId(2, vector<int>(n, -1));
int id = 1;
const vector<int> di = {1, -1, 0, 0};
const vect... | 5 |
#include <bits/stdc++.h>
using namespace std;
int ans[100005 * 4];
long long l[100005 + 5];
long long c[100005 + 5];
int main(void) {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
int loc = 0, v = 0;
scanf("%d%d", &loc, &v);
ans[loc + 100005] = v;
}
int a = 0, b = 0;
int s = 0, t = 0;
long l... | 1 |
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cctype>
using namespace std;
typedef long long lint;
#define cout cerr
#define ni (next_num<int>())
template<class T>inline T next_num(){
T i=0;char c;
while(!isdigit(c=getchar())&&c!='-');
bool flag=c=='-';
flag?c=getchar():0;
w... | 0 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const double pi = 2 * acos(0.0);
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
;
long long n;
cin >> n;
long long a[n + 1];
set<long long> st;
set<long long, greate... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n == 1) {
cout << 1;
return 0;
}
int res = 2 * (n - 1) * n + 1;
cout << res;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
struct _seq {
int val, pos;
} b[100002];
bool cmp(struct _seq x, struct _seq y) { return x.val < y.val; }
int n, m, i, _check, flag = 2, actual[100002], f[100002];
int binarySearch(int x) {
int p = 0, q = n - 1, m;
while (q > p) {
m = (p + q) / 2;
if (b[m].val... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e3 + 5;
long long int dp[N][55][55];
long long int lps1[55];
long long int lps2[55];
string s;
string a, b;
void H1() {
long long int i = 1, len = 0;
lps1[0] = 0;
while (i < a.size()) {
if (a[i] == a[len]) {
len++;
lps1[i] = le... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 10005;
pair<int, int> E[2 * MAXN];
vector<int> G[MAXN];
int N, M;
int color[MAXN];
int dfsnum[MAXN];
int num = 0;
int totalOdd;
int cntOddCycles[2 * MAXN];
int cntEvenCycles[2 * MAXN];
int curOdd;
int curEven;
inline bool isvalid(const int &e) {
return to... | 5 |
#include <bits/stdc++.h>
using namespace std;
int gcm(int x,int y){
if(x<y)swap(x,y);
int r=x%y;
while(r!=0){
x=y;
y=r;
r=x%y;
}
return y;
}
int main(){
int N,K,m=0,g;
cin >> N >> K;
for(int i=0;i<N;i++){
int A;
cin >> A;
m=max(m,A);
if(i==0)g=A;
else g=gcm(g,A);
}
if(K<=m && (m-K)%g==0)cout... | 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using ll = long long;
using ld = long double;
template <typename T>
using mat = vector<vector<T> >;
template <int mod>
struct modint {
int x;
modint() : x(0) {}
modint(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
modin... | 6 |
#include <bits/stdc++.h>
using namespace std;
const string T = "abacaba";
bool check(string s) {
int cnt = 0;
for (int i = 0; i < s.length() - 6; i++)
if (s.substr(i, 7) == T) cnt++;
return (cnt == 1);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
string s[6];
int main(int argc, char const *argv[]) {
string sx;
cin >> sx;
deque<char> dq;
for (auto i : sx) {
dq.push_back(i);
}
queue<char> l;
stack<char> r;
while (dq.size() >= 4) {
char ccnt[4] = {0, 0, 0, 0};
ccnt[dq.front() - 'a']++;
d... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, l;
vector<int> a;
vector<int> b;
vector<int> f;
void increase(int li, int ri, int i) {
int left = lower_bound(b.begin(), b.end(), li) - b.begin();
int right = upper_bound(b.begin(), b.end(), ri) - b.begin() - 1;
if (left <= right) {
int al = (n + left - i) ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 50 * 1000 + 23, SQ = 220 + 3;
unordered_map<int, bitset<MAXN>> h;
unordered_map<int, unordered_set<int>> l;
bitset<MAXN> on, ish, tmp;
int n, m, q, o, d[MAXN];
stringstream s;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin... | 4 |
// A.
#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;
int main(int argc, char* argv[]) {
int h = -1, w;
cin >> h >> w;
vector<string> b(h);
for (int i = 0; i < h; ++i) {
cin >> b[i];
}
int dp[102][102][2] = {};
memset(dp, 0x3f, sizeof(dp)... | 0 |
#include <bits/stdc++.h>
using namespace std;
int N, a, b, d, dist, c, m;
int K;
int dp[1234];
int in[1000007];
int benefit[1234];
int X[125], Y[1254];
int getAbs(int x, int y) { return abs(X[x] - X[y]) + abs(Y[x] - Y[y]); }
bool likeDJ(int mid) {
bool vis[125] = {0};
memset(dp, -1, sizeof(dp));
dp[1] = mid;
pr... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
short at[4000][4000];
short dp[4000][4000];
short pt[4000][4000];
int locate(int x, const vector<int>& u) {
return lower_bound(u.begin(), u.end(), x) - u.begin();
}
int n, x[2000], r[2000], v[2000];
void output(int i, int j) {
if (i == j) ret... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 100, M = 6, MOD = 1000 * 1000 * 1000 + 7;
int sum(int a, int b) {a += b;return (a < 0? a + MOD: a >= MOD? a - MOD: a);}
void _sum(int &a, int b) {a = sum(a, b);}
int mul(int a, int b) {return 1LL * a * b % MOD;}
void _mul(int &a, int b) {a = mul(a, b);... | 0 |
#include <bits/stdc++.h>
using namespace std;
inline void read() {}
template <typename T, typename... Ts>
inline void read(T& A, Ts&... As) {
T x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
x = (x << 1) + (... | 4 |
#include <bits/stdc++.h>
using namespace std;
void print(long long int *arr, long long int k, long long int l) {
for (int i = l; i < k; i++) cout << arr[i] << " ";
cout << endl;
}
int main() {
int n, c;
cin >> n;
c = floor(sqrt(n));
for (int i = 1; i <= n / c + 1; i++) {
for (int j = 0; j < c; j++) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, q, i, l, r;
cin >> q;
for (i = 0; i < q; i++) {
cin >> l >> r;
if (l % 2 == 0) {
if (r % 2 == 0) {
cout << r - (r - l) / 2 << endl;
} else {
cout << (r - l + 1) / 2 * -1 << endl;
}
} else {
if ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
const int ITER = 40;
const int LOG = 18;
const int INF = 1e9;
const long double eps = 1e-12;
int N, M;
pair<int, int> p[MAXN];
long double dist[MAXN], phi[MAXN];
int jmp[MAXN][LOG];
long double gap[MAXN][LOG];
long double pt[MAXN];
void load() {
... | 5 |
#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;
void solve() {
string s, t;
cin >> s;
cin >> t;
long long n = (long long)s.length();
long long m = (long long)t.length();
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n % 2 == 0) {
cout << -1;
return 0;
}
for (int i = 0; i < n; i++) {
cout << i << " ";
}
cout << endl;
for (int i = 0; i < n; i++) {
cout << i << " ";
}
cout << endl;
for (int i = 0; i < n; i++) {
co... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y) {
long long res = 1;
while (y > 0) {
if (y & 1) res = (res * x) % 1000000007;
y = y / 2;
if (y != 0) x = (x * x) % 1000000007;
}
return res;
}
long long ans[2000005], n0[2000005], n1[2000005];
int main() {
ios_... | 4 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;
int main() {
ll n,ma,mb;
cin >> n >> ma >> mb;
vec a(n);
vec b(n);
vec c(n);
for(ll i=0;i<n;i++) cin ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
long long b;
cin >> n >> k >> b;
int a[100004];
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
priority_queue<int> q;
long long sum = 0;
if (k == 1) {
for (int i = 0; i < n - 1; ++i)
if (a[i] > b) {
cout << i + 1 ... | 2 |
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int n;
cin>>n;
int res=0;
int num[3];
while(n>1){
if(n<=3) n=3;
num[0]=n/3;
num[1]=(n-num[0])/2;
num[2]=n-num[1]-num[0];
n=max(num[0],num[2]);
res++;
}
cout << res<<endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
long double nCr(unsigned long long n, unsigned long long r) {
if (n < r) return 0;
if (n == r) return 1;
return (nCr(n - 1, r) / (n - r)) * n;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m, h;
cin >> n >> m >> h;
h--;
n--;
int sum = 0... | 2 |
#include <bits/stdc++.h>
const int MN = 5e5 + 100, MM = 5e5 + 100;
int n, m, deg[MN], depth[MN], parent[MN], lower, upper, q[MN], pred[MN];
std::vector<int> graph[MN];
std::vector<int> mod[3];
bool dfs(int v) {
bool r = 0;
for (int u : graph[v])
if (parent[v] != u && deg[u] % 3 == 2) {
if (depth[u])
... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long a[10000];
int main() {
long long n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int j = 0; j < n - 1; ++j) {
if (a[j] >= a[j + 1] + 2) {
cout << "NO";
return 0;
}
}
cout << "YES";
}
| 3 |
#include<iostream>
using namespace std;
int m, n;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int divi[100][100];
int used[100][100];
int r;
void solve(int x, int y, int res);
int main(){
while(1){
cin >> m;
cin >> n;
r = 0;
if(m == 0 && n == 0) break;
for(int i = 0; i < n; i++){
f... | 0 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const long long infLL = 9000000000000000000;
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
int dx[] = {0, 0, +1, -1, +1, +1, -1, -1};
int dy[] = {+1, -1, 0, 0, +1, -1, +1, -... | 3 |
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
int cnt[26];
int main() {
string s, t;
while (cin >> t)s += t;
for (char c : s) {
if (!isalpha(c))continue;
if (islower(c))c = toupper(c);
cnt[c - 'A']++;
}
rep(i, 26) {
cout << (char)('a' + i) << " : " << cnt[i] << endl;
}... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > adj, islands;
vector<bool> vis;
void dfs(int v) {
vis[v] = 1;
islands.back().push_back(v);
for (int u : adj[v])
if (!vis[u]) dfs(u);
}
int main() {
int i, n;
cin >> n;
pair<int, int> b[n];
int a[n];
adj.assign(n + 1, {});
vis.assig... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 300010, M = 2 * N;
int n, m, idx, h[N], e[M], ne[M], colour[N];
inline void add(int a, int b) { e[idx] = b, ne[idx] = h[a], h[a] = idx++; }
inline void dfs(int u)
{
int f = 0;
for (int i = h[u]; i != -1; i = ne[i])
{
int v = e[i];
... | 4 |
#include <bits/stdc++.h>
using namespace std;
double pi = 3.14159265358979323846;
int main() {
ios_base::sync_with_stdio(0);
int a, x, y;
cin >> a >> x >> y;
int c = y / a;
if (y % a == 0) {
cout << "-1";
return 0;
} else if (c == 0) {
if ((double)x > (double)-a / 2 && (double)x < (double)a / 2)... | 2 |
#include <bits/stdc++.h>
using namespace std;
struct edge {
int to, dist, cost;
edge(){}
edge(int to, int dist, int cost):to(to), dist(dist), cost(cost){}
};
typedef pair<int, int> P;
typedef pair<P, int> PP;
int N, M;
vector< vector<edge> > G;
const int inf = 1<<25;
int dijkstra()
{
vector<int> mindist(N... | 0 |
#include <bits/stdc++.h>
using namespace std;
int x[] = {
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37,
41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89,
97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151,
157, 163, 167, 173, 179, 181, ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int p(int x) {
for (int i = 2; i * i <= x; i++)
if (x % i == 0) return 0;
return 1;
}
int main() {
int n;
cin >> n;
if (p(n))
cout << 1;
else if (n % 2 == 0 || p(n - 2))
cout << 2;
else
cout << 3;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int n, cost[1510][1510], s[2][1510], r, d[2][1510], from[2][1510], add[2][1510],
v[2][1510];
bool augment() {
int i, b_x, b_y, x, y;
for (y = 1; y <= n; y++) {
d[0][y] = s[0][y] ? 1000000000 : 0;
d[1][y] = 1000000000;
v[0][y] = v[1][y] = false;
}
for... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <class C>
void mini(C& a4, C b4) {
a4 = min(a4, b4);
}
template <class C>
void maxi(C& a4, C b4) {
a4 = max(a4, b4);
}
template <class T1, class T2>
ostream& operator<<(ostream& out, pair<T1, T2> pair) {
return out << "(" << pair.first << ", " << pair.second ... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct dsu {
vector<int> p;
int n;
dsu(int n) : n(n) {
p.resize(n);
iota(p.begin(), p.end(), 0);
}
int get(int x) { return (x == p[x] ? x : (p[x] = get(p[x]))); }
bool unite(int x, int y) {
x = get(x);
y = get(y);
if (x != y) {
p[x] = y... | 5 |
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
long long n,a,b,c,d,e;
cin >> n >> a >> b >> c >> d >> e;
long long m;
m = min({a,b,c,d,e});
cout << (n+m-1)/m+4 << endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
long min(long a, long b) {
if (a > b)
return b;
else
return a;
}
using namespace std;
int main() {
map<string, long> mp;
long long int n, k, m, i, a, x, j, h;
cin >> n >> k >> m;
long long int price[n], cost = 0;
string s[n], l;
for (i = 0; i < n; i++) {
cin >> s[i];... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int TESTCASE;
cin >> TESTCASE;
while (TESTCASE--) {
long long int n;
cin... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<vector<int>> edge(n + 1);
vector<pair<int, int>> a(n + 1);
int root;
for (int i = 1; i <= n; i++) {
cin >> a[i].first >> a[i].second;
if (!a[i].first)
root = i;
else
... | 4 |
#include <cstdio>
#include <cstring>
#define int long long
#define dp(i,j) dp[(i)+2300][(j)+2300]
int dp[5001][5001],n,a[200001],b[200001],fac[100001];const int p=1e9+7;
int qpow(int bs,int ex){int ans=1;while(ex){if(ex&1)ans=1ll*ans*bs%p;bs=1ll*bs*bs%p;ex>>=1;}return ans;}
int binom(int n,int m){return 1ll*fac[n]*qpow... | 0 |
#include <bits/stdc++.h>
using namespace std;
string vow = "aeiou";
long long month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const long long dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const long long dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};
const long long dx4[] = {-1, 0, 1, 0};
const long long dy4[] =... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9 + 111;
const long long llinf = (long long)3e18;
const int N = (int)2e5 + 111;
const long double PI = (long double)acos(-1);
int main() {
int n;
int arr[2005];
cin >> n;
int sum = 0;
for (int i = 1; i <= n; i++) {
cin >> arr[i];
sum... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 35000000;
const int MD = 1051131;
const int rev2 = 525566;
int a[MAXN];
int m, s;
long long t;
int mult_coeff;
int powMod(int x, long long st) {
int res = 1;
while (st) {
if (st & 1) {
res = 1ll * res * x % MD;
}
st /= 2;
x = 1ll *... | 5 |
#include <bits/stdc++.h>
using namespace std;
struct lhy {
int sum, lazy, r;
} tree[4 * 3 * 100010];
int n, ans, L, R, l[100010], r[100010], v[100010];
vector<pair<int, int> > v1[3 * 100010], v2[3 * 100010];
inline void down(int k) {
tree[k << 1].sum += tree[k].lazy;
tree[k << 1].lazy += tree[k].lazy;
tree[k <<... | 4 |
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
int a;
bool k = false;
while (cin >> a&&a != 0) {
if (k)
cout << endl;
string s[10];
int b[10];
int g[10];
bool l[10];
for(int i = 0; i < a; i++) {
string m;
int c, d, e;
cin >> m >> c >> d >> e;
s[i... | 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
bool home = 1;
signed realMain();
signed main() {
home = 0;
if (home) {
freopen("tony_stark", "r", stdin);
} else {
ios::sync_with_stdio(0);
cin.tie(0);
}
realMain();
}
const int N = (... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
string k[60];
int usedI[60] = {0};
int usedJ[60] = {0};
queue<int> qI, qJ;
int main() {
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> k[i];
bool res = true;
int cont = 1;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) {
cont++;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int r;
vector<long long> LenDou(81), afirst(81), alast(81), bfirst(81), blast(81);
long long min(long long a, long long b) {
if (a > b)
return b;
else
return a;
}
long long max(long long a, long long b) {
if (a < b)
return b;
else
return a;
}
void In... | 5 |
// AOJ 0279
#include<cstdio>
#include<algorithm>
#define rep(i,a) for( int i = 0; i != (a); ++i )
int N;
int main()
{
while( scanf( "%d", &N ), N )
{
bool fl = false;
int cnt = 0;
rep( i, N )
{
int k;
scanf( "%d", &k );
if( k >= 2 )
fl = true;
if( !k )
++cnt;
}
if( !fl )
{
puts... | 0 |
#include <bits/stdc++.h>
using namespace std;
int N, M, K;
const long long MOD = 1e9 + 7;
int par[500005], sz[500005];
unordered_map<long long, vector<pair<int, int>>> mp;
long long val[500005];
int getrt(int n) { return par[n] = (par[n] == n ? n : getrt(par[n])); }
long long add(long long a, long long b) { return (a +... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1LL << 28;
const long long mod = 1LL;
bool col[100010];
int mark[100010];
int path[100010];
vector<int> adj[100010];
pair<long long, long long> dp[100010];
int start, best, n;
pair<long long, long long> dfs(int u, int dist) {
col[u] = 1;
if (mark[u... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
s = "0" + s + "0";
if (s.find("000") != string::npos || s.find("11") != string::npos)
puts("NO");
else
puts("YES");
return 0;
}
| 1 |
#include <bits/stdc++.h>
namespace competitive_programming::utility {
class timer {
private:
std::chrono::time_point<std::chrono::steady_clock> begin, end;
public:
timer() : begin(), end() {}
~timer() {}
};
} // namespace competitive_programming::utility
constexpr bool test_cases = true;
auto solve = []() -> ... | 1 |
#include <bits/stdc++.h>
using namespace std;
bool comparator(pair<long long int, long long int> a,
pair<long long int, long long int> b) {
return a.first < b.first;
}
int main() {
long long int n, k;
long long int cost[300100];
long long int indexes[300100];
long long int size = 0, removido;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
void bad(string mes = "Impossible") {
cout << mes;
exit(0);
}
template <typename T>
string bin(T x, int st = 2) {
string ans = "";
while (x > 0) {
ans += char('0' + x % st);
x /= st;
}
reverse(ans.begin(), ans.end());
return ans.empty() ? "0" : ans;
}
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = int(3e4 + 5);
const int INF = 1e9 + 7;
int n;
string s1, s2, s3;
string cut(string s) {
string ans;
for (int i = 0; i < s.size(); ++i) {
if (s[i] != '_' && s[i] != ';' && s[i] != '-') {
ans += s[i];
}
}
for (int i = 0; i < ans.size(); ++i... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> a(5005);
int occ[5005][2];
int dp[5005];
int vis[5005];
int main() {
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
if (!occ[a[i]][0]) occ[a[i]][0] = i;
occ[a[i]][1] = i;
}
for (int i = 1; i <= n; ++i) {
int cur = 0;
int... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int K,X;cin>>K>>X;
for(int i=-K+1; i<=K-1; i++){
cout << X+i << endl;
}
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3005;
int x[N], y[N], z[N], a[N], s, size1[N], size2[N], n, f[N];
int find(int x) {
if (x == f[x]) return x;
return f[x] = find(f[x]);
}
int pd(int val) {
for (int i = 1; i <= n; i++) f[i] = i;
for (int i = 1; i < n; i++)
if (z[i] < val) f[find(x[i... | 5 |
#include <iostream>
using namespace std;
int n;
long long arr[55];
int main(){
cin>>n;
for(int i=0;i<n;i++){
cin>>arr[i];
}
bool found=true;
long long sol=0;
int cnt=0;
while(found){
cnt++;
found=false;
for(int i=0;i<n;i++){
if(arr[i]>=n)found=true;
else continue;
long long times= arr[i]/n;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 500 + 1;
int dyn[maxn][maxn];
int n;
int ans(int m, int k, long long mod) {
if (m == 0 && k == 0) return 1;
if (m < 0 || k < 0) return 0;
if (dyn[m][k] != -1) return dyn[m][k];
long long a = 0;
if (m > 1) a += (((m * (m - 1)) / 2) % mod) * (ans(m ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n[4] = {};
for (int k = 0; k < 4; k++) cin >> n[k];
sort(n, n + 4);
cout << n[3] - n[0] << " " << n[3] - n[1] << " " << n[3] - n[2] << endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 100000 + 10;
int n1, n2, n3;
long long D1, E2;
class Tree {
public:
int head[MaxN], nxt[MaxN << 1], to[MaxN << 1], top, son[MaxN], size;
long long totaldis[MaxN], PD[MaxN], PE[MaxN];
bool vis[MaxN];
void addedge(int fr, int tt) {
top++;
nxt... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int M = 1000000007;
const int MM = 998244353;
const long double PI = acos(-1);
long long power(long long b, long long e, long long m) {
if (e == 0) return 1;
if (e & 1) return b * power(b * b % m, e / 2, m) % m;
return power(b * b % m, e / 2, m);
}
long long pow... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 10, MAXM = 1e5 + 10;
vector<pair<int, pair<int, int> > > A, B;
vector<int> ans;
int n, m, par[MAXN][3];
bool G[MAXM];
int getpar(int v, int p) {
if (v == par[v][p]) return v;
par[v][p] = getpar(par[v][p], p);
return par[v][p];
}
void rpar(int p)... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
template <typename... Args>
void db(Args... args) {}
long long qpow(long long a, long long b) {
long long res = 1;
while (b) {
if (b & 1) res = res * a % MOD;
a = a * a % MOD;
b /= 2;
}
return res;
}
long long inv(long lo... | 5 |
#include<stdio.h>
int main(void)
{
int i,j,k;
while(1){
scanf("%d %d",&j,&k);
if(j==0&&k==0)break;
if(j>k)printf("%d %d\n",k,j);
else printf("%d %d\n",j,k);
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long v[3], t[3];
int main() {
for (int i = 0; i < 3; ++i) {
scanf("%lld", v + i);
t[i] = 1;
}
long long k;
scanf("%lld", &k);
while (k) {
int p = -1;
for (int i = 0; i < 3; ++i) {
if (v[i] == t[i]) continue;
if (p == -1 || t[i] < t... | 1 |
#include "bits/stdc++.h"
using namespace std;
int main() {
long long N, X, M;
cin >> N >> X >> M;
set<long long>s;
map<long long, long long>p;
vector<long long>Ans(M + 10);
s.insert(X);
p[X] = 0;
Ans[0] = 0;
Ans[1] = Ans[0] + X;
for (long long i = 1; i < N; ++i) {
X *= X;
X %= M;
Ans[i + 1] = Ans[i] + ... | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.