#include <bits/stdc++.h>
using namespace std;

const int maxn = 1e5 + 10;

char s[maxn];
int n, node_cnt, dp[maxn];
map<string, int> mp;
vector <int> vc[maxn];
string temp;

int fa[maxn];
inline int setfind(int x){ return x == fa[x] ? x : fa[x] = setfind(fa[x]);}
inline void setunion(int x,int y){ x = setfind(fa[x]); y = setfind(fa[y]); fa[x] = y;}
inline bool setcheck(int x,int y){ x = setfind(x); y = setfind(y); return x == y;}

int main()
{
    //freopen("C:/Users/MACHENIKE/Desktop/data.in","r",stdin);
    scanf("%s", s + 1);
    n = strlen(s + 1);
    dp[n + 1] = 1;
    for (int i = 1; i <= (int)1e5; i++) fa[i] = i;
    for (int ed = n; ed >= 5; ed--)
    {
        if (dp[ed + 1] == 0) continue;
        for (int st = ed - 1; st >= ed - 2; st--)
        {
            if (st <= 5) break;
            int len = ed - st + 1;
            temp = "";
            for (int i = st; i <= ed; i++) temp += s[i];
            if (mp.find(temp) != mp.end())
            {
                bool ok = false;
                for (auto it : vc[mp[temp]])
                {
                    if (ok) break;
                    if (setcheck((ed + 1) * 2, it * 2 + ((len & 1) ^ 1)) || setcheck((ed + 1) * 2 + 1, it * 2 + ((len & 1) ^ 1))) ok = true;
                    for (int i = it + 1; i <= it + len - 1; i++)
                    {
                        if (ok) break;
                        if (setcheck((ed + 1) * 2, i * 2) || setcheck((ed + 1) * 2 + 1, i * 2)
                            || setcheck((ed + 1) * 2, i * 2 + 1) || setcheck((ed + 1) * 2 + 1, i * 2 + 1)) ok = true;
                    }
                }
                if (!ok) continue;
            }
            else mp[temp] = ++node_cnt;
            vc[mp[temp]].push_back(st * 2 + (len & 1));
            setunion(st * 2 + (len & 1), (ed + 1) * 2); setunion(st * 2 + (len & 1), (ed + 1) * 2 + 1);
            dp[st] |= dp[ed + 1];
        }
    }
    printf("%d\n", mp.size());
    for (auto it : mp) cout << it.first << '\n';
    return 0;
}


#include <bits/stdc++.h>

int main() {
	std::string s;
	std::getline(std::cin, s);

	s.erase(0, 5);
	std::reverse(s.begin(), s.end());

	int n = s.size();

	std::vector<bool> d2(n, false);
	std::vector<bool> d3(n, false);

	int i;

	if (n >= 2) {
		d2[1] = true;
	}
	if (n >= 3) {
		d3[2] = true;
	}

	for (i = 3; i < n; ++i) {
		if (d3[i - 2]) {
			d2[i] = true;
		}
		else if (d2[i - 2] && s.substr(i - 3, 2) != s.substr(i - 1, 2)) {
			d2[i] = true;
		}

		if (d2[i - 3]) {
			d3[i] = true;
		}
		else if (i >= 5 && d3[i - 3] && s.substr(i - 5, 3) != s.substr(i - 2, 3)) {
			d3[i] = true;
		}
	}

	std::set<std::string> suffixes;
	for (i = 0; i < n; ++i) {
		if (d2[i]) {
			std::string temp = s.substr(i - 1, 2);
			std::reverse(temp.begin(), temp.end());
			suffixes.insert(temp);
		}

		if (d3[i]) {
			std::string temp = s.substr(i - 2, 3);
			std::reverse(temp.begin(), temp.end());
			suffixes.insert(temp);
		}
	}

	std::cout << suffixes.size() << std::endl;
	for (auto su : suffixes) {
		std::cout << su << std::endl;
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
vector<int>vec;
int main(){
	string AA;
	cin >> AA;
	if(AA.length()<=6){
		printf("0\n");
		return 0;
	}
	vector<string>vec;
	string A=AA.substr(5,A.length()-5);
//	cout << A << endl;
	if(A.length()==3){
		cout << "2 \n";
		cout << A[0] << A[1] << endl;
		cout << A << endl;
		return 0;
	}
	if(A.length()==2){
		cout << "1\n";
		cout << A << endl;
		return 0;
	}
	vec.push_back(A.substr(A.length()-2,2));
	vec.push_back(A.substr(A.length()-3,3));
	for(int i=0;i<A.length()-3;i++){
		vec.push_back(A.substr(i,2));
	}
	for(int i=0;i<A.length()-4;i++){
		vec.push_back(A.substr(i,3));
	}
	sort(vec.begin(),vec.end());
	vector<string>vec2;
	for(int i=1;i<vec.size();i++){
		if(vec[i]!=vec[i-1])
			vec2.push_back(vec[i-1]);
	}
	vec2.push_back(vec[vec.size()-1]);
	cout << vec2.size() << endl;
	for(int i=0;i<vec2.size();i++)
		cout << vec2[i] << endl;

}


#include<bits/stdc++.h>
using namespace std;
vector<int>vec;
int main(){
	string AA;
	cin >> AA;
	if(AA.length()<=6){
		printf("0\n");
		return 0;
	}
	vector<string>vec;
	string A=AA.substr(5,AA.length()-5);
//	cout << A << endl;
	if(A.length()==3){
		cout << "2 \n";
		cout << A[0] << A[1] << endl;
		cout << A << endl;
		return 0;
	}
	if(A.length()==2){
		cout << "1\n";
		cout << A << endl;
		return 0;
	}
	vec.push_back(A.substr(A.length()-2,2));
	vec.push_back(A.substr(A.length()-3,3));
	for(int i=0;i<A.length()-3;i++){
		vec.push_back(A.substr(i,2));
	}
	for(int i=0;i<A.length()-4;i++){
		vec.push_back(A.substr(i,3));
	}
	sort(vec.begin(),vec.end());
	vector<string>vec2;
	for(int i=1;i<vec.size();i++){
		if(vec[i]!=vec[i-1])
			vec2.push_back(vec[i-1]);
	}
	vec2.push_back(vec[vec.size()-1]);
	cout << vec2.size() << endl;
	for(int i=0;i<vec2.size();i++)
		cout << vec2[i] << endl;

}


#include<bits/stdc++.h>
using namespace std;
void solve(){
	string  A;
	cin >> A;
	int ans1=0,ans2=0;
	int n=A.length();
	vector<int>vec0,vec1;
	int pref[2][1000],suff[2][1000];
	for(int i=0;i<n;i++){
		pref[0][i]=0;
		pref[1][i]=0;
		suff[0][i]=0;
		suff[1][i]=0;
	}
	for(int i=0;i<n;i++){
		if(A[i]=='0')
			vec0.push_back(i);
		else
			vec1.push_back(i);
	}
	for(int i=0;i<vec0.size()-1;i++){
		ans1+=(vec0[i+1]-vec0[i]-1);
	}
	int temp1=0,temp2=0;
	if(vec1[vec1.size()-1]>vec0[vec0.size()-1]){
		temp1=(vec1[vec1.size()-1]-vec0[vec0.size()-1]);
	}
	if(vec0[0]>vec1[0]){
		temp2=(vec0[0]-vec1[0]);
	}
	ans1+=(min(temp1,temp2));
	temp1=0,temp2=0;
	for(int i=0;i<vec1.size()-1;i++){
		ans2+=(vec1[i+1]-vec1[i]-1);
	}
	if(vec0[vec0.size()-1]>vec1[vec1.size()-1]){
		temp1=(vec0[vec0.size()-1]-vec1[vec1.size()-1]);
	}
	if(vec1[0]>vec0[0]){
		temp2=(vec1[0]-vec0[0]);
	}
	ans2+=(min(temp1,temp2));
	cout << min(ans1, ans2) << endl;
}
int main(){
	int t;
	cin >> t;
	while(t--)
		solve();
}


#include <bits/stdc++.h>
#define watch(x) std::cout << "$ LINE @" << __LINE__ << " FUNC @" << __FUNCTION__ << "\n$ " \
                           << (#x) << ": " << x << std::endl

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

template <typename Tp>
inline void read(Tp &x)
{
    static char c;
    static bool neg;
    x = 0, c = getchar(), neg = false;
    for (; !isdigit(c); c = getchar())
    {
        if (c == '-')
        {
            neg = true;
        }
    }
    for (; isdigit(c); c = getchar())
    {
        x = x * 10 + c - '0';
    }
    if (neg)
    {
        x = -x;
    }
}

const int N = 1e4 + 5;

string str, temp;
int n;
bool vis[N];
vector<string> vec;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);

    cin >> str;
    if (str.length() == 5UL)
    {
        puts("0");
        return 0;
    }
    str = str.substr(5);
    n = (int)str.length();
    vis[n] = true;
    for (int i = n - 1; i >= 0; --i)
    {
        for (int len = 2; len <= 3; ++len)
        {
            if (i + len <= n)
            {
                temp = str.substr(i, len);
                if (((int)str.find(temp, i + len) != i + len || vis[i + 5]) && vis[i + len])
                {
                    vec.emplace_back(temp);
                    vis[i] = true;
                }
            }
        }
    }
    sort(vec.begin(), vec.end());
    cout << vec.size() << "\n";
    for (const auto &s : vec)
    {
        cout << s << "\n";
    }
}


#include <bits/stdc++.h>
#define watch(x) std::cout << "$ LINE @" << __LINE__ << " FUNC @" << __FUNCTION__ << "\n$ " \
                           << (#x) << ": " << x << std::endl

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

template <typename Tp>
inline void read(Tp &x)
{
    static char c;
    static bool neg;
    x = 0, c = getchar(), neg = false;
    for (; !isdigit(c); c = getchar())
    {
        if (c == '-')
        {
            neg = true;
        }
    }
    for (; isdigit(c); c = getchar())
    {
        x = x * 10 + c - '0';
    }
    if (neg)
    {
        x = -x;
    }
}

const int N = 1e4 + 5;

string str, temp;
int n;
bool vis[N];
vector<string> vec;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);

    cin >> str;
    if (str.length() == 5UL)
    {
        puts("0");
        return 0;
    }
    str = str.substr(5);
    n = (int)str.length();
    vis[n] = true;
    for (int i = n - 1; i >= 0; --i)
    {
        for (int len = 2; len <= 3; ++len)
        {
            if (i + len <= n)
            {
                temp = str.substr(i, len);
                if (((int)str.find(temp, i + len) != i + len || vis[i + 5]) && vis[i + len])
                {
                    vec.emplace_back(temp);
                    vis[i] = true;
                }
            }
        }
    }
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    cout << vec.size() << "\n";
    for (const auto &s : vec)
    {
        cout << s << "\n";
    }
}


#include <bits/stdc++.h>
#define watch(x) std::cout << "$ LINE @" << __LINE__ << " FUNC @" << __FUNCTION__ << "\n$ " \
                           << (#x) << ": " << x << std::endl

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

template <typename Tp>
inline void read(Tp &x)
{
    static char c;
    static bool neg;
    x = 0, c = getchar(), neg = false;
    for (; !isdigit(c); c = getchar())
    {
        if (c == '-')
        {
            neg = true;
        }
    }
    for (; isdigit(c); c = getchar())
    {
        x = x * 10 + c - '0';
    }
    if (neg)
    {
        x = -x;
    }
}

string str;
unordered_set<string> st;
unordered_map<string, int> cnt;
vector<string> res;

void dfs(int depth, int len)
{
    if (depth < 5)
    {
        return;
    }
    string suffix = str.substr(depth, len);
    ++cnt[suffix];
    dfs(depth - 2, 2);
    dfs(depth - 3, 3);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);

    cin >> str;
    dfs(str.length() - 2UL, 2);
    dfs(str.length() - 3UL, 3);
    for (const auto &p : cnt)
    {
        if (p.second == 1)
        {
            res.emplace_back(p.first);
        }
    }
    sort(res.begin(), res.end());
    cout << res.size() << "\n";
    for (const auto &s : res)
    {
        cout << s << "\n";
    }
    return 0;
}


#include <bits/stdc++.h>
#define watch(x) std::cout << "$ LINE @" << __LINE__ << " FUNC @" << __FUNCTION__ << "\n$ " \
                           << (#x) << ": " << x << std::endl

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

template <typename Tp>
inline void read(Tp &x)
{
    static char c;
    static bool neg;
    x = 0, c = getchar(), neg = false;
    for (; !isdigit(c); c = getchar())
    {
        if (c == '-')
        {
            neg = true;
        }
    }
    for (; isdigit(c); c = getchar())
    {
        x = x * 10 + c - '0';
    }
    if (neg)
    {
        x = -x;
    }
}

const int N = 1e4 + 5;

string str, temp;
int n;
bool vis[N];
vector<string> vec;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);

    cin >> str;
    if (str.length() == 5UL)
    {
        puts("0");
        return 0;
    }
    str = str.substr(5);
    n = (int)str.length();
    vis[n] = true;
    for (int i = n - 1; i >= 0; --i)
    {
        for (int len = 2; len <= 3; ++len)
        {
            if (i + len <= n)
            {
                temp = str.substr(i, len);
                if ((str.find(temp, i + len) == str.npos || vis[i + 5]) && vis[i + len])
                {
                    vec.emplace_back(temp);
                    vis[i] = true;
                }
            }
        }
    }
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    cout << vec.size() << "\n";
    for (const auto &s : vec)
    {
        cout << s << "\n";
    }
}


#include <bits/stdc++.h>
#define watch(x) std::cout << "$ LINE @" << __LINE__ << " FUNC @" << __FUNCTION__ << "\n$ " \
                           << (#x) << ": " << x << std::endl

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

template <typename Tp>
inline void read(Tp &x)
{
    static char c;
    static bool neg;
    x = 0, c = getchar(), neg = false;
    for (; !isdigit(c); c = getchar())
    {
        if (c == '-')
        {
            neg = true;
        }
    }
    for (; isdigit(c); c = getchar())
    {
        x = x * 10 + c - '0';
    }
    if (neg)
    {
        x = -x;
    }
}

const int N = 1e4 + 5;

string str, temp;
int n;
bool vis[N];
vector<string> vec;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);

    cin >> str;
    n = str.length();
    if (n == 5)
    {
        puts("0");
        return 0;
    }
    vis[n] = true;
    for (int i = n - 1; i >= 5; --i)
    {
        for (int len = 2; len <= 3; ++len)
        {
            if (i + len <= n)
            {
                temp = str.substr(i, len);
                if (((int)str.find(temp, i + len) != i + len || vis[i + 5]) && vis[i + len])
                {
                    vec.emplace_back(temp);
                    vis[i] = true;
                }
            }
        }
    }
    sort(vec.begin(), vec.end());
    cout << vec.size() << "\n";
    for (const auto &s : vec)
    {
        cout << s << "\n";
    }
}


#include <bits/stdc++.h>
#define watch(x) std::cout << "$ LINE @" << __LINE__ << " FUNC @" << __FUNCTION__ << "\n$ " \
                           << (#x) << ": " << x << std::endl

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

template <typename Tp>
inline void read(Tp &x)
{
    static char c;
    static bool neg;
    x = 0, c = getchar(), neg = false;
    for (; !isdigit(c); c = getchar())
    {
        if (c == '-')
        {
            neg = true;
        }
    }
    for (; isdigit(c); c = getchar())
    {
        x = x * 10 + c - '0';
    }
    if (neg)
    {
        x = -x;
    }
}

const int N = 1e4 + 5;

string str, temp;
int n;
bool vis[N];
vector<string> vec;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);

    cin >> str;
    if (str.length() == 5UL)
    {
        puts("0");
        return 0;
    }
    str = str.substr(5);
    n = (int)str.length();
    vis[n] = true;
    for (int i = n - 1; i >= 0; --i)
    {
        for (int len = 2; len <= 3; ++len)
        {
            if (i + len <= n)
            {
                temp = str.substr(i, len);
                if (((int)str.find(temp, i + len) != i + len || vis[i + 5]) && vis[i + len])
                {
                    vec.emplace_back(temp);
                    vis[i] = true;
                }
            }
        }
    }
    cout << vec.size() << "\n";
    for (const auto &s : vec)
    {
        cout << s << "\n";
    }
}


#include <bits/stdc++.h>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<utility>
#include<vector>

typedef long long int ll;
typedef unsigned long long int ull;

const ll mod = 1e9+9;

using namespace std;

main(int argc, char const *argv[]) {
  //freopen("test.txt","r", stdin);

  string s;
  ll size;

  cin >> s;
  size = s.length();

  set<string>res;

  bool lel[size] = {1};
  for (int i = size - 1; i > 4; i--) {
        if (lel[i + 2] == true) {
            string t = s.substr(i, 2);
            if (s.find(t, i + 2) != i + 2 || lel[i + 5]) {
                lel[i] = 1;
                res.insert(t);
            }
        }
        if (lel[i + 3] == true){
            string t = s.substr(i, 3);
            if (s.find(t, i + 3) != i + 3 || lel[i + 5])
            {
                lel[i] = 1;
                res.insert(t);
            }
        }
    }
    ll conut = res.size();
    cout << conut << endl;

    for (auto iter : res) {
        cout << iter << endl;
    }

 // cout << valid << endl;
  return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <set>
using namespace std;

bool valid[10000 + 100];
set<string>ans;
int main()
{
    string s;
    cin >> s;
    valid[s.length()] = 1;
    for (int i = s.length() - 1; i>4; --i)
    {
        if (valid[i + 2])
        {
            string t = s.substr(i, 2);
            if (s.find(t, i + 2) != i + 2 || valid[i + 5])
            {
                valid[i] = 1;
                ans.insert(t);
            }
        }
        if (valid[i + 3])
        {
            string t = s.substr(i, 3);
            if (s.find(t, i + 3) != i + 3 || valid[i + 5])
            {
                valid[i] = 1;
                ans.insert(t);
            }
        }
    }
    cout << ans.size() << "\n";
    for (auto &ite : ans)
    {
        cout << ite << "\n";
    }
    return 0;
}


#include <bits/stdc++.h>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<utility>
#include<vector>

typedef long long int ll;
typedef unsigned long long int ull;

const ll mod = 1e9+9;

using namespace std;

main(int argc, char const *argv[]) {
  //freopen("test.txt","r", stdin);

  string s;
  int size;

  cin >> s;
  size = s.length();

  set<string>res;

  bool lel[size] = {true};
  for (int i = size - 1; i > 4; i--) {
        if (lel[i + 2]) {
            if (s.find(s.substr(i, 2), i + 2) != i + 2 || lel[i + 5]) {
                lel[i] = true;
                res.insert(s.substr(i, 2));
            }
        }
        if (lel[i + 3]){
            if (s.find(s.substr(i, 3), i + 3) != i + 3 || lel[i + 5]) {
                lel[i] = true;
                res.insert(s.substr(i, 3));
            }
        }
    }
    int conut = res.size();
    cout << conut << endl;

    for (auto iter : res) {
        cout << iter << endl;
    }

 // cout << valid << endl;
  return 0;
}


#include <bits/stdc++.h>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<utility>
#include<vector>

typedef long long int ll;
typedef unsigned long long int ull;

const ll mod = 1e9+9;

using namespace std;

main(int argc, char const *argv[]) {
  freopen("test.txt","r", stdin);

  string s;
  int size;

  cin >> s;
  size = s.length();

  set<string>res;

  bool valid[size] = {true};
  for (int i = size - 1; i > 4; i--) {
        if (valid[i + 2]) {
            string t = s.substr(i, 2);
            if (s.find(t, i + 2) != i + 2 || valid[i + 5]) {
                valid[i] = true;
                res.insert(t);
            }
        }
        if (valid[i + 3]){
            string t = s.substr(i, 3);
            if (s.find(t, i + 3) != i + 3 || valid[i + 5])
            {
                valid[i] = true;
                res.insert(t);
            }
        }
    }
    int conut = res.size();
    cout << conut << endl;

    for (auto iter : res) {
        cout << iter << endl;
    }

 // cout << valid << endl;
  return 0;
}


// dile a la jardinera que traigo flores
#pragma GCC optimize ("Ofast,unroll-loops")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>

#define pb push_back
#define ff  first
#define ss second
#define tm1 first
#define tm2 second.first
#define tm3 second.second
#define sz(x) int(x.size())
#define fill(x, v) memset(x, v, sizeof(x))
#define all(v) (v).begin(), (v).end()
#define FER(i,a,b) for(ll i=ll(a); i< ll(b); ++i)
#define IFR(i,a,b) for(ll i=ll(a); i>=ll(b); --i )
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)

#define N 200005
#define mod 1000000007
#define N1 1005
#define sqr(x) (x)*(x)
#define INF 10000000000000

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef pair<ll, ll> ii;
typedef pair<ll, ii > tri;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> set_t;

#define trace(...) f(#__VA_ARGS__, __VA_ARGS__)

template<typename t> void f(const char* x, t&& val1){
  cout<<x<< " : "<<val1<<endl;
}
template<typename t1, typename... t2> void f(const char* x, t1&& val1, t2&&... val2){
  const char* xd=strchr(x+1, ',');
  cout.write(x, xd-x)<<" : "<<val1<<" | ";
  f(xd+1, val2...);
}
string s;
inline string go(ll i, ll ta){
  string ans;
  if(i+ta>sz(s)) return ans;
  FER(j, i, i+ta) ans+=s[j];
  return ans;
}
ll dp[N][2];
ll tnt[N];
int main(){
  fastio;
  cin>>s;
  map<string, ll> m;
  fill(tnt, 0);
  fill(dp, 0);
  ll ta=sz(s);
  tnt[ta-3]=1;
  tnt[ta-2]=1;
  dp[ta-2][0]=1;
  dp[ta-3][1]=1;
  IFR(i,ta-4,4){
    string a1=go(i, 2), a2=go(i, 3);
    string t1=go(i+2,2), t2=go(i+3, 3);
    //trace(a1, a2, t1, t2);
    dp[i][0]=(a1==t1)? (m[go(i+2, 3)]++, dp[i+2][1]): (m[t1]++, m[go(i+2, 3)], tnt[i+2]);
    dp[i][1]=(a2==t2)? (m[go(i+3, 2)]++, dp[i+3][0]):(m[t2]++, m[go(i+3, 2)], tnt[i+3]);
    //trace(tnt[i+2], tnt[i+3]);
    //trace(dp[i][0], dp[i][1], i);
    tnt[i]=dp[i][0]+dp[i][1];
  }
  ll froz=(sz(m));
  cout<<max(froz-1, 0LL)<<endl;
  if(froz){
  	auto it=m.begin();
    m.erase(it);
    for(auto xd: m) cout<<xd.ff<<endl;
  }
  return 0;
}


// dile a la jardinera que traigo flores
#pragma GCC optimize ("Ofast,unroll-loops")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>

#define pb push_back
#define ff  first
#define ss second
#define tm1 first
#define tm2 second.first
#define tm3 second.second
#define sz(x) int(x.size())
#define fill(x, v) memset(x, v, sizeof(x))
#define all(v) (v).begin(), (v).end()
#define FER(i,a,b) for(ll i=ll(a); i< ll(b); ++i)
#define IFR(i,a,b) for(ll i=ll(a); i>=ll(b); --i )
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)

#define N 200005
#define mod 1000000007
#define N1 1005
#define sqr(x) (x)*(x)
#define INF 10000000000000

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef pair<ll, ll> ii;
typedef pair<ll, ii > tri;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> set_t;

#define trace(...) f(#__VA_ARGS__, __VA_ARGS__)

template<typename t> void f(const char* x, t&& val1){
  cout<<x<< " : "<<val1<<endl;
}
template<typename t1, typename... t2> void f(const char* x, t1&& val1, t2&&... val2){
  const char* xd=strchr(x+1, ',');
  cout.write(x, xd-x)<<" : "<<val1<<" | ";
  f(xd+1, val2...);
}
string s;
inline string go(ll i, ll ta){
  string ans;
  if(i+ta>sz(s)) return ans;
  FER(j, i, i+ta) ans+=s[j];
  return ans;
}
ll dp[N][2];
ll tnt[N];
int main(){
  fastio;
  cin>>s;
  ll n=sz(s);
  dp[n][0]=1;
  dp[n][1]=1;
  map<string, ll>m;
  IFR(i, n-2, 5){
    if(dp[i+2][1] || dp[i+2][0] && go(i+2, 2)!=go(i, 2)) dp[i][0]=1, m[go(i, 2)]++;
    if(dp[i+3][0] || dp[i+3][1] && go(i+3, 3)!=go(i, 3)) dp[i][1]=1, m[go(i, 3)]++;
  }
  cout<<sz(m)<<endl;
  for(auto xd: m) cout<<xd.ff<<endl;
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod=1000000007;
int main()
{
    ll n,i,j,res,count;
    string s;
    cin>>s;
    n=s.length();
    char c[n + 1];
    strcpy(c,s.c_str());
    set<string> v;
    for(i=n-1;i>=6;i--)
    {
        if(i==n-2)
            continue;
        char a[3];
        a[0]=c[i-1];
        a[1]=c[i];
        a[2]='\0';
        std::string sx(a);
        v.insert(sx);
    }
    for(i=n-1;i>=7;i--)
    {
        if(i==n-2)
            continue;
        char a[4];
        a[0]=c[i-2];
        a[1]=c[i-1];
        a[2]=c[i];
        a[3]='\0';
        std::string sx(a);
        if((i+4)<n)
        {
            if((c[i+1]==c[i+3])&&(c[i+2]==c[i+4]))
                continue;
        }
        if((i+6)<n)
        {
            if((c[i+1]==c[i+4])&&(c[i+2]==c[i+5])&&(c[i+3]==c[i+6]))
                continue;
        }
        v.insert(sx);
    }
    cout<<v.size()<<"\n";
    set<string>::iterator it;
    for(it=v.begin();it!=v.end();it++)
    {
        cout<<*it<<"\n";
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod=1000000007;
int main()
{
    ll n,i,j,res,count;
    string s;
    cin>>s;
    n=s.length();
    char c[n + 1];
    strcpy(c,s.c_str());
    set<string> v;
    for(i=n-1;i>=6;i--)
    {
        if(i==n-2)
            continue;
        char a[2];
        a[0]=c[i-1];
        a[1]=c[i];
        std::string sx(a);
        v.insert(sx);
    }
    for(i=n-1;i>=7;i--)
    {
        if(i==n-2)
            continue;
        char a[3];
        a[0]=c[i-2];
        a[1]=c[i-1];
        a[2]=c[i];
        std::string sx(a);
        v.insert(sx);
    }
    cout<<v.size()<<"\n";
    set<string>::iterator it;
    for(it=v.begin();it!=v.end();it++)
    {
        cout<<*it<<"\n";
    }
    return 0;
}


import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{
	PrintWriter out = new PrintWriter(System.out);
	BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer tok = new StringTokenizer("");
    String next() throws IOException {
        if (!tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); }
        return tok.nextToken();
    }
    int ni() throws IOException { return Integer.parseInt(next()); }
    long nl() throws IOException { return Long.parseLong(next()); }

    long mod=1000000007;

    void solve() throws IOException {
        String s=next();
        String t=next();
        int tn=t.length();
        int[]A=new int[tn];

        for (int i=0;i<tn;i++) {
            if (t.charAt(i)=='1') A[i]=1;
            //h=(h*3+A[i])%mod;
        }

        long h=0;
        long g=0;
        long mult=1;
        ArrayList<Integer>C=new ArrayList();

        for (int i=0;i<tn-1;i++) {
            h=(h*3+A[i])%mod;
            g=(g+mult*A[tn-1-i])%mod;
            mult=(mult*3)%mod;
            if (g==h) C.add(i+1);
            //out.println(i+" "+h+" "+g);
        }

        int over=0;
        for (int i=C.size()-1;i>=0;i--) {
            int u=C.get(i);
            //out.println(u);
            boolean f=true;
            for (int p=0,q=tn-u;p<u;p++,q++) {
                if (A[p]!=A[q]) { f=false; break; }
            }
            if (f) { over=u; break; }
        }

        //out.println(over);

        int one=0;
        int zero=0;
        for (int i=0;i<s.length();i++) {
            if (s.charAt(i)=='1') one++;
            else zero++;
        }

        int ct=0;
        int p=0;
        while (ct<s.length()) {
            if (A[p]==1) {
                if (one>0) { out.print(1); one--; }
                else break;
            }
            else {
                if (zero>0) { out.print(0); zero--; }
                else break;
            }
            ct++;
            p++;
            if (p==tn) p=over;
        }

        while (one>0) { out.print(1); one--; }
        while (zero>0) { out.print(0); zero--; }
        out.println();
        out.flush();
    }

    int gcd(int a,int b) { return(b==0?a:gcd(b,a%b)); }
    long gcd(long a,long b) { return(b==0?a:gcd(b,a%b)); }
    long mp(long a,long p) { long r=1; while(p>0) { if ((p&1)==1) r=(r*a)%mod; p>>=1; a=(a*a)%mod; } return r; }

    public static void main(String[] args) throws IOException {
        new Main().solve();
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class D {

	public static void main(String[] args) {
		FastReader scan = new FastReader();
		PrintWriter out = new PrintWriter(System.out);
		int o = 0, z = 0;
		char[] a = scan.next().toCharArray();
		char[] b = scan.next().toCharArray();
		for(char c : a) {
			if(c == '1') o++;
			else z++;
		}
		int index = 0;
		for(int i = 0; i < a.length; i++) {
			if(b[index] == '1' ) {
				if(o > 0) {
					out.print('1');
					o--;
				}
				else {
					out.print('0');
					z--;
				}
			}
			else {
				if(z > 0) {
					out.print('0');
					z--;
				}
				else {
					out.print('1');
					o--;
				}
			}
			index = (index+1) % b.length;
		}
		out.close();

	}

	static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Random;
import java.util.StringTokenizer;

public class E {

	public static void main(String[] args) {
		FastReader scan = new FastReader();
		PrintWriter out = new PrintWriter(System.out);
		Task solver = new Task();
		solver.solve(1, scan, out);
		out.close();
	}

	static class Task {
		static long[][] exp;
		static char[] s;
		static char[] t;
		static int[] val = {7, 13};
		static long[] MOD = {17, 23, 57, 107, 109, 217, 651};

		public void solve(int testNumber, FastReader scan, PrintWriter out) {
			s = scan.next().toCharArray();
			t = scan.next().toCharArray();
			exp = new long[t.length+1][MOD.length];
			for(int i = 0; i <= t.length; i++) {
				for(int j = 0; j < MOD.length; j++) {
					if(i == 0) exp[i][j] = 1;
					else exp[i][j] = mult(exp[i-1][j], 2, MOD[j]);
				}
			}
			int minLen = t.length-findMax(), at = 0;
			int[] count = new int[2];
			for(int i = 0; i < s.length; i++) count[s[i]-'0']++;
			for(int i = 0; i < s.length; i++) {
				int need = t[at]-'0';
				if(count[need] == 0) need ^= 1;
				count[need]--;
				out.print(need);
				at = (int) add(at, 1, minLen);
			}
 		}

		static int findMax() {
			RollingHash start = new RollingHash(), end = new RollingHash();
			int max = 0;
			for(int i = 0; i < t.length/2; i++) {
				start.addLast(t[i]-'0');
				end.addFirst(t[t.length-i-1]-'0');
				if(start.check(end)) max = i+1;
			}
			return max;
		}

		static long mult(long a, long b, long mod) {
			return ((a%mod)*(b%mod))%mod;
		}
		static long add(long a, long b, long mod) {
			return (a%mod+b%mod)%mod;
		}

		static class RollingHash {
			int size = 0;
			long[] value = new long[MOD.length];

			public void addFirst(int v) {
				for(int i = 0; i < value.length; i++) {
					value[i] = add(value[i], mult(val[v], exp[size][i], MOD[i]), MOD[i]);
				}
				size++;
			}
			public void addLast(int v) {
				for(int i = 0; i < value.length; i++) {
					value[i] = mult(value[i], 2, MOD[i]);
					value[i] = add(value[i], val[v], MOD[i]);
				}
				size++;
			}
			public boolean check(RollingHash other) {
				for(int i = 0; i < value.length; i++) {
					if(value[i] != other.value[i]) return false;
				}
				return true;
			}
		}
	}

	static void shuffle(int[] a) {
		Random get = new Random();
		for(int i = 0; i < a.length; i++) {
			int r = get.nextInt(a.length);
			int temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
	}

	static void shuffle(long[] a) {
		Random get = new Random();
		for(int i = 0; i < a.length; i++) {
			int r = get.nextInt(a.length);
			long temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		public FastReader(String s) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(new File(s)));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Random;
import java.util.StringTokenizer;

public class E {

	public static void main(String[] args) {
		FastReader scan = new FastReader();
		PrintWriter out = new PrintWriter(System.out);
		Task solver = new Task();
		solver.solve(1, scan, out);
		out.close();
	}

	static class Task {
		static long[][] exp;
		static char[] s;
		static char[] t;
		static int[] val = {7, 13};
		static long[] MOD = {(int) 1e9+7, (int) 1e9+9, (int) 1e9+23};

		public void solve(int testNumber, FastReader scan, PrintWriter out) {
			s = scan.next().toCharArray();
			t = scan.next().toCharArray();
			exp = new long[t.length+1][MOD.length];
			for(int i = 0; i <= t.length; i++) {
				for(int j = 0; j < MOD.length; j++) {
					if(i == 0) exp[i][j] = 1;
					else exp[i][j] = mult(exp[i-1][j], 2, MOD[j]);
				}
			}
			int minLen = t.length-findMax(), at = 0;
			int[] count = new int[2];
			for(int i = 0; i < s.length; i++) count[s[i]-'0']++;
			for(int i = 0; i < s.length; i++) {
				int need = t[at]-'0';
				if(count[need] == 0) need ^= 1;
				count[need]--;
				out.print(need);
				at = (int) add(at, 1, minLen);
			}
 		}

		static int findMax() {
			RollingHash start = new RollingHash(), end = new RollingHash();
			int max = 0;
			for(int i = 0; i < t.length/2; i++) {
				start.addLast(t[i]-'0');
				end.addFirst(t[t.length-i-1]-'0');
				if(start.check(end)) max = i+1;
			}
			return max;
		}

		static long mult(long a, long b, long mod) {
			return ((a%mod)*(b%mod))%mod;
		}
		static long add(long a, long b, long mod) {
			return (a%mod+b%mod)%mod;
		}

		static class RollingHash {
			int size = 0;
			long[] value = new long[MOD.length];

			public void addFirst(int v) {
				for(int i = 0; i < value.length; i++) {
					value[i] = add(value[i], mult(val[v], exp[size][i], MOD[i]), MOD[i]);
				}
				size++;
			}
			public void addLast(int v) {
				for(int i = 0; i < value.length; i++) {
					value[i] = mult(value[i], 2, MOD[i]);
					value[i] = add(value[i], val[v], MOD[i]);
				}
				size++;
			}
			public boolean check(RollingHash other) {
				for(int i = 0; i < value.length; i++) {
					if(value[i] != other.value[i]) return false;
				}
				return true;
			}
		}
	}

	static void shuffle(int[] a) {
		Random get = new Random();
		for(int i = 0; i < a.length; i++) {
			int r = get.nextInt(a.length);
			int temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
	}

	static void shuffle(long[] a) {
		Random get = new Random();
		for(int i = 0; i < a.length; i++) {
			int r = get.nextInt(a.length);
			long temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		public FastReader(String s) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(new File(s)));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Random;
import java.util.StringTokenizer;

public class E {

	public static void main(String[] args) {
		FastReader scan = new FastReader();
		PrintWriter out = new PrintWriter(System.out);
		Task solver = new Task();
		solver.solve(1, scan, out);
		out.close();
	}

	static class Task {
		static long[][] exp;
		static char[] s;
		static char[] t;
		static int[] val = {7, 13};
		static long[] MOD = {17, 23, 57};

		public void solve(int testNumber, FastReader scan, PrintWriter out) {
			s = scan.next().toCharArray();
			t = scan.next().toCharArray();
			exp = new long[t.length+1][MOD.length];
			for(int i = 0; i <= t.length; i++) {
				for(int j = 0; j < MOD.length; j++) {
					if(i == 0) exp[i][j] = 1;
					else exp[i][j] = mult(exp[i-1][j], 2, MOD[j]);
				}
			}
			int minLen = t.length-findMax(), at = 0;
			int[] count = new int[2];
			for(int i = 0; i < s.length; i++) count[s[i]-'0']++;
			for(int i = 0; i < s.length; i++) {
				int need = t[at]-'0';
				if(count[need] == 0) need ^= 1;
				count[need]--;
				out.print(need);
				at = (int) add(at, 1, minLen);
			}
 		}

		static int findMax() {
			RollingHash start = new RollingHash(), end = new RollingHash();
			int max = 0;
			for(int i = 0; i < t.length/2; i++) {
				start.addLast(t[i]-'0');
				end.addFirst(t[t.length-i-1]-'0');
				if(start.check(end)) max = i+1;
			}
			return max;
		}

		static long mult(long a, long b, long mod) {
			return ((a%mod)*(b%mod))%mod;
		}
		static long add(long a, long b, long mod) {
			return (a%mod+b%mod)%mod;
		}

		static class RollingHash {
			int size = 0;
			long[] value = new long[MOD.length];

			public void addFirst(int v) {
				for(int i = 0; i < value.length; i++) {
					value[i] = add(value[i], mult(val[v], exp[size][i], MOD[i]), MOD[i]);
				}
				size++;
			}
			public void addLast(int v) {
				for(int i = 0; i < value.length; i++) {
					value[i] = mult(value[i], 2, MOD[i]);
					value[i] = add(value[i], val[v], MOD[i]);
				}
				size++;
			}
			public boolean check(RollingHash other) {
				for(int i = 0; i < value.length; i++) {
					if(value[i] != other.value[i]) return false;
				}
				return true;
			}
		}
	}

	static void shuffle(int[] a) {
		Random get = new Random();
		for(int i = 0; i < a.length; i++) {
			int r = get.nextInt(a.length);
			int temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
	}

	static void shuffle(long[] a) {
		Random get = new Random();
		for(int i = 0; i < a.length; i++) {
			int r = get.nextInt(a.length);
			long temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		public FastReader(String s) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(new File(s)));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class D {

	public static void main(String[] args) {
		FastReader scan = new FastReader();
		PrintWriter out = new PrintWriter(System.out);
		int o = 0, z = 0;
		char[] a = scan.next().toCharArray();
		char[] b = change(scan.next()).toCharArray();
		for(char c : a) {
			if(c == '1') o++;
			else z++;
		}
		int index = 0;
		for(int i = 0; i < a.length; i++) {
			if(b[index] == '1' ) {
				if(o > 0) {
					out.print('1');
					o--;
				}
				else {
					out.print('0');
					z--;
				}
			}
			else {
				if(z > 0) {
					out.print('0');
					z--;
				}
				else {
					out.print('1');
					o--;
				}
			}
			index = (index+1) % b.length;
		}
		out.close();

	}

	static String change(String l) {
		String res = "";
		int i = 0, j = 1;
		while(j < l.length()) {
			if(l.charAt(i) == l.charAt(j)) {
				i++;
				j++;
			}
			else {
				i = 0;
				j++;
			}
		}
		res = l.substring(0, j - i);
		return res;
	}

	static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class D {

	public static void main(String[] args) {
		FastReader scan = new FastReader();
		PrintWriter out = new PrintWriter(System.out);
		int o = 0, z = 0;
		char[] a = scan.next().toCharArray();
		char[] b = scan.next().toCharArray();
		for(char c : a) {
			if(c == '1') o++;
			else z++;
		}
		int index = 0;
		for(int i = 0; i < a.length; i++) {
			if(b[index] == '1' ) {
				if(o > 0) {
					out.print('1');
					o--;
				}
				else out.println('0');
			}
			else {
				if(z > 0) {
					out.print('0');
					z--;
				}
				else out.print('1');
			}
			index = (index+1) % b.length;
		}
		out.close();

	}

	static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class D {

	public static void main(String[] args) {
		FastReader scan = new FastReader();
		PrintWriter out = new PrintWriter(System.out);
		int o = 0, z = 0;
		char[] a = scan.next().toCharArray();
		char[] b = scan.next().toCharArray();
		for(char c : a) {
			if(c == '1') o++;
			else z++;
		}
		int index = 0;
		for(int i = 0; i < a.length; i++) {
			if(b[index] == '1' ) {
				if(o > 0) {
					out.print('1');
					o--;
				}
				else out.print('0');
			}
			else {
				if(z > 0) {
					out.print('0');
					z--;
				}
				else out.print('1');
			}
			index = (index+1) % b.length;
		}
		out.close();

	}

	static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

}


package codeforces.Round545;

import java.io.*;
import java.util.*;

public class D_CampSchedule {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader inp = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Solver solver = new Solver();
        solver.solve(inp, out);
        out.close();
    }

    private static class Solver {
        private void solve(InputReader inp, PrintWriter out) {
            String s = inp.next();
            String t = inp.next();
            int k = t.length() - 1;

            RollingHash left = new RollingHash(500001);
            RollingHash right = new RollingHash(500001);

            // minimum characters needed from the back
            int min = t.length();
            //left gets characters from the back
            //right gets charactes form the front
            for (int i = 0; i < t.length() - 1; i++) {
                left.addFirst(t.charAt(k - i));
                right.addLast(t.charAt(i));
                if (left.hash == right.hash && equal(left.hashedString, right.hashedString)) {
                    min = k - i;
                }
            }

            int costEA = 0, costEB = 0;
            for (int i = 0; i < min; i++) {
                if (t.charAt(k - i) == '0') costEA++;
                else costEB++;
            }

            int costSA = 0, costSB = 0;
            for (char c: s.toCharArray()) {
                if (c == '0') costSA++;
                else costSB++;
            }
            int costTA = 0, costTB = 0;
            for (char c: t.toCharArray()) {
                if (c == '0') costTA++;
                else costTB++;
            }
            StringBuilder sb = new StringBuilder();
            if (costTA <= costSA && costTB <= costSB) {
                sb.append(t);
                costSA -= costTA;
                costSB -= costTB;
            }
            String sub = t.substring(t.length() - min);
            while (costEA <= costSA && costEB <= costSB) {
                sb.append(sub);
                costSA -= costEA;
                costSB -= costEB;
            }
            while (costSA > 0) {
                sb.append('0');
                costSA--;
            }
            while (costSB > 0) {
                sb.append('1');
                costSB--;
            }
            out.print(sb.toString());
        }

        private boolean equal(LinkedList<Character> a, LinkedList<Character> b) {
            Object[] aa = a.toArray();
            Object[] ba = b.toArray();
            if (aa.length != ba.length) throw new RuntimeException();
            for (int i = 0; i < aa.length; i++) {
                if ((char) aa[i] != (char) ba[i]) return false;
            }
            return true;
        }

        public class RollingHash {
            //private String hashedString;
            private LinkedList<Character> hashedString;
            private long hash = 0;
            private final long a = 22695477;
            private final long m = (long) Math.pow(2, 32);
            private long invA;
            private long[] pow;

            private RollingHash(int n) {
                hashedString = new LinkedList<>();
                this.invA = inverse1(a, m);

                pow = new long[n + 1];
                pow[0] = 1;
                for (int i = 1; i <= n; i++) pow[i] = (pow[i - 1] * a) % m;
            }

            private void removeLast() {
                int n = hashedString.size() - 1;
                char c = hashedString.removeLast();
                hash -= c * pow[n];
                hash = ((hash % m) + m) % m;
            }

            private void removeFirst() {
                char c = hashedString.removeFirst();
                hash -= c;
                hash *= invA;
                hash = ((hash % m) + m) % m;
            }

            private void addLast(char c) {
                int n = hashedString.size();
                hash += c * pow[n];
                hash = hash % m;

                hashedString.addLast(c);
            }

            private void addFirst(char c) {
                hash *= a;
                hash += c;
                hash = hash % m;

                hashedString.addFirst(c);
            }
        }
        public static long inverse1(long a, long m) {
            long m0 = m, y = 0, x = 1;
            if (m == 1) return 0;
            while (a > 1) {
                long q = a / m, t = m;
                m = a % m;
                a = t;
                t = y;
                y = x - q * y;
                x = t;
            }
            if (x < 0) x += m0;
            return x;
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }
    }
}


import java.io.*;
import java.util.*;

public class D_CampSchedule {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader inp = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Solver solver = new Solver();
        solver.solve(inp, out);
        out.close();
    }

    private static class Solver {
        private void solve(InputReader inp, PrintWriter out) {
            String s = inp.next();
            String t = inp.next();
            int k = t.length() - 1;

            RollingHash left = new RollingHash(500001);
            RollingHash right = new RollingHash(500001);

            // minimum characters needed from the back
            int min = t.length();
            //left gets characters from the back
            //right gets charactes form the front
            for (int i = 0; i < t.length() - 1; i++) {
                left.addFirst(t.charAt(k - i));
                right.addLast(t.charAt(i));
                if (left.hash == right.hash && equal(left.hashedString, right.hashedString)) {
                    min = k - i;
                }
            }

            int costEA = 0, costEB = 0;
            for (int i = 0; i < min; i++) {
                if (t.charAt(k - i) == '0') costEA++;
                else costEB++;
            }

            int costSA = 0, costSB = 0;
            for (char c: s.toCharArray()) {
                if (c == '0') costSA++;
                else costSB++;
            }
            int costTA = 0, costTB = 0;
            for (char c: t.toCharArray()) {
                if (c == '0') costTA++;
                else costTB++;
            }
            StringBuilder sb = new StringBuilder();
            if (costTA <= costSA && costTB <= costSB) {
                sb.append(t);
                costSA -= costTA;
                costSB -= costTB;
            }
            String sub = t.substring(t.length() - min);
            while (costEA <= costSA && costEB <= costSB) {
                sb.append(sub);
                costSA -= costEA;
                costSB -= costEB;
            }
            while (costSA > 0) {
                sb.append('0');
                costSA--;
            }
            while (costSB > 0) {
                sb.append('1');
                costSB--;
            }
            out.print(sb.toString());
        }

        private boolean equal(LinkedList<Character> a, LinkedList<Character> b) {
            Object[] aa = a.toArray();
            Object[] ba = b.toArray();
            if (aa.length != ba.length) throw new RuntimeException();
            for (int i = 0; i < aa.length; i++) {
                if ((char) aa[i] != (char) ba[i]) return false;
            }
            return true;
        }

        public class RollingHash {
            //private String hashedString;
            private LinkedList<Character> hashedString;
            private long hash = 0;
            private final long a = 22695477;
            private final long m = (long) Math.pow(2, 32);
            private long invA;
            private long[] pow;

            private RollingHash(int n) {
                hashedString = new LinkedList<>();
                this.invA = inverse1(a, m);

                pow = new long[n + 1];
                pow[0] = 1;
                for (int i = 1; i <= n; i++) pow[i] = (pow[i - 1] * a) % m;
            }

            private void removeLast() {
                int n = hashedString.size() - 1;
                char c = hashedString.removeLast();
                hash -= c * pow[n];
                hash = ((hash % m) + m) % m;
            }

            private void removeFirst() {
                char c = hashedString.removeFirst();
                hash -= c;
                hash *= invA;
                hash = ((hash % m) + m) % m;
            }

            private void addLast(char c) {
                int n = hashedString.size();
                hash += c * pow[n];
                hash = hash % m;

                hashedString.addLast(c);
            }

            private void addFirst(char c) {
                hash *= a;
                hash += c;
                hash = hash % m;

                hashedString.addFirst(c);
            }
        }
        public static long inverse1(long a, long m) {
            long m0 = m, y = 0, x = 1;
            if (m == 1) return 0;
            while (a > 1) {
                long q = a / m, t = m;
                m = a % m;
                a = t;
                t = y;
                y = x - q * y;
                x = t;
            }
            if (x < 0) x += m0;
            return x;
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }
    }
}


import java.io.*;
import java.util.*;

public class D_CampSchedule {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader inp = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Solver solver = new Solver();
        solver.solve(inp, out);
        out.close();
    }

    private static class Solver {
        private void solve(InputReader inp, PrintWriter out) {
            String s = inp.next();
            String t = inp.next();
            int k = t.length() - 1;

            RollingHash left = new RollingHash(500001);
            RollingHash right = new RollingHash(500001);

            // minimum characters needed from the back
            int min = t.length();
            //left gets characters from the back
            //right gets charactes form the front
            for (int i = 0; i < t.length() - 1; i++) {
                left.addFirst(t.charAt(k - i));
                right.addLast(t.charAt(i));
                if (left.hash == right.hash && equal(left.hashedString, right.hashedString)) {
                    min = k - i;
                }
            }

            int costEA = 0, costEB = 0;
            for (int i = 0; i < min; i++) {
                if (t.charAt(k - i) == '0') costEA++;
                else costEB++;
            }

            int costSA = 0, costSB = 0;
            for (char c: s.toCharArray()) {
                if (c == '0') costSA++;
                else costSB++;
            }
            int costTA = 0, costTB = 0;
            for (char c: t.toCharArray()) {
                if (c == '0') costTA++;
                else costTB++;
            }
            StringBuilder sb = new StringBuilder();
            if (costTA <= costSA && costTB <= costSB) {
                sb.append(t);
                costSA -= costTA;
                costSB -= costTB;
            }
            String sub = t.substring(t.length() - min);
            while (costEA <= costSA && costEB <= costSB) {
                sb.append(sub);
                costSA -= costEA;
                costSB -= costEB;
            }
            while (costSA > 0) {
                sb.append('0');
                costSA--;
            }
            while (costSB > 0) {
                sb.append('1');
                costSB--;
            }
            out.print(sb.toString());
        }

        private boolean equal(LinkedList<Character> a, LinkedList<Character> b) {
            return true;
            /*Object[] aa = a.toArray();
            Object[] ba = b.toArray();
            if (aa.length != ba.length) throw new RuntimeException();
            for (int i = 0; i < aa.length; i++) {
                if ((char) aa[i] != (char) ba[i]) return false;
            }
            return true;*/
        }

        public class RollingHash {
            //private String hashedString;
            private LinkedList<Character> hashedString;
            private long hash = 0;
            private final long a = 22695477;
            private final long m = (long) Math.pow(2, 32);
            private long invA;
            private long[] pow;

            private RollingHash(int n) {
                hashedString = new LinkedList<>();
                this.invA = inverse1(a, m);

                pow = new long[n + 1];
                pow[0] = 1;
                for (int i = 1; i <= n; i++) pow[i] = (pow[i - 1] * a) % m;
            }

            private void removeLast() {
                int n = hashedString.size() - 1;
                char c = hashedString.removeLast();
                hash -= c * pow[n];
                hash = ((hash % m) + m) % m;
            }

            private void removeFirst() {
                char c = hashedString.removeFirst();
                hash -= c;
                hash *= invA;
                hash = ((hash % m) + m) % m;
            }

            private void addLast(char c) {
                int n = hashedString.size();
                hash += c * pow[n];
                hash = hash % m;

                hashedString.addLast(c);
            }

            private void addFirst(char c) {
                hash *= a;
                hash += c;
                hash = hash % m;

                hashedString.addFirst(c);
            }
        }
        public static long inverse1(long a, long m) {
            long m0 = m, y = 0, x = 1;
            if (m == 1) return 0;
            while (a > 1) {
                long q = a / m, t = m;
                m = a % m;
                a = t;
                t = y;
                y = x - q * y;
                x = t;
            }
            if (x < 0) x += m0;
            return x;
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class D {
    int[] funcZ(String two){
        int[] z = new int[two.length()];
        int l = 0;
        int r = 0;
        for(int i = 1;i<two.length();i++){
            if(i < r){
                z[i] = Math.min(r - i, z[i - l]);
            }
            while(i + z[i]< two.length() && two.charAt(i + z[i]) == two.charAt(z[i])){
                z[i]++;
            }
            if(i + z[i] > r){
                l = i;
                r = i + z[i];
            }
        }
        return z;
    }
    void solve() {
        String one = readString();
        String two = readString();
        if(two.length() > one.length()){
            out.print(one);
            return;
        }

        int[] z = funcZ(two);
        int num = two.length();
        for(int i = 1;i<two.length();i++){
            if(z[i] == two.length() - i){
                num = i;
                break;
            }
        }

        int now = 0;
        StringBuilder ans = new StringBuilder();
        for(int i = 0;i<two.length();i++){
            if(two.charAt(i) == '1') now++;
            ans.append(two.charAt(i));
        }

        int limit = 0;
        for(int i = 0;i<one.length();i++){
            if(one.charAt(i) == '1') limit++;
        }

        if(now > limit || one.length() - ans.length() < limit - now){
            out.print(one);
            return;
        }

        StringBuilder add =new StringBuilder();
        int addOne = 0;
        for(int i = two.length() - num;i<two.length();i++){
            add.append(two.charAt(i));
            if(two.charAt(i) == '1') addOne++;
        }

        while(add.length() + ans.length() <= one.length() && now + addOne <= limit && one.length() - ans.length() - add.length() >= limit - now - addOne){
            ans.append(add);
            now += addOne;
        }
        while(now < limit){
            ans.append('1');
            now++;
        }
        while(ans.length() < one.length()) ans.append('0');
        out.print(ans);
    }

    public static void main(String[] args) {
        new D().run();
    }

    private void run() {
        try {
            init();
            solve();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }

    private BufferedReader in;
    private StringTokenizer tok = new StringTokenizer("");

    private PrintWriter out;

    private void init() {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);

//        try {
//            in = new BufferedReader(new FileReader("absum.in"));
//            out = new PrintWriter(new File("absum.out"));
//        } catch (FileNotFoundException e) {
//            e.printStackTrace();
//        }
    }

    private String readLine() {
        try {
            return in.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    private String readString() {
        while (!tok.hasMoreTokens()) {
            String nextLine = readLine();
            if (nextLine == null) return null;
            tok = new StringTokenizer(nextLine);
        }

        return tok.nextToken();
    }

    private int readInt() {
        return Integer.parseInt(readString());
    }

    private long readLong() {
        return Long.parseLong(readString());
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class D {
    void solve() {
        String one = readString();
        String two = readString();
        if(two.length() > one.length()){
            out.print(one);
            return;
        }
        int left = 0;
        for(int i = 0;i<one.length();i++){
            if(one.charAt(i) == '1') left++;
        }
        int right = 0;
        for(int i = 0;i<two.length();i++){
            if(two.charAt(i) == '1') right++;
        }
        int now = left;
        StringBuilder ans = new StringBuilder();
        while(now - right >= 0 && ans.length() + two.length() <= one.length() && one.length() - ans.length() - two.length() >= now - right){
            ans.append(two);
            now-=right;
        }
        for(int i = ans.length();i<one.length();i++){
            if(now > 0){
                now--;
                ans.append('1');
            }else{
                ans.append('0');
            }
        }
        out.print(ans);
    }

    public static void main(String[] args) {
        new D().run();
    }

    private void run() {
        try {
            init();
            solve();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }

    private BufferedReader in;
    private StringTokenizer tok = new StringTokenizer("");

    private PrintWriter out;

    private void init() {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);

//        try {
//            in = new BufferedReader(new FileReader("absum.in"));
//            out = new PrintWriter(new File("absum.out"));
//        } catch (FileNotFoundException e) {
//            e.printStackTrace();
//        }
    }

    private String readLine() {
        try {
            return in.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    private String readString() {
        while (!tok.hasMoreTokens()) {
            String nextLine = readLine();
            if (nextLine == null) return null;
            tok = new StringTokenizer(nextLine);
        }

        return tok.nextToken();
    }

    private int readInt() {
        return Integer.parseInt(readString());
    }

    private long readLong() {
        return Long.parseLong(readString());
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class D {
    int[] funcZ(String two){
        int[] z = new int[two.length()];
        int l = 0;
        int r = 0;
        for(int i = 1;i<two.length();i++){
            if(i < r){
                z[i] = Math.min(r - i, z[i - l]);
            }
            while(i + z[i]< two.length() && two.charAt(i + z[i]) == two.charAt(z[i])){
                z[i]++;
            }
            if(i + z[i] > r){
                l = i;
                r = i + z[i];
            }
        }
        return z;
    }
    void solve() {
        String one = readString();
        String two = readString();
        if(two.length() > one.length()){
            out.print(one);
            return;
        }

        int[] z = funcZ(two);
        int num = two.length();
        for(int i = 1;i<two.length();i++){
            if(z[i] == two.length() - i){
                num = i;
                break;
            }
        }

        int now = 0;
        StringBuilder ans = new StringBuilder();
        for(int i = 0;i<two.length();i++){
            if(two.charAt(i) == '1') now++;
            ans.append(two.charAt(i));
        }

        int limit = 0;
        for(int i = 0;i<one.length();i++){
            if(one.charAt(i) == '1') limit++;
        }

        if(now > limit){
            out.print(one);
            return;
        }

        StringBuilder add =new StringBuilder();
        int addOne = 0;
        for(int i = two.length() - num;i<two.length();i++){
            add.append(two.charAt(i));
            if(two.charAt(i) == '1') addOne++;
        }

        while(add.length() + ans.length() <= one.length() && now + addOne <= limit && one.length() - ans.length() - add.length() >= limit - now - addOne){
            ans.append(add);
            now += addOne;
        }
        while(now < limit){
            ans.append('1');
            now++;
        }
        while(ans.length() < one.length()) ans.append('0');
        out.print(ans);
    }

    public static void main(String[] args) {
        new D().run();
    }

    private void run() {
        try {
            init();
            solve();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }

    private BufferedReader in;
    private StringTokenizer tok = new StringTokenizer("");

    private PrintWriter out;

    private void init() {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);

//        try {
//            in = new BufferedReader(new FileReader("absum.in"));
//            out = new PrintWriter(new File("absum.out"));
//        } catch (FileNotFoundException e) {
//            e.printStackTrace();
//        }
    }

    private String readLine() {
        try {
            return in.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    private String readString() {
        while (!tok.hasMoreTokens()) {
            String nextLine = readLine();
            if (nextLine == null) return null;
            tok = new StringTokenizer(nextLine);
        }

        return tok.nextToken();
    }

    private int readInt() {
        return Integer.parseInt(readString());
    }

    private long readLong() {
        return Long.parseLong(readString());
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class D {
    void solve() {
        String one = readString();
        String two = readString();
        if(two.length() > one.length()){
            out.print(one);
            return;
        }
        int left = 0;
        for(int i = 0;i<one.length();i++){
            if(one.charAt(i) == '1') left++;
        }
        int right = 0;
        for(int i = 0;i<two.length();i++){
            if(two.charAt(i) == '1') right++;
        }
        int now = left;
        StringBuilder ans = new StringBuilder();
        while(now - right >= 0 && ans.length() + two.length() <= one.length() && one.length() - ans.length() + two.length() >= now - right){
            ans.append(two);
            now-=right;
        }
        for(int i = ans.length();i<one.length();i++){
            if(now > 0){
                now--;
                ans.append('1');
            }else{
                ans.append('0');
            }
        }
        out.print(ans);
    }

    public static void main(String[] args) {
        new D().run();
    }

    private void run() {
        try {
            init();
            solve();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }

    private BufferedReader in;
    private StringTokenizer tok = new StringTokenizer("");

    private PrintWriter out;

    private void init() {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);

//        try {
//            in = new BufferedReader(new FileReader("absum.in"));
//            out = new PrintWriter(new File("absum.out"));
//        } catch (FileNotFoundException e) {
//            e.printStackTrace();
//        }
    }

    private String readLine() {
        try {
            return in.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    private String readString() {
        while (!tok.hasMoreTokens()) {
            String nextLine = readLine();
            if (nextLine == null) return null;
            tok = new StringTokenizer(nextLine);
        }

        return tok.nextToken();
    }

    private int readInt() {
        return Integer.parseInt(readString());
    }

    private long readLong() {
        return Long.parseLong(readString());
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;

public class CF1138D {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		char[] s = br.readLine().toCharArray();
		char[] t = br.readLine().toCharArray();
		int[] ctr = new int[2];
		for(int i=0; i<s.length; i++) ctr[s[i]-'0']++;
		int[] prefixHashes = new int[t.length];
		int[] suffixHashes = new int[t.length];
		int x = 256, mod = 1000000007;
		prefixHashes[0] = t[0];
		suffixHashes[t.length-1] = t[t.length-1];
		int maxps = 0;
		if(prefixHashes[0]==suffixHashes[t.length-1] && match(t, 1)) maxps = 1;
		for(int i=1; i<t.length-1; i++){
			prefixHashes[i] = (x*prefixHashes[i-1]+t[i])%mod;
			suffixHashes[t.length-i-1] = (x*suffixHashes[t.length-i]+t[t.length-i-1])%mod;
			if(prefixHashes[i]==suffixHashes[t.length-i-1] && match(t, i+1)) maxps = i+1;
		}
		int i = 0;
		StringBuilder sb = new StringBuilder();
		while(true){
			if(ctr[t[i]-'0']<1) break;
			sb.append(t[i]);
			ctr[t[i]-'0']--;
			i++;
			if(i==t.length) i = maxps;
		}
		while(ctr[0]>0){
			ctr[0]--;
			sb.append(0);
		}
		while(ctr[1]>0){
			ctr[1]--;
			sb.append(1);
		}
		System.out.println(sb);
	}

	static boolean match(char[] s, int len){
		for(int i=0; i<len; i++) if(s[i]!=s[s.length-len+i]) return false;
		return true;
	}
}


import java.io.BufferedReader;
import java.io.InputStreamReader;

public class CF1138D {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		char[] s = br.readLine().toCharArray();
		char[] t = br.readLine().toCharArray();
		int[] ctr = new int[2];
		for(int i=0; i<s.length; i++) ctr[s[i]-'0']++;
		int i = 0;
		StringBuilder sb = new StringBuilder();
		while(true){
			if(ctr[t[i]-'0']<1) break;
			sb.append(t[i]);
			ctr[t[i]-'0']--;
			i = (i+1)%t.length;
		}
		while(ctr[0]>0){
			ctr[0]--;
			sb.append(0);
		}
		while(ctr[1]>0){
			ctr[1]--;
			sb.append(1);
		}
		System.out.println(sb);
	}
}


import java.io.BufferedReader;
import java.io.InputStreamReader;

public class CF1138D {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		char[] s = br.readLine().toCharArray();
		char[] t = br.readLine().toCharArray();
		int[] ctr = new int[2];
		for(int i=0; i<s.length; i++) ctr[s[i]-'0']++;
		int[] prefixHashes = new int[t.length];
		int[] suffixHashes = new int[t.length];
		int x = 256, mod = 1000000007;
		prefixHashes[0] = t[0];
		suffixHashes[t.length-1] = t[t.length-1];
		int maxps = 0;
		if(t.length>1 && prefixHashes[0]==suffixHashes[t.length-1] && match(t, 1)) maxps = 1;
		for(int i=1; i<t.length-1; i++){
			prefixHashes[i] = (x*prefixHashes[i-1]+t[i])%mod;
			suffixHashes[t.length-i-1] = (x*suffixHashes[t.length-i]+t[t.length-i-1])%mod;
			if(prefixHashes[i]==suffixHashes[t.length-i-1] && match(t, i+1)) maxps = i+1;
		}
		int i = 0;
		StringBuilder sb = new StringBuilder();
		while(true){
			if(ctr[t[i]-'0']<1) break;
			sb.append(t[i]);
			ctr[t[i]-'0']--;
			i++;
			if(i==t.length) i = maxps;
		}
		while(ctr[0]>0){
			ctr[0]--;
			sb.append(0);
		}
		while(ctr[1]>0){
			ctr[1]--;
			sb.append(1);
		}
		System.out.println(sb);
	}

	static boolean match(char[] s, int len){
		for(int i=0; i<len; i++) if(s[i]!=s[s.length-len+i]) return false;
		return true;
	}
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class CF1138D {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		char[] s = br.readLine().toCharArray();
		char[] t = br.readLine().toCharArray();
		if(t.length==1) System.out.println(s);
		else {
			int[] ctr = new int[2];
			for(int i=0; i<s.length; i++) ctr[s[i]-'0']++;
			long[] prefixHashes = new long[t.length];
			long[] suffixHashes = new long[t.length];
			int x = 256, mod = 1000000007;
			prefixHashes[0] = t[0];
			int maxps = 0;
			for(int i=1; i<t.length-1; i++){
				prefixHashes[i] = (x*prefixHashes[i-1]+t[i])%mod;
			}
			long[] xPows = new long[t.length];
			xPows[0] = 1;
			for(int i=1; i<t.length; i++) {
				xPows[i] = (xPows[i-1]*x)%mod;
			}
//			System.out.println(Arrays.toString(xPows));
//			System.out.println(prefixHashes[t.length-2]);
//			System.out.println(t[0]*xPows[t.length-2]);
			suffixHashes[1] = (x*(prefixHashes[t.length-2]-t[0]*xPows[t.length-2])+t[t.length-1])%mod;
			if(suffixHashes[1]<0) suffixHashes[1]+=mod;
			for(int i=2; i<t.length; i++){
				suffixHashes[i] = (suffixHashes[i-1]-t[i-1]*xPows[t.length-i]);
				if(suffixHashes[i]<0) suffixHashes[i]+=mod*Math.ceil(-1.0*suffixHashes[i]/mod);
			}
//			System.out.println(Arrays.toString(prefixHashes));
//			System.out.println(Arrays.toString(suffixHashes));
			for(int i=0; i<t.length-1; i++) {
//				System.out.println(prefixHashes[i]+" "+suffixHashes[t.length-1-i]);
				if(prefixHashes[i]==suffixHashes[t.length-1-i] && match(t, i+1)) maxps = i+1;
			}
//			System.out.println(maxps);
			int i = 0;
			StringBuilder sb = new StringBuilder();
			while(true){
				if(ctr[t[i]-'0']<1) break;
				sb.append(t[i]);
				ctr[t[i]-'0']--;
				i++;
				if(i==t.length) i = maxps;
			}
			while(ctr[0]>0){
				ctr[0]--;
				sb.append(0);
			}
			while(ctr[1]>0){
				ctr[1]--;
				sb.append(1);
			}
			System.out.println(sb);
		}
	}

	static boolean match(char[] s, int len){
		for(int i=0; i<len; i++) if(s[i]!=s[s.length-len+i]) return false;
		return true;
	}
}


import java.io.IOException;
import java.util.NoSuchElementException;
public class Main{

	public static void main(String[] args){
		FastScanner sc = new FastScanner();

		String S = sc.next();
		String T = sc.next();
		int o = overlap(T,T);
		int a = 0;
		int b = 0;
		int c = 0;
		int d = 0;
		for(int i=0;i<T.length();i++){
			if(i<o){
				if(T.charAt(i)=='0'){
					a++;
				}else{
					b++;
				}
			}else{
				if(T.charAt(i)=='0'){
					c++;
				}else{
					d++;
				}
			}
		}
		int p = 0;
		int q = 0;
		for(int i=0;i<S.length();i++){
			if(S.charAt(i)=='0'){
				p++;
			}else{
				q++;
			}
		}
		//System.out.println(o);
		if(a+c>p||b+d>q){
			for(int i=0;i<p;i++){
				System.out.print(0);
			}
			for(int i=0;i<q;i++){
				System.out.print(1);
			}
		}else{
			System.out.print(T);
			p -= a+c;
			q -= b+d;
			//System.out.println(p+" "+q);
			//System.out.println(c+" "+d);
			int f = c==0?1000000:p/c;
			int g = d==0?1000000:q/d;
			int min = Math.min(f,g);
			for(int i=0;i<min;i++){
				System.out.print(T.substring(o));
			}
			p -= c * min;
			q -= d * min;
			for(int i=0;i<p;i++){
				System.out.print(0);
			}
			for(int i=0;i<q;i++){
				System.out.print(1);
			}
		}
	}

	private static int overlap(String a, String b) {
		int l = a.length();
		long ah1 = 0;
		long ah2 = 0;
		long bh1 = 0;
		long bh2 = 0;
		long t1 = 1;
		long t2 = 1;
		int A = 1000000007;
		int B = 1000000009;
		int ans = 0;
		for(int i=1;i<l;i++){
			ah1 = ah1 + a.charAt(l-i) * t1;
			ah2 = ah2 + a.charAt(l-i) * t2;
			bh1 = bh1 * A + b.charAt(i-1);
			bh2 = bh2 * B + b.charAt(i-1);
			if(ah1==bh1&&ah2==bh2){
				ans = i;
			}
			t1 *= A;
			t2 *= B;
		}
		return ans;

	}

}

class FastScanner {
    private final java.io.InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return (minus ? -n : n);
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return (int) (minus ? -n : n);
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
}


import java.io.IOException;
import java.util.NoSuchElementException;
public class Main{

	public static void main(String[] args){
		FastScanner sc = new FastScanner();

		String S = sc.next();
		String T = sc.next();
		int o = overlap(T,T);
		int a = 0;
		int b = 0;
		int c = 0;
		int d = 0;
		for(int i=0;i<T.length();i++){
			if(i<o){
				if(T.charAt(i)=='0'){
					a++;
				}else{
					b++;
				}
			}else{
				if(T.charAt(i)=='0'){
					c++;
				}else{
					d++;
				}
			}
		}
		int p = 0;
		int q = 0;
		for(int i=0;i<S.length();i++){
			if(S.charAt(i)=='0'){
				p++;
			}else{
				q++;
			}
		}
		System.out.println(o);
		if(a+c>p||b+d>q){
			for(int i=0;i<p;i++){
				System.out.print(0);
			}
			for(int i=0;i<q;i++){
				System.out.print(1);
			}
		}else{
			System.out.print(T);
			p -= a+c;
			q -= b+d;
			//System.out.println(p+" "+q);
			//System.out.println(c+" "+d);
			int min = Math.min(p/c,q/d);
			for(int i=0;i<min;i++){
				System.out.print(T.substring(o));
			}
			p -= c * min;
			q -= d * min;
			for(int i=0;i<p;i++){
				System.out.print(0);
			}
			for(int i=0;i<q;i++){
				System.out.print(1);
			}
		}
	}

	private static int overlap(String a, String b) {
		int l = a.length();
		long ah1 = 0;
		long ah2 = 0;
		long bh1 = 0;
		long bh2 = 0;
		long t1 = 1;
		long t2 = 1;
		int A = 1000000007;
		int B = 1000000009;
		int ans = 0;
		for(int i=1;i<l;i++){
			ah1 = ah1 + a.charAt(l-i) * t1;
			ah2 = ah2 + a.charAt(l-i) * t2;
			bh1 = bh1 * A + b.charAt(i-1);
			bh2 = bh2 * B + b.charAt(i-1);
			if(ah1==bh1&&ah2==bh2){
				ans = i;
			}
			t1 *= A;
			t2 *= B;
		}
		return ans;

	}

}

class FastScanner {
    private final java.io.InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return (minus ? -n : n);
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return (int) (minus ? -n : n);
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
}


import java.io.IOException;
import java.util.NoSuchElementException;
public class Main{

	public static void main(String[] args){
		FastScanner sc = new FastScanner();

		String S = sc.next();
		String T = sc.next();
		int o = overlap(T,T);
		int a = 0;
		int b = 0;
		int c = 0;
		int d = 0;
		for(int i=0;i<T.length();i++){
			if(i<o){
				if(T.charAt(i)=='0'){
					a++;
				}else{
					b++;
				}
			}else{
				if(T.charAt(i)=='0'){
					c++;
				}else{
					d++;
				}
			}
		}
		int p = 0;
		int q = 0;
		for(int i=0;i<S.length();i++){
			if(S.charAt(i)=='0'){
				p++;
			}else{
				q++;
			}
		}
		//System.out.println(o);
		if(a+c>p||b+d>q){
			for(int i=0;i<p;i++){
				System.out.print(0);
			}
			for(int i=0;i<q;i++){
				System.out.print(1);
			}
		}else{
			System.out.print(T);
			p -= a+c;
			q -= b+d;
			//System.out.println(p+" "+q);
			//System.out.println(c+" "+d);
			int min = Math.min(p/c,q/d);
			for(int i=0;i<min;i++){
				System.out.print(T.substring(o));
			}
			p -= c * min;
			q -= d * min;
			for(int i=0;i<p;i++){
				System.out.print(0);
			}
			for(int i=0;i<q;i++){
				System.out.print(1);
			}
		}
	}

	private static int overlap(String a, String b) {
		int l = a.length();
		long ah1 = 0;
		long ah2 = 0;
		long bh1 = 0;
		long bh2 = 0;
		long t1 = 1;
		long t2 = 1;
		int A = 1000000007;
		int B = 1000000009;
		int ans = 0;
		for(int i=1;i<l;i++){
			ah1 = ah1 + a.charAt(l-i) * t1;
			ah2 = ah2 + a.charAt(l-i) * t2;
			bh1 = bh1 * A + b.charAt(i-1);
			bh2 = bh2 * B + b.charAt(i-1);
			if(ah1==bh1&&ah2==bh2){
				ans = i;
			}
			t1 *= A;
			t2 *= B;
		}
		return ans;

	}

}

class FastScanner {
    private final java.io.InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return (minus ? -n : n);
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return (int) (minus ? -n : n);
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
}


import java.io.IOException;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
public class Main{

	public static void main(String[] args){
		FastScanner sc = new FastScanner();

		String S = sc.next();
		String T = sc.next();
		PrintWriter out = new PrintWriter(System.out);
		int o = overlap(T,T);
		int a = 0;
		int b = 0;
		int c = 0;
		int d = 0;
		for(int i=0;i<T.length();i++){
			if(i<o){
				if(T.charAt(i)=='0'){
					a++;
				}else{
					b++;
				}
			}else{
				if(T.charAt(i)=='0'){
					c++;
				}else{
					d++;
				}
			}
		}
		int p = 0;
		int q = 0;
		for(int i=0;i<S.length();i++){
			if(S.charAt(i)=='0'){
				p++;
			}else{
				q++;
			}
		}
		//System.out.println(o);
		if(a+c>p||b+d>q){
			for(int i=0;i<p;i++){
				out.print(0);
			}
			for(int i=0;i<q;i++){
				out.print(1);
			}
		}else{
			out.print(T);
			p -= a+c;
			q -= b+d;
			//System.out.println(p+" "+q);
			//System.out.println(c+" "+d);
			int f = c==0?1000000:p/c;
			int g = d==0?1000000:q/d;
			int min = Math.min(f,g);
			for(int i=0;i<min;i++){
				out.print(T.substring(o));
			}
			p -= c * min;
			q -= d * min;
			for(int i=0;i<p;i++){
				out.print(0);
			}
			for(int i=0;i<q;i++){
				out.print(1);
			}
		}
		out.flush();
	}

	private static int overlap(String a, String b) {
		int l = a.length();
		long ah1 = 0;
		long ah2 = 0;
		long bh1 = 0;
		long bh2 = 0;
		long t1 = 1;
		long t2 = 1;
		int A = 1000000007;
		int B = 1000000009;
		int ans = 0;
		for(int i=1;i<l;i++){
			ah1 = ah1 + a.charAt(l-i) * t1;
			ah2 = ah2 + a.charAt(l-i) * t2;
			bh1 = bh1 * A + b.charAt(i-1);
			bh2 = bh2 * B + b.charAt(i-1);
			if(ah1==bh1&&ah2==bh2){
				ans = i;
			}
			t1 *= A;
			t2 *= B;
		}
		return ans;

	}

}

class FastScanner {
    private final java.io.InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return (minus ? -n : n);
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return (int) (minus ? -n : n);
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
}