Language: C++

#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define rep(b,a,c) for(b=a;b<c;b++)
#define ll long long
#define re return
#define fi first
#define se second 

using namespace std;

//Please Hake Me
//by Eyes
/*

int main(){
	freopen("gomn.out","w",stdout);
	for(int a=1;a<=12;a++)
		for(int b=a+1;b<=12;b++)
		    for(int c=b+1;c<=12;c++)
		        for(int d=c+1;d<=12;d++)if(a+b+c+d==26)cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
}
int i,j,par[N],root[N],n,r[N];
bool fa[N];
int Find(int x){
	if(par[x]==x)return x;
	else returnFind(par[x]);
}
int main(){
	scanf("%d",&n);
	rep1(i,n){
		cin>>par[i];fa[par[i]]=true;
	}
	rep1(i,n)root[i]=Find[i];
	int flag=1;
	rep1(i,n){
	    bool f=false;
		rep1(j,flag-1){
			if(root[i]==r[j]){
				f=true;
				break;
			}
		if(f)r[flag]=root[i];
		}
}
	cout<<flag-1<<endl;
	rep1(i,n){

	if(!fa[i]&&flag>1&&root[i]!=r[flag]){
		par[r[flag]]=i;
		flag--;
	}else if(flag==1)break;}
	rep1(i,n)cout<<par[i]<<" ";
	puts("");
	return 0;
}
int i,j,par[200100],n,tot,ab[20010077];
bool vi[200100],rubbish;
void dfs(int a){
	if(par[a]==a)return;
	if(vi[par[a]])
}



//ANT ON THE TREE （第一种做法）
int n,i,j,x,y;
vector <int> v[301],ans;
inline bool dfs(int a,int b,int la) {
	if(b==a)return true;
	rep0(i,v[a].size()) {
		if(la==v[a][i])continue;
		if(dfs(v[a][i],b,a)) {
			ans.push_back(a);
			return true;
		}
		return false;
	}
}
int main() {
	cin>>n;
	rep0(i,n-1) {
		int a,b;
		cin>>x>>y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	y=1;
	while(scanf("%d",&x)!=EOF) {
		dfs(x,y,0);
		y=x;
	}
	dfs(1,y,0);
	if(ans.size()!=(2*n-1)) {
		cout<<"-1"<<endl;
		return 0;
	}
	//不懂悲欢离合煎熬的我们
	rep0(i,ans.size()) {
		cout<<ans[i]<<" ";
	}
	cout<<endl;
	return 0;
}



//BEAUTIFUL IP ADDRESS

const int N=300;
const int I=1e5;
int n,tmp,g[N],kd[N],d[N][N],mask[N],q[N],aw[I],ax[I],ay[I],az[I],i,j;
bool b[N],good[N];
int main(){
	int w,x,y,z;
	cin>>n;
	rep0(i,10)b[i]=false;
	int need=0;
	rep0(i,n){
		cin>>tmp;
		need|=(i<<tmp);
		b[tmp]=true;
	}
	if(n>6){
		puts("0");
		re 0;
	}
	int kg=0;
	memset(good,true,sizeof(good));
	rep0(i,256){
		good[i]=true;
		int x=i;mask[i]=0;
		kd[i]=0;
		while(x>0){
			d[i][kd[i]++]=x%10;
			if(!b[x%10])good[i]=false;
			mask[i]=(1<<(x%10));
			x/=10;
		}
		if(i==0&&!b[0])good [i]=false;
		if(i==0){
			d[i][kd[i]++]=0;
			mask[i]|=(1<<0);
		}
		if(good[i])g[kg++]=i;
	}
	int ka=0;
	rep0(w,256)if(good[w])
	rep0(x,256)if(good[x])
	rep0(y,256)if(good[y]){
		if(mask[w]|mask[x]|mask[y]!=need)continue;
		rep0(z,256)if(good[z]){
			int u=0;
			for(i=kd[w]-1;i>=0;i--)q[u++]=d[w][i];
			for(i=kd[x]-1;i>=0;i--)q[u++]=d[x][i];
			for(i=kd[y]-1;i>=0;i--)q[u++]=d[y][i];
			for(i=kd[z]-1;i>=0;i--)q[u++]=d[z][i];
			bool ok=true;
			rep0(i,u-i-1)if(q[i]!=q[u-i-1]){
				ok=false;
				break;
			}
			if(ok){
				aw[ka]=w;
				ax[ka]=x;
				ay[ka]=y;
				az[ka]=z;
				ka++;
			}
		}
	}
	cout<<ka<<endl;
	rep0(i,ka)cout<<aw[i]<<"."<<ax[i]<<"."<<ay[i]<<"."<<az[i]<<endl;
	return 0;
}






//TIC-TAC-TOE

int n,m;
int main(){
	cin>>n>>m;
	if(n==1){cout<<(m+2)/3<<endl;re 0;
	}else if(n==2){cout<<m/2+1<<endl;re 0;
	}else if(n==3){cout<<m+(m-1)/4<<endl;re 0;
	}else if(m==1){cout<<(n+2)/3<<endl;re 0;
	}else if(m==2){cout<<n/2+1<<endl;re 0;
	}else if(m==3){cout<<n+(n-1)/4<<endl;re 0;
	}else if(n==4){cout
	}
}



//CLIkB ON THE WALLS

int n,k;


char s[2][100010];
bool vi[2][100010]
inline void dfs(int a,int b,int dep){
	if(s[a][b]=='X'||vi[a][b]||b<dep||b<0)return;
	vi[a][b]=true;
	if(b>n){
		puts("YES");
		exit(0);
	}
	dfs(a,b+1,dep+1);
	dfs(a,b-1,dep+1);
	dfs((a+1)%2,b+k,dep+1);
}
int kain(){
	scanf("%d%d%s%s",&n,&k,s[0],s[1]);n--;
	dfs(0,1,1);
	dfs(1,k,1);
	puts("NO");
	return 0;
}



//GREAT+SWERC=PORTO(Gym100783)
bool letters[26],nu[10],nonz[26];
int num[26],i,j,n,ans;
char s[10][21];

inline void check(){
	int a[9];
	rep(i,0,n){
		rep(j,0,strlen(s[i]))a[i]=a[i]*10+num[s[i][j]-'A'];
	}
	int tot;
	rep(i,0,n-1)tot+=a[i];
	if(tot==a[n])ans++;
	cout<<"OK"<<endl;
}

inline void dfs(int c){
	rep(i,0,10){
		if(nonz[c]&&i==0)continue;
		if(!nu[i]){
			num[c]=i;
			nu[i]=true;for(int k=25;k>=0;k--)if(letters[k]){
				if(num[k]!=-1){
					check();
				}else break;
			}
			rep(j,c,26)if(letters[j])dfs(j);
			nu[i]=false;num[c]=-1;
		}
	}
	cout<<"YEAH"<<endl;
}

inline int binarysearch(int x,int v[],int m){
	int high,low,mid;
	high=n-1;low=0;
	while(low<high){
		mid=(high-low)/2;
		if(x<v[i])high=mid-1;
		else if(x>v[mid])low=mid+1;
		else return mid;
	}
	return -1;
}

int main(){
	scanf("%d",&n);
	rep(i,0,n){
		scanf("%s",s[i]);
		nonz[s[i][0]-'A']=true;
		rep(j,0,strlen(s[i]))if(!letters[s[i][j]-'A'])letters[s[i][j]-'A']=true;
	}
	cout<<"OK1"<<endl;
	memset(num,-1,sizeof num);
	rep(i,0,26)if(letters[i]){
		dfs(i);break;
	}
	cout<<"OK2"<<endl;
	printf("%d\n",&ans);
	cout<<"odshods"<<endl;
}


//460c
int i,j,n,a[100005],c[200010],w,m;
inline bool check(int h){
	memset(c,0,sizeof c);
	int add=0,used=0;
	rep(i,0,n){
		add+=c[i];
		int now=max(0,h-a[i]+add);
		used+=now;
		add+=now;
		c[i+w]-=now;
		if(used>m)re false;
	}
	re true;
}

int main(){
	cin>>n>>m>>w;
	rep(i,0,n);
	cin>>a[i];
	int low=1,high=1000100000;
	while (high-low>1){
	int mid=(high-low)/2;
	if(check(mid))low=mid;
	else high=mid;
	}
	cout<<low<<endl;
}


//IPv4
int n,num[256],i,j,x,y,ans,z;
bool a[10],used[10];
vector <string> s;

inline void Find(){
	int a[4];
	rep(i,0,flag){
		a[0]=num[i];used[a[0]/100]=used[a[0]/10%10]=used[a[0]%10]=true;
		rep(j,0,flag){
			a[1]=num[j];used[a[1]/100]=used[a[1]/10%10]=used[a[1]%10]=true;
			rep(x,0,flag){
				a[2]=num[x];used[a[2]/100]=used[a[2]/10%10]=used[a[2]%10]=true;int cnt=0;rep(z,0,10){if(!used[z]&&a[z])cnt++};
				if(cnt<4)
				rep(y,0,flag){
					a[3]=num[x];used[a[3]/100]=used[a[3]/10%10]=used[a[3]%10]=true;
					bool b=true;
					rep(z,0,10)if(!used[z]&&a[z])b=false;
					if(b){ans++;
					cout<<a[0]<<"."<<a[1]<<"."<<a[2]<<"."<<a[3]<<endl;
					}
				}
			}
		}
	}
	
}

int main(){
	cin>>n;int x;
	rep(i,0,n){
		int x;
		a[x]=true;
	}int flag=0;
	rep(i,0,256)
		if(a[i/100]&&a[(i%100)/10]&&(a[i]%10)){
			num[flag++]=a;
		}
	Find();
	cout<<ans<<endl;
	re 0;
}


//Number 24
int a,b,c,d,CASE=1,i,j,ans,k;

inline void check(){
	int a[9];
	rep(i,0,n){
		rep(j,0,strlen(s[i]))a[i]=a[i]*10+num[s[i][j]-'A'];
	}
	int tot;
	rep(i,0,n-1)tot+=a[i];
	if(tot==a[n])ans++;
	cout<<"OK"<<endl;
}

inline void dfs(int c){
	rep(i,0,10){
		if(nonz[c]&&i==0)continue;
		if(!nu[i]){
			num[c]=i;
			nu[i]=true;for(int k=25;k>=0;k--)if(letters[k]){
				if(num[k]!=-1){
					check();
				}else break;
			}
			rep(j,c,26)if(letters[j])dfs(j);
			nu[i]=false;num[c]=-1;
		}
	}
	cout<<"YEAH"<<endl;
}

inline void solve(){
	
}
int main(){
	cin>>a>>b>>c>>d;
	while(a&&b&&c&&d){
		cout<<"Case "<<CASE<<": ";
		
	}
	re 0;
}
int n,i,j,k;
string s,t;
int main(){
	cin>>n;
	rep(i,0,n){
		cin>>s;int len=0;
		rep(j,0,;s.size()){
			if(s[j]==":"){
				if(len>0&&)
			}
		}
	}
}*/


//Widespread
priority_queue <ll> q;
ll h,i,j,k,t,deathline,a,b,n,ans=0,m=1e9+10;
int main(){
	scanf("%lld%lld%lld",&n,&a,&b);
	deathline=0;
	rep(i,0,n){
		scanf("%lld",&h);q.push(h);m=min(m,h);
	}
	a-=b;eathline){
		t=q.top();q.pop();
		t-=a;q.push(t);
		ans++;
		deathline+=b;
	}
	printf("%lld\n",&ans);
	re 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:482:14: error: 'eathline' was not declared in this scope; did you mean 'deathline'?
  482 |         a-=b;eathline){
      |              ^~~~~~~~
      |              deathline