Problem:
Score : 100 points

Problem Statement

You are given two strings s and t consisting of lowercase English letters and an integer L.

We will consider generating a string of length L by concatenating one or more copies of s and t. Here, it is allowed to use the same string more than once.

For example, when s = at, t = code and L = 6, the strings atatat, atcode and codeat can be generated.

Among the strings that can be generated in this way, find the lexicographically smallest one. In the cases given as input, it is always possible to generate a string of length L.

Constraints

1 ≤ L ≤ 2 × 10^5

1 ≤ |s|, |t| ≤ L

s and t consist of lowercase English letters.

It is possible to generate a string of length L in the way described in Problem Statement.

Input

Input is given from Standard Input in the following format:

N
x_1 s_1
x_2 s_2
:
x_N s_N

Output

Print the lexicographically smallest string among the ones that can be generated in the way described in Problem Statement.

Sample Input 1

6
at
code

Sample Output 1

atatat

This input corresponds to the example shown in Problem Statement.

Sample Input 2

8
coding
festival

Sample Output 2

festival

It is possible that either s or t cannot be used at all in generating a string of length L.

Sample Input 3

8
same
same

Sample Output 3

samesame

It is also possible that s = t.

Sample Input 4

10
coin
age

Sample Output 4

ageagecoin

Solution in C++14 (GCC 5.4.1) (judge verdict: Runtime Error)

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#include<bitset>
#include<iomanip>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
string ss[400001],tt[400001];
int main(){
	int L;
	string s,t;
	vpint kuminum;
	scan(L);scan(s);scan(t);
	ss[0]="",tt[0]="";
	int sl=s.size(),tl=t.size();
	string ans="";
	rep(i,L){
		ans+='~';
	}
	for(int i=0;i*sl<=L;i++){
		if((L-i*sl)%tl==0){
			kuminum.push_back(mp(i,(L-i*sl)/tl));
		}
	}
	for(int i=1;i*sl<=L;i++){
		ss[i]=ss[i-1]+s;
	}
	for(int i=1;i*tl<=L;i++){
		tt[i]=tt[i-1]+t;
	}
	rep(i,kuminum.size()){
		int snum=kuminum[i].first,tnum=kuminum[i].second;
		string kouho;
		if(ss[snum].substr(0,min(ss[snum].size(),tt[tnum].size()))<tt[tnum].substr(0,min(ss[snum].size(),tt[tnum].size()))){
			kouho=ss[snum]+tt[tnum];
		}
		else{
			kouho=tt[tnum]+ss[snum];
		}
		ans=min(ans,kouho);
	}
	prin(ans);
	return 0;
}