# Codeforces1137b camp schedule

## 利用KMP的Next数组贪心

Posted by yjjr's blog on March 12, 2019

# Code

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
#define mem(x,num) memset(x,num,sizeof x)
#define reg(x) for(int i=last[x];i;i=e[i].next)
using namespace std;
ll f=1,x=0;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
const int maxn=5e5+6;
int nx[maxn],len1,len2,o=0,z=0;
char s[maxn],t[maxn];
void GetNext(char st[]){
int i=0,j=-1;nx[0]=-1;
while(i<len1){
if(j==-1||st[i]==st[j])nx[++i]=++j;else j=nx[j];
}
}
int main(){
cin>>s>>t;
len1=strlen(s),len2=strlen(t);GetNext(t);
rep(i,0,len1-1)if(s[i]=='0')z++;else o++;
string ans="";
int tot=0;
while(z&&o){
if(t[tot]=='0'){
if(z)z--,ans+='0';else break;
}else{
if(o)o--,ans+='1';else break;
}
if((++tot)==len2)tot=nx[tot];
}
while(z--)ans+='0';
while(o--)ans+='1';
cout<<ans<<endl;
}