//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("bmi,bmi2,lzcnt,popcnt")
//#pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
//#pragma expected_value
//#pragma isolated_call
//#pragma disjoint
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
//#define int long long
//#define double long double
#define Fi first
#define Se second
#define Rep(i,a,b) for (int i=a;i<=b;++i)
#define Repu(i,b,a) for (int i=b;i>=a;--i)
#define pb push_back
#define ms(a,i) memset(a,i,sizeof(a))
#define sz size()
#define mp make_pair
#define endl '\n'
#define sef setprecision(12)<<fixed
#define cer cout<<"cak"<<endl;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<double> va;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<va> vva;
//const double EPS=1e-9;
const double PI=acos(-1);
//const int oo=1e18;
const int MN=5e5+5;
const int mod=1e9+7;
using cd=complex<double>;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> index_set;
string s,t;
int longest;
vector<int> prefix_function(const string &a){
vector<int> pf(a.size());
pf[0] = 0;
for (int i=1; i<a.size(); i++){
int ptr = pf[i-1];
while (ptr != 0 && a[ptr] != a[i]) ptr = pf[ptr-1];
pf[i] = ptr + (a[ptr] == a[i]);
}
return pf;
}
int cnt[2];
int sech[2];
int caknqu[2];
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>s>>t;
vi pf=prefix_function(t);
longest=pf[t.sz-1];
s=" "+s; t=" "+t;
Rep(i,1,s.sz-1) {
cnt[s[i]-'0']++;
}
Rep(i,longest+1,t.sz-1) {
sech[t[i]-'0']++;
}
Rep(i,1,longest) {
caknqu[t[i]-'0']++;
}
caknqu[0]+=sech[0]; caknqu[1]+=sech[1];
if(cnt[0]<caknqu[0] or cnt[1]<caknqu[1]) {
Rep(i,1,s.sz-1) cout<<s[i];
return 0;
}
Rep(i,1,t.sz-1) cout<<t[i];
cnt[0]-=caknqu[0]; cnt[1]-=caknqu[1];
while(cnt[0]>=sech[0] and cnt[1]>=sech[1]) {
Rep(i,longest+1,t.sz-1) {
cout<<t[i];
}
cnt[0]-=sech[0]; cnt[1]-=sech[1];
}
Rep(i,1,cnt[0]) cout<<0;
Rep(i,1,cnt[1]) cout<<1;
}
2148. Count Elements With Strictly Smaller and Greater Elements | 2149. Rearrange Array Elements by Sign |
2150. Find All Lonely Numbers in the Array | 2151. Maximum Good People Based on Statements |
2144. Minimum Cost of Buying Candies With Discount | Non empty subsets |
1630A - And Matching | 1630B - Range and Partition |
1630C - Paint the Middle | 1630D - Flipping Range |
1328A - Divisibility Problem | 339A - Helpful Maths |
4A - Watermelon | 476A - Dreamoon and Stairs |
1409A - Yet Another Two Integers Problem | 977A - Wrong Subtraction |
263A - Beautiful Matrix | 180C - Letter |
151A - Soft Drinking | 1352A - Sum of Round Numbers |
281A - Word Capitalization | 1646A - Square Counting |
266A - Stones on the Table | 61A - Ultra-Fast Mathematician |
148A - Insomnia cure | 1650A - Deletions of Two Adjacent Letters |
1512A - Spy Detected | 282A - Bit++ |
69A - Young Physicist | 1651A - Playoff |