code1
stringlengths 54
12k
| code2
stringlengths 66
12k
| similar
int64 0
1
| __index_level_0__
int64 24
101M
|
---|---|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
int t[++N], x[N], y[N];
t[0] = 0;
x[0] = 0;
y[0] = 0;
for (int i = 1; i < N; i++) {
cin >> t[i] >> x[i] >> y[i];
}
for (int i = 1; i < N; i++) {
if (t[i]-t[i-1] < abs(x[i]-x[i-1])+abs(y[i]-y[i-1]) || (t[i]-t[i-1]-abs(x[i]-x[i-1])-abs(y[i]-y[i-1]))%2) {
cout << "No";
return 0;
}
}
cout << "Yes";
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
lint fac[MAX], finv[MAX], inv[MAX];
void COMinit()
{
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (lint i = 2; i < MAX; i++)
{
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
long long COM(lint n, lint k)
{
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
lint primary(lint num)
{
if (num < 2) return 0;
else if (num == 2) return 1;
else if (num % 2 == 0) return 0;
double sqrtNum = sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2)
{
if (num % i == 0)
{
return 0;
}
}
return 1;
}
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1) res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
lint lcm(lint a,lint b){
return a/__gcd(a,b)*b;
}
int main(){
string s,s1;
cin>>s;
rep(i,s.size()){
if(s[i]!='x') s1+=s[i];
}
bool isp=true;
lint ans=0;
rep(i,s1.size()/2){
if(s1[i]!=s1[s1.size()-1-i])isp=false;
}
if(!isp)cout<<-1;
else {
rep(i,s.size()/2){
if(s[i]==s[s.size()-1-i])continue;
else if(s[i]=='x'&&s[s.size()-1-i]!='x')s.insert(s.size()-i,"x");
else if(s[s.size()-1-i]=='x'&&s[i]!='x')s.insert(i,"x");
ans++;
}
cout<<ans;
}
} | 0 | 20,504,907 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,k,x,y;
cin >> n >> k >> x >> y;
int sum=0;
if(n-k>0){
sum += k*x +(n-k)*y;
}
else{
sum += n*x;
}
cout << sum << endl;
} | #include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
int LD(string s1, string s2)
{
int l1 = s1.length() + 1;
int l2 = s2.length()+ 1;
vvi dist(l1);
rep(i,l1) dist[i].resize(l2);
int cost = 0;
rep(i,l1) dist[i][0] = i;
rep(i,l2) dist[0][i] = i;
REP(i,1,l1){
REP(j,1,l2){
cost = !(s1[i-1] == s2[j-1]);
dist[i][j] = min(dist[i-1][j]+1,min(dist[i][j-1]+1,dist[i-1][j-1]+cost));
}
}
return dist[l1-1][l2-1];
}
int main()
{
string s1; cin>>s1;
string s2; cin>>s2;
cout<<LD(s1,s2)<<endl;
return 0;
} | 0 | 65,641,902 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int INF = 100100100;
const double PI = 3.14159265358979323846;
typedef long long ll;
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define REP(i, n) for (ll i = 0; i < (n); ++i)
int main() {
ll n, a, b;
string winner;
cin >> n >> a >> b;
if ((b - a) % 2 == 0) {
winner = "Alice";
} else if ((b - a) % 2 == 1) {
winner = "Borys";
}
cout << winner << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
ios::sync_with_stdio(false);
cin.tie();
ll k;
cin>>k;
queue<ll> q;
for(int i = 1; i < 10; i++){
q.push(i);
}
ll t = 0;
while(1){
t++;
ll x = q.front();
if(t == k){
cout<<x;
return 0;
}
q.pop();
if(x%10 != 0) q.push(x*10+(x%10)-1);
q.push(x*10+x%10);
if(x%10 != 9) q.push(x*10+x%10+1);
}
} | 0 | 74,142,465 |
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>pppp(int64_t x){
vector<pair<int64_t,int64_t>>p;
for(int64_t i=2;i*i<=x;i++){
int cnt=0;
if(x%i==0){
while(x%i==0){cnt++;x/=i;}
p.push_back(make_pair(i,cnt));
}
}
if(x!=1){p.push_back(make_pair(x,1));}
return p;
}
int main() {
int N,M;
cin>>N>>M;
vector<int>a(M),b(M);
vector<bool>P(N,false),Q(N,false);
for(int i=0;i<M;i++){
cin>>a[i]>>b[i];
if(b[i]==N){P[a[i]]=true;}
if(a[i]==1){Q[b[i]]=true;}
}
for(int i=0;i<N;i++){
if(Q[i]&&P[i]){cout<<"POSSIBLE"<<endl;return 0;}
}
cout<<"IMPOSSIBLE"<<endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
int main(void){
int n,q;
cin >> n >> q;
int a[n+1],b[n+1];
int p[q],x[q];
vector<vector<int>> s(n+1);
vector<bool> seen;
vector<int> num(n+1,0);
seen.assign(n+1,false);
for(int i = 1;i < n;i++){
cin >> a[i] >> b[i];
s[a[i]].push_back(b[i]);
s[b[i]].push_back(a[i]);
}
for(int i = 0;i < q;i++){
cin >> p[i] >> x[i];
num[p[i]] += x[i];
}
queue<int> que;
que.push(1);
while(!que.empty()){
int t = que.front();
que.pop();
seen[t] = 1;
for(auto v:s[t]){
if(!seen[v]){
num[v] += num[t];
que.push(v);
}
}
}
for(int i = 1;i <= n;i++)cout << num[i] << " ";
} | 0 | 13,334,053 |
#include <bits/stdc++.h>
using namespace std;
long long extended_euclidean(long long a, long long b, long long &x, long long &y)
{
x = 1;
y = 0;
long long u = 0, v = 1;
long long ri = a, rj = b, rk, k;
while (1) {
k = ri/rj;
rk = ri%rj;
ri = rj;
rj = rk;
long long newx, newy, newu, newv;
newx = u;
newy = v;
newu = x-k*u;
newv = y-k*v;
x = newx;
y = newy;
u = newu;
v = newv;
if (rk == 0)
break;
}
return a*x+b*y;
}
int main(void)
{
int a, b;
cin >> a >> b;
long long x, y;
long long d = extended_euclidean(a, b, x, y);
cout << a / d * b << endl;
return 0;
} | # include <bits/stdc++.h>
# define sz(x) (int)((x).size())
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int N = (int) 3e5 + 5;
const int inf = (int) 1e9 + 7;
int n, l;
int a[N];
ll p[N];
set<pii> s;
set<int> can;
ll sum(pii x) {
return p[x.second] - p[x.first - 1];
}
int main() {
cin >> n >> l;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
p[i] = p[i - 1] + a[i];
s.insert(make_pair(i, i));
}
for (int i = 1; i < n; ++i) {
if (a[i] + a[i + 1] >= l) {
can.insert(i);
}
}
vector<int> ans;
while (!can.empty()) {
int p = *can.begin();
can.erase(can.begin());
auto cur = prev(s.upper_bound(make_pair(p, inf)));
if (next(cur) != s.end()) {
pii F = *cur;
pii S = *next(cur);
s.erase(F);
s.erase(S);
ans.push_back(F.second);
s.insert(make_pair(F.first, S.second));
cur = prev(s.upper_bound(make_pair(F.first, inf)));
if (next(cur) != s.end() && sum(*cur) + sum(*next(cur)) >= l) {
can.insert(cur -> first);
}
if (cur != s.begin() && sum(*cur) + sum(*prev(cur)) >= l) {
can.insert(prev(cur) -> first);
}
}
}
if (sz(s) != 1) {
cout << "Impossible\n";
return 0;
}
reverse(ans.begin(), ans.end());
cout << "Possible\n";
for (int i : ans) {
cout << i << "\n";
}
return 0;
} | 0 | 96,436,704 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long a,b,c,d;
cin>>a>>b>>c>>d;
long long s1=a*c,s2=a*d,s3=b*c,s4=b*d;
long long sum=max(s4,max(s3,max(s2,s1)));
cout<<sum;
} | #include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;
int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
void dfs(int now, int past, ll d, ll &sum, VVI &e){
sum += d;
for (int next : e[now]){
if (next == past) continue;
dfs(next, now, d + 1, sum, e);
}
}
int main() {
ll n;
cin >> n;
VL d(n);
vector<PL> p(n);
REP(i,n){
d[i] = lin();
p[i] = PL(d[i], i);
}
sort(ALL(p));
reverse(ALL(p));
map<ll, ll> mp;
REP(i,n) mp[p[i].first] = i;
VL cnt(n, 1);
vector<PL> ans;
REP(i,n-1){
ll x = p[i].first - (n - 2 * cnt[i]);
if (!mp.count(x) || mp[x] <= i){
cout << -1 << endl;
return 0;
}
int j = mp[x];
cnt[j] += cnt[i];
ans.push_back(PL(p[i].second, p[j].second));
}
VVI e(n);
for (P p : ans){
e[p.first].push_back(p.second);
e[p.second].push_back(p.first);
}
ll sum = 0;
dfs(p[0].second, -1, 0, sum, e);
if (sum != p[0].first){
cout << -1 << endl;
return 0;
}
REP(i,n-1){
printf("%lld %lld\n", ans[i].first + 1, ans[i].second + 1);
}
return 0;
} | 0 | 6,969,719 |
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<" "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;
int check(string s) {
if (s == "Male") return 1;
if (s == "Female") return 2;
return 0;
}
int main() {
int n;
cin >> n;
string s;
cout << 0 << endl;
cin >> s;
int e = check(s);
if (e == 0) return 0;
ll r = n, l = -1;
while (1) {
ll mid = (l + r) / 2;
cout << mid << endl;
cin >> s;
int res = check(s);
if (res == 0) return 0;
if (mid&1) {
if (e == res) r = mid;
else l = mid;
}
else {
if (e == res) l = mid;
else r = mid;
}
}
return 0;
} | #include <iostream>
#include <utility>
#include <queue>
using namespace std;
typedef pair<int,int> P;
P a;
priority_queue< int > pq;
int n;
string s;
int main(){
while(1){
cin >>s;
if(s=="insert"){
cin >>n;
pq.push(n);
}else if(s=="extract"){
cout <<pq.top() <<endl;
pq.pop();
}else if(s=="end"){
break;
}
}
} | 0 | 55,342,365 |
#include<bits/stdc++.h>
using namespace std;
using ll=int64_t;
int main(){
ll x,y,z;
cin>>x>>y;
z=y;
for(int w=1;w<x;w++) z*=y-1;
cout<<z<<endl;
} | #include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;
typedef pair<int, int> P;
typedef priority_queue<int, vector<int>, greater<int>> PQ;
const int MOD = 1000000007;
int main(){
int H, W, D;
cin >> H >> W >> D;
map<int, pair<int, int>> positions;
rep(i,H){
rep(j,W){
int a; cin >> a;
pair<int, int> p = make_pair(i,j);
positions[a] = p;
}
}
vector<int> C(H*W+1,0);
rep(i,D){
int index = i + D;
while(index <= H*W){
int x = abs(positions[index].first-positions[index-D].first);
int y = abs(positions[index].second-positions[index-D].second);
C[index] = x + y + C[index-D];
index += D;
}
}
int Q; cin >> Q;
vector<int> L(Q), R(Q);
rep(i,Q) cin >> L[i] >> R[i];
rep(i,Q){
printf("%d\n", C[R[i]] - C[L[i]]);
}
} | 0 | 27,685,116 |
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln = '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main(){
int a, b, c; cin >> a >> b >> c;
bool fg = true;
if(a%b== 0 && c != 0) fg = false;
else{
if(c%__gcd(a,b)!=0)fg = false;
}
if(fg) cout << "YES" << ln;
else cout << "NO" << ln;
} | #include <bits/stdc++.h>
using namespace std;
int main(){
vector<int> s(9);
for(int i=0;i<9;i++){
cin >> s.at(i);
}
int n;
cin >> n;
vector<int> m(n);
for(int i=0;i<n;i++){
cin >> m.at(i);
for(int j=0;j<9;j++){
if(m.at(i) == s.at(j)) s.at(j) = 0;
}
}
bool e = false;
for(int i=0;i<3;i++){
if(s.at(i) == 0 && s.at(i+3) == 0 && s.at(i+6) == 0){
e = true;
break;
}
}
if(s.at(0) == 0 && s.at(1) == 0 && s.at(2) == 0){
e = true;
}
if(s.at(3) == 0 && s.at(4) == 0 && s.at(5) == 0){
e = true;
}
if(s.at(6) == 0 && s.at(7) == 0 && s.at(8) == 0){
e = true;
}
if(s.at(0) == 0 && s.at(4) == 0 && s.at(8) == 0){
e = true;
}
if(s.at(2) == 0 && s.at(4) == 0 && s.at(6) == 0){
e = true;
}
if(e == true) cout << "Yes" << endl;
else cout << "No" << endl;
} | 0 | 24,632,432 |
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);
int main() {
string S;
cin>>S;
string tmp;
bool can = false;
for(int i=0;i<S.size();++i){
for(int j=i;j<S.size();++j){
tmp = "";
for(int k=0;k<i;++k){
tmp += S[k];
}
for(int k=j;k<S.size();++k){
tmp += S[k];
}
if(tmp=="keyence") can = true;
}
}
if(can) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
} | #include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7
using ll = long long;
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
int main(){
ll a,b;
cin>>a>>b;
if(b%2==1){
if((b+1)%4==0)b=0;
else b=1;
}
else if(b%4!=0)b^=1;
if(a==0){
ll ans=b^a;
cout<<ans<<endl;
return 0;
}
a--;
if(a%2==1){
if((a+1)%4==0)a=0;
else a=1;
}
else if(a%4!=0)a^=1;
ll ans=a^b;
cout<<ans<<endl;
return 0;
} | 0 | 7,219,623 |
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <set>
#define rep0(i, n) for (i = 0; i < n; i++)
#define rep(s, i, n) for (i = s; i < n; i++)
using namespace std;
int sieve[1000002], cnt[1000002], a[1000002], n, m, i, j, g, t;
int gcd(int x, int y) {
return y? gcd(y,x%y) : x;
}
int main() {
scanf("%d",&n);
for(i=0;i<n;i++) {
scanf("%d",a+i);
if(a[i]>m) m=a[i];
if(g) g=gcd(g,a[i]);
else g=a[0];
}
if(g>1){
printf("not coprime\n");
return 0;
}
for(i=2;i<=m;i++) {
if(sieve[i]==0) {
sieve[i]=i;
if((long long)i*i<=m)
for(j=i*i;j<=m;j+=i){
if(sieve[j]==0) sieve[j]=i;
}
}
}
for(i=0;i<n;i++){
j=a[i];
while(j>1){
t=sieve[j];
cnt[t]++;
if(cnt[t]>1) {
printf("setwise coprime\n");
return 0;
}
while(j%t==0) j/=t;
}
}
printf("pairwise coprime\n");
return 0;
} | #include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef unsigned long long ll;
int main()
{
int n;
cin>>n;
vector<int> a(n);
vector<bool> visited(n,false);
visited[0] = true;
for(int i = 0; i < n; i++){
int num;
cin>>num;
num--;
a[i] = num;
}
bool ans = true;
int next = a[0];
int count = 1;
while( next != 1){
visited[next] = true;
next = a[next];
count++;
if( next == 1){
ans = true;
break;
}else if( visited[next] == false){
}else{
ans = false;
break;
}
}
if( ans == true){
cout<<count<<endl;
}else{
cout<<-1<<endl;
}
return 0;
} | 0 | 31,811,605 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 + 20;
int n, a[maxn], g;
int main()
{
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> a[i];
}
for (int i = 0; i < n; i++)
{
if (a[i] == a[i+1])
{
if (a[i+1] == a[i+2])
{
i += 1;
g++;
}
else
{
g++;
}
}
}
cout << g;
return 0;
} | #include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <set>
#define ll long long
#define MODD 1000000007
using namespace std;
ll arr[1000000]={0};
ll brr[1000000]={0};
int main() {
ll a , b;cin >>a>>b;
int flag=1;
a--,b--;
cout<<100<<" "<<100<<endl;
for(int i=1;i<=50;i++){
for(int j=1;j<=100;j++){
if(i%2==0&&j%2==0&&a){
a--;
cout<<".";
}
else cout<<"#";
}
cout<<endl;
}
for(int i=1;i<=50;i++){
for(int j=1;j<=100;j++){
if(i%2==0&&j%2==0&&b){
b--;
cout<<"#";
}
else cout<<".";
}
cout<<endl;
}
return 0;
} | 0 | 9,328,392 |
#include <iostream>
#include <algorithm>
using namespace std;
#define INF ((1<<31)-1)
int main(){
int v,e; cin>>v>>e;
long long int edge[v][v];
for(int i=0;i<v;i++){
for(int j=0;j<v;j++) edge[i][j]=INF;
}
int s,t,d;
for(int i=0;i<e;i++){
cin>>s>>t>>d;
edge[s][t]=d;
}
for(int k=0;k<v;k++){
for(int i=0;i<v;i++){
for(int j=0;j<v;j++){
if(edge[i][k]!=INF&&edge[k][j]!=INF){
edge[i][j]=min(edge[i][j],edge[i][k]+edge[k][j]);
}
}
}
}
for(int i=0;i<v;i++){
if(edge[i][i]<0){
cout<<"NEGATIVE CYCLE"<<endl;
return 0;
}
}
for(int i=0;i<v;i++){
for(int j=0;j<v;j++){
if(j) cout<<" ";
if(i==j) cout<<0;
else if(edge[i][j]>=INF) cout<<"INF";
else cout<<edge[i][j];
}
cout<<endl;
}
return 0;
} | #include<iostream>
#include<vector>
int main() {
int N, M;
std::cin >> N >> M;
std::vector<int> height(N);
for (int i = 0; i < N; i++) std::cin >> height[i];
std::vector<bool> flag(N, true);
for (int i = 0; i < M; i++) {
int A, B;
std::cin >> A >> B;
if (height[A - 1] < height[B - 1]) flag[A - 1] = false;
else if (height[A - 1] == height[B - 1]) {
flag[A - 1] = false;
flag[B - 1] = false;
}
else flag[B - 1] = false;
}
int answer = 0;
for (int i = 0; i < N; i++) {
if (flag[i]) answer++;
}
std::cout << answer << std::endl;
return 0;
} | 0 | 35,624,430 |
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
int main(){
int r, D;
cin >> r >> D;
int x;
cin >> x;
for(int i = 0; i < 10; i++){
x = r * x - D;
cout << x << endl;
}
} | #include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main(){
int n, k, s;
cin >> n >> k >> s;
if(s > 100000){
rep(i, k) cout << s << ' ';
rep(i, n-k) cout << 1 << ' ';
}else{
rep(i, k) cout << s << ' ';
rep(i, n-k) cout << 1000000000 << ' ';
}
cout << endl;
return 0;
} | 0 | 62,652,272 |
#include <iostream>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
using namespace std;
using namespace __gnu_pbds;
typedef tree<pair<long long int,long long int>,null_type,less<pair<long long int,long long int> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
void go()
{
ll int n,m,mod=(ll int)1e9+7;
cin>>n>>m;
vector<vector<char> > a(n,vector<char>(m));
vector<vector<ll int> > dp(n,vector<ll int>(m,0)),temp(n,vector<ll int>(m,0));
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
cin>>a[i][j];
if(a[i][j] == '.')
temp[i][j]=1;
}
}
dp[0][0]=1;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(i > 0 && j > 0)
{
if(a[i][j]=='.')
dp[i][j]=dp[i-1][j]+dp[i][j-1],dp[i][j]%=mod;
else
dp[i][j]=0;
}
if(i == 0 && j > 0)
{
if(a[i][j]=='.')
dp[i][j]=dp[i][j-1],dp[i][j]%=mod;
else
dp[i][j]=0;
}
if(i > 0 && j == 0)
{
if(a[i][j]=='.')
dp[i][j]=dp[i-1][j],dp[i][j]%=mod;
else
dp[i][j]=0;
}
}
}
cout<<dp[n-1][m-1];
}
int main()
{
FIO;
go();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> piipi;
typedef pair<pii, pii> piipii;
#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define eb emplace_back
char s[100005];
int dp[100005];
int main(){
int n;
scanf("%d", &n);
scanf("%s", s);
for(int j=0;j<2;j++){
for(int k=0;k<2;k++){
memset(dp, -1, sizeof(dp));
dp[n-1] = j;
dp[0] = k;
bool ok = 1;
for(int i=0;i<n;i++){
if(dp[i] == 0){
if(s[i] == 'o'){
if(dp[(i+1)%n] == -1) dp[(i+1)%n] = dp[(i-1+n)%n];
else if(dp[(i+1)%n] != dp[(i-1+n)%n]) ok = 0;
}
else{
if(dp[(i+1)%n] == -1) dp[(i+1)%n] = 1-dp[(i-1+n)%n];
else if(dp[(i+1)%n] != 1-dp[(i-1+n)%n]) ok = 0;
}
}
else{
if(s[i] == 'x'){
if(dp[(i+1)%n] == -1) dp[(i+1)%n] = dp[(i-1+n)%n];
else if(dp[(i+1)%n] != dp[(i-1+n)%n]) ok = 0;
}
else{
if(dp[(i+1)%n] == -1) dp[(i+1)%n] = 1-dp[(i-1+n)%n];
else if(dp[(i+1)%n] != 1-dp[(i-1+n)%n]) ok = 0;
}
}
}
if(ok){
for(int i=0;i<n;i++){
if(dp[i] == 0 ) printf("S");
else printf("W");
}
return 0;
}
}
}
printf("-1\n");
} | 0 | 41,774,943 |
#include<bits/stdc++.h>
#include<deque>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
int x,y,a,b,c;
cin>>x>>y>>a>>b>>c;
deque<int>arr;
deque<int>arr2;
deque<int>arr3;
int num;
for(int i=0;i<a;i++)
{
cin>>num;
arr.push_back(num);
}
for(int i=0;i<b;i++)
{
cin>>num;
arr2.push_back(num);
}
for(int i=0;i<c;i++)
{
cin>>num;
arr3.push_back(num);
}
sort(arr.begin(),arr.end());
sort(arr2.begin(),arr2.end());
sort(arr3.begin(),arr3.end());
reverse(arr3.begin(),arr3.end());
while(arr.size()>x){ arr.pop_front();}
while(arr2.size()>y){ arr2.pop_front();}
while(arr3.size())
{
int variable=arr3.front();
int minimo=min(arr.front(),arr2.front());
if(variable<=minimo) break;
if(arr.front()<arr2.front()){
arr.pop_front();
arr.push_back(variable);
}
else
{
arr2.pop_front();
arr2.push_back(variable);
}
arr3.pop_front();
}
long long resultado=0;
for(int i=0;i<arr.size();i++)
resultado+=arr[i];
for(int i=0;i<arr2.size();i++)
resultado+=arr2[i];
cout<<resultado;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;
int main() {
int H, W;
cin >> H >> W;
ll ans = LLINF;
for(int h = 1; h < H; ++h) {
ll s1 = (ll)h * W, s2 = (ll)(H - h) * (W / 2),
s3 = (ll)(H - h) * W - s2;
ll mi = min(s1, min(s2, s3)), ma = max(s1, max(s2, s3));
ans = min(ans, ma - mi);
s2 = (ll)(H - h) / 2 * W, s3 = (ll)(H - h) * W - s2;
mi = min(s1, min(s2, s3)), ma = max(s1, max(s2, s3));
ans = min(ans, ma - mi);
}
for(int w = 1; w < W; ++w) {
ll s1 = (ll)w * H, s2 = (ll)(W - w) * (H / 2),
s3 = (ll)(W - w) * H - s2;
ll mi = min(s1, min(s2, s3)), ma = max(s1, max(s2, s3));
ans = min(ans, ma - mi);
s2 = (ll)(W - w) / 2 * H, s3 = (ll)(W - w) * H - s2;
mi = min(s1, min(s2, s3)), ma = max(s1, max(s2, s3));
ans = min(ans, ma - mi);
}
cout << ans << endl;
return 0;
} | 0 | 59,616,699 |
#include <iostream>
#include <string>
using namespace std;
bool is_upper(char c)
{
if ('A' <= c && c <= 'Z')
{
return true;
}
else
{
return false;
}
}
bool is_lower(char c)
{
if ('a' <= c && c <= 'z')
{
return true;
}
else
{
return false;
}
}
int main()
{
char c;
int diff = 'A' - 'a';
string str;
getline(cin, str);
for (auto c : str)
{
if (is_lower(c))
{
cout << (char)(c + diff);
}
else if (is_upper(c))
{
cout << (char)(c - diff);
}
else
{
cout << c;
}
}
cout << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
vector<string> split(const string &s, char delim) {
vector<string> elems;
stringstream ss(s);
string item;
while (getline(ss, item, delim)) {
if (!item.empty()) {
elems.push_back(item);
}
}
return elems;
}
int to_seconds(vector<string> t) {
int h = atoi(t[0].c_str()) * 3600;
int m = atoi(t[1].c_str()) * 60;
int s = atoi(t[2].c_str());
return h + m + s;
}
const int MAX_M = 24 * 60 * 60;
int sum[MAX_M];
int main() {
while (1) {
int n;
cin >> n;
if (n == 0) return 0;
rep(i, MAX_M) sum[i] = 0;
rep(i, n) {
string a, b;
cin >> a >> b;
int dep = to_seconds(split(a, ':'));
int arr = to_seconds(split(b, ':'));
sum[dep]++;
if (arr < MAX_M) sum[arr]--;
}
rep(i, MAX_M - 1) sum[i + 1] += sum[i];
int ans = 0;
rep(i, MAX_M) ans = max(ans, sum[i]);
cout << ans << endl;
}
return 0;
} | 0 | 8,000,958 |
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#include <numeric>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
ll dy[8]={ 1, 0,-1, 0, 1,-1, 1,-1};
int main(void) {
ll a, b, m;
cin >> a >> b >> m;
ll x[a], y[b];
map<p, ll> I{};
for(ll i = 0; i < a; i++)
cin >> x[i];
for(ll i = 0; i < b; i++)
cin >> y[i];
ll ans = 1e+9;
for(ll i = 0; i < m; i++){
ll c, d, e;
cin >> c >> d >> e;
ans = min(ans, x[c-1]+y[d-1]-e);
}
sort(x, x+a);
sort(y, y+b);
ans = min(ans, x[0]+y[0]);
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, start, n) for (int i = (int)(start); i < (int)(n); ++i)
static const int INFTY = (1 << 30);
int N;
void func()
{
cin >> N;
vector<pair<int, int>> red, blue;
int a, b;
rep(i, 0, N)
{
cin >> a >> b;
red.push_back(make_pair(a, b));
}
rep(i, 0, N)
{
cin >> a >> b;
blue.push_back(make_pair(a, b));
}
sort(red.begin(), red.end());
sort(blue.begin(), blue.end());
int ans = 0;
int maxi, maxs;
for (int i = 0; i < N; ++i)
{
maxi = -1, maxs = -1;
for (int j = 0; j < N; ++j)
{
if (red[j].first < blue[i].first && red[j].second < blue[i].second)
{
if (red[j].second > maxs)
maxi = j, maxs = red[j].second;
}
}
if (maxi != -1)
{
++ans;
red[maxi].first = INFTY, red[maxi].second = INFTY;
}
}
cout << ans << endl;
}
int main()
{
func();
} | 0 | 25,952,559 |
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define input_output freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define ll long long
#define read1(x) cin>>x
#define read2(x,y) cin>>x>>y
#define print(x) cout<<x<<endl
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>
#define vd vector<double>
#define vs vector<string>
#define ff first
#define ss second
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define vpii vector<pii>
#define umap unordered_map
#define uset unordered_set
#define clr(a,b) memset(a,b,sizeof a)
#define all(ds) ds.begin(), ds.end()
#define rev(ds) ds.rbegin(), ds.rend()
#define asc(A) sort(A.begin(), A.end())
#define dsc(A) sort(A.begin(), A.end(), greater<int>())
#define gcd(x,y) __gcd(x,y)
#define clr(a,b) memset(a,b,sizeof a)
#define fr(i, n) for(int i=0; i<n;++i)
#define fr1(i, n) for(int i=1; i<=n; ++i)
#define rfr(i, n) for(int i=n-1; i>=0; --i)
#define printVector(v) for(int i= 0;i<v.size();i++) {cout<<v[i]<<" ";} cout<<endl;
#define precise(x) cout<<fixed<<setprecision(x)
#define inf 10000000000000
ll lcm(ll a, ll b) {return (a*b)/__gcd(a, b); }
ll power(ll x, ll y, ll m) { if(!y) return 1; ll p=power(x, y>>1, m)%m; p=p*p%m; return (y&1)?(x*p)%m:p;}
ll modInverse(ll a, ll m){ return power(a, m-2, m); }
bool isPrime(ll num){bool flag=true;for(ll i =2;i<=num/2;i++){if(num%i==0) {flag=false; break;} }return flag;}
ll sumofdigits(ll n){ll c=0;while(n>0){c++;n/=10;}return c;}
bool sortinrev(const pair<int,int>&a,const pair<int,int>&b) {return a.first > b.first; }
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b) {return a.second < b.second; }
const long long MOD= 1000000007;
int n, m, k, total;
char v[6][6];
char newv[6][6];
void newCopy(){
fr(i,n){
fr(j,m){
newv[i][j] = v[i][j];
}
}
}
void colorRed(int row, int col){
fr(i,n){
if(row & (1<<i)){
fr(j,m){
newv[i][j] = 'R';
}
}
}
fr(j,m){
if(col & (1<<j)){
fr(i,n){
newv[i][j] = 'R';
}
}
}
}
bool countBlack(){
int ans = 0;
fr(i,n){
fr(j,m){
if(newv[i][j] == '#')
ans++;
}
}
return ans == k;
}
void tryAll(){
for(int i = 0; i < (1<<n); ++i){
for(int j = 0; j < (1<<m); ++j){
newCopy();
colorRed(i, j);
total += countBlack();
}
}
}
void solve(){
cin>>n>>m>>k;
total = 0;
fr(i,n){
fr(j, m){
cin>>v[i][j];
}
}
tryAll();
print(total);
}
int main()
{
#ifndef ONLINE_JUDGE
input_output
#else
fastio
#endif
int t =1 ;
while(t--){
solve();
}
return 0;
} | #include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
ll digitSum(ll x){
ll sum = 0;
while(x > 0){
sum += x % 10;
x /= 10;
}
return sum;
}
int main(){
ll N, A, B;
cin >> N >> A >> B;
ll ans = 0;
REP(i, N){
ll sum = digitSum(i);
if(sum >= A && sum <= B){
ans += i;
}
}
cout << ans << endl;
return 0;
} | 0 | 49,082,611 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
vector<int64_t> A(n), B(n);
vector<array<int64_t, 2>> S(n);
for (int i = 0; i < n; i++){
cin >> A[i] >> B[i];
S[i][0] = A[i] + B[i];
S[i][1] = i;
}
sort(S.begin(), S.end(), greater<array<int64_t, 2>>());
int64_t ans = 0;
for (int i = 0; i < n; i++){
if (i % 2 == 0)
ans += A[S[i][1]];
else
ans -= B[S[i][1]];
}
cout << ans << endl;
} | #include <iostream>
#include <cmath>
using namespace std;
int main(void)
{
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
double x1, y1, x2, y2, x3, y3, x4, y4;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
if (((x2-x1)==0) && ((x4-x3)==0))
cout << "YES" << endl;
else {
double d = abs((y2-y1)*(x4-x3) - (y4-y3)*(x2-x1));
cout << ((d <= 1e-10)? "YES" : "NO") << endl;
}
}
return 0;
} | 0 | 28,301,941 |
#include <iostream>
#define toDigit(c) (c-'0')
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define _ std::ios::sync_with_stdio(false); std::cin.tie(0);
#define debug(x) std::cout << '>' << #x << ':' << x << std::endl;
typedef long long LL;
int main() { _
int n;
std::cin >> n;
int acc = 0;
for(int i=1; i<=n; i++)
acc += i;
std::cout << acc << '\n';
return 0;
} | #include <bits/stdc++.h>
#define ll long long int
#define dbg(x) cout<<"( "<<#x<<" -> "<<x<<" )"<<endl;
using namespace std;
int main()
{
int n;
scanf("%d",&n);
string s;
cin>>s;
if (n%2==1)
printf("No\n");
else
{
int c=0;
for (int i=0;i<n/2;i++)
{
if (s.at(i)==s.at(i+n/2))
c++;
}
if (c==n/2)
printf("Yes\n");
else
printf("No\n");
}
return 0;
} | 0 | 53,053,962 |
#include <bits/stdc++.h>
#include <x86intrin.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define chmin(x,y) x = min(x, y)
#define chmax(x,y) x = max(x, y)
#define V vector
vector<int> dx = {-1, 1, 0, 0, -1, -1, 1, 1};
vector<int> dy = { 0, 0, -1, 1, -1, 1, -1, 1};
int main () {
int n, k, s; cin >> n >> k >> s;
rep(i, k) printf("%d ", s);
rep(i, n-k) {
if (s == 1e9) printf("1 ");
else printf("1000000000 ");
}
cout << endl;
return 0;
} | #include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
#define NUM 1000000007
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
int n,m;
cin>>n>>m;
vector<bool> ok(n+1,true);
rep(i,m){
int a;
cin>>a;
ok[a]=false;
}
vector<ll> dp(n+1);
dp[0]=1;
rep(now,n){
for(int next=now+1;next<=min(n,now+2);next++){
if(ok[next]){
dp[next]+=dp[now];
dp[next]%=NUM;
}
}
}
cout<<dp[n];
} | 0 | 9,681,624 |
#include <bits/stdc++.h>
#include<cmath>
#define N 100005
#define A 1000005
#define MOD 998244353
#define INF 1000000000000000000
#define ll long long
using namespace std;
#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
#define itr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define mem(a, b) memset(a, (ll)b, sizeof(a))
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define edge(v, x, y) v[x].pb(y); v[y].pb(x);
#define popcount __builtin_popcount
#define ANS(s) {cout << s << "\n"; return;}
#define printpii(a) cout << a.ft << " " << a.sd << endl;
#define printpiii(a) cout << a.ft << " " << a.sd.ft << " " << a.sd.sd << endl;
#define print(a, n) rep(i, n) cout << a[i] << " "; cout << endl;
#define printv(v) for(auto x: v)cout << x << " "; cout << endl;
#define printm(a, n, m) rep(i, n) { rep(j, m) cout << a[i][j] << "\t"; cout << endl;}
ll dx[4] = {0, 0, 1, -1};
ll dy[4] = {1, -1, 0, 0};
void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout << setprecision(12) << fixed;}
void solve(){
ll a[26]; mem(a, 0);
string s;
cin >> s;
for(auto x: s){
a[x-'a']++;
}
rep(i, 26)
if(a[i] == 0) ANS( (char)(i+'a'));
ANS("None");
}
main(){
fast();
ll t = 1;
while(t--){
solve();
}
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
typedef long long ll;
ll dp[200010];
int main(){
ll n;cin>>n;
vector<ll> coin;
coin.push_back(1LL);
rep(i,1,7)coin.push_back((ll)pow(6,i));
rep(i,1,6)coin.push_back((ll)pow(9,i));
rep(i,0,n+1)dp[i]=1e9;
dp[0]=0;
rep(i,0,n+1){
rep(j,0,coin.size()){
dp[i+coin[j]]=min(dp[i+coin[j]],dp[i]+1);
}
}
cout<<dp[n]<<endl;
} | 0 | 46,142,945 |
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <cctype>
#include <fstream>
#include <ctime>
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int f(int x )
{
return x*x;
}
int main()
{
string str = "";
while (getline (cin, str ) ){
stringstream ss (str );
int d;
ss >> d;
int area = 0;
for (int x = d; x <= 600 - d; x += d ){
area += d*f(x);
}
cout << area << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;
#ifdef _DEBUG
inline void dump() { cerr << endl; }
template<typename Head> void dump(Head&& head) { cerr << head; dump(); }
template<typename Head, typename... Tail> void dump(Head&& head, Tail&&... tail) { cerr << head << ", "; dump(forward<Tail>(tail)...); }
#define debug(...) do {cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; dump(__VA_ARGS__); } while (false)
#else
#define dump(...)
#define debug(...)
#endif
template<typename T>
struct edge {
int src, to;
T cost;
edge(int to, T cost) : src(-1), to(to), cost(cost) {}
edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
edge &operator=(const int &x) {
to = x;
return *this;
}
operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;
const ll inf = 1LL<<60;
int main()
{
ll h, w; cin>>h>>w;
vector<string> s(h);
rep(i, h) cin>>s[i];
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
rep(i, h) rep(j, w) {
if (s[i][j] == '.') continue;
bool isok = false;
rep(k, 4) {
int ni = i - dx[k];
int nj = j - dy[k];
if (ni<0||h<=ni||nj<0||w<=nj) continue;
if (s[ni][nj] == '#') isok = true;
}
if (!isok) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
return 0;
} | 0 | 34,991,154 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
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];
long long add_a = 0, add_b = 0;
long long diffs = 0;
for (int i = 0; i < n; i++) {
int diff = b[i] - a[i];
diffs += diff;
if (diff > 0) add_a += diff / 2;
else add_b += -1 * diff;
}
if (add_a >= add_b) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define sz(v) ((int)((v).size()))
#define clr(v, d) memset(v, d, sizeof(v))
#define rep(i, v) for(int i=0; i<sz(v); ++i)
#define lp(i, n) for(int i=0; i<(int)(n); ++i)
#define lpi(i, j, n) for(int i=(j); i<(int)(n); ++i)
#define lpd(i, j, n) for(int i=(j); i>=(int)(n); --i)
#define INF 1000000000
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
const int N = 1e5+5;
priority_queue<pair<int, int>> all;
priority_queue<pair<int, int>> rep;
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>> > sol;
int vis[N];
int main()
{
std::ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, k, uniq = 0;
cin >> n >> k;
lp(i, n){
pair<int, int> in;
cin >> in.second >> in.first;
all.push(in);
}
lp(i, n){
pair<int, int> in = all.top();
all.pop();
if(vis[in.second] > 0 || uniq == k)
rep.push(in);
else{
sol.push(in);
++vis[in.second];
++uniq;
}
}
lpi(i, uniq, k){
sol.push(rep.top());
++vis[rep.top().second];
rep.pop();
}
while(!rep.empty()){
ll op1 = 0ll + (uniq-1)*(uniq-1) + rep.top().first;
ll op2 = 0ll + (uniq)*(uniq) + sol.top().first;
if(op1 > op2){
sol.pop();
sol.push(rep.top());
rep.pop();
--uniq;
}
else
break;
}
ll ans = 0;
ans = 1ll * uniq * uniq;
while(!sol.empty()){
ans += 0ll + sol.top().first;
sol.pop();
}
cout << ans;
return 0;
} | 0 | 21,739,994 |
#pragma GCC optimize("Ofast")
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
#include<iomanip>
#include<queue>
const long long INF_L = 1e17+7;
const long long INF_I = 1e9+7;
const long long MOD = 1e9+7;
const double EPS = 1e-8;
const double PI=acos(-1);
using namespace std;
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
string s;
cin >> s;
int k;
cin >> k;
k--;
for(int i=0;i<n;i++){
if(s[i]==s[k])continue;
s[i]='*';
}
cout << s << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
template<typename T>
struct WarshallFloyd {
const T INF = numeric_limits<T>::max();
int n;
vector<vector<T>> d;
WarshallFloyd(int n) : n(n), d(n, vector<T>(n, INF)) {
for (int i = 0; i < n; i++) d[i][i] = 0;
}
void add_edge(int s, int t, T w, bool directed) {
d[s][t] = min(d[s][t], w);
if (directed) d[t][s] = min(d[t][s], w);
for (int k : {s, t})
for (int i = 0; i < n; i++) if (d[i][k] != INF)
for (int j = 0; j < n; j++) if (d[k][j] != INF)
d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}
bool has_neg_cycle() {
for (int i = 0; i < n; i++) if (d[i][i] < 0) return true;
return false;
}
bool in_shortest_path(int s, int t, T w) {
return d[s][t] >= w;
}
};
int main() {
int n, m; cin >> n >> m;
vector<int> a(m), b(m), c(m);
for (int i = 0; i < m; i++) cin >> a[i] >> b[i] >> c[i], a[i]--, b[i]--;
WarshallFloyd<int> wf(n);
for (int i = 0; i < m; i++) wf.add_edge(a[i], b[i], c[i], true);
int cnt = 0;
for (int i = 0; i < m; i++) cnt += !wf.in_shortest_path(a[i], b[i], c[i]);
cout << cnt << endl;
return 0;
} | 0 | 76,849,459 |
#include <iostream>
#include <algorithm>
using namespace std;
int SelectionSort(int a[],int n){
int s = 0;
for(int i = 0;i < n-1;i++){
int minj = i;
for(int j = i; j < n;j++){
if(a[j] < a[minj]) minj = j;
}
swap(a[i],a[minj]);
if(i != minj)s++;
}
return s;
}
int main(){
int a[100] = {};
int n,s;
cin >> n;
for(int i = 0;i < n;i++) cin >> a[i];
s = SelectionSort(a,n);
for(int i = 0;i < n;i++){
if(i)cout << " ";
cout << a[i];
}
cout << endl;
cout << s << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1005;
int n, m;
int X[N], Y[N];
ll d[N];
const int dx[5] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};
const char dc[5] = {'R', 'L', 'U', 'D'};
void getp(ll x, ll y) {
for(int i = m; i; i--) {
int now = d[i];
for(int j = 0; j < 4; j++) {
ll curx = x + d[i] * dx[j], cury = y + d[i] * dy[j];
if(abs(curx) + abs(cury) < now) {
cout << dc[j];
x = curx, y = cury;
break;
}
}
}
}
int main() {
ios::sync_with_stdio(false); cin.tie(0);
cin >> n;
int sign = 1, mx = 0;
for(int i = 1; i <= n; i++) cin >> X[i] >> Y[i];
for(int i = 2; i <= n; i++) {
if((abs(X[i] + Y[i]) & 1) != (abs(X[i - 1] + Y[i - 1]) & 1))
sign = 0;
mx = max(mx, abs(X[i]) + abs(Y[i]));
}
if(!sign) {cout << -1; return 0;}
for(d[m = 1] = 1; d[m] << 1 <= mx; ++m, d[m] = d[m - 1] << 1);
if(abs(X[1] + Y[1]) & 1) sign = 0;
cout << m + sign << '\n';
if(sign) cout << 1 << ' ';
for(int i = m; i; i--) cout << d[i] << " \n"[i == 1];
for(int i = 1; i <= n; i++) {
if(sign) cout << 'R';
getp(X[i] - sign, Y[i]);
cout << '\n';
}
return 0;
} | 0 | 9,597,556 |
#include <bits/stdc++.h>
#include<cmath>
#define N 100005
#define A 1000005
#define MOD 1000000007
#define inf 1000000000000000000
#define ll long long
using namespace std;
#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
#define itr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define mem(a, b) memset(a, (ll)b, sizeof(a))
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define edge(v, x, y) v[x].pb(y); v[y].pb(x);
#define popcount __builtin_popcount
#define ANS(s) {cout << s << "\n"; return;}
#define printpii(a) cout << a.ft << " " << a.sd << endl;
#define printpiii(a) cout << a.ft << " " << a.sd.ft << " " << a.sd.sd << endl;
#define print(a, n) rep(i, n) cout << a[i] << " "; cout << endl;
#define printv(v) for(auto x: v)cout << x << " "; cout << endl;
#define printm(a, n, m) rep(i, n) { rep(j, m) cout << a[i][j] << "\t"; cout << endl;}
ll lx[4] = {0, 0, 1, -1};
ll ly[4] = {1, -1, 0, 0};
ll dx[8] = {0, 0, 1, -1, 1, -1, 1, -1};
ll dy[8] = {1, -1, 0, 0, 1, 1, -1, -1};
void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout << setprecision(12) << fixed;}
void solve();
main(){
fast();
ll t = 1;
while(t--){
solve();
}
}
void solve(){
ll n, m;
cin >> n >> m;
ll sx[n], sy[n], cx[m], cy[m];
rep(i, n) cin >> sx[i] >> sy[i];
rep(i, m) cin >> cx[i] >> cy[i];
ll ax[n], a[n];
rep(i, n)
{
a[i] = inf;
rep(j, m)
{
ll dis = abs(sx[i] - cx[j]) + abs(sy[i] - cy[j]);
if(a[i] > dis) {
a[i] = dis;
ax[i] = j+1;
}
}
}
rep(i, n) cout << ax[i] << " ";
} | #include <iostream>
#include <vector>
#include <deque>
using namespace std;
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(false)
#define pb push_back
#define pf pop_front
typedef long long ll;
typedef pair<int, int> pii;
const ll MAX_N = 10 * 1000 + 24;
int n, m;
int d[MAX_N];
vector<int> G[MAX_N], vec;
deque<int> dq;
int main() {
FAST;
cin>>n>>m;
int u, v;
for (int i = 0; i < m; i++) {
cin>>u>>v;
G[u].pb(v);
d[v]++;
}
for (int i = 0; i < n; i++) {
if (d[i] == 0) {
dq.pb(i);
vec.pb(i);
}
}
while (dq.size()) {
for (int j = 0; j < G[dq[0]].size(); j++) {
u = G[dq[0]][j];
d[u]--;
if (d[u] == 0) {
dq.pb(u);
vec.pb(u);
}
}
dq.pf();
}
for (int i = 0; i < n; i++) {
cout<<vec[i]<<"\n";
}
} | 0 | 15,017,835 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using Graph = vector<vector<int>>;
using Edge = map<pair<int,int>,int>;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
std::fill( (T*)array, (T*)(array+N), val );
}
ll gcd(ll a,ll b){
if (a%b == 0) return(b);
else return(gcd(b, a%b));
}
ll lcm(ll a, ll b){
return a*b/gcd(a, b);
}
int main()
{
cout << fixed << setprecision(15);
ll N;
cin >> N;
vector<ll> L(87);
;
L[1] = 1;
REP(i, N+1){
if(i == 0){
L[0] = 2;
continue;
}
if(i == 1){
L[1] = 1;
continue;
}
L[i] = L[i-1] + L[i-2];
}
cout << L[N] << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
#define PI 3.14159265358979
const int INF = 1 << 29;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
typedef pair<int, int> P;
int main(){
int N;
cin >> N;
int a = 6, b = 9;
vector<int> D = {1};
while(a <= N){
D.push_back(a);
a *= 6;
}
while(b <= N){
D.push_back(b);
b *= 9;
}
int s = D.size();
vector<vector<int>> dp(s + 10, vector<int>(N + 10, INF));
rep(j, 0, s) dp.at(j).at(0) = 0;
rep(j, 0, N + 1) dp.at(0).at(j) = j;
rep(i, 0, s - 1){
rep(n, 0, N + 1){
dp.at(i + 1).at(n) = min(dp.at(i).at(n), dp.at(i + 1).at(n));
if (n >= D.at(i + 1)){
dp.at(i + 1).at(n) = min(dp.at(i + 1).at(n - D.at(i + 1)) + 1, dp.at(i + 1).at(n));
}
}
}
cout << dp.at(s - 1).at(N) << endl;
} | 0 | 90,209,832 |
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <ctime>
#include <list>
using namespace std;
static const double EPS = 1e-8;
typedef long long ll;
typedef pair<int,int> PI;
#ifndef M_PI
const double M_PI=acos(-1);
#endif
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int((a).size()))
#define F first
#define S second
int dx[]={0,1,0,-1,0,0},dy[]={1,0,-1,0,0,0};
int dz[]={0,0,0,0,1,-1};
int st[10000];
int ed[10000];
int n;
void solve(){
priority_queue<PI> q;
rep(i,n){
int hh,mm,ss;
scanf("%d:%d:%d",&hh,&mm,&ss);
st[i]=hh*3600+mm*60+ss;
q.push(mp(-st[i],0));
scanf("%d:%d:%d",&hh,&mm,&ss);
ed[i]=hh*3600+mm*60+ss;
q.push(mp(-ed[i],1));
}
int ans=0;
int cu=0;
while(!q.empty()){
int cc=q.top().S;
q.pop();
cu+=cc;
if(cc==0 && cu==0)++ans;
else if(cc==0)--cu;
}
cout<<ans<<endl;
}
main(){
while(cin>>n,n)
solve();
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(int i=0;i<(int)(n);i++)
#define foi(i,k,n) for(int i=(k); i<(int)(n); i+=1)
#define fod(i,n,k) for(int i=k; i>=(int)n; i-=1)
#define fast_io ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define all(x) x.begin(), x.end()
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define endl "\n"
#define int long long
#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define fir first
#define sec second
#define pb push_back
#define mp make_pair
typedef long long llint;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<llint> VL;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MII;
typedef set<int> SI;
string tostr(int n) {stringstream rr;rr<<n;return rr.str();}
llint toint(string s) {stringstream ss(s); llint x; ss >> x; return x;}
const int MX = 2e8 + 100;
bitset <MX> vis;
bool check(int x){
if(x % 2 == 0){
if(vis[2]) return true;
vis[2] = 1;
}
while(x % 2 == 0){
x /= 2;
}
for(int i = 3; i <= sqrt(x); i += 2){
if(x % i == 0 && vis[i]) return true;
while(x % i == 0){
vis[i] = 1;
x /= i;
}
}
if(x > 1){
if(vis[x]) return true;
vis[x] = 1;
}
return false;
}
void solve(){
int n;
cin >> n;
VI v(n);
loop(i, n) cin >> v[i];
bool b = false;
loop(i, n){
b |= check(v[i]);
}
if(!b){
cout << "pairwise coprime";
return;
}
loop(i, n){
if(i) v[i] = __gcd(v[i], v[i - 1]);
}
if(v[n - 1] == 1){
cout << "setwise coprime";
return;
}
cout << "not coprime";
}
int32_t main() {
fast_io;
int t = 1;
while(t--) {
solve();
}
return 0;
} | 0 | 17,772,712 |
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, N, a, b) for(int i = a; i < N; i += b)
int main(){
vector<int> A(3);
rep(i, 3) cin >> A.at(i);
sort(A.begin(), A.end());
cout << (A.at(2) - A.at(1)) + (A.at(1) - A.at(0)) << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int a,b,m;
int smallA = 100000;
int smallB = 100000;
int smallWariNasi = 0;
int smallWari = 200000;
cin >> a >> b >> m;
vector<int> vecA(a);
vector<int> vecB(b);
for(int i = 0; i < a; i++){
cin >> vecA.at(i);
if(smallA > vecA.at(i)) smallA = vecA.at(i);
}
for(int i = 0; i < b; i++){
cin >> vecB.at(i);
if(smallB > vecB.at(i)) smallB = vecB.at(i);
}
smallWariNasi = smallA + smallB;
int tmpA,tmpB,wariKin;
for(int i = 0; i < m; i++){
cin >> tmpA >> tmpB >> wariKin;
tmpA--;
tmpB--;
if(smallWari > vecA.at(tmpA) + vecB.at(tmpB) - wariKin){
smallWari = vecA.at(tmpA) + vecB.at(tmpB) - wariKin;
}
}
if(smallWariNasi <= smallWari) cout << smallWariNasi;
else cout << smallWari;
} | 0 | 23,778,923 |
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
int64_t MOD=1000000007;
int main() {
int N;
cin>>N;
bool error=false;
int64_t ans=0;
vector<int64_t> S(N+1);
vector<int64_t> T(N+1);
for(int i=0;i<=N;i++)cin>>S.at(i);
T.at(N)=S.at(N);
for(int i=N-1;i>0;i--) T.at(i)=T.at(i+1)+S.at(i);
T.at(0)=1;
for(int i=1;i<=N;i++){
T.at(i)=min(T.at(i),2*T.at(i-1)-2*S.at(i-1));
if(T.at(i)<1) error=true;
}
if(error||S.at(N)!=T.at(N)) cout<<-1;
else{
for(int i=0;i<=N;i++){
ans+=T.at(i);
}
cout<<ans<<endl;
}
} | #include <iostream>
#include <string>
using namespace std;
int main(){
int n;
int taroP = 0;
int hanakoP = 0;
string taro,hanako;
cin >> n;
for (int i = 0; i < n ; ++i) {
cin >> taro;
cin >> hanako;
if (taro == hanako) {
taroP += 1;
hanakoP += 1;
}else {
if (taro > hanako){
taroP += 3;
}else {
hanakoP += 3;
}
}
}
cout << taroP << " " << hanakoP << endl;
return 0;
} | 0 | 84,484,543 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n); ++i)
typedef long long ll;
const int mod = 1e9+7;
const int INF = 2000000;
const double PI = acos(-1.0);
int main() {
int X;
cin >> X;
int K = 1;
while(X*K%360 != 0) K++;
cout << K << endl;
} | #include <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
vector < int > v;
map < int, int > mp;
int main()
{
bool vis[110];
int M,k;
cin >> M >> k;
int Xor = 0;
for(int i = 0; i<(1 << M); i++)
{
v.push_back(i);
v.push_back(i);
if(i != k) Xor^=i;
}
if(k == 0){
for(auto it : v) cout << it << " ";
return 0;
}
if(Xor == k){
int n = (1 << (M + 1));
v[n/2 - 1] = k;
int j = 0;
for(int i = 0;i<n/2 - 1;i++){
if(j == k) j++;
v[i] = j;
v[n - 2 - i] = j;
j++;
}
v[n - 1] = k;
for(auto it : v) cout << it << " ";
return 0;
}
cout << -1;
return 0;
} | 0 | 2,284,510 |
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<n; i++)
#define REP(i,x,n) for (int i=x; i<n; i++)
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
const int mod =1'000'000'007;
int main(){
int n, k;
cin >> n >> k;
vi h(n);
rep(i,n) cin >> h.at(i);
sort(h.rbegin(), h.rend());
ll ans = 0;
REP(i,k,n) ans += h.at(i);
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
int p[n];
for(int i=0; i<n; i++){
cin >> p[i]; p[i]--;
}
int a[n],b[n];
for(int i=0; i<n; i++){
a[i] = i+1;
b[i] = n-i;
}
for(int i=0; i<n-1; i++){
int q = p[i];
for(int j=0; j<q; j++) b[j] += n-i;
for(int j=q+1; j<n; j++) a[j] += n-i;
}
for(int i=0; i<n; i++){
cout << a[i] << ' ';
}
cout << endl;
for(int i=0; i<n; i++){
cout << b[i] << ' ';
}
cout << endl;
return 0;
} | 0 | 80,021,157 |
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long;
const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;
int main(void){
int p,q,r; cin >> p >> q >> r;
int ans1=INF,ans2=INF;
ans1 = min(p+q,r+q);
ans2 = min(r+p,q+p);
int ans = min(ans1,ans2);
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int64_t N;
cin >> N;
vector<int64_t> A(N+1), B(N);
for (int64_t i=0; i<N+1; i++) {
cin >> A[i];
}
for (int64_t i=0; i<N; i++) {
cin >> B[i];
}
int64_t m=0;
for (int64_t i=0; i<N; i++) {
if (A[i]>=B[i]) {
A[i]-=B[i];
m+=B[i];
}
else {
m+=A[i];
B[i]-=A[i];
A[i]=0;
if (A[i+1]>=B[i]) {
A[i+1]-=B[i];
m+=B[i];
}
else {
m+=A[i+1];
B[i]-=A[i+1];
A[i+1]=0;
}
}
}
cout << m << endl;
} | 0 | 19,829,874 |
#include <bits/stdc++.h>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
using ll = long long;
using P = pair<int,int>;
using graph = vector<vector<char>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
int N;
cin>>N;
vector<vector<int>> R(N,vector<int>(2)),B(N,vector<int>(2));
vector<int> g(2*N,-1);
rep(i,N) cin>>R[i][0]>>R[i][1];
rep(i,N) {
cin>>B[i][0]>>B[i][1];
g[B[i][1]]=B[i][0];
}
sort(R.begin(),R.end());
reverse(R.begin(),R.end());
int ans = 0;
for(auto x:R){
for(int i = x[1]+1; i < 2*N; i++){
if(g[i]>x[0]) {
ans++;
g[i]=-1;
break;
}
}
}
cout<<ans<<endl;
} | #include<bits/stdc++.h>
#define Rushia_mywife ios::sync_with_stdio(0);cin.tie(0);
#define rep(i,head,n) for(int i=(head);i<n;i++)
#define int long long
#define F first
#define S second
#define pb push_back
#define p2(n) (1<<(n))
#define lg2(n) __lg(n)
using namespace std;
using pii = pair<long long,long long>;
using ld = long double;
mt19937 mt_rand(time(0));
const int mod = 1000000007;
const int hnum = 998244353;
const ld PI = acos(-1);
const int N = 5010;
int ans,n,k,cnt,len,times;
int p[N];
int c[N];
int mx[N];
bool vis[N];
vector<int>path;
void dfs(int now,int x){
vis[now] = 1;
int pre = path.back();
path.pb(pre+c[p[now]]);
cnt++;
mx[cnt] = max(mx[cnt-1],path.back());
if(!vis[p[now]])
dfs(p[now],x);
}
void solve(){
ans = (int)-1e18;
cin >> n >> k;
rep(i,1,n+1)
cin >> p[i];
rep(i,1,n+1)
cin >> c[i];
rep(i,1,n+1){
memset(vis,0,sizeof(vis));
mx[0] = (int)-1e18;
cnt = 0;
path.clear();
path.pb(0);
dfs(i,i);
len = path.size()-1;
times = k/len;
if(times)
ans = max(ans,path[len]*(times-1)+mx[len]);
if(path[len]>0)
ans = max(ans,path[len]*times+max(0LL,mx[k%len]));
ans = max(ans,mx[min(k,len)]);
}
cout << ans << '\n';
}
signed main(){
Rushia_mywife
solve();
} | 0 | 63,162,219 |
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
signed main(){
ll n,m; cin>>n>>m;
vl v(n);
rep(i,0,n)cin>>v[i];
sort(all(v));
reverse(all(v));
ll ans=0;
rep(i,0,n){
if(m>0){
m--;
}
else ans+=v[i];
}
cout<<ans<<endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define P pair<ll,ll>
#define Graph vector<vector<ll>>
#define INF (1ll<<55)
#define mod 1000000007
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;} return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;} return false;}
void prime_div(vector<ll> &ret,ll n){
ll x=n;
for(ll i=2;i*i<=x;i++){
while(n%i==0){
n/=i;
ret.push_back(i);
}
}
if(n!=1){
ret.push_back(n);
}
return;
}
int main(){
ll n;cin>>n;
vector<ll> ret;
for(ll i=1;i<=n;i++){
prime_div(ret,i);
}
sort(ret.begin(),ret.end());
ret.push_back(INF);
vector<ll> pr(101,0);
ll num=1;
rep(i,ret.size()-1){
if(ret[i]==ret[i+1]){
num++;
}else{
if(num!=1){
pr[ret[i]]=num;
}
num=1;
}
}
ll n2=0,n4=0,n14=0,n24=0,n74=0;
rep(i,pr.size()){
if(pr[i]>=74){
n74++;
}
if(pr[i]>=24){
n24++;
}
if(pr[i]>=14){
n14++;
}
if(pr[i]>=4){
n4++;
}
if(pr[i]>=2){
n2++;
}
}
cout<<n74+n24*(n2-1)+n14*(n4-1)+n4*(n4-1)*(n2-2)/2<<endl;
return 0;
} | 0 | 73,810,528 |
#include <bits/stdc++.h>
using namespace std;
long long Solve(long long a, long long b, long long g) {
return b / g - (a - 1) / g;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long a, b, c, d;
cin >> a >> b >> c >> d;
long long g = c / __gcd(c, d) * d;
long long Not = Solve(a, b, c) + Solve(a, b, d) - Solve(a, b, g);
long long ans = b - a + 1 - Not;
cout << ans << endl;
} | #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define eps 1e-9
#define maxp 1000400
#define mod 1000000007
#define pi 3.141592653589793238
#define sin(s) scanf("%lld",&s);
#define sout(s) printf("%lld\n",s);
#define in(s) cin>>s
#define in2(a,b) cin>>a>>b
#define in3(a,b,c) cin>>a>>b>>c
#define vll vector<ll>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define endl '\n'
#define sp ' '
#define gear_change ios_base::sync_with_stdio(false),cin.tie(0)
#define nfl(i,n) for(i=0;i<n;i++)
#define sfl(i,s,e) for(i=s;i<e;i++)
#define ufl(i,n) for(i=n-1;i>=0;i--)
ll power(ll x,ll y){
ll ret=1;
while(y>0){
if(y&1)
ret=(ret*x);
y/=2;
x=(x*x);
}
return ret;
}
string rot(string s){
string ret="";
ll i;
for(i=1;s[i];i++){
ret+=s[i];
}
ret+=s[0];
return ret;
}
void solve(){
string s,t;
cin>>s>>t;
string s2=s;
if(s==t){
cout<<"Yes"<<endl;
return;
}
s=rot(s);
while(s!=s2){
if(s==t){
cout<<"Yes"<<endl;
return;
}
s=rot(s);
}
cout<<"No"<<endl;
}
int main(){
gear_change;
ll test=1;
while(test--){
solve();
}
} | 0 | 48,353,180 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
using ll = long long;
int main()
{
int n, p;
scanf("%d%d", &n, &p);
int m = 0;
rep(i, n) {
int a;
scanf("%d", &a);
if(a % 2 == 1) m++;
}
if(m == 0) {
if(p == 0) printf("%lld\n", 1ll << n);
else printf("0\n");
}
else {
printf("%lld\n", 1ll << (n - 1));
}
return 0;
} | #include<iostream>
using namespace std;
#define ll long long
int N;
ll X;
ll a[50],p[50];
ll fact(int n,ll x){
if(n==0) return 1;
if(x==1) return 0;
if(x<=1+a[n-1]) return fact(n-1,x-1);
if(x==2+a[n-1]) return p[n-1]+1;
if(x<=2*a[n-1]+2) return p[n-1]+1+fact(n-1,x-a[n-1]-2);
if(x==2*a[n-1]+3) return p[n-1]*2+1;
}
int main(){
cin>>N>>X;
a[0]=p[0]=1;
for(int i=1;i<N;i++){
a[i]=2*a[i-1]+3;
p[i]=2*p[i-1]+1;
}
cout<<fact(N,X)<<endl;
return 0;
} | 0 | 20,801,336 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
bool OK = false;
for (int j = 0; j <= n / 4; j++) {
for (int k = 0; k <= n / 7; k++) {
if (4 * j + 7 * k == n) OK = true;
}
}
if (OK == false) cout << "No" << endl;
else cout << "Yes" << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main()
{
int g[3][3];
for (int i = 0; i < 3; i++)
cin >> g[i][0] >> g[i][1] >> g[i][2];
int n;
cin >> n;
set<int> cj;
for (int i = 0; i < n; i++) {
int b;
cin >> b;
cj.insert(b);
}
bool can = (cj.count(g[0][0]) > 0 && cj.count(g[1][1]) > 0 && cj.count(g[2][2]) > 0) ||
(cj.count(g[0][2]) > 0 && cj.count(g[1][1]) > 0 && cj.count(g[2][0]) > 0);
for (int i = 0; i < 3; i++) {
if (cj.count(g[i][0]) > 0 && cj.count(g[i][1]) > 0 && cj.count(g[i][2]) > 0)
can = true;
else if (cj.count(g[0][i]) > 0 && cj.count(g[1][i]) > 0 && cj.count(g[2][i]) > 0)
can = true;
}
if (can)
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
} | 0 | 41,266,444 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
int N, M;
int L[100000], R[100000];
cin >> N >> M;
int min = 0;
int max = N;
for(int i = 0; i < M; i++)
{
cin >> L[i] >> R[i];
if (L[i] > min) min = L[i];
if (R[i] < max) max = R[i];
}
int total = 0;
if ((max - min) >= 0)
{
total = (max - min) + 1;
}
cout << total << endl;
} | #include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int main() {
int h,w;cin>>h>>w;
int a[h][w];
rep(i,h)rep(j,w)a[i][j]=0;
int bh[h],bw[w];
rep(i,h)bh[i]=0;
rep(i,w)bw[i]=0;
rep(i,h){
string s;cin>>s;
rep(j,w)if(s[j]=='#'){
a[i][j]=1;
bh[i]=1;
bw[j]=1;
}
}
rep(i,h){
rep(j,w){
if(bh[i]==0||bw[j]==0)continue;
else{
if(a[i][j]==1)cout<<'#';
else cout<<'.';
}
}
cout<<endl;
}
return 0;
} | 0 | 27,208,613 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
const int mod=1e9+7;
int main(){
int n;cin>>n;
vector<ll> x(n+1);rep(i,n)cin>>x[i];
x[n]=1e18+1;
int l;cin>>l;
vector<vector<int>> db(18,vector<int>(n,0));
rep(i,n){
int idx=upper_bound(all(x),x[i]+l)-x.begin();
db[0][i]=--idx;
}
rep(i,1,18){
rep(j,n){
db[i][j]=db[i-1][db[i-1][j]];
}
}
int q;cin>>q;
rep(_,q){
int a,b;cin>>a>>b;
if(a>b)swap(a,b);
--a;--b;
int ctr=0;
for(int i=17;i>=0;--i){
int p=db[i][a];
if(p<b){
a=p;ctr+=(1<<i);
}
}
cout<<ctr+1<<endl;
}
} | #include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <complex>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rRep(i,a,b) for(ll i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
if('0' <= c && c <= '9') return (c-'0');
return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
for(auto i=begin(v); i != end(v); ++i){
if(i !=begin(v)) os << ' ';
os << *i;
}
return os;
}
vector<vector<ll>> V(1007);
bool C[1007];
bool com;
ll pre[1007];
int main(){
string S;
cin >> S;
cout << S.substr(0,4) << " " << S.substr(4,8) << endl;
} | 0 | 13,909,677 |
#include<bits/stdc++.h>
#include<algorithm>
#include<unordered_map>
#include<vector>
#include<unordered_set>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD 1000000007
#define MOD1 998244353
#define nline "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define PI 3.141592653589793238462
#define debug(x) cout << #x << " " << x <<endl;
#define set_bits __builtin_popcount
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
ll gcd(ll a, ll b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);}
ll expo(ll a, ll b, ll mod)
{ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}
vector<int> sieve(int n) {int*arr = new int[n + 1](); vector<int> vect; for (int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;}
void extendgcd(ll a, ll b, ll*v) {if (b == 0) {v[0] = 1; v[1] = 0; v[2] = a; return ;} extendgcd(b, a % b, v); ll x = v[1]; v[1] = v[0] - v[1] * (a / b); v[0] = x; return;}
ll mminv(ll a, ll b) {ll arr[3]; extendgcd(a, b, arr); return arr[0];}
ll mminvprime(ll a, ll b) {return expo(a, b - 2, b);}
bool revsort(ll a, ll b) {return a > b;}
void swap(int &x, int &y) {int temp = x; x = y; y = temp;}
ll combination(ll n, ll r, ll m, ll* fact) {ll val1 = fact[n]; ll val2 = mminvprime(fact[r], m); ll val3 = mminvprime(fact[n - r], m); return ((val1 * val2) % m * val3) % m;}
void google(int t) {cout << "Case #" << t << ": ";}
int main()
{
fastio();
#ifndef ONLINE_JUDGE
freopen("Input.txt", "r", stdin);
freopen("Output.txt", "w", stdout);
freopen("Error.txt", "w", stderr);
#endif
ll x, a;
cin >> x >> a;
if (x < a)
cout << 0 << endl;
else
cout << 10 << endl;
return 0;
} | #include "bits/stdc++.h"
using namespace std;
#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
#define int long long
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge
{
int s, t, cost;
Edge(int s,int t,int cost):s(s),t(t),cost(cost){}
Edge():Edge(-1,-1,-1){}
};
int d[100][100];
int V, E;
void shortest_path()
{
rep(k, 0, V)rep(i, 0, V)rep(j, 0, V)if (d[i][k] != INF&&d[k][j] != INF)d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}
signed main()
{
cin.tie(0);
ios::sync_with_stdio(false);
int start;
cin >> V >> E;
rep(i, 0, V)rep(j, 0, V)if (i != j)d[i][j] = INF;
rep(i, 0, E)
{
int s, t, c;
cin >> s >> t >> c;
d[s][t] = c;
}
shortest_path();
rep(i, 0, V)if (d[i][i] < 0)
{
cout << "NEGATIVE CYCLE" << endl;
return 0;
}
rep(i, 0, V)
{
rep(j, 0, V)
{
if (j != 0)
{
printf(" ");
}
printf(d[i][j] == INF ? "INF" : "%lld", d[i][j]);
}
printf("\n");
}
return 0;
} | 0 | 68,628,584 |
#include <iostream>
#include <cmath>
using namespace std;
int main() {
double a, b;
cin >> a >> b;
cout << round((a + b) / 2);
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
int main()
{
string S;
cin >> S;
if (S.find("RRR") != string::npos) {
cout << 3 << endl;
} else {
if (S.find("RR") != string::npos) {
cout << 2 << endl;
} else {
if (S.find("R") != string::npos) {
cout << 1 << endl;
} else {
cout << 0 << endl;
}
}
}
return 0;
} | 0 | 22,140,982 |
#include <iostream>
using namespace std;
int main() {
int H, W, i, k;
while (1) {
cin >> H >> W;
if (H == 0 && W == 0) {
break;
}
for (k = 1; k <= H; k++) {
for (i = 1; i <= W; i++) {
if (i != W) {
cout << "#";
} else {
cout << "#" << endl;
}
}
if(k == H){
cout << "\n";
}
}
}
return 0;
} | #include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)
template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x) cerr << #x << " = " << (x) << endl
#define MOD 1000000007
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vector<ll> X(N), Y(N);
rep(i, 0, N) cin >> X[i] >> Y[i];
ll max_xy = 0;
for (int i = 0; i < N - 1; ++i) {
if (abs(X[i] + Y[i]) % 2 != abs(X[i + 1] + Y[i + 1]) % 2) {
cout << -1 << endl;
return 0;
}
chmax(max_xy, abs(X[i]) + abs(Y[i]));
}
chmax(max_xy, abs(X[N - 1]) + abs(Y[N - 1]));
vector<ll> v;
if (abs(X[0] + Y[0]) % 2 == 0) {
v.push_back(1ll);
}
v.push_back(1ll);
for (int i = 0; v.back() + 1 < max_xy; ++i) {
v.push_back(v.back() * 2ll);
}
reverse(all(v));
int m = v.size();
cout << m << endl;
for (int i = 0; i < m; ++i) {
cout << v[i];
if (i < m - 1) cout << " ";
else cout << endl;
}
for (int i = 0; i < N; ++i) {
ll x = X[i];
ll y = Y[i];
string ans;
for (int j = 0; j < m; ++j) {
if (abs(x) > abs(y)) {
if (x > 0) {
x -= v[j];
ans += 'R';
} else {
x += v[j];
ans += 'L';
}
} else {
if (y > 0) {
y -= v[j];
ans += 'U';
} else {
y += v[j];
ans += 'D';
}
}
}
cout << ans << endl;
}
return 0;
} | 0 | 38,449,324 |
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main() {
ll N;
cin >> N;
string S;
cin >> S;
for(int bit=0;bit<(1<<2);++bit){
vector<bool> isSheep(N,false);
for(int i=0;i<2;i++){
if((bit>>i) &1){
isSheep[i] = true;
}
}
for(int i=1;i<N-1;i++){
if(isSheep[i]){
if(S[i] == 'o'){
isSheep[i+1] = isSheep[i-1];
}else{
isSheep[i+1] = !isSheep[i-1];
}
}else{
if(S[i] == 'x'){
isSheep[i+1] = isSheep[i-1];
}else{
isSheep[i+1] = !isSheep[i-1];
}
}
}
bool ok = true;
for(int i=0;i<2;i++){
int t = (N-1+i)%N;
int next = (N+i)%N;
int prev = (N-2+i)%N;
if(isSheep[t]){
if(S[t] == 'o'){
if(isSheep[next] != isSheep[prev]){
ok = false;
}
}else{
if(isSheep[next] == isSheep[prev]){
ok = false;
}
}
}else{
if(S[t] == 'o'){
if(isSheep[next] == isSheep[prev]){
ok = false;
}
}else{
if(isSheep[next] != isSheep[prev]){
ok = false;
}
}
}
}
if(!ok){
continue;
}
for(int i=0;i<N;i++){
if(isSheep[i]){
cout <<"S";
}else{
cout <<"W";
}
}
cout <<endl;
return 0;
}
cout << -1 << endl;
return 0;
} | #define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
#define CONTAINS_SET(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
signed main()
{
int N;
cin >> N;
for (int i = N; i <= 999; i++)
{
if (i < 10)
{
cout << i << endl;
return 0;
}
if (i < 100)
{
if (i / 10 == i % 10)
{
cout << i << endl;
return 0;
}
}
if (i < 1000)
{
if ((i / 10) % 10 == i % 10 && i / 100 == i % 10)
{
cout << i << endl;
return 0;
}
}
}
} | 0 | 47,316,339 |
#include <stdio.h>
int
main(void)
{
char line[80];
int n;
if (fgets(line, sizeof line, stdin)) {
if (sscanf(line, "%d", &n) == 1) {
long long r = 1;
for (int i = 2; i <= n; i++) {
r *= i;
}
printf("%lld\n", r);
}
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;
const int MOD = 1e9 + 7;
int main()
{
int n, a, b;
cin >> n >> a >> b;
int ans = 0;
int tmp, cnt;
rep2(i, 1, n + 1)
{
cnt = 0;
tmp = i;
while (tmp)
{
cnt += tmp % 10;
tmp /= 10;
}
if (a <= cnt && cnt <= b)
{
ans += i;
}
}
cout << ans << endl;
return (0);
} | 0 | 54,676,259 |
#define _GIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
vector<bool> seen;
int n, m;
int ans = 0;
void dfs(const Graph &g, int v, int num) {
seen[v] = true;
if (num == n) {
ans++;
}
for (auto next_v: g[v]) {
if (seen[next_v]) continue;
dfs(g, next_v, num + 1);
}
seen[v] = false;
}
int main(void) {
cin >> n >> m;
Graph g(n);
rep(i, m) {
int a, b;
cin >> a >> b;
--a;
--b;
g[a].push_back(b);
g[b].push_back(a);
}
seen.assign(n, false);
dfs(g, 0, 1);
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define arep(i, x, n) for (int i = int(x); i < (int)(n); i++)
#define rep(i, n) for (long long i = 0; i < n; ++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9 + 7
using ll = long long;
int main() {
ll n;
cin >> n;
vector<ll> a(n);
vector<bool> history(n);
rep(i, n) {
cin >> a[i];
history[i] = false;
}
ll curpt = 1;
ll cnt = 0;
bool isDone = false;
while (isDone == false) {
cnt++;
curpt = a[curpt - 1];
if (curpt == 2) {
isDone = true;
} else {
if(history[curpt - 1]){
isDone = true;
cnt = -1;
}
}
history[curpt - 1] = true;
}
cout << cnt << endl;
} | 0 | 239,735 |
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;
string A[60], B[60];
int main()
{
int N, M;
cin >> N >> M;
for (int i = 0; i < N; i++) cin >> A[i];
for (int i = 0; i < M; i++) cin >> B[i];
for (int i = 0; i <= N - M; i++) {
for (int j = 0; j <= N - M; j++) {
bool ok = true;
for (int k = 0; k < M; k++) {
if (A[i + k].substr(j, M) != B[k].substr(0, M)) {
ok = false;
break;
}
}
if (ok) {
cout << "Yes" << endl;
return 0;
}
}
}
cout << "No" << endl;
} | #include <iostream>
#include <cmath>
using namespace std;
int main (void) {
double x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
double xdiff = x2-x1;
double ydiff = y2-y1;
cout << fixed;
cout.precision(8);
cout << hypot(xdiff,ydiff) << endl;
} | 0 | 11,714,054 |
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include<iomanip>
#define rep(i,n) for(int i = 0; i < (n);i++)
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
using namespace std;
using ll =long long;
#define INF 2000000000
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
#define che(a,string) cout<<"
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
int main(){
ll a,b,k;
cin >> a >> b >> k;
int count = 0;
for(int i = 0 ; i < k ; i ++){
if(a % 2 == 1){
a --;
}
a /= 2;
b += a;
count++;
if(count == k) break;
if(b % 2 == 1){
b--;
}
b /= 2;
a += b;
count++;
if(count == k) break;
}
cout<<a<<" "<<b<<endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
struct edge{
int to,color;
};
using Graph = vector<vector<edge>>;
int main(){
int N;
cin >> N;
vector<ll> A(N);
rep(i,N){
cin >> A[i];
}
vector<ll> B(N);
rep(i,N){
B[i] = A[i] - i - 1;
}
sort(B.begin(),B.end());
ll b = B[N/2];
ll sum = 0;
rep(i,N){
sum += abs(B[i]-b);
}
cout << sum << endl;
} | 0 | 98,412,954 |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
ll s,c;
cin>>s>>c;
ll ans=0;
ans+=min(2*s,c-(c&1));
ans>>=1;
if(ans==s){
c-=2*s;
ans+=(c/4);
}
cout<<ans<<endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = 1LL<<60;
constexpr ll MOD = 1e9+7;
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
#if loc||local
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}
signed main(){
ll n,m,v,p;
cin>>n>>m>>v>>p;
vector<ll> a(n);
cin>>a;
sort(rbegin(a),rend(a));
auto check = [&](ll idx)->ll{
auto b = a;
ll key = a[idx]+m;
rep(i,n){
if(b[i]<=key)b[i]=min(b[i]+m,key);
else if(b[i]>key)b[i]+=m;
}
vector<ll>d(n);
rep(i,n)if(b[i]-a[i]<m)d[i]=m-(b[i]-a[i]);
sort(rbegin(d),rend(d));
ll cnt = 0;
rep(i,n)cnt+=b[i]-a[i];
sort(rbegin(b),rend(b));
auto itr = lower_bound(b.begin(),b.end(),key,greater<>());
int id = itr-begin(b);
for(int i=0;i+id+1<p;++i){
cnt += d[i];
}
return id+1<=p && cnt>=m*v;
};
ll loweq = 0;
ll high = n;
while(high-loweq>1){
ll mid = high+loweq>>1;
if(check(mid))loweq=mid;
else high=mid;
}
cout<<(high)<<endl;
} | 0 | 45,852,492 |
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v) reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF UnionFind
#define Pint pair<int,int>
#define keta(a) fixed << setprecision(a)
constexpr auto INF = 100000000000;
constexpr auto mod = 1000000007;
struct edge { int to, cost; };
void dijkdtra(int s,int v,vector<int>&d,whei(edge)&G) {
priority_queue<Pint, vector<Pint>, greater<Pint>> que;
d[s] = 0;
que.push(Pint(0, s));
while (!que.empty()) {
Pint p = que.top();
que.pop();
int V = p.second;
if (d[V] < p.first)continue;
for (int i = 0; i < G[V].size();i++) {
edge e = G[V][i];
if (d[e.to] > d[V] + e.cost) {
d[e.to] = d[V] + e.cost;
que.push(Pint(d[e.to], e.to));
}
}
}
}
int main() {
llint n,m;
cin >> n >> m;
hei(llint) a(n + 1, 0);
rep(i, 0, n) {
llint b;
cin >> b;
a[i + 1] = (a[i] + b) % m;
}
llint ans = 0;
sort(a.begin(), a.end());
a.push_back(m + 1);
llint x = 1;
rep(i, 0, n) {
if (a[i] == a[i + 1])x++;
else {
ans += (x*(x - 1)) / 2;
x = 1;
}
}
ans += x * (x - 1) / 2;
cout << ans << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define N_MAX 100001
#define NIL -1
struct node{
int parent, sibiling, child;
};
int n;
node T[N_MAX];
int D[N_MAX];
void insert(){
int i, j;
int s, p, c, m, tmp_s;
for(i=0; i<n; i++) T[i].parent=T[i].sibiling=T[i].child=NIL;
for(i=0; i<n; i++){
scanf("%d %d", &p, &m);
for(j=0; j<m; j++){
scanf("%d", &s);
T[s].parent=p;
if(j==0) T[p].child=s;
else T[tmp_s].sibiling=s;
tmp_s=s;
}
}
}
void setd(int i, int d){
D[i]=d;
if(T[i].sibiling != NIL) setd(T[i].sibiling, d);
if(T[i].child != NIL) setd(T[i].child, d+1);
}
void depth(){
int i, root;
for(i=0; i<n; i++){
if(T[i].parent==NIL){
root=i;
break;
}
}
setd(root, 0);
}
void print(int i){
int j, s=T[i].child;
printf("node %d: parent = %d, depth = %d, ", i, T[i].parent, D[i]);
if(T[i].parent==NIL){
printf("root, [");
for(j=0; ; j++){
if(j==0){
if(s==NIL) break;
printf("%d", s);
s=T[s].sibiling;
}
else{
if(s==NIL) break;
printf(", %d", s);
s=T[s].sibiling;
}
}
printf("]\n");
}
else if(T[i].child==NIL) printf("leaf, []\n");
else{
printf("internal node, [");
for(j=0; ; j++){
if(j==0){
if(s==NIL) break;
printf("%d", s);
s=T[s].sibiling;
}
else{
if(s==NIL) break;
printf(", %d", s);
s=T[s].sibiling;
}
}
printf("]\n");
}
}
int main(void){
int i;
scanf("%d", &n);
insert();
depth();
for(i=0; i<n; i++) print(i);
return 0;
} | 0 | 28,223,516 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
int a, b, c;
cin >> a >> b >> c;
set<int> st;
st.insert(a);
st.insert(b);
st.insert(c);
cout << st.size() << "\n";
} | #include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1e17;
const int inf = 1e5;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
struct UnionFind {
vector<int> par;
UnionFind(int n) : par(n, -1) { }
void init(int n) { par.assign(n, -1); }
int root(int x) {
if (par[x] < 0) return x;
else return par[x] = root(par[x]);
}
bool issame(int x, int y) {
return root(x) == root(y);
}
bool merge(int x, int y) {
x = root(x); y = root(y);
if (x == y) return false;
if (par[x] > par[y]) swap(x, y);
par[x] += par[y];
par[y] = x;
return true;
}
int size(int x) {
return -par[root(x)];
}
};
struct SegmentTree{
int N;
vector<int> node;
public :
void intit(vector<int>v){
int sz = v.size();
N=1;
while(N<sz) N*=2;
node.resize(N);
for(int i=0 ; i<sz ; i++) node[i+N-1] = v[i];
for(int i=N-2 ; i>=0 ; i--) node[i] = min(node[i*2+1], node[i*2+2]);
}
void update(int x, int val){
x += N-1;
node[x+N-1] = val;
while(x>0){
x = (x-1)/2;
node[x] = min(node[x*2+1], node[x*2+2]);
}
}
int getmin(int a, int b, int k, int l, int r){
if(b<=l || r<=a) return inf;
else if(a<=l && r<=b) return node[k];
else{
int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
return min(vl, vr);
}
}
};
ll func(ll k){
ll res=0;
switch (k%4) {
case 0: res=k;
break;
case 1: res=1LL;
break;
case 2: res=k+1;
break;
case 3: res=0;
break;
}
return res;
}
int main(){
ll a,b; cin>>a>>b;
if(a!=0) a--;
ll ans = func(a)^func(b);
cout<<ans<<endl;
return 0;
} | 0 | 22,359,283 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> primes;
vector<int> factor;
map<int,int> ma;
int z[1010101];
int main(){
ll n;
cin >> n;
for(int i = 2; i <= 1010101; i++){
if(z[i]) continue;
z[i] = i;
primes.push_back(i);
for(int u = i; u <= 1010101; u += i){
z[u] = i;
}
}
while(n){
bool bo = false;
for(auto u : primes){
if(u > sqrt(n)) break;
if(n % u == 0){
bo = true;
ma[u]++;
n /= u;
}
}
if(!bo){ma[n]++;break;}
}
ll su = 0;
ma[1] = 0;
for(auto u : ma){
ll s = 0;
for(int i = 1; i <= 100; i++){
s += i;
if(s > u.second) break;
su++;
}
}
cout << su << "\n";
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
template<class T> inline void chmin(T& a, T b){
if (a > b){
a = b;
}
}
template<class T> inline void chmax(T& a, T b){
if (a < b){
a = b;
}
}
signed main(){
cin.tie(0);
ios::sync_with_stdio(false);
cout<<fixed<<setprecision(10);
string S;
cin >> S;
int sizes = S.size();
sort(ALL(S));
UNIQUE(S);
cout << (sizes - S.size() ? "no" : "yes") << "\n";
} | 0 | 79,661,235 |
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
using namespace std;
using int64 = long long;
int64 calc(int64 h, int64 w) {
int64 res = INT_MAX;
for (int i=1; i<h; i++) {
int64 a = i * w;
int64 rest_h = h - i;
{
int64 b = ceil(rest_h/2.0) * w;
int64 c = floor(rest_h/2.0) * w;
int64 s_max = max(a, max(b,c));
int64 s_min = min(a, min(b,c));
res = min(res, s_max - s_min);
}
{
int64 b = ceil(w/2.0) * rest_h;
int64 c = floor(w/2.0) * rest_h;
int64 s_max = max(a, max(b,c));
int64 s_min = min(a, min(b,c));
res = min(res, s_max - s_min);
}
}
return res;
}
int main() {
int64 h, w;
cin >> h >> w;
int64 ans = calc(h,w);
ans = min(ans, calc(w,h));
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<long long> A(N);
long long totA = 0;
for (int i = 0; i < N; i++) {
cin >> A.at(i);
totA += A.at(i);
}
vector<long long> B(N);
long long totB = 0;
for (int i = 0; i < N; i++) {
cin >> B.at(i);
totB += B.at(i);
}
if (totA < totB) {
cout << -1 << endl;
return 0;
}
vector<int> C(N);
long long ans = 0;
long long cost = 0;
for (int i = 0; i < N; i++) {
C.at(i) = A.at(i) - B.at(i);
if (C.at(i) < 0) {
ans++;
cost += C.at(i) * (-1);
}
}
sort(C.begin(), C.end());
reverse(C.begin(), C.end());
int i = 0;
while (cost > 0) {
cost -= C.at(i);
i++;
ans++;
}
cout << ans << endl;
} | 0 | 31,646,737 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)
bool sort_by(pi c, pi d){
return c.S < d.S;
}
int main() {
string s;
ll k, ans= 0, d = 0;
cin >> s >> k;
int i = 1;
bool same = true;
REP(i, 1, (int)s.size()){
if(s[i] != s[0]){
same = false;
break;
}
}
if(same){
cout << (int)s.size()*k/2;
return 0;
}
while(i < (int)s.size()){
if(s[i] == s[i-1]){
++d;
++i;
}
++i;
}
ans = d*k;
int ss = s.size()-1;
if(s[0] == s[ss]){
int a = 0;
int b = 0;
while(a <= ss && s[a] == s[0]) ++a;
while(ss- b >= 0 && s[ss-b] == s[0]) ++b;
ans -= ((a/2 +b/2 - (a+b)/2) * (k-1));
}
cout << ans;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
string s; cin >> s;
string ans = "";
for (int i = 0; i < s.length(); i++) {
if (s[i] == 'B') {
if (ans.length() > 0) {
ans.erase(ans.length() - 1 , 1);
}
}
else {
ans += s[i];
}
}
cout << ans << endl;
} | 0 | 71,800,780 |
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
int a[n];
for (int i = 0; i < (n); ++i)
cin >> a[i];
int ans[n];
for (int i = 0; i < (n); ++i)
ans[a[i]-1] = i+1;
for (int i = 0; i < (n); ++i)
cout << ans[i] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main()
{
string s, t;
cin >> s >> t;
bool ans = true;
for (int i = 0; i < s.length(); i++)
{
if (s.at(i) != t.at(i))
{
ans = false;
}
}
if (ans)
{
cout << "Yes" << endl;
}
else
{
cout << "No" << endl;
}
return 0;
} | 0 | 5,972,211 |
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#define INF 9999999
using namespace std;
int a[100000+5];
vector<int> line[500];
int main(){
int n;
scanf("%d",&n);
int k=floor(sqrt(2*n)+0.5);
if(k*(k+1)==2*n){
int cnt=k+1;
int t=1;
for(int i=1;i<cnt;i++){
int s=i*(i-1)/2+1;
for(int j=0;j<i;j++)line[j].push_back(s++);
for(int j=0;j<i;j++)line[i].push_back(--s);
}
printf("Yes\n%d\n",cnt);
for(int i=0;i<cnt;i++){
printf("%d",line[i].size());
for(int j=0;j<line[i].size();j++)
printf(" %d",line[i][j]);
printf("\n");
}
}else{
printf("No\n");
}
} | #include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>
using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x)
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0)
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T iabs(const T& x) { return max(x, -x); }
int main() {
i64 h, w;
cin >> h >> w;
i64 ans = 1e9;
for (int k = 0; k < 2; ++k) {
for (int i = 1; i < h; ++i) {
i64 a = i * w;
i64 g = h - i;
{
i64 b = g / 2 * w, c = (g - g / 2) * w;
if (b != 0 && c != 0) {
ans = min(ans, max({a, b, c}) - min({a, b, c}));
}
}
{
i64 b = w / 2 * g, c = (w - w / 2) * g;
if (b != 0 && c != 0) {
ans = min(ans, max({a, b, c}) - min({a, b, c}));
}
}
}
swap(h, w);
}
cout << ans << endl;
return 0;
} | 0 | 84,739,932 |
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, k, gcdv, maxv = 0, minv = 1e9 + 7;
cin >> n >> k;
rep(i, 0, n) {
int a;
cin >> a;
chmax(maxv, a);
chmin(minv, a);
if (i == 0)
gcdv = a;
else
gcdv = __gcd(gcdv, a);
}
if (k % gcdv == 0 && k >= minv && k <= maxv)
cout << "POSSIBLE" << endl;
else
cout << "IMPOSSIBLE" << endl;
} | #include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
#define all(x) x.begin(),x.end()
#define pb push_back
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define sll set<ll>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define endl "\n"
const ll maxn = 2e5+2;
ll flag[1000002];
int main()
{
fastio;
ll i, j, k, n, m, t;
vll a;
memset(flag,0,sizeof(flag));
cin>>n;
for ( i = 0; i < n; i++)
{
cin>>j;
a.pb(j);
}
sort(all(a));
for ( i = 0; i < n-1; i++)
{
if(a[i]==a[i+1])
flag[a[i]]=1;
}
ll maxi=*max_element(all(a));
for ( i = 0; i < n; i++)
{
for ( j = 2*a[i]; j<= maxi ; j+=a[i])
{
flag[j]=1;
}
}
ll c=0;
a.clear();
for ( i = 0; i < n; i++)
{
if(flag[a[i]]==0)
c++;
}
cout<<c<<endl;
return 0;
} | 0 | 65,210,526 |
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i,a,n)for(int (i) = (a);i<(n);i++)
#define INF 1e9
using namespace std;
int main(){
using i64 = long long;
#define int long long
int N;
cin >> N;
vector<int> num;
num.push_back(1);
num.push_back(2);
num.pop_back();
for(int i =2;i<=N;i++){
num.push_back(i);
num.pop_back();
if(num[i-2]+i>N)break;
num.push_back(num[i - 2] + i);
}
num.push_back(num[num.size()-1]+num.size()+1);
int MAX = num.size();
if(num[num.size()-2]==N)MAX--;
if(num[num.size() - 2] == N) num.pop_back();
for(int i = MAX;N>0;i--){
if(i > N) continue;
int ei1333 =1333;
break;
return 0;
}
for(int i = MAX;N>0;i--){
if(i > N) continue;
int ei1333 = 1333;
cout<<i<<endl;
N -= i;
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;
template<class TYPE>
struct edge{
TYPE to,cost;
edge(TYPE t,TYPE c){
to = t;
cost = c;
}
};
int main(){
int N;
cin >> N;
int C[N];
int S[N];
int F[N];
for(int i = 1; i < N; i++){
cin >> C[i] >> S[i] >> F[i];
}
vector<int> ans;
for(int i = 1; i < N; i++){
int time = S[i] + C[i];
for(int j = i+1; j < N; j++){
time = max(time,S[j]);
int n = (time-1)/F[j] + 1 - S[j] / F[j] + 1;
time = S[j] + F[j]*(n - 1) + C[j];
}
ans.emplace_back(time);
}
ans.emplace_back(0);
for(int num : ans) cout << num << endl;
return 0;
} | 0 | 9,382,039 |
#include <bits/stdc++.h>
#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
using namespace std;
typedef long long ll;
int main()
{
ll N;
cin >> N;
vector<ll> A(N);
REP(i, N)
{
cin >> A[i];
}
sort(ALL(A));
vector<ll> sumA(N);
sumA[0] = A[0];
REP(i, N - 1)
{
sumA[i + 1] = sumA[i] + A[i + 1];
}
ll ans = 1;
REP(i, N - 1)
{
if (A[N - 1 - i] <= 2 * sumA[N - 2 - i])
{
ans++;
}
else
{
break;
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#include <iostream>
#define ll long long
#define map unordered_map
#define set unordered_set
#define pll pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>
using namespace std;
const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);
const int MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];
void init_com() {
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 - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
ll com(int n, int k) {
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll indices[100005];
int main() {
fill_n(indices, 100005, -1);
init_com();
ll N;
scanf("%lld", &N);
ll same_index1 = -1;
ll same_index2 = -1;
vector<ll> list;
for (ll i = 0; i < N + 1; i++) {
ll v;
scanf("%lld", &v);
list.emplace_back(v);
if (indices[v] >= 0) {
same_index1 = indices[v];
same_index2 = i;
}
indices[v] = i;
}
ll rest1 = same_index1;
ll rest2 = N - same_index2;
ll rest = rest1 + rest2;
for (ll i = 1; i <= N + 1; i++) {
ll count_all = com(N + 1, i);
ll dup = com(rest, i - 1);
ll ans = ((count_all - dup) + MOD) % MOD;
cout << ans << endl;
}
} | 0 | 12,323,735 |
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
int main(){
ll n;
cin >> n;
ll ans = 0;
for(ll i=1;i*i<=n;i++){
if(n%i==0 && (n/i)-1 > i){
ans += n/i - 1;
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i,n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
template<class T>bool chmax(T &a,const T &b) {if(a<b){a=b; return 1;} return 0;}
template<class T>bool chmin(T &a,const T &b) {if(b<a){a=b; return 1;} return 0;}
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
int main() {
IOS;
int n; cin >> n;
vector<int> a(n);
REP(i,n) cin >> a[i];
ll ans=0;
int sum=0,r=0;
REP(l,n) {
while(r < n) {
if ((sum^a[r]) != (sum+a[r])) break;
sum += a[r];
r++;
}
ans += r - l;
if (r == l) r++;
sum -= a[l];
}
COUT(ans);
return 0;
} | 0 | 82,415,046 |
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;
ll A[1010], B[1010], C[1010];
int main()
{
int X, Y, Z, K;
cin >> X >> Y >> Z >> K;
for (int i = 0; i < X; i++) cin >> A[i];
for (int i = 0; i < Y; i++) cin >> B[i];
for (int i = 0; i < Z; i++) cin >> C[i];
sort(A, A + X, greater<ll>());
sort(B, B + Y, greater<ll>());
sort(C, C + Z, greater<ll>());
vector<ll> V;
for (int i = 0; i < X; i++) {
for (int j = 0; j < Y; j++) {
V.push_back(A[i] + B[j]);
}
}
sort(V.begin(), V.end(), greater<ll>());
vector<ll> ans;
for (int i = 0; i < min((int)V.size(), K); i++) {
for (int j = 0; j < Z; j++) {
ans.push_back(V[i] + C[j]);
}
}
sort(ans.begin(), ans.end(), greater<ll>());
for (int i = 0; i < K; i++) {
cout << ans[i] << endl;
}
} | #include<iostream>
using namespace std;
int main(){
int turi;
int hara;
int count;
while(1){
count=0;
cin>>hara;
if(hara==0) break;
turi=1000-hara;
while(turi!=0){
if(turi>=500){
turi=turi-500;
count++;
}
else if(turi>=100){
turi=turi-100;
count++;
}
else if(turi>=50){
turi=turi-50;
count++;
}
else if(turi>=10){
turi=turi-10;
count++;
}
else if(turi>=5){
turi=turi-5;
count++;
}
else if(turi>=1){
turi=turi-1;
count++;
}
}
cout<<count<<endl;
}
} | 0 | 18,245,202 |
#include<bits/stdc++.h>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define rrep(i,a) for(int i=(int)a-1;i>=0;--i)
#define REP(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RREP(i,a,b) for(int i=(int)a-1;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
typedef std::vector<int> vi;
typedef std::vector<std::vector<int>> vvi;
typedef std::vector<long long> vl;
typedef std::vector<std::vector<long long>> vvl;
#define out(x) cout<<x<<"\n";
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
ll gcd(ll n, ll m) {
ll tmp;
while (m!=0) {
tmp = n % m;
n = m;
m = tmp;
}
return n;
}
ll lcm(ll n, ll m) {
return abs(n) / gcd(n, m)*abs(m);
}
using namespace std;
void solve()
{
int n;
cin >> n;
vector<ll> a(n);
rep(i, n) cin >> a[i];
ll cur = 1;
ll ans = 0;
rep(i, n)
{
ans += (a[i] - 1) / cur;
if(i==0)
++cur;
else if (a[i] == cur)
++cur;
}
cout << ans << "\n";
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout<<fixed<<setprecision(15);
solve();
return 0;
} | #include <iostream>
#include <queue>
#include <vector>
using namespace std;
#define MAXN 100
struct Matrix {int r, c; };
int main(){
int n; cin >> n;
struct Matrix M[MAXN];
for(int i=0; i<n; ++i){
cin >> M[i].r >> M[i].c;
}
int dp[MAXN+1][MAXN];
for(int i=0; i<n; ++i){
dp[1][i] = 0;
}
for(int m=2; m<=n; ++m){
for(int i=0; i<=n-m; ++i){
priority_queue<int, vector<int>, greater<int> > pq;
for(int j=1; j<m; ++j){
int x = dp[j][i] + dp[m-j][i+j] + M[i].r*M[i+j].r*M[m+i-1].c;
pq.push(x);
}
dp[m][i] = pq.top();
}
}
cout << dp[n][0] << endl;
} | 0 | 99,827,606 |
#include "bits/stdc++.h"
#include "math.h"
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) int((a).size())
#define out(a) cout<<(a)<<endl;
const int INF=INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;
ll fac[MAX], finv[MAX], inv[MAX];
int main(){
ll n;cin>>n;
vll h(n);
rep(i,0,n){
cin>>h[i];
}
ll ans=h[0];
rep(i,1,n){
if(h[i]>h[i-1]){
ans+=h[i]-h[i-1];
}
}
cout<<ans<<endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v) \
cout << #v << ":"; \
for (auto x : v) \
{ \
cout << x << ' '; \
} \
cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
if (a < b)
{
a = b;
return 1;
}
return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
if (b < a)
{
a = b;
return 1;
}
return 0;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
char s;
string ans="aiueo";
cin>>s;
rep(i,5){
if(s==ans[i]){
cout<<"vowel"<<"\n";
return 0;
}
}
cout<<"consonant"<<"\n";
} | 0 | 97,224,832 |
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int MOD = 1000000007;
const int INF = 1e11;
using Graph = vector<vector<int>>;
signed main(){
int N, X, M;
cin >> N >> X >> M;
vector<int> kou;
set<int> num;
kou.push_back(X);
num.insert(X);
int ans = 0;
for( int i = 1; i < N; i++ ){
int A = kou[i-1]*kou[i-1];
A %= M;
int ichi = 0;
if( num.count(A) ){
for( int j = 0; j < kou.size(); j++ ){
if( kou[j] == A ){
ichi = j;
break;
}
ans += kou[j];
}
int roop = 0;
for( int j = ichi; j < kou.size(); j++ ){
roop += kou[j];
}
ans += (N-ichi)/(kou.size()-ichi)*roop;
int amari = (N-ichi)%(kou.size()-ichi);
for( int j = ichi; j < ichi+amari; j++ ) ans += kou[j];
cout << ans << endl;
return 0;
}else{
num.insert(A);
kou.push_back(A);
}
}
for( int i = 0; i < kou.size(); i++ ) ans += kou[i];
cout << ans << endl;
} | #include <bits/stdc++.h>
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
#ifdef DEBUG
#define dump(...) fprintf(stderr, __VA_ARGS__)
#else
#define dump(...)
#endif
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
int main(void){
cin.tie(0);
ios::sync_with_stdio(false);
int D; cin >> D;
string res = "Christmas";
rep(_, 25 - D){
res += " Eve";
}
cout << res << endl;
return 0;
} | 0 | 22,893,759 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N,D;
cin >> N >> D;
vector<vector<int>> X(N, vector<int>(D));
for(int i=0; i<N; i++){
for(int j=0; j<D; j++){
cin >> X.at(i).at(j);
}
}
int ans=0;
for(int i=0; i<N; i++){
for(int j=i+1; j<N; j++){
int norm = 0;
for(int k=0; k<D; k++){
int diff = X.at(i).at(k) - X.at(j).at(k);
norm += diff * diff;
}
for(int k=0; k <= norm; k++){
if(k*k == norm){
ans++;
}
}
}
}
cout << ans << endl;
} | # include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
typedef pair<LL, LL> P;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x) (x).begin(),(x).end()
# define UNIQ(c) (c).erase(unique(ALL((c))),(c).end())
# define mp make_pair
# define eb emplace_back
# define FOR(i,a,b) for(int i=(a);i<(b);i++)
# define RFOR(i,a,b) for(int i=(a);i>=(b);i--)
# define REP(i,n) FOR(i,0,n)
# define INIT std::ios::sync_with_stdio(false);std::cin.tie(0)
LL n, a, b;
int main() {
cin >> n >> a >> b;
if (a + b > n + 1) {
cout << -1 << endl;
return 0;
}
if (a*b < n) {
cout << -1 << endl;
return 0;
}
for (int i = a - 1; i >= 0; i--) {
cout << n - i << " ";
}
n -= a;
LL num = b;
--b;
for (int i = 1; i < num; i++) {
LL cur = n - b + 1;
cur = min(cur, a);
for (int j = cur - 1; j >= 0; j--) {
cout << n - j << " ";
}
n -= cur;
--b;
}
cout << endl;
} | 0 | 38,037,194 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int MOD = 1000000007;
const int INF = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};
int main(){
int n, k;
cin >> n >> k;
string s;
cin >> s;
int now = 1;
int cnt = 0;
vector<int> num;
rep(i,n){
if(now==s[i]-'0') cnt++;
else{
num.push_back(cnt);
cnt = 1;
now = 1 - now;
}
}
num.push_back(cnt);
if(num.size()%2==0) num.push_back(0);
vector<int> sum(num.size()+1);
sum[0] = 0;
rep(i, num.size()){
sum[i+1] = sum[i] + num[i];
}
int tmp = 0;
int add = 2*k+1;
int ans = 0;
for(int i = 0; i < num.size(); i+=2){
int left = i;
int right = min(i+add, (int)num.size());
tmp = sum[right] - sum[left];
chmax(ans, tmp);
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#include <chrono>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep2l(i, s, n) for (ll i = (ll)(s); i < (ll)n; i++)
int main() {
int n;
cin >> n;
vector<int> ans(26, 0);
int count = 1;
while (count <= n) {
string S;
cin >> S;
if (count == 1) {
rep(i, S.size()) {
ans[(int)(S[i]-'a')]++;
}
count++;
continue;
}
vector<int> res(26, 0);
rep(i, S.size()) {
res[(int)(S[i]-'a')]++;
}
rep(i, 26) {
ans[i] = min(ans[i], res[i]);
}
count++;
}
string answer;
rep(i, 26) {
rep(j, ans[i]) {
answer += (char)('a' + i);
}
}
cout << answer << endl;
} | 0 | 50,257,909 |
#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1001001001
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define double long double
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll a,b,c,d,m,n,maxi=0,f=0,mini=INF,sum=0;
string str;
cin>>a>>b>>c>>d>>n;
a*=4;
b*=2;
mini=min(a,b);
mini=min(mini,c);
if(mini*2>d&&n!=1){
sum=n/2*d;
if(n%2) sum+=mini;
}else{
sum=n*mini;
}
cout<<sum<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
char a, b;
cin >> a >> b;
bool ans;
if (a == 'H') {
if (b == 'H') ans = true;
else ans = false;
} else {
if (b == 'H') ans = false;
else ans = true;
}
cout << (ans ? "H" : "D") << endl;
return 0;
} | 0 | 5,046,908 |
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
#include <stack>
#include <iomanip>
#include <limits>
using namespace std;
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
typedef priority_queue<ll> PQ_HIGH;
typedef priority_queue<ll,VL,greater<ll>> PQ_LOW;
int main(){
ll n,k;cin>>n>>k;
vector<char> past(n,'0');
int R,S,P;
cin>>R>>S>>P;
string s;cin>>s;
ll ans=0;
for(int i=0;i<n;i++){
if(i>=k){
if(past[i-k]==s[i]){
continue;
}
}
if(s[i]=='r'){
past[i]='r';
ans+=P;
}else if(s[i]=='s'){
past[i]='s';
ans+=R;
}else if(s[i]=='p'){
past[i]='p';
ans+=S;
}
}
cout<<ans<<endl;
} | #include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int lcs(string s, string t){
int a[s.size()+1][t.size()+1];
for(int i=0;i<s.size()+1;i++) a[i][0]=0;
for(int i=0;i<t.size()+1;i++) a[0][i]=0;
for(int i=1;i<s.size()+1;i++){
for(int j=1;j<t.size()+1;j++){
if(s[i-1]==t[j-1]) a[i][j] = a[i-1][j-1]+1;
else a[i][j] = max(a[i-1][j], a[i][j-1]);
}
}
return a[s.size()][t.size()];
}
int main(){
string s,t;
int n;
cin>>n;
for(int i=0;i<n;i++){
cin>>s>>t;
cout<<lcs(s,t)<<endl;
}
return 0;
} | 0 | 35,370,307 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
int main() {
int n;
cin >> n;
std::vector<int> p(n), q(n);
rep(i,n) cin >> p.at(i);
rep(i,n) cin >> q.at(i);
std::vector<int> a(n);
rep(i,n) a.at(i) = i+1;
map<std::vector<int>, int> mp;
do {
mp[a] = mp.size();
} while (next_permutation(a.begin(), a.end()));
int ans = abs(mp[p] - mp[q]);
cout << ans << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
if(a.first != b.first){
return a.first < b.first;
}else{
return a.second < b.second;
}
}
bool In_map(ll y,ll x,ll h,ll w){
if(y<0 || x<0 || y>=h || x>=w){
return 0;
}else{
return 1;
}
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};
int main() {
ll N;
string S,T;
cin >>S>>T;
N=S.size();
if(S==T){
cout<<"Yes"<<endl;
return 0;
}
rep(i,N){
S = S[N-1]+S.substr(0,N-1);
if(S==T){
cout<<"Yes"<<endl;
return 0;
}
}
cout <<"No" << endl;
return 0;
} | 0 | 83,982,206 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string S, T;
cin >> S >> T;
if(T.size() != S.size()+1) cout << "No" << endl;
else {
for(int i = 0; i < S.size(); i++) {
if(S.at(i) != T.at(i)) {
cout << "No" << endl;
break;
}
else {
if(i == S.size() -1) cout << "Yes" << endl;
else continue;
}
}
}
} | #include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long
const int MOD = 1000000007;
const int IINF = INT_MAX;
const ll INF = 1LL << 60;
int main() {
int n, m, x, y; cin >> n >> m >> x >> y;
V<int> vx(n);
for(int i = 0; i < n; i++) cin >> vx[i];
V<int> vy(m);
for(int i = 0; i < m; i++) cin >> vy[i];
vx.push_back(x);
vy.push_back(y);
int xmax = *max_element(ALL(vx));
int ymix = *min_element(ALL(vy));
if(xmax < ymix){
cout << "No War" << endl;
}else{
cout << "War" << endl;
}
return 0;
} | 0 | 90,664,514 |
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) {
cout << (expr ? "Yes" : "No") << "\n";
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
lint N, M, V, P;
cin >> N >> M >> V >> P;
vector<lint> A(N);
REP(i, N) cin >> A[i];
sort(ALL(A), greater<lint>());
vector<lint> S(N+1);
REP(i, N) S[i+1] = S[i] + A[i];
int l = -1;
int r = N;
while(r-l > 1) {
lint m = (l+r) / 2;
if(A[P-1] > A[m]+M) {
r = m;
continue;
}
lint area = 0;
REP(i, N) {
if(i < P-1 || i >= m) {
area += M;
} else {
area += A[m]+M-A[i];
}
}
if(area >= M*V) {
l = m;
} else {
r = m;
}
}
cout << l+1 << endl;
} | #include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
int main(){
ll h,w,n;
cin>>h>>w>>n;
map<pair<ll,ll>,int> m;
rep(i,n){
int y,x;cin>>y>>x;
range(j,0,3)range(k,0,3){
if(3<=y+j&&y+j<=h&&3<=x+k&&x+k<=w){
auto p=mp(y+j,x+k);
if(m.find(p)==m.end()){
m[p]=0;
}
m[p]++;
}
}
}
vector<ll> a(10,0);
ll total=0;
for(auto p:m){
a[p.second]++;
total++;
}
a[0]=(h-2)*(w-2)-total;
for(auto i:a)cout<<i<<endl;
return 0;
} | 0 | 18,196,723 |
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
ll x,y;cin>>x>>y;
if(x%y==0)cout<<-1<<endl;
else cout<<x*(y-1)<<endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e12);
const ll mod = ll(1e9) + 1;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()
ll gcd(ll a,ll b){
if(a < b)swap(a, b);
if(b == 0) return a;
return gcd(b,a%b);
}
ll lcm(ll a,ll b){
ll g = gcd(a,b);
return a / g * b;
}
ll factorial(ll n){
ll t = 1;
rep1(i, n){
t *= i;
t %= mod;
}
return t;
}
ll power(ll a, ll b){
a %= mod;
if(b == 0){
return 1;
}
ll ans = power(a, b / 2);
ans = ans * ans % mod;
if(b % 2 == 1){
ans = ans * a % mod;
}
return ans;
}
ll combination(ll a, ll b){
if((a == b) || (b == 0)){
return 1;
}
if(a < b) return 0;
ll ans = 1;
for(ll i = 0; i < b; i++) {
ans *= (a - i);
ans %= mod;
ans *= power(i + 1, mod - 2);
ans %= mod;
}
return ans;
}
int main(){
ll n,ans = 0,cnt = 0;
cin >> n;
rep0(i, n){
ll a;
cin >> a;
cnt += a;
if(a == 0){
ans += cnt / 2;
cnt = 0;
}
}
pf(ans + cnt / 2);
return 0;
} | 0 | 16,901,073 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,c=0;
cin>>a>>b;
c=a-b;
++c;
cout<<c;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n;
ll ans;
int main() {
cin.sync_with_stdio(0); cin.tie(0);
cin >> n;
vector<ll> a(n);
for (auto& i : a) cin >> i;
for (int i = 0; i < n; i++) {
if (!a[i]) continue;
if (i < n - 1) {
if (a[i] % 2 && a[i + 1]) {
--a[i], --a[i + 1];
ans += 1;
}
}
}
for (int i = 0; i < n; i++) {
ans += a[i] / 2;
}
cout << ans;
} | 0 | 15,103,750 |
#include<bits/stdc++.h>
using namespace std;
bool pal(string s)
{
string r;
r=s;
reverse(s.begin(),s.end());
return s==r;
}
int main()
{
string s,a,d;
int i,n;
cin>>s;
n=s.size();
if(pal(s))
{
a=s.substr(0,(n-1)/2);
d=s.substr(((n+3)/2)-1,n-((n+3)/2)+1);
if(pal(a)&&pal(d))
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
else
cout<<"No"<<endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;
int main(){
int k,s;
cin>>k>>s;
int ans=0;
for(int x=0;x<=k;x++){
for(int y=0;y<=k;y++){
int z=s-(x+y);
if(0<=z && z<=k) ans++;
}
}
cout<<ans<<endl;
} | 0 | 30,786,531 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x;
cin>>x;
cout<<10-x/200;
} | #pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif
void d_err() {
cerr << endl;
}
template <typename H, typename... T>
void d_err(H h, T... t) {
cerr << h << " ";
d_err(t...);
}
template <typename T>
void print(T x) {
cout << x << endl;
}
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;
ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;
int main(){
cin.tie(0);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(20);
int N, M;
cin >> N >> M;
vector<vector<ll>> v(N);
vector<int> P(M), Y(M);
REP(i, M) {
cin >> P[i] >> Y[i];
v[P[i] - 1].pb(Y[i]);
}
REP(i, N) {
sort(ALL(v[i]));
}
#define out cout << setfill('0') << right << setw(6)
REP(i, M) {
out << P[i];
int o = lower_bound(ALL(v[P[i] - 1]), Y[i]) - v[P[i] - 1].begin() + 1;
out << o << endl;
}
} | 0 | 75,724,892 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
int h, w;
cin >> h >> w;
string in[100];
for (int i = 0; i < h; ++i)
{
cin >> in[i];
}
for (int i = 0; i < h * 2; ++i)
{
cout << in[i/2] << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
int C[N-1],S[N-1],F[N-1];
for (int i=0; i<N-1; i++) {
cin >> C[i] >> S[i] >> F[i];
}
for (int i=0; i<N-1; i++) {
int t=S[i];
for (int j=i; j<N-1; j++) {
if (t<S[j]) t=S[j];
while (t%F[j]!=0) {
t++;
}
t+=C[j];
}
cout << t << endl;
}
cout << 0 << endl;
} | 0 | 39,065,193 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int h1,m1,h2,m2,k; cin >> h1 >> m1 >> h2 >> m2 >> k;
int ans = (60*h2+m2) - (60*h1+m1) -k;
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main(void){
long long N;cin>>N;
long long A[N],B[N-1];
for(long long i=0;i<N-1;i++){
cin>>B[i];
}
A[0]=B[0];
for(long long i=1;i<N;i++){
if(i==N-1){
A[i]=B[i-1];
}
else{
A[i]=min(B[i],B[i-1]);
}
}
long long ans=0;
for(long long i=0;i<N;i++){
ans+=A[i];
}
cout<<ans<<endl;
return 0;
} | 0 | 97,682,038 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
string o,e;
cin >> o;
cin >> e;
for (int i = 0; i < e.length(); i++)
{
cout << o.at(i);
cout << e.at(i);
}
if(o.length()-e.length()==1) cout << o.at(o.length()-1);
cout << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define MAX 100
int INFTY = (1<<21);
int num,M[MAX][MAX];
int d[MAX];
void bfs(int s){
queue<int> q;
q.push(s);
int u,i,v;
for( i = 0; i < num; i++){
d[i] = INFTY;
}
d[s] = 0;
while( !q.empty()){
u = q.front();
q.pop();
for(v = 0; v < num; v++){
if( M[u][v] == 0){
continue;
}
if( d[v] != INFTY){
continue;
}
d[v] = d[u]+1;
q.push(v);
}
}
for(i = 0; i < num; i++){
cout << i+1 << " " << ( (d[i] == INFTY) ? (-1) : d[i] ) << endl;
}
}
int main(){
int u,k,v,i,j;
cin >> num;
for(i = 0; i < num; i++){
for(j = 0; j < num; j++){
M[i][j] = 0;
}
}
for(i = 0; i < num; i++){
cin >> u >> k;;
u--;
for(j = 0; j < k; j++){
cin >> v;
v--;
M[u][v] = 1;
}
}
bfs(0);
return 0;
} | 0 | 98,962,999 |
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
int main(){
INT(n,q);
vector<vector<int>> tree(n);
int x,y,a;
rep(i,n-1){
in(x,y);
tree[x-1].push_back(y-1);
tree[y-1].push_back(x-1);
}
map<int,ll> map1;
rep(i,q){
in(x,y);
if(map1.count(x-1)){
map1[x-1]+=(ll)y;
}else{
map1[x-1]=(ll)y;
}
}
vector<ll> ans(n,-1);
queue<int> next;
next.push(0);
ans[0]=0;
while(!next.empty()){
a=next.front();
next.pop();
if(map1.count(a)){
ans[a]+=(ll)map1[a];
}
if(tree[a].size()==0)continue;
rep(i,tree[a].size()){
if(ans[tree[a][i]]==-1){
ans[tree[a][i]]=ans[a];
next.push(tree[a][i]);
}
}
}
out(ans);
} | #include <bits/stdc++.h>
using namespace std;
using ll= long long;
#define double long double
#define sz(x) (int)x.size()
#define all(x) (x).begin(),(x).end()
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _set(x) __builtin_popcount(x)
#define PI 3.14159265358979323846264338327950L
#define mod 1000000007
#define dpv(...) cerr<< "["#__VA_ARGS__ " : ";for(int i: (__VA_ARGS__)){cerr<<i<<" ";}cerr<<"]\n"
const int maxN= 105;
const int INF = 1e9;
int dp[maxN][maxN];
bool g[maxN][maxN];
void solve(){
int h,w;
cin>>h>>w;
char c;
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
cin>>c;
g[i][j]=(c=='#')?0:1;
dp[i][j]= INF;
}
}
dp[0][0]= g[0][0]?0:1;
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
dp[i+1][j] = min(dp[i+1][j],(g[i][j] && !g[i+1][j])? dp[i][j]+1: dp[i][j] );
dp[i][j+1] = min(dp[i][j+1],(g[i][j] && !g[i][j+1])? dp[i][j]+1: dp[i][j] );
}
}
cout<<dp[h-1][w-1]<<"\n";
}
int32_t main(){
IOS
int _;
_=1;
while(_--){
solve();
}
return 0;
} | 0 | 40,518,787 |
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)
int main() {
string s;
cin >> s;
vector<int> id;
rep(i, s.size()) {
if (s[i] != 'x') {
id.push_back(i);
}
}
if (id.size() == 0) {
cout << 0 << endl;
return 0;
}
queue<char> q1, q2;
if (id.size() % 2 != 0) {
int M = id.size() / 2;
rrep(i, id[M]) { q1.push(s[i]); }
for (int i = id[M] + 1; i < s.size(); i++) {
q2.push(s[i]);
}
} else {
int M = id.size() / 2;
for (int i = id[M - 1]; i >= 0; i--) {
q1.push(s[i]);
}
for (int i = id[M]; i < s.size(); i++) {
q2.push(s[i]);
}
}
q1.push('$');
q2.push('$');
int result = 0;
while (!q1.empty() || !q2.empty()) {
if (q1.front() == q2.front()) {
q1.pop();
q2.pop();
} else if (q1.front() == 'x') {
q1.pop();
result++;
} else if (q2.front() == 'x') {
q2.pop();
result++;
} else {
cout << -1 << endl;
return 0;
}
}
cout << result << endl;
return 0;
} | #include <iostream>
using namespace std;
int main()
{
int n,m,p,i,s,a[100];
for(;;){
cin >> n >> m >> p;
if(n==0 && m==0 && p==0) break;
s = 0;
for(i=0;i<n;i++){
cin >> a[i];
s += a[i];
}
if(a[m-1] == 0) cout << "0" << endl;
else{
s = s * (100 - p);
cout << s / a[m-1] << endl;
}
}
return 0;
} | 0 | 80,762,837 |
#include"bits/stdc++.h"
#include <sstream>
using namespace std;
#define rpt0(i, n) for(ll i = 0; i < (n); i++)
#define rpt1(i, n) for(ll i = 1; i <= (n); i++)
#define rptb0(i ,n) for(ll i = (n) - 1; i >= 0; --i)
#define rptb1(i ,n) for(ll i = (n); i >= 1; --i)
#define pb push_back
#define all(v) v.begin(),v.end()
#define PI (acos(-1))
typedef long long ll;
typedef long double ld;
typedef vector<int> vint;
typedef vector<double> vdouble;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pair<ll, ll>> vl_l;
typedef vector<pair<int, int>> vi_i;
typedef vector<pair<double, double>> vd_d;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
typedef pair<double, double> d_d;
template <typename T>
void read(T& x) {
cin >> x;
}
template <typename T, typename T0>
void read(T& x, T0& y) {
cin >> x >> y;
}
template <typename T, typename T0, typename T1>
void read(T& x, T0& y, T1& z) {
cin >> x >> y >> z;
}
template <typename T, typename T0, typename T1, typename T2>
void read(T& x, T0& y, T1& z, T2& w) {
cin >> x >> y >> z >> w;
}
template <typename T>
void read(vector< T >& oneD, int n) {
ll n1 = (ll)n;
rpt0(i, n1)
{
ll x;
read(x);
oneD.push_back(x);
}
}
template <typename T>
void read(vector< T >& oneD, ll n) {
rpt0(i, n)
{
ll x;
read(x);
oneD.push_back(x);
}
}
template <typename T>
void read(T oneD[], int n) {
ll n1 = (ll)n;
rpt1(i, n1) {
read(oneD[i]);
}
}
template <typename T>
void read(T oneD[], ll n) {
rpt1(i, n) {
read(oneD[i]);
}
}
template <typename T, typename T0>
void read(pair< T, T0 >& p) {
cin >> p.first >> p.second;
}
template <typename T>
void write(T& x) {
cout << x << endl;
}
template <typename T, typename T0>
void write(T& x, T0& y) {
cout << x << " " << y << "\n";
}
template <typename T, typename T0, typename T1>
void write(T& x, T0& y, T1& z) {
cout << x << " " << y << " " << z << "\n";
}
template <typename T, typename T0, typename T1, typename T2>
void write(T& x, T0& y, T1& z, T2& w) {
cout << x << " " << y << " " << z << " " << w << "\n";
}
template <typename T>
void write(vector< T >& oneD, int n) {
ll n1 = (ll)n;
rpt0(i, n1) {
cout << oneD[i] << " ";
}
cout << endl;
}
template <typename T>
void write(vector< T >& oneD, ll n) {
rpt0(i, n) {
cout << oneD[i] << " ";
}
cout << endl;
}
template <typename T>
void write(T oneD[], int n) {
ll n1 = (ll)n;
rpt1(i, n1) {
write(oneD[i]);
}
cout << endl;
}
template <typename T>
void write(T oneD[], ll n) {
rpt1(i, n) {
write(oneD[i]);
}
cout << endl;
}
template <typename T, typename T0>
void write(pair< T, T0 >& p) {
cout << p.first << " " << p.second << " ";
cout << endl;
}
bool cmp(i_i a, i_i b) {
return a.first < b.first;
}
int main(void) {
int n; read(n);
vi_i r; r.resize(n);
for (int i = 0; i < n; i++) {
cin >> r[i].first >> r[i].second;
}
vi_i b; b.resize(n);
for (int i = 0; i < n; i++) {
cin >> b[i].first >> b[i].second;
}
sort(all(r), cmp); sort(all(b), cmp);
int ans = 0;
vi_i reg;
for (int i = 0; i < n; i++) {
reg.clear();
for (int j = 0; j < n; j++) {
if (r[j].first < b[i].first && r[j].second < b[i].second) {
reg.push_back(r[j]);
}
}
if (reg.empty() != true) {
int idx = -1;
int max = -1;
for (int k = 0; k < reg.size(); k++) {
if (max < reg[k].second) {
idx = k;
max = reg[k].second;
}
}
if (idx != -1) {
ans++;
auto itr = find(all(r), reg[idx]);
i_i pmax(10000, 10000);
*itr = pmax;
}
}
}
write(ans);
return 0;
} | #include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define endl "\n"
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define PI 3.1415926535897932384626433832795
#define F first
#define S second
#define V vector<ll>
#define ALL(sss) sss.begin(),sss.end()
#define arall(rr,n) rr+0,rr+n
#define mod 1000000007
#define M 100
#define MAXN 1000000000
int dp[262145][2];
int ans=INT_MAX;
ll n;
using namespace std;
void fileio(){
#ifndef ONLINE_JUDGE
freopen("input.in", "r", stdin);
freopen("output.out", "w", stdout);
#endif
}
int main(){
fileio();
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll T=1,q;
while(T--){
ll n,k;cin>>n>>k;
ll a[n];
for (int i = 0; i < n; ++i)
{
cin>>a[i];
}
vector<ll> dp(n+1,INT_MAX);
dp[0]=0;dp[1]=abs(a[1]-a[0]);
for (ll i = 2; i <= n; ++i)
{
for(ll j=1;j<=min(k,i);j++){
dp[i]=min(dp[i-j]+abs(a[i-j]-a[i]),dp[i]);
}
}
cout<<dp[n-1];
}
return 0;
} | 0 | 93,828,755 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353
int main() {
string S; cin >> S;
int ans = 0;
while(S != "") {
S = S.substr(0, S.size() - 2);
string left = S.substr(0, S.size() / 2 - 1);
string right = S.substr(S.size() / 2, S.size() / 2 - 1);
if(left == right) {
ans = S.size();
break;
}
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <vector>
#include <functional>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;
int main(){
int n; cin >> n;
string s; cin >> s;
int fi=0,fj=0,fk=0;
int count=0;
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++)
{
for (int k = 0; k < 10; k++)
{
fi = s.find(to_string(i),0);
if(fi != string::npos){
fj = s.find(to_string(j),fi+1);
if(fj != string::npos){
fk = s.find(to_string(k),fj+1);
if(fk != string::npos){
count++;
}
}
}
}
}
}
cout << count << endl;
return 0;
} | 0 | 95,074,162 |
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
const int N = 1e6+50;
int n, l, q, x[N];
int f[21][N];
int main() {
scanf("%d", &n);
REP(i,1,n) scanf("%d",x+i);
scanf("%d%d", &l, &q);
int now = n;
PER(i,1,n) {
while (x[now]-x[i]>l) --now;
f[0][i] = now;
REP(j,1,20) f[j][i]=f[j-1][f[j-1][i]];
}
REP(i,1,q) {
int x, y;
scanf("%d%d", &x, &y);
if (x>y) swap(x,y);
int ans = 0;
PER(i,0,20) if (f[i][x]<y) {
x = f[i][x];
ans ^= 1<<i;
}
printf("%d\n", ans+1);
}
} | #include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
for (auto i = first;i != last;i++){
cin >> (*i);
}
}
template<class itr> void array_output(itr start,itr goal){
string ans = "",k = " ";
for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
if (!ans.empty()) ans.pop_back();
PRINT(ans);
}
ll gcd(ll a, ll b) {
return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 100000000;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
const ll MAX = 200010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll h,w,d;
cin >> h >> w >> d;
vector<P> place(h*w+1);
ll a;
rep(i,h){
rep(j,w){
cin >> a;
place[a] = P(i,j);
}
}
vector<vector<ll>> power(d);
rep(i,d) power[i].push_back(0);
rep(i,d,h*w+1){
ll x,y,nx,ny;
tie(x,y) = place[i-d];
tie(nx,ny) = place[i];
power[i%d].push_back(abs(nx-x)+abs(ny-y));
}
rep(i,d){
rep(j,power[i].size()-1){
power[i][j+1] += power[i][j];
}
}
ll q;
cin >> q;
ll l,r;
rep(i,q){
cin >> l >> r;
PRINT(power[l%d][r/d]-power[l%d][l/d]);
}
} | 0 | 17,901,027 |
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define MOD 1000000007
using namespace std;
int d[10];
bool valid(int n) {
while(n) {
if(d[n%10]) return false;
n/=10;
}
return true;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s;
int i=1,flag = 0, l, r;
cin >> s;
if(s.length() == 2) {
if(s[0] == s[1]) {
flag = 1;
l = 0; r = 1;
}
} else {
while(s[i]) {
if(s[i+1]) {
if((s[i] == s[i-1]) || (s[i] == s[i+1]) || (s[i-1] == s[i+1])) {
l = i-1 ; r = i+1;
flag = 1;
break;
}
}
i++;
}
}
if(flag) {
cout << l+1 << ' ' << r+1;
} else cout << -1 << ' ' << -1;
cout << "\n";
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
string S;
cin >> S;
int N = S.size();
int W = 0, B = 0;
vector<int> place(N);
rep(i, N) {
if (S[i] == 'W') {
place[i] = W;
++W;
} else {
place[i] = B;
++B;
}
}
ll ans = 0;
rep(i, N) {
if (S[i] == 'W') {
ans += i - place[i];
} else {
ans += W + place[i] - i;
}
}
cout << ans / 2 << endl;
} | 0 | 88,675,274 |
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const int INF = 1e9 + 10;
int main() {
string s;
cin >> s;
int n = s.size();
int ans = 0;
rep(i,n) {
ans += s[i] - '0';
}
string res = (ans%9==0) ? "Yes" : "No";
cout << res << endl;
return 0;
} | #include <cstdio>
#include <algorithm>
using namespace std;
const int INF = 1000000000;
int main()
{
int n, v1, v2;
scanf("%d", &n);
int m[n + 1][n + 1], p[n + 1];
for (int i = 0; i <= n; i++)
for (int j = 0; j <= n; j++)
m[i][j] = INF;
for (int i = 0; i <= n; i++)
m[i][i] = 0;
scanf("%d%d", &v1, &v2);
p[0] = v1;
p[1] = v2;
for (int i = 1; i < n; i++)
{
scanf("%d%d", &v1, &v2);
p[i + 1] = v2;
}
for (int l = 2; l <= n; l++)
for (int i = 1; i <= n - l + 1; i++)
{
int j = i + l - 1;
for (int k = i; k < j; k++)
m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
}
printf("%d\n", m[1][n]);
return 0;
} | 0 | 30,500,470 |
#include <iostream>
using namespace std;
int main(){
long long a,b,c,d,cnt=0;
cin>>a>>b>>c>>d;
long long n;
cin>>n;
n=n*4;
if(a*2<b)b=2*a;
if(a*4<c)c=4*a;
if(a*8<d)d=8*a;
if(b*2<c)c=2*b;
if(b*4<d)d=4*b;
if(c*2<d)d=2*c;
if(n>=8){
cnt+=n/8*d;
n=n%8;
}
if(n>=4){
cnt+=n/4*c;
n=n%4;
}
if(n>=2){
cnt+=n/2*b;
n=n%2;
}
if(n>=1){
cnt+=n/1*a;
}
cout<<cnt;
} | #include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7, m = 1e5;
int f[m + 2], frq[m + 1] = {};
int modularPow(int a, int p) {
if (!p)
return 1;
if (p & 1)
return (1ll * a * modularPow((1ll * a * a) % mod, p / 2)) % mod;
return modularPow((1ll * a * a) % mod, p / 2);
}
int modF(int a, int b) { return (1ll * a * modularPow(b, mod - 2)) % mod; }
int choose(int n, int k) { return modF(f[n], (1ll * f[n - k] * f[k]) % mod); }
int sub(int a, int b) {
a -= b;
if (a < 0)
a += mod;
return a;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
f[0] = 1;
for (int i = 1; i <= m + 1; i++)
f[i] = (1ll * i * f[i - 1]) % mod;
int n, ind1, ind2;
cin >> n;
int arr[n + 1];
for (int i = 0; i <= n; i++) {
cin >> arr[i];
frq[arr[i]]++;
if (frq[arr[i]] == 2) {
for (int j = 0; j < i; j++)
if (arr[j] == arr[i]) {
ind1 = j + 1;
break;
}
ind2 = i + 1;
}
}
for (int i = 1; i <= n + 1; i++) {
int all = choose(n + 1, i);
if (i - 1 <= (n + 1 - ind2) + (ind1 - 1))
all = sub(all, choose((n + 1 - ind2) + (ind1 - 1), i - 1));
cout << all << "\n";
}
return 0;
} | 0 | 97,037,138 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
int main() {
cin>>n;
ll u[n], v[n];
vector <ll> point[n+1];
for (int i=1; i<n; i++) {
cin>>u[i]>>v[i];
if (u[i]>v[i]) point[u[i]].push_back(v[i]);
else point[v[i]].push_back(u[i]);
}
for (int i=1; i<=n; i++) {
sort(point[i].begin(), point[i].end());
}
ll ans=0;
for (int i=1; i<=n; i++) {
ll tambah=i*(n-i+1);
ans+=tambah;
}
for (int i=1; i<=n; i++) {
ll byk=point[i].size(), kiri, kanan=n-i+1;
for (int j=0; j<byk; j++) {
if (j>0) kiri=point[i][j]-point[i][j-1];
else kiri=point[i][j];
ans-=(kiri*kanan*(byk-j));
}
}
cout<<ans<<endl;
} | #include <bits/stdc++.h>
using namespace std;
template <class t>
using vc = vector<t>;
template <class t>
using vvc = vector<vector<t>>;
typedef long long ll;
typedef vc<int> vi;
typedef vvc<int> vvi;
typedef pair<int, int> pi;
#define uset unordered_set
#define umap unordered_map
#define endl "\n"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(a) a.bg, a.ed
template <class t, class u>
ostream &operator<<(ostream &os, const pair<t, u> &p) {
return os << "( " << p.first << ", " << p.second << " )";
}
template <class t>
ostream &operator<<(ostream &os, const vc<t> &v) {
os << "[ ";
for (int i = 0; i < v.size(); i++) {
os << v[i];
if (i != v.size() - 1) {
os << ", ";
}
}
return os << " ]";
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vi b(n);
ll tot = 0;
for (int i = 1; i < n; i++) {
cin >> b[i];
b[0] = b[1];
tot += min(b[i - 1], b[i]);
}
cout << tot + b.back();
} | 0 | 12,041,083 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long n,k;cin>>n>>k;
long a[n];
for(long i=0;i<n;++i){
a[i] =0;
}
long tmp;
for(long i=0;i<n;++i){
cin>>tmp;
a[tmp-1] +=1;
}
sort(a, a+n, greater<long>());
long ans=0;
for(long i=k;i<n;++i){
if(a[i]==0)break;
ans+=a[i];
}
cout<<ans<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) {
if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
}return (N * jou(N, P-1)) % mod;}
int main() {
int n;
cin>>n;
vector<int> sosu={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
vector<int> p(25);
rep(i,25){
int m=n;
int cnt=0;
while(m>0){
cnt+=m/sosu[i];
m/=sosu[i];
}
p[i]=cnt;
}
int nayo=0;
int niyo=0;
int juyo=0;
int yo=0;
int ni=0;
rep(i,25){
if(p[i]>=74) nayo++;
if(p[i]>=24) niyo++;
if(p[i]>=14) juyo++;
if(p[i]>=4) yo++;
if(p[i]>=2) ni++;
}
int ans=0;
ans+=nayo;
ans+=niyo*(ni-1);
ans+=juyo*(yo-1);
ans+=yo*(yo-1)*(ni-2)/2;
cout << ans << endl;
} | 0 | 50,449,038 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
int n; cin >> n;
vector<ll> a(n), b(n);
for(int i=0; i<n; i++){
cin >> a.at(i) >> b.at(i);
}
ll sum=0;
for(int i=n-1; 0<=i; i--){
if((sum+a.at(i))%b.at(i)==0) continue;
sum += b.at(i)-(sum + a.at(i))%b.at(i);
}
cout << sum << endl;
} | #include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll N;
cin >> N;
if (N % 2 == 1) {
cout << 0 << endl;
return 0;
} else {
ll sum = 0;
ll base = 5;
ll n = N;
while (n >= base) {
sum += (n / base) / 2;
base *= 5;
}
cout << sum << endl;
}
} | 0 | 51,385,480 |
#include <iostream>
using namespace std;
int main(){
int a, b, c, min, mid, max;
cin >> a >> b >> c;
min = a;
if (min > b){
min = b; mid = a;
} else{
mid = b;
}
if (min > c){
max = mid; mid = min; min = c;
} else{
if(mid < c){
max = c;
} else{
max = mid; mid = c;
}
}
cout << min << " " << mid << " " << max << "\n";
} | #include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << x << endl;
#define popcnt __builtin_popcount
int main() {
int N; cin>>N;
vector<int> T(N), A(N), patT(N), patA(N);
for (int i = 0; i < N; i++) cin>>T[i];
for (int i = 0; i < N; i++) cin>>A[i];
if(T[N-1]!=A[0]){
cout<<0<<endl;
return 0;
}
patT[0]=1; patA[N-1]=1;
int nowmxT=T[0], nowmxA=A[N-1];
for(int i = 1; i < N; i++)
{
if(nowmxT==T[i]){
patT[i]=nowmxT;
}else if(nowmxT<T[i]){
nowmxT=T[i];
patT[i]=1;
if(A[i]<T[i]){
cout<<0<<endl;
return 0;
}
}
}
for(int i = N-2; i >= 0; i--)
{
if(nowmxA==A[i]){
patA[i]=nowmxA;
}else if(nowmxA<A[i]){
nowmxA=A[i];
patA[i]=1;
if(A[i]>T[i]){
cout<<0<<endl;
return 0;
}
}
}
ll res = 1LL;
for(int i = 0; i < N; i++)
{
res*=(ll)min(patT[i], patA[i]);
res%=MOD;
}
cout<<res<<endl;
return 0;
} | 0 | 69,711,420 |
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
signed main(){
int a,b; cin>>a>>b;
cout<<a-b+1<<endl;
return 0;
} | #include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1000000007;
#define vec vector<int>
#define vecll vector<ll>
#define vecd vector<double>
#define vecst vector<string>
#define vecb vector<bool>
#define v2(v,n,m,init) vector<vector<int>> v(n, vector<int>(m, init))
#define vb2(v,n,m,init) vector<vector<bool>> v(n, vector<bool>(m, init))
#define vll2(v,n,m,init) vector<vector<ll>> v(n, vector<ll>(m, init))
#define rep(i,n) for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n) for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n) vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n) vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n) vecst var(n); rep(i,n){cin >> var[i];}
#define all(var) (var).begin(), (var).end()
#define sortall(var) sort(all(var))
#define uniqueall(v) v.erase(unique(v.begin(), v.end()), v.end());
#define pb(var) push_back(var)
#define prt(var) cout << (var) << "\n"
#define prtd(n, var) cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var) cout << setw(n) << setfill('0') << (var);
#define prt2(v1, v2) cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtall(v) rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
template <typename T>
bool chmax(T &a, const T& b){if(a<b){a=b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a>b){a=b; return true;} return false;}
int main(void) {
int n;
cin >> n;
vec div6(9), div9(9);
div6[0]=1;
div9[0]=1;
rep(i,8){
div6[i+1] = 6 * div6[i];
div9[i+1] = 9 * div9[i];
}
int ans = 1e8;
rep(i,n+1){
int tmp=0;
int for6=i;
int for9=n-i;
int id6=8, id9=8;
while(for6){
if(div6[id6]>for6) id6--;
else {
for6 -= div6[id6];
tmp++;
}
}
while(for9){
if(div9[id9]>for9) id9--;
else {
for9 -= div9[id9];
tmp++;
}
}
chmin(ans, tmp);
}
prt(ans);
} | 0 | 41,889,338 |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes \
cout << "Yes" << endl; \
return 0;
#define No \
cout << "No" << endl; \
return 0;
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;
template <typename T>
void print(const T &v);
int main()
{
string s;
cin >> s;
sort(s.begin(), s.end());
if (s == "abc")
{
Yes
}
else
{
No
}
}
template <typename T>
void print(T const &v)
{
for (int i = 0; i < v.size(); i++)
{
if (i)
cout << " ";
cout << v[i];
}
cout << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
int main()
{
int n;
while (cin >> n, n)
{
vector<long long int> data;
data.push_back(0);
rep(i, n)
{
long long int temp;
cin >> temp;
data.push_back(data[i] + temp);
}
long long int ans = INT_MAX*-1;
rep(i, n + 1)
{
REP(j, i + 1, n + 1)
{
ans = max(ans, data[j] - data[i]);
}
}
cout << ans << endl;
}
return 0;
} | 0 | 38,591,886 |
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#pragma region Macros
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define all(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define CEIL(a,b) ((a+b-1)/b)
int GCD(int a, int b)
{
if (a < b)
swap(a, b);
if (b == 0)
return a;
if (a % b == 0)
return b;
return GCD(b, a % b);
}
int LCM(int a, int b)
{
return a * b / GCD(a, b);
}
inline bool BETWEEN(int x, int min,int max) {
if (min <= x && x <= max)
return true;
else
return false;
}
using namespace std;
#pragma endregion
signed main() {
int A;
cin >> A;
cout << A/3 << endl;
} | #include <bits/stdc++.h>
#define loop(s, e, i) for (int i = s; i < e; ++i)
#define print(s) cout << s << endl;
using namespace std;
using ll = long long;
ll gcd(ll a, ll b)
{
if (a < b)
{
return gcd(b, a);
}
while (b != 0)
{
ll tmp = b;
b = a % b;
a = tmp;
}
return a;
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int N, M;
cin >> N >> M;
priority_queue<int, vector<int>, less<int>> q;
loop(0, N, i) {
int tmp;
cin >> tmp;
q.push(tmp);
}
loop(0, M, i) {
int top = q.top() / 2;
q.pop();
q.push(top);
}
ll sum = 0;
loop(0, N, i) {
int nx = q.top();
q.pop();
sum += nx;
}
print(sum);
} | 0 | 46,269,780 |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define fr(i,k,n) for (int i = k; i < n; ++i)
#define fri(i,k,n) for (int i = k; i >= n; --i)
#define INF (int)1e9
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define all(arr) arr.begin(),arr.end()
void boost(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
const int N=102,K=1e5+5;
int arr[N],pre[K];
ll dp[N][K];
void solve(){
int n,k;
cin>>n>>k;
fr(i,1,n+1){
cin>>arr[i];
}
dp[0][0]=1;
fr(i,0,k+1)
pre[i]=1;
fr(i,1,n+1){
int t=arr[i];
fr(j,0,k+1){
dp[i][j]=pre[j];
if(j-t>0)
dp[i][j]=(dp[i][j]-pre[j-t-1]+MOD)%MOD;
}
pre[0]=dp[i][0];
fr(j,1,k+1){
pre[j]=(dp[i][j]+pre[j-1])%MOD;
}
}
cout<<dp[n][k]<<endl;
return;
}
int main()
{
boost();
int tc=1;
while(tc--)
solve();
return 0;
} | #include <iostream>
#include <string>
#include <list>
using namespace std;
void print_list(list<int> &V)
{
for(list<int>::iterator it = V.begin();
it != V.end();it ++)
{
if(it == V.begin()){
cout << *it;
}
else{
cout << " " << *it;
}
}
cout << endl;
}
void delete_num(list<int> &V, int x)
{
for(list<int>::iterator it = V.begin();
it != V.end();it ++)
{
if(*it == x){
V.erase(it);
break;
}
}
}
int main(void)
{
ios_base::sync_with_stdio(false);
list<int> V;
int n;
cin >> n;
for(int i = 0; i < n; i++){
string s;
cin >> s;
if(s == "insert"){
int x;
cin >> x;
V.push_front(x);
}
else if(s == "delete"){
int x;
cin >> x;
delete_num(V, x);
}
else if(s == "deleteFirst"){
V.pop_front();
}
else{
V.pop_back();
}
}
print_list(V);
return 0;
} | 0 | 75,927,990 |
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <string>
#include <string.h>
using namespace std;
double PI = 3.1415926535897932;
long mod = 1000000007;
const long INF = (1<<30);
int main() {
string s,t;
cin >> s >> t;
bool flag = 0;
for(int i = 0; i < s.size(); i++) {
string a = s.substr(0,i);
string b = s.substr(i);
if(a+b == t | b+a == t) flag = 1;
}
if(flag)
cout << "Yes" << endl;
else cout << "No" << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end())
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;
int main(){
int n;
cin>>n;
vector<int64_t> a(n);
int64_t min = 10000000000;
int64_t max = 0;
int64_t sum=0;
rep(i,n){
cin>>a[i];
a[i] -= (i+1);
}
all(a);
int64_t med;
int64_t ans = 0;
if(n%2!=0){
med = a[n/2];
rep(i,n){
ans += abs(a[i]-med);
}
}
else{
int64_t M = 10000000000000000;
for(int64_t med = a[n/2-1];med<=a[n/2];med++){
int64_t sad = 0;
rep(i,n){
sad += abs(a[i]-med);
}
if(sad<M){
M = sad;
}
}
ans = M;
}
cout<<ans<<endl;
} | 0 | 13,276,859 |
#include <bits/stdc++.h>
using namespace std;
long long n , c , k , t[200000] , pos , ans , isi;
int main(){
cin >> n >> c >> k;
for(int i = 1 ; i <= n ; i++){
cin >> t[i];
}
sort(t + 1 , t + n + 1);
pos = 0;
isi = c;
for(int i = 1 ; i <= n ; i++){
if(isi == 0 || t[i] > pos){
ans++;
isi = c - 1;
pos = t[i] + k;
}
else {
isi--;
}
}
cout << ans << endl;
} | #include<iostream>
#include<climits>
using namespace std;
int dp[1000001][4];
int a[1000001];
int b[1000001];
int c[1000001];
int solve(int n)
{
dp[1][0]=a[1];
dp[1][1]=b[1];
dp[1][2]=c[1];
for(int i=2;i<=n;i++)
{
dp[i][0]=a[i]+max(dp[i-1][1],dp[i-1][2]);
dp[i][1]=b[i]+max(dp[i-1][0],dp[i-1][2]);
dp[i][2]=c[i]+max(dp[i-1][1],dp[i-1][0]);
}
int c=max(dp[n][0],max(dp[n][1],dp[n][2]));
return c;
}
int main()
{
int n; cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
cin>>b[i];
cin>>c[i];
}
cout<<solve(n)<<endl;
} | 0 | 7,389,407 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
cin.tie(0);
ios::sync_with_stdio(0);
ll n,m;
cin>>n>>m;
vector<pair<ll,ll>> a(n);
for(int i=0;i<n;i++)
{
int ia,ib;
cin>>ia>>ib;
a[i]=make_pair(ia,ib);
}
sort(a.begin(),a.end());
ll ans=0;
for(int i=0;m>0;i++)
{
ans+=a[i].first*min(a[i].second,m);
m-=a[i].second;
}
cout<<ans<<"\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
int main() {
string s1,s2;
int l1,l2;
cin >> s1 >> s2;
l1=s1.size(), l2=s2.size();
vector<vector<int>> dp(l1+1, vector<int>(l2+1));
rep(i,l1)
dp.at(i+1).at(0) = i+1;
rep(i,l2)
dp.at(0).at(i+1) = i+1;
rep(i,l1)
rep(j,l2) {
dp.at(i+1).at(j+1) = min(dp.at(i).at(j+1)+1, dp.at(i+1).at(j)+1);
if(s1.at(i) == s2.at(j))
dp.at(i+1).at(j+1) = min(dp.at(i+1).at(j+1), dp.at(i).at(j));
else
dp.at(i+1).at(j+1) = min(dp.at(i+1).at(j+1), dp.at(i).at(j)+1);
}
cout << dp.at(l1).at(l2) << endl;
} | 0 | 38,944,244 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
int main(){
int n,m;cin>>n>>m;
cout<<n-m+1<<endl;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 200000000007;
signed main(){
int n;
string s;
cin>>n>>s;
bool a[n];
for(int i=0;i<n;i++){
if(s[i]=='o')a[i]=false;
else a[i]=true;
}
bool ans[n];
if(n%3==0){
ans[0]=0;ans[1]=0;ans[2]=0;
for(int i=0;i<n/3;i++){
ans[(3*i+3)%n]=ans[3*i]^a[3*i+1]^a[3*i+2];
ans[(3*i+4)%n]=ans[3*i+1]^a[3*i+2]^a[3*i+3];
ans[(3*i+5)%n]=ans[3*i+2]^a[3*i+3]^a[3*i+4];
}
if(ans[0]==0&&ans[1]==0&&ans[2]==0){
for(int i=0;i<n;i++){
if(ans[i]^a[1])cout<<'W';
else cout<<'S';
}
}else cout<<-1;
}else{
ans[0]=0;
for(int i=0;i<n;i++){
ans[(3*i+3)%n]=ans[(3*i)%n]^a[(3*i+1)%n]^a[(3*i+2)%n];
}
if(ans[0]==0){
bool k=ans[0]^ans[1]^ans[2]^a[1];
for(int i=0;i<n;i++){
if(ans[i]^k)cout<<'W';
else cout<<'S';
}
}else cout<<-1;
}
return 0;
} | 0 | 8,735,624 |