code1
stringlengths 54
12k
| code2
stringlengths 65
12k
| similar
int64 0
1
| __index_level_0__
int64 44
101M
|
|---|---|---|---|
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+5;
int n;
int ar[N];
int pr[N][20];
bool can(int mid , int idx){
for(int i = 0; i < 20; i++){
if(pr[mid][i] - pr[idx - 1][i] > 1)
return 0;
}
return 1;
}
int main(){
scanf("%d" , &n);
for(int i = 1; i <= n; i++){
scanf("%d" , &ar[i]);
for(int j = 0; j < 20; j++){
pr[i][j] = pr[i - 1][j] + ( (ar[i] & (1 << j)) != 0);
}
}
long long ans = 0;
for(int i = 1; i <= n; i++){
int l = i , r = n;
while(l < r){
int mid = (l + r + 1) >> 1;
if(can(mid , i)){
l = mid;
} else {
r = mid - 1;
}
}
ans += l - i + 1;
}
printf("%lld\n" , ans);
}
|
#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[55];
int cnt[26], cnt2[26];
int main(){
int n;
scanf("%d", &n);
for(int i=0;i<26;i++) cnt[i] = 1e9;
for(int i=1;i<=n;i++){
scanf("%s", s);
int l = strlen(s);
memset(cnt2, 0, sizeof(cnt2));
for(int i=0;i<l;i++){
cnt2[s[i]-'a']++;
}
for(int i=0;i<26;i++){
cnt[i] = min(cnt[i], cnt2[i]);
}
}
for(int i=0;i<26;i++){
for(int j=0;j<cnt[i];j++) printf("%c", i+'a');
}
}
| 0
| 98,051,175
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string ABCD;
cin >> ABCD;
int a, b, c, d;
a = (int)ABCD.at(0) - 48;
b = (int)ABCD.at(1) - 48;
c = (int)ABCD.at(2) - 48;
d = (int)ABCD.at(3) - 48;
int n = 3;
vector<int> answerCal(3);
for (int bit = 0; bit < (1 << n); bit++) {
int total = 0;
vector<int> cal(3);
if (bit & 1) {
cal.at(0) = 1;
total += a + b;
} else {
total += a - b;
}
if (bit & 2) {
cal.at(1) = 1;
total += c;
} else {
total -= c;
}
if (bit & 4) {
cal.at(2) = 1;
total += d;
} else {
total -= d;
}
if (total == 7) {
answerCal = cal;
break;
}
}
string answer = "";
answer += to_string(a);
answerCal.at(0) == 1 ? answer += "+" : answer += "-";
answer += to_string(b);
answerCal.at(1) == 1 ? answer += "+" : answer += "-";
answer += to_string(c);
answerCal.at(2) == 1 ? answer += "+" : answer += "-";
answer += to_string(d);
answer += "=7";
cout << answer << endl;
return 0;
}
|
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)
struct edge{int c,s,f;};
int main(){
int n;
cin >> n;
vector<edge> v(n-1);
rep(i,n-1){
int a,b,c;
cin >> a >> b >> c;
v[i].c = a;
v[i].s = b;
v[i].f = c;
}
for (int i = 0;i < n-1;i++){
int now = v[i].s;
now += v[i].c;
for (int j = i+1;j < n-1;j++){
int tmp = v[j].s/v[j].f;
while (tmp*v[j].f < now){
tmp++;
}
now = tmp*v[j].f + v[j].c;
}
cout << now << endl;;
}
cout << 0 << endl;
return 0;
}
| 0
| 44,986,205
|
#include<bits/stdc++.h>
#define PI 3.1415926535897932384626
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,a,b) for(i=a;i<b;i++)
#define ll long long
#define pb push_back
#define popb pop_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define ini(a) memset(a,-1,sizeof(a))
#define M (ll)(1e9+7)
#define chk(a) cout << endl << #a << " : " << a << endl
#define chk2(a,b) cout << endl << #a << " : " << a << "\t" << #b << " : " << b << endl
#define chk3(a,b,c) cout << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << endl
#define chk4(a,b,c,d) cout << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << "\t" << #d << " : " << d << endl
using namespace std;
typedef pair<int, int> pi;
typedef pair<int,pi> pii;
typedef pair<ll, ll> pl;
typedef pair<ll,pl> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
void add_self_modulo(ll &a,ll b){
a+=b;
if(a>=M){
a-=M;
}
}
void sub_self_modulo(ll &a,ll b){
a-=b;
if(a<0LL){
a+=M;
}
}
void solve(){
ll n,k,K,i,j,aj;
cin>>n>>K;
ll a[n];
fo(i,n){cin>>a[i];}
vector<ll> dp(K+1,0);
dp[0]=1LL;
fo(i,n){
vector<ll> fake(K+2,0LL);
for(ll used_candies=0;used_candies<=K;used_candies++){
ll limit=min(a[i],K-used_candies);
ll L=used_candies+1;
ll R=used_candies+limit;
if(L>R)continue;
add_self_modulo(fake[L],dp[used_candies]);
sub_self_modulo(fake[R+1],dp[used_candies]);
}
ll prefix_sum=0LL;
for(j=0;j<=K;j++){
add_self_modulo(prefix_sum,fake[j]);
add_self_modulo(dp[j],prefix_sum);
}
}
cout<<dp[K]<<endl;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
ll t=1;
while(t--){
solve();
}
return 0;
}
|
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>
#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()
const int INF = 1e9;
const double PI = 3.14159;
int dx[4]={0, 1, 0, -1}, dy[4]={-1, 0, 1, 0};
using namespace std;
typedef long long ll;
#include <complex>
#define X real()
#define Y imag()
const double EPS = 1e-11;
typedef double D;
typedef complex<D> P;
int sig(D a, D b=0) { return a < b - EPS ? -1 : (a > b + EPS ? 1 : 0); }
D dot_product(P a, P b) { return (conj(a)*b).real(); }
D cross_product(P a, P b) { return (conj(a)*b).imag(); }
int main()
{
int N; cin>>N;
rep(i, N) {
P a, b;
D x1, y1, x2, y2;
cin>>x1>>y1>>x2>>y2;
a.X = (x2 - x1);
a.Y = (y2 - y1);
cin>>x1>>y1>>x2>>y2;
b.X = (x2 - x1);
b.Y = (y2 - y1);
if (abs(cross_product(a, b))<EPS) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
}
| 0
| 42,031,659
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int A , B , C , D;
cin >> A >> B >> C >> D;
int a = A + B;
int c = C + D;
if (a < c) {
cout << "Right" << endl;
}
else if (a == c) {
cout << "Balanced" << endl;
}
else if (a > c) {
cout << "Left" << endl;
}
}
|
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
int main(){
int n;
while(cin>>n,n){
int state=0,cnt=0;
for(string step;n>0;--n){
cin>>step;
if(step=="lu"||step=="ru"){
if(state==1) cnt++;
state=1;
}else{
if(state==0) cnt++;
state=0;
}
}
cout<<cnt<<endl;
}
return EXIT_SUCCESS;
}
| 0
| 85,516,828
|
#include <bits/stdc++.h>
#include<list>
#include<algorithm>
#define ll long long int
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define rep(a,b,c) for(a=b;a<c;a++)
#define repj(a,b,c) for(a=b;a<c;a++)
#define repr for(i=n-1;i>=0;i--)
#define pii pair<ll,ll>
#define pll pair<ll, ll>
#define inf 100000001
const double pie =3.141592653589793238463;
#define mod 1000000007
#define lb lower_bound
#define up upper_bound
#define rep1 for(i=1;i<=n;i++)
#define vr vector
#define POP(x) __builtin_popcountll(x)
#define zerobits(x) __builtin_ctzll(x)
#define ef else if
#define all(x) (x).begin(), (x).end()
#define SORT(A) sort(A.begin(),A.end());
#define REV(A) reverse(A.begin(), A.end());
#define lenth length()
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n"
const ll dx[4] = { -1, 1, 0, 0};
const ll dy[4] = {0, 0, -1, 1};
ll XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
ll YY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
#define precise(x) cout<<fixed<<setprecision(x)
#define t1(x) cerr<<#x<<": "<<x<<endl
#define t2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define t3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define t4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define t5(a, b, c, d, e) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define t6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
using namespace std;
void SieveOfEratosthenes(ll n)
{
bool prime[n+1];
memset(prime, true, sizeof(prime));
for (ll p=2; p*p<=n; p++)
{
if (prime[p] == true)
{
for (ll i=p*p; i<=n; i += p)
prime[i] = false;
}
}
}
ll power(ll x, ll y, ll p)
{
ll res = 1;
x = x % p;
if (x == 0) return 0;
while (y > 0)
{
if (y & 1)
res = (res*x) % p;
y = y>>1;
x = (x*x) % p;
}
return res;
}
int main()
{
fastio
ll t,i,j,k,l,m,n,a,x,b,y,z,c,h,d,f,e,p,o,nl,np,q,r,g;
cin>>n;
ll brr[105];
ll sum=0;
ll arr[106];
rep(i,0,n-1)
{
cin>>brr[i];
}
arr[0]=brr[0];
arr[n-1]=brr[n-2];
rep(i,1,n-1)
{
arr[i]=min(brr[i-1],brr[i]);
}
rep(i,0,n)
sum+=arr[i];
cout<<sum<<endl;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forin(in, n) for(int i=0; i<n; i++) cin>>in[i]
#define forout(out, n) for(int i=0; i<n; i++) cout<<out[i]<<endl
int main(){
int K, S; cin>>K>>S;
int cnt=0;
for(int x=0; x<=K; x++){
for(int y=0; y<=K; y++){
if(x+ y+ max(0, S-x-y) ==S && S-x-y<=K){
cnt++;
}
}
}
cout<<cnt<<endl;
}
| 0
| 5,440,068
|
#include <iostream>
#include<cmath>
#include<string>
using namespace std;
int main()
{
string s;
cin>>s;
int a=0,b=0;
int k=s.length();
for(int i=0;i<k;i++)
{
if(s[i]=='A')
a++;
else
b++;
}
if(a==b+1 || b==a+1)
cout<<"Yes";
else
cout<<"No";
}
|
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using vll = vector<ll>;
int N;
vll A;
bool f(ll k) {
ll sum = 0;
rep(i,A.size()) {
sum += (A[i]+k+1)/(N+1);
}
return sum <= k;
}
int main() {
cin >> N;
A.resize(N);
rep(i,N) cin >> A[i];
ll sum = 0;
rep(i,N) sum += A[i];
for (ll i = sum-N*(N-1); ; i++) {
if (f(i)) {
cout << i << endl;
return 0;
}
}
}
| 0
| 89,695,717
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
string s;
int main(void){
cin>>s;
for(int i=0;i<s.size();i++){
if(s[i]!=','){
cout<<s[i];
}else{
cout<<" ";
}
}
cout<<endl;
}
|
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
class DisjointSet{
public:
vector<int> p;
DisjointSet(int size){
for(int i=0;i<size;i++) makeSet(i);
}
void makeSet(int x){
p.push_back(x);
}
void unite(int x, int y){
link(findSet(x), findSet(y));
}
int findSet(int x){
if(x != p[x]) p[x]=findSet(p[x]);
return p[x];
}
void link(int x, int y){
p[y]=x;
}
bool isSameSet(int x, int y){
return findSet(x)==findSet(y);
}
};
int main(){
int n, q; cin >> n >> q;
DisjointSet ds=DisjointSet(n);
for(int i=0;i<q;i++){
int com, x, y; cin >> com >> x >> y;
if(com){
if(ds.isSameSet(x, y)) cout << 1 << endl;
else cout << 0 << endl;
}else{
ds.unite(x, y);
}
}
}
| 0
| 30,803,278
|
#include <iostream>
#include<queue>
struct cheese{
int x,y;
};
using namespace std;
int map[1001][1001],walk[1001][1001];
int main(void){
int X,Y,sx,sy,gx,gy,xx,yy,N,Ncnt=1,i,i2,ans=0,bx[4]={1,-1,0,0},by[4]={0,0,1,-1};
char nyuryoku[1001][1001];
queue<cheese> jotai;
cheese ima,tugi;
cin>>Y>>X>>N;
for(i=1;i<=Y;i++){
for(i2=1;i2<=X;i2++){
cin>>nyuryoku[i2][i];
}
}
for(i=1;i<=Y;i++){
for(i2=1;i2<=X;i2++){
switch(nyuryoku[i2][i]){
case 'S':
map[i2][i]=0;
sx=i2;
sy=i;
break;
case 'X':
map[i2][i]=-1;
break;
case '.':
map[i2][i]=0;
break;
case '1':
map[i2][i]=1;
break;
case '2':
map[i2][i]=2;
break;
case '3':
map[i2][i]=3;
break;
case '4':
map[i2][i]=4;
break;
case '5':
map[i2][i]=5;
break;
case '6':
map[i2][i]=6;
break;
case '7':
map[i2][i]=7;
break;
case '8':
map[i2][i]=8;
break;
case '9':
map[i2][i]=9;
break;
}
}
}
while(Ncnt<=N){
for(i=1;i<=Y;i++)for(i2=1;i2<=X;i2++)walk[i2][i]=-1;
walk[sx][sy]=0;
ima.x=sx;
ima.y=sy;
jotai.push(ima);
while(!jotai.empty()){
ima=jotai.front();
jotai.pop();
for(int I=0;I<4;I++){
xx=ima.x+bx[I];
yy=ima.y+by[I];
if(map[ima.x][ima.y]==Ncnt){
gx=ima.x;
gy=ima.y;
}
else if(xx>0&&yy>0&&xx<=X&&yy<=Y&&((walk[xx][yy]>walk[ima.x][ima.y]+1)||walk[xx][yy]==-1)&&map[xx][yy]!=-1){
tugi.x=xx;
tugi.y=yy;
walk[xx][yy]=walk[ima.x][ima.y]+1;
jotai.push(tugi);
}
}
}
ans+=walk[gx][gy];
sx=gx;
sy=gy;
Ncnt++;
}
cout<<ans<<endl;
}
|
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define mp make_pair
ll mod = 10e9+7;
ll mod2 = 998244353;
int main(){
vector<ll> ans;
while (true){
int n,k;cin>>n>>k;
if (n==0 && k==0){
break;
}
vector<ll> a(n);
rep(i,0,n) cin>>a[i];
vector<ll> b(n+1,0);
rep(i,0,n) b[i+1] = b[i] + a[i];
ll num = 0;
rep(i,0,n-k){
num = max(num,b[i+k]-b[i]);
}
ans.push_back(num);
}
for(auto x:ans){
cout<<x<<endl;
}
}
| 0
| 24,334,921
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(n) begin(n),end(n)
using ll = long long;
using P = pair<int,int>;
int main() {
int n, m;
cin >> n >> m;
vector<string> a(n),b(m);
rep(i,n) cin >> a[i];
rep(i,m) cin >> b[i];
bool ok = false;
rep(i,n) {
rep(j,n) {
if(i+m-1 >= n || j+m-1 >= n) continue;
bool match = true;
rep(k,m){
rep(l,m) {
if(a[i+k][j+l] != b[k][l]) match = false;
}
}
if(match) ok = true;
}
}
if(ok) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX
#define INFLL LLONG_MAX
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << 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; }
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(10);
vi time(5);
ll minVal = 10, minIdx = 4;
rep(i, 5){
cin >> time[i];
if(time[i]%10 != 0 && minVal > time[i]%10){
minVal = time[i]%10;
minIdx = i;
}
}
ll ans = 0;
rep(i, 5){
if(i != minIdx) time[i] = (ll)(ceil(time[i]/10.0)*10);
ans += time[i];
}
cout << ans << endl;
}
| 0
| 70,395,315
|
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define int long long
#define endl '\n'
using namespace std;
const int N = 2e5 + 77;
void sol(){
string s ,t ; cin >> s >> t ;
int n = s.length() , m = t.length();
for(int i = n-m; i >=0 ; --i){
string a = s;
bool ok = 1;
for(int j = 0 ; j < m ; ++j){
if(!(s[i+j]==t[j] || s[i+j]=='?')){ok = 0;break;}
a[i+j] = t[j];
}
if(ok){
for(int ii = 0; ii < n ; ++ii){
if(a[ii]=='?') cout << 'a';
else cout << a[ii] ;
}
cout << endl;
return;
}
}
cout << "UNRESTORABLE" << endl;
}
int32_t main(){
fast;
int t = 1;
while(t--) sol();
return 0;
}
|
#include <algorithm>
#include <bits/stdc++.h>
#define ll long long
#define pi (acos(-1))
#define rep(i, n) for (unsigned long long i = 0; i < (unsigned long long)(n); ++i)
using namespace std;
std::vector<unsigned ll> genprimevec(const unsigned ll N);
int main()
{
unsigned ll h, w;
cin >> h >> w;
if(h==1||w==1){cout<<1<<endl;return 0;}
ll one = (h / 2) + (h % 2);
ll two;
if (h % 2 == 0) { two = 2 * one; }
else
{
two =( 2 * one) - 1;
}
if (w % 2 == 0)
{
cout << two * (w / 2) << endl;
return 0;
}
if (h % 2 == 0)
{
cout << one * w << endl;
return 0;
}
cout << (two * (w / 2)) + one << endl;
return 0;
}
/*author https:
ll extgcd(ll a, ll b, ll &x, ll &y)
{
if (b == 0)
{
x = 1, y = 0;
return a;
}
ll d = extgcd(b, a % b, y, x);
y -= a / b * x;
return d;
}
std::vector<unsigned ll> genprimevec(const unsigned ll N)
{
std::vector<bool> is_prime(N + 1);
for (unsigned ll i = 0; i <= N; i++) { is_prime[i] = true; }
std::vector<unsigned ll> P;
for (unsigned ll i = 2; i <= N; i++)
{
if (is_prime[i])
{
for (unsigned ll j = 2 * i; j <= N; j += i) { is_prime[j] = false; }
P.emplace_back(i);
}
}
return P;
}
| 0
| 98,135,250
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
string reply;
cin >> a >> b;
if (((a %= 2) == 0) || ((b %= 2) == 0)) {
reply = "Even";
} else {
reply = "Odd";
}
cout << reply << endl;
}
|
#include<bits/stdc++.h>
#include<climits>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define umapii unordered_map<int,int>
#define pqmaxi priority_queue<int>
#define pqmini priority_queue<int,vector<int>,greater<int>>
#define arr(type,a,n) type* a = new type[n];
#define ff first
#define ss second
#define pb push_back
#define w(t) int t;cin>>t;while(t--)
#define popb pop_back
#define mod pow(10,9)+7;
#define mapii map<int,int>
#define mp make_pair
#define vint vector<int>
#define presesion fixed<<presesion(y)<<x
typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update>pbds;
int32_t main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output2.txt", "w", stdout);
#endif
string a, b, c;
cin >> a >> b >> c;
if (a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0]) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
| 0
| 82,719,038
|
#include<cstdio>
#include<iostream>
using namespace std;
int main(){
int a,b;
int cnt=0;
int m[16]={0};
while(scanf("%d%d",&a,&b),a,b){
int ro[32][32]={{0}};
ro[0][1]=1;
int n;
scanf("%d",&n);
int x,y;
for(int i=0;i<n;i++){
scanf("%d%d",&x,&y);
ro[y][x]=1;
}
for(int i=1;i<=b;i++){
for(int j=1;j<=a;j++){
if(ro[i][j]==1)ro[i][j]=0;
else ro[i][j]=(ro[i-1][j]+ro[i][j-1]);
}
}
m[cnt]=ro[b][a];
cnt++;
}
for(int i=0;i<cnt;i++){
printf("%d\n",m[i]);
}
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() {
int n;
string s;
cin >> n >> s;
set<int> rs, gs, bs;
rep(i, n) {
switch (s[i]) {
case 'R':
rs.insert(i);
break;
case 'G':
gs.insert(i);
break;
case 'B':
bs.insert(i);
break;
default:
break;
}
}
ll ans = 0;
for (auto ir = rs.begin(); ir != rs.end(); ++ir) {
for (auto ig = gs.begin(); ig != gs.end(); ++ig) {
ll now = bs.size();
int r = *ir;
int g = *ig;
if (bs.find(2*r-g) != bs.end()) --now;
if (bs.find(2*g-r) != bs.end()) --now;
if ((r+g)%2 == 0 && bs.find((r+g)/2) != bs.end()) --now;
ans += now;
}
}
cout << ans << endl;
return 0;
}
| 0
| 29,574,057
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll Max = 100000+5;
const static ll INF = 1e18+5;
vector<set<ll>> G(Max);
ll N, Q, K;
map<pair<ll, ll>, ll> C;
ll DP[Max];
void Dijkstra(ll s){
for(int i = 0; i < Max; i++) DP[i] = INF;
DP[s] = 0;
for(auto v : G[s]) DP[v] = C[make_pair(s, v)];
priority_queue< pair<ll, pair<ll, ll>>, vector<pair<ll, pair<ll, ll>>>, greater<pair<ll, pair<ll, ll>>> > Q;
for(auto v : G[s]){
if(C.find(make_pair(s, v)) != C.end()) Q.push(make_pair(C[make_pair(s, v)], make_pair(s, v)));
}
while(!Q.empty()){
auto next = Q.top(); Q.pop();
auto w = next.second.second;
for(auto v : G[w]) if(C.find(make_pair(w, v)) != C.end()){
if(DP[w] + C[make_pair(w, v)] <= DP[v]){
DP[v] = DP[w] + C[make_pair(w, v)];
Q.push(make_pair(C[make_pair(w, v)], make_pair(w, v)));
}
}
}
}
int main() {
cin >> N;
for(int i = 0; i < N-1; i++){
int a, b, c; cin >> a >> b >> c;a--;b--;
G[a].insert(b);
G[b].insert(a);
C[make_pair(a, b)] = c;
C[make_pair(b, a)] = c;
}
cin >> Q >> K;K--;
Dijkstra(K);
for(ll i = 0; i < Q; i++){
int x, y; cin >> x >> y;x--;y--;
cout << DP[x] + DP[y] << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
#define int long long
#define INF 1e+9
using namespace std;
signed main(){
int n,a[100000],ma = 0,b = INF;
cin >> n;
for(int i = 0;i < n;i++){
cin >> a[i];
ma = max(ma,a[i]);
}
bool flag = false;
for(int i = 0;i < n;i++){
if(!flag && a[i] == ma) flag = true;
else if(min(abs(b - ma / 2),abs(b - (ma + 1) / 2)) > min(abs(a[i] - ma / 2),abs(a[i] - (ma + 1) / 2))) b = a[i];
}
cout << ma << " " << b << endl;
return 0;
}
| 0
| 25,884,759
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
int main(){
int n,m;
cin >> n >> m;
pair<int,int>p[100009];
rep(i,n){
cin >> p[i].first >> p[i].second;
}
int sum=0;
int now=0;
ll ans=0;
sort(p,p+n);
while(sum<m){
ans+=p[now].first;
p[now].second-=1;
if(p[now].second==0)now++;
sum++;
}
cout << ans;
return 0;
}
|
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
#define NUM 100
#define INF 1000000000
int X_dim[NUM];
int Y_dim[NUM];
int M[NUM][NUM];
void init(){
for(int i = 0; i < NUM; i++){
for(int j = 0; j < NUM; j++){
if(i == j){
M[i][j] = 0;
}else{
M[i][j] = INF;
}
}
}
}
int main(void){
init();
int n;
scanf("%d", &n);
for(int i = 0; i < n; i++){
scanf("%d %d", &X_dim[i], &Y_dim[i]);
}
for(int k = 1; k <= n - 1; k++){
for(int x = 0; x + k <= n - 1; x++){
for(int t = x; t <= x + k - 1; t++){
M[x][x + k] = min(M[x][x + k], M[x][t] + M[t + 1][x + k] + X_dim[x] * Y_dim[t] * Y_dim[x + k]);
}
}
}
printf("%d\n", M[0][n - 1]);
}
| 0
| 62,803,709
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD 1000000007
#define mm(arr) memset(arr, 0, sizeof(arr))
int main(){
FAST
int arr[3];
for(int i = 0; i < 3; i++){
cin >> arr[i];
}
sort(arr, arr + 3);
cout << arr[0] + arr[1];
return 0;
}
|
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
int main()
{
int X, Y, N;
cin >> X >> Y >> N;
vector<vector<bool>> v(X, vector<bool>(Y, false));
for (int i = 0; i < N; i++)
{
int x, y, a;
cin >> x >> y >> a;
switch (a)
{
case 1:
for (int i = 0; i < x; i++)
{
for (int j = 0; j < Y; j++)
{
v.at(i).at(j) = true;
}
}
break;
case 2:
for (int i = x; i < X; i++)
{
for (int j = 0; j < Y; j++)
{
v.at(i).at(j) = true;
}
}
break;
case 3:
for (int i = 0; i < X; i++)
{
for (int j = 0; j < y; j++)
{
v.at(i).at(j) = true;
}
}
break;
case 4:
for (int i = 0; i < X; i++)
{
for (int j = y; j < Y; j++)
{
v.at(i).at(j) = true;
}
}
break;
}
}
int ans = X * Y;
for (int i = 0; i < X; i++)
{
for (int j = 0; j < Y; j++)
{
if (v.at(i).at(j))
{
ans--;
}
}
}
cout << ans;
return 0;
}
| 0
| 45,287,340
|
#include<bits/stdc++.h>
using namespace std;
int get(vector<int> &a, int x) {
int res = 0;
for(int i : a) {
res += (x - i) * (x - i);
}
return res;
}
int main() {
int n;
cin >> n;
int s = 0;
int x;
vector<int> a;
for(int i = 0; i < n; ++i) {
cin >> x;
s += x;
a.push_back(x);
}
int res = -1;
int resV = 1e9;
int div = s / n;
for(int i = div - 1; i <= div + 1; ++i) {
if(i >= 0) {
if(get(a, i) < resV) {
resV = get(a, i);
res = i;
}
}
}
cout << resV << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define REP(i, init, n) for(int i = (int)(init); i < (int)(n); i++)
#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>
long MOD = 1000000007;
int main() {
int N, M;
cin>>N>>M;
vl X(N), Y(M);
REP(i, 0, N) cin >> X[i];
REP(i, 0, M) cin >> Y[i];
vector<long long> X_T(N), Y_T(M), X_Mer(N), Y_Mer(M);
X_T[0] = N-1; X_T[N-2] = N-1;
Y_T[0] = M-1; Y_T[M-2] = M-1;
REP(i, 0, N-1) X_Mer[i] = X[i+1]- X[i];
REP(i, 0, M-1) Y_Mer[i] = Y[i+1]- Y[i];
REP(i, 1, (N+1)/2) X_T[i] = X_T[N - 2 - i] = (X_T[i-1] + N - 1 - i * 2) % MOD;
REP(i, 1, (M+1)/2) Y_T[i] = Y_T[M - 2 - i] = (Y_T[i-1] + M - 1 - i * 2) % MOD;
long long X_sum = 0, Y_sum = 0;
REP(i, 0, N-1){
X_sum += X_Mer[i] * X_T[i] % MOD;
X_sum %= MOD;
}
REP(i, 0, M-1){
Y_sum += Y_Mer[i] * Y_T[i] % MOD;
Y_sum %= MOD;
}
long long ans = X_sum * Y_sum % MOD;
cout << ans << endl;
}
| 0
| 56,695,232
|
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi pair<ll,ll>
#define pd pair<ld,ld>
#define pb push_back
#define inf 1e18
#define mod 1000000007
#define en '\n'
#define ld long double
#define ff first
#define ss second
#define ull unsigned long long
#define lb lower_bound
#define ub upper_bound
#define fr(a,b,c) for(ll a = b ; a <= c ; ++a )
#define frn(a,b,c) for(ll a = b ; a >= c ; a -- )
#define fra(a,b) for(auto a: b)
#define ms(a) memset(a,0,sizeof a);
#define alla(a) a,a+n
#define allv(a) a.begin(),a.end()
#define size(a) (ll)a.size()
#define getMat(x,n,m,val) vector<vector<ll>>x(n,vector<ll>(m,val))
const ll MAXN = 1000005;
#define pii 3.14159265358979323846
ll pw(ll b, ll r, ll md){
ll ans = 1;
while(r){
if(r&1)ans = (ans*b)%md;
b = (b*b)%md;
r>>=1;
}
return ans;
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll n,m;cin>>n>>m;
vector<ll>g[n+1];
fr(i,0,m-1){
ll a,b;cin>>a>>b;
g[a].pb(b);
g[b].pb(a);
}
ll ans[n+1];ms(ans);
queue<ll>q;
q.push(1);
ans[1]=1;
while(!q.empty()){
ll u = q.front();
q.pop();
for(auto v: g[u]){
if(!ans[v]){
q.push(v);
ans[v]=u;
}
}
}
bool flag = false;
fr(i,1,n)if(!ans[i])flag=true;
if(flag)cout<<"No\n";
else {
cout<<"Yes\n";
fr(i,2,n)cout<<ans[i]<<en;
}
return 0 ;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;
int main() {
int n, k;
cin >> n >> k;
Int sm[n+2];
sm[0] = 0;
rep(i,n+1) {
sm[i+1] = (sm[i] + i) % MOD;
}
Int ans = 0;
for (int i = k; i <= n+1; i++) {
Int mn = sm[i];
Int mx = sm[n+1] - sm[n-i+1];
ans += mx - mn + 1;
ans %= MOD;
}
if (ans < 0) ans += MOD;
cout << ans << endl;
}
| 0
| 58,013,840
|
#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, t;
cin >> s;
char pre = s[0];
t.push_back(pre);
for (int i = 1; i < s.size(); i++) {
if (pre != s[i]) {
pre = s[i];
t.push_back(pre);
}
}
cout << t.size() - 1 << endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;
#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);
template <typename First>
void debug_print_in(First first){
cerr << first << endl;
return;
}
template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
cerr << first << " ";
debug_print_in(rest...);
return;
}
void IN(void){
return;
}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
cin >> first;
IN(rest...);
return;
}
template <typename First>
void OUT(First first){
cout << first << endl;
return;
}
template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
cout << first << " ";
OUT(rest...);
return;
}
template<class t, class u> t chmax(t&a,u b){if(a<b)a=b; return a;};
template<class t, class u> t chmin(t&a,u b){if(a>b)a=b; return a;};
int popcount(int t){return __builtin_popcount(t);}
int popcount(ll t){return __builtin_popcountll(t);}
template <typename T>
void vec_print(vector<T> VEC){
REP(i, VEC.size()){
cerr << VEC[i] << " ";
}
cerr << endl;
};
template <typename T>
void mat_print(vector<vector<T> > MAT){
REP(i,MAT.size()){
REP(j,MAT[i].size()){
cerr << MAT[i][j] << " ";
}
cerr << endl;
}
};
constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll K;
IN(K);
ll N=50;
vll a(N, N-1);
ll tmp = K/N;
REP(i,N) a[i] += tmp;
K = K-tmp*N;
REP(i,K){
a[i] += N+1;
REP(j,N) a[j] -= 1;
}
printf("%lld\n", N);
REP(i,N) printf("%lld ", a[i]);
printf("\n");
return 0;
}
| 0
| 66,197,817
|
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int MAXN=1e5+5;
int n,L,T;
int a[MAXN],w[MAXN];
int ans[MAXN];
int main(){
scanf("%d%d%d",&n,&L,&T);
for(int i=1;i<=n;i++){
scanf("%d%d",&a[i],&w[i]);
if(w[i]==2) w[i]=-1;
}
ll cnt=0;
for(int i=1;i<=n;i++){
ll np=a[i]+w[i]*T;
if(!np) continue;
if(np>0) (cnt+=np/L)%=n;
else (cnt+=(np+1)/L-1)%=n;
ans[i]=(np%L+L)%L;
}
sort(ans+1,ans+n+1);
cnt=(cnt+n)%n;
for(int i=cnt+1;i<=n;i++) printf("%d\n",ans[i]);
for(int i=1;i<=cnt;i++) printf("%d\n",ans[i]);
}
|
#include <iostream>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#define MAXV 10005
#define MAXE 100005
using namespace std;
int N,E;
bool V[MAXV];
vector<int> G[MAXV],out;
int indeg[MAXV];
void bfs(int u){
queue<int> q;
q.push(u);
V[u]=true;
int i;
while(!q.empty()){
int a=q.front();q.pop();
out.push_back(a);
for(i=0;i<G[a].size();i++){
int v=G[a][i];
indeg[v]--;
if(indeg[v]==0&&!V[v]){
V[v]=true;
q.push(v);
}
}
}
}
void tsort(){
int i;
for(i=0;i<N;i++){
if(!V[i]&&indeg[i]==0){
bfs(i);
}
}
for(i=0;i<out.size();i++)cout<<out[i]<<endl;
}
int main(){
cin>>N>>E;
int i,j;
for(i=0;i<E;i++){
int a,b;
cin>>a>>b;
G[a].push_back(b);
}
memset(indeg,0,sizeof(indeg));
for(i=0;i<N;i++)V[i]=false;
for(i=0;i<N;i++){
for(j=0;j<G[i].size();j++){
indeg[G[i][j]]++;
}
}
tsort();
return 0;
}
| 0
| 36,422,042
|
#include <algorithm>
#include <climits>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <unordered_map>
#include <vector>
const int mod = 1e9 + 7;
const int kmax = 510000;
const int last_days[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
long long fact[kmax], fact_inv[kmax], inv[kmax];
void init_comb()
{
fact[0] = fact[1] = 1;
fact_inv[0] = fact_inv[1] = 1;
inv[1] = 1;
for (int i = 2; i < kmax; i++) {
fact[i] = fact[i - 1] * i % mod;
inv[i] = mod - inv[mod % i] * (mod / i) % mod;
fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
}
}
long long comb(int n, int r)
{
if (n < r) {
return 0;
}
if (n < 0 || r < 0) {
return 0;
}
return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}
template <typename T, T N>
class UnionFind {
T parent_[N];
T rank_[N];
T size_[N];
public:
UnionFind();
T Root(T idx);
bool IsSame(T x, T y);
void Unite(T x, T y);
T GetSize(T idx);
};
template <typename T, T N>
UnionFind<T, N>::UnionFind()
{
for (T i = 0; i < N; i++) {
parent_[i] = i;
rank_[i] = 0;
size_[i] = 1;
}
}
template <typename T, T N>
T UnionFind<T, N>::Root(T idx)
{
return parent_[idx] == idx ? idx : parent_[idx] = Root(parent_[idx]);
}
template <typename T, T N>
bool UnionFind<T, N>::IsSame(T x, T y)
{
return Root(x) == Root(y);
}
template <typename T, T N>
void UnionFind<T, N>::Unite(T x, T y)
{
x = Root(x);
y = Root(y);
if (x == y) {
return;
}
if (rank_[x] < rank_[y]) {
parent_[x] = y;
size_[y] += size_[x];
} else {
parent_[y] = x;
size_[x] += size_[y];
if (rank_[x] == rank_[y]) {
rank_[x]++;
}
}
}
template <typename T, T N>
T UnionFind<T, N>::GetSize(T idx)
{
return size_[Root(idx)];
}
long long pow_mod(long long n, long long p, long long m)
{
if (p == 0) {
return 1;
}
if (p % 2 == 0) {
long long t = pow_mod(n, p / 2, m);
return t * t;
}
return n * pow_mod(n, p - 1, m);
}
long long nCr_mod(long long n, long long r)
{
long long x = 1;
for (long long i = n - r + 1; i <= n; i++) {
x *= i;
}
long long a = 1;
for (long long i = 1; i <= r; i++) {
a *= i;
}
long long y = pow_mod(a, mod - 2, mod);
return x * y;
}
long long nCr(long long n, long long r)
{
long long ans = 1;
for (long long i = 1; i <= r; i++) {
ans = ans * (n - i + 1) / i;
}
return ans;
}
bool is_prime(long long n)
{
if (n == 1) {
return false;
}
for (long long i = 2; i * i <= n; i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
bool is_leap(long long y)
{
return (y % 4 == 0 && y % 100 != 0) || y % 400 == 0;
}
void next_day(long long& y, long long& m, long long& d)
{
d++;
if (d > last_days[m - 1] + (m == 2 && is_leap(y) ? 1 : 0)) {
d = 1;
m++;
}
if (m > 12) {
y++;
m = 1;
}
}
long long fib(long long n)
{
long long a = 0, b = 1;
for (int i = 0; i < n; i++) {
long long t = a;
a = b;
b = a + t;
}
return a;
}
int main()
{
long long n, p;
std::cin >> n >> p;
std::map<long long, long long> m;
for (int i = 0; i < n; i++) {
long long temp;
std::cin >> temp;
m[temp % 2]++;
}
long long ans = pow_mod(2, m[0], mod);
long long t = 0;
for (long long i = p; i <= m[1]; i += 2) {
t += nCr(m[1], i);
}
std::cout << ans * t << std::endl;
}
|
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define FF(i,a,b) for(int i=a;i<b;i++)
#define BF(i,a,b) for(int i=a;i>=b;i--)
#define vi vector<int>
#define MAP map<int,int>
#define pb push_back
#define MP make_pair
#define F first
#define S second
#define pi pair<int,int>
#define all(v) v.begin(),v.end()
#define PIE 3.1415926535897932384626433832795
#define print0(a) cout<<a<<"\n"
#define print1(a) cout<<a<<' '
#define print2(a,b) cout<<a<<" "<<b<<" ";
#define print3(a,b,c) cout<<a<<" "<<b<<" "<<c<<" ";
#define print4(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<" ";
#define FastIO ios::sync_with_stdio(0); cin.tie(0);cout.tie(0)
const int mod = 1e9+7;
const int N = 2e5+10;
const int inf = 1e18;
vector<int> g[N];
template <typename A>istream& operator>>(istream& input,vector<A>& x) {for(auto& i:x)input>>i;return input;}
template<typename A>ostream& operator<<(ostream& output,vector<A>& x) {for(auto& i:x)output<<i<<' ';return output;}
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;}
int add(int a, int b){return (a%mod + b%mod + mod)%mod;}
int sub(int a, int b){return (a%mod - b%mod + mod)%mod;}
int mul(int a, int b){return ((a%mod)*(b%mod) + mod)%mod;}
int Power(int a,int b)
{
int res=1;
while(b)
{
if(b&1)res*=a;
a*=a;
b>>=1;
}
return res;
}
signed main()
{
FastIO;
int T=1;
while(T--)
{
string s;
cin>>s;
int n=s.length()+1;
vi a(n);
FF(i,0,n-1)
{
if(s[i]=='<')
{
chmax(a[i+1],a[i]+1);
}
}
BF(i,n-2,0)
{
if(s[i]=='>')
{
chmax(a[i],a[i+1]+1);
}
}
cout<<accumulate(all(a),(0LL))<<endl;
}
}
| 0
| 256,300
|
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;
void solve(){
}
int main (){
ios::sync_with_stdio(0);
cin.tie(0);
int s;
cin >> s;
int m = s;
vector<int> a(10000);
a[m]+=1;
rep(i,1000001){
if(m%2==0){
m/=2;
a[m]+=1;
if(a[m]==2){
cout << i+2;
return 0;
}
}
else{
m = 3*m + 1;
a[m]+=1;
if(a[m]==2){
cout << i+2;
return 0;
}
}
}
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int main()
{
int n, m, X, Y;
cin >> n >> m >> X >> Y;
vector<int> x(n), y(m);
rep (i, n)
cin >> x[i];
rep (i, m)
cin >> y[i];
sort(x.rbegin(), x.rend());
sort(y.begin(), y.end());
bool ok = false;
for (int i = X + 1; i <= Y; i++)
if (x[0] < i && y[0] >= i)
ok = true;
cout << (ok ? "No War" : "War") << endl;
return 0;
}
| 0
| 1,661,410
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e15;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll MOD = 1e9+7;
int main(){
ll N; cin >> N;
string S; cin >> S;
map<char, ll> M;
for(auto ch : S) M[ch]++;
ll ans = 0;
for(int i = 0; i < 10; i++){
for(int j = 0; j < 10; j++){
for(int k = 0; k < 10; k++){
char s1 = 48+i, s2 = 48+j, s3 = 48+k;
ll idx = 0;
bool flag = false;
for(; idx < N; idx++){
if(S[idx] == s1){idx++; break;}
}
for(;idx < N; idx++){
if(S[idx] == s2){idx++; break;}
}
for(; idx < N; idx++){
if(S[idx]== s3){
idx++; flag = true; break;
}
}
if(flag) ans++;
}
}
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<tuple>
#define DIV 1000000007
#define TE 2e5
using namespace std;
using ll = long long;
using ldb = long double;
int main() {
int N, M; cin >> N >> M;
vector<ll> s(N+1), t(M+1);
for (int i = 1; i <= N; i++) {
cin >> s[i];
}
for (int i = 1; i <= M; i++) {
cin >> t[i];
}
ll dp[2005][2005]={0};
ll sum[2005][2005]={0};
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= M; j++) {
if (s[i] == t[j])
dp[i][j] = (sum[i - 1][j - 1] + 1) % DIV;
sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + dp[i][j];
sum[i][j] = (sum[i][j] + DIV) % DIV;
}
}
cout << (sum[N][M] + 1 + DIV) % DIV << endl;
}
| 0
| 65,704,569
|
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define vl vector
#define ff first
#define ss second
using namespace std;
int main()
{
ll a,b,i,j,n,t;
string s;
cin>>n;
ll arr[n];
for(i=0;i<n;i++) cin>>arr[i];
sort(arr,arr+n);
b=n/2;
a=b-1;
ll ans=arr[b]-arr[a];
cout<<ans;
}
|
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;
}
struct io
{
io()
{
ios::sync_with_stdio(false);
cin.tie(0);
}
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-19;
signed main() {
string s1;
cin >> s1;
string s2;
cin >> s2;
Sort(s1);
rSort(s2);
if (s1 < s2) {
mes("Yes");
} else {
mes("No");
}
}
| 0
| 92,017,526
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;
int main(){
cin.tie(0); ios::sync_with_stdio(false);
ll n, x;
cin >> n >> x;
ll ans = n;
ll a = max(x, n-x);
ll b = min(x, n-x);
while(b > 0){
ans += 2*b*(a/b);
ll tmp = a;
a = b;
b = tmp%b;
}
ans -= a;
print(ans)
return 0;
}
|
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
using namespace std;
int main() {
string a;
string d[10] = { "",".,!? ","abc","def","ghi","jkl","mno",
"pqrs","tuv","wxyz" };
int m;
cin >> m;
for (int z = 0; z < m; z++) {
cin >> a;
string c = "";
for (int i = 0; i < a.length();) {
while (a[i] == '0'&&i < a.length())i++;
if (i == a.length()) break;
int j = i;
while (a[j] == a[i] && i < a.length()) {
i++;
}
int sum = i - j - 1;
sum %= d[(int)a[j] - '0'].length();
if (i < a.length() && a[i] == '0')c += d[(int)a[j] - '0'][sum];
}
if (c != "") cout << c << endl;
}
}
| 0
| 76,236,007
|
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define PI acos(-1)
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define All(vec) vec.begin(), vec.end()
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Count(vec, x) count(vec.begin(), vec.end(), x)
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define Find(S, s) S.find(s) != string::npos
int main() {
int N;
cin >> N;
vector<int> a(N);
bool flag = false;
Rep(i, N) {
cin >> a[i];
if (a[i] == 1) flag = true;
}
if (!flag) cout << -1 << endl;
else {
int index = 1, ans = 0;
Rep(i, a.size()) {
if (a[i] != index) {
ans++;
}
else {
index++;
}
}
cout << ans << endl;
}
return 0;
}
|
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
void answer() {
int n, k;
cin >> n >> k;
int lim = (n-1) * (n-2) / 2;
if(k > lim) {
cout << -1 << '\n';
return;
}
int m = n-1+lim-k;
cout << m << '\n';
REPC(i, 2, n) {
cout << 1 << ' ' << i << '\n';
}
REPC(i, 2, n-1) REPC(j, i+1, n) {
if(k < lim) {
cout << i << ' ' << j << '\n';
lim--;
}
}
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
answer();
return 0;
}
| 0
| 26,528,994
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
int N,S;
cin >> N;
rep(i,N) {
int l_i,r_i;
cin >> l_i >> r_i;
S += r_i - l_i + 1;
}
cout << S << endl;
}
|
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define INF 1e18
#define EPS 1e-9
#define MOD 1000000007
#define F first
#define S second
#define all(x) begin(x), end(x)
using ll = long long;
using ull = unsigned long long;
using ui = unsigned int;
using ld = long double;
#define int long long
template<typename T>
ostream& operator<<(ostream &stream, vector<T> v)
{
for (const auto &it : v)
stream << it << " ";
return stream;
}
template<typename T1, typename T2>
ostream& operator<<(ostream &ostream, pair<T1, T2> p)
{
ostream << p.first << " " << p.second;
return ostream;
}
template<typename T>
void swap(T &a, T &b)
{
T t = a;
a = b;
b = t;
}
void swap(int &a, int &b)
{
int t = a;
a = b;
b = t;
}
int GCD(int a, int b)
{
if (!b)
return a;
return GCD(b, a % b);
}
int LCM(int a, int b)
{
return (a * b) / GCD(a, b);
}
int modpow(int x, int n, int m = MOD)
{
if (n == 0) return 1 % m;
long long u = modpow(x, n / 2, m);
u = (u * u) % m;
if (n % 2 == 1)
u = (u * x) % m;
return u;
}
void solve(int tc)
{
int n, m;
cin >> n >> m;
char a[n][m];
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
cin >> a[i][j];
int dp[n + 1][m + 1];
for (int i = 0; i <= n; i++)
{
for (int j = 0; j <= m; j++)
{
if (!i || !j)
{
dp[i][j] = 0;
continue;
}
if (i == 1 && j == 1)
{
dp[i][j] = 1;
continue;
}
dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
if (a[i - 1][j - 1] == '#')
dp[i][j] = 0;
dp[i][j] %= MOD;
}
}
cout << dp[n][m];
}
int32_t main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
int t = 1;
for (int i = 1; i <= t; i++)
{
solve(i);
}
return 0;
}
| 0
| 3,414,068
|
#include <iostream>
#include <vector>
using namespace std;
const long long int MOD = 1000000007;
int main(){
long long int n, k;
cin >> n >> k;
vector<int> a(n+1);
for(int i = 0; i < n; i++) cin >> a[i];
long long int ans_in = 0;
long long int ans_out = 0;
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(i == j) continue;
if(a[i] > a[j]){
if(i < j) ans_in++;
ans_out++;
}
}
}
long long int ans = 0;
ans = ans_in * k;
ans %= MOD;
long long int c = k * (k-1);
c /= 2LL;
c %= MOD;
ans += ans_out * c;
ans %= MOD;
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
for(int i=0;i<(int)(s.size());++i) {
cout << s[i];
if(i == (int)(s.size())-1) cout << endl;
else cout << " ";
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
while(1) {
int m, n1, n2; cin >> m >> n1 >> n2;
if(m == 0) break;
vi a(m);
for(int i=0;i<m;++i) {
cin >> a[i];
}
sort(a.rbegin(), a.rend());
n1--;
n2--;
int ma = 0;
int argma = 0;
for(int i=n1;i<=n2;++i) {
if(ma <= a[i] - a[i+1]) {
ma = a[i] - a[i+1];
argma = i+1;
}
}
cout << argma << endl;
}
}
| 0
| 89,654,443
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
int main(){
int N,T;
cin >> N >> T;
vector<int> t(N);
for(int i = 0; i < N; i++){
cin >> t[i];
}
ll ans = 0;
for(int i = 1; i < N; i++){
int gap = t[i] - t[i-1];
if(gap >= T){
ans += T;
}else{
ans += gap;
}
}
ans += T;
cout << ans << endl;
}
|
# include <bits/stdc++.h>
# define speed ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
# pragma GCC target("avx2")
# pragma GCC optimize("O3")
# pragma GCC optimize("unroll-loops")
# define int long long
using namespace std;
const int N = 1e3 + 7;
const int mod = 1e9 + 7;
int dp[N][N];
string a[N];
int32_t main() {
speed;
int n, m;
cin >> n >> m;
for ( int i = 1; i <= n; i++ ) {
cin >> a[i];
a[i] = '#' + a[i];
}
dp[1][1] = 1;
for ( int i = 1; i <= n; i++ ) {
for ( int j = 1; j <= m; j++ ) {
if ( i == 1 && j == 1 || a[i][j] == '#' ) {
continue;
}
if ( i > 1 && a[i - 1][j] == '.' ) {
dp[i][j] += dp[i - 1][j];
}
if ( j > 1 && a[i][j - 1] == '.' ) {
dp[i][j] += dp[i][j - 1];
}
dp[i][j] %= mod;
}
}
cout << dp[n][m];
}
| 0
| 88,332,286
|
#include <iostream>
int main() {
long long int r, d, x;
std::cin >> r >> d >> x;
for (int i = 0; i < 10; ++i) {
std::cout << r * x - d << "\n";
x = r * x - d;
}
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};
int main() {
ll n, k, g, mx;
cin >> n >> k >> g;
mx = g;
rep(i, n - 1) {
ll a;
cin >> a;
g = gcd(g, a);
mx = max(mx, a);
}
bool ans = true;
if(k > mx)
ans = false;
else if(k % g)
ans = false;
cout << (ans ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}
| 0
| 36,836,998
|
#include <stdio.h>
int main()
{
long long n;
int i;
char s[111];
scanf("%s%lld", s, &n);
for(i = 0; s[i] && s[i] == 49; i++);
if(n > i) printf("%c\n", s[i]);
else puts("1");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int main() {
int N,M;
while(scanf("%d %d",&N,&M),N) {
priority_queue<P> Q;
for(int i=0;i<N;i++) {
int d,p;
scanf("%d %d",&d,&p);
Q.push(P(p,d));
}
int sum=0;
while(!Q.empty()) {
P p=Q.top();Q.pop();
int d=min(p.second,M);
M-=d;
p.second-=d;
sum+=p.second*p.first;
}
printf("%d\n",sum);
}
}
| 0
| 90,326,846
|
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
int main() {
int n, k;
cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < k; i++) {
vector<int> b(n + 1);
for (int j = 0; j < n; j++) {
int l = max(0, j - a[j]);
int r = min(n, j + a[j] + 1);
b[l]++;
b[r]--;
}
for (int j = 0; j < n; j++) {
b[j + 1] += b[j];
}
b.pop_back();
if (a == b) break;
a = b;
}
for (int i = 0; i < n; i++) {
cout << a[i] << endl;;
}
return 0;
}
|
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>
#include <cstdint>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rrep(i, n) for(ll i = (ll)(n-1); i >= 0; i--)
#define repi(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rrepi(i,a,b) for(ll i=(ll)(b-1);i>=(ll)(a);i--)
#define all(x) (x).begin(),(x).end()
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
ll n;
cin>>n;
cout<<0<<endl;
string s;
cin>>s;
ll l=0,r=0;
if(s=="Female")l=1;
if(s=="Vacant"){
return 0;
}
cout<<n-1<<endl;
cin>>s;
if(s=="Female")r=1;
if(s=="Vacant")return 0;
ll li=0,ri=n-1;
while(ri-li>1){
ll mid=(li+ri)/2;
cout<<mid<<endl;;
cin>>s;
ll f=0;
if(s=="Vacant")return 0;
if(s=="Female")f=1;
if(mid%2)f^=1;
if(f==l)li=mid;
else ri=mid;
}
return 0;
}
| 0
| 23,647,704
|
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s,t;
int a,b;
while(cin>>a>>b)
{
int c,d,e,f,g;
c=a-1;
d=(c*(c+1))/2.;
e=b-1;
f=(e*(e+1))/2.;
cout<<d+f<<endl;
}
return 0;
}
|
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char *argv[])
{
string map[10] = {"", ".,!? ", "abc", "def", "ghi", "jkl", "mno",
"pqrs", "tuv", "wxyz"};
string line;
int n, cnt, num;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> line;
cnt = 0;
for (int j = 0; j < line.length(); ++j) {
if (line[j] == '0') {
if (j == 0 || line[j - 1] == '0')
continue;
num = line[j - 1] - '0';
cout << map[num][(cnt - 1) % map[num].length()];
cnt = 0;
} else if (line[j] != '0') {
cnt++;
}
}
cout << endl;
}
return 0;
}
| 0
| 75,258,638
|
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
const long long MOD = 1000000007;
#define SET(x) memset(x, 0, sizeof(x))
#define SET2d(x,m,n) memset(x, 0, sizeof(x[0][0]) * m * n)
#define SETBOOL(x) memset(x,false,sizeof(x))
#define CLR(x) memset(x, -1, sizeof(x))
#define CLR2d(x,m,n) memset(x, -1, sizeof(x[0][0]) * m * n)
#define mp make_pair
#define PII pair<int, int>
#define pf printf
#define sf scanf
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define np std::string::npos
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define cases(cs,t) for(int cs=1;cs<=t;cs++)
#define PI acos(-1)
#define no1 __builtin_popcount
#define BOUNDARY(i, j) ((i >= 0 && i < row) && (j >= 0 && j < column))
#define uniq(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define sz(a) int(a.size())
#define ff first
#define ss second
#define endl "\n"
#define forch(it,s) for(auto it:s)
#define each(it,s) for(auto it = s.begin(); it != s.end(); ++it)
#define rep(i,a) for(int i=0; i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define bits(n) __builtin_popcount(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const int maxx=100005;
bool sortinrev(const pair<int,int> &a,const pair<int,int> &b)
{
return a.first>b.first;
}
template<typename T>inline T Bigmod(T base, T power, T MOD){
T ret=1;
while(power)
{
if(power & 1)ret=(ret*base)%MOD;
base=(base*base)%MOD;
power>>=1;
}
return ret;
}
double sq(double x) {return x*x;}
ll po(ll b,ll p){
ll res=1;
while(p){
res*=b;
p--;
}
return res;
}
ll lg2(ll x){
ll res=0;
while(x>1){
res++;
x/=2ll;
}
return res;
}
void solve(){
ll n;
cin>>n;
ll maxi=highest(ll);
for(ll i=1;i*i<=n;i++){
if(n%i==0){
maxi=min(maxi,((i-1)+((n/i)-1)));
}
}
cout<<maxi<<endl;
}
signed main()
{
IOS;
int t;
t=1;
while(t--){
solve();
}
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define Boost() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
typedef long long int lli;
typedef vector<int> vi;
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<int>::iterator vit;
typedef set<int>::iterator sit;
#define rep0(i,n) for(i=0;i<n;i++)
#define rep1(i,n) for(i=1;i<=n;i++)
#define sf scanf
#define pf printf
#define pb push_back
#define all(c) c.begin(),c.end()
#define MK make_pair
#define F first
#define S second
#define endl '\n'
#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))
inline bool checkBit(ll n, int i)
{
return n&(1LL<<i);
}
inline ll setBit(ll n, int i)
{
return n|(1LL<<i);;
}
inline ll resetBit(ll n, int i)
{
return n&(~(1LL<<i));
}
string makeintString(int x)
{
stringstream ss;
ss << x;
string str = ss.str();
return str;
}
string makellString(ll x)
{
stringstream ss;
ss << x;
string str = ss.str();
return str;
}
char cpp(char c)
{
return static_cast<char>(c + 1);
}
struct func
{
bool operator()(pii const &a, pii const &b)
{
if(a.F==b.F)
return (a.S<b.S);
return (a.F<b.F);
}
};
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007
int main()
{
Boost();
int t;
t=1;
while(t--)
{
ll n,l,x;
cin>>n>>l;
vector<ll>a;
for(ll i=0; i<n; i++)
{
cin>>x;
a.pb(x);
}
ll idx=-1;
for(ll i=0; i<n-1; i++)
{
if(a[i]+a[i+1]>=l)
{
idx=i+1;
break;
}
}
if(idx==-1)
{
cout<<"Impossible"<<endl;
}
else
{
cout<<"Possible"<<endl;
for(ll i=1; i<=(idx-1); i++)
{
cout<<i<<endl;
}
for(ll i=n-1; i>=idx; i--)
{
cout<<i<<endl;
}
}
}
return 0;
}
| 0
| 18,886,223
|
#include <iostream>
#include <vector>
using namespace std;
int main(){
while(true){
int m, nmin, nmax;
cin >> m >> nmin >> nmax;
if(m == 0)
break;
vector<int> p(m);
for(int i=0; i<m; i++)
cin >> p[i];
int amax = 0, ans;
for(int i=nmin; i<=nmax; i++){
if(p[i-1] - p[i] >= amax){
amax = p[i-1] - p[i];
ans = i;
}
}
cout << ans << endl;
}
return 0;
}
|
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcountll(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;
typedef vector<vector<lint>> mat;
mat mtx{
{1,0,1},
{1,0,0},
{0,1,0},
};
vector<lint> F{0,0,1};
mat mul(mat &A,mat &B){
mat C(A.size(),vector<lint>(B[0].size()));
rep(i,A.size()) rep(j,B.size()) rep(k,B[0].size()){
C[i][k]=(C[i][k]+A[i][j]*B[j][k])%MOD;
}
return C;
}
mat powmat(mat A,lint n){
mat B(A.size(),vector<lint>(A.size()));
rep(i,A.size()) B[i][i]=1;
while(n){
if(n&1) B=mul(B,A);
A=mul(A,A);
n>>=1;
}
return B;
}
lint calc(lint n){
mat A=mtx;
A=powmat(A,n-1);
lint res=0;
rep(i,A.size()) res=(res+A[A.size()-1][i]*F[A.size()-1-i])%MOD;
return res;
}
int main(void){
int S;
cin >> S;
cout << calc(S) << endl;
}
| 0
| 52,787,569
|
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main(){
int n;
while(1){
cin >> n;
if (n==0) return 0;
string tmp;
int cnt=0,state=0;
int ud = 0;
for(int i=0; i<n; i++) {
cin >> tmp;
if (tmp == "lu") {
if (state == 0) state = 2;
else if (state == 1) {
state = 3;
if (ud == 0) cnt++; ud=1;
}
} else if (tmp == "ru") {
if (state == 0) state = 1;
else if (state == 2) {
state = 3;
if (ud == 0) cnt++; ud=1;
}
} else if (tmp == "ld") {
if (state == 3) state = 1;
else if (state == 2) {
state = 0;
if (ud == 1) cnt++; ud=0;
}
} else if (tmp == "rd") {
if (state == 3) state = 2;
else if (state == 1) {
state = 0;
if (ud == 1) cnt++; ud=0;
}
}
}
cout << cnt << endl;
}
}
|
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <chrono>
#include <random>
#include <time.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
#define INF 1e9+7
#define LLINF 1e18+7
#define N 500000
ll MOD=1e9+7;
int change(vec v){
int ret=0,bi=1;
rep(i,26){
ret+=v[i]*bi;
bi*=2;
}
return ret;
}
int dp[1<<26+2];
main(){
string ss;cin>>ss;
int n=ss.size();
vec s;
rep(i,n){
s.pb((int)(ss[i]-'a'));
}
vec counter(26);
rep2(i,1,n){
counter[s[i-1]]^=1;
}
int flag=1;
rep(i,26)flag-=counter[i];
if(flag>=0){
cout<<1<<endl;return 0;
}
counter=vec(26);
dp[0]=0;
rep(i,n+1){
int now=change(counter);
if(dp[now]==0&&now)dp[now]=INF;
rep(j,26){
vec temp=counter;
temp[j]^=1;
int place=change(temp);
if(dp[place]==0&&place)dp[place]=INF;
dp[now]=min(dp[now],dp[place]+1);
}
if(i<n)
counter[s[i]]^=1;
else
cout<<dp[now]<<endl;
}
return 0;
}
| 0
| 50,396,711
|
#include<bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
int arr[205][205];
int main(){
int n,m,r;
cin>>n>>m>>r;
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++) arr[i][j] = INF;
}
vector<int>town(r);
for(int i=0; i<r; i++) cin>>town[i];
sort(town.begin(),town.end());
while(m--){
int a,b,c;
cin>>a>>b>>c;
arr[a][b] = min(arr[a][b],c);
arr[b][a] = min(arr[b][a],c);
}
for(int k=1; k<=n; k++){
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
arr[i][j] = min(arr[i][j],arr[i][k]+arr[k][j]);
}
}
}
int mindist = numeric_limits<int>::max();
do{
int dist = 0;
for(int i=1; i<r; i++) dist+=arr[town[i-1]][town[i]];
mindist = min(mindist,dist);
}while(next_permutation(town.begin(),town.end()));
cout<<mindist;
}
|
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
int bingo[3][3];
bool mark[3][3];
int main(){
for(int i=0; i<3; ++i){
for(int j=0; j<3; ++j){
int a;
cin >> a;
bingo[i][j] = a;
}
}
int N; cin >> N;
for(int n=0; n<N; ++n){
int b; cin >> b;
for(int i=0; i<3; ++i){
for(int j=0; j<3; ++j){
if(b == bingo[i][j]) mark[i][j] = true;
}
}
}
string ans = "No";
for(int i=0; i<3; ++i){
if (mark[i][0] == true &&
mark[i][1] == true &&
mark[i][2] ==true ){
ans = "Yes";
}
}
for(int j=0; j<3; ++j){
if (mark[0][j] == true &&
mark[1][j] == true &&
mark[2][j] ==true ){
ans = "Yes";
}
}
if(mark[0][0] == true &&
mark[1][1] == true &&
mark[2][2] == true){
ans = "Yes";
}
if(mark[0][2] == true &&
mark[1][1] == true &&
mark[2][0] == true){
ans = "Yes";
}
cout << ans << endl;
}
| 0
| 96,859,292
|
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n , k , ga;
cin>>n>>k;
if(k==0)
{
cout<<"0 0";
} else {
int ca[n+1] = { 0 };
int wa[n+1] = { 0 };
int x;
string s,c="AC";
while(k--)
{
cin>>x>>s;
if(s==c)
{
ca[x]=1;
} else {
if(ca[x]==0)
{
wa[x]++;
}
}
}
int ans1 = 0 , ans2 = 0;
for(int i = 1;i<=n;i++)
{
ans1 = ans1+ca[i];
if(ca[i]==1)
ans2 = ans2 +wa[i];
}
cout<<ans1<<" "<<ans2;
}
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;
const int inf = 1000000000;
const ll inff = 1000000000000000000;
int main(){
string s;
ll n;
cin >> s >> n;
for(int i = 0; i < min((ll)s.size(), n); i++) {
if(s[i] >= '2') {
cout << s[i] << endl;
return 0;
}
}
cout << '1' << endl;
return 0;
}
| 0
| 92,137,485
|
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define ALL(obj) (obj).begin(), (obj).end()
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; }
int dy[]={0, 0, 1, -1, 1, -1, -1, 1};
int dx[]={1, -1, 0, 0, 1, 1, -1, -1};
int main() {
cout<<fixed<<setprecision(10);
int n,q; cin>>n>>q;
dsu d(n);
rep(_,q){
int t,u,v;
cin>>t>>u>>v;
if(t==0){
d.merge(u,v);
}else{
if(d.same(u,v)) cout<<1<<endl;
else cout<<0<<endl;
}
}
return 0;
}
|
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
#include<deque>
#include<iomanip>
#include<utility>
using namespace std;
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
#define S 21
llfor;
const ll mod=1000000007;
const double pi=acos(-1);
ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
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 llpow(ll x,ll n){ll ans=1;rep(i,0,n){ans*=x;}return ans;}
ll fact(ll x){ll ans=1;rep(i,0,x)ans*=(x-i);return ans;}
ll ncr(ll n,ll r){return fact(n)*fact(n-r)/fact(r);}
ll npr(ll n,ll r){return fact(n)/fact(n-r);}
bool prime(ll a){if(a<=1)return false;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll fib(ll x){ll fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
ll dig(ll n){ll d=0,tmp=n;while(tmp!=0){tmp/=10;d++;}return d;}
void matcpy(ll a[S][S],ll b[S][S]){ll t=i;rep(i,0,S)rep(j,0,S)b[i][j]=a[i][j];i=t;}
void matrst(ll a[S][S]){ll t=i;rep(i,0,S)rep(j,0,S)a[i][j]=0;i=t;}
void matpow(ll a[S][S]){ll ans[S][S];matrst(ans);ll t=i,k;rep(i,0,S)rep(j,0,S)rep(k,0,S)ans[i][j]+=a[i][k]*a[k][j];matcpy(ans,a);i=t;}
void matmul(ll a[S][S],ll b[S][S], ll as[S][S]){ll t=i,k;matrst(as);rep(i,0,S)rep(j,0,S)rep(k,0,S)as[i][j]+=a[i][k]*b[k][j];i=t;}
int main(){
ll q,h,s,d,n;
cin>>q>>h>>s>>d>>n;
q*=4;
h*=2;
ll t=min(q,h);
t=min(t,s);
ll ans=min((n/2)*d+(n%2)*t,n*t);
pr(ans);
return 0;}
| 0
| 64,786,225
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
using P = pair<int,int>;
using pq = priority_queue<int>;
typedef long long ll;
int main()
{
int n, k; cin >> n >> k;
int ans = 1;
rep(i, n)
{
if (ans * 2 - ans <= k)
ans *= 2;
else
ans += k;
}
cout << ans << endl;
return (0);
}
|
#pragma target("avx")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;
#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
bool first = true;
string res = "{";
for (const auto& x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a[ohara], b[ohara], c, d, tmp, m, h, w, x, y, sum, k, q;
ll dp[ohara], dp_cou, need;
int main(void) {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
cin >> n;
rep(i, n) cin >> a[i];
rep(i, n) cin >> b[i];
rep(i, n) {
if (a[i] == b[i]) continue;
if (b[i] < a[i])
dp[dp_cou++] = a[i] - b[i];
else
ans++, need += b[i] - a[i];
}
sort(dp, dp + dp_cou);
reverse(dp, dp + dp_cou);
rep(i, dp_cou) {
if (need <= 0) break;
need -= dp[i];
ans++;
}
if (need > 0) ans = -1;
Cout(ans);
return 0;
}
| 0
| 7,307,563
|
#include <iostream>
#include <vector>
#include <algorithm>
using ll = long long;
using namespace std;
int n;
int c[15000];
int A[2000001];
void countingsort(int A[], int k){
for (int i = 0; i < k; ++i) {
c[i] = 0;
}
for (int j = 0; j < n; ++j) {
c[A[j]]++;
}
}
int main() {
cin >> n;
int co = 0;
for (int i = 0; i < n; ++i) {
scanf("%d", &A[i]);
}
countingsort(A, 15000);
for (int j = 0; j < 12000; j++) {
if (c[j]) {
for (int i = 0; i < c[j];++i) {
co++;
if(co != n) printf("%d ", j);
else {printf("%d\n", j); return 0;}
}
}
}
return 0;
}
|
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<class F>auto recursive(F f){return[f](auto...a){return f(f,a...);};}
template<class T>using rev_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<class T>using vector2d=vector<vector<T>>;
struct fixprec{int p;fixprec(int p):p(p){}};
ostream&operator<<(ostream&o,fixprec f){return o<<fixed<<setprecision(f.p);}
int main() {
int N;
cin >> N;
vector<i64> A(N);
for(i64 &x : A) cin >> x;
vector2d<int> edge(N);
for(int i = 0; i < N - 1; i++) {
int a, b;
cin >> a >> b;
a--, b--;
edge[a].push_back(b);
edge[b].push_back(a);
}
int r = -1;
for(r = 0; r < N; r++) {
if(edge[r].size() == 1) {
break;
}
}
bool ans = true;
ans &= recursive([&](auto f, int prev, int i) -> i64 {
if(i != r && edge[i].size() == 1) return A[i];
i64 n;
if(i == r) n = A[i];
else n = 2 * A[i];
for(int j : edge[i]) {
if(j == prev) continue;
i64 x = f(f, i, j);
if(x > A[i]) ans = false;
n -= x;
}
if(n > A[i] || 0 > n) ans = false;
return n;
})(r, r) == 0;
cout << (ans ? "YES" : "NO") << endl;
return 0;
}
| 0
| 66,785,907
|
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
cin >> N;
vector<int> A(N);
for(int i = 0; i < N; i++){
cin >> A[i];
}
int sum = 0;
sum += abs(A[0]);
for(int i = 0; i < N - 1; i++){
sum += abs(A[i] - A[i + 1]);
}
sum += abs(A[N - 1]);
int sum1 = sum;
sum1 -= abs(A[0]);
sum1 -= abs(A[1] - A[0]);
sum1 += abs(A[1]);
cout << sum1 << endl;
for(int i = 1; i < N - 1; i++){
sum1 = sum;
sum1 -= abs(A[i] - A[i + 1]);
sum1 -= abs(A[i] - A[i - 1]);
sum1 += abs(A[i - 1] - A[i + 1]);
cout << sum1 << endl;
}
sum1 = sum;
sum1 -= abs(A[N - 1]);
sum1 -= abs(A[N - 1] - A[N - 2]);
sum1 += abs(A[N - 2]);
cout << sum1 << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define uniq(x) ((x).erase(unique(all(x)),(x).end()))
#define sz(x) ((int)(x).size())
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#ifdef LOCAL
#define debug(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<(x)<<endl
#define debug_vec(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = ";\
rep(i,sz(x)){cerr<<x[i]<<" ";}cerr<<endl
#define debug_mat(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<endl;\
rep(i,sz(x)){rep(j,sz(x[i])){cerr<<x[i][j]<<" ";}cerr<<endl;}cerr<<endl
#else
#define debug(x) void(0)
#define debug_vec(x) void(0)
#define debug_mat(x) void(0)
#endif
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
int main(){
ios_base::sync_with_stdio(false);cin.tie(0);
int N;
cin >> N;
int ans=0;
for(int i=1;i<=N;i+=2){
int cnt=0;
REP(j,1,i+1) if(i%j==0) cnt++;
if(cnt==8) ans++;
}
cout << ans << endl;
return 0;
}
| 0
| 48,708,007
|
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
long long n,m,h[100005],a,b,ans=0;
bool c[100005]={};
cin>>n>>m;
for(int i=0;i<n;i++){
cin>>h[i];
}
for(int i=0;i<m;i++){
cin>>a>>b;
a--;
b--;
if(h[a]>h[b]){
c[b]=true;
}
else if(h[a]<h[b]){
c[a]=true;
}
else{
c[a]=true;
c[b]=true;
}
}
for(int i=0;i<n;i++){
if(!c[i])
ans++;
}
cout<<ans<<endl;
return(0);
}
|
#define LOCAL
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1);
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;
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; }
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
string res;
for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
return res;
}
string to_string(vector<bool> v) {
string res = "{";
for (bool e : v) res += to_string(e) + ", ";
return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
string res = "{";
for (auto e : c) res += to_string(e) + ", ";
return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define DEBUG(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define DEBUG(...)
#endif
int main(int argc, const char * argv[]) {
std::cout << std::fixed << std::setprecision(15);
int N; cin >> N;
vector<int> A(N);
ll ans = 0;
rep(i, N){
int a; cin >> a;
int cnt = a / 2;
if(cnt > 0){
if(a % 2 == 0){
A[i] = 2;
cnt--;
}
else{
A[i] = 1;
}
}
else{
if(a % 2 == 0){
A[i] = 0;
}
else{
A[i] = 1;
}
}
ans += cnt;
}
rep(i, N){
if(A[i] == 2){
ans++;
A[i] -= 2;
}
else if(A[i] == 1){
if(i+1 <= N -1){
if(A[i+1] == 2){
A[i]--; A[i+1]--;
ans++;
}
else if(A[i+1] == 1){
A[i]--; A[i+1]--;
ans++;
}
}
}
}
cout << ans << endl;
}
| 0
| 44,043,065
|
#include <bits/stdc++.h>
#include <algorithm>
#include <queue>
using namespace std;
int main(){
int N;
cin >> N;
int X[N];
int min = 101;
int max = 0;
for(int i=0; i<N; i++){
cin >> X[i];
if (min > X[i]){min=X[i];}
if (max < X[i]){max=X[i];}
}
int nums = int(max-min+1);
int dp[nums];
int dp_linear[nums];
dp[0] = 0;
dp_linear[0]=0;
for(int j=0; j<N; j++){
dp[0] += pow((X[j] -min),2);
dp_linear[0] += (X[j] -min);
}
priority_queue<long, vector<long>, greater<long>> que;
que.push(dp[0]);
for(int k=1; k<nums; k++){
dp[k] = dp[k-1] - 2*dp_linear[k-1] + N;
dp_linear[k] = dp_linear[k-1] - N;
que.push(dp[k]);
}
int ans = que.top();
cout << ans << endl;
}
|
#include <stdio.h>
int main(){
int W,H,j=0;
int n = 0;
int d[10000][2];
while(j == 0){
scanf("%d %d",&H,&W);
if(W == 0 && H == 0){
j = 1;
}else{
d[n][0] = H;
d[n][1] = W;
n++;
}
}
for(int i = 0;i < n;i++){
for(int q = 0;q < d[i][0];q++){
for(j = 0;j < d[i][1];j++){
printf("#");
}
printf("\n");
}
printf("\n");
}
}
| 0
| 100,540,649
|
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
template <typename T>
void print_vec(const vector<T>& v, bool is_reverse=false, int num=0){
if(num == 0) num = (int)v.size();
if(is_reverse) for(int i=num-1; i>=0; i--){ cout<<v[i]; if(i!=0) cout<<" ";}
else for(int i=0; i<num; i++){ cout<<v[i]; if(i!=num-1) cout<<" ";}
cout << endl;
}
template <typename T>
void print_pairvec(const vector<T> &v, int num=0){
if(num == 0) num = (int)v.size();
cout << endl;
for(int i=0; i<num; i++){ cout << v[i].first << " " << v[i].second << endl;}
}
template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
cout << endl; cout << " ";
for(int i=0; i<v[0].size(); i++) cout << i << " ";
cout << endl;
for(int i=0; i<v.size(); i++){
cout << "i=" << i << ": ";
for(int j=0; j<v[i].size(); j++){
if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << " ";
else cout << "\x1B[31m" << v[i][j] << " ";
}
cout << "\x1B[0m" << endl;
}
}
int main(){
ll N;
cin >> N;
vector<ll> C(N-1), S(N-1), F(N-1);
for(int i=0; i<N-1; i++) cin >> C[i] >> S[i] >> F[i];
S.push_back(0);
for(int i=0; i<N; i++){
ll time = 0;
for(int now=i; now<N-1; now++){
ll num = max(time-S[now], (ll)0);
ll start_time = S[now] + (num + F[now] - 1)/F[now]*F[now];
time = start_time + C[now];
}
cout << time << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> cnt(n, 0);
int AC = 0, WA = 0;
rep(i, m)
{
int p;
string s;
cin >> p >> s;
p--;
if (cnt[p] == -1)
continue;
if (s == "AC")
{
AC++;
WA += cnt[p];
cnt[p] = -1;
}
else
cnt[p]++;
}
cout << AC << " " << WA << endl;
}
| 0
| 79,453,444
|
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main() {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
if (a >= 0 && c <= 100) {
if (a<b && b<c) {
printf("Yes\n");
}
else {
printf("No\n");
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
int n;
vector<int> pcnt(110, 0);
int main() {
cin >> n;
pcnt.at(1) = 1;
for(int i = 2; i <= n; ++i) {
int check = i;
for(int j = 2; j <= n; ++j) {
while(check % j == 0) {
pcnt.at(j)++;
check /= j;
}
}
}
int ans = 0;
int cnt2 = 0; int cnt24 = 0;
for(int i = 0; i <= n; ++i) {
if(pcnt.at(i) >= 24) cnt24++;
if(pcnt.at(i) >= 2) cnt2++;
}
int fircnt = cnt24 * max(0, (cnt2-cnt24)) + cnt24 * max(0, (cnt24 - 1));
int cnt4 = 0; int cnt14 = 0;
for(int i = 0; i <= n; ++i) {
if(pcnt.at(i) >= 14) cnt14++;
if(pcnt.at(i) >= 4) cnt4++;
}
int scdcnt = cnt14 * max(0, (cnt4-cnt14)) + cnt14 * max(0, (cnt14 - 1));
int cntl2 = 0; int cntl4 = 0;
for(int i = 0; i <= n; ++i) {
if(pcnt.at(i) >= 4) cntl4++;
if(pcnt.at(i) >= 2) cntl2++;
}
int thdcnt = max(0, (cntl2-cntl4)) * cntl4 * max(0, (cntl4 - 1)) / 2;
if(cntl4 >= 3) thdcnt += cntl4 * ((cntl4 - 1) * (cntl4 - 2) / 2);
int cnt74 = 0;
for(int i = 0; i <= n; ++i) if(pcnt.at(i) >= 74) cnt74++;
ans = fircnt + scdcnt + thdcnt + cnt74;
cout << ans << endl;
}
| 0
| 98,075,584
|
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int a[5];
for(int i=1;i<6;i++){
cin>>a[i];
}
sort(a+1,a+6);
for(int i=5;i>0;i--){
if(i==1)cout<<a[i];
else cout<<a[i]<<' ';
}
cout<<endl;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
int main(){
int n;
cin>>n;
vector<int> a(n);
rep(i,n) cin>>a[i];
sort(all(a));
int sum=0;
rep(i,n) sum+=abs(a[i]);
if(a[0]>0) sum-=2*a[0];
if(a[n-1]<0) sum+=2*a[n-1];
cout<<sum<<endl;
int acc=a[0];
for(int i=1;i<n-1;i++){
if(a[i]>=0){
cout<<acc<<" "<<a[i]<<endl;
acc-=a[i];
}
}
cout<<a[n-1]<<" "<<acc<<endl;
acc=a[n-1]-acc;
for(int i=1;i<n-1;i++){
if(a[i]<0){
cout<<acc<<" "<<a[i]<<endl;
acc-=a[i];
}
}
}
| 0
| 81,424,935
|
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long i, x = 0, ans = 0;
string s;
cin >> s;
for(i = 0; i < s.size(); i++)
{
if(s[i] == 'B')
x++;
else
ans += x;
}
cout << ans;
}
|
#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL,LL> PLL;
typedef map<int,int> MII;
typedef queue<int> QI;
typedef queue<PII> QPII;
typedef stack<int> SI;
typedef stack<PII> SPII;
typedef deque<int> DI;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<bool> VB;
typedef vector<VB> VVB;
typedef vector<double> VD;
typedef vector<VD> VVD;
typedef vector<string> VS;
typedef vector<VS> VVS;
typedef vector<char> VC;
typedef vector<VC> VVC;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef priority_queue<int> PQGI;
typedef priority_queue<int, VI, greater<int>> PQLI;
typedef priority_queue<PII> PQGP;
typedef priority_queue<PII, VPII, greater<int>> PQLP;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).rbegin(), (c).rend())
#define LB lower_bound
#define UB upper_bound
#define NEXP next_permutation
#define FI first
#define SE second
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define FORR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REPR(i,n) FORR(i,0,n)
#define BREP(bit,N) for(int bit = 0; bit < (1<<N); ++bit)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX/3;
const LL LINF = LLONG_MAX/3;
const int RINF = INT_MIN/3;
const LL RLINF = LLONG_MIN/3;
const LL MOD = 1e9+7;
const LL MODD = 998244353;
const int MAX = 510000;
inline bool Eq(double a, double b) { return fabs(b - a) < EPS; }
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; }
#define COUT(x) cout << (x) << endl
#define COUT2(x,y) cout << (x) << " " << (y) << endl
#define PR(x) cout << (x)
#define ENDL cout << endl
#define SPACE cout << " "
#define BC(x) __builtin_popcountll(x)
void cYes(){ COUT("Yes");exit(0); }
void cNo(){ COUT("No");exit(0); }
void cYES(){ COUT("YES");exit(0); }
void cNO(){ COUT("NO");exit(0); }
void cyes(){ COUT("yes");exit(0); }
void cno(){ COUT("no");exit(0); }
void cMINU(){ COUT(-1);exit(0); }
void cZERO(){ COUT(0);exit(0); }
VI dx = {1,0,-1,0,1,1,-1,-1};
VI dy = {0,1,0,-1,1,-1,1,-1};
VC dc = {'R','D','L','U'};
VS ds = {"R","D","L","U","RD","RU","LD","LU"};
LL Gcd(LL a, LL b) {return __gcd(a,b);}
LL Lcm(LL a, LL b) {return a/Gcd(a,b)*b;}
LL ModPow(LL A, LL N, LL M){
LL res = 1;
while(N>0){
if(N&1) res = res * A % M;
A = A * A % M;
N >>= 1;
}
return res;
}
LL fac[MAX], finv[MAX], inv[MAX];
void ConInit(LL M) {
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 % M;
inv[i] = M - inv[M%i] * (M / i) % M;
finv[i] = finv[i - 1] * inv[i] % M;
}
}
LL COM(int n, int k, LL M){
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % M) % M;
}
template<class T> void VCout(vector<T> &v){
int N = SZ(v);
REP(i,N){
cout << v.at(i);
if(i == N-1) cout << endl;
else cout << " ";
}
return;
}
bool isOK(int N, LL M, int V, int P, VLL &A, int x){
if(x <= P) return true;
LL now = A.at(--x) + M;
if(A.at(--P) > now) return false;
LL sco = 0;
sco += P*M;
sco += (N-x)*M;
FOR(i,P,x) sco += min(M,max(0LL,now-A.at(i)));
return sco >= M*V;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(12);
int N,V,P;
LL M;
cin >> N >> M >> V >> P;
VLL A(N);
REP(i,N) cin >> A.at(i);
SORTR(A);
int ok = 0, ng = N+1;
while(abs(ng - ok) > 1){
int mid = (ok+ng) / 2;
if(isOK(N, M, V, P, A, mid)) ok = mid;
else ng = mid;
}
COUT(ok);
return 0;
}
| 0
| 22,507,339
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
using namespace std;
int main() {
string k = "keyence";
string s; cin >> s;
string ans = "YES";
int p = 0;
bool d = false;
bool d2 = false;
int count = 0;
int n = s.length();
int left;
while(1){
if(s[p] == k[count]){
count ++;
if (count == 7) break;
p ++;
}else{
left = 7-count;
for(int i = n-left; i < n; i ++){
if(s[i] != k[count]) ans = "NO";
count ++;
}
break;
}
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using namespace std::chrono;
#define f0r(a, b) for (long long a = 0; a < (b); a++)
#define f1r(a, b, c) for (long long a = (b); a < (c); a++)
#define f0rd(a, b) for (long long a = (b); a >= 0; a--)
#define f1rd(a, b, c) for (long long a = (b); a >= (c); a--)
#define ms(arr, v) memset(arr, v, sizeof(arr))
#define pb push_back
#define io {ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}
#define fix(prec) {cout << setprecision(prec) << fixed;}
#define mp make_pair
#define f first
#define s second
#define presum(p, a, n) {p[0] = a[0]; for (int i = 1; i < (n); i++) p[i] = a[i] + p[i-1];}
#define all(v) v.begin(), v.end()
#define getunique(v) {sort(all(v)); v.erase(unique(all(v)), v.end());}
#define readgraph(list, edges) for (int i = 0; i < edges; i++) {int a, b; cin >> a >> b; a--; b--; list[a].pb(b); list[b].pb(a);}
#define ai(a, n) for (int ele = 0; ele < n; ele++) cin >> a[ele];
#define ain(a, lb, rb) for (int ele = lb; ele <= rb; ele++) cin >> a[ele];
#define ao(a, n) {for (int ele = 0; ele < n; ele++) { if (ele) cout << " "; cout << a[ele]; } cout << '\n';}
#define aout(a, lb, rb) {for (int ele = lb; ele <= rb; ele++) { if (ele > lb) cout << " "; cout << a[ele]; } cout << '\n';}
typedef long long ll;
typedef double ld;
typedef long double lld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v);
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";
}
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) {
cin >> p.first;
return cin >> p.second;
}
mt19937 rng(steady_clock::now().time_since_epoch().count());
void usaco(string filename) {
freopen((filename + ".in").c_str(), "r", stdin);
freopen((filename + ".out").c_str(), "w", stdout);
}
const lld pi = 3.14159265358979323846;
const ll mod = 1000000007;
namespace modop {
ll madd(ll a, ll b) {
return (a + b) % mod;
}
ll msub(ll a, ll b) {
return (((a - b) % mod) + mod) % mod;
}
ll mmul(ll a, ll b) {
return ((a % mod) * (b % mod)) % mod;
}
ll mpow(ll base, ll exp) {
ll res = 1;
while (exp) {
if (exp % 2 == 1){
res = (res * base) % mod;
}
exp >>= 1;
base = (base * base) % mod;
}
return res;
}
ll minv(ll base) {
return mpow(base, mod - 2);
}
ll mdiv(ll a, ll b) {
return mmul(a, minv(b));
}
}
using namespace modop;
ll n, m, k, q, Q, T, l, r, x, y, z;
ll a[1000005];
ll b[1000005];
ll c[1000005];
string s, t;
ll ans = 0;
ll dp[305][305];
int main() {
io;
cin >> n >> k;
ai(a, n);
f0r(i, k + 1) f0r(j, n + 1) dp[i][j] = mod * mod;
f0r(i, k + 1) {
ll mn = mod;
f0r(j, n + 1) {
if (j < i) {
dp[i][j] = 0;
} else if (j == i) {
dp[i][j] = a[j];
} else {
f1rd(l, j, j - i) {
int low = i + l - j;
dp[i][j] = min(dp[i][j], dp[low][l - 1] + max(0LL, a[j] - a[l - 1]));
}
}
}
}
ll ans = mod * mod;
cout << dp[k][n] << endl;
}
| 0
| 47,814,450
|
#include<stdio.h>
#include<algorithm>
#include<string>
#include<iostream>
#include<vector>
#include<queue>
#include<map>
using namespace std;
#define REP(i,n) for(long long int (i)=0;(i) < (n);(i)++)
int n,m;
char from,to,tmp;
int main(){
cin >> n;
while(n){
map<char,char>dict;
REP(i,n){
cin >> from >> to;
dict[from] = to;
}
cin >> m;
REP(i,m){
cin >> tmp;
if(dict.find(tmp) == dict.end()) cout << tmp;
else cout << dict[tmp];
}
cout << endl;
cin >> n;
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <list>
#include <math.h>
#include <stack>
#include <stdio.h>
#include <string>
#include <queue>
#include <vector>
using namespace std;
int main()
{
list<int> l;
int n, x;
cin >> n;
string cmd;
for (int i = 0; i < n; i++) {
cin >> cmd;
if (cmd == "insert") {
cin >> x;
l.push_front(x);
}
else if (cmd == "delete") {
cin >> x;
for (list<int>::iterator itr = l.begin(); itr != l.end(); itr++) {
if (*itr == x) {
l.erase(itr);
break;
}
}
}
else if (cmd == "deleteFirst") {
l.pop_front();
}
else if (cmd == "deleteLast") {
l.pop_back();
}
}
for (list<int>::iterator itr = l.begin(); itr != l.end(); itr++) {
if (itr != l.begin()) cout << " ";
cout << *itr;
}
cout << "\n";
}
| 0
| 31,036,014
|
#include<iostream>
using namespace std;
int main(){
int n;
int m;
cin>>n;
cin>>m;
cout<<(n*(n-1)/2+m*(m-1)/2)<<endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;
template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (ll i=(ll)N-1; i>=0; i--)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const ll INF = pow(2,30)-1;
vector<ll> fac;
void c_fac(ll x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { ll d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll modpow(ll x, ll p) { ll result = 1, now = 1, pm = x; while (now<=p) { if (p&now) { result = result * pm % MOD; } now*=2; pm = pm*pm % MOD; } return result; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }
struct coord { ll x, y; };
int main() {
ll H, W; cin >> H >> W;
string A[H]; rep(i,H) cin >> A[i];
vector<vector<ll>> turn(H, vector<ll>(W,-1));
queue<coord> q;
rep(i,H) rep(j,W) {
if (A[i][j]=='#') {
q.push({i,j});
turn[i][j] = 0;
}
}
coord to[4] = {{-1,0},{0,-1},{0,1},{1,0}};
while (q.size()) {
coord now = q.front(); q.pop();
rep(i,4) {
ll tox = now.x+to[i].x, toy = now.y+to[i].y;
if (tox>=0&&tox<H) {
if (toy>=0&&toy<W) {
if (turn[tox][toy]==-1) {
turn[tox][toy] = turn[now.x][now.y] + 1;
q.push({tox,toy});
}
}
}
}
}
ll result = 0; rep(i,H) rep(j,W) result = max(result,turn[i][j]);
cout << result << endl;
return 0;
}
| 0
| 91,539,951
|
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007
ull modpow(ll n,ll r){
ll res = 1;
while(r){
if(r & 1)res = res*n%MOD;
n = n*n %MOD;
r >>= 1;
}
return res;
}
int main(){
string s;
cin >> s;
ull res = 0,cnt = 0;
int n = s.size();
rep(i,n){
if(s[i] == '1'){
(res += modpow(3,n-i-1)*modpow(2,cnt))%=MOD;
cnt++;
}
}
(res += modpow(2,cnt))%=MOD;
cout << res << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
vector<pair<pair<int,int>, int>> city(M);
vector<pair<int, int>> ans(M);
for (int i = 0; i < M; i++) {
int P, Y;
cin >> P >> Y;
pair<int, int> p = make_pair(P,Y);
city[i] = make_pair(p, i);
pair<int, int> q = make_pair(P, 0);
ans[i] = q;
}
sort(city.begin(), city.end());
int lower = 1;
vector<pair<int,int>> junban(M);
for (int i = 0; i < M; i++) {
if (city[i].first.first == city[i+1].first.first) {
ans[city[i].second].second = lower;
lower++;
} else {
pair<int, int> q = make_pair(city[i].second, lower);
ans[city[i].second].second = lower;
lower = 1;
}
}
for (int i = 0; i < M; i++) {
printf("%06d", ans[i].first);
printf("%06d", ans[i].second);
cout << endl;
}
}
| 0
| 22,997,443
|
#include <bits/stdc++.h>
#define pb push_back
#define tam 5010
#define se second
#define fi first
#define pitem item*
#define forr(i,p,n) for(ll i=p;i<n;i++)
using namespace std;
typedef long long ll;
const ll MOD=1000000007 ;
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll add(ll a, ll b, ll p=MOD){return (a%p + b%p)%p;}
typedef pair<ll,ll> ii;
typedef vector<vector<ll> > vvi;
typedef double lld;
int dpiz[tam][tam],dpder[tam][tam];
int main()
{
int n,val,Y;
scanf("%d %d",&n,&Y);
vector<int> v;
int ans=0;
forr(i,0,n)
{
scanf("%d",&val);
if (val>=Y)
{
ans++;
continue;
}
v.pb(val);
}
n=v.size();
ans=0;
memset(dpiz,0,sizeof dpiz);
memset(dpder,0,sizeof dpder);
dpiz[0][0]=dpder[n+1][0]=1;
int posi,num;
forr(i,0,v.size())
{
num=v[i];
for(int k=Y-1;k>=0;k--)
{
if (dpiz[i][k]==1)
{
dpiz[i+1][k]=1;
if (k+num<Y)
dpiz[i+1][k+num]=1;
}
}
}
for(int i=v.size();i>=1;i--)
{
num=v[i-1];
for(int k=Y-1;k>=0;k--)
{
if (dpder[i+1][k]==1)
{
dpder[i][k]=1;
if (num+k<Y)
dpder[i][num+k]=1;
}
}
}
forr(i,1,n+1)
{
num=v[i-1];
set<int> s;
forr(k,0,Y)
if (dpiz[i-1][k]==1)
s.insert(k);
bool cond=0;
forr(k,0,Y)
{
if (dpder[i+1][k]==1)
{
ll delta=(Y-num)-k;
set<int>::iterator ite=s.lower_bound(delta);
if (ite!=s.end()&& *ite+k<Y&& *ite+num+k>=Y)
{
cond=1;
break;
}
}
}
if (cond==0)
ans++;
}
printf("%d\n",ans);
}
|
#include <iostream>
#include <bitset>
#include <algorithm>
typedef long long ll;
const ll MAXN = 1e6+5;
std::bitset<MAXN> is;
int pr[MAXN], primes = 0;
void sieve() {
is[2] = true; pr[primes++] = 2;
for (int i = 3; i < MAXN; i += 2) is[i] = 1;
for (ll i = 3; i*i < MAXN; i += 2)
if (is[i])
for (ll j = i*i; j < MAXN; j += i)
is[j]= 0;
for (int i = 3; i < MAXN; i += 2)
if (is[i])
pr[primes++] = i;
}
ll N;
int main() {
sieve();
std::cin >> N;
ll ans = 0;
for (int i = 0; i < primes; ++i) {
if (pr[i] > N) break;
int cnt = 0;
while (N % pr[i] == 0) {
cnt++;
N /= pr[i];
}
for (int j = 1; j <= cnt; j++) {
ans++;
cnt -= j;
}
}
if (N != 1)
ans++;
std::cout << ans << "\n";
return 0;
}
| 0
| 9,666,230
|
#include<bits/stdc++.h>
using namespace std;
const long long MOD=1000000007;
long long a[100100],b[100100];
main()
{
long long n,m;
long long suma=0;
long long sumb=0;
long long ans=0;
scanf("%lld %lld",&n,&m);
for(long long i=0;i<n;i++)
scanf("%lld",&a[i]);
for(long long i=0;i<m;i++)
scanf("%lld",&b[i]);
long long total=0;
for(long long i=0;i<n;i++)
{
total+=(i)*a[i]-suma;
total%=MOD;
suma+=a[i];
suma%=MOD;
}
long long total2=0;
for(long long i=0;i<m;i++)
{
total2+=(i)*b[i]-sumb;
total2%=MOD;
sumb+=b[i];
sumb%=MOD;
}
printf("%lld\n",(total*total2)%MOD);
}
|
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
using namespace std;
typedef long long lint;
const int MAXN = 100100;
vector<pair<int, int> > G[MAXN];
lint depth[MAXN];
bool visited[MAXN];
bool dfs(int v, lint d) {
depth[v] = d;
visited[v] = true;
for (const auto e : G[v]) {
if (visited[e.first]) {
if (depth[e.first] != d + e.second) {
return false;
}
} else {
if (!dfs(e.first, d + e.second)) {
return false;
}
}
}
return true;
}
int main() {
int N, M;
cin >> N >> M;
for (int i = 0; i < M; i++) {
int l, r, d;
cin >> l >> r >> d;
--l; --r;
G[l].emplace_back(r, d);
G[r].emplace_back(l, -d);
}
for (int i = 0; i < N; i++) {
if (visited[i]) continue;
if (!dfs(i, 0)) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
return 0;
}
| 0
| 68,630,215
|
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
signed main(){
int n;cin>>n;
vector<int> a(n);
vector<int> b(n);
vector<P> sum(n);
int A=0;
int T=0;
rep(i,n){
cin>>a[i]>>b[i];
sum[i].first=a[i]+b[i];
sum[i].second=i;
}
sort(sum.begin(),sum.end());
for(int i=n-1;i>=0;--i){
if((n-1-i)%2==0){
T+=a[sum[i].second];
}
else{
A+=b[sum[i].second];
}
}
cout<<T-A<<endl;
return 0;
}
|
#include <iostream>
using namespace std;
const int maxn = 1e5 + 5;
int A, B, M, a[maxn], b[maxn], x[maxn], y[maxn], c[maxn];
int main() {
cin >> A >> B >> M;
for (int i=0; i<A; i++) {
cin >> a[i];
}
for (int i=0; i<B; i++) {
cin >> b[i];
}
for (int i=0; i<M; i++) {
cin >> x[i] >> y[i] >> c[i];
}
int ans = 0, besta = a[0], bestb = b[0];
for (int i=0; i<A; i++) {
besta = min(besta, a[i]);
}
for (int i=0; i<B; i++) {
bestb = min(bestb, b[i]);
}
ans = besta + bestb;
for (int i=0; i<M; i++) {
ans = min(ans, a[x[i] - 1] + b[y[i] - 1] - c[i]);
}
cout << ans << "\n";
}
| 0
| 18,202,603
|
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,x,y;
cin>>a>>b>>x>>y;
int aa=max(a,x);
int bb=min(b,y);
if(bb<aa)cout<<0<<endl;
else cout<<bb-aa<<endl;
}
|
#include<iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <iomanip>
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i=0; i<(ll)(n); ++i)
#define mod 1000000007
vector<ll>to[1000005];
int main(){
ll a;cin>>a;
string b,c;cin>>b>>c;
for(ll i=0;i<a;i++){
string d=b.substr(i,a),e=c.substr(0,a-i);
if(d==e)
{
cout<<a+i;
return 0;
}
}
cout<<a*2;
}
| 0
| 25,514,378
|
#include <iostream>
using namespace std;
int main()
{
string str;
while (cin >> str, str != "#") {
int hand = -1, res = -1;
for (int i = 0; i < str.length(); i++) {
if (str[i] == 'y' || str[i] == 'u' || str[i] == 'i' || str[i] == 'o' || str[i] == 'p'
|| str[i] == 'h' || str[i] == 'j' || str[i] == 'k' || str[i] == 'l' || str[i] == 'n' || str[i] == 'm') {
if (hand != 0) {
hand = 0;
res++;
}
}
else {
if (hand != 1) {
hand = 1;
res++;
}
}
}
cout << res << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
int main() {
int N;
std::string str1, str2;
int point1, point2;
point1 = point2 = 0;
std::cin >> N;
for(int i = 0; i < N; ++i) {
std::cin >> str1 >> str2;
if( str1 > str2 ) {
point1 += 3;
}
else if( str1 < str2 ) {
point2 += 3;
}
else {
point1 += 1;
point2 += 1;
}
}
std::cout << point1 << " " << point2 << std::endl;
return 0;
}
| 0
| 86,514,124
|
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;
int main(){
while (1){
int n;
cin >> n;
if (n == 0) break;
vector<int> num;
for (int i = 0; i < n; i++){
int tmp;
cin >> tmp;
num.push_back(tmp);
}
int max = -1;
int min = 99999;
int sum = 0;
for (int i = 0; i < num.size(); i++){
if (num[i] >= max) max = num[i];
if (num[i] <= min) min = num[i];
sum += num[i];
}
int avg = floor((sum - max - min) / (n - 2));
cout << avg << endl;
}
return 0;
}
|
#pragma GCC diagnostic ignored "-Wunused-variable"
#include <bits/stdc++.h>
using namespace std;
#define BOOST
#ifdef BOOST
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/range/adaptor/reversed.hpp>
using namespace boost;
using ml = boost::multiprecision::cpp_int;
using md = boost::multiprecision::cpp_dec_float_100;
#define forir(i, ...) if(ll i=(ll)v.size())for(__VA_ARGS__)if(i--,1)
#define eachr(i, e, c) forir(i, auto &&e: adaptors::reverse(c))
#endif
using ll = long long;
using ld = long double;
using pll = pair<long long, long long>;
template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;
template <class T> using vvvt = vector<vector<vector<T>>>;
#define all(c) (c).begin(), (c).end()
#define coutd cout << fixed << setprecision(10)
#define output(x) do{cout<<x;return 0;}while(0)
#define rep(i, b, e) for (ll i = b; i < e; i++)
#define repr(i, b, e) for (ll i = b; e < i; i--)
#define fori(i, ...) if (ll i = -1) for(__VA_ARGS__) if (i++, 1)
#define each(i, e, c) fori (i, auto&& e: c)
#define llong_max 9223372036854775807
#define ldbl_max 1.79769e+308
#define pi 3.1415926535897932
auto Ceil = []
(auto x) { return (ll)ceil(x); };
auto Count = []
(auto b, auto e, auto x) { return (ll)count(b, e, x); };
auto CtoL = []
(auto c) { return (ll)c - (ll)'0'; };
auto LtoC = []
(auto n) { return (char)('0' + n); };
auto Pow = []
(auto a, auto b) { return (ll)pow(a, b); };
auto Pow2 = []
(auto n) { return (1LL << n); };
auto Pow10 = []
(auto n) { return (ll)pow(10, n); };
auto Size = []
(auto& c) { return (ll)(c).size(); };
auto Sum = []
(auto b, auto e) { return accumulate(b, e, 0LL); };
template <class T> void MakeVVT
(ll ys, ll xs, vvt<T>& v, T fill = T())
{
v.resize(ys); rep(y, 0, ys) v[y].resize(xs, fill);
}
template <class T> void MakeVVVT
(ll zs, ll ys, ll xs, vvvt<T>& v, T fill = T())
{
v.resize(zs); rep(z, 0, zs) MakeVVT(ys, xs, v[z], fill);
}
template <class T> void InputVT
(ll xs, vt<T>& v, T fix = T())
{
v.resize(xs); rep(i, 0, xs) { cin >> v[i]; v[i] += fix; }
}
template <class T> void InputVVT
(ll ys, ll xs, vvt<T>& v, T fix = T())
{
MakeVVT(ys, xs, v, fix);
rep(y, 0, ys) rep(x, 0, xs) { cin >> v[y][x]; v[y][x] += fix; }
}
template <class T> void InputVVVT
(ll zs, ll ys, ll xs, vvvt<T>& v, T fix = T())
{
v.resize(zs); rep(z, 0, zs) InputVVT(ys, xs, v[z], fix);
}
namespace NyaGadget {}
namespace NyaGadget
{
struct NT_NyaaNumberEnumeration
{
std::vector<long long> test;
void Run(std::pair<long long, long long> range, long long size, std::vector<std::vector<long long>>& res)
{
if ((long long)test.size() == size)
{
res.push_back(test);
return;
}
for (long long i = range.first; i <= range.second; ++i)
{
if (Size(test) != 0 && 1 < abs(test.back() - i)) continue;
test.push_back(i);
Run(range, size, res);
test.pop_back();
}
}
};
}
using namespace NyaGadget;
int main(void)
{
ll K; cin >> K;
set<ll> ans;
rep(k, 1, 11)
{
std::vector<std::vector<long long>> res;
NT_NyaaNumberEnumeration nne;
nne.Run({ 0,9 }, k, res);
each(i, e, res)
{
ll test = 0;
rep(j, 0, Size(e)) test += Pow10(j) * e[j];
ans.insert(test);
}
}
each(i, e, ans) if (i == K) cout << e;
return 0;
}
| 0
| 58,312,168
|
#include <iostream>
int main() {
int N, X, T;
int ans;
std::cin >> N >> X >> T;
ans = N / X;
if(N % X != 0) {
ans++;
}
std::cout << ans * T << std::endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int k, s;
int x, y, z;
int formas = 0;
cin >> k >> s;
for (int x = 0; x <= k; x++) {
for (int y = 0; y <= k; y++) {
z = s - x - y;
if (z >= 0 && z <= k) formas++;
}
}
cout << formas;
}
| 0
| 77,712,507
|
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <limits>
#include <bits/stdc++.h>
#include<queue>
#include<type_traits>
#include<cstdint>
using namespace std;
using ll=long long;
int main(){
while(1){
int n;
cin >> n;
if(n==0){
break;
}
vector<ll> vec(n);
for(int i=0;i<n;i++){
int x;
cin >> x;
vec[i]=x;
}
ll MIN=1e9;
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
MIN = min(abs(vec[i]-vec[j]),MIN);
}
}
cout << MIN <<endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
int n;
cin >> n;
vector<double> vec(n + 1);
cout << fixed << setprecision(6);
for (int i = 1; i <= n; i++)
{
cin >> vec[i];
}
double ans = 0;
for (int i = 1; i < n; i++)
{
sort(vec.begin(), vec.end());
ans = (vec[i] + vec[i + 1]) / 2;
vec[i + 1] = ans;
}
cout << vec[n] << endl;
}
| 0
| 24,805,562
|
#include <bits/stdc++.h>
using namespace std;
using Point = pair<int,int>;
int main()
{
int N,K;
cin >> N >> K;
vector<long long> h(N);
for(int i=0;i<N;i++)
{
cin >> h[i];
}
long long ans = LONG_LONG_MAX;
for(int bit = 0;bit < (1<<N);bit++)
{
vector<int> used;
for(int i=0;i<N;i++)
{
if(bit & (1 << i))
{
used.push_back(i);
}
}
if(used.size() < K)
{
continue;
}
long long temp = 0;
vector<long long> a(N);
a=h;
for(int i = 0;i<used.size();i++)
{
for(int j = 0;j<used[i];j++)
{
long long k =a[j]-a[used[i]] + 1;
if(k>0)
{
a[used[i]] += k;
temp += k;
}
}
}
ans = min(temp,ans);
}
cout << ans << endl;
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
using namespace std;
int main() {
ll n;
cin >> n;
ll a[n + 1];
ll b[n];
for(ll i = 0; i < n + 1; ++i) {
cin >> a[i];
}
for(ll i = 0; i < n; ++i) {
cin >> b[i];
}
ll beat = 0;
for(ll i = 0; i < n; ++i) {
if(a[i] >= b[i]) {
beat += b[i];
a[i] -= b[i];
b[i] -= b[i];
} else {
beat += a[i];
b[i] -= a[i];
a[i] -= a[i];
}
if(a[i + 1] >= b[i]) {
beat += b[i];
a[i + 1] -= b[i];
b[i] -= b[i];
} else {
beat += a[i + 1];
b[i] -= a[i + 1];
a[i + 1] -= a[i + 1];
}
}
cout << beat << endl;
}
| 0
| 87,052,698
|
#include <bits/stdc++.h>
using namespace std;
int n,a,b,cost;
vector<int>ans;
int main(){
scanf("%d%d%d",&n,&a,&b);
if(a*1LL*b < n || a + b - 1 > n)return puts("-1"),0;
for(int i = n - a + 1;i <= n;i++)ans.push_back(i);
n-=a;
for(int i = b - 1;i >= 1;i--){
int t = min(n - i + 1,a);
for(int j = n - t + 1;j <= n;j++)ans.push_back(j);
n-=t;
}
for(auto i : ans)printf("%d ",i);
}
|
#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;
cin>>n;
string s,t;
cin>>s>>t;
string s_t;
for(int i=0;i<n;i++)
{
s_t.push_back(s[i]);
s_t.push_back(t[i]);
}
cout<<s_t<<endl;
return 0;
}
| 0
| 50,468,441
|
#include <iostream>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
if((a==1 && b==2) || (a==2 && b==1)) cout << "3" << endl;
else if((a==1 && b==3) || (a==3 && b==1)) cout << "2" << endl;
else if((a==2 && b==3) || (a==3 && b==2)) cout << "1" << endl;
return 0;
}
|
#include <iostream>
#include <set>
#include <iterator>
#include <utility>
using namespace std;
int q[100001];
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, p;
cin >> n;
for (int i = 1; i <= n; i++){
cin >> p;
q[p] = i;
}
set <int> myset;
myset.insert(-1); myset.insert(0); myset.insert(n+1); myset.insert(n+2);
set <int> :: iterator it;
int i, j;
long long a, b, c, d, x, y;
long long ans = 0;
for (i = n; i > 0; i--){
j = q[i];
it = myset.insert(j).first;
b = *(--it); a = *(--it);
++it; ++it;
c = *(++it); d = *(++it);
x = (a == -1) ? 0 : (c - j)*(b - a);
y = (d == n+2) ? 0 : (d - c)*(j - b);
ans += (x + y) * i;
}
cout << ans << '\n';
}
| 0
| 93,849,796
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, t;
cin >> s >> t;
sort(s.begin(), s.end());
sort(t.begin(), t.end());
vector<int> a(26, 0);
vector<int> b(26, 0);
for (int i = 0; i < s.size(); i++) {
int c = s.at(i) - 'a';
a.at(c)++;
}
for (int i = 0; i < t.size(); i++) {
int c = t.at(i) - 'a';
b.at(c)++;
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
for (int i = 0; i < 26; i++) {
if (a.at(i) != b.at(i)) {
cout << "No";
return 0;
}
}
cout << "Yes";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
typedef long long ll;
const int Inf = 1e9;
const double EPS = 1e-9;
const int MAX = 100001;
void bfs(int);
int gcd(int a, int b) {
if (b == 0) {
return a;
} else {
return gcd(b, a % b);
}
}
int lcm(int a, int b) {
return a * b / gcd(a, b);
}
int bitCount(long bits) {
bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}
vector<int> g[MAX];
bool visited[MAX];
int entry[MAX];
list<int> out;
int v;
void tsort() {
rep (i, v) entry[i] = 0;
rep (i, v) {
rep (j, g[i].size()) {
int c = g[i][j];
entry[c]++;
}
}
rep (i, v) {
if (entry[i] == 0 && !visited[i]) bfs(i);
}
for (auto iter = out.begin(); iter != out.end(); iter++) {
cout << *iter << endl;
}
}
void bfs(int s) {
queue<int> q;
q.push(s);
visited[s] = true;
while (!q.empty()) {
int t = q.front();
q.pop();
out.push_back(t);
rep (i, g[t].size()) {
int u = g[t][i];
entry[u]--;
if (entry[u] == 0 && !visited[u]) {
q.push(u);
visited[u] = true;
}
}
}
}
int main() {
int e;
cin >> v >> e;
rep (i, v) visited[i] = false;
rep (i, e) {
int s, t;
cin >> s >> t;
g[s].push_back(t);
}
tsort();
return 0;
}
| 0
| 31,146,623
|
#include <bits/stdc++.h>
using namespace std;
int main(){
vector<vector<int>> a(3, vector<int> (3, 0));
for(int i = 0; i<3; i++) {
for(int j = 0; j<3; j++) {
cin >> a[i][j];
}
}
int n;
cin >> n;
vector<int> b(n);
for(int i = 0; i<n; i++) cin >> b[i];
bool ans = false;
for(int i = 0; i < 3; i++) {
for ( int j = 0; j< 3; j++) {
for(int k = 0; k<n; k++){
if( a[i][j] == b[k] ) a[i][j] = -1;
}
}
}
if (a[0][0] == -1 && a[0][1] == -1 && a[0][2] == -1) ans = true;
else if (a[1][0] == -1 && a[1][1] == -1 && a[1][2] == -1) ans = true;
else if (a[2][0] == -1 && a[2][1] == -1 && a[2][2] == -1) ans = true;
else if (a[0][0] == -1 && a[1][0] == -1 && a[2][0] == -1) ans = true;
else if (a[0][1] == -1 && a[1][1] == -1 && a[2][1] == -1) ans = true;
else if (a[0][2] == -1 && a[1][2] == -1 && a[2][2] == -1) ans = true;
else if (a[0][0] == -1 && a[1][1] == -1 && a[2][2] == -1) ans = true;
else if (a[0][2] == -1 && a[1][1] == -1 && a[2][0] == -1) ans = true;
if(ans) puts("Yes");
else puts("No");
}
|
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
const int MAX_N = 100050;
std::string S;
int N;
int tmp[MAX_N];
void proc() {
for (int i = 2; i < S.size(); i++) {
if (tmp[i-1] == 0) {
if (S[i-1] == 'o') {
tmp[i] = tmp[i-2];
} else {
tmp[i] = 1 - tmp[i-2];
}
} else {
if (S[i-1] == 'o') {
tmp[i] = 1 - tmp[i-2];
} else {
tmp[i] = tmp[i-2];
}
}
}
}
void out() {
std::string ret;
for (int i = 0; i < S.size(); i++) {
if (tmp[i] == 0) {
ret.push_back('S');
} else {
ret.push_back('W');
}
}
std::cout << ret << std::endl;
}
bool check(const int i) {
int l = (i == 0) ? N - 1 : i - 1;
int r = (i == N - 1) ? 0 : i + 1;
if (tmp[i] == 0) {
if (S[i] == 'o') {
return tmp[l] == tmp[r];
} else {
return tmp[l] != tmp[r];
}
} else {
if (S[i] == 'o') {
return tmp[l] != tmp[r];
} else {
return tmp[l] == tmp[r];
}
}
}
int main(int argc, char **argv) {
std::cin >> N;
std::cin >> S;
for (int i0 = 0; i0 <= 1; i0++) {
for (int i1 = 0; i1 <= 1; i1++) {
tmp[0] = i0;
tmp[1] = i1;
proc();
if (check(0) && check(N-1)) {
out();
return 0;
}
}
}
std::cout << "-1" << std::endl;
return 0;
}
| 0
| 2,410,354
|
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
const int mod=1e9+7;
int main(){
int n;
cin>>n;
cout<<180+(n-3)*180<<endl;
}
|
#include <algorithm>
#include <functional>
#include <iostream>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
void solve();
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
solve();
return 0;
}
#define ini(...) \
int __VA_ARGS__; \
in(__VA_ARGS__)
#define inl(...) \
ll __VA_ARGS__; \
in(__VA_ARGS__)
#define ins(...) \
string __VA_ARGS__; \
in(__VA_ARGS__);
void in() {}
template <typename T, class... U>
void in(T& t, U&... u) {
cin >> t;
in(u...);
}
void out() {
cout << endl;
}
template <typename T, class... U>
void out(const T& t, const U&... u) {
cout << t;
if (sizeof...(u))
cout << " ";
out(u...);
}
#define rep(i, n) for (long long i = 0; i < n; i++)
void solve();
#ifndef ONLINE_JUDGE
#include "./lib.hpp"
#endif
void solve() {
inl(H, W);
ll res = 1LL << 62;
for (int w = 1; w < W; w++) {
vll S;
S.push_back(H * w);
ll w2 = (W - w) / 2;
ll w3 = W - w - w2;
S.push_back(H * w2);
S.push_back(H * w3);
sort(S.begin(), S.end());
if (S.back() - S.front() < res)
res = S.back() - S.front();
S.clear();
S.push_back(H * w);
ll h2 = H / 2;
ll h3 = H - h2;
S.push_back(h2 * (W - w));
S.push_back(h3 * (W - w));
sort(S.begin(), S.end());
if (S.back() - S.front() < res)
res = S.back() - S.front();
}
swap(H, W);
for (int w = 1; w < W; w++) {
vll S;
S.push_back(H * w);
ll w2 = (W - w) / 2;
ll w3 = W - w - w2;
S.push_back(H * w2);
S.push_back(H * w3);
sort(S.begin(), S.end());
if (S.back() - S.front() < res)
res = S.back() - S.front();
S.clear();
S.push_back(H * w);
ll h2 = H / 2;
ll h3 = H - h2;
S.push_back(h2 * (W - w));
S.push_back(h3 * (W - w));
sort(S.begin(), S.end());
if (S.back() - S.front() < res)
res = S.back() - S.front();
}
out(res);
}
| 0
| 22,626,987
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<string,int>;
const double PI = acos(-1);
int main() {
int n;
cin >> n;
vector<int> even;
vector<int> odd;
rep(i,n){
int a;
cin >> a;
if(i%2 == 0) odd.push_back(a);
else even.push_back(a);
}
if(n%2 == 0){
reverse(even.begin(),even.end());
rep(i,even.size()) cout << even.at(i) << " ";
rep(i,odd.size()) cout << odd.at(i) << " ";
}
else{
reverse(odd.begin(),odd.end());
rep(i,odd.size()) cout << odd.at(i) << " ";
rep(i,even.size()) cout << even.at(i) << " ";
}
}
|
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)
#define inf (1<<29)
int main(int argc,char* argv[]){
int n;
cin >> n;
vector<double> v(n);
for(auto &x:v)cin >> x;
sort(v.begin(),v.end());
double val=0;
for(int i=0;i<n-1;i++){
val=(v[i]+v[i+1])/2;
v[i+1]=val;
}
cout << v[n-1] << endl;
return 0;
}
| 0
| 33,299,240
|
#include<bits/stdc++.h>
using namespace std;
int main()
{
int k,n;
cin>>k>>n;
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
int total =0;
for(int i=1;i<n;i++)
{
total += a[i] - a[i-1];
}
total += a[0] + k-a[n-1];
int m = INT_MIN;
for(int i=1;i<n;i++)
{
m = max( m , a[i] - a[i-1]);
}
m = max( m , a[0] + k-a[n-1]);
cout<<total - m;
}
|
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <random>
#include <ctime>
using namespace std;
int main(){
int n,k ;
string s ;
cin >> n >> s >> k ;
char key = s.at(k-1) ;
for (int i = 0; i < s.size(); i++)
{
if (s.at(i) != key)
{
s.at(i) = '*' ;
}
}
cout << s << endl ;
}
| 0
| 25,492,124
|
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
typedef unsigned long long ull;
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define f(i,a,b) for(ll i=a;i<=b;i++)
#define testcases ll t;cin>>t;while(t--)
#define dec(x) greater<x>()
#define mx 200005
#define mod 1000000007
#define PI acos(-1.0)
#define eps 1e-7
#define size1 100005
const char nl = '\n';
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define mem(name, value) memset(name, value, sizeof(name))
typedef vector <ll> vll;
typedef set <ll> sll;
typedef multiset <ll> msll;
typedef queue <ll> qll;
typedef map <ll, ll> mll;
typedef pair <ll, ll> pll;
typedef vector <pair <ll , ll> > vpll;
#define all(v) (v).begin(), (v).end()
#define rev(v) reverse(all(v))
#define srt(v) sort(all(v))
#define srtGreat(v) sort(all(v), greater<ll>())
inline bool cmp(pll a, pll b) { if (a.ff == b.ff)return a.ss < b.ss; return a.ff > b.ff; }
#define en cout << '\n';
#define no cout << "NO" << '\n'
#define yes cout << "YES" << '\n'
#define case cout << "Case " << t++ << ": "
template <class T> inline T gcd(T a, T b) {if (b == 0)return a; return gcd(b, a % b);}
template <class T> inline T lcm(T a, T b) {return a * b / gcd<T>(a, b);}
template <class T> inline T power(T b, T p) {ll ans = 1; while (p--) ans *= b; return ans;}
void solve()
{
ld n,x,t;
cin>>n>>x>>t;
ld z=ceil(n/x);
cout<<int(z*t);
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("C:/Users/91731/Documents/input.txt", "r", stdin);
freopen("C:/Users/91731/Documents/output.txt", "w", stdout);
freopen("C:/Users/91731/Documents/error.txt", "w", stderr);
#endif
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
solve();
}
|
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <set>
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 PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()
typedef pair<double, double> XY;
XY koch(XY p, XY q, double dist) {
if (q.first > p.first) {
switch ((int)round(180.0 / acos(-1) * atan((p.second - q.second) / (p.first - q.first)))) {
case 0:
return make_pair((p.first + q.first) / 2, p.second + sqrt(3) / 2 * dist);
break;
case 60:
return make_pair(p.first * 2 - q.first, q.second);
break;
case -60:
return make_pair(q.first * 2 - p.first, p.second);
break;
default:
break;
}
}else {
switch ((int)round(180.0 / acos(-1) * atan((p.second - q.second) / (p.first - q.first)))) {
case 0:
return make_pair((p.first + q.first) / 2, p.second - sqrt(3) / 2 * dist);
break;
case 60:
return make_pair(p.first * 2 - q.first, q.second);
break;
case -60:
return make_pair(q.first * 2 - p.first, p.second);
break;
default:
break;
}
}
return make_pair(-1, -1);
}
void grow(vector<XY> &v, double dist) {
for(int i = v.size()-1; i >= 1; i--) {
XY p = v[i];
XY q = v[i-1];
XY pp, qq;
pp = make_pair((p.first * 2 + q.first) / 3, (p.second * 2 + q.second) / 3);
qq = make_pair((p.first + q.first * 2) / 3, (p.second + q.second * 2) / 3);
XY pq = koch(qq, pp, dist);
v.insert(v.begin() + i, pp);
v.insert(v.begin() + i, pq);
v.insert(v.begin() + i, qq);
}
}
void printXY(vector<XY> v) {
REP(i,v.size()) {
printf("%.8f %.8f\n", v[i].first, v[i].second);
}
}
int main() {
int n;
cin >> n;
vector<XY> v;
v.push_back(make_pair(0, 0));
v.push_back(make_pair(100, 0));
double dist = 100/3.;
REP(i,n) {
grow(v, dist);
dist /= 3;
}
printXY(v);
return 0;
}
| 0
| 35,783,618
|
#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
using ll=long long;
typedef pair<int,int> P;
int main(){
int n;
cin >> n;
int ans = 0;
for (int i=1;i<=n;i=i+2){
int tmp = 0;
for (int j=1;j<=i;j++){
if (i%j==0) tmp++;
}
if(tmp==8) ans++;
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
int main(){
ll n, m;
cin >> n >> m;
vector<vector<ll>> r(100010);
vector<ll> p(m), y(m);
rep(i, 0, m){
cin >> p[i] >> y[i];
r[p[i]].push_back(y[i]);
}
map<ll, bool> seen;
vector<map<ll, ll>> o(100010);
for(auto t : p){
if(seen[t]) continue;
seen[t] = true;
sort(r[t].begin(), r[t].end());
rep(i, 0, r[t].size()){
o[t][r[t][i]] = i + 1;
}
}
rep(i, 0, m){
string s = to_string(p[i]);
ll lm = s.size();
rep(j, 0, 6-lm){
s = "0" + s;
}
ll ty = o[p[i]][y[i]];
string ss = to_string(ty);
lm = ss.size();
rep(j, 0, 6-lm){
ss = "0" + ss;
}
cout << s + ss << endl;
}
return 0;
}
| 0
| 1,309,844
|
#define _CRT_SECURE_NO_WARNINGS
#define _SCL_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <limits>
#include <numeric>
#include <valarray>
#include <fstream>
#include <array>
#include <random>
#include <unordered_set>
#include <unordered_map>
using namespace std;
using uint = uint32_t;
using LL = int64_t;
using ULL = uint64_t;
using PP = pair<LL, LL>;
template <typename T> using PriorityQ = priority_queue<T, vector<T>, greater<T> >;
#define REP(i, a, n) for(LL i = (a), i##_max_ = (n); i < i##_max_; ++i)
#define REM(i, a, n) for(LL i = (LL)(n) - 1, i##_min_ = (a); i >= i##_min_; --i)
#define FLOAT fixed << setprecision(16)
#define SPEEDUP { cin.tie(NULL); ios::sync_with_stdio(false); }
const int INF = 0x3FFFFFFF;
const LL INFLL = 0x3FFFFFFF3FFFFFFF;
const double INFD = 1.0e+308;
const double EPS = 1.0e-9;
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
template <class T, class U> istream& operator>>(istream& ist, pair<T, U>& right) { return ist >> right.first >> right.second; }
template <class T, class U> ostream& operator<<(ostream& ost, const pair<T, U>& right) { return ost << right.first << ' ' << right.second; }
template <class T, class TCompatible, size_t N> void Fill(T(&dest)[N], const TCompatible& val) { fill(dest, dest + N, val); }
template <class T, class TCompatible, size_t M, size_t N> void Fill(T(&dest)[M][N], const TCompatible& val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); }
template <class T> T Next() { T buf; cin >> buf; return buf; }
istream& Ignore(istream& ist) { string s; ist >> s; return ist; }
bool Inside(int i, int j, int h, int w) { return i >= 0 && i < h && j >= 0 && j < w; }
#ifdef ONLY_MY_ENVIR
#include "Accumulator.h"
#include "Algebraic.h"
#include "BinaryMatrix.h"
#include "BinaryTree.h"
#include "Bipartite.h"
#include "BIT.h"
#include "Compressor.h"
#include "Decompositions.h"
#include "DynamicMod.h"
#include "Factorization.h"
#include "FFT.h"
#include "FlowSolver.h"
#include "Graph.h"
#include "GraphUtil.h"
#include "IntMod.h"
#include "LazySegmentTree.h"
#include "LIS.h"
#include "Math.h"
#include "MathUtil.h"
#include "Matrix.h"
#include "MinCostFlowSolver.h"
#include "MinMax.h"
#include "Numbers.h"
#include "Optimize.h"
#include "Permutation.h"
#include "Polynomial.h"
#include "Position.h"
#include "Range.h"
#include "Rational.h"
#include "SegmentTree.h"
#include "SegmentTree2D.h"
#include "Sets.h"
#include "Shortest.h"
#include "SlidingWindow.h"
#include "SpanningTree.h"
#include "StringSearching.h"
#include "SuffixArray.h"
#include "Tree.h"
#include "TreeUtil.h"
#include "UnionFind.h"
#include "Util.h"
#include "VectorUtil.h"
#endif
#ifdef __GNUC__
typedef __int128 LLL;
istream& operator>>(istream& ist, __int128& val) { LL tmp; ist >> tmp; val = tmp; return ist; }
ostream& operator<<(ostream& ost, __int128 val) { LL tmp = val; ost << tmp; return ost; }
#endif
int K, N;
LL A[15];
LL sub(int s) {
LL prev = 0;
LL sum = 0;
REP(i, 0, N) {
LL h = A[i];
if (s >> i & 1) {
if (A[i] <= prev) {
sum += prev - A[i] + 1;
}
h = max(prev + 1, A[i]);
}
prev = max(prev, h);
}
return sum;
}
int main() {
cin >> N >> K;
REP(i, 0, N) cin >> A[i];
LL mn = INFLL;
REP(s, 0, 1 << N) {
if (bitset<16>(s).count() != K) continue;
mn = min(mn, sub(s));
}
cout << mn << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
typedef long long ll;
static const ll MX = 100005;
static const ll MX_ll = 1e18;
const double PI = acos(-1);
using namespace std;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
int changeDoubleToInt(string decimal){
decimal.erase(1, 1);
int n_decimal = atoi(decimal.c_str());
return n_decimal;
}
int main(){
int n, m, x;
cin >> n >> m >> x;
int c[n], a[n][m];
rep(i, n){
cin >> c[i];
rep(j, m){
cin >> a[i][j];
}
}
int ans = 1001001001;
rep(s, 1<<n){
int cost = 0;
vector<int> d(m);
rep(i, n){
if(s>>i&1){
cost += c[i];
rep(j,m) d[j] += a[i][j];
}
}
bool ok = true;
rep(j,m) if(d[j] < x) ok = false;
if(ok) ans = min(ans, cost);
}
if(ans==1001001001) cout << -1 << endl;
else cout << ans << endl;
return 0;
}
| 0
| 1,267,306
|
#include <bits/stdc++.h>
using namespace std;
int main(){
int N,A,B,C,F=1,Q=167167167;
cin>>N>>A>>B>>C;
vector<int> l(N);
for(int i=0;i<N;i++){
cin>>l[i];
F*=4;
}
for(int i=1;i<F;i++){
int D=i,X=0,Y=0,Z=0,K=0;
for(int j=0;j<N;j++){
if(D%4==1){
X+=l[j];
}
else if(D%4==2){
Y+=l[j];
}
else if(D%4==3){
Z+=l[j];
}
else{
K++;
}
D/=4;
}
if(X*Y*Z){
Q=min(Q,abs(A-X)+abs(B-Y)+abs(C-Z)+10*(N-K-3));
}
}
cout<<Q<<endl;
}
|
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
int find(string s,string keyword){
int count = 0;
string::size_type pos = s.find(keyword);
while(pos != string::npos){
count++;
pos = s.find(keyword,pos+keyword.length());
}
return count;
}
int main() {
int n;
cin >> n;
vector<string> s(n);
rep(i,n) cin >> s[i];
int ans = 0,ab=0,a=0,b=0;
rep(i,n){
if(s[i].back() == 'A' && s[i].front() == 'B') ab++;
else if(s[i].back() == 'A') a++;
else if(s[i].front() == 'B') b++;
ans+=find(s[i],"AB");
}
int m = min(a,b);
if(a || b){
m = m + ab;
}
else m=max(0,ab-1);
ans = ans+m;
cout<<ans<<endl;
return 0;
}
| 0
| 24,974,843
|
#include<iostream>
using namespace std;
int main(){
while(1){
int h,w;
cin >> h >> w;
if(h == 0 && w == 0){
break;
}
for(int n = 0; n < h; n++){
for(int m = 0; m < w; m++){
cout << "#";
}
cout << endl;
}
cout << endl;
}
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define fast() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define test() ll t; cin>>t; while(t--)
#define lp0(i,begin,end) for(ll i=begin;i<end;i++)
#define lp1(i,begin,end) for(ll i=begin;i<=end;i++)
#define rlp(i,begin,end) for(ll i=end;i>=begin;i--)
#define prec(n) fixed<<setprecision(n)
#define initial(a,i) memset(a,i,sizeof(a))
#define pb push_back
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define F first
#define S second
#define all(a) (a).begin(),(a).end()
#define BPC(x) __builtin_popcountll(x)
#define gcd(a,b) __gcd(a,b)
ll gcd(ll a,ll b) {if (a==0) return b;return gcd(b%a,a);}
ll power(ll x,ll n)
{
ll result = 1;
while (n)
{
if (n & 1)
result = result * x;
n = n / 2;
x = x * x;
}
return result;
}
void solution(ll compte)
{
string s, t;
cin >> s >> t;
t.pop_back();
if (s == t)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
int main()
{
ll compte = 1;
solution(compte);
compte++;
return 0;
}
| 0
| 86,512,716
|
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
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;}
#define int ll
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
os<<"("<<p.first <<", "<<p.second<<")";
return os;
}
signed main(){
cin.tie(0);
ios::sync_with_stdio(0);
int n;cin>>n;
map<int,int> mp,mpp;
rep(i,n){
int a;cin>>a;
mp[a]++;
}
for(auto p:mp) mpp[p.second]++;
vector<pair<int,int>> v;
v.push_back(make_pair(INF,0));
for(auto p:mpp)v.push_back(p);
sort(ALL(v));reverse(ALL(v));
vector<int> ans(n+1);
int var=(int)mp.size();
ans[var]=v.back().first;
for(int i=var+1;i<=n;i++) ans[i]=0;
for(int k=var-1;k>1;k--){
auto p=v.back();v.pop_back();
int rem=p.first;
if(p.second>1)v.push_back(make_pair(p.first,p.second-1));
while(rem){
auto pn=v.back();v.pop_back();
int need=(v.back().first-pn.first)*pn.second;
if(rem>=need){
rem-=need;
auto pnn=v.back();v.pop_back();
pnn.second=pnn.second+pn.second;
v.push_back(pnn);
}else{
pair<int,int> fs=make_pair(pn.first+rem/pn.second+1,rem%pn.second);
if(fs.second!=0){
if(v.back().first==fs.first){
fs.second+=v.back().second;v.pop_back();
v.push_back(fs);
}else{
v.push_back(fs);
}
}
pair<int,int> sc=make_pair(pn.first+rem/pn.second,pn.second-rem%pn.second);
if(v.back().first==sc.first){
sc.second+=v.back().second;v.pop_back();
v.push_back(sc);
}else{
v.push_back(sc);
}
rem=0;
}
}
ans[k]=v.back().first;
}
ans[1]=n;
for(int i=1;i<=n;i++) cout<<ans[i]<<endl;
return 0;
}
|
#include<bits/stdc++.h>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));
const int MOD = 1000000007;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
int main() {
string s, t; cin >> s >> t;
int n = s.size();
int m = t.size();
int idx = -1;
for(int i = 0; i < n-m+1; ++i){
bool flg = true;
for(int j = 0; j < m; ++j){
if(s[i+j]!='?' && s[i+j] != t[j]) flg = false;
}
if(flg) idx = i;
}
if(idx == -1) cout << "UNRESTORABLE" << endl;
else{
for(int i = idx; i < idx+m; i ++){
s[i] = t[i-idx];
}
rep(i,n){
if(s[i] == '?') cout << 'a';
else cout << s[i];
}
}
return 0;
}
| 0
| 95,797,264
|
#include <bits/stdc++.h>
using namespace std;
void solve(long long N, std::string S, std::string T){
for(int i = 0; i < N; ++i){
cout << S[i] << T[i];
}
cout << endl;
return;
}
int main(){
long long N;
scanf("%lld",&N);
std::string S;
std::cin >> S;
std::string T;
std::cin >> T;
solve(N, S, T);
return 0;
}
|
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int cou[200004];
vector<int> edge[200004];
int ans[200004];
void func(int pos,int nowcou,int bef){
int nowans=nowcou+cou[pos];
ans[pos]=nowans;
for(int i=0;i<edge[pos].size();i++){
if(edge[pos][i]!=bef)func(edge[pos][i],nowans,pos);
}
}
int main(){
int N,Q;
cin>>N>>Q;
for(int i=0;i<N-1;i++){
int a,b;
cin>>a>>b;
edge[a].push_back(b);
edge[b].push_back(a);
}
for(int i=0;i<Q;i++){
int a,b;
cin>>a>>b;
cou[a]+=b;
}
func(1,0,-1);
for(int i=1;i<=N;i++){
cout<<ans[i];
if(i!=N)cout<<' ';
}
cout<<endl;
return 0;
}
| 0
| 30,548,619
|
#include <iostream>
using namespace std;
int main(){
int n,m;
cin >> n >> m;
int ev = n*(n-1) / 2;
int od = m*(m-1) / 2;
int ans = ev + od;
cout << ans << endl;
}
|
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll=long long;
using ld=long double;
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
if (i == 0) return 1;
return (fact(i - 1)) * i;
}
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int lcm(int a, int b) {
return a * b / gcd(a, b);
}
int keta(int n) {
if (n == 0) return 1;
int count = 0;
while (n != 0) {
n /= 10;
count++;
}
return count;
}
int ketasum(int n) {
int sum = 0;
while (n != 0) {
sum += n % 10;
n /= 10;
}
return sum;
}
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;
}
char toSmall(char c) {
return (c + 0x20);
}
char toLarge(char c) {
return (c - 0x20);
}
float myPower(int a, int n) {
float x = 1;
while (n > 0) {
if (n & 1) {
x *= a;
}
a *= a;
n >>= 1;
}
return x;
}
string a, b, c;
int main(void) {
cin >> a >> b >> c;
cout << (char)(a[0] - 32) << (char)(b[0] - 32) << (char)(c[0] - 32) << endl;
return 0;
}
| 0
| 1,503,197
|
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<algorithm>
#define MOD (1000000007)
using namespace std;
typedef long long int Int;
int main(void) {
int n;
vector<int> a;
cin>>n;
for(int i = 0;i < n;i++) {
int temp;
cin>>temp;
a.push_back(temp);
}
sort(a.begin(),a.end());
if(n == 2) {
cout<<a[1]<<" "<<a[0]<<endl;
return 0;
}
int temp = a[n-1]/2;
int min_diff = 1e9;
int value = -1;
for(int i = 0;i < n;i++) {
if(abs(a[i] - temp) <= min_diff)
{
min_diff = abs(a[i] - temp);
value = a[i];
}
}
cout<<a[n-1]<<" "<<value<<endl;
return 0;
}
|
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
#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>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define ALL(n) begin(n),end(n)
#define IN(a, x, b) (a<=x && x<b)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
template<class T> inline T CHMAX(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T & a, const T b) { return a = (a > b) ? b : a; }
const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
const long long MOD = 1000000007;
char ans[100010];
string s;
bool solve_common(void){
bool badans = false ;
char tmp;
REP(i, s.size()){
if(i ==0){
continue;
}
if(ans[i] == 'S'){
if(s[i] == 'o'){
if( ans[i-1] == 'S' ){
tmp = 'S' ;
}else if( ans[i-1] == 'W'){
tmp = 'W' ;
}
}
if(s[i] == 'x'){
if( ans[i-1] == 'S' ){
tmp = 'W' ;
}else if( ans[i-1] == 'W'){
tmp = 'S' ;
}
}
}else{
if(s[i] == 'x'){
if( ans[i-1] == 'S' ){
tmp = 'S' ;
}else if( ans[i-1] == 'W'){
tmp = 'W' ;
}
}
if(s[i] == 'o'){
if( ans[i-1] == 'S' ){
tmp = 'W' ;
}else if( ans[i-1] == 'W'){
tmp = 'S' ;
}
}
}
if(i==s.size()-2){
if(ans[s.size()-1] != tmp){
badans = true;
break;
}
if( ans[s.size()-1] == 'S'){
if( s[s.size()-1] == 'o' && ans[s.size()-2] != ans[0]){
badans = true;
break;
}
if( s[s.size()-1] == 'x' && ans[s.size()-2] == ans[0]){
badans = true;
break;
}
ans[i+1] =tmp;
break;
}else{
if( s[s.size()-1] == 'o' && ans[s.size()-2] == ans[0]){
badans = true;
break;
}
if( s[s.size()-1] == 'x' && ans[s.size()-2] != ans[0]){
badans = true;
break;
}
ans[i+1] =tmp;
break;
}
}else{
ans[i+1] =tmp;
}
}
return badans;
}
bool solve_1(void){
ans[0] = 'S';
if(s[0] == 'o'){
ans[1] = 'S';
ans[s.size()-1] = 'S';
}
if(s[0] == 'x'){
ans[1] = 'S';
ans[s.size()-1] = 'W';
}
return solve_common();
}
bool solve_2(void){
ans[0] = 'S';
if(s[0] == 'o'){
ans[1] = 'W';
ans[s.size()-1] = 'W';
}
if(s[0] == 'x'){
ans[1] = 'W';
ans[s.size()-1] = 'S';
}
return solve_common();
}
bool solve_3(void){
ans[0] = 'W';
if(s[0] == 'o'){
ans[1] = 'S';
ans[s.size()-1] = 'W';
}
if(s[0] == 'x'){
ans[1] = 'W';
ans[s.size()-1] = 'W';
}
return solve_common();
}
bool solve_4(void){
ans[0] = 'W';
if(s[0] == 'o'){
ans[1] = 'W';
ans[s.size()-1] = 'S';
}
if(s[0] == 'x'){
ans[1] = 'S';
ans[s.size()-1] = 'S';
}
return solve_common();
}
int main(void){
ll n;
cin >> n;
cin >> s;
bool bad_ans = false ;
bad_ans = solve_1();
if(bad_ans){
bad_ans = solve_2();
}
if(bad_ans){
bad_ans = solve_3();
}
if(bad_ans){
bad_ans = solve_4();
}
if(bad_ans){
cout << -1 << endl;
}else{
cout << ans << endl;
}
return 0;
}
| 0
| 40,728,320
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int, int>;
int main()
{
int a, b, c;
cin >> a >> b >> c;
if(a == b && a == c) cout << "Yes" << endl;
else cout << "No" << 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>;
int main() {
int n;
cin >> n;
vector<string> a, b, ab, c;
int count = 0;
rep(i,n) {
string s;
cin >> s;
int pos = s.find("AB");
while (pos != string::npos) {
count++;
if (pos+2 < s.size()) pos = s.find("AB", pos+2);
else break;
}
if(s.at(0) == 'B' && s.at(s.size()-1) == 'A') ab.push_back(s);
else if (s.at(0) == 'B') b.push_back(s);
else if (s.at(s.size() - 1) == 'A') a.push_back(s);
else c.push_back(s);
}
int minab = min(a.size(), b.size());
int maxab = max(a.size(), b.size());
count += minab;
if(0 < ab.size() && 0 == maxab) count += ab.size() - 1;
else count += ab.size();
cout << count << endl;
return 0;
}
| 0
| 33,151,224
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0 , -1};
signed main() {
int N;
cin >> N;
vector<int>A(N);
set<int>Set;
for(int i = 0; i < N; i++) {
cin >> A[i];
Set.insert(A[i]);
}
cout << Set.size()-(N-Set.size())%2 << endl;
return 0;
}
|
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <math.h>
#include <cmath>
#include <stdlib.h>
using namespace std;
#define int long long
#define endl "\n"
#define all(v) v.begin(),v.end()
#define fir first
#define sec second
#define m_p make_pair
#define m_t make_tuple
#define rep(i,n) for(int i=0; i<(int) (n); i++)
const double pai = 3.1415926535897;
const int mod = 1000000007;
const int INF = 1000000021;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
int z00 = 1;
for (int i = 0; i < y00; i++) {
z00 *= x00;
}
return z00;
}
int keta(int x00) {
int z00 = x00;
int w00 = 0;
while (z00 != 0) {
z00 /= 10;
w00++;
}
return w00;
}
int krag(double xx) {
return INF - (int)(INF - xx);
}
int b_s(vector<int>& vec, int xx) {
return lower_bound(all(vec),xx)-vec.begin();
}
template<typename T>
void vecout(vector<T>& vec) { for (T t : vec) cout << t << " "; cout << endl; }
template<typename TT>
void vecin(vector<TT>& vec) {
for (int i = 0; i < vec.size(); i++) {
cin >> vec[i];
}
}
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
long long 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;
}
long long modinv(long long a, long long m) {
long long b = m, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
u %= m;
if (u < 0) u += m;
return u;
}
int modpow(int a, int n) {
int res = 1;
while (n > 0) {
if (n & 1) res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
int gcd(int xx, int yy) {
int p = xx;
int q = yy;
if (q > p)swap(p, q);
while (p % q != 0) {
p %= q;
swap(p, q);
}
return q;
}
int lcm(int xx, int yy) {
return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
if (xx <= 1) {
return 0;
}
for (int i = 2; i*i <= xx; i++) {
if (xx % i == 0) {
return 0;
}
}
return 1;
}
signed main() {
int n,a,ans=0;
cin >> n;
map<int, int>ma;
rep(i, n) {
cin >> a;
if (!ma.count(a)) {
ma[a] = 1;
}
else {
ma[a]++;
}
}
for (auto p : ma) {
auto k = p.first;
auto v = p.second;
if (k > v)ans += v;
else ans += v - k;
}
cout << ans << endl;
}
| 0
| 100,461,311
|
#include <bits/stdc++.h>
#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 ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
using namespace std;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;
int main(int argc, char const *argv[])
{
ll n, m;
cin >> n >> m;
if (n == 1 && m == 1)
{
cout << 1 << endl;
}
else if (n == 1)
{
cout << max(0ll, m - 2) << endl;
}
else if (m == 1)
{
cout << max(0ll, n - 2) << endl;
}
else
{
cout << (n - 2) * (m - 2) << endl;
}
return 0;
}
|
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"
#define pi 3.1415926535897932384626433832795028841971693993751058
#define maxn 100005
#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)
#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define pq priority_queue
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
#define ceil(a,b) (a+b-1)/b
using namespace std;
int binpow(int a, int b) {
int res = 1;
while (b > 0) {
if (b & 1)
res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
void solve()
{
int a,b;
cin>>a>>b;
cout<<(3*a + b)/2<<endl;
}
signed main()
{
fast;
int t = 1;
while(t--)
{
solve();
}
return 0;
}
| 0
| 83,960,525
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define ALL(x) x.begin(),x.end()
#define SIZE(x) ll(x.size())
#define INF 1000000000000
#define MOD 1000000007
#define MAXR 100000
#define PB emplace_back
#define MP make_pair
#define F first
#define S second
#define Umap unordered_map
#define Uset unordered_set
int main(){
ll n, m;
cin >> n >> m;
vector<ll> k(m), p(m);
vector<vector<bool>> s(m, vector<bool>(10, 0));
REP(i, m){
cin >> k[i];
REP(j, k[i]){
ll tmp;
cin >> tmp;
s[i][tmp-1] = true;
}
}
REP(i, m) cin >> p[i];
ll ans = 0;
for (int bit = 0; bit < (1<<n); ++bit) {
bool ok = true;
vector<ll> tmp(m, 0);
for(int i = 0; i < n; i++){
if(bit & (1<<i)){
REP(j, m) if(s[j][i] == true) tmp[j]++;
}
}
REP(i, m) if(tmp[i] % 2 != p[i]) ok = false;
if(ok) ans++;
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll N, C, K;
cin >> N >> C >> K;
vector<ll> T(N);
REP(i, N) { cin >> T.at(i); }
sort(T.begin(), T.end());
vector<ll> T2(N - 1);
REP(i, N - 1) { T2.at(i) = T.at(i + 1) - T.at(i); }
ll ans = 0;
ll base = T.at(0);
ll limit = base + K;
ll current = base;
ll count = 1;
REP(i, N - 1) {
current += T2.at(i);
if (count == C || current > limit) {
base = current;
limit = base + K;
ans += (count + C - 1) / C;
count = 1;
} else {
++count;
}
}
ans += (count + C - 1) / C;
cout << ans << endl;
return 0;
}
| 0
| 64,479,134
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
long long MOD = 1000000000 + 7;
int main(){
cout << setprecision(10);
int N;
cin >> N;
map<int,int> odd,even;
odd[0] = 0;
even[0] = 0;
for(int i = 0; i < N; i++){
int tmp;
cin >> tmp;
if(i %2 == 0){
if(odd.count(tmp) == 0){
odd[tmp] = 1;
} else {
odd[tmp] += 1;
}
} else {
if(even.count(tmp) == 0){
even[tmp] = 1;
} else {
even[tmp] += 1;
}
}
}
vector<pair<int,int>> v_odd;
for(auto x: odd){
v_odd.push_back(make_pair(x.second, x.first));
}
sort(v_odd.rbegin(), v_odd.rend());
vector<pair<int,int>> v_even;
for(auto x: even){
v_even.push_back(make_pair(x.second, x.first));
}
sort(v_even.rbegin(), v_even.rend());
int ans = 0;
if(v_odd[0].second != v_even[0].second){
ans += (N/2) - v_odd[0].first;
ans += (N/2) - v_even[0].first;
} else {
int tmpans1 = 0;
if(v_odd[1].first >= v_even[1].first){
ans += (N/2) - v_odd[1].first;
ans += (N/2) - v_even[0].first;
} else {
ans += (N/2) - v_odd[0].first;
ans += (N/2) - v_even[1].first;
}
}
cout << ans << endl;
}
|
#include <iostream>
#include <stack>
#include <math.h>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#define rep(i,n) for(int i=0; i < n; i++)
using ll = long long;
using namespace std;
int main()
{
int people, day, choco;
cin >> people >> day >> choco;
vector<int> a(people);
rep(i, people)
{
cin >> a[i];
int eat_day = a[i] + 1;
for (int j = 0; a[i] * j < day; j++)
{
choco++;
}
}
cout << choco << endl;
return 0;
}
| 0
| 44,354,672
|
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main(){
int a,b,c,d;
cin >> a >> b >> c >> d ;
bool q = true;
if(abs(a-c) >d){
if(abs(a-b)>d|| abs(b-c) >d){
q = false;
}
}
if(q ==true)cout << "Yes" << endl;
else cout << "No" << endl;
}
|
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;
int main() {
int A, B, C;
cin >> A >> B >> C;
int M = max(max(A, B), C);
int sum = A + B + C;
if ((M * 3 - sum) % 2) M++;
cout << (M * 3 - sum) / 2 << endl;
}
| 0
| 93,032,509
|
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(I, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ll = long long;
int main() {
int n;
cin >> n;
vector<int> v(n);
vector<int> v1(n);
vector<bool> ok(n,true);
int mx = 0;
REP(i,n){
cin >> v[i];
v1[i] = v[i];
}
sort(v1.begin(),v1.end());
REP(i,n){
if(v[i] != v1[n-1]){
mx = max(mx,v[i]);
}
}
if(v1[n-1] == v1[n-2]){
REP(i,n){
cout << v1[n-1] << endl;
}
}
else{
REP(i,n){
if(v[i] == v1[n-1]){
cout << mx << endl;
}
else{
cout << v1[n-1] << endl;
}
}
}
}
|
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <tuple>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int>
#define int int64_t
#define Fixed fixed << setprecision(10)
#define moke_pair make_pair
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1000000007;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class T,class U> using umap = unordered_map<T,U>;
inline int64_t updiv(int64_t n,int64_t d){
return ((n + d -1) / d);
}
signed main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n,a,b;
cin >> n >> a >> b;
cout << ((abs(a-b) & 1) ? "Borys\n" : "Alice\n");
return 0;
}
| 0
| 91,177,895
|
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#define pai 3.141592653589793238462643383279
int main(){
int keta=-1; ll pow[11]; pow[0] = 1;
rep(i, 10){
pow[i+1] = pow[i]*10;
}
for(int i=0; i<=10; i++){
cout << "? " << flush;
cout << pow[i] << flush;
cout << endl << flush;
char c; cin >> c;
if(c=='N'){
keta = i; break;
}
}
if(keta==-1){
for(int i=0; i<=10; i++){
cout << "? " << flush;
cout << (ll)2LL*pow[i] << endl << flush;
char c; cin >> c;
if(c=='Y'){
cout << "! " << pow[i] << endl << flush; return 0;
}
}
}
vector<int> made;
for(int i=1; i<=keta; i++){
ll ng = -1, ok = 9;
if(i==1) ng = 0;
while(abs(ok-ng)>1){
ll mid = (ok+ng)/2;
cout << "? " << flush;
for(auto k: made){
cout << k << flush;
}
cout << mid << flush;
rep(i, keta-made.size()){
cout << 9 << flush;
}
cout << endl;
cout << flush;
char c; cin >> c;
if(c=='Y') ok = mid;
else ng = mid;
}
made.push_back(ok);
}
cout << "! " << flush;
for(auto k: made){
cout << k << flush;
}
cout << endl; cout << flush; return 0;
}
|
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
string s;
cin >> s;
int n, i, j, k, ct = 0;
for (auto ch : s) {
if (ch == 'o') ct++;
}
ct += (15 - s.length());
if (ct >= 8) cout << "YES\n";
else cout << "NO\n";
return 0;
}
| 0
| 15,274,960
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;
int main() {
string S;
cin >> S;
int cnt = 0;
rep(i, S.size()) if (S[i] == 'B') cnt += 1;
ll ans = 0;
int last = S.size() - 1;
for (int i = S.size() - 1; cnt != 0; --i) {
if (S[i] == 'B') {
ans += last - i;
cnt -= 1;
last -= 1;
}
}
cout << ans << endl;
return 0;
}
|
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main(){
long long int i, x, N , K, score, score_max, cycle, K_rem, ans;
cin >> N >> K;
score = 0;
score_max = 0;
cycle = 0;
long long int P[N], C[N], Sc[N], Sm[N], Cy[N], Max[N];
for (i = 0; i < N; i++){
cin >> P[i];
P[i] -= 1;
}
for (i = 0; i < N; i++){
cin >>C[i];
}
x = C[0];
for (i = 0; i < N; i++){
x = max(x, C[i]);
}
if (x <= 0){
cout << x << "\n";
return 0;
}
for (i = 0; i < N; i++){
x = i;
score = 0;
cycle = 0;
score_max = 0;
while (1){
x = P[x];
score += C[x];
score_max = max(score, score_max);
cycle++;
if (x == i) break;
}
Cy[i] = cycle;
Sc[i] = score;
Sm[i] = score_max;
}
for (i = 0; i < N; i++){
x = i;
score = 0;
cycle = 0;
score_max = 0;
K_rem = (K - 1) % Cy[i] + 1;
while (1){
x = P[x];
score += C[x];
score_max = max(score, score_max);
cycle++;
if (cycle == K_rem) break;
}
if (Sc[i] <= 0){
Max[i] = Sm[i];
} else {
Max[i] = (K - 1) / Cy[i] * Sc[i] + score_max;
}
}
ans = 0;
for (i = 0; i < N; i++){
ans = max(ans, Max[i]);
}
cout << ans << "\n";
return 0;
}
| 0
| 37,157,851
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string S;cin>>S;
cout<<(S.size()>=4? (S.substr(0,4)=="YAKI"?"Yes":"No"):"No")<<endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define endl "\n"
#define pb push_back
#define PI 3.1415926535897932384626433832795l
#define F first
#define S second
#define mp make_pair
#define f(i,n) for(int i=0;i<n;i++)
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define gcd(a,b) __gcd((a),(b))
#define fill(a,value) memset(a,value,sizeof(a));
#define minn(v) *min_element(v.begin(), v.end());
#define maxx(v) *max_element(v.begin(), v.end());
#define print(x) cout<<(x)<<endl;
#define sum(v)+x accumulate(v.begin(), v.end(),x);
#define debug(x) cout<<#x<<'='<<(x)<<endl;
typedef pair<int,int> pii;
typedef vector<int> vi;
signed main()
{
fastio;
cout << fixed << setprecision(12);
int n;
cin>>n;
vector<double> a(n);
f(i,n)
{
double x;
cin>>x;
a[i]=(double)1.0/x;
}
double s=0;
for(int i=0;i<n;i++)
{
s+=a[i];
}
cout<<1/s<<endl;
return 0;
}
| 0
| 94,543,187
|
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
int main() {
int n;
cin >> n;
double a = 0;
double b = 1;
vector<int>v(n);
for (int i = 0; i < n; ++i) {
int x;
cin >> x;
v[i] = x;
b *= x;
}
for (int i = 0; i < n; ++i) {
a += (b/v[i]);
}
double ans = b/a;
cout << fixed << setprecision(12) << ans;
}
|
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define per(i,n) for (int i = n - 1; i >= 0; --i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline T intceil(T a, T b) { return (a + (b - 1)) / b; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const long long MOD = 1e9+7;
#define precout() cout << std::fixed << std::setprecision(20);
const string alphabet = "abcdefghijklmnopqrstuvwxyz";
const int dy[4] = { 0, 1, 0, -1 };
const int dx[4] = { 1, 0, -1, 0 };
static const double pi = 3.141592653589793;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
string s; cin >> s;
int n = s.size() + 1;
vector<ll> cnt(n, 0);
rep(i, n - 1) {
if(s[i] == '<') {
chmax(cnt[i + 1], cnt[i] + 1);
}
}
per(i, n - 1) {
if(s[i] == '>') {
chmax(cnt[i], cnt[i + 1] + 1);
}
}
ll ans = 0;
rep(i, n) {
ans += cnt[i];
}
cout << ans << endl;
}
| 0
| 58,811,991
|
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MAXX 10005
#define PI 3.14159265358979323846264338327950
#define ll signed long long int
using namespace std;
ll t , n, c[MAXX];
vector<ll> adj[MAXX];
bool used[MAXX];
signed main()
{
FAST;
ll a, b, r;
cin >> r >> a >> b;
c[0] = b;
for(ll i = 1; i <= 10; i++){
c[i] = r*c[i-1] -a;
}
for(ll i = 1; i <= 10; i++){
cout << c[i] << endl;
}
}
|
#include <iostream>
#include <string>
using namespace std;
int main()
{
string arg, arg2;
cin >> arg;
cin >> arg2;
arg += arg;
if (arg.find(arg2) == string::npos)
{
cout << "No\n";
return 0;
}
cout << "Yes\n";
return 0;
}
| 0
| 12,569,031
|
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define yesno(flg) if(flg){cout<<'YES'<<endl;}else{cout<<'NO'<<endl;}
#define vi vector<int>
#define pb push_back
#define i197 1000000007
#define MAX_N 200002
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<Pii,int> Piii;
typedef pair<int,ll> Pil;
typedef pair<ll,ll> Pll;
typedef pair<string,int> Psi;
typedef pair<Psi,int> Psii;
const int inf=1000000000;
struct edge{
int myc,to,c,cost;
};
struct pos{
int to,cost,color;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
vi vec[200001];
int x[200001]={};
int dp[200001];
int main() {
string s,t;
cin>>s>>t;
int r=0;
rep(i,3){
if(s[i]==t[i])r++;
}
cout<<r<<endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define MAXN 200005
#define MAXVAL 1000005
int a[MAXN];
int f[MAXVAL];
int n, ans;
int main(){
scanf("%d", &n);
for(int i = 1; i <= n; i++)
scanf("%d", &a[i]);
sort(a+1, a+n+1);
if(a[1] == 1){
if(a[2] == 1)
printf("%d\n", 0);
else
printf("%d\n", 1);
return 0;
}
for(int i = 1; i <= n; i++){
int j = a[i];
if(f[j] == 0)
f[j] = 1;
else if(f[j] == 1)
f[j] = 2;
for(int k = 2*j; k < MAXVAL; k+= j)
f[k] = 2;
}
for(int i = 1; i <= n; i++)
if(f[a[i]] == 1)
ans++;
printf("%d\n", ans);
}
| 0
| 18,439,105
|
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
#define ll long long
#define ld long double
ll ctoi(const char c){if('0'<=c&&c<='9') return (c-'0');return -1;}
#define ALL(x) begin(x),end(x)
int main(){
ll n,m;
cin >> n >> m;
vector<ll> l(m),r(m);
rep(i,m) cin >> l[i] >> r[i];
sort(ALL(l));
sort(ALL(r));
if(r[0]-l[m-1]+1>0) cout << r[0]-l[m-1]+1 << endl;
else cout << "0" << endl;
}
|
#include<bits/stdc++.h>
using namespace std;
int main(){
int n, m;
cin >> n >> m;
vector<string> a(n);
vector<string> b(m);
for(int i = 0;i < n;i++)cin >> a.at(i);
for(int i = 0;i < m;i++)cin >> b.at(i);
for(int ay = 0;ay < n;ay++){
for(int ax = 0;ax < n;ax++){
if(n - m + 1 <= ay || n - m + 1 <= ax)break;
bool judge = true;
for(int by = 0;by < m;by++){
for(int bx = 0;bx < m;bx++){
if(a.at(ay + by).at(ax + bx) != b.at(by).at(bx))judge = false;
}
}
if(judge){
cout << "Yes" << endl;
return 0;
}
}
}
cout << "No" << endl;
}
| 0
| 13,112,802
|
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstdio>
#include<iomanip>
#include<map>
#include<cstring>
using namespace std;
long long n,m;
int main()
{
cin>>n>>m;
if(n*2>m) cout<<m/2;
else if(n*2==m) cout<<n;
else
{
m-=n*2;
m/=4;
cout<<n+m;
}
return 0;
}
|
#include <bits/stdc++.h>
#define pb push_back
#define Int long long
using namespace std;
const int MAXN=500005;
const long MOD=(long)(1e9+7);
vector<int> adj[MAXN];
vector<pair<int,int>> G[MAXN];
Int N,M,K;
Int X,Y,Z;
Int ceilS(Int x,Int y){
return (x+y-1)/y;
}
using D=long double;
Int perform(Int x){
return (x*(x+1))/2LL;
}
int main()
{
cin>>N;
Int A[N][3];
for(int i=0;i<N;++i){
cin>>A[i][0]>>A[i][1]>>A[i][2];
}
Int dp[N][3];
for(int i=0;i<3;++i) dp[0][i]=A[0][i];
for(int i=1;i<N;++i){
dp[i][0]=max(dp[i-1][1],dp[i-1][2])+A[i][0];
dp[i][1]=max(dp[i-1][0],dp[i-1][2])+A[i][1];
dp[i][2]=max(dp[i-1][0],dp[i-1][1])+A[i][2];
}
Int ans=max({dp[N-1][0],dp[N-1][1],dp[N-1][2]});
cout<<ans<<"\n";
}
| 0
| 96,635,495
|
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)
int main(){
char x;
cin >> x;
if (isupper(x)) cout << 'A' << endl;
else cout << "a"<< endl;
return 0;
}
|
#include<stdio.h>
#include<string.h>
int main(){
char a[11];
char b[11];
char c[11];
scanf("%s",a);
scanf("%s",b);
scanf("%s",c);
int len1 = strlen(a);
int len2 = strlen(b);
int len3 = strlen(c);
if(a[len1-1] == b[0] && b[len2-1] == c[0]){
printf("YES");
}
else{
printf("NO");
}
return 0;
}
| 0
| 19,067,863
|
#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<iomanip>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<string> vstring;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
typedef vector<vbool> vvbool;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#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 YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;
#define Pi 3.1415926535897932384626
#define mod llint(1e9+7)
#define Inf 2147483647
#define llInf 9223372036854775807
#define all(x) x.begin(),x.end()
#define pb push_back
#define isin(n,i) 0<=i&&i<n
class UnionFind {
public:
vector<int> Parent;
UnionFind(int N) {
Parent = vector<int>(N, -1);
}
int root(int A) {
if (Parent[A] < 0) return A;
return Parent[A] = root(Parent[A]);
}
int size(int A) {
return -Parent[root(A)];
}
bool connect(int A, int B) {
A = root(A);
B = root(B);
if (A == B) {
return false;
}
if (size(A) < size(B)) swap(A, B);
Parent[A] += Parent[B];
Parent[B] = A;
return true;
}
};
template<typename T>
struct SegTree {
using F = function<T(T, T)>;
vector<T>seg;
int siz;
const T unit;
const F f;
SegTree(int n, const T unit, const F f) : unit(unit), f(f) {
siz = 1;
while (siz < n)siz <<= 1;
seg.assign(siz * 2 - 1, unit);
siz--;
}
void set(int k, const T& t) {
seg[k + siz] = t;
}
void build() {
for (int i = siz - 1; 0 <= i; i--) {
seg[i] = f(seg[i * 2 + 1], seg[i * 2 + 2]);
}
}
T operator[](const int i) {
return seg[i + siz];
}
void update(int k, T x) {
k += siz;
seg[k] = x;
while (0 < k) {
k = (k - 1) >> 1;
seg[k] = f(seg[k * 2 + 1], seg[k * 2 + 2]);
}
}
T query(int a, int b) {
T l = unit, r = unit;
for (a += siz, b += siz; a < b; a >>= 1, b >>= 1) {
if (!(a & 1))l = f(seg[a++], l);
if (!(b & 1))r = f(seg[--b], r);
}
return f(l, r);
}
};
long long GCD(long long a, long long b) {
if (b == 0) return a;
else return GCD(b, a % b);
}
long long extGCD(long long a, long long b, long long& x, long long& y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
long long d = extGCD(b, a % b, y, x);
y -= a / b * x;
return d;
}
template<typename T>
bool check(T a, T b) {
return a < b;
}
long long modinv(long long a, long long m) {
long long b = m, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
u %= m;
if (u < 0) u += m;
return u;
}
llint nCr(llint n, llint r) {
llint ans = 1;
for (llint i = 0; i < r; i++) {
ans *= n - i;
ans %= 1000000007;
}
for (llint i = 1; i <= r; i++) {
ans *= modinv(i, 1000000007);
ans %= 1000000007;
}
return ans;
}
llint power(llint a, llint b) {
if (b == 1)return a;
if (b == 0)return 1;
llint tmp = power(a, (llint)b / 2);
tmp *= tmp;
tmp %= mod;
if (b % 2 == 1) {
tmp *= a;
tmp %= mod;
}
return tmp;
}
int main() {
int a[4] = {};
rep(i, 6) {
int x;
cin >> x;
a[x - 1]++;
}
bool ans = true;
rep(i, 4) {
if (a[i] > 2)ans = false;
}
YES(ans);
return 0;
}
|
#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 (){
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < (int)(n); i++){
cin >> a[i];
}
int k=1;
int ans=0;
int no=0;
for (int i = 0; i < (int)(n); i++){
if (a[i] == k){
k++;
ans++;
}
if (a[i] != 1) no++;
}
if (no == n) cout << "-1" << endl;
if (no != n) cout << n-ans << endl;
}
| 0
| 90,498,686
|
#include <bits/stdc++.h>
using namespace std;
#define trav(a, A) for (auto & a : A)
#define f first
#define s second
typedef long long ll;
const ll MOD = 1e+9+7;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const ll MAXN = 1e+5+7;
void solve(){
string s, t;
cin >> s >> t;
int ans = INF;
int n = s.size(), m = t.size();
for (int i = 0; i <= n - m; ++i){
int tmp = 0;
for (int j = 0; j < m; ++j){
if (s[i+j] != t[j])tmp++;
}
ans = min(tmp, ans);
}
cout << ans << '\n';
}
int main ()
{
ios_base::sync_with_stdio (0);
cin.tie (0);
ll i, j, n;
int t = 1;
while(t--) solve();
return 0;
}
|
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
using namespace std;
#define INT(x) int x; scanf("%d",&x)
#define LL(x) ll x; scanf("%lld",&x)
#define INPUT(x) cin >> x
#define REP1(x,n) for(int x = 0; x < n; x++)
#define REP2(x,s,e) for(int x = s; x <= e; x++)
#define RREP1(x,n) for(int x = n-1; x >= 0; x--)
#define RREP2(x,s,e) for(int x = s; x >= e; x--)
#define BR printf("\n")
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
typedef long long ll;
int main(){
int A[100][100];
INT(N);INT(E);
REP1(i,N){
REP1(j,N){
if(i != j){
A[i][j] = INF_INT;
}else{
A[i][j] = 0;
}
}
}
REP1(i,E){
INT(s);INT(t);INT(d);
A[s][t] = d;
}
REP1(k,N){
REP1(i,N){
if (A[i][k] == INF_INT) continue;
REP1(j,N){
if (A[k][j] == INF_INT) continue;
A[i][j] = min(A[i][j], A[i][k] + A[k][j]);
}
}
}
REP1(i,N){
if(A[i][i] < 0){
cout << "NEGATIVE CYCLE" << endl;
return 0;
}
}
REP1(i,N){
REP1(j,N){
if (A[i][j] == INF_INT) {
cout << "INF";
}else{
cout << A[i][j];
}
if (j+1 != N)cout << " ";
}
cout << endl;
}
return 0;
}
| 0
| 83,302,356
|
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>
using namespace std;
int ans=0,k;
string s;
int dp[110][4][2];
int solve(int pos,int n_k,bool less){
if(n_k > k)
return 0;
if(pos==s.size())
return n_k == k;
if(dp[pos][n_k][less])
return dp[pos][n_k][less];
if(less){
for(char c='0';c<='9';++c){
dp[pos][n_k][less]+=solve(pos+1,n_k+(c!='0'),true);
}
}
else{
char great = s[pos];
for(char c='0';c<great;++c){
dp[pos][n_k][less]+=solve(pos+1,n_k+(c!='0'),true);
}
dp[pos][n_k][less]+=solve(pos+1,n_k+(great!='0'),false);
}
return dp[pos][n_k][less];
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>s>>k;
cout<<solve(0,0,0)<<endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main()
{
long int n;
cin>>n;
long int i,j,a[n],t=0,x=1,s=0;
for(i=0;i<n;i++)
{
cin>>a[i];
}
for(j=0;j<n;j++)
{
if(x==a[j])
{
x++;
}
else
{
s++;
}
}
if(x==1)
{
cout<<-1<<endl;
return 0;
}
cout<<s<<endl;
}
| 0
| 93,074,595
|
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <string>
#include <string.h>
using namespace std;
int main() {
string s;
cin >> s;
sort(s.begin(),s.end());
if(s == "abc")
cout << "Yes" << endl;
else cout << "No" << endl;
}
|
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using lb = long double;
using P = pair<ll,ll>;
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define debug(x) cerr << #x << ": " << x << "\n"
#define INF 1000000000000
#define inf 2147483647
#define MOD 1000000007
#define MAXR 100000
#define endl "\n"
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define CST(x) cout<<fixed<<setprecision(x)
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;
}
int gcd(int a, int b) {
if (b==0) return a;
else return gcd(b, a%b);
}
int lcm(int a, int b) {
return a * b / gcd(a, b);
}
int two(int n){
ll ans=1;
rep(i,n){
ans*=2;
}
return ans;
}
int main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int n;cin>>n;
vector<int> A(n+1);
rep(i,n){
cin>>A[i+1];
}
ll ans=0;
rep(i,n){
if(A[A[i+1]]==i+1)ans++;
}
cout<<ans/2<<endl;
return 0;
}
| 0
| 5,717,815
|
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,z,w;
cin>>n>>z>>w;
vector<int> a(n);
for(int i=0;i<n;i++)
cin>>a.at(i);
vector<int> x(n);
vector<int> y(n);
for(int i=n-1;i>=0;i--){
x[i]=abs((i>0?a.at(i-1):w)-a.at(n-1));
y[i]=abs((i>0?a.at(i-1):z)-a.at(n-1));
for(int j=i+1;j<n;j++){
x[i]=max(x[i],y[j]);
y[i]=min(y[i],x[j]);
}
}
cout<<x[0]<<endl;
}
|
#include<iostream>
using namespace std;
const int size=1e5+5;
const int level = 60;
typedef long long int ll;
ll basis[level];
void add(ll mask)
{
for(int i=level-1;i>=0;i--)
{
if(((mask>>i)&1) == 0)
continue;
if(!basis[i])
{
basis[i] = mask;
return;
}
mask ^= basis[i];
}
}
int main()
{
int n;
cin>>n;
ll arr[n];
ll total = 0;
for(int i=0;i<n;i++)
cin>>arr[i],total ^= arr[i];
ll ans = 0;
for(int i=0;i<level;i++)
{
if((total>>i)&1)
{
for(int j=0;j<n;j++)
if((arr[j]>>i)&1)
arr[j] -= (1LL<<i);
}
}
for(int i=0;i<n;i++)
add(arr[i]);
for(int i=level-1;i>=0;i--)
{
if(!basis[i])
continue;
if((ans>>i)&1) continue;
ans ^= basis[i];
}
cout<<(ans+(ans+total))<<"\n";
return 0;
}
| 0
| 43,294,108
|
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main(){
string s; getline(cin,s);
string word;
map<string,int> dic;
for(int i=0;i<s.size();i++){
if(s[i]!=' '){
word+=s[i];
}
else{
dic[word]++;
word="";
}
}
dic[word]++;
int num=0;
for(auto it:dic) num=max(num,it.second);
for(auto it:dic){
if(num==it.second) cout<<it.first<<" ";
}
num=0;
for(auto it:dic) num=max(num,(int)it.first.size());
for(auto it:dic){
if(num==it.first.size()) cout<<it.first<<endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using UL=unsigned int;
using LL=long long;
using ULL=unsigned long long;
#define rep(i,n) for(UL i=0; i<(n); i++)
struct Vec{
double x,y;
Vec(double xx,double yy):x(xx),y(yy){}
};
Vec Relate(Vec o, Vec x, Vec p){
Vec ans{0,0};
x.x-=o.x; x.y-=o.y;
ans.x += x.x*p.x; ans.y += x.y*p.x;
ans.x -= x.y*p.y; ans.y += x.x*p.y;
ans.x+=o.x; ans.y+=o.y;
return ans;
}
vector<Vec> buf;
int main(){
UL N; cin>>N;
buf.push_back(Vec(0.0,0.0));
buf.push_back(Vec(100.0,0.0));
rep(n,N){
vector<Vec> tmp;
tmp.push_back(Vec(0.0,0.0));
rep(i,buf.size()-1){
tmp.push_back(Relate(buf[i],buf[i+1],Vec(1.0/3.0,0.0)));
tmp.push_back(Relate(buf[i],buf[i+1],Vec(0.5,sqrt(0.75)/3.0)));
tmp.push_back(Relate(buf[i],buf[i+1],Vec(2.0/3.0,0.0)));
tmp.push_back(Relate(buf[i],buf[i+1],Vec(1.0,0.0)));
}
buf=move(tmp);
}
cout<<fixed<<setprecision(10);
for(Vec& v:buf){
cout<<v.x<<" "<<v.y<<endl;
}
}
| 0
| 89,038,914
|
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
using namespace std;
ll n,t,x,y,m,q;
int main(){
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin>>n;
string s,s1;
cin>>s>>s1;
for(int i=0;i<n;i++){
cout<<s[i]<<s1[i];
}
}
|
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
using namespace std;
using ll = long long;
const ll MOD = 1000000007LL;
const double PI = 3.14159265358979;
void solve()
{
int h, w;
cin >> h >> w;
vector<string> a(h);
for(int i = 0; i < h; ++i)
{
cin >> a[i];
}
vector<int> erased_h;
vector<int> erased_w;
for(int i = 0; i < h; ++i)
{
if (a[i] == string(w, '.'))
{
erased_h.emplace_back(i);
}
}
erased_h.emplace_back(1000);
for(int i = 0; i < w; ++i)
{
bool ok = true;
for(int j = 0; j < h; ++j)
{
ok &= (a[j][i] == '.');
}
if(ok) erased_w.emplace_back(i);
}
reverse(erased_w.begin(), erased_w.end());
for(int i = 0; i < h; ++i)
{
for(const auto& e : erased_w)
{
a[i].erase(a[i].begin() + e);
}
}
int eh = 0;
for(int i = 0; i < h; ++i)
{
if (erased_h[eh] == i)
{
eh++;
continue;
}
cout << a[i] << endl;
}
}
int main()
{
fastio;
solve();
return 0;
}
| 0
| 57,555,746
|
#include <iostream>
#include <string>
using namespace std;
int main() {
string a, b, c;
cin >> a >> b >> c;
if (a[a.size() - 1] == b[0] &&b[b.size() - 1] == c[0]) cout << "YES\n";
else cout << "NO\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define ll long long
const int MAX = 510000;
const int MOD = 1000000007;
ll fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++){
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - 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;
}
int main(){
int n,p; cin >> n >> p;
ll all = pow(2,n);
COMinit();
vector<int> a(n);
map<int,int> mp;
rep(i,n){
int a; cin >> a;
mp[a%2]++;
}
if(mp[1]==0) cout << (p==0?(1LL<<n):0) << endl;
else cout << (1LL<<(n-1)) <<endl;
}
| 0
| 95,510,250
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.