solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <cstdio>
long long gcd(long long a,long long b)
{
return b?gcd(b,a%b):a;
}
int main()
{
long long n,x;
scanf("%lld%lld",&n,&x);
long long d=gcd(n,x);
printf("%lld\n",(n-d)*3);
return 0;
}
| 0 |
#include <cmath>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
const long long lim = 40000000;
const long long inf = 0x3f3f3f3f3f3f3f3f;
signed main(void)
{
int n, m, s; cin >> n >> m >> s;
vector<pair<pair<int, int>, int > > edge;
for (int... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXK = 5000;
const int PRIMESIZE = 669;
int n;
vector<int> prime;
map<int, int> primeIndex;
int number[MAXK + 1];
bool isPrime[MAXK + 1];
vector<int> factor[MAXK + 1];
vector<int> power[MAXK + 1];
long long int dist[MAXK + 1];
int fPower[MAXK + 1][PRIMESIZE];
int ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int tt, cnt, tim, tp;
bool w[N];
vector<int> q[N];
int u[N], head[N], to[N], nxt[N], dfn[N], low[N], v[N], c[N];
inline int gi() {
int x = 0, o = 1;
char ch = getchar();
while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
if (ch == '-')... | 5 |
#include <iostream>
#include <string>
#include <string_view>
#include <vector>
using namespace std;
int ModAtoi(string_view sv, int d) {
int r = 0;
for (char c : sv) {
r *= 2;
r %= d;
r += c - '0';
}
return r;
}
inline int popcount(int x) { return __builtin_popcount(x); }
int f(int x) { return x... | 0 |
/*
* D.cpp
*
* Created on: 2012-8-25
* Author: Administrator
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
int n, m;
int h, w;
struct page {
string name;
int bn;
int pt[105];
int x1[105];
int x2[105];
int y1[105];
int y... | 0 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;cin>>n;
string s,t;
cin>>s;cin>>t;
for(int i=0;i<n;i++)
cout<<s[i]<<t[i];
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n, ans[1010], cnt;
int main() {
scanf("%d", &n);
for (int i = 2; i <= n; i++) {
bool flag = 0;
for (int j = 2; j * j <= i; j++) {
if (i % j == 0) {
flag = 1;
break;
}
}
if (flag) continue;
for (int j = i; j <= n; j *= ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<string> a;
long long get(string s) {
long long pts = 0;
int nh = 0;
for (int i = ((int)(s).size()) - 1; i >= 0; i--) {
if (s[i] == 'h') {
nh++;
} else {
pts += nh;
}
}
return pts;
}
struct cmp {
inline bool operator()(const ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000;
int n, m, g[maxn + 1][maxn + 1];
int number[maxn + 1], low[maxn + 1], parent[maxn + 1];
int dem;
void del(int x, int y) {
int i;
for (i = 1; i <= g[x][0]; i++)
if (g[x][i] == y) break;
if (g[x][i] == y) {
for (int j = i; j <= g[x][0]; j+... | 3 |
#include <iostream>
using namespace std;
void solve()
{
int a, b;
while(cin >> a >> b)
{
if(!a && !b)
{
break;
}
int back = b - a;
int count1000 = back / 1000;
back %= 1000;
int count500 = back / 500;
back %= 500;
int count100 = back / 100;
cout << count100 << " " << count500 << " " << count... | 0 |
#include <bits/stdc++.h>
using namespace std;
double dp[2005][2005], cnt[2005][2005];
double p[2005], u[2005];
int main() {
int n, a, b;
cin >> n >> a >> b;
;
for (int i = 0; i < n; i++) cin >> *(p + 1 + i);
;
for (int i = 0; i < n; i++) cin >> *(u + 1 + i);
;
double lo = -4000.0, hi = 0.0;
int t = 10... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int n, rt, d, dep[N], ans, p1, p2, c[N], len, maxd;
int head[N], numE = 0;
vector<int> g[N];
char s[10];
struct E {
int next, v;
} e[N << 1];
void inline add(int u, int v) {
e[++numE] = (E){head[u], v};
head[u] = numE;
}
void dfs(int u, int last) {... | 6 |
#include <cstdio>
#include <algorithm>
#include <utility>
#include <queue>
using namespace std;
typedef long long int ll;
int N,M;
const int DATA_SIZE=100000;
const ll BIGNUM = 2000000000;
// 値段*美味しさ
pair<ll, ll> sweets[DATA_SIZE];
// 値段*個数
pair<ll,ll> friends[DATA_SIZE+1];
struct Sweet_ptr_comp{
// 美味しさを下降順... | 0 |
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
using namespace std;
const int maxn = 2e5+15;
int n,Q,a,b,c,d,cnt,head[maxn],ans[maxn];
struct edge{
int to,nxt,col,len;
}e[maxn<<1];
struct query{
int l,r,x,y,id;
}q[maxn<<1];
pii p[maxn];
inline void add(int u,int v,int c,i... | 0 |
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#de... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
long long n, c[N], ans[N], pw[64];
queue<long long> q[64];
int main() {
cin >> n;
pw[0] = 1;
for (int i = 1; i <= 60; i++) pw[i] = pw[i - 1] << 1;
for (int i = 1; i <= n; i++) {
cin >> c[i];
for (int j = 60; j >= 0; j--)
if (c[i] ... | 3 |
#include <bits/stdc++.h>
#define range(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define rep(i,n) range(i,0,n)
using namespace std;
int main(void){
int ans=0;
while(1){
string s;
cin >> s;
if(cin.eof()) break;
int n=s.size();
int cur=0;
rep(i,n){
if(isdigit(s[i])){
cur=cur*10+(s[i]-'0');
}else{
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int tailleEnsemble[100 * 1000 + 3];
int dernierVu[100 * 1000 + 3], numero = 1;
int pere[100 * 1000 + 3];
map<long long, int> dictionnaire;
bool couleur[100 * 1000 + 3];
vector<int> frere[100 * 1000 + 3];
int trouverPere(int p) {
if (pere[p] == p) return p;
return pere[p... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long int add(long long int x, long long int y) {
x += y;
while (x >= 1000000007) x -= 1000000007;
while (x < 0) x += 1000000007;
return x;
}
long long int mul(long long int x, long long int y) {
return (x * 1ll * y) % 1000000007;
}
long long int binpow(long l... | 3 |
#include <bits/stdc++.h>
using namespace std;
int isperfect(long long int n) {
if (sqrt(n) == floor(sqrt(n)))
return 1;
else
return 0;
}
int A[100001];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
int arr[n];
int max1 = INT_MIN;
for (int i = 0; i < n; ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int N, M, a, b;
long long d[100010], pos[100010], H[100010], sum;
pair<long long, long long> tree[4 * 100010];
inline int Sx(int p) { return p << 1; }
inline int Dx(int p) { return (p << 1) + 1; }
inline long long Orario(int p) { return pos[p]; }
inline long long AntiOrario... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int menor[n];
for (int i = 0; i < n; i++) menor[i] = INT_MAX;
int e = 1;
while (e < n) e *= 2;
while (e > 1) {
e /= 2;
int a = 0, b = 0;
for (int i = 0; i < n; i++)
if (i & e)
a++;
else
b++;... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long INF = 10000000000000;
int main(){
int N;
cin >> N;
vector<int> a(N);
for (int i = 0; i < N; i++){
cin >> a[i];
}
int V = N + 2;
vector<map<int, long long>> E(V);
long long ans = 0;
for (int i = 0; i < N; i++){
if (a[i] > 0){
ans += ... | 0 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,c;
cin>>a>>b>>c;
cout<<max(abs(a-b),max(abs(c-a),b-c))<<endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
const int MOD = 1e9 + 7;
const int MAXN = 1e9 + 1;
const double PI = 3.14159265359;
using namespace std;
int a[100001], q[100001];
int main() {
ios_base::sync_with_stdio(0);
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
q[a[i]] = i;
}
int z = 0, mx = 0;
for ... | 1 |
#include <bits/stdc++.h>
#pragma optimise("O3")
using namespace std;
mt19937 rnumber((long long)new char);
typedef struct Treap* Arbore;
Arbore NIL;
struct Treap {
int move_st, move_dr;
int poz, poz_min, poz_max, w, g;
int prio;
long long suma;
Arbore st, dr;
Treap(int g, int poz)
: move_st(0),
... | 3 |
#include <bits/stdc++.h>
int main() {
std::istream& is = std::cin;
std::ostream& os = std::cout;
std::string s, t, u;
std::getline(is, s);
std::getline(is, t);
std::sort(s.begin(), s.end());
std::sort(t.begin(), t.end());
int n = s.length();
u.resize(n);
int sl = 0, sr = n / 2 + n % 2 - 1, tl = n / ... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long n, i, j, x, y, t, ans = 0;
vector<long long> b1(200001, 2002), b2(200001, 2002);
int main() {
scanf("%I64d", &n);
for (i = 0; i < n; ++i) {
scanf("%I64d%I64d", &x, &y);
b1[i] = -x - y;
b2[i] = x - y;
}
sort(b1.begin(), b1.end());
sort(b2.begi... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
while (1) {
int N, M;
cin >> N >> M;
if (!N & !M) break;
unordered_map<int, int> DV;
for (int i = 1; i <= M; i++) {
DV[i] = 0;
}
for (int ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2000000000;
const double pi = acos(-1.0);
int primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53};
int a[105], dp[105][1 << 17], n, bit[105], path[105][1 << 17];
int solve(int pos, int mask) {
if (pos >= n) return 0;
int& ret = dp[pos... | 4 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int E,Y;
cin>>E>>Y;
if(E==0){
if(Y>=1989&&Y<=2016)cout<<"H"<<Y-1988<<endl;
if(Y>=1926&&Y<=1988)cout<<"S"<<Y-1925<<endl;
if(Y>=1912&&Y<=1925)cout<<"T"<<Y-1911<<endl;
if(Y>=1868&&Y<=1911)cout<<"M"<<Y-1867<<endl;
}
else{
if(E==1)cout<<Y+1867<<endl;
if(E==2)c... | 0 |
#include <iostream>
#include <complex>
#include <cmath>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
const double EPS = 1e-12;
double cross(const xy_t &a, const xy_t &b){
return imag(conj(a) * b);
}
double dot(const xy_t &a, const xy... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct kraw {
int m, M, a, p;
};
vector<vector<int> > st;
int n;
int A = -1, B = -1;
void gen(vector<int>& a, int x, int nr, int max_dl, vector<int>& ogr) {
a[nr] = x;
if (nr == max_dl - 1) {
st.push_back(a);
return;
}
if (nr == max_dl - 2)
gen(a, -1, ... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline void chkmin(T1 &x, T2 y) {
if (x > y) x = y;
}
template <typename T1, typename T2>
inline void chkmax(T1 &x, T2 y) {
if (x < y) x = y;
}
using ll = long long;
using ld = long double;
const string FILENAME = "input";
int main() ... | 5 |
//ITP1_5_D
#include<iostream>
using namespace std;
int main()
{
int i,x,n;
cin>>n;
for(i=1;i<=n;i++){
if(0==i%3)
cout<<" "<<i;
else for(x=i;x!=0;x/=10)
{
if(3==x%10){
cout<<" "<<i;
break;
}
}
}
cout<<endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
bitset<2000005> bs;
vector<int> p;
void build() {
bs[0] = bs[1] = 1;
for (int i = 2; i < 2000005; i++) {
if (!bs[i]) p.push_back(i);
for (int j = 0; i * p[j] < 2000005; j++) {
bs[i * p[j]] = 1;
if (i % p[j] == 0) break;
}
}
}
int in[1005];
bits... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1010;
const int inf = 4 * MAXN * MAXN;
int n, m;
int xp, yp, xk, yk;
char A[MAXN][MAXN];
int graf[inf][5];
int size[inf];
char delta[inf][4];
char temp[4];
void load() {
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) scanf("%s", A[i]);
scanf("%d%d... | 4 |
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef long long ll;
typedef pair<int, int> pii;
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define itn int
ll powmod(ll a,ll b) {ll res=1; assert(b>=0); for(;b;b>>=1){if(b&1)r... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k, c = 1;
cin >> n >> k;
while (true) {
while (k - 3 >= 0 && (n - c) * 2 <= k - 3 && c <= n && c++) k -= 3;
while (k - 4 >= 0 && (n - c) * 2 <= k - 4 && c <= n && c++) k -= 4;
while (k - 5 >= 0 && (n - c) * 2 <= k - 5 && c <= n &&... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
const int inf = ~0U >> 1;
const int mod = 1e9 + 7;
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};
int n, m, mat[N][N];
long long k;
bool ans[N][N];
inline int idx(int x, int y) { return x * m + y; }
inline bool inRange(int x, int y) { ... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void show(const vector<T> &a) {
for (T x : a) cout << x << " ";
cout << '\n';
}
const long long N = 3e5 + 50, oo = 1e18 + 100, mod = 1e9 + 7;
const long double eps = 1e-9, PI = 2 * acos(0.0);
vector<long long> g[N];
vector<long long> visit(N, 0);
long... | 1 |
#include <bits/stdc++.h>
using namespace std;
std::vector<int> adj[100107];
bool mat[150][150];
std::vector<pair<int, int> > edge;
bool vis[100107];
int dist[100107], par[100107];
int n;
int ans = 1e9;
void bfs(int x, int y) {
for (int i = 0; i < n; i++) vis[i] = 0, dist[i] = 1e9, par[i] = -1;
dist[x] = 0;
queue<... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int max_n = 3e5 + 5;
int n;
int ans[max_n];
vector<int> v;
int rob(int pos) {
if (pos + 1 < 0 || pos + 1 >= n) return -1e9;
if (pos + 2 >= n) return v[pos + 1];
return min(max(v[pos], v[pos + 2]), v[pos + 1]);
}
int main() {
scanf("%d", &(n));
;
for (int i... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 * 1000 + 10;
int n, m, a[maxn], al[maxn], ar[maxn], tind[3 * maxn];
vector<int> tc[3 * maxn];
unordered_set<int> s;
int *ind = tind + maxn;
vector<int> *c = tc + maxn;
long long ans;
int main() {
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin ... | 5 |
#include <bits/stdc++.h>
using namespace std;
struct block {
int x, y;
inline bool operator<(const block &cpr) const {
if (x != cpr.x) return x < cpr.x;
return y < cpr.y;
}
inline bool operator==(const block &cpr) const {
return ((x == cpr.x) && (y == cpr.y));
}
};
struct nblock {
int x, y, id;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> v[n];
for (int i = 0; i < n; i++) {
string str;
cin >> str;
for (int j = 0; j < str.length(); j++) {
if (str[j] == '#') v[i].push_back(j);
}
}
int flag = 1;
for (int i = 0; i < n - 1; i++)... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, m, tmp;
cin >> n >> m;
vector<vector<int>> a(n, vector<int>(m)), b(m, vector<int>(n));
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) cin >> a[i][j];
for (int i = 0; i < m; i++)
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10231;
int n, A, cf, cm;
long long m;
pair<int, int> t[N];
long long pref[N];
long long ok(int z, int w) {
int x = upper_bound(t + 1, t + n + 1, make_pair(z, -1)) - t - 1;
x = min(x, n - w);
return (long long)z * x - pref[x];
}
int ans[N];
int main... | 2 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> goods, g;
vector<int> cost;
int n;
vector<vector<int>> d(105, vector<int>(100005, -1));
void bfs(vector<int>& nds, vector<int>& dis) {
queue<int> q;
for (auto& i : nds) {
q.push(i);
dis[i] = 0;
}
while (!q.empty()) {
int top = q.front... | 1 |
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll ;
#define rep(i, a, b) for (int i = a; i <= b; ++ i)
const int N = 1e5 + 5 ;
using namespace std ;
int X, Y, Z, n, top, q[N] ; ll sum, f[N] ;
struct poi { int x, y, z ; } a[N] ;
bool cmp(poi a, poi b) ... | 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
const int MAX = 2e5 + 5;
const long long MAX2 = 11;
const int MOD = 1000000000 + 7;
const long long INF = 20000;
const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1};
const double pi = acos(-1);
const double E... | 4 |
#include <bits/stdc++.h>
using namespace std;
char a[100005];
int main() {
int n, x1, y1, x2, y2, n1, n2;
char ch1, ch2;
int t1, t2;
cin >> n >> x1 >> y1 >> x2 >> y2;
cin >> a;
if (x1 > x2) {
ch1 = 'W';
n1 = x1 - x2;
} else {
ch1 = 'E';
n1 = x2 - x1;
}
if (y1 > y2) {
ch2 = 'S';
... | 2 |
#include <iostream>
#include <cstdio>
#include <vector>
#include <complex>
#include <cmath>
#include <algorithm>
using namespace std;
// * XYツ催?標
#define X real()
#define Y imag()
// * ツ点ツづ個表ツ個サ
typedef complex<double> P;
// * ツ仰鳴容ツつキツづゥツ古ォツ債キツε?
const double EPS = 1e-10;
// * Infinity
const double INF = 1e12;
// * ツ... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long a[100005];
int main() {
long long n, m;
while (scanf("%lld%lld", &n, &m) != EOF) {
memset(a, 0, sizeof(a));
long long sum = 0;
while (m--) {
long long x, d;
scanf("%lld%lld", &x, &d);
sum += n * x;
if (d > 0) {
sum +... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long s, a[200020], b, g, i, d, l, r, m, tmp, presum[200020];
vector<pair<long long, long long>> v;
cin >> s >> b;
for (i = 1; i <= s; i++) {
cin >> a[i];
}
for (i = 1; i <= b; i++) {
cin >> d >> g;
v.push_back({d, g});
}
sort(v.... | 2 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
string S;
cin>>S;
if(S=="hi"||S=="hihi"||S=="hihihi"||S=="hihihihi"||S=="hihihihihi"){cout<<"Yes"<<endl;}
else{cout<<"No"<<endl;}
} | 0 |
#include <bits/stdc++.h>
using namespace std;
struct sta
{
int X,Y;
sta(){}
sta(int a,int b){X=a;Y=b;}
inline bool operator>(const sta& a) const
{
return X!=a.X?X>a.X:Y<a.Y;
}
};
#define P sta
const int MAXN=1e5+10,INF=1<<27;
int n,m,x,y,z,dist[MAXN];
set<int> s[MAXN];
vector<P> G[MAXN];
int main()
{
sca... | 0 |
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
ll x,y,tmp;
inline ll gcd(ll x,ll y){
if(y==0)return x;
return gcd(y,x%y);
}
int main(){
cin >>x>>y;
ll g = gcd(x,y);
for(ll i=2; i<= g / i; i++)
if(g%i==0)
{
tmp++;
while(g%i == 0) g /= i;
}
if(g>1)tmp++;
cout<<tmp+1<<... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 13;
int n, L, a[1 << N], b[1 << N], c[1 << N], d[1 << N], val[1 << N], sum;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
L = 1 << n;
for (int i = 0; i < L; ++i)
cin >> val[i], sum ^= val[i], a[i] = b[i] = c[i] = d[i]... | 5 |
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define forE(i,x) for(int i=head[x];i!=-1;i=ne[i])
using namespace std;
typedef long long i64;
typedef unsigned long long u64;
typedef unsigned u32;
typedef pair<int,int> pin;
#define mk(a,b) make_pair(a,b)... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int32_t main() {
std::ios::sync_with_stdio(0);
std::cin.tie(0);
;
long long n, m, q;
cin >> n >> m >> q;
long long g = gcd(n, m);
long lo... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int eps = 10e-13;
long long power(long long x, long long y, long long p) {
long long res = 1;
x = x % p;
if (x == 0) return 0;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
int main() {
ios_base:... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
scanf("%d", &T);
while (T--) {
int n;
scanf("%d", &n);
vector<int> a(n);
for (int i = (0); i <= (n - 1); ++i) scanf("%d", &a[i]);
int l = 0, r = 1e9, ans = 0;
auto check = [&](int mid) -> int {
auto b(a);
for (in... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int arr[n];
long long int temp = 0;
long long int count = 0;
for (int i = 0; i < n; i++) {
cin >> arr[i];
if (arr[i] >... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long X;
long long Ans[8000010][2] = {{0}};
int Ansp = 0;
int main() {
cin >> X;
X *= 6;
for (long long i = 1;; i++) {
if (i * i * i > X) break;
long long div = i * (i + 1);
if (X % div == 0) {
long long MM = X / div;
long long M3 = MM + i ... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct point{
int a,b;
point *l,*r,*pa;
point(){l=r=pa=NULL;}
point(int aa,int bb):a(aa),b(bb){l=r=pa=NULL;};
};
point *root;
point *rightRotate(point *t){
point *s=t->l;
t->l=s->r;
s->r=t;
return s;
}
point *leftRotate(point *t){
point *s=t->r;
t->r=s->l;
s->l=t... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, p, t, ans, f[100010], g[100010];
struct node {
int x, y;
} A[100010];
inline void div(int a, int b, int &c, int &r) {
c = a / b;
r = a % b;
}
int main() {
scanf("%*d%d%d%d", &n, &p, &t);
for (int i = 1; i <= n; ++i) scanf("%d%d", &A[i].x, &A[i].y);
g[0] =... | 5 |
#include <bits/stdc++.h>
using namespace std;
map<long long, long long> mp;
long long p;
long long mul(long long x, long long y) { return (x * y) % p; }
long long val(long long x, long long k) {
long long f = mul(mul(x, x), mul(x, x));
long long s = mul(k, x);
f -= s;
f %= p;
f += p;
return f % p;
}
int mai... | 2 |
#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
using namespace std;
const long long MOD = 1e9 + 7;
long long n, m, k, l, r;
long long q, y;
long long kla, klb, dp[1000001], ans[1000001], e[1000001];
long long a[1000001];
string s, d;
vector<pair<long long, long long> > v;
bool tt[100... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long N, a[26][26], min1[26][26], max1[26][26];
int main() {
long long i, j;
cin >> N;
for (j = N - 2; j >= 0; j--) {
for (i = 1; i < N; i++) {
a[i][j] = max1[i - 1][j + 1] - min1[i][j + 1] + 1;
min1[i][j] = min1[i][j + 1] + a[i][j];
}
max1... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int A,B,C;
cin >> A >> B >> C;
string ans="NO";
for(int i=1;i<10000000;i++){
if(i*A%B==C){
ans="YES";}
}
cout << ans << endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
string s;
cin >> s;
int res = 0, cur = 0;
for (int i = 0; i < s.size(); ++i) {
if (s[i] == '(') {
++cur;
} else {
if (cur > 0) {
--cur;
res += 2;
}
}
}
cout << res << endl;... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 300 + 5;
const int MMAX = 3000 + 5;
const int INF = 1000000000;
const int BS = 1000000000 + 7;
const long long INFLL = 1000000000ll * 1000000000ll;
const long double eps = 1e-6;
int a[NMAX];
int c[NMAX];
map<int, int> dp[NMAX];
int gcd(int x, int y) {
if ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
int cnt, n, m;
long long d[100005];
int head[100005], vis[100005];
struct cmp {
bool operator()(const pair<long long, int> p1,
const pair<long long, int> p2) {
return p1.first > p2.first;
}
};
priority_queue<pair<long lo... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long readint() {
long long x = 0, y = 1;
char c = getchar();
while ((c < '0' || c > '9') && c != '-') c = getchar();
if (c == '-') y = -1, c = getchar();
while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * y;
}
long long n;
long lon... | 2 |
#include<iostream>
#include<string>
using namespace std;
int main()
{
string sentence;
string::size_type a, b, i;
int c, d;
getline(cin, sentence);
i = 0;
while (1) {
a = sentence.find("apple", i);
b = sentence.find("peach", i);
if( a==string::npos && b==string::npos ) break;
if (a<b) {
sentence.repl... | 0 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,k;cin>>n>>k;
cout<<(((n-1)/(k-1))+((n-1)%(k-1)?1:0))<<endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
using vi = vector<long long>;
template <typename T>
std::istream& operator>>(std::istream& input, std::pair<T, T>& data) {
input >> data.first >> data.second;
return input;
}
template <typename T>
std::istream& operator>>(std::istream& input, std::vector<T>& data) {
f... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long int fib[51];
vector<long long int> calc(long long int n, long long int k) {
vector<long long int> res;
if (!n) return res;
if (n == 1) {
res.push_back(1);
return res;
}
if (k <= fib[n - 1]) {
res.push_back(1);
vector<long long int> v = ca... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int nmax = 1000001;
int memo1[nmax];
int memo2[nmax];
int main() {
int m;
cin >> m;
int x1, y1, x2, y2, a1, a2;
long long h1, h2;
cin >> h1 >> a1;
cin >> x1 >> y1;
cin >> h2 >> a2;
cin >> x2 >> y2;
int ans1 = 0, ans2 = 0;
for (int i = 0; i < m; ++i... | 3 |
// AOJ q0040
// YAMADA Terushige
// 2013.5.6
#include<iostream>
#include<sstream>
#include<string>
#include<cctype>
using namespace std;
const int N = 26;
char decode(const char c,const int a,const int b){
if(islower(c)){
// int t = ((c - 'a') + N - b)%N;
int t = c - 'a' - b;
while(t%a != 0){
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long p = (long long)1e9 + 7;
long long n, k;
long long bin_pow(long long a, long long n) {
if (!n) return 1;
if (n % 2)
return (bin_pow(a, n - 1) * a) % p;
else {
long long b = bin_pow(a, n / 2);
return (b * b) % p;
}
}
int main() {
cin >> n... | 4 |
#include <iostream>
using namespace std;
int main(void){
int n;
cin >> n;
string name;
long m,a,r,c,h;
m=0;
a=0;
r=0;
c=0;
h=0;
for (int i = 0; i < n; i++)
{
cin >> name;
if (name[0] == 'M') m++;
if (name[0] == 'A') a++;
if (name[0] == 'R') r++;
if (name[0] == 'C') c++;
... | 0 |
#include<iostream>
#include<string>
using namespace std;
int main(){
string s;
while(cin >>s){
bool f = false;
int x = 0;
for(int i=0; i<s.size(); i++){
if(s[i] == '@'){f = true;}
else if(f && x == 0){x = s[i]-'0';}
else if(f){
for(int j=0; j<x; j++){cout <<s[i];}
f = false;
x = 0;
... | 0 |
#include<cstdio>
#define RI register int
using namespace std;
typedef long long LL;
const int N=205;
struct Linear_Basis
{
LL p[63];
inline void clear(void)
{
for (RI i=0;i<63;++i) p[i]=0;
}
inline void insert(LL x)
{
for (RI i=62;~i;--i) if ((x>>i)&1)
{
if (!p[i]) return (void)(p[i]=x); x^=p[i];
}
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 83;
const int MAXM = 4007;
struct eT {
void setd(int _u, int _v, int _w, int _l) {
u = _u, v = _v, w = _w, ... | 4 |
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const int INF=1e9;
const int MO... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5005;
const long long int MOD = 998244353;
long long int postsum[MAXN], fact[MAXN], inv_fact[MAXN];
long long int power(long long int a, long long int b)
{
if (b == 0)
{
return 1;
}
long long int ans = power(a, b/2);
ans = (ans * ans) % MOD;
if (b%2... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2007;
const double EPS = 1e-10;
double add(double a, double b) {
if (abs(a + b) < EPS * (abs(a) + abs(b))) return 0;
return a + b;
}
struct P {
double x, y;
P() {}
P(double x_, double y_) : x(x_), y(y_) {}
P operator+(P p) { return P(add(x, p.x)... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
unsigned long long int n, k, p, c;
cin >> n >> k >> p;
if (n % 2 == 0) {
if (k > n / 2) {
unsigned long long int u = 2 * k - n;
unsigned long long int r = 2 * n - 2 * k;
for (long i = 1; i <= p; i++) {
cin >> c;
if (c... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int main() {
ios_base::sync_with_stdio(false);
int n, a, b, k;
cin >> n >> a >> b >> k;
string s;
cin >> s;
s += '1';
int cnt = 0, all = 0;
for (int i = 0; i <= n; i++) {
if (s[i] == '1') {
all += cnt / b;
cnt = 0;
... | 2 |
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
map<string, bool>mp;
bool check(string s) {
if (s.empty())return true;
if (*s.begin() != 'm' || *s.rbegin() != 'w')return false;
if (mp.find(s) != mp.end())return mp[s];
for (int i = 1; i < s.size() - 1; i++) {
if (s[i] != 'e')co... | 0 |
#include <bits/stdc++.h>
using namespace std;
bool comparator(pair<int, int> &ai, pair<int, int> &bi) {
return ai.second < bi.second;
}
int main() {
string sin, sout;
cin >> sin;
int i, n = sin.length();
vector<int> i_dot;
bool find_at = false;
for (i = 0; i <= n - 3;) {
if (sin.substr(i, 2) == string... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int k;
vector<int> ans;
int main() {
cin >> n >> m >> k;
for (int i = 0; i < k; i++) ans.push_back(1);
int r = n;
int qr = k;
while (r < n + m + 1) {
if (qr == k) {
ans.push_back(r);
qr = 1;
r++;
if (r < n + m + 1) {
b... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long Maxn = 300010;
long long N, K;
pair<long long, long long> pr[Maxn];
priority_queue<pair<long long, long long> > Q;
long long z[Maxn];
int main() {
scanf("%lld%lld", &N, &K);
for (long long i = 1; i <= N; i++)
scanf("%lld", &pr[i].first), pr[i].second... | 3 |
#include <bits/stdc++.h>
using namespace std;
int i, t, n, rs, nr, dp[205];
string a, b, nume[205];
void Normalizare(string &s) {
int i, n = s.length();
for (i = 0; i < n; ++i)
if (s[i] >= 'A' && s[i] <= 'Z') s[i] += 'a' - 'A';
}
int find(string s) {
for (int i = 1; i <= nr; ++i)
if (nume[i] == s) return ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s1, s2, s3, s4;
cin >> s1 >> s2 >> s3;
s4 = s2 + s1;
sort(s3.begin(), s3.end());
sort(s4.begin(), s4.end());
if (s3 == s4)
cout << "YES";
else
cout << "NO";
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
constexpr long long INF = (sizeof(long long) == 4 ? 1e9 : 2e18) + 1e5;
constexpr long long MOD = 1e9 + 7;
constexpr long long MAXN = 2e5 + 3;
void solve() {
long long n;
cin >> n;
vector<long long> arr(n + 1);
long long sum = 0;
for (long long i = 1; i <= n; ++i) ... | 2 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
map<pair<long long, long long>, int> F;
int calc(long long a, long long b) {
if (a > b) {
swap(a, b);
}
if (a == 0 || b == 0) {
return 2;
}
if (b % a == 0) {
return 1;
}
if (a <= 2000000000LL) {
long ... | 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.