solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int n;
const int N = 101235;
int a[N], b[N];
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
for (int i = 0; i < m; i++) scanf("%d", &b[i]);
int up = 0, down = 0;
long long ans = 0;
long long sumU = 0, sumD = 0;
sumU += ... | 2 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ss = stringstream;
using ul = unsigned long long;
template <typename T>
inline T LCM(T a, T b) {
return (a * b) / GCD(a, b);
}
template <typename T>
inline T GCD(T a, T b) {
ll t;
while (a) {
t = a;
a = b % a;
b = t;
}
retur... | 3 |
#include <bits/stdc++.h>
using namespace std;
inline void pisz(int n) { printf("%d\n", n); }
const int fx[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
const int fxx[8][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0},
{1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
template <typename T, typename TT>
ostream& operator... | 2 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > p;
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
map<pair<int, int>, vector<pair<pair<int, int>, pair<int, int> > > > m;
double infi = 1000000005;
int main() {
int n;
scanf("%d", &n);
int x, y;
int x1 = 0, y1 = 0, ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int check(int a, int b) {
string x, y;
while (a) {
x.push_back(a % 10);
a /= 10;
}
while (b) {
y.push_back(b % 10);
b /= 10;
}
int ans(0);
while (!x.empty()) {
if (!y.empty() && x.back() == y.back())
y.pop_back(), x.pop_back();
el... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n == 1)
cout << 1 << " " << 1 << "\n" << 1;
else
cout << (n - 1) * 2 << " " << 2 << endl << 1 << " " << 2;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, a1, a2, b1, b2, max1, max2;
cin >> t;
while (t > 0) {
cin >> a1 >> b1;
cin >> a2 >> b2;
max1 = max(a1, b1);
max2 = max(a2, b2);
if (max1 == max2) {
int min1, min2;
min1 = min(a1, b1);
min2 = min(a2, b2);
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 6000;
int t[maxn], l[maxn], r[maxn], d[maxn], a[maxn], b[maxn];
int n, m;
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) a[i] = 5e7;
for (int i = 1; i <= m; i++) cin >> t[i] >> l[i] >> r[i] >> d[i];
for (int i = m; i >= 1; i--) {
if (t... | 3 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int res = 0;
bool zf = 0;
char c;
while (((c = getchar()) < '0' || c > '9') && c != '-')
;
if (c == '-')
zf = 1;
else
res = c - '0';
while ((c = getchar()) >= '0' && c <= '9')
res = (res << 3) + (res << 1) + c - '0';
if (z... | 5 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
long long n;
string second;
long long cnt1 = 0, cnt2 = 0;
vector<long long> v;
int32_t main() {
ios_base::sync_with_stdio();
cin.tie();... | 1 |
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
vector<string> text;
while ( true )
{
string t;
getline( cin, t );
if ( t == "END_OF_TEXT" )
break;
text.push_back( t );
}
int cx = 0;
int cy = 0;
string buf;
while ( true )
{
char c;
cin >> c;
if ( c... | 0 |
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define MOD 998244353
#define inf 9e18
#define tikoo (int) (1e9 + 7)
template<typename T, typename T1> T max(T a, T1 b) { if (b > a) a = b; return a; }
template<typename T, typename T1> T min(T a, T1 b) { if (b < a) a = b; return a; }
int fastpow(int a... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e3 + 5;
char ch[3] = {'R', 'G', 'B'};
string str;
int main() {
int q;
cin >> q;
while (q--) {
int n, k;
cin >> n >> k;
cin >> str;
int tmp = 0;
int ans = maxn;
int cnt = 0;
for (int i = 0; i <= n - k; i++) {
for (int... | 4 |
#include <bits/stdc++.h>
int main() {
int n, sum, rem, rem1, sum1;
scanf("%d", &n);
n = n + 1;
while (n > 0) {
int temp = n;
while (temp > 0) {
rem = temp % 10;
temp /= 10;
sum = temp % 10;
temp /= 10;
rem1 = temp % 10;
temp /= 10;
sum1 = temp % 10;
temp /... | 1 |
#include <iostream>
using namespace std;
int dn[33];
int main(){
int n=0;
dn[0]=1;
for(int i=0;i<30;i++){
for(int j=1;j<=3;j++){
dn[i+j]+=dn[i];
}
}
while(true){
cin >> n;
if(n==0)
break;
int l=dn[n]/(365*10);
if(dn[n]%(365*10)!=0)
l++;
cout << l << endl;
}
} | 0 |
#include <bits/stdc++.h>
#define inv(n) qpow(n, M-2)
using namespace std;
const long long M = 1000003;
typedef long long ll;
int fact[M];
int qpow(long long a, int n) {
return (n?(qpow(a*a%M, n/2)*(n%2?a:1)):1)%M;
}
int main() {
fact[0] = 1;
for (int i = 1; i < M; ++i)
fact[i] = (ll)fact[i-1]*i%M;
int q, x, ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MB = 1 << 20;
struct FastIO {
char ib[MB + 100], *p, *q;
char ob[MB + 100], *r, stk[128];
int tp;
FastIO() { p = q = ib, r = ob, tp = 0; }
~FastIO() { fwrite(ob, 1, r - ob, stdout); }
char read_char() {
if (p == q) {
p = ib, q = ib + fread(ib... | 6 |
#include <stdio.h>
char a[500];
int main(){
scanf("%s",a);
printf("%s\n",a[0]=='S'?"Cloudy":(a[0]=='C'?"Rainy":"Sunny"));
} | 0 |
#include <bits/stdc++.h>
using namespace std;
bool same[50];
vector<int> ones[50], cero[50];
int main() {
int n, x, y;
scanf("%d %d %d", &n, &x, &y);
for (int i = 1; i <= n; i++) {
for (int j = 0; j < int(10); j++)
if ((i & (1 << j)) != 0)
ones[j].push_back(i);
else
cero[j].push_ba... | 5 |
#include <bits/stdc++.h>
int n, a, b, c, ans;
long long int t[110000][2];
int sum;
int main() {
scanf("%d", &n);
scanf("%d", &t[0][0]);
t[0][1] = 20;
sum = 20;
printf("20\n");
for (int i = 1; i < n; i++) {
scanf("%d", &t[i][0]);
a = sum + 20;
int whatever = std::max(0, i - 91);
b = 200000000... | 2 |
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
using namespace std;
#define FOR(i,k,n) for(int i=(k); i<(int)n; +... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N_DEL = 0, N_VAL = 0;
inline int mOp(int x, int y) { return x + y; }
inline int qOp(int lval, int rval) { return lval ^ rval; }
inline int dOnSeg(int d, int len) { return d == N_DEL ? N_DEL : d * len; }
inline int joinD(int d1, int d2) {
if (d1 == N_DEL) return ... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct node {
string type;
int val;
int left, right;
};
vector<int> vals;
vector<node> nodes;
vector<int> depths;
vector<list<int>> changes;
void dfs(int x, int depth) {
depths[x] = depth;
if (nodes[x].type == "IN")
vals[x] = nodes[x].val;
else {
dfs(nod... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 0x3f3f3f3f3f3f3f3f;
const long long N = 5000;
long long n, m, s, t;
vector<pair<long long, pair<long long, long long> > > nei[N + 1];
vector<long long> rv[N + 1];
void ae(long long x, long long y, long long c, long long w) {
nei[x].push_back(make_pai... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long double pi = acos(-1);
const int MOD = 1e9 + 7;
const long long int LINF = 0x3f3f3f3f3f3f3f3f;
const int MAXSZ = 4000006;
const int MAXN = 100005;
int tr[MAXSZ], L[MAXSZ], R[MAXSZ], root[MAXSZ], ptr, n, q, a[MAXN], last[MAXN];
int m(int... | 5 |
#include <iostream>
#include <vector>
#include <string>
using namespace std;
using cat = long long;
cat pw(cat a, cat e, cat mod) {
if(e <= 0) return 1;
cat x = pw(a, e/2, mod);
x = x * x % mod;
return e&1 ? x * a % mod : x;
}
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int N, M;
cin >> N ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 505;
int n, m, ret;
bool Map[N][N], tMap[N][N];
int LEFT[N][N], UP[N][N], UPLEFT[N][N], UPRIGHT[N][N];
string s;
void Rotate() {
for (int i = 1; i <= int(n); i++) {
for (int j = 1; j <= int(m); j++) {
tMap[j][i] = Map[i][j];
}
}
swap(n, m);... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, k, l, cnt, at;
int op[200002], oper[200002];
int a[200002];
char s[200002];
int v[200000];
long long sums[5][10000], ans;
int mod5[10000];
void recalc(int at) {
int i, j;
for (i = 0; i < 5; i++) sums[i][at] = 0;
j = 0;
for (i = k * at; i < k * (at + ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 10;
char ch[10][10];
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
for (int i = 1; i <= 9; i++) {
char ch1;
for (int j = 1; j <= 9; j++) {
cin >> ch1;
if (ch1 == ' ') {
cin >> ch[i][j];
} else {
... | 2 |
#include <bits/stdc++.h>
const int MAXN = 1e5 + 5;
int n, k;
bool vis[MAXN];
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
scanf("%d%d", &n, &k);
for (int i = 0; i < n; i++) {
int a;
scanf("%d", &a);
vis[a % k] = true;
}
int cur = 0;
for (int i = 0; i < k; ... | 5 |
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).... | 0 |
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
typedef long long int ll;
using namespace std;
struct UnionFind {
vector<int> par;
vector<int> rank;
UnionFind(int n) : par(n), rank(n, 1) {
for(int i=0; i<n; ++i) par[i] = i;
}
in... | 0 |
#include <bits/stdc++.h>
using namespace std;
int N, M, MAX, REG, ROUND;
int POW[1111], DMG[1111], Ret[1111], Res[1111];
bool ATTACK[1111];
int main() {
scanf("%d%d%d", &N, &MAX, ®);
for (int i = 1; i <= N; i++) scanf("%d%d", &POW[i], &DMG[i]);
int NOW = MAX;
for (int i = 0; i <= MAX + REG; i++) {
ROUND+... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, c[35], d[35], o;
while (cin >> a) {
int i, j;
int b[35][35];
for (i = 0; i < a; i++) {
for (j = 0; j < a; j++) {
cin >> b[i][j];
}
}
for (i = 0; i < a; i++) {
o = 0;
for (j = 0; j < a; j++) {
... | 1 |
#include <bits/stdc++.h>
const int MAXN = 1024;
int n;
inline int LowBit(int x) { return x & -x; }
class C_TreeArray {
public:
C_TreeArray() { memset(tr, 0, sizeof(tr)); }
~C_TreeArray() {}
void Modify(int x, long long v) {
while (x <= n) {
tr[x] ^= v;
x += LowBit(x);
}
}
long long Sum(in... | 4 |
#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFL = 1e18;
const long long N = 1e5 + 7;
const long long hMod = 239017;
int main() {
ios_base::sync_wi... | 5 |
#include <iostream>
using namespace std;
string s;
int main(){
while(1){
cin>>s;
if(s=="0") break;
int ans=0,S=s.size();
for(int i=0;i<S;i++) ans+=s[i]-'0';
cout<<ans<<endl;
}
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int a[3000005], sum[3000005], b[3000005], i, num, allsum, x, y, n, q;
int main() {
scanf("%d%d", &n, &q);
while (q--) {
scanf("%d%d", &x, &y);
if (x == 1) {
a[++num] = y;
sum[y]++;
allsum++;
} else if (x == 2) {
allsum -= sum[y];
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n;
int p[100005];
int main() {
cin >> n;
if (n % 4 > 1) {
cout << -1;
return 0;
}
p[(n + 1) / 2] = (n + 1) / 2;
for (int i = 0; i < n / 4; i++) {
p[1 + 2 * i] = (i + 1) * 2;
p[2 + 2 * i] = n - 2 * i;
p[n - 2 * i] = n - 1 - 2 * i;
p[n - ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int t = 1;
while (t--) {
string s;
cin >> s;
long long int cnt = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || ... | 1 |
#include <bits/stdc++.h>
int N, head[200001], next[399999], to[399999], id[399999], E, O, q[200001],
fa[200001], d[200001];
std::vector<int> V[200001];
int main() {
scanf("%d", &N);
for (int i = 1, u, v; i < N; i++) {
scanf("%d%d", &u, &v);
d[u]++;
d[v]++;
next[++E] = head[u], to[E] = v, id[E] =... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, C;
int none, mx;
int l[(1 << 19)], r[(1 << 19)], cost[(1 << 19)];
int id[(1 << 19)], pos[(1 << 19)];
int ans[(1 << 19)];
map<int, int> two[(1 << 19)];
int one[(1 << 19)];
int mx_with[(1 << 19)];
struct RMQ_Tree {
int n;
int mx[1 << 20];
void init(int _n) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
class Messenger {
const int MAGIC = 200;
vector<bool> isHeavy;
vector<bool> isOnline;
vector<set<int> > lightFriends;
vector<set<int> > heavyFriends;
vector<int> onlineLightFriendCount;
void makeHeavy(int u) {
assert(isHeavy[u] == false);
isHeavy[u] = ... | 4 |
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int long long
using namespace std;
signed main() {
int m; cin >> m;
int a[123456], p = m - 2;
for (int i = 0; i < m; i++)cin >> a[i]; sort(a, a + m, greater<int>());
for (int i = 0; i < m - 1; i++) {
if (a[i + 1] <= 0) {
p = i... | 0 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-10;
const int inf = 1000000009;
int i, j, k, m, n, l;
int ans;
int a[601][601], b[601][601];
long long c[16][16], dp[16][1 << 16], path[16][1 << 16];
long long dist(int i, int j) {
long long ret = 0;
int div = 2;
for (int k = 0; k < n / div; k++)... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
n /= 1000;
if (n & 1)
cout << 2 << endl;
else
cout << 1 << endl;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
int get() {
char ch;
while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-')
;
if (ch == '-') {
int s = 0;
while (ch = getchar(), ch >= '0' && ch <= '9') s = s * 10 + ch - '0';
return -s;
}
int s = ch - '0';
while (ch = getchar(), ch >= '0' &... | 5 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pa... | 0 |
#include <bits/stdc++.h>
using namespace std;
#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))
using ll = long long;
using P = std::tuple<int,int>;
using ui = unsigned int;
const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1},... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void maxi(T &x, T y) {
if (y > x) x = y;
}
template <class T>
inline void mini(T &x, T y) {
if (y < x) x = y;
}
const int N = 1e6 + 5, B = 0x7fffffff;
vector<string> si;
char s[N];
string ss = "";
vector<string> lvl[N];
bool vis[N];
int ma;
int... | 5 |
#include <bits/stdc++.h>
using namespace std;
int a[303], b[303];
int n;
int main() {
int i;
scanf("%d", &n);
for (i = 1; i <= n; ++i) scanf("%d", &a[i]);
for (i = 1; i <= n; ++i) {
while (b[i] < a[i]) {
if (i == n) {
printf("P");
++b[i];
if (b[i] < a[i]) printf("LR");
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3;
int n, k, db;
vector<int> pr;
set<int> s;
bool p[maxn + 1];
void solve() {
cin >> n >> k;
for (int i = 2; i <= maxn; ++i) {
if (p[i]) continue;
pr.push_back(i);
s.insert(i);
for (int j = 2 * i; j <= maxn; j += i) {
p[j] = true... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
class SqrMatrix {
static int n;
static bool objectCreated;
T* values;
public:
SqrMatrix() {
values = new T[n * n];
objectCreated = true;
}
SqrMatrix(int n_) {
if (objectCreated) {
values = new T[n * n];
} else {
... | 3 |
#include <iostream>
#include <string>
using namespace std;
int main() {
int N;
string S;
cin >> N >> S;
if (S.substr(0, N / 2) == S.substr(N / 2, N - N / 2))
cout << "Yes" << endl;
else
cout << "No" << endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000010;
const long long INF = 10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 200010, LOG = 20;
long long n, m, k, u, v, x, y, t, a, b, ans;
long long A[MAXN];
long long seg[MAXN << 2], lazy[MAXN << 2];
int Mn[MAXN << 2], Mx[MAXN << 2];... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long n;
cin >> n;
vector<long> v(n + 1);
map<long, long> m;
for (int i = 1; i <= n; i++) {
cin >> v[i];
m[v[i]]++;
}
long long ans = 0;
for (int i = 1; i <= n; i++) {
long j = 0;
while (j <= 31) {
long long curr = pow(2, j)... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 5;
int a, n, mn = N, Cnt[N], Brk[N], Rnk[N], Saa[N], Hgh[N];
char Str[N];
void Init() {
int m = 0;
for (int i = 1; i <= n; ++i) m = max(m, Rnk[i] = Str[i]);
for (int i = 1; i <= n; ++i) ++Cnt[Rnk[i]];
for (int i = 1; i <= m; ++i) Cnt[i] += Cnt[i ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 4e5 + 5;
int f[MAXN], u[MAXN], v[MAXN], con[MAXN];
pair<int, int> ans[MAXN];
bool ss[MAXN], tt[MAXN];
int n, m, tot;
int s, t, ds, dt, fa, fb;
int brg, both, now;
int find(int a) {
if (a != f[a]) f[a] = find(f[a]);
return f[a];
}
int main() {
while (~... | 6 |
#include <bits/stdc++.h>
using namespace std;
int arr[200009];
int main() {
int n, a, b, i, z = 1000000009, k;
string s;
cin >> n >> s;
for (int i = 0; i < n; i++) cin >> arr[i];
for (int i = 0; i < n - 1; i++) {
if (s[i] == 'R' && s[i + 1] == 'L') k = (arr[i + 1] - arr[i]) / 2;
z = min(z, k);
}
i... | 1 |
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int gi(){
int x=0,w=1;char ch=getchar();
while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
if(ch=='-')w=0,ch=getchar();
while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
return w?x:-x;
}
#define ll long long
const int N=1e5+5;
int n,... | 0 |
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
using ll = long long;
int ask(int x, int y) {
cout << "? " << x << ' ' << y << endl;
int r;
cin >> r;
return r;
}
int main() {
int n;
cin >> n;
vector<int> p(n +... | 3 |
#include <bits/stdc++.h>
int main() {
int a, b;
scanf("%d", &a);
for (int i = 1;; ++i) {
a++;
b = a;
if (b < 0) b = -b;
while (b > 0) {
if (b % 10 == 8) {
printf("%d", i);
return 0;
}
b = b / 10;
}
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k = 0, cnt = 0;
string s;
cin >> s;
while (s.length() > 1) {
k = 0;
for (int i = 0; i < (int)s.length(); i++) k += (s[i] - '0');
s = to_string(k);
cnt++;
}
cout << cnt;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
long long N, L, c[32], l[32], better[32], rubles[32], i,
ans = 1000000000000000000, now, ultim;
int main() {
cin >> N >> L;
for (int i = 1; i <= N; i++) cin >> c[i];
l[1] = 1;
for (int i = 2; i <= N; i++) l[i] = 1LL * 2 * l[i - 1];
better[1] = c[1];
for (int... | 3 |
#include <bits/stdc++.h>
const long long inf = 1e9 + 44;
const int MAX = 3e5 + 9;
const long long MOD = 1e9 + 7;
const double eps = 1e-10;
double const PI = 3.1415926535897931;
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
void _print(vector<int> v) {
cout << "[ ";
for (auto u : v) cout... | 3 |
#include <bits/stdc++.h>
using namespace std;
#define int long long
int a[100010];
int rui[300010];
int rui2[300010];
int n, m;
int isOK(int num){
int ans = 0;
for(int i = 0;i < n;i++){
ans += rui[max(num-a[i], 0ll)];
}
return ans;
}
int solve(int num){
int ans = 0;
for(int i = 0;... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long BIAS = 1e18;
long long Mo;
long long g[20], e[20];
void step() {
e[0] = 1;
for (int i = 1; i <= 18; i++) e[i] = e[i - 1] * 10 % Mo;
g[1] = 45 % Mo;
for (int i = 2; i <= 18; i++)
g[i] = (g[i - 1] * 10 % Mo + e[i - 1] * g[1] % Mo) % Mo;
}
int main(... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
struct mint {
long long x;
mint() : x(0) {}
mint(long long x) : x((x % mod + mod) % mod) {}
mint& fix() {
x = (x % mod + mod) % mod;
return *this;
}
mint operator-() const { return mint(0) - *this; }
mint& operator+=(c... | 1 |
#include <bits/stdc++.h>
using namespace std;
int find(vector<int> &w, int a) {
int i = 0;
int n = w.size() - 1;
while (i < n) {
int mid = (i + n) / 2;
if (a == w[mid]) {
return mid + 1;
} else if (a > w[mid]) {
i = mid + 1;
} else {
n = mid;
}
}
return i + 1;
}
int main(... | 2 |
#include <bits/stdc++.h>
using namespace std;
int arr[10000000] = {0};
int main() {
long long int a, b, c, l;
scanf("%lld %lld %lld", &a, &b, &c);
long long int i, j, k, sum = 0;
for (i = 1; i <= a; i++) {
for (j = 1; j <= b; j++) {
for (k = 1; k <= c; k++) {
long long int num = i * j * k;
... | 2 |
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
int main(){
bool judge;
char tmp[7],tmp2[7];
int sta,sta2;
char num[7],num2[7];
cin >> sta;
sta2 = sta;
while(1){
sprintf(num,"%d",sta);
sprintf(num2,"%d",sta2);
if(strlen(num... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<pair<int, int> > a;
vector<int> lnum;
int e[100005];
vector<pair<int, int> > res;
int p[100005];
int tr[100005];
int des;
bool luck(int u) {
while (u > 0) {
if (u % 10 != 4 && u % 10 != 7) return false;
u /= 10;
}
return true;
}
void find(int u) ... | 4 |
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin>>n;
int a[n],i,c=0;
for(i=0;i<n;i++)
{
cin>>a[i];
}
for(i=0;i<n;i++)
{
if(a[i]!=i+1)
c++;
}
if(c<=2)
cout<<"YES";
else
cout<<"NO";
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000005, mod = 1e9 + 7;
int n, a[MAXN];
int p[MAXN];
long long sum[MAXN];
int f[MAXN], dp[MAXN];
inline long long gcd(long long a, long long b) {
return b == 0 ? a : gcd(b, a % b);
}
inline int read() {
int a = 0, c;
do c = getchar();
while (!isdigi... | 3 |
#include <bits/stdc++.h>
using namespace std;
struct DATA {
int num, va;
int p[205];
} d[205];
int a[205], ans[205];
bool cmp(DATA x, DATA y) { return x.num > y.num; }
int main() {
int i, j, n, num;
scanf("%d", &n);
for (i = 0; i <= 103; i++) d[i].num = 0, d[i].va = i;
for (i = 1; i <= 2 * n; i++) {
sca... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
int sum[maxn];
long long a[maxn], b[maxn];
long long n, k;
bool solve(long long now) {
long long ans = 0;
memset(sum, 0, sizeof(sum));
if (now == 0) {
for (int i = 1; i <= n; i++) {
if (((b[i] + a[i] - 1) / b[i]) < (k - 1)) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1000000000;
long long n, c, x, y;
long long dist(long long x1, long long y1, long long x2, long long y2) {
return abs(x1 - x2) + abs(y1 - y2);
}
long long cnt(long long t) {
if (t == 0) return 1;
long long sum = t * t + (t + 1) * (t + 1);
if (x... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
long long a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
if (n % 2 == 0) {
cout << a[(n / 2) - 1];
} else if (n % 2 == 1) {
cout << a[n / 2];
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
#define INF 1000000000
#define MAX_V 202
using namespace std;
typedef pair<int, int> P;
struct edge {
int to, cap, cost, rev;
edge(int to_, int cap_, int cost_, int rev_)
: to(to_), cap(cap_), cost(cost_), rev(rev_) {}
};
int V;
vector<edge> G[MAX_V];
int h[MAX_V];
int dist[MAX_V];
int pre... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, i, j, k;
cin >> n >> m;
vector<int> v1[505 * 2];
vector<int> v2[505 * 2];
int a, b, l1, l2;
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
cin >> a;
v1[i + j].push_back(a);
}
}
for (i = 0; i < n; i++) {
for... | 3 |
#include <bits/stdc++.h>
#define ALL(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int mod = 1e9 + 7;
void mul(vector<vector<ll>>& A, vector<vector<ll>> B) {
int n = A.size();
vector<vector<ll>> C(n, vector<ll>(n));
for(int i = 0; i < n; i++) {
for(int j = 0; j < n... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int tt;
cin >> tt;
while (tt) {
string s;
cin >> s;
int t, b, l, r;
int t0, t1, b0, b1, l0, l1, r0, r1;
t = b = l = r = t0 = t1 = b0 = b1 = l0 = l1 = r0 = r1 = 0;
int x = 0, y = 0;
f... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, m, a[800001], w[800001], q[800001][4], f[800001];
struct node {
int x, y, z, type, pos;
bool operator<(const node &A) const { return x < A.x; }
} c[2000001];
inline void add(int x, int y) {
for (; x <= n; x += x & (-x)) f[x] += y;
}
int calc(int x) {
int will... | 3 |
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loo... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
long long x[3005][3005], dp[3005][3005][4], ans;
int main() {
scanf("%d%d%d", &n, &m, &k);
while (k--) {
int ta, tb;
long long tc;
scanf("%d%d%lld", &ta, &tb, &tc);
x[ta][tb] += tc;
}
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, B;
cin >> n >> B;
int a[n + 1];
a[0] = 0;
int* oddNum = new int[n + 1];
int* evenNum = new int[n + 1];
memset(evenNum, 0, n + 1);
memset(oddNum, 0, n + 1);
for (int i = 1; i < n + 1; i++) {
cin >> a[i];
if (a[i] % 2 == 0) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
map<pair<pair<long long int, long long int>,
pair<long long int, long long int>>,
long long int>
pqr;
map<pair<long long int, long long int>, long long int> xyz;
map<long long int, long long int, greater<long long int>> yz;
vector<pair<long long int, string... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, i, arr[200005];
cin >> n;
for (i = 0; i < n; i++) cin >> arr[i];
long long ans = 1, maxi = 1;
for (i = 1; i < n; i++) {
if (arr[i - 1] * 2 >= arr[i])
ans++;
else
ans = 1;
maxi = max(maxi, ans);
}
cout << maxi <... | 2 |
#include <bits/stdc++.h>
#pragma optimize("O3")
using namespace std;
const int N = 1005;
int cnt[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
;
int m, n;
cin >> n >> m;
int u, v;
for (int i = 0; i < m; i++) {
cin >> u >> v;
cnt[u]++;
cnt[v]++;
}
cout << n - 1 <<... | 2 |
#include <bits/stdc++.h>
using namespace std;
char buf[1 << 21], *p1 = buf, *p2 = buf;
template <class T>
void read(T &x) {
x = 0;
int c = getchar();
int flag = 0;
while (c < '0' || c > '9') flag |= (c == '-'), c = getchar();
while (c >= '0' && c <= '9')
x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
... | 3 |
#include<iostream>
#include<iomanip>
using namespace std;
int main() {
double n, m, d;
cin>>n>>m>>d;
if(d==0){
cout<<setprecision(20)<<(m-1)/n<<endl;
}
else{
cout<<setprecision(20)<<(n-d)*2*(m-1)/(n*n)<<endl;
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, t; cin >> s >> t;
cout << (s == t.substr(0, ~-t.length()) ? "Yes" : "No") << endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10, mod = 1e9 + 7;
long long qpow(long long x, int y) {
long long res = 1;
while (y) {
if (y & 1) res = res * x % mod;
x = x * x % mod;
y /= 2;
}
return res;
}
void add(long long &x, long long y) {
x += y;
if (x >= mod) x -= mo... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int T, n, i, j, k;
cin >> T;
string str;
for (i = 0; i < T; i++) {
cin >> n;
cin >> str;
for (j = 0, k = n - 1; j < n / 2; j++, k--) {
if (abs(str.at(j) - str.at(k)) != 2 && abs(str.at(j) - str.at(k)) != 0) {
cout << "NO" << en... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1000005;
const double eps = 1e-8;
const double DINF = 1e100;
const int INF = 1000000006;
const long long LINF = 1000000000000000005ll;
struct Edge {
int a, b, c;
Edge() {}
Edge(int a, int b, int c) : a(a), b(b), c(c) {}
} edge[MaxN];
int fa[MaxN];
int... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7, MAXN = 1e6 + 10, INF = 1e18;
long long n, ans[10], a = 1, ans1;
int main() {
cin >> n;
while (n) {
for (long long i = 0; i < n % 10; i++) {
ans[i] += a;
}
n /= 10;
a *= 10;
}
for (long long i = 0; i < 10; i++) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main(){
string s,w;
cin>>s>>w;
reverse(s.begin(), s.end());
if(s == w)puts("YES");
else puts("NO");
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int base = 1e9;
const int maxn = 105;
const int logn = 20;
const int inf = 2e9;
const int alpha = 26;
const int my_hash = 29;
const int my_mod = 2495828519;
const long long l_inf = 4e18;
const long long mod = 1e9 + 7;
const double pi = acos(-1.0);
const double eps = 1... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 100;
string s;
int a[N];
int k;
int cnt = 0;
bool judge(int x) {
int num = 1;
int len = 0;
for (int i = 0; i < cnt; i++) {
if (len + a[i] <= x) {
len += a[i];
} else {
if (a[i] > x)
return 0;
else {
num++;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct node {
long long u, v, next, w, p, c;
} edge[400005];
long long cnt, nxt[200005], sum[200005];
void link(long long u, long long v, long long w, long long p) {
edge[cnt] = {u, v, nxt[u], w, p, 0};
nxt[u] = cnt++;
}
void dfs(long long u) {
long long i, v, tmp;
... | 5 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.