solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
void solve() {
int a[100];
int n, i;
scanf("%d", &n);
getchar();
for (i = 0; i < n; i++) {
a[i] = getchar() - '0';
}
for (i = 0; i < n; i++) {
if (a[i] == 1 || a[i] == 4 || a[i] == 6 || a[i] == 8 || a[i] == 9) {
printf("%d\n%d\n", 1, a[i]);
... | 2 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
int N;
cin >> N;
vector<ll> A(N,0);
ll sum = 0;
for(int i=0;i<N;i++){
cin >> A[i];
sum += A[i];
}
sum -= 2*A[0];
ll ans = abs(sum);
for(int i=1;i<N-1;i++){
sum -= 2*A[i];
ans = min(ans,abs(sum));
}
cou... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, x, b, y;
cin >> n >> a >> x >> b >> y;
int p = a;
int q = b;
for (int i = 0; i < n; i++) {
if (p == x || q == y) break;
if (p != q) {
p++;
q--;
}
if (p == n + 1) {
p = 1;
}
if (q == 0) {
q = n;... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d, x, y;
cin >> a >> b >> c >> d >> x >> y;
c = c - a;
d = d - b;
if (c % x == 0 && d % y == 0 && (abs(c / x) % 2) == (abs(d / y) % 2))
cout << "YES";
else
cout << "NO";
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 5e3 + 10;
int f[2][maxn][2], g[2][maxn][2];
char s[maxn];
int Mod(int x) {
while (x >= mod) x -= mod;
while (x < 0) x += mod;
return x;
}
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%s", s + ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int v[100010];
char test[100010];
long long dp[100010][2];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", &v[i]);
}
string old0;
string old1;
for (int i = 1; i <= n; ++i) {
dp[i][1] = 1e15;
dp[i][0] = 1e15;
}
in... | 3 |
#include <bits/stdc++.h>
using namespace std;
using pii = pair<long long, long long>;
signed main() {
long long q;
cin >> q;
while (q--) {
long long a, b;
cin >> a >> b;
if (b < a) swap(a, b);
long long t = b - a;
long long ans = 0;
if (t >= 5) {
ans += t / 5;
t -= (t / 5) * 5;... | 1 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
int n;
cin >> n;
int a[100005];
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
int inter = a[1] - a[0];
for (int i = 2; i < n; i++) {
inter = gcd(inter, a[i] - a[i - 1]);
... | 2 |
#include <bits/stdc++.h>
#define loop(i, a, n) for (int i = a; i < (int) n; i++)
#define rep(i, n) loop(i, 0, n)
using namespace std;
int INF = 1e9;
int main() {
int N;
cin >> N;
vector<int> minChar(256, INF);
vector<int> dp(N);
rep(i, N) {
string w;
cin >> w;
if (i == 0) {
dp[i] = 1;
... | 0 |
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int MAX_N = 30001;
int L[MAX_N], R[MAX_N], sum[MAX_N];
int n, m, w, h, s;
int bin_search_line(double x, double y) {
int l = 0, r = m, line = 0;
while (l <= r) {
int mid = (l + r) >> 1;
if ((y - L[mid]) * w > x * (R[mid] - L[mid... | 0 |
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define F first
#define S second
#define pb push_back
const int P = 1e9+7;
using namespace std;
int n;
string s;
ll dp[3030][3030];
int main(){
cin >> n >> s;
dp[0][0] = 1;
int m = s.size();
for(int i=0; i<m; i++)... | 0 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-5;
const int oo = 0x3f3f3f3f;
template <class T>
inline void checkmin(T &a, T b) {
if (b < a) a = b;
}
template <class T>
inline void checkmax(T &a, T b) {
if (b > a) a = b;
}
template <class T>
inline T sqr(T x) {
r... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long int MAX = -1000000000000000000;
const long long int MIN = 1000000000000000000;
const long long int inf = 1000000000;
const long long int KOK = 100000;
const long long int LOG = 30;
const long long int li = 5005;
const long long int mod = 1000000007;
long lon... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long n;
cin >> n;
for (int i = 0; i < n; ++i) {
long long x;
cin >> x;
if (x % 2 == 0) {
cout << x * 4 + 1 << '\n';
} else if (x % 4 == 1)
cout << 2 * x + 1 << '\n';
else
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, m, i, cnt;
char s[50005];
bool flag;
int main() {
gets(s);
n = strlen(s);
cnt = 1;
while (cnt <= (n >> 1)) {
m = 0;
flag = false;
for (i = 0; i < n - cnt; i++) {
if (s[i] == s[i + cnt])
m++;
else
m = 0;
if (m == c... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k, cent;
cin >> k;
vector<int> a(12);
for (int i = 0; i < 12; i++) {
cin >> a[i];
}
sort(a.begin(), a.end());
int ind = 0, sum = 0;
for (int i = 11; i >= 0; i--) {
sum += a[i];
if (sum < k) {
ind++;
} else {
break... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int w[4][2] = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}};
int R, a[4], rp[4], tmp, n, sz, id[110][110], fr, p[10010][110], slv[110][110],
num[110], val[110], mn, pl, ans;
int POW(int x, int y) {
int tot = 1;
while (y)
y& 1 ? tot = 1ll * to... | 5 |
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int main(){
double n;
while(cin >> n , n >= 0){
string ans = "",tmp = "";
int integer = n;
n -= integer;
while(integer){
tmp += (integer % 2) + '0';
integer /= 2;
}
int len = (int)tmp.size();
... | 0 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> calc(int num) {
int ones = 0, length = 1;
while (num > 1) {
if (num % 2 != 0) ones++;
num /= 2;
length++;
}
if (num == 1) ones++;
return pair<int, int>(length, ones);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);... | 2 |
#include<bits/stdc++.h>
using namespace std;
int N,Q;
string s;
vector<char> t(200009),d(200009);
int lb,ub,LB,UB;
bool C(int x){
for(int i=0;i<Q;i++){
if(s[x]==t[i]){
if(d[i]=='L')x--;
else x++;
}
if(x<0)return false;
if(x>=N)return true;;
}
return true;
}
bool Cc(int x){
for(int ... | 0 |
#include <bits/stdc++.h>
using namespace std;
bool common(int x, int y) {
while (x) {
int yy = y;
while (yy) {
if (yy % 10 == x % 10) return true;
yy /= 10;
}
x /= 10;
}
return false;
}
int main() {
int x;
cin >> x;
int cnt = 0;
for (int i = 1; i <= sqrt(x); i++) {
if (x % ... | 2 |
#include<iostream>
#include<algorithm>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define PUT 0
#define REMOVE 1
#define CHECK_PLANE 2
int cnt;
int m[10][10];
int ans[10][10];
bool is_origin[10][10];
bool make_rect(int now,int x,int y,int width,int height,int flag,
... | 0 |
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
using namespace std;
int idx;
string s;
int solve(){
if(isdigit(s[idx])){
string tmp = "";
while(isdigit(s[idx])){
tmp += s[idx];
idx++;
}
return atoi(tmp.... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const double eps = 1e-9;
int main() {
int n, k, i;
cin >> n >> k;
vector<int> s(n);
for (i = 0; i < n; ++i) cin >> s[i];
sort(s.begin(), s.end());
int l = 0, r = 0, d = 0;
vector<vector<int> > dp(n + 1, vector<int>(k + 1, 0));
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int A[2001][30], k, n, p;
vector<int> C[30];
int B[2001][101];
string a, aux;
char c;
int find_row(void) {
int i = 0;
while (A[i][c - 'a'] < p) {
p -= A[i][c - 'a'];
i++;
}
A[i][c - 'a']--;
return i;
}
int find_colum(int row) {
int rst = 0;
while (p)
... | 3 |
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
const long long int mod = 1000000007ll;
const long long int smod = 998244353ll;
const long long int inf = 10000000000000007ll;
const double eps = 1e-10;
struct less_key {
bool operator()(const std::pair<long long int, long long int> &left,
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int N, a[109];
long long answer, K;
vector<int> ds;
void addSegm(long long st, long long dr) {
long long sus = K, jos = N;
for (int i = 1; i <= N; i++) sus += a[i], jos += (a[i] - 1) / st;
long long Lim2 = sus / jos;
if (Lim2 >= st) {
if (dr < Lim2) Lim2 = dr;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main(){
long N, K, i, ans=0; cin >> N >> K; vector<long> H(N);
for(i=0; i<N; i++){ cin >> H[i]; }
sort(H.begin(), H.end());
for(i=0; i<N-K; i++){ ans+=H[i]; }
cout << ans << "\n";
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
vector<int> v;
stack<int> st;
vector<string> S;
getline(cin, s);
int up = 0, pos = 0;
for (int i = 0; i < s.size() - 1; i++) {
if (s[i] == ':') {
if (!up)
v.push_back(v.size());
else
v.push_back(-1);
... | 3 |
#include<stdio.h>
char x[10];
int main(){
scanf("%s",x);
if(x[0]==x[1]&&x[1]==x[2]){
printf("No");
return 0;
}
printf("Yes");
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int t;
cin >> t;
while (t--) {
long long int n;
cin >> n;
string a, b;
cin >> a >> b;
if (a == b) {
cout << "0\n";
continue;
}
long long int corr = ... | 3 |
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
long long int a[n];
long long int c = 0, pos = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] % 2 == 0) {
c = ... | 1 |
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define xx first
#define yy second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define sz(x) x.size()
#define pii pair<int,int>
#define en '\n'
#define sp ' '
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
usi... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
const int M = 1e5 + 7;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
int head[N], s[N], ans[N], flow[N], tot, n, m, sum;
bool vis[N];
struct Edge {
int to, id, nx;
} edge[N << 1];
void add(int u, int ... | 6 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
long long a[100000], b[1000000], n, k;
bool f(long long no) {
long long sum = 0;
for (long long i = 0; i < n; i++) {
if (b[i] < no * a[i]) sum += (no * a[i] - b[i]);
if (sum > k) return 0;
}
return 1;
}
int32_t main() {
cin >>... | 4 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
int f(int a) {
if (a == 0) return 0;
return f(a % __builtin_popcount(a)) + 1;
}
int main() {
int n;
string x_;
cin >> n >> x_;
vector<int> x(n);
int pc_ = 0;
rep(i, n) {
x[i] = x_[i] - '0';
pc_ += x[i];... | 0 |
#include <bits/stdc++.h>
using namespace std;
int parent[1001];
int main() {
int N, K;
cin >> N >> K;
int arr[N];
for (int i = 0; i < N; i++) cin >> arr[i];
long long int ans = K;
for (int i = 0; i < N - 1; i++) {
int buys = K / arr[i];
int bacha = K % arr[i];
for (int j = i + 1; j < N; j++) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long int dp[100005][2];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int n;
cin >> n;
vector<long long int> v(n), v1(n);
for (long long int i = 0, temp; i < n; i++) {
cin >> v[i];
}
for (long long int i =... | 3 |
#include <bits/stdc++.h>
using namespace std;
struct dsu {
vector<int> P, rank;
dsu(int n) : P(n), rank(n) {
for (int i = 0; i < n; i++) {
P[i] = i;
rank[i] = 0;
}
}
int fnd(int i) {
if (i != P[i]) P[i] = fnd(P[i]);
return P[i];
}
void join(int x, int y) {
int PX = fnd(x);
... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream& operator<<(ostream& out, vector<T>& v) {
out << "[";
for (auto k : v) out << k << " ";
out << "]"
<< "\n";
return out;
}
template <class T>
ostream& operator<<(ostream& out, set<T> s) {
out << "{";
for (auto k : s) out << k << "... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int k, l, i = 0;
cin >> k >> l;
while (pow(k, i) != l) {
i++;
if (pow(k, i) > l) {
i = -1;
break;
}
}
if (i == -1)
cout << "NO";
else
cout << "YES" << endl << i - 1;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
set<int> s;
int len = 0;
bool flag = false;
for (int i = 0; i < n; i++) {
int k;
cin >> k;
len = s.size();
s.insert(k);
if (s.size() == len) flag = true;
}
if (flag)
cout << "YES"
<< "\n";
el... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = -1;
vector<long long> v, ac;
long long fsoma(int l, int r) {
if (l > r) return 0;
return ac[r + 1] - ac[l];
}
int main() {
int n;
cin >> n;
long long x;
for (int i = 0; i < n; i++) scanf("%lld", &x), v.emplace_back(x);
sort((v).begin(), (v).end()... | 2 |
#include <bits/stdc++.h>
using namespace std;
int a[5];
bool d[803][803], d3[301][301][301], l[350][350];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
if (n == 1) {
if (a[0] == 0)
cout << "BitAryo";
else
cout << "BitLGM";
return 0;
}
d[0][0] = 0;
for (int ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long p[32];
p[0] = 1;
for (int i = 1; i < 32; i++) p[i] = p[i - 1] * 2;
long long n, a, cnt = 0;
map<long long, vector<long long>> mpv;
vector<long long> vi;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a;
vi.push_back(a);
mpv... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
while ((n % 10 + (n / 10) % 10 + (n / 100) % 10 + (n / 1000) % 10) % 4 != 0) {
n++;
}
cout << n;
return 0;
}
| 1 |
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
#define RG register
#define file(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)
#define clear(x, y) memset(x, y, sizeof(x))
#define int long long
inline int read()
{
int data = 0, w = 1; char ch = getchar();
while(ch != '-... | 0 |
#include <bits/stdc++.h>
using namespace std;
int len, k;
string str;
int main() {
cin >> len >> k;
cin >> str;
cout << len << endl;
string ans = "";
for (int i = 0; i < len; i++) {
ans += str[i % k];
}
if (ans < str) {
for (int i = k - 1; i >= 0; i--) {
if (str[i] == '9') {
str[i] =... | 3 |
#include<cstdio>
#include<cmath>
#define ll long long
int main()
{
ll a,b,c;
scanf("%lld%lld%lld",&a,&b,&c);
c-=(a+b);
ll sq=sqrtl(4*a*b);
if(c>sq)
printf("Yes");
else
printf("No");
return 0;
} | 0 |
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#de... | 0 |
#include <bits/stdc++.h>
using namespace std;
double PI = 3.141592653589793;
void solve() {
long long n, a, b;
cin >> n >> a >> b;
n *= 6;
vector<pair<long long, long long> > proc;
proc.push_back({n, n});
for (long long i = n - 1; i > 0;) {
long long k = (n + i - 1) / i;
long long lo = (n + k - 1) /... | 2 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll=long long;
const ll MOD=1000000007,MOD2=998244353;
int main() {
int N;
cin>>N;
string S;
cin>>S;
int ans=0;
for(int i=1;i<N;i++){
int count=0,now=0;
rep(j,N-i){
if(S.at(j... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, k;
cin >> n >> k;
vector<int> a(n), b(n);
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) cin >> b[i];
int Z = 1000000;
vector<int> p(Z, -999999);
p[Z / 2] = 0;
for (int i = ... | 3 |
#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
int x[500005];
int y[500005];
char a[500005];
int main() {
int n;
cin >> n;
int x1, y1;
cin >> x1 >> y1;
char a1, a2, a3, a4, a5, a6, a7, a8;
long long x2 = 9999999999, x3 = -9999999999, y2 = 9999999999,
y3 = -9999999999, x4 = -9999... | 4 |
#include <bits/stdc++.h>
using namespace std;
int cube[6][4];
int copyCube[6][4];
bool check() {
int fullSides = 0;
for (int i = 0; i < 6; i++) {
int count = 1;
for (int j = 1; j < 4; j++) {
if (copyCube[i][j] == copyCube[i][j - 1]) count++;
}
if (count == 4) fullSides++;
}
if (fullSides =... | 3 |
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
typedef int Weight;
struct Edge {
int src, dst;
Weight weight;
Edge(int src_, int dst_, Weight weight_) :
src(src_),... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f;
const long long MOD = 1e9 + 7;
const long double eps = 1e-9;
const long double PI = acos(-1.0);
long long n;
inline long long read() {
long long s = 0, w = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') w = ... | 3 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
ll a[123456];
void solve() {
int n;
cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i];
int ans = 0;
if (n == 1)
ans = 1;
else {
int reset_len = 2;
for (int i = 3; i <= n; ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int kMaxN = 500;
int n;
double h, f;
inline int sgn(double x) {
if (fabs(x) < 1E-7) return 0;
if (x > 0.0) return 1;
return -1;
}
struct Point {
double x, y;
Point() {}
Point(double x_, double y_) : x(x_), y(y_) {}
};
Point operator+(const Point &a, const ... | 5 |
#include<iostream>
using namespace std;
#define MAX 1000000
typedef long long llong;
int m, k;
llong T[MAX];
int check(llong p) {
int i = 0;
for (int j = 0; j < k; j++ )
{
llong s = 0;
while( s + T[i] <= p ) {
s += T[i];
i++;
if (i == m ) return m;
}
}
return i;
}
int solve() {
llong left = 0;
llong right = 10000... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a[n];
int freq[101] = {0};
for (int i = 0; i < n; i++) {
cin >> a[i];
freq[a[i]] += 1;
}
int ans = 0;
int i;
int f = 0;
for (i = 0; i <= 100; i++) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
string s = "";
string ans = "";
int n = s.size();
bool check(int pos) {
if (pos == 0) return true;
if (islower(s[pos]))
return false;
else
return check(pos - 1);
}
int main() {
cin >> s;
auto str = s.c_str();
int n = s.size();
bool upFlag = false, lowF... | 1 |
#include <bits/stdc++.h>
using namespace std;
void help() {
int n, k;
cin >> n >> k;
map<int, vector<int>> mp;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
if (mp[x].size() < k) mp[x].push_back(i);
}
vector<int> ans(n, 0);
int m = 0;
for (auto i : mp) {
m += i.second.size();
}
m -=... | 2 |
#include <bits/stdc++.h>
using namespace std;
using INT = long long;
using pii = pair<int, int>;
using pi3 = pair<int, pii>;
int n, m;
int nxt[100010];
int a[100010], b[100010];
set<pii> A, B;
set<pi3> ans;
int calc_max(int u, set<pair<int, int> > &st) {
auto it = st.upper_bound({m - 1 - u, n + 100});
if (it == st.... | 5 |
#include<iostream>
#include<string>
using namespace std;
int main() {
int m, g;
int n;
while (cin >> n&&n != 0) {
m = 0;
g = 0;
string a;
bool l = true;
for (int i = 0; i < n; i++) {
cin >> a;
if (a == "A") {
m++;
}
else if(a=="Un"){
m--;
}
if (m<0) {
l = false;
}
}
if ... | 0 |
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
double x[1100], y[1100];
void init()
{
x[0] = y[0] = 0.0;
x[1] = 1.0;
y[1] = 0.0;
for (int i = 2; i < 1100; i++) {
double d = sqrt(x[i - 1] * x[i - 1] + y[i - 1] * y[i - 1]);
double dx = -y[i - 1] / d;
... | 0 |
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#inclu... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, i;
cin >> a;
cin >> b;
for (i = 1; a <= b; i++) {
a = 3 * a;
b = 2 * b;
}
cout << i - 1;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
const int seed = 233233;
const int maxn = 100009;
const int maxm = 35;
int f[maxn][maxm], power[maxn], hashS[maxn], hashT[maxn];
char s[maxn], t[maxn];
int n, m, x, l, ans;
void init() {
power[0] = 1;
for (int i = 1; i < maxn; i++) power[i] = ... | 5 |
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#def... | 0 |
#include<algorithm>
#include<cstdio>
using namespace std;
const int mod=1e9+7;
int n,m,fac[4000010],ifc[4000010],dp[2010][2010];
int pow(int k,int i)
{
int t=1;
while(i)
{
if(i&1) t=1ll*t*k%mod;
k=1ll*k*k%mod;i>>=1;
}
return t;
}
int C(int x,int y)
{
if(x<y) return 0;
return 1ll*fac[x]*ifc[y]%mod*ifc[x-y]%mo... | 0 |
#include <bits/stdc++.h>
int len, n, m;
char opt[2000005];
int dfs(int A, int B) {
while (1) {
if (A >= B)
opt[++len] = 'T', A -= B;
else
opt[++len] = 'B', B -= A;
if (!A || !B) return A ^ B;
if (len > n) return -1;
}
}
int ans = 0x7f7f7f7f, ansx, ansy;
void work(int A, int B) {
len = ... | 2 |
#include <iostream>
using namespace std;
int main(){
int n;
long a, max=-1000000, min=1000000, sum=0;
cin >> n;
for(int i=0; i<n; i++){
cin >> a;
if(a>max) max = a;
if(a<min) min = a;
sum+=a;
}
cout << min << " " << max << " " << sum << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
#pragma GCC optimize "-O3"
using namespace std;
const long long ML = 1000;
const int C = 3;
const double PI = acos(-1.0);
int rev(int x, int k) {
int ans = 0;
for (int i = 0; i < k; ++i) {
ans = ans * 2 + (x & 1);
x >>= 1;
}
return ans;
}
void fft(complex<double> *a, int k, int ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int const N = 200200;
int n, m, a, b, t, Enter;
pair<int, int> Seg[10 * N], Lazy[10 * N];
int Depth[N], In[N], Out[N], Arr[N];
vector<int> Tree[N];
void DFS(int u = 1, int p = -1) {
In[u] = ++Enter;
for (auto i : Tree[u])
if (i != p) {
Depth[i] = Depth[u] + 1;... | 5 |
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
long long c[100005];
int main()
{
long long k;
long long n,i,a,b;
cin >> n >> k;
for(i=0; i<n; i++)
{
cin >> a >> b;
c[a]+=b;
}
for(i=1; i<=100000; i++)
{
k-=c[i];
if(k<=0)
{
cout << i;
break;
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const long long mod = 1e9 + 7;
int n, k, m;
map<int, int> id;
int num[maxn];
int unlucky;
long long quick_pow(long long a, long long p, long long n) {
long long ret = 1;
while (p) {
if (p % 2 == 1) ret = ret * a % n;
a = a * a % n;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, k, i, a, f = 0, tw1 = 0, tw2 = 0;
cin >> n >> k;
for (i = 0; i < k; i++) {
cin >> a;
f += a / 4;
a %= 4;
if (a == 3)
f++;
else {
if (a == 2) tw2++;
if (a == 1) tw1++;
}
}
long long int tt = 2 ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int i, j, x, y, N, M; cin >> N >> M; string A[N], B[M];
for(i=0; i<N; i++){ cin >> A[i]; }
for(i=0; i<M; i++){ cin >> B[i]; }
int d=N-M;
for(x=0; x<=d; x++){for(y=0; y<=d; y++){
for(i=0; i<M; i++){for(j=0; j<M; j++){ if(A[i+x][j+y]!=B[i][j]){i=M+1; break;} }}
i... | 0 |
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int a[7],m;
int right[25]={0,2,3,5,4,1,4,6,3,1,2,6,5,1,5,6,2,1,3,6,4,2,4,5,3};
for(int i=1;i<7;i++)
{
cin>>a[i];
}
cin>>m;
for(int i=0;i<m;i++)
{
int top,front;
cin>>top>>front;
... | 0 |
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T>
int sz(const T &a){return int(a.size());}
const int MN=601;
int dist[MN];
bool used[MN];
int arr[MN][MN];
int main(){
cin.tie(NULL);
ios_base::sync_with_stdio(false);
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, k, nlen;
char name[110], des[110], ope[110];
bool flag, pos[110];
bool judge(int p) {
p = p - nlen + 1;
if (p < 0) return true;
for (int i = 0; i < nlen; ++i) {
if (des[p + i] == name[i])
continue;
else
return true;
}
return false;
}
boo... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct node {
node(long long vl, int sz) {
val = vl;
size = sz;
left = NULL;
right = NULL;
}
unordered_map<int, int> upd1;
unordered_map<int, int> upd2;
long long val;
int size;
node *left, *right;
};
struct str {
node *root = NULL;
void in... | 6 |
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/
#include<bits/stdc++.h>
using namespace std;
#define io ios_base::sync_with_stdio(false)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vll vector<long long>
#define pb push_back
#define mod 1000000007
#de... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 20;
struct edge {
long long to, co;
edge(long long a = 0, long long b = 0) : to(a), co(b) {}
};
vector<edge> adj[MAX];
long long A[MAX], S[MAX];
long long dp[MAX];
long long c[MAX];
vector<int> childs[MAX];
int n;
void dfs(int v, int pa, long long ... | 4 |
#include <bits/stdc++.h>
using namespace std;
bool judge(int x) {
int m = sqrt(x + 0.5);
for (int i = 2; i <= m; i++)
if (x % i == 0) return false;
return true;
}
int main() {
int n;
cin >> n;
if (judge(n))
cout << 1;
else if (n % 2 == 0)
cout << 2;
else if (judge(n - 2))
cout << 2;
el... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 7;
char s[MAXN];
int main() {
scanf("%s", s);
int n = strlen(s), cnt1 = 0, pos = n;
for (int i = n - 1; i >= 0; i--) {
if (s[i] == '1') {
s[i] = '#';
cnt1++;
}
if (s[i] == '2') pos = i;
}
for (int i = 0; i < pos; i++)... | 2 |
#include <bits/stdc++.h>
long long R = 7 + 1e9, NUMTESTCASE;
const int NN = 10 + 1e5, MM = (1 << 8);
const double pi = acos(-1.0);
int di[4] = {1, 0, -1, 0}, dj[4] = {0, 1, 0, -1},
DI[8] = {1, 1, 0, -1, -1, -1, 0, 1}, DJ[8] = {0, 1, 1, 1, 0, -1, -1, -1};
using namespace std;
long long n, p, x, k, Arr[NN][10], Memo[... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, ans = 0;
cin >> n;
pair<int, int> xy[n];
bool puntos[2001][2001];
for (int i = 0; i < n; i++) {
cin >> xy[i].first >> xy[i].second;
xy[i].first += 1000;
xy[i].second += 1000;
puntos[xy[i].first][xy[i].second] = 1;
}
for (int... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MM = 2e5 + 5;
int n, k, a, b, q, pref[MM], suff[MM], cnt[MM];
void upd(int bit[], int x, int v) {
for (; x < MM; x += x & -x) {
bit[x] += v;
}
}
int get(int bit[], int x) {
int res = 0;
for (; x > 0; x -= x & -x) res += bit[x];
return res;
}
int get(... | 2 |
#include <bits/stdc++.h>
using namespace std;
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
void Open() {}
int main() {
fast();
int t, n;
cin >> t;
while (t--) {
cin >> n;
vector<long long> v(n + 1);
for (int i = 1; i <= n; i++) {
cin >> v[i];
}
... | 2 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1, c = getchar();
while (!isdigit(c)) {
if (c == '-') f = -1;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f == 1 ? x : -x;
}
const int N = 5e5 + 4;
int n, Q,... | 6 |
#include <bits/stdc++.h>
using namespace std;
double abss(double a) {
if (a < 0) return -a;
return a;
}
int main() {
long long ost = 1000000007;
int n, k, m, d;
cin >> n >> k;
string s;
cin >> s;
vector<long long> x(k, 0);
vector<bool> f(k, true);
long long p = 1, q;
m = s.length();
for (int i =... | 5 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
int n;
cin >> n;
cout << 1 << ' ' << 0 << endl;
if (n == 1) {
cout << 0 << ' ' << 1 << ' ' << 1 << ' ' << 1 << endl;
exit(0);
}
string color;
cin >> color;
int step = (1 << (n - 2));
int cur = 0;
int fig = 1;
for (int i = 1; i ... | 3 |
#include <bits/stdc++.h>
using namespace std;
bool fight(int h1, int a1, int h2, int a2) {
int d2;
if (a2 <= 0 and a1 > 0) return true;
if (a1 <= 0) return false;
if (h2 % a1 == 0)
d2 = h2 / a1;
else
d2 = h2 / a1 + 1;
h1 = h1 - (d2 * a2);
h2 = h2 - (d2 * a1);
if (h1 > 0)
return true;
else
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
cin >> T;
while (T--) {
int a, b, c, d, k, minn, maxx;
cin >> a >> b >> c >> d >> k;
if (a % c != 0)
minn = a / c + 1;
else
minn = a / c;
if ((k - minn) * d >= b) {
cout << minn << " " << k - minn;
} else {... | 1 |
#include<bits/stdc++.h>
using namespace std;
int n;
int main(){
cin>>n;
cout<<n*n*n;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const long long LLINF = 9223372036854775807LL;
int m;
const int mod = 1000000007;
struct matr {
int a[60][60];
matr() { memset(a, 0, sizeof(a)); }
};
matr mul(matr m1, matr m2) {
matr res;
for (int i = 0; i < m; ++i)
for (int j = 0; j... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
ios_base::sync_with_stdio(0);
;
string s;
cin >> s;
vector<int> sol(s.size());
for (int i = 0; i < s.size(); i++) {
int val = s[i] - '0';
sol[i] = val % 3;
}
int ans = 0;
int sum = 0;
int sumM... | 4 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.