solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
bool prime[1000001];
long long f[1000005];
long long pow1(long long x, long long y) {
long long res = 1;
x = x % mod;
if (x == 0) return 0;
while (y > 0) {
if (y & 1) res = (res * x) % mod;
y = y >> 1;
x = (x * x) % mod;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int n = s.size(), ans = 0, k1 = -1;
for (int k = 0; k < n - 3; k++)
if (s.substr(k, 4) == "bear") {
int a1 = (k - k1) * (n - k - 3);
ans += a1;
k1 = k;
}
cout << ans << endl;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 7;
const int INF = 1e9 + 7;
int n, c, p_1[N], p_2[N], t_1[N], t_2[N], ans_1, ans_2, T_1, T_2;
int main() {
cin >> n >> c;
for (int i = 1; i <= n; i++) {
cin >> p_1[i];
p_2[i] = p_1[i];
}
for (int i = 1; i <= n; i++) {
cin >> t_1[i];
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int times[100005];
int sum;
int ans[100005];
int num[100005];
int pos[100005];
struct q {
int l;
int r;
int id;
} a[100005];
int n, m;
void init() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) scanf("%d", &num[i]);
int block = int(sqrt(n));
for (int i ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const int inf = 2000000000;
const long long infLL = 9000000000000000000;
template <typename first, typename second>
ostream& operator<<(ostream& os, const pair<first, second>& p) {
return os << "(" << p.first << ", " << p.second << ")";
}
template... | 3 |
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
int input() {
int r;
scanf("%lld", &r);
return r;
}
int f1(int a, int p) {
if (p == 1)return a;
if (p % 2)return f1(a, p - 1) * a % mod;
else {
return f1(a * a % mod, p / 2) ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_BUF_SIZE = 16384;
char BUFOR[MAX_BUF_SIZE];
int BUF_SIZE, BUF_POS;
char ZZZ;
const int MXN = 1000010;
const int C = 262144;
const int INF = 1000000001;
int a[MXN];
int n;
void test() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
lon... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const double PI = acos(-1.0);
const double EPS = 1e-9;
struct Point {
long long x;
long long y;
Point() {
x = 0LL;
y = 0LL;
}
Point(long long _x, long long _y) {
x = _x;
y = _y;
}
};
struct Vector {
long long x;
lo... | 4 |
#include <bits/stdc++.h>
using namespace std;
void solve();
int main() {
cin.sync_with_stdio(false);
solve();
return 0;
}
char s[4020][4020];
void solve() {
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> s[i];
reverse(s[i], s[i] + n);
}
int revgor[4020], revvert[4020];
int ans = 0;
me... | 3 |
#include<iostream>
int main(){int a,b,c;std::cin>>a>>b>>c;std::cout<<(b/a>c?c:b/a);} | 0 |
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZER... | 0 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0;
char ch;
while (!isdigit(ch = getchar()))
;
x = ch - 48;
while (isdigit(ch = getchar())) x = x * 10 + ch - 48;
return x;
}
const int MAXN = 2e5 + 5;
int n, m, k;
vector<pair<int, int> > t[4], tmp;
vector<int> ans;
inline int ca... | 5 |
#include <bits/stdc++.h>
using namespace std;
struct Point {
int x, y;
} point[100010];
int n;
int maxn[100010][2];
int minn[100010][2];
bool cmp1(Point a, Point b) { return a.x < b.x; }
long long solve() {
long long st = 0, ed = (long long)200000000 * (long long)200000000;
long long mid;
long long maxx, minx;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200005, K = 3005;
struct node {
int l, r, tim, id;
} q[N];
struct node2 {
int v, id, kd;
} ls[N];
struct node3 {
int p, v;
} q2[N];
int n, m, nn, q1, qt, now, opt, size, size2, bl[N], a[N], ans[N], tot[N],
totk[K], cnt[N], bl2[N];
bool cmd(node a, no... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int num[6][3] = {{0, 1, 2}, {1, 0, 2}, {1, 2, 0},
{2, 1, 0}, {2, 0, 1}, {0, 2, 1}};
int n, x;
cin >> n >> x;
int t = n % 6;
printf("%d\n", num[t][x]);
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const int _max = 1e9;
int a[maxn], b[maxn];
int dp[maxn];
vector<int> pos[maxn];
int main() {
int n, m, s, e;
scanf("%d%d%d%d", &n, &m, &s, &e);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
for (int i = 1; i <= m; i++) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <int MOD_> struct modnum {
static constexpr int MOD = MOD_;
static_assert(MOD_ > 0, "MOD must be positive");
private:
using ll = long long;
int v;
static int minv(int a, int m) {
a %= m;
assert(a);
return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) /... | 0 |
#include <bits/stdc++.h>
using namespace std;
int solve() {
long long n;
cin >> n;
vector<int> a(n);
for (int(i) = 0; (i) < n; (i)++) {
cin >> a[i];
}
if (a[n - 1] == 15)
cout << "DOWN";
else if (a[n - 1] == 0)
cout << "UP";
else if (n == 1)
cout << -1;
else if (a[n - 2] > a[n - 1])
... | 1 |
#include<iostream>
int main()
{
int a,b,c,d;
std::cin>>a>>b>>c>>d;
if(a*b>c*d)std::cout<<a*b;
else std::cout<<c*d;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
long long mul(long long a, long long b) {
long long res = ((a % 1000000007) * (b % 1000000007)) % 1000000007;
return res;
}
long long power(long long a, long long b) {
if (!b) return 1ll;
long long res = power(a, b / 2);
res = mul(res, res);
if (b & 1) res = mul... | 3 |
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#include <array>
#include <climit... | 0 |
#include <bits/stdc++.h>
using namespace std;
int K, N1, N2, N3, T1, T2, T3;
short U1[30000100], U2[30000100], U3[30000100];
int main() {
scanf("%d%d%d%d%d%d%d", &K, &N1, &N2, &N3, &T1, &T2, &T3);
int ans = 0;
int ctim = 0;
for (int i = 0; i < K; ++i) {
for (;;) {
if (U1[ctim] < N1 && U2[ctim + T1] < ... | 4 |
#include <bits/stdc++.h>
using namespace std;
bool used[100005];
long long n, a[100006], t[500000];
vector<long long> pos[100006];
void build(int v, int vl, int vr) {
if (vl == vr) {
t[v] = used[vl];
return;
}
int vm = (vl + vr) / 2;
build(2 * v, vl, vm);
build(2 * v + 1, vm + 1, vr);
t[v] = t[2 * v... | 2 |
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef pair<int,int> pii;
int main(){
int n;
cin >> n;
vector<int> cnt(n+10, 0);
int ones = 0, border = 0;
rep(i,n){
int x;
cin >> x;
if(x >= n+10){
ones... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, id[100005];
long long cnt, sum;
int main() {
cin >> n >> cnt;
for (int i = 1; i <= n; ++i) cin >> id[i];
for (int i = 1; i <= n; ++i) {
if (cnt - i > 0)
cnt -= i;
else {
cout << id[cnt] << '\n';
return 0;
}
}
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int t, n, m, b[N], a[N];
int main() {
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
for (int i = 1; i <= n; i++) b[i] = 0;
int mmo = -1, mp = -1;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
mmo = max(mmo, a[i]);... | 4 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, neg = 1;
char c = getchar();
while (!isdigit(c)) {
if (c == '-') neg = -1;
c = getchar();
}
while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
return x * neg;
}
inline void print(int x) {
if (x < 0) {
putchar('-'... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
while (k--) cout << n-- << " ";
for (int i = 1; i <= n; i++) cout << i << " ";
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int A[n];
bool S[n];
for (int i = 0; i < n; ++i) {
cin >> A[i];
S[i] = true;
}
int t = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (S[i] == true && S[j] == true && i != j && (A[i] + A[j]) ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1000007;
long long n, a[maxn], s[maxn];
long long get_ans(long long u) {
long long ans = 0;
for (long long i = 1; i <= n; ++i) {
ans += min(s[i] % u, u - s[i] % u);
}
return ans;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0), ... | 5 |
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
char are(char c, int i){
int tmp = ((int)(c -'0' + i))%10;
if(tmp>=0) return (char)(tmp + '0');
return (char)((tmp+10) + '0');
}
int kore(string start, string goal,int sum){
if(start.empty()) return sum;
int move = (int)... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1003;
int prime[MAXN];
int initPrime(int max) {
bool isPrime[MAXN] = {false};
int p = 0;
for (int i = 2; i <= max; i++) {
if (!isPrime[i]) {
prime[p] = i;
p++;
for (int j = i + i; j <= max; j += i) {
isPrime[j] = true;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, mod = 1e9 + 7;
int l, r, num, fen[N], wh[N], a[N], Add[N];
long long tot, fen2[N];
void add(int x, int val) {
for (; x < N; x += x & -x) {
if (val > 0) {
fen[x]++;
} else {
fen[x]--;
}
fen2[x] += val;
}
}
pair<int, lon... | 3 |
#include<cstdio>
int main(){
char a[64];
while(scanf("%s",&a[0])>0){
for(int i=1;i<8;i++)
scanf("%s",&a[8*i]);
for(int i=0;i<64;i++){
if(a[i]=='1'){
if(a[i+1]=='1'){
if(a[i+2]=='1'){
puts("C");
}else if(a[i+7]=='1'){
puts("G");
}else if(a[i+8]=='1'){
puts("A");
}else... | 0 |
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
long long n;
int dfs(long long d,bool a,bool b,bool c){
if(d>n) return 0;
int res=(a&&b&&c?1:0);
res+=dfs(10*d+3,true,b,c);
res+=dfs(10*d+5,a,true,c);
res+=dfs(10*d+7,a,b,true);
return res;
}
int main(){
scanf("%lld",&n);
... | 0 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using db = double;
using vi = vector<int>;
#define fir first
#define sec second
#define pb push_back
#define lowbit(x) ((x)&(-(x)))
struct data {
int a, b, c;
}p[200000];
int x, y, z;
ll l[200000], r[200000];
boo... | 0 |
#include<iostream>
#include<string>
#include<math.h>
using namespace std;
int a[10][10000];
int main(){
int r,c;
while(true){
cin>>r>>c;
if(r==0&&c==0)
break;
for(int i=0;i<r;i++){
for(int j=0;j<c;j++){
cin>>a[i][j];
}
}
double rrr=r;
int best=0;
for(int i=0;i<pow(2,rrr);i++){
int count=0;
fo... | 0 |
#include <bits/stdc++.h>
int N;
char s[507][507];
int rX[] = {-1, 0, 1, 0};
int rY[] = {0, -1, 0, 1};
int spoj[507][507];
int rozm[1000007];
int akt[1000007];
int terRozm;
int wyn;
void dfs(int y, int x, int num) {
spoj[y][x] = num;
terRozm++;
for (int i = 0; i < 4; i++) {
int nx = x + rX[i], ny = y + rY[i];
... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T BM(T p, T e, T M) {
long long int ret = 1;
for (; e > 0; e >>= 1) {
if (e & 1) ret = (ret * p) % M;
p = (p * p) % M;
}
return (T)ret;
}
template <class T>
inline T gcd(T a, T b) {
if (b == 0) return a;
return gcd(b, a % b);
}
... | 2 |
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
int main() {
int N, X[200000];
cin >> N;
vector< int > vs;
for(int i = 0; i < N; i++) {
cin >> X[i];
vs.emplace_back(X[i]);
}
sort(begin(vs), end(vs));
int mex1 = vs[(N - 1) / 2];
int mex2 = vs[(N + 1) / 2];
for(int i =... | 0 |
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int collatz(int n){
if(n==1) return 0;
if(n&1) return 1+collatz(3*n+1);
else return 1+collatz(n/2);
}
int32_t main(){
int n;cin>>n;if(n<=2)cout<<4;else cout<<collatz(n)+2;
}
| 0 |
#include<bits/stdc++.h>
using namespace std;
const int N=3e5+11;
int k,n,ans[N],len;
int main(){
// freopen("ex.in","r",stdin);
scanf("%d%d",&k,&n);
if(k%2==0){
printf("%d",k/2);
for(int i=1;i<n;++i) printf(" %d",k);
return 0;
}
for(int i=1;i<=n;++i) ans[i]=(k+1)/2;
int T=n/2;
len=n;
while(T--){
if(ans[l... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
long long A[100001] = {0};
for (long long i = 0; i < n; i++) {
cin >> A[i];
if (A[i] >= 0) A[i] = -A[i] - 1;
}
if (n % 2 == 1) {
int min = 0;
while (A[min] == -1 && min < n) min++;
if (min == n) {
A[0... | 2 |
#include <bits/stdc++.h>
using namespace std;
int fv[10010];
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
string s;
cin >> s;
int ans = 0;
int dif = 0;
for (auto &x : s) {
fv[x]++;
if (fv[x] == 1) {
dif++;
}
if (fv[x] > 1) {
an... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000;
int num;
int minp[MAXN + 1], p[MAXN + 1];
int prime(int n = MAXN) {
num = 0;
memset(minp, 0, sizeof(minp));
for (int i = 2; i <= n; ++i) {
if (!minp[i]) p[num++] = i, minp[i] = i;
;
for (int j = 0; j < num && i * p[j] <= n; ++j) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
string second;
cin >> second;
long long n = ((long long)second.size());
vector<long long> F(n, 0), B(n, 0);
for (long long i = 1; i < n; i++) {
F[i] = F[i - 1] + (second[i - 1] == '0');
}
for (long long i = n - 2; i >= 0; i--) {
B[i] = B... | 2 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> tab[1100005];
vector<pair<int, int>> pol[1100005];
bool odw[1100005];
vector<pair<pair<int, int>, int>> out;
vector<pair<pair<int, int>, int>> w;
void dfs(int a) {
while (!pol[a].empty()) {
if (odw[pol[a].back().second])
pol[a].pop_back();
els... | 6 |
#include<bits/stdc++.h>
#define N 2005
using namespace std;
int n,m;
char s[N][N];
int same[N][N];
int sta[N],top;
int main(){
scanf("%d%d",&n,&m);
int ans=max(n,m);
for(int i=1;i<=n;i++){
scanf("%s",s[i]+1);
top=0;sta[0]=1;
for(int j=2;j<=m+1;j++){
same[i][j]=(s[i-1][j]^... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, w, h, f[2050];
long long fjc[200050], fjcinv[200050];
pair<int, int> a[2050];
inline int read() {
char c = getchar();
int f = 1;
while (c > '9' || c < '0') {
if (c == '-') f = -1;
c = getchar();
}
int num = 0;
while (c >= '0' && c <= '9') {
nu... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 100000;
const int MOD =1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++){
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m, par[5005];
vector<int> sz[5005];
string s[5005];
int f(int i) {
if (par[i] != i) par[i] = f(par[i]);
return par[i];
}
void merge(int a, int b) {
a = f(a), b = f(b);
if (a == b) return;
if (sz[a].size() < sz[b].size()) {
par[a] = b;
for (__typeof(... | 4 |
#include<bits/stdc++.h>
using namespace std;
const int MAX_N = 1<<17;
int n,dat[2*MAX_N-1];
void init(int n_){
n=1;
while(n<n_)n*=2;
for(int i=0;i<2*n-1;i++)dat[i]=INT_MAX;
}
void update(int k,int a){
k+=n-1;
dat[k]=a;
while(k>0){
k=(k-1)/2;
dat[k]=min(dat[k*2+1],dat[k*2+2]);
}
}
int query(int... | 0 |
#include <bits/stdc++.h>
using namespace std;
int a[105][105];
struct second {
int x, y, z, i, j, k;
void pr() {
cout << x + 1 << " " << y + 1 << " " << z + 1 << " " << i + 1 << " "
<< j + 1 << " " << k + 1 << "\n";
}
};
void tc() {
int n, m;
cin >> n >> m;
for (int i = 0; i < int(n); i++) {
... | 1 |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
void solve () {
int n;
cin >> n;
vector<ll> arr (n);
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
sort(arr.begin(), arr.end());
ll prevsum = 0;
ll ans = 0;
for (int i = 0; i < n; i++) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int atas0[1010], atas1[1010], kiri0[1010], kiri1[1010];
long long ans;
int main() {
int i, j, x;
scanf("%d%d", &n, &m);
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
scanf("%d", &x);
if (x) {
ans += kiri0[i];
kiri0[i] = ... | 2 |
#include <bits/stdc++.h>
using namespace std;
class C_ {};
template <typename T>
C_& operator<<(C_& __m, const T& __s) {
if (!1) cerr << "\E[91m" << __s << "\E[0m";
return __m;
}
C_ merr;
struct __s {
__s() {
if (1) {
ios_base::Init i;
cin.sync_with_stdio(0);
cin.tie(0);
}
}
~__s() {... | 5 |
#include <bits/stdc++.h>
using namespace std;
int a[10001], n, i, j, c;
int main() {
cin >> n;
for (i = 2; i <= n; i++) {
if (a[i] == 0)
for (j = i; j <= n; j += i) a[j]++;
if (a[i] == 2) c++;
}
cout << c;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
char a[55][55];
struct Tpoint {
int x, y;
} p[55][55][4][2];
const int dir[4][2] = {{-1, 0}, {0, +1}, {+1, 0}, {0, -1}};
int main() {
int ss, n, m;
scanf("%d%d", &n, &ss);
for (int i = 0; i < n; i++) scanf("%s", a[i]);
m = strlen(a[0]);
for (int i = 0; i < n; i+... | 2 |
#include <bits/stdc++.h>
using namespace std;
vector<long long int> D(1000000);
vector<pair<long long int, long long int> > G[1000000];
set<long long int> A;
long long int findmin(long long int x) {
long long int temp = -1;
for (unsigned long long int i = 0; i < G[x].size(); i++) {
if (A.find(G[x][i].second) ==... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
if (n <= 5) {
cout << "-1\n";
} else {
for (int i = 2; i <= 4; ++i) {
cout << "1 " << i << '\n';
}
for (int i = 5; i <= n; ++i) {
cout << "2 " << i << '\n';
}
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 300010;
const int INF = 2000000010;
int n, m, k;
int mi[maxn], ma[maxn], a[maxn], sum[maxn], v[maxn], la[maxn];
vector<pair<int, int>> G;
void add(int x, int cnt) {
for (int i = x; i <= max(n, m); i += (i & -i)) {
sum[i] += cnt;
}
}
int get_sum(int ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int nmax = 100005;
ifstream in("snacks.in");
ofstream out("snacks.out");
queue<int> q[nmax];
int snacks[nmax], sad = 0, n, k;
pair<int, int> g_prefs[nmax];
int guests[nmax];
void input() {
int i;
cin >> n >> k;
for (i = 1; i <= k; i++) {
cin >> g_prefs[i].fi... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long fx[4] = {1, -1, 0, 0};
long long fy[4] = {0, 0, 1, -1};
int smallest(int x, int y, int z) {
int c = 0;
while (x && y && z) {
x--;
y--;
z--;
c++;
}
return c;
}
bool rs(long long a, long long b) { return (a > b); }
int main() {
long long n;... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int ans = n;
while (n > 1) {
int fac;
int flag = 0;
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
fac = i;
flag = 1;
break;
}
}
if (flag == 0) fac = n;
ans = ans + (n / ... | 2 |
#include <iostream>
using namespace std;
int main(){
int A, B, C;
cin >> A >> B;
C = A + B;
cout << (C % 24) << endl;
} | 0 |
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
const int maxn = 1e6;
const int maxN = 1e5 + 5;
const long long mod = 998244353;
using namespace std;
int n, m;
vector<int> adj[maxn];
bool vs[maxn];
int par[maxn];
pair<int, int> dfs(int u, int p... | 6 |
#include <bits/stdc++.h>
using namespace std;
int a, b, c, d, mi, va;
int main() {
cin >> a >> b >> c >> d;
mi = max(3 * a / 10, a - a / 250 * c);
va = max(3 * b / 10, b - b / 250 * d);
if (mi > va) {
cout << "Misha";
} else if (va > mi) {
cout << "Vasya";
} else {
cout << "Tie";
}
return 0;... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, l, c, d, p, nl, np, a1, a2, a3, minele;
cin >> n >> k >> l >> c >> d >> p >> nl >> np;
a1 = (k * l) / nl;
a2 = c * d;
a3 = p / np;
minele = min(a1, a2);
minele = min(minele, a3);
cout << minele / n << endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int i, j, k, l;
int main() {
char s[2222];
cin >> n >> s;
sort(s, s + n);
sort(s + n, s + n + n);
bool b1, b2;
b1 = b2 = true;
for (i = 0; i < n; ++i) {
b1 &= (s[i] > s[i + n]);
b2 &= (s[i] < s[i + n]);
}
cout << ((b1 | b2) ? "YES" : "NO"... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 110;
int n, m;
int a[MAX] = {0};
void clear() {}
bool cmp(const int &a, const int &b) { return a > b; }
void solve() {
scanf("%d", &m);
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
sort(a, a + n, cmp);
int r = 0;
while (m > 0) {
m -= a[r++];... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long binexp(long long a, long long b, long long m) {
a %= m;
long long ans = 1;
while (b) {
if (b & 1) ans = (ans * a) % m;
a = (a * a) % m;
b >>= 1;
}
ret... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long t, n, i, j, k, x, y, z, l, r, mid, ans, mod = 1e9 + 7, g, m;
long long a[400005], b[400005], c[400005];
char ch;
string s, st;
vector<long long> v[300004], u;
int main() {
ios::sync_with_stdio(NULL);
cin.tie(0);
cout.tie(0);
cin >> t;
while (t--) {
c... | 1 |
#include <cstdio>
#include <cmath>
int main(){
int a=100000,n;
scanf("%d",&n);
while(n--){
int b=a/20;
a+=b-b%1000;
if(b%1000!=0)
a+=1000;
}
printf("%d\n",a);
} | 0 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int rt, K, n, cnt, typ;
vector<int> linker[2005];
void dfs(int x, int fa, int ndep)
{
if (ndep > ((K - typ) >> 1)) ++ cnt;
for (int cur : linker[x])
if (cur != fa) dfs(cur, x, ndep + 1);
}
int main()
{
scanf("%d %d", &n, &K);
for (int i = 1; i ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int n;
int a, b, c, d;
int main() {
while (~scanf("%d", &n)) {
int ok = -1;
int ans1, ans2;
for (int i = 0; i < 4; ++i) {
scanf("%d%d%d%d", &a, &b, &c, &d);
if (ok == -1) {
if (a + c <= n || a + d <= n || b + c <= ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, k, s;
cin >> n >> m >> k >> s;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i], --a[i];
vector<vector<int>> dp(n, vector<int>(k, 100000000));
vector<vector<int>> adj(n);
for (int i = 0; i < m; i++) {
int u, v;
cin >> u ... | 1 |
#include <bits/stdc++.h>
using namespace std;
using PII = pair<int, int>;
using PLL = pair<long long, long long>;
using VLL = vector<long long>;
using VI = vector<int>;
inline void fastio() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return ((a * b) / gcd(a, b)); }
long long int read_int() {
char r;
bool start = false, neg = false;
long long int ret = 0;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000 + 7;
const int M = 100000 + 2;
const int inf = 1e9 + 7;
const long long linf = 1ll * inf * inf + 7;
const double pi = acos(-1);
const double eps = 1e-8;
const bool multipleTest = 0;
int n;
int a[N];
int dp[N][126][270];
int pre[N][10];
int last[10];
void ... | 5 |
/* template.cpp {{{ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n)... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
long long len, d;
cin >> len >> d;
string s;
cin >> s;
long long j = 1;
long long count = 0;
long long i = 0;
long long point = -1;
while (1) {
if (i < d && j < len) {
if (s[j] == '1') point =... | 1 |
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#define MOD 1000000007
using namespace std;
int n, m, k;
int quickPow(int n, int m) {
int res = 1;
while (m) {
if (m & 1) res = 1LL * res * n % MOD;
m >>= 1;
n = 1LL * n * n % MOD;
}
return res;
}
int main() {
scanf("%d%d%d", &n... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 0x3f3f3f3f;
int n, k, a[35001], dp[35001][55];
int tree[55][176000], ever[55][176000];
int put(int k, int a, int b, int l, int r, int id, int val) {
if (r <= a || l >= b) {
return tree[id][k] + ever[id][k];
}
if (r <= b && l >= a) {
ever[id][k]... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const int MSIZE = 3e5;
const long long base = 7;
const double EPS = 1e-9;
vector<long long> fac;
vector<long long> ifac;
long long gcd(long long a, long long b, long long& x, long long& y) {
if (a == 0) {
x = 0;
y = 1;
return b;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long ar[100006];
long long cnt[100004];
int main() {
long long n;
cin >> n;
long long m = 1;
if (n % 2 == 0) m = 2;
long long mid = (n + 1) / 2;
long long k = 1;
long long mx = -1;
for (long long i = 1; i <= n; i++) {
cin >> ar[i];
long long df ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MN = 155;
int n, k;
int s;
int a[MN];
int dp[MN][MN * MN];
int main() {
for (int i = 0; i < MN; i++) {
for (int j = 0; j < MN * MN; j++) {
dp[i][j] = 1e9;
}
}
cin >> n >> k >> s;
s += (k - 1) * k / 2;
for (int i = 0; i < n; i++) {
cin >... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 50005;
const int inf = 1000000000;
const int B = 8;
int n, bin[10], cnt, last[N], anc[N], fa[N], ans[N][256], dp[256][10], dep[N],
a[N], q;
struct edge {
int to, next;
} e[N * 2];
int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' ... | 5 |
#include<bits/stdc++.h>
using namespace std;
static const int64_t mod=1000000007;
int64_t f(int64_t x,int64_t y){
if(y==0)
return 1;
else if(y%2==0)
return (f(x,y/2)*f(x,y/2))%mod;
else
return (f(x,y/2)*((x*f(x,y/2))%mod))%mod;
}
int64_t comb(int64_t x,int64_t y){
int64_t ans=1;
for(int64_t i=y;1<=i;i--... | 0 |
#include<bits/stdc++.h>
#define LL long long
#define maxn 100005
using namespace std;
int a[maxn];
void solve(int n)
{
int mx=0,mn=n;
for(int i=1;i<=n;i++)
{
mx=max(mx,a[i]);
mn=min(mn,a[i]);
}
if(mx-mn>=2)
{
puts("No");
return ;
}
if(mx==mn)
{
if(mx==n-1) puts("Yes");
else if(mx*2<=n) puts("Yes");... | 0 |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef vector<int> vi;
#define PB push_back
#define rep(i,x) for(int i=0;i<(x);++i)
#define rep1(i,x) for(int i=1;i<=(x);++i)
#define all(a) a.begin(),a.end()
int P[1001];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int ... | 0 |
#include <bits/stdc++.h>
using namespace std;
void _print(long long t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(char t) { cerr << t; }
void _print(long double t) { cerr << t; }
void _print(double t) { cerr << t; }
void _print(unsigned long long t) { cerr << t; }
template <class T, class V>
void _... | 1 |
#include <iostream>
using namespace std;
int main() {
int d,i,s;
while (cin >> d) {
s=0;
for (i=d;i<600;i+=d) s+=d*i*i;
cout << s << endl;
}
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000 * 1000 * 1000;
const long long LINF = 1LL * INF * INF;
const int MAX = 100010;
const long double PI = acos(-1.);
const double EPS = 1e-6;
long long mod = 1000LL * 1000 * 1000 + 7;
int n, v;
int cnt[104];
int a[300005];
int pr[300005];
int main() {
ios... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int v[1505][1505];
long long mem[1505][1505];
const long long OO = 1LL * 1500 * 1500 * 20000 + 5;
int main() {
scanf("%d %d", &n, &m);
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) scanf("%d", &v[i][j]);
for (int i = 0; i < n; i++)
for (int... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
const long long mod = 998244353, invg = 332748118;
long long fp[N], fac[N], inv[N];
inline long long power(long long a, long long b) {
long long res = 1;
for (; b; b >>= 1, a = a * a % mod)
if (b & 1) res = res * a % mod;
return res;
}
inli... | 3 |
#include <bits/stdc++.h>
using namespace std;
vector<int> a;
int main() {
int n, x, m;
cin >> n >> m;
while (n--) {
cin >> x;
a.push_back(x);
}
sort(a.begin(), a.end());
while (m--) {
cin >> x;
cout << upper_bound(a.begin(), a.end(), x) - a.begin() << endl;
}
}
| 2 |
#include <bits/stdc++.h>
long long s[100001];
long long b[100001];
long long a[200000];
int p(long long n, long long k) {
if (k == 0) return 1;
long long h = p(n, k >> 1);
if (k & 1)
return (((h * h) % 1000000007) * n) % 1000000007;
else
return (h * h) % 1000000007;
}
int main() {
long long n, i, r = ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, a;
long long x, y;
while (cin >> n >> m >> a) {
if (n / a == n / (double)a)
x = n / a;
else
x = (int)(n / (double)a) + 1;
if (m / a == m / (double)a)
y = m / a;
else
y = (int)(m / (double)a) + 1;
cout ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, inf = 1e9 + 7, mod = 1e9 + 7;
const long double eps = 1e-12;
const long long linf = (long long)1e18 + 7;
long long n, m, x, y, a[N], b[N], cnt;
vector<long long> g[N];
map<int, bool> q;
bool ok = 0;
int main() {
cin >> n >> m;
for (int i = 1; i <=... | 4 |
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
typedef long long ll;
#define MAX(x, y) (((x) > (y))? (x) : (y))
#define MIN(x, y) (((x) < (y))? (x) : (y))
#define ABS(x) (((x) < 0)? (-1*(x)) : (x))
#define REPI(x,y) for (int i=(x);i<(y);i++)
#define REPJ(x,y) for (int j=(x);j<(y);j++)
... | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.