/*
    AUTHOR:         BHUVNESH JAIN
    INSTITUITION:   BITS PILANI, PILANI
*/
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <iterator>
#include <cmath>
#include <cassert>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <climits>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<int,pii> piii;

#define fastio          std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define PAUSE_EXE       assert(false)
#define inchar          getchar
#define outchar(x)      putchar(x)
#define MAX             200005
#define MOD             1000000007LL
#define REP(i,n)        for(__typeof(n) i=0; i<n; ++i)
#define CREP(i,n)       for(__typeof(n) i=n-1; i>=0; --i)
#define MYREP(i,a,b)    for(__typeof(a) i=a; i<=b; ++i)
#define MYCREP(i,a,b)   for(__typeof(a) i=b; i>=a; --i)
#define SET(a, b)       memset(a, b, sizeof(a))
#define count_one(a)    __builtin_popcountll(a)
#define power_2(a)      (a)&(a-1)==0
#define sz(a)           int((a).size())
#define pb              push_back
#define mp              make_pair
#define fi              first
#define sec             second
#define all(c)          (c).begin(),(c).end()
#define allr(c)         (c).rbegin(),(c).rend()
#define loop(c,i)       for(typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define loopr(c,i)      for(typeof(c.end()) i = c.end(); i != c.begin(); )
#define UNIQUE(a)       sort(all(a)), (a).erase(unique(all(a)),(a).end())
#define present(c,x)    ((c).find(x) != (c).end())
#define cpresent(c,x)   (find(all(c),x) != (c).end())

const double EPS = 1e-10;
const double PI = acos(-1.0);

template <typename T> void inPos(T &x)
{x=0;register T c=inchar();while(((c<48)||(c>57))&&(c!='-'))c=inchar();bool neg=false;if(c=='-')neg=true;for(;c<48||c>57;c=inchar());for(;c>47&&c<58;c=inchar())x=(x<<3)+(x<<1)+(c&15);if(neg)x=-x;}

template <typename T> void outPos (T n)
{char snum[65];int i=0;do {snum[i++]=n%10+'0';n/=10;}while(n);i=i-1;while(i>=0)outchar(snum[i--]);outchar('\n');}

// === tick a time ===
#include <ctime>
double tick() {static clock_t oldtick;clock_t newtick=clock();double diff = 1.0*(newtick-oldtick)/CLOCKS_PER_SEC;oldtick = newtick;return diff;}

template <typename T> T mod(T a, T b) {return (a < b ? a : a % b);}
LL mulmod(LL a,LL b, LL m){LL q=(LL)(((LD)a*(LD)b)/(LD)m);LL r=a*b-q*m;if(r>m)r%=m;if(r<0)r+=m;return r;}
template <typename T, typename S>T expo(T e, S n){T x=1,p=e;while(n){if(n&1)x=x*p;p=p*p;n>>=1;}return x;}
template <typename T>T power(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mod(x*p,m);p=mod(p*p,m);n>>=1;}return x;}
template <typename T>T powerL(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mulmod(x,p,m);p=mulmod(p,p,m);n>>=1;}return x;}
template <typename T> T InverseEuler(T a, T m){return (a==1? 1 : power(a, m-2, m));}
template <typename T> T gcd(T a, T b){return __gcd(a,b);}
template <typename T> T lcm(T a, T b){return (a*(b/gcd(a,b)));}

int cmp(string a, string b)
{
    if (a.length()==b.length())
    {
        if (a<b)
            return -1;
        else if (a>b)
            return 1;
        else if (a==b)
            return 0;
    }
    else if (a.length() < b.length())
    {
        string sub = b.substr(0, a.length());
        if (sub==a)
            return 1;
        else if (sub < a)
            return 1;
        else
            return -1;
    }
    else
    {
        string sub = a.substr(0, b.length());
        if (sub==b)
            return -1;
        else if (sub < b)
            return -1;
        else
            return 1;
    }
}

vector < string > temp;

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("inp.txt", "r", stdin);
    #endif
    fastio;
    int n;
    cin>>n;
    REP(i, n)
    {
    	string x;
    	cin>>x;
    	temp.pb(x);
    }
    REP(i, n)
    {
        REP(j, n)
        {
            if (j<=i)
                continue;
            else if (cmp(temp[i], temp[j]) == 1)
                swap(temp[i], temp[j]);
        }
    }
    REP(i, n)
    {
    	cout<<temp[i];
    }
    // cerr<<tick();
    return 0;
}


/*
    AUTHOR:         BHUVNESH JAIN
    INSTITUITION:   BITS PILANI, PILANI
*/
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <iterator>
#include <cmath>
#include <cassert>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <climits>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<int,pii> piii;

#define fastio          std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define PAUSE_EXE       assert(false)
#define inchar          getchar
#define outchar(x)      putchar(x)
#define MAX             200005
#define MOD             1000000007LL
#define REP(i,n)        for(__typeof(n) i=0; i<n; ++i)
#define CREP(i,n)       for(__typeof(n) i=n-1; i>=0; --i)
#define MYREP(i,a,b)    for(__typeof(a) i=a; i<=b; ++i)
#define MYCREP(i,a,b)   for(__typeof(a) i=b; i>=a; --i)
#define SET(a, b)       memset(a, b, sizeof(a))
#define count_one(a)    __builtin_popcountll(a)
#define power_2(a)      (a)&(a-1)==0
#define sz(a)           int((a).size())
#define pb              push_back
#define mp              make_pair
#define fi              first
#define sec             second
#define all(c)          (c).begin(),(c).end()
#define allr(c)         (c).rbegin(),(c).rend()
#define loop(c,i)       for(typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define loopr(c,i)      for(typeof(c.end()) i = c.end(); i != c.begin(); )
#define UNIQUE(a)       sort(all(a)), (a).erase(unique(all(a)),(a).end())
#define present(c,x)    ((c).find(x) != (c).end())
#define cpresent(c,x)   (find(all(c),x) != (c).end())

const double EPS = 1e-10;
const double PI = acos(-1.0);

template <typename T> void inPos(T &x)
{x=0;register T c=inchar();while(((c<48)||(c>57))&&(c!='-'))c=inchar();bool neg=false;if(c=='-')neg=true;for(;c<48||c>57;c=inchar());for(;c>47&&c<58;c=inchar())x=(x<<3)+(x<<1)+(c&15);if(neg)x=-x;}

template <typename T> void outPos (T n)
{char snum[65];int i=0;do {snum[i++]=n%10+'0';n/=10;}while(n);i=i-1;while(i>=0)outchar(snum[i--]);outchar('\n');}

// === tick a time ===
#include <ctime>
double tick() {static clock_t oldtick;clock_t newtick=clock();double diff = 1.0*(newtick-oldtick)/CLOCKS_PER_SEC;oldtick = newtick;return diff;}

template <typename T> T mod(T a, T b) {return (a < b ? a : a % b);}
LL mulmod(LL a,LL b, LL m){LL q=(LL)(((LD)a*(LD)b)/(LD)m);LL r=a*b-q*m;if(r>m)r%=m;if(r<0)r+=m;return r;}
template <typename T, typename S>T expo(T e, S n){T x=1,p=e;while(n){if(n&1)x=x*p;p=p*p;n>>=1;}return x;}
template <typename T>T power(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mod(x*p,m);p=mod(p*p,m);n>>=1;}return x;}
template <typename T>T powerL(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mulmod(x,p,m);p=mulmod(p,p,m);n>>=1;}return x;}
template <typename T> T InverseEuler(T a, T m){return (a==1? 1 : power(a, m-2, m));}
template <typename T> T gcd(T a, T b){return __gcd(a,b);}
template <typename T> T lcm(T a, T b){return (a*(b/gcd(a,b)));}

int cmp(string a, string b)
{
    if (a.length()==b.length())
    {
        if (a<b)
            return -1;
        else if (a>b)
            return 1;
        else if (a==b)
            return 0;
    }
    else if (a.length() < b.length())
    {
        string sub = b.substr(0, a.length());
        if (sub==a)
        {
            int m = 0;
            for(int i=a.length(); i<b.length(); ++i)
            {
                if (b[i]==a[m])
                {
                    m++;
                    if (m==a.length())
                        m = 0;
                }
                else
                {
                    if (b[i]<a[m])
                        return 1;
                    else
                        return -1;
                }
            }
        }
        else if (sub < a)
            return 1;
        else
            return -1;
    }
    else
    {
        string sub = a.substr(0, b.length());
        if (sub==b)
        {
            int m = 0;
            for(int i=b.length(); i<a.length(); ++i)
            {
                if (a[i]==b[m])
                {
                    m++;
                    if (m==b.length())
                        m = 0;
                }
                else
                {
                    if (a[i]<b[m])
                        return -1;
                    else
                        return 1;
                }
            }
        }
        else if (sub < b)
            return -1;
        else
            return 1;
    }
}

vector < string > temp;

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("inp.txt", "r", stdin);
    #endif
    fastio;
    int n;
    cin>>n;
    REP(i, n)
    {
    	string x;
    	cin>>x;
    	temp.pb(x);
    }
    REP(i, n)
    {
        REP(j, n)
        {
            if (j<=i)
                continue;
            else if (cmp(temp[i], temp[j]) == 1)
                swap(temp[i], temp[j]);
        }
    }
    REP(i, n)
    {
    	cout<<temp[i];
    }
    // cerr<<tick();
    return 0;
}


/*
    AUTHOR:         BHUVNESH JAIN
    INSTITUITION:   BITS PILANI, PILANI
*/
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <iterator>
#include <cmath>
#include <cassert>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <climits>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<int,pii> piii;

#define fastio          std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define PAUSE_EXE       assert(false)
#define inchar          getchar
#define outchar(x)      putchar(x)
#define MAX             200005
#define MOD             1000000007LL
#define REP(i,n)        for(__typeof(n) i=0; i<n; ++i)
#define CREP(i,n)       for(__typeof(n) i=n-1; i>=0; --i)
#define MYREP(i,a,b)    for(__typeof(a) i=a; i<=b; ++i)
#define MYCREP(i,a,b)   for(__typeof(a) i=b; i>=a; --i)
#define SET(a, b)       memset(a, b, sizeof(a))
#define count_one(a)    __builtin_popcountll(a)
#define power_2(a)      (a)&(a-1)==0
#define sz(a)           int((a).size())
#define pb              push_back
#define mp              make_pair
#define fi              first
#define sec             second
#define all(c)          (c).begin(),(c).end()
#define allr(c)         (c).rbegin(),(c).rend()
#define loop(c,i)       for(typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define loopr(c,i)      for(typeof(c.end()) i = c.end(); i != c.begin(); )
#define UNIQUE(a)       sort(all(a)), (a).erase(unique(all(a)),(a).end())
#define present(c,x)    ((c).find(x) != (c).end())
#define cpresent(c,x)   (find(all(c),x) != (c).end())

const double EPS = 1e-10;
const double PI = acos(-1.0);

template <typename T> void inPos(T &x)
{x=0;register T c=inchar();while(((c<48)||(c>57))&&(c!='-'))c=inchar();bool neg=false;if(c=='-')neg=true;for(;c<48||c>57;c=inchar());for(;c>47&&c<58;c=inchar())x=(x<<3)+(x<<1)+(c&15);if(neg)x=-x;}

template <typename T> void outPos (T n)
{char snum[65];int i=0;do {snum[i++]=n%10+'0';n/=10;}while(n);i=i-1;while(i>=0)outchar(snum[i--]);outchar('\n');}

// === tick a time ===
#include <ctime>
double tick() {static clock_t oldtick;clock_t newtick=clock();double diff = 1.0*(newtick-oldtick)/CLOCKS_PER_SEC;oldtick = newtick;return diff;}

template <typename T> T mod(T a, T b) {return (a < b ? a : a % b);}
LL mulmod(LL a,LL b, LL m){LL q=(LL)(((LD)a*(LD)b)/(LD)m);LL r=a*b-q*m;if(r>m)r%=m;if(r<0)r+=m;return r;}
template <typename T, typename S>T expo(T e, S n){T x=1,p=e;while(n){if(n&1)x=x*p;p=p*p;n>>=1;}return x;}
template <typename T>T power(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mod(x*p,m);p=mod(p*p,m);n>>=1;}return x;}
template <typename T>T powerL(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mulmod(x,p,m);p=mulmod(p,p,m);n>>=1;}return x;}
template <typename T> T InverseEuler(T a, T m){return (a==1? 1 : power(a, m-2, m));}
template <typename T> T gcd(T a, T b){return __gcd(a,b);}
template <typename T> T lcm(T a, T b){return (a*(b/gcd(a,b)));}

bool cmp(string a, string b)
{
    if (a.length()==b.length())
        return (a < b);
    else
    {
        int i, j=min(a.length(), b.length());
        for(int k=0; k<j; ++k)
        {
            if (a[k]==b[k])
                continue;
            else
                return (a[k]<b[k]);
        }
        if (a.length() < b.length())
            return -1;
        else
            return 1;
    }
}
vector < string > temp;

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("inp.txt", "r", stdin);
    #endif
    int n;
    cin>>n;
    REP(i, n)
    {
    	string x;
    	cin>>x;
    	temp.pb(x);
    }
    sort(all(temp), cmp);
    REP(i, n)
    {
    	cout<<temp[i];
    }
    // cerr<<tick();
    return 0;
}


/*
    AUTHOR:         BHUVNESH JAIN
    INSTITUITION:   BITS PILANI, PILANI
*/
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <iterator>
#include <cmath>
#include <cassert>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <climits>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<int,pii> piii;

#define fastio          std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define PAUSE_EXE       assert(false)
#define inchar          getchar
#define outchar(x)      putchar(x)
#define MAX             200005
#define MOD             1000000007LL
#define REP(i,n)        for(__typeof(n) i=0; i<n; ++i)
#define CREP(i,n)       for(__typeof(n) i=n-1; i>=0; --i)
#define MYREP(i,a,b)    for(__typeof(a) i=a; i<=b; ++i)
#define MYCREP(i,a,b)   for(__typeof(a) i=b; i>=a; --i)
#define SET(a, b)       memset(a, b, sizeof(a))
#define count_one(a)    __builtin_popcountll(a)
#define power_2(a)      (a)&(a-1)==0
#define sz(a)           int((a).size())
#define pb              push_back
#define mp              make_pair
#define fi              first
#define sec             second
#define all(c)          (c).begin(),(c).end()
#define allr(c)         (c).rbegin(),(c).rend()
#define loop(c,i)       for(typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define loopr(c,i)      for(typeof(c.end()) i = c.end(); i != c.begin(); )
#define UNIQUE(a)       sort(all(a)), (a).erase(unique(all(a)),(a).end())
#define present(c,x)    ((c).find(x) != (c).end())
#define cpresent(c,x)   (find(all(c),x) != (c).end())

const double EPS = 1e-10;
const double PI = acos(-1.0);

template <typename T> void inPos(T &x)
{x=0;register T c=inchar();while(((c<48)||(c>57))&&(c!='-'))c=inchar();bool neg=false;if(c=='-')neg=true;for(;c<48||c>57;c=inchar());for(;c>47&&c<58;c=inchar())x=(x<<3)+(x<<1)+(c&15);if(neg)x=-x;}

template <typename T> void outPos (T n)
{char snum[65];int i=0;do {snum[i++]=n%10+'0';n/=10;}while(n);i=i-1;while(i>=0)outchar(snum[i--]);outchar('\n');}

// === tick a time ===
#include <ctime>
double tick() {static clock_t oldtick;clock_t newtick=clock();double diff = 1.0*(newtick-oldtick)/CLOCKS_PER_SEC;oldtick = newtick;return diff;}

template <typename T> T mod(T a, T b) {return (a < b ? a : a % b);}
LL mulmod(LL a,LL b, LL m){LL q=(LL)(((LD)a*(LD)b)/(LD)m);LL r=a*b-q*m;if(r>m)r%=m;if(r<0)r+=m;return r;}
template <typename T, typename S>T expo(T e, S n){T x=1,p=e;while(n){if(n&1)x=x*p;p=p*p;n>>=1;}return x;}
template <typename T>T power(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mod(x*p,m);p=mod(p*p,m);n>>=1;}return x;}
template <typename T>T powerL(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mulmod(x,p,m);p=mulmod(p,p,m);n>>=1;}return x;}
template <typename T> T InverseEuler(T a, T m){return (a==1? 1 : power(a, m-2, m));}
template <typename T> T gcd(T a, T b){return __gcd(a,b);}
template <typename T> T lcm(T a, T b){return (a*(b/gcd(a,b)));}

bool cmp(string a, string b)
{
    return a+b < b+a;
}

vector < string > temp;

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("inp.txt", "r", stdin);
    #endif
    fastio;
    int n;
    cin>>n;
    REP(i, n)
    {
    	string x;
    	cin>>x;
    	temp.pb(x);
    }
    sort(all(temp), cmp);
    REP(i, n)
    {
    	cout<<temp[i];
    }
    // cerr<<tick();
    return 0;
}


/*
    AUTHOR:         BHUVNESH JAIN
    INSTITUITION:   BITS PILANI, PILANI
*/
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <iterator>
#include <cmath>
#include <cassert>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <climits>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<int,pii> piii;

#define fastio          std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define PAUSE_EXE       assert(false)
#define inchar          getchar
#define outchar(x)      putchar(x)
#define MAX             200005
#define MOD             1000000007LL
#define REP(i,n)        for(__typeof(n) i=0; i<n; ++i)
#define CREP(i,n)       for(__typeof(n) i=n-1; i>=0; --i)
#define MYREP(i,a,b)    for(__typeof(a) i=a; i<=b; ++i)
#define MYCREP(i,a,b)   for(__typeof(a) i=b; i>=a; --i)
#define SET(a, b)       memset(a, b, sizeof(a))
#define count_one(a)    __builtin_popcountll(a)
#define power_2(a)      (a)&(a-1)==0
#define sz(a)           int((a).size())
#define pb              push_back
#define mp              make_pair
#define fi              first
#define sec             second
#define all(c)          (c).begin(),(c).end()
#define allr(c)         (c).rbegin(),(c).rend()
#define loop(c,i)       for(typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define loopr(c,i)      for(typeof(c.end()) i = c.end(); i != c.begin(); )
#define UNIQUE(a)       sort(all(a)), (a).erase(unique(all(a)),(a).end())
#define present(c,x)    ((c).find(x) != (c).end())
#define cpresent(c,x)   (find(all(c),x) != (c).end())

const double EPS = 1e-10;
const double PI = acos(-1.0);

template <typename T> void inPos(T &x)
{x=0;register T c=inchar();while(((c<48)||(c>57))&&(c!='-'))c=inchar();bool neg=false;if(c=='-')neg=true;for(;c<48||c>57;c=inchar());for(;c>47&&c<58;c=inchar())x=(x<<3)+(x<<1)+(c&15);if(neg)x=-x;}

template <typename T> void outPos (T n)
{char snum[65];int i=0;do {snum[i++]=n%10+'0';n/=10;}while(n);i=i-1;while(i>=0)outchar(snum[i--]);outchar('\n');}

// === tick a time ===
#include <ctime>
double tick() {static clock_t oldtick;clock_t newtick=clock();double diff = 1.0*(newtick-oldtick)/CLOCKS_PER_SEC;oldtick = newtick;return diff;}

template <typename T> T mod(T a, T b) {return (a < b ? a : a % b);}
LL mulmod(LL a,LL b, LL m){LL q=(LL)(((LD)a*(LD)b)/(LD)m);LL r=a*b-q*m;if(r>m)r%=m;if(r<0)r+=m;return r;}
template <typename T, typename S>T expo(T e, S n){T x=1,p=e;while(n){if(n&1)x=x*p;p=p*p;n>>=1;}return x;}
template <typename T>T power(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mod(x*p,m);p=mod(p*p,m);n>>=1;}return x;}
template <typename T>T powerL(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mulmod(x,p,m);p=mulmod(p,p,m);n>>=1;}return x;}
template <typename T> T InverseEuler(T a, T m){return (a==1? 1 : power(a, m-2, m));}
template <typename T> T gcd(T a, T b){return __gcd(a,b);}
template <typename T> T lcm(T a, T b){return (a*(b/gcd(a,b)));}

int cmp(string a, string b)
{
    if (a.length()==b.length())
    {
        if (a<b)
            return -1;
        else if (a>b)
            return 1;
        else if (a==b)
            return 0;
    }
    else if (a.length() < b.length())
    {
        int m = 0;
        for(int i=0; i<b.length(); ++i)
        {
            if (b[i]==a[m])
            {
                m++;
                if (m==a.length())
                    m = 0;
            }
            else
            {
                if (b[i]<a[m])
                    return 1;
                else
                    return -1;
            }
        }
    }
    else
    {
        int m = 0;
        for(int i=0; i<a.length(); ++i)
        {
            if (a[i]==b[m])
            {
                m++;
                if (m==b.length())
                    m = 0;
            }
            else
            {
                if (a[i]<b[m])
                    return -1;
                else
                    return 1;
            }
        }
    }
}

vector < string > temp;

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("inp.txt", "r", stdin);
    #endif
    fastio;
    int n;
    cin>>n;
    REP(i, n)
    {
    	string x;
    	cin>>x;
    	temp.pb(x);
    }
    REP(i, n)
    {
        REP(j, n)
        {
            if (j<=i)
                continue;
            else if (cmp(temp[i], temp[j]) == 1)
                swap(temp[i], temp[j]);
        }
    }
    REP(i, n)
    {
    	cout<<temp[i];
    }
    // cerr<<tick();
    return 0;
}


/*
    AUTHOR:         BHUVNESH JAIN
    INSTITUITION:   BITS PILANI, PILANI
*/
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <iterator>
#include <cmath>
#include <cassert>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <climits>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<int,pii> piii;

#define fastio          std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define PAUSE_EXE       assert(false)
#define inchar          getchar
#define outchar(x)      putchar(x)
#define MAX             200005
#define MOD             1000000007LL
#define REP(i,n)        for(__typeof(n) i=0; i<n; ++i)
#define CREP(i,n)       for(__typeof(n) i=n-1; i>=0; --i)
#define MYREP(i,a,b)    for(__typeof(a) i=a; i<=b; ++i)
#define MYCREP(i,a,b)   for(__typeof(a) i=b; i>=a; --i)
#define SET(a, b)       memset(a, b, sizeof(a))
#define count_one(a)    __builtin_popcountll(a)
#define power_2(a)      (a)&(a-1)==0
#define sz(a)           int((a).size())
#define pb              push_back
#define mp              make_pair
#define fi              first
#define sec             second
#define all(c)          (c).begin(),(c).end()
#define allr(c)         (c).rbegin(),(c).rend()
#define loop(c,i)       for(typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define loopr(c,i)      for(typeof(c.end()) i = c.end(); i != c.begin(); )
#define UNIQUE(a)       sort(all(a)), (a).erase(unique(all(a)),(a).end())
#define present(c,x)    ((c).find(x) != (c).end())
#define cpresent(c,x)   (find(all(c),x) != (c).end())

const double EPS = 1e-10;
const double PI = acos(-1.0);

template <typename T> void inPos(T &x)
{x=0;register T c=inchar();while(((c<48)||(c>57))&&(c!='-'))c=inchar();bool neg=false;if(c=='-')neg=true;for(;c<48||c>57;c=inchar());for(;c>47&&c<58;c=inchar())x=(x<<3)+(x<<1)+(c&15);if(neg)x=-x;}

template <typename T> void outPos (T n)
{char snum[65];int i=0;do {snum[i++]=n%10+'0';n/=10;}while(n);i=i-1;while(i>=0)outchar(snum[i--]);outchar('\n');}

// === tick a time ===
#include <ctime>
double tick() {static clock_t oldtick;clock_t newtick=clock();double diff = 1.0*(newtick-oldtick)/CLOCKS_PER_SEC;oldtick = newtick;return diff;}

template <typename T> T mod(T a, T b) {return (a < b ? a : a % b);}
LL mulmod(LL a,LL b, LL m){LL q=(LL)(((LD)a*(LD)b)/(LD)m);LL r=a*b-q*m;if(r>m)r%=m;if(r<0)r+=m;return r;}
template <typename T, typename S>T expo(T e, S n){T x=1,p=e;while(n){if(n&1)x=x*p;p=p*p;n>>=1;}return x;}
template <typename T>T power(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mod(x*p,m);p=mod(p*p,m);n>>=1;}return x;}
template <typename T>T powerL(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mulmod(x,p,m);p=mulmod(p,p,m);n>>=1;}return x;}
template <typename T> T InverseEuler(T a, T m){return (a==1? 1 : power(a, m-2, m));}
template <typename T> T gcd(T a, T b){return __gcd(a,b);}
template <typename T> T lcm(T a, T b){return (a*(b/gcd(a,b)));}

int cmp(string a, string b)
{
    if (a.length()==b.length())
    {
        if (a<b)
            return -1;
        else if (a>b)
            return 1;
        else if (a==b)
            return 0;
    }
    else if (a.length() < b.length())
    {
        int m = 0;
        for(int i=0; i<b.length(); ++i)
        {
            if (b[i]==a[m])
            {
                m++;
                if (m==a.length())
                    m = 0;
            }
            else
            {
                if (b[i]<a[m])
                    return 1;
                else
                    return -1;
            }
        }
        return 1;
    }
    else
    {
        int m = 0;
        for(int i=0; i<a.length(); ++i)
        {
            if (a[i]==b[m])
            {
                m++;
                if (m==b.length())
                    m = 0;
            }
            else
            {
                if (a[i]<b[m])
                    return -1;
                else
                    return 1;
            }
        }
        return -1;
    }
}

vector < string > temp;

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("inp.txt", "r", stdin);
    #endif
    fastio;
    int n;
    cin>>n;
    REP(i, n)
    {
    	string x;
    	cin>>x;
    	temp.pb(x);
    }
    REP(i, n)
    {
        REP(j, n)
        {
            if (j<=i)
                continue;
            else if (cmp(temp[i], temp[j]) == 1)
                swap(temp[i], temp[j]);
        }
    }
    REP(i, n)
    {
    	cout<<temp[i];
    }
    // cerr<<tick();
    return 0;
}


/*
    AUTHOR:         BHUVNESH JAIN
    INSTITUITION:   BITS PILANI, PILANI
*/
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <iterator>
#include <cmath>
#include <cassert>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <climits>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<int,pii> piii;

#define fastio          std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define PAUSE_EXE       assert(false)
#define inchar          getchar
#define outchar(x)      putchar(x)
#define MAX             200005
#define MOD             1000000007LL
#define REP(i,n)        for(__typeof(n) i=0; i<n; ++i)
#define CREP(i,n)       for(__typeof(n) i=n-1; i>=0; --i)
#define MYREP(i,a,b)    for(__typeof(a) i=a; i<=b; ++i)
#define MYCREP(i,a,b)   for(__typeof(a) i=b; i>=a; --i)
#define SET(a, b)       memset(a, b, sizeof(a))
#define count_one(a)    __builtin_popcountll(a)
#define power_2(a)      (a)&(a-1)==0
#define sz(a)           int((a).size())
#define pb              push_back
#define mp              make_pair
#define fi              first
#define sec             second
#define all(c)          (c).begin(),(c).end()
#define allr(c)         (c).rbegin(),(c).rend()
#define loop(c,i)       for(typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define loopr(c,i)      for(typeof(c.end()) i = c.end(); i != c.begin(); )
#define UNIQUE(a)       sort(all(a)), (a).erase(unique(all(a)),(a).end())
#define present(c,x)    ((c).find(x) != (c).end())
#define cpresent(c,x)   (find(all(c),x) != (c).end())

const double EPS = 1e-10;
const double PI = acos(-1.0);

template <typename T> void inPos(T &x)
{x=0;register T c=inchar();while(((c<48)||(c>57))&&(c!='-'))c=inchar();bool neg=false;if(c=='-')neg=true;for(;c<48||c>57;c=inchar());for(;c>47&&c<58;c=inchar())x=(x<<3)+(x<<1)+(c&15);if(neg)x=-x;}

template <typename T> void outPos (T n)
{char snum[65];int i=0;do {snum[i++]=n%10+'0';n/=10;}while(n);i=i-1;while(i>=0)outchar(snum[i--]);outchar('\n');}

// === tick a time ===
#include <ctime>
double tick() {static clock_t oldtick;clock_t newtick=clock();double diff = 1.0*(newtick-oldtick)/CLOCKS_PER_SEC;oldtick = newtick;return diff;}

template <typename T> T mod(T a, T b) {return (a < b ? a : a % b);}
LL mulmod(LL a,LL b, LL m){LL q=(LL)(((LD)a*(LD)b)/(LD)m);LL r=a*b-q*m;if(r>m)r%=m;if(r<0)r+=m;return r;}
template <typename T, typename S>T expo(T e, S n){T x=1,p=e;while(n){if(n&1)x=x*p;p=p*p;n>>=1;}return x;}
template <typename T>T power(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mod(x*p,m);p=mod(p*p,m);n>>=1;}return x;}
template <typename T>T powerL(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mulmod(x,p,m);p=mulmod(p,p,m);n>>=1;}return x;}
template <typename T> T InverseEuler(T a, T m){return (a==1? 1 : power(a, m-2, m));}
template <typename T> T gcd(T a, T b){return __gcd(a,b);}
template <typename T> T lcm(T a, T b){return (a*(b/gcd(a,b)));}

int cmp(string a, string b)
{
    if (a.length()==b.length())
    {
        if (a<b)
            return -1;
        else if (a>b)
            return 1;
        else if (a==b)
            return 0;
    }
    else if (a.length() < b.length())
    {
        int m = 0;
        for(int i=0; i<b.length(); ++i)
        {
            if (b[i]==a[m])
            {
                m++;
                if (m==a.length())
                    m = 0;
            }
            else
            {
                if (b[i]<a[m])
                    return 1;
                else
                    return -1;
            }
        }
        return -1;
    }
    else
    {
        int m = 0;
        for(int i=0; i<a.length(); ++i)
        {
            if (a[i]==b[m])
            {
                m++;
                if (m==b.length())
                    m = 0;
            }
            else
            {
                if (a[i]<b[m])
                    return -1;
                else
                    return 1;
            }
        }
        return 1;
    }
}

vector < string > temp;

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("inp.txt", "r", stdin);
    #endif
    fastio;
    int n;
    cin>>n;
    REP(i, n)
    {
    	string x;
    	cin>>x;
    	temp.pb(x);
    }
    REP(i, n)
    {
        REP(j, n)
        {
            if (j<=i)
                continue;
            else if (cmp(temp[i], temp[j]) == 1)
                swap(temp[i], temp[j]);
        }
    }
    REP(i, n)
    {
    	cout<<temp[i];
    }
    // cerr<<tick();
    return 0;
}


/*
    AUTHOR:         BHUVNESH JAIN
    INSTITUITION:   BITS PILANI, PILANI
*/
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <iterator>
#include <cmath>
#include <cassert>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <climits>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<int,pii> piii;

#define fastio          std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define PAUSE_EXE       assert(false)
#define inchar          getchar
#define outchar(x)      putchar(x)
#define MAX             200005
#define MOD             1000000007LL
#define REP(i,n)        for(__typeof(n) i=0; i<n; ++i)
#define CREP(i,n)       for(__typeof(n) i=n-1; i>=0; --i)
#define MYREP(i,a,b)    for(__typeof(a) i=a; i<=b; ++i)
#define MYCREP(i,a,b)   for(__typeof(a) i=b; i>=a; --i)
#define SET(a, b)       memset(a, b, sizeof(a))
#define count_one(a)    __builtin_popcountll(a)
#define power_2(a)      (a)&(a-1)==0
#define sz(a)           int((a).size())
#define pb              push_back
#define mp              make_pair
#define fi              first
#define sec             second
#define all(c)          (c).begin(),(c).end()
#define allr(c)         (c).rbegin(),(c).rend()
#define loop(c,i)       for(typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define loopr(c,i)      for(typeof(c.end()) i = c.end(); i != c.begin(); )
#define UNIQUE(a)       sort(all(a)), (a).erase(unique(all(a)),(a).end())
#define present(c,x)    ((c).find(x) != (c).end())
#define cpresent(c,x)   (find(all(c),x) != (c).end())

const double EPS = 1e-10;
const double PI = acos(-1.0);

template <typename T> void inPos(T &x)
{x=0;register T c=inchar();while(((c<48)||(c>57))&&(c!='-'))c=inchar();bool neg=false;if(c=='-')neg=true;for(;c<48||c>57;c=inchar());for(;c>47&&c<58;c=inchar())x=(x<<3)+(x<<1)+(c&15);if(neg)x=-x;}

template <typename T> void outPos (T n)
{char snum[65];int i=0;do {snum[i++]=n%10+'0';n/=10;}while(n);i=i-1;while(i>=0)outchar(snum[i--]);outchar('\n');}

// === tick a time ===
#include <ctime>
double tick() {static clock_t oldtick;clock_t newtick=clock();double diff = 1.0*(newtick-oldtick)/CLOCKS_PER_SEC;oldtick = newtick;return diff;}

template <typename T> T mod(T a, T b) {return (a < b ? a : a % b);}
LL mulmod(LL a,LL b, LL m){LL q=(LL)(((LD)a*(LD)b)/(LD)m);LL r=a*b-q*m;if(r>m)r%=m;if(r<0)r+=m;return r;}
template <typename T, typename S>T expo(T e, S n){T x=1,p=e;while(n){if(n&1)x=x*p;p=p*p;n>>=1;}return x;}
template <typename T>T power(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mod(x*p,m);p=mod(p*p,m);n>>=1;}return x;}
template <typename T>T powerL(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mulmod(x,p,m);p=mulmod(p,p,m);n>>=1;}return x;}
template <typename T> T InverseEuler(T a, T m){return (a==1? 1 : power(a, m-2, m));}
template <typename T> T gcd(T a, T b){return __gcd(a,b);}
template <typename T> T lcm(T a, T b){return (a*(b/gcd(a,b)));}

vector < string > temp;

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("inp.txt", "r", stdin);
    #endif
    int n;
    cin>>n;
    REP(i, n)
    {
    	string x;
    	cin>>x;
    	temp.pb(x);
    }
    sort(all(temp));
    REP(i, n)
    {
    	cout<<temp[i];
    }
    // cerr<<tick();
    return 0;
}


/*
    AUTHOR:         BHUVNESH JAIN
    INSTITUITION:   BITS PILANI, PILANI
*/
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <iterator>
#include <cmath>
#include <cassert>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <climits>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<int,pii> piii;

#define fastio          std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define PAUSE_EXE       assert(false)
#define inchar          getchar
#define outchar(x)      putchar(x)
#define MAX             200005
#define MOD             1000000007LL
#define REP(i,n)        for(__typeof(n) i=0; i<n; ++i)
#define CREP(i,n)       for(__typeof(n) i=n-1; i>=0; --i)
#define MYREP(i,a,b)    for(__typeof(a) i=a; i<=b; ++i)
#define MYCREP(i,a,b)   for(__typeof(a) i=b; i>=a; --i)
#define SET(a, b)       memset(a, b, sizeof(a))
#define count_one(a)    __builtin_popcountll(a)
#define power_2(a)      (a)&(a-1)==0
#define sz(a)           int((a).size())
#define pb              push_back
#define mp              make_pair
#define fi              first
#define sec             second
#define all(c)          (c).begin(),(c).end()
#define allr(c)         (c).rbegin(),(c).rend()
#define loop(c,i)       for(typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define loopr(c,i)      for(typeof(c.end()) i = c.end(); i != c.begin(); )
#define UNIQUE(a)       sort(all(a)), (a).erase(unique(all(a)),(a).end())
#define present(c,x)    ((c).find(x) != (c).end())
#define cpresent(c,x)   (find(all(c),x) != (c).end())

const double EPS = 1e-10;
const double PI = acos(-1.0);

template <typename T> void inPos(T &x)
{x=0;register T c=inchar();while(((c<48)||(c>57))&&(c!='-'))c=inchar();bool neg=false;if(c=='-')neg=true;for(;c<48||c>57;c=inchar());for(;c>47&&c<58;c=inchar())x=(x<<3)+(x<<1)+(c&15);if(neg)x=-x;}

template <typename T> void outPos (T n)
{char snum[65];int i=0;do {snum[i++]=n%10+'0';n/=10;}while(n);i=i-1;while(i>=0)outchar(snum[i--]);outchar('\n');}

// === tick a time ===
#include <ctime>
double tick() {static clock_t oldtick;clock_t newtick=clock();double diff = 1.0*(newtick-oldtick)/CLOCKS_PER_SEC;oldtick = newtick;return diff;}

template <typename T> T mod(T a, T b) {return (a < b ? a : a % b);}
LL mulmod(LL a,LL b, LL m){LL q=(LL)(((LD)a*(LD)b)/(LD)m);LL r=a*b-q*m;if(r>m)r%=m;if(r<0)r+=m;return r;}
template <typename T, typename S>T expo(T e, S n){T x=1,p=e;while(n){if(n&1)x=x*p;p=p*p;n>>=1;}return x;}
template <typename T>T power(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mod(x*p,m);p=mod(p*p,m);n>>=1;}return x;}
template <typename T>T powerL(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mulmod(x,p,m);p=mulmod(p,p,m);n>>=1;}return x;}
template <typename T> T InverseEuler(T a, T m){return (a==1? 1 : power(a, m-2, m));}
template <typename T> T gcd(T a, T b){return __gcd(a,b);}
template <typename T> T lcm(T a, T b){return (a*(b/gcd(a,b)));}

int cmp(string a, string b)
{
    if (a.length()==b.length())
        return (a < b);
    else
    {
        int i, j=min(a.length(), b.length());
        for(int k=0; k<j; ++k)
        {
            if (a[k]==b[k])
                continue;
            else
                return (a[k]<b[k]);
        }
        if (a.length() < b.length())
            return -1;
        else
            return 1;
    }
}

vector < string > temp;

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("inp.txt", "r", stdin);
    #endif
    int n;
    cin>>n;
    REP(i, n)
    {
    	string x;
    	cin>>x;
    	temp.pb(x);
    }
    sort(all(temp), cmp);
    REP(i, n)
    {
    	cout<<temp[i];
    }
    // cerr<<tick();
    return 0;
}


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

int n;
vector<string> v;

bool compare (const string &a, const string &b) {
	return a + b < b + a;
}

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; ++i) {
		string s; cin >> s;
		v.push_back(s);
	}
	sort(v.begin(), v.end(), compare);
	for (int i = 0; i < v.size(); ++i)
		cout << v[i];
	cout << '\n';
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 5e4 + 10;
const int M = 30;

int n;
vector<int> ans;
vector<int> v[N][M];
vector<string> word;

bool compare (const int &a, const int &b) {
	// cout << word[a] << ' ' << word[b] << '\n';
	for (int i = 0; i < M; ++i) {
		if (!v[a][i].size() and !v[b][i].size()) {
			// cout << "nenhuma tem: " << char('a' + i) << '\n';
			continue;
		}
		if (v[a][i].size() and !v[b][i].size()) {
			// cout << "a < b, because b dont have: " << char('a' + i) << '\n';
			return true;
		}
		if (!v[a][i].size() and v[b][i].size()) {
			// cout << "a > b, because a dont have: " << char('a' + i) << '\n';
			return false;
		}
		for (int j = 0; j < min(v[a][i].size(), v[b][i].size()); ++j) {
			if (v[a][i][j] < v[b][i][j]) {
				// cout << "a < b, because a have first: " << char('a' + i) << '\n';
				return true;
			}
			if (v[b][i][j] < v[a][i][j]) {
				// cout << "a > b, because b have first: " << char('a' + i) << '\n';
				return false;
			}
		}
		if (v[a][i].size() < v[b][i].size()) {
			// cout << "a < b, because b have more: " << char('a' + i) << '\n';
			return false;
		}
		if (v[b][i].size() < v[a][i].size()) {
			// cout << "a > b, because a have more: " << char('a' + i) << '\n';
			return true;
		}
	}
	// cout << "são iguais -.-" << '\n';
	return false;
}

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; ++i) {
		string s; cin >> s;
		ans.push_back(i);
		word.push_back(s);
		for (int j = 0; j < s.length(); ++j)
			v[i][s[j] - 'a'].push_back(j);
	}
	sort(ans.begin(), ans.end(), compare);
	for (int i = 0; i < ans.size(); ++i)
		cout << word[ans[i]];
	cout << '\n';
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 5e4 + 10;
const int M = 30;

int n;
vector<int> ans;
vector<int> v[N][M];
vector<string> word;

bool compare (const int &a, const int &b) {
	for (int i = 0; i < M; ++i) {
		if (!v[a][i].size() and !v[b][i].size())
			continue;
		if (v[a][i].size() and !v[b][i].size())
			return true;
		if (!v[a][i].size() and v[b][i].size())
			return false;
		for (int j = 0; j < min(v[a][i].size(), v[b][i].size()); ++j) {
			if (v[a][i][j] < v[b][i][j])
				return true;
			if (v[b][i][j] < v[a][i][j])
				return false;
		}
		if (v[a][i].size() < v[b][i].size())
			return false;
		if (v[b][i].size() < v[a][i].size())
			return true;
	}
	return false;
}

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; ++i) {
		string s; cin >> s;
		ans.push_back(i);
		word.push_back(s);
		for (int j = 0; j < s.length(); ++j)
			v[i][s[j] - 'a'].push_back(j);
	}
	sort(ans.begin(), ans.end(), compare);
	for (int i = 0; i < ans.size(); ++i)
		cout << word[ans[i]];
	cout << '\n';
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 5e4 + 10;
const int M = 30;

int n;
vector<string> word;
vector<int> ans, pos[N][M];

bool compare (const int &a, const int &b) {
	for (int i = 0; i < M; ++i) {
		for (int j = 0; j < min(pos[a][i].size(), pos[b][i].size()); ++j) {
			if (pos[a][i][j] < pos[b][i][j])
				return true;
			if (pos[a][i][j] > pos[b][i][j])
				return false;
		}
		if (pos[a][i].size() > pos[b][i].size())
			return true;
		if (pos[a][i].size() < pos[b][i].size())
			return false;
	}
	return false;
}

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; ++i) {
		string s; cin >> s;
		ans.push_back(i);
		word.push_back(s);
		for (int j = 0; j < s.length(); ++j)
			pos[i][s[j] - 'a'].push_back(j);
	}
	sort(ans.begin(), ans.end(), compare);
	for (int i = 0; i < n; ++i)
		cout << word[ans[i]];
	cout << '\n';
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 5e4 + 10;
const int M = 30;

int n;
vector<int> ans;
vector<int> v[N][M];
vector<string> word;

bool compare (const int &a, const int &b) {
	for (int i = 0; i < M; ++i) {
		if (!v[a][i].size() and !v[b][i].size())
			continue;
		if (v[a][i].size() and !v[b][i].size())
			return true;
		if (!v[a][i].size() and v[b][i].size())
			return false;
		for (int j = 0; j < min(v[a][i].size(), v[b][i].size()); ++j) {
			if (v[a][i][j] < v[b][i][j])
				return true;
			if (v[a][i][j] > v[b][i][j])
				return false;
		}
		if (v[a][i].size() > v[b][i].size())
			return true;
		if (v[a][i].size() < v[b][i].size())
			return true;
	}
	return false;
}

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; ++i) {
		string s; cin >> s;
		ans.push_back(i);
		word.push_back(s);
		for (int j = 0; j < s.length(); ++j)
			v[i][s[j] - 'a'].push_back(j);
	}
	sort(ans.begin(), ans.end(), compare);
	for (int i = 0; i < ans.size(); ++i)
		cout << word[ans[i]];
	cout << '\n';
	return 0;
}


#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cstdio>
#include <numeric>
using namespace std;

# define WTF() printf("UNEXPECTED at line %d\n", __LINE__)
# define INF ((int)1e9 + 100500)
# define MOD ((int)1e9 + 9)
# define LIM (2000)

int main()
{
	int n; cin >> n;

	vector<string> ans(n);
	for(int i=0; i<n; ++i) {
		cin >> ans[i];
	}

	sort(ans.begin(), ans.end(), [](const string &a, const string &b) {
		string s1 = a+b;
		string s2 = b+a;
		for(int i=0; i<s1.size(); ++i) {
			if (s1[i] != s2[i]) {
				return (s1[i] < s2[i]);
			}
		}
		return true;
	});

	for(int i=0; i<ans.size(); ++i) {
		printf("%s", ans[i].c_str());
	}
	return 0;
}


#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cstdio>
#include <numeric>
using namespace std;

# define WTF() printf("UNEXPECTED at line %d\n", __LINE__)
# define INF ((int)1e9 + 100500)
# define MOD ((int)1e9 + 9)
# define LIM (2000)

int main()
{
	int n; cin >> n;

	vector<string> ans(n);
	for(int i=0; i<n; ++i) {
		cin >> ans[i];
	}

	sort(ans.begin(), ans.end(), [](const string &a, const string &b) {
		int ml = max(a.size(), b.size());
		for(int i=0; i<ml; ++i) {
			char ch1 = a[i%a.size()];
			char ch2 = b[i%b.size()];
			if (ch1 != ch2) {
				return (ch1 < ch2);
			}
		}
		return false;
	});

	for(int i=0; i<ans.size(); ++i) {
		printf("%s", ans[i].c_str());
	}
	return 0;
}


#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cstdio>
#include <numeric>
using namespace std;

# define WTF() printf("UNEXPECTED at line %d\n", __LINE__)
# define INF ((int)1e9 + 100500)
# define MOD ((int)1e9 + 9)
# define LIM (2000)

int main()
{
	int n; cin >> n;

	vector<string> ans(n);
	for(int i=0; i<n; ++i) {
		cin >> ans[i];
	}

	sort(ans.begin(), ans.end(), [](const string &a, const string &b) {
		int ml = max(a.size(), b.size());
		for(int i=0; i<ml; ++i) {
			char ch1 = (i < a.size()? a[i]:b[i-a.size()]);
			char ch2 = (i < b.size()? b[i]:a[i-b.size()]);
			if (ch1 != ch2) {
				return (ch1 < ch2);
			}
		}
		return (a.size() < b.size());
	});

	for(int i=0; i<ans.size(); ++i) {
		printf("%s", ans[i].c_str());
	}
	return 0;
}


#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cstdio>
#include <numeric>
using namespace std;

# define WTF() printf("UNEXPECTED at line %d\n", __LINE__)
# define INF ((int)1e9 + 100500)
# define MOD ((int)1e9 + 9)
# define LIM (2000)

int main()
{
	int n; cin >> n;

	vector<string> ans(n);
	for(int i=0; i<n; ++i) {
		cin >> ans[i];
	}

	sort(ans.begin(), ans.end(), [](const string &a, const string &b) {
		int ml = max(a.size(), b.size());
		for(int i=0; i<ml; ++i) {
			char ch1 = a[i%a.size()];
			char ch2 = b[i%b.size()];
			if (ch1 != ch2) {
				return (ch1 < ch2);
			}
		}
		return (a.size() < b.size());
	});

	for(int i=0; i<ans.size(); ++i) {
		printf("%s", ans[i].c_str());
	}
	return 0;
}


#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cstdio>
#include <numeric>
using namespace std;

# define WTF() printf("UNEXPECTED at line %d\n", __LINE__)
# define INF ((int)1e9 + 100500)
# define MOD ((int)1e9 + 9)
# define LIM (2000)

int main()
{
	int n; cin >> n;

	vector<string> ans(n);
	for(int i=0; i<n; ++i) {
		cin >> ans[i];
	}

	sort(ans.begin(), ans.end(), [](const string &a, const string &b) {
		string s1 = a+b;
		string s2 = b+a;
		for(int i=0; i<s1.size(); ++i) {
			if (s1[i] != s2[i]) {
				return (s1[i] < s2[i]);
			}
		}
		return (a.size() < b.size());
	});

	for(int i=0; i<ans.size(); ++i) {
		printf("%s", ans[i].c_str());
	}
	return 0;
}


#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cstdio>
#include <numeric>
using namespace std;

# define WTF() printf("UNEXPECTED at line %d\n", __LINE__)
# define INF ((int)1e9 + 100500)
# define MOD ((int)1e9 + 9)
# define LIM (2000)

int main()
{
	int n; cin >> n;

	vector<string> ans(n);
	for(int i=0; i<n; ++i) {
		cin >> ans[i];
	}

	sort(ans.begin(), ans.end(), [](const string &a, const string &b) {
		int ml = max(a.size(), b.size());
		for(int i=0; i<ml; ++i) {
			char ch1 = a[i%a.size()];
			char ch2 = b[i%b.size()];
			if (ch1 != ch2) {
				return (ch1 < ch2);
			}
		}
		return (a.size() > b.size());
	});

	for(int i=0; i<ans.size(); ++i) {
		printf("%s", ans[i].c_str());
	}
	return 0;
}


#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cstdio>
#include <numeric>
using namespace std;

# define WTF() printf("UNEXPECTED at line %d\n", __LINE__)
# define INF ((int)1e9 + 100500)
# define MOD ((int)1e9 + 9)
# define LIM (2000)

int main()
{
	int n; cin >> n;

	vector<string> ans(n);
	for(int i=0; i<n; ++i) {
		cin >> ans[i];
	}

	sort(ans.begin(), ans.end(), [](const string &a, const string &b) {
		int ml = max(a.size(), b.size());
		for(int i=0; i<ml; ++i) {
			char ch1 = (i < a.size()? a[i]:a[0]);
			char ch2 = (i < b.size()? b[i]:b[0]);
			if (ch1 != ch2) {
				return (ch1 < ch2);
			}
		}
		return (a.size() < b.size());
	});

	for(int i=0; i<ans.size(); ++i) {
		printf("%s", ans[i].c_str());
	}
	return 0;
}


#include<bits/stdc++.h>
#define F(i,a,b) for(ll i=(a) ; i<=(b) ; i++)
using namespace std;
typedef long long ll;
const ll M=5e4+100;

string t1,t2;
vector<string> s;
ll n;

inline bool cmmp(const string &x,const string &y){
	t1=x;
	t1+=y;
	t2=y;
	t2+=x;
	return t1<t2;/*
	F(i,0,t1.length()-1){
		if((t1[i]-'a')<(t2[i]-'a')){
			return true;
		}
		if((t1[i]-'a')>(t2[i]-'a')){
			return false;
		}
	}
	return true;*/
}

int main(){

cin>>n;
F(i,0,n-1) cin>>t1,s.push_back(t1);
sort(s.begin(),s.end(),cmmp);
F(i,0,n-1) cout<<s[i];

return 0;
}


#include<bits/stdc++.h>
#define F(i,a,b) for(ll i=(a) ; i<=(b) ; i++)
using namespace std;
typedef long long ll;
const ll M=5e4+100;

string t1,t2;
vector<string> s;
ll n;

inline bool cmmp(const string &x,const string &y){
	t1=x;
	t1+=y;
	t2=y;
	t2+=x;
	F(i,0,t1.length()-1){
		if((t1[i]-'a')<(t2[i]-'a')){
			return true;
		}
		if((t1[i]-'a')>(t2[i]-'a')){
			return false;
		}
	}
	return true;
}

int main(){

cin>>n;
F(i,0,n-1) cin>>t1,s.push_back(t1);
sort(s.begin(),s.end(),cmmp);
F(i,0,n-1) cout<<s[i];

return 0;
}


#include <bits/stdc++.h>

using namespace std;

static map<int, set<int> > divisors;

set<int> get_divisors(int nr)
{
  if (divisors.count(nr) == 0)
  {
    set<int> newentry;
    for (int i = 1; i<= (nr/2); i++)
      if ((nr % i) == 0) newentry.insert(i);
    newentry.insert(nr);
    divisors[nr] = newentry;
  }
  return divisors[nr];
}

int main (void)
{
  ios::sync_with_stdio(false);

  int n;
  cin >> n;

  map<int, int> most_recent_occurrence;

  for (int i = 0; i < n ; i++)
  {
    int x,y;
    cin >> x >> y;

    // Get divisors
    set<int> divisors = get_divisors(x);

    // Print answer
    if (y == 0)
    {
      cout << divisors.size() << "\n";
    }
    else
    {
      cout << count_if(divisors.begin(), divisors.end(), [&most_recent_occurrence, i, y](int d){return (most_recent_occurrence.count(d) == 0) || (most_recent_occurrence[d] < (i-y));}) << "\n";
    }

    // Update history
    for (int d : divisors)
    {
      most_recent_occurrence[d] = i;
    }
  }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

static map<int, set<int> > divisors;
static vector<int> history;

set<int> get_divisors(int nr)
{
  if (divisors.count(nr) == 0)
  {
    set<int> newentry;
    for (int i = 1; i<= (nr/2); i++)
      if ((nr % i) == 0) newentry.insert(i);
    newentry.insert(nr);
    divisors[nr] = newentry;
  }
  return divisors[nr];
}

int main (void)
{
  ios::sync_with_stdio(false);

  int n;
  cin >> n;

  for (int i = 0; i < n ; i++)
  {
    int x,y;
    cin >> x >> y;
    history.push_back(x);
    if (y == 0)
    {
      cout << get_divisors(x).size() << "\n";
    }
    else
    {
      int answer = 0;
      for (int d : get_divisors(x))
      {
        bool count = true;
        int j = y;
        while (count && (j > 0))
        {
          count = count && (get_divisors(history[i-j]).count(d) == 0);
          j--;
        }
        if (count) answer++;
      }
      cout << answer << "\n";
    }

  }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

static array<vector<int>, 100001 > divisors;

const vector<int> &get_divisors(int nr)
{
  if (divisors[nr].size() == 0)
  {
    for (int i = 1; i<= (nr/2); i++)
      if ((nr % i) == 0) divisors[nr].push_back(i);
    divisors[nr].push_back(nr);
  }
  return divisors[nr];
}

int main (void)
{
  ios::sync_with_stdio(false);

  int n;
  cin >> n;

  array<int, 100001> most_recent_occurrence;
  most_recent_occurrence.fill(-1);

  for (int i = 0; i < n ; i++)
  {
    int x,y;
    cin >> x >> y;

    // Get divisors
    const auto &divisors = get_divisors(x);

    // Print answer
    cout << count_if(divisors.begin(), divisors.end(), [&most_recent_occurrence, i, y](int d){return (most_recent_occurrence[d] < (i-y));}) << "\n";

    // Update history
    for (int d : divisors)
    {
      most_recent_occurrence[d] = i;
    }
  }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

static map<int, array<bool, 100001>> divisors;
static vector<array<bool, 100001>> history;

array<bool, 100001> get_divisors(int nr)
{
  if (divisors.count(nr) == 0)
  {
    array<bool, 100001> newentry;
    newentry.fill(false);
    for (int i = 1; i<= (nr/2); i++)
      newentry[i] = ((nr % i) == 0);
    newentry[nr] = true;
    divisors[nr] = newentry;
  }
  return divisors[nr];
}

int main (void)
{
  ios::sync_with_stdio(false);

  int n;
  cin >> n;

  for (int i = 0; i < n ; i++)
  {
    int x,y;
    cin >> x >> y;
    history.push_back(get_divisors(x));
    if (y == 0)
    {
      cout << count(history[i].begin(), history[i].end(), true) << "\n";
    }
    else
    {
      int answer = 0;
      for (int d = 1; d <= x; d++)
      {
        if (history[i][d])
        {
          bool count = true;
          int j = y;
          while (count && (j > 0))
          {
            count = count && (!history[i-j][d]);
            j--;
          }
          if (count) answer++;
        }
      }
      cout << answer << "\n";
    }

  }

  return 0;
}


 #include<bits/stdc++.h>
 using namespace std;
vector<int>v;
int A[100005];
 int main(){
     memset(A,-1,sizeof(A));
int q;cin>>q;
for(int i=0;i<q;i++){
    int x,y;scanf("%d%d",&x,&y);
    int res=0;
    for(int j=1;j*j<=x;j++){
        if(x%j)continue;
        if(A[j]==-1||i-A[j]>y)res++;
        if((A[j]==-1||i-A[x/j]>y)&&x/j!=j)res++;
    A[x/j]=i;
    A[j]=i;}
    printf("%d\n",res);
}
 return 0;}


 #include<bits/stdc++.h>
 using namespace std;
vector<int>v;
int A[100005];
 int main(){
     memset(A,-1,sizeof(A));
int q;cin>>q;
for(int i=0;i<q;i++){
    int x,y;scanf("%d%d",&x,&y);
    int res=0;
    for(int j=1;j*j<=x;j++){
        if(x%j)continue;
        if(A[j]==-1||i-A[j]>y)res++;
        if((A[x/j]==-1||i-A[x/j]>y)&&x/j!=j)res++;
    A[x/j]=i;
    A[j]=i;}
    printf("%d\n",res);
}
 return 0;}


#define  _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<map>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<stack>
#include<math.h>
#include<set>
#include<string>
#include<cstring>
#include<queue>
#include<complex>
#include<assert.h>
#include<math.h>
#include<memory.h>
#include <stdlib.h>
#include<sstream>
#include<cstdio>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define repi(i,a,n) for(int i=a;i<n;i++)

#define mp make_pair
#define pb push_back
#define fastIO ios::sync_with_stdio(false)
#define read freopen("in.in","r",stdin)
#define write freopen("out.out","w",stdout)
#define scf(xx) scanf("%d",&xx)
#define All(a) a.begin(), a.end()
#define LSOne(S) (S & (-S))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef long double ld;

#define X first
#define Y second
int dx[] = { 0, 0, 1, -1, -1, -1, 1, 1 };
int dy[] = { 1, -1, 0, 0, 1, -1, 1, -1 };

const int MAX_N = 100010;
// Sieve Algorithm to generate all primes number in the range [0, MAX_N];
vi primes;  // save a list of all prime Numbers smaller than MAX_N
bool is_prime[MAX_N]; // check if index(number) is prime or not !
void sieve(){ // Big-O( nlog(log(n)) )
	for (int i = 0; i < MAX_N; i++)
		is_prime[i] = true; // Assume that all numbers are primes number
	is_prime[0] = is_prime[1] = false; // 0 & 1 are not a prime numbers
	for (ll i = 2; i < MAX_N; i++)
	{
		if (is_prime[i]) // prime number found :D
		{
			primes.push_back(i);
			for (ll j = i * i; j < MAX_N; j += i)
				is_prime[j] = false;   // all multiples of (i) are not  prime numbers !
		}
	}
}

vi d[MAX_N];
void divisors(int x){
	for (ll i = 1; i*i <= x; i++)
	if (x%i == 0) d[x].push_back(i), d[x].push_back(x / i);
}

map<int, int> M;
int main(){
	//fastIO;
	//read; write;
	sieve();
	repi(i, 1,MAX_N)
		divisors(i);
	int n,x,y; scf(n);
	int res = 0;
	rep(i, n){
		scf(x); scf(y);
		rep(j, d[x].size()){
			if (M.find(d[x][j]) == M.end()) res++;
			else if (M[d[x][j]] < i - y) res++;
			M[d[x][j]] = i;
		}
		printf("%d\n", res);
		res = 0;
	}
	return 0;
}


#define  _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<map>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<stack>
#include<math.h>
#include<set>
#include<string>
#include<cstring>
#include<queue>
#include<complex>
#include<assert.h>
#include<math.h>
#include<memory.h>
#include <stdlib.h>
#include<sstream>
#include<cstdio>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define repi(i,a,n) for(int i=a;i<n;i++)

#define mp make_pair
#define pb push_back
#define fastIO ios::sync_with_stdio(false)
#define read freopen("in.in","r",stdin)
#define write freopen("out.out","w",stdout)
#define scf(xx) scanf("%d",&xx)
#define All(a) a.begin(), a.end()
#define LSOne(S) (S & (-S))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef long double ld;

#define X first
#define Y second
int dx[] = { 0, 0, 1, -1, -1, -1, 1, 1 };
int dy[] = { 1, -1, 0, 0, 1, -1, 1, -1 };

const int MAX_N = 100010;
// Sieve Algorithm to generate all primes number in the range [0, MAX_N];
vi primes;  // save a list of all prime Numbers smaller than MAX_N
bool is_prime[MAX_N]; // check if index(number) is prime or not !
void sieve(){ // Big-O( nlog(log(n)) )
	for (int i = 0; i < MAX_N; i++)
		is_prime[i] = true; // Assume that all numbers are primes number
	is_prime[0] = is_prime[1] = false; // 0 & 1 are not a prime numbers
	for (ll i = 2; i < MAX_N; i++)
	{
		if (is_prime[i]) // prime number found :D
		{
			primes.push_back(i);
			for (ll j = i * i; j < MAX_N; j += i)
				is_prime[j] = false;   // all multiples of (i) are not  prime numbers !
		}
	}
}

vi factors[MAX_N];
void prime_Factors(ll N) { // remember: vi is vector<int>, ll is long long
	int x = N;
	ll PF_idx = 0, PF = primes[PF_idx]; // using PF = 2, then 3,5,7,...    // PF:Prime Factor
	while (N != 1 && (PF * PF <= N)) { // stop at sqrt(N), but N can get smaller
		while (N % PF == 0) { N /= PF; factors[x].push_back(PF); } // remove this PF
		PF = primes[++PF_idx]; // only consider primes!
	}
	if (N != 1) factors[x].push_back(N); // special case if N is actually a prime
}

int main(){
	fastIO;
	//read; write;
	sieve();
	repi(i, 1,MAX_N)
		prime_Factors(i);
	cout << "DONE";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 1e5;
vector<int> mem[N + 1];
vector<int> last(N, -1);

vector<int> &get_dividers(int n) {
    if (!mem[n].empty()) {
        return mem[n];
    }

    for (int i = 1; i * i <= n; i++)
        if (n % i == 0) {
            mem[n].push_back(i);

            if (i * i != n) {
                mem[n].push_back(n / i);
            }
        }

    return mem[n];
}

main() {
#ifndef ONLINE_JUDGE
    freopen("1.txt", "r", stdin);
#endif // ONLINE_JUDGE

    int m;
    scanf("%d", &m);

    for (int i = 0; i < m; i++) {
        int x, y, ans = 0;
        scanf("%d%d", &x, &y);
        y = min(y, i);

        for (int j : get_dividers(x)) {
            ans += last[j] < i - y;
            last[j] = i;
        }

        printf("%d\n", ans);
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 1e5;
vector<int> mem[N + 1];
vector<int> last(N, -1);

vector<int> &get_dividers(int n) {
    if (!mem[n].empty()) {
        return mem[n];
    }

    for (int i = 1; i * i <= n; i++)
        if (n % i == 0) {
            mem[n].push_back(i);

            if (i * i != n) {
                mem[n].push_back(n / i);
            }
        }

    return mem[n];
}

main() {
#ifndef ONLINE_JUDGE
    freopen("1.txt", "r", stdin);
#endif // ONLINE_JUDGE

    int m;
    scanf("%d", &m);

    for (int i = 0; i < m; i++) {
        int x, y, ans = 0;
        scanf("%d%d", &x, &y);

        for (int j : get_dividers(x)) {
            ans += last[j] < i - y;
            last[j] = i;
        }

        printf("%d\n", ans);
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 1e5;
vector<int> mem[N + 1];
vector<int> last(N + 1, -1e9);

vector<int> &get_dividers(int n) {
    if (!mem[n].empty()) {
        return mem[n];
    }

    for (int i = 1; i * i <= n; i++)
        if (n % i == 0) {
            mem[n].push_back(i);

            if (i * i != n) {
                mem[n].push_back(n / i);
            }
        }

    return mem[n];
}

main() {
#ifndef ONLINE_JUDGE
    freopen("1.txt", "r", stdin);
#endif // ONLINE_JUDGE

    int m;
    scanf("%d", &m);

    for (int i = 0; i < m; i++) {
        int x, y, ans = 0;
        scanf("%d%d", &x, &y);

        for (int j : get_dividers(x)) {
            ans += last[j] < i - y;
            last[j] = i;
        }

        printf("%d\n", ans);
    }

    return 0;
}


#include <iostream>

using namespace std;

int    n , x[100010] , y ;

int sol(int i , int y){
     bool test ;
     int j ;
     int  ans=0 ;
     for (j=1 ; j*j<x[i] ; j++){
          if (x[i]%j==0){
               test = true ;
               for (int ii=1 ; ii<=y ; ii++)
                    if (x[i-ii]%j==0) test=false;
               if (test) ans++;
               test = true ;
               int jj = x[i]/j;
               for (int ii=1 ; ii<=y ; ii++)
                    if (x[i-ii]%jj==0) test=false;
               if (test) ans++;
          }
     }
     if (j*j==x[i]){
               test = true ;
               for (int ii=1 ; ii<=y ; ii++)
                    if (x[i-ii]%j==0) test=false;
               if (test) ans++;

     }
     return ans ;
}

int main(){
     cin >> n ;
     for (int i=0 ; i<n ; i++){
          cin >> x[i] >> y ;
          cout << sol(i,y) << endl ;
     }
}


#include <iostream>

using namespace std;

int    n , x , d[100008] , y ;

int sol(int i , int y){
     int j;
     int ans=0;
     for (j=1 ; j*j<x ; j++){
          if (x%j==0){
               if (d[j]<i-y) ans++;
               d[j]=i;
               if (d[x/j]<i-y) ans++;
               d[x/j]=i;
          }
     }
     if (j*j==x){
          if (d[j]<i-y) ans++;
          d[j]=i;
     }
     return ans ;
}

int main(){
     cin >> n ;
     for (int i=0 ; i<n ; i++){
          cin >> x >> y ;
          cout << sol(i+1,y) << endl ;
     }
}


#include <iostream>

using namespace std;

int    n , x[100010] , y ;

int sol(int i , int y){
     bool test ;
     int j ;
     int  ans=0 ;
     for (j=1 ; j*j<x[i] ; j++){
          if (x[i]%j==0){
               test = true ;
               int ii=1;
               while (test && ii<=y)
                    if (x[i-ii++]%j==0) test=false;
               if (test) ans++;
               test = true ;
               int jj = x[i]/j;
               ii=1;
               while (test && ii<=y)
                    if (x[i-ii++]%jj==0) test=false;
               if (test) ans++;
          }
     }
     if (j*j==x[i]){
               test = true ;
               for (int ii=1 ; ii<=y ; ii++)
                    if (x[i-ii]%j==0) test=false;
               if (test) ans++;

     }
     return ans ;
}

int main(){
     cin >> n ;
     for (int i=0 ; i<n ; i++){
          cin >> x[i] >> y ;
          cout << sol(i,y) << endl ;
     }
}


#include <iostream>

using namespace std;

int    n , x , d[100010] , y ;

int sol(int i , int y){
     int j;
     int ans=0;
     for (j=1 ; j*j<x ; j++){
          if (x%j==0){
               if (d[j]<i-y) ans++;
               d[j]=i;
               if (d[x/j]<i-y) ans++;
               d[x/j]=i;
          }
     }
     if (j*j==x){
          if (d[j]<i-y) ans++;
          d[j]=i;
     }
     return ans ;
}

int main(){
     cin >> n ;
     for (int i=0 ; i<n ; i++){
          cin >> x >> y ;
          cout << sol(i+1,y) << endl ;
     }
}


#include <iostream>

using namespace std;

int    n , x[100010] , d[100010] , y ;

int sol(int i , int y){
     int j;
     int ans=0;
     for (j=1 ; j*j<x[i] ; j++){
          if (x[i]%j==0){
               if (d[j]<i-y) ans++;
               d[j]=i;
               if (d[x[i]/j]<i-y) ans++;
               d[x[i]/j]=i;
          }
     }
     if (j*j==x[i]){
          if (d[j]<i-y) ans++;
          d[j]=i;
     }
     return ans ;
}

int main(){
     cin >> n ;
     for (int i=0 ; i<n ; i++){
          cin >> x[i+1] >> y ;
          cout << sol(i+1,y) << endl ;
     }
}


#include <iostream>

using namespace std;

int    n , x[100010] , y ;

int sol(int i , int y){
     bool test ;
     int j ;
     int  ans=0 ;
     for (j=1 ; j*j<x[i] ; j++){
          if (x[i]%j==0){
               test = true ;
               for (int ii=1 ; ii<=y ; ii++)
                    if (x[i-ii]%j==0) test=false;
               if (test) ans++;
               test = true ;
               int jj = x[i]/j;
               for (int ii=1 ; ii<=y ; ii++)
                    if (x[i-ii]%jj==0) test=false;
               if (test) ans++;
          }
     }
     if (j*j==x[i]){
               test = true ;
               for (int ii=0 ; ii<y ; ii++)
                    if (x[i-ii]%j==0) test=false;
               if (test) ans++;

     }
     return ans ;
}

int main(){
     cin >> n ;
     for (int i=0 ; i<n ; i++){
          cin >> x[i] >> y ;
          cout << sol(i,y) << endl ;
     }
}


#include <bits/stdc++.h>
using namespace std;
#define oo 1000000000
typedef long long int     ll;
map<int, int>mp;
const int N = 303;
int n;vector<int>v;
int x[N], y[N];

vector<int> findDiv(int a){
    vector<int>s;
    for(int i=1;i*i<=a;i++){
        if(!(a%i)){
            if(a/i != i)
                s.push_back(a/i);
            s.push_back(i);
        }
    }
    return s;
}

int main() {
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif // ONLINE_JUDGE
    scanf("%d", &n);
    for(int i=0;i<n;i++) scanf("%d%d", x+i, y+i);
    for(int i=0;i<n;i++){
        int newIndx = i-y[i];
        v = findDiv(x[i]); int no = v.size();
        if(y[i] == 0) goto there;
        for(int j=0;j<v.size();j++)
            if(mp.count(v[j]) > 0) if(mp[v[j]] >= newIndx) no--;
        there:
        for(int j=0;j<v.size();j++) mp[v[j]] = i;
        cout << no << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define oo 1000000000
typedef long long int     ll;
map<int, int>mp;
const int N = 100005;
int n;vector<int>v;
int x[N], y[N];

vector<int> findDiv(int a){
    vector<int>s;
    for(int i=1;i*i<=a;i++){
        if(!(a%i)){
            if(a/i != i)
                s.push_back(a/i);
            s.push_back(i);
        }
    }
    return s;
}

int main() {
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif // ONLINE_JUDGE
    scanf("%d", &n);
    for(int i=0;i<n;i++) scanf("%d%d", x+i, y+i);
    for(int i=0;i<n;i++){
        int newIndx = i-y[i];
        v = findDiv(x[i]); int no = v.size();
        if(y[i] == 0) goto there;
        for(int j=0;j<v.size();j++)
            if(mp.count(v[j]) > 0) if(mp[v[j]] >= newIndx) no--;
        there:
        for(int j=0;j<v.size();j++) mp[v[j]] = i;
        cout << no << endl;
    }
    return 0;
}


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

#define ENGZ ios::sync_with_stdio(0);cin.tie(0);ios_base::sync_with_stdio(0);
#define sfi(x) scanf("%d" , &x)
#define sfi2(x, y) scanf("%d%d" , &x,&y)
#define sfl2(x, y) scanf("%I64d%I64d" , &x,&y)
#define sfl(x) scanf("%I64d" , &x)
#define sfl3(x, y, z) scanf("%I64d%I64d%I64d", &x, &y, &z)
#define sfd(x) scanf("%lf", &x)
#define sfd2(x, y) scanf("%lf", &x, &y)
#define sfs(x) scanf("%s", &x)
#define testv(x) cerr << x << ' '
#define wtf(s) freopen((s), "w", stdout)
#define rff(s) freopen((s), "r", stdin)
#define test cerr << "here"
#define fst(x) cout << fixed << setprecision(x)
#define mod 1000000007
#define pi (2 * acos(0))
typedef long double ld;
typedef long long ll;

int gcd(int a, int b)
{
    return b == 0? a: gcd(b, a % b);
}

int main()
{
    int n, ans = 0, vis[100005] = {}, a, b;
    sfi(n);
    for (int i = 1; i <= n; i++)
    {
        ans = 0;
        sfi2(a, b);
        for (int j = 1; j * j <= a; j++)
            if (a % j == 0)
            {
                if (vis[j] < i - b)
                    ans++;
                vis[j] = i;
                if (j * j != a)
                {
                    if (vis[a / j] < i - b)
                        ans++;
                    vis[a / j] = i;
                }
            }
        printf("%d\n", ans);
    }
    return 0;
}


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

#define ENGZ ios::sync_with_stdio(0);cin.tie(0);ios_base::sync_with_stdio(0);
#define sfi(x) scanf("%d" , &x)
#define sfi2(x, y) scanf("%d%d" , &x,&y)
#define sfl2(x, y) scanf("%I64d%I64d" , &x,&y)
#define sfl(x) scanf("%I64d" , &x)
#define sfl3(x, y, z) scanf("%I64d%I64d%I64d", &x, &y, &z)
#define sfd(x) scanf("%lf", &x)
#define sfd2(x, y) scanf("%lf", &x, &y)
#define sfs(x) scanf("%s", &x)
#define testv(x) cerr << x << ' '
#define wtf(s) freopen((s), "w", stdout)
#define rff(s) freopen((s), "r", stdin)
#define test cerr << "here"
#define fst(x) cout << fixed << setprecision(x)
#define mod 1000000007
#define pi (2 * acos(0))
typedef long double ld;
typedef long long ll;

int gcd(int a, int b)
{
    return b == 0? a: gcd(b, a % b);
}

int main()
{
    int n, ans = 0;
    pair<int, int> a[100005];
    map<pair<int, int>, int> mp;
    sfi(n);
    for (int i = 1; i <= n; i++)
    {
        ans = 0;
        vector<int> v;
        sfi2(a[i].first, a[i].second);
        for (int j = 1; j * j <= a[i].first; j++)
            if (a[i].first % j == 0)
            {
                mp[{j, i}] = mp[{j, i - 1}] + 1;
                v.push_back(j);
                if (j * j != a[i].first)
                    mp[{a[i].first / j, i}] = mp[{a[i].first / j, i - 1}] + 1,
                    v.push_back(a[i].first / j);
            }
        for (auto it: mp)
            if (mp[{it.first.first, i}] == 0)
                mp[{it.first.first, i}] = mp[{it.first.first, i - 1}];
        for (auto it: v)
            if (mp[{it, i}] - mp[{it, i - a[i].second - 1}] == 1)
                ans++;
        printf("%d\n", ans);
    }
    return 0;
}


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

#define ENGZ ios::sync_with_stdio(0);cin.tie(0);ios_base::sync_with_stdio(0);
#define sfi(x) scanf("%d" , &x)
#define sfi2(x, y) scanf("%d%d" , &x,&y)
#define sfl2(x, y) scanf("%I64d%I64d" , &x,&y)
#define sfl(x) scanf("%I64d" , &x)
#define sfl3(x, y, z) scanf("%I64d%I64d%I64d", &x, &y, &z)
#define sfd(x) scanf("%lf", &x)
#define sfd2(x, y) scanf("%lf", &x, &y)
#define sfs(x) scanf("%s", &x)
#define testv(x) cerr << x << ' '
#define wtf(s) freopen((s), "w", stdout)
#define rff(s) freopen((s), "r", stdin)
#define test cerr << "here"
#define fst(x) cout << fixed << setprecision(x)
#define mod 1000000007
#define pi (2 * acos(0))
typedef long double ld;
typedef long long ll;

int gcd(int a, int b)
{
    return b == 0? a: gcd(b, a % b);
}

int main()
{
    int n, ans = 0, vis[100005], a, b;
    sfi(n);
    for (int i = 1; i <= n; i++)
    {
        ans = 0;
        sfi2(a, b);
        for (int j = 1; j * j <= a; j++)
            if (a % j == 0)
            {
                if (vis[j] < i - b)
                    ans++;
                vis[j] = i;
                if (j * j != a)
                {
                    if (vis[a / j] < i - b)
                        ans++;
                    vis[a / j] = i;
                }
            }
        printf("%d\n", ans);
    }
    return 0;
}


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

#define ENGZ ios::sync_with_stdio(0);cin.tie(0);ios_base::sync_with_stdio(0);
#define sfi(x) scanf("%d" , &x)
#define sfi2(x, y) scanf("%d%d" , &x,&y)
#define sfl2(x, y) scanf("%I64d%I64d" , &x,&y)
#define sfl(x) scanf("%I64d" , &x)
#define sfl3(x, y, z) scanf("%I64d%I64d%I64d", &x, &y, &z)
#define sfd(x) scanf("%lf", &x)
#define sfd2(x, y) scanf("%lf", &x, &y)
#define sfs(x) scanf("%s", &x)
#define testv(x) cerr << x << ' '
#define wtf(s) freopen((s), "w", stdout)
#define rff(s) freopen((s), "r", stdin)
#define test cerr << "here"
#define fst(x) cout << fixed << setprecision(x)
#define mod 1000000007
#define pi (2 * acos(0))
typedef long double ld;
typedef long long ll;

int gcd(int a, int b)
{
    return b == 0? a: gcd(b, a % b);
}

int main()
{
    int n, ans = 0;
    pair<int, int> a[100005];
    map<pair<int, int>, int> mp;
    set<int> s;
    sfi(n);
    for (int i = 1; i <= n; i++)
    {
        ans = 0;
        vector<int> v;
        sfi2(a[i].first, a[i].second);
        for (int j = 1; j * j <= a[i].first; j++)
            if (a[i].first % j == 0)
            {
                mp[{j, i}] = mp[{j, i - 1}] + 1;
                v.push_back(j);
                s.insert(j);
                if (j * j != a[i].first)
                    mp[{a[i].first / j, i}] = mp[{a[i].first / j, i - 1}] + 1,
                    v.push_back(a[i].first / j),
                    s.insert(a[i].first / j);
            }
        for (auto it: s)
            if (mp[{it, i}] == 0)
                mp[{it, i}] = mp[{it, i - 1}];
        for (auto it: v)
            if (mp[{it, i}] - mp[{it, i - a[i].second - 1}] == 1)
                ans++;
        printf("%d\n", ans);
    }
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <memory.h>

using namespace std;

int n,x,y;
int last[10001];

int main() {
	scanf("%d",&n);

	memset(last,-1,sizeof(last));

	for(int i=0; i<n; i++) {
		scanf("%d%d",&x,&y);
		int z = max(0,i-y);
		int cnt = 0;

		for(int j=1; j*j<=x; j++) {
			if(x%j==0) {
				if(last[j]<z) cnt++;
				last[j] = i;
				if(x/j != j) {
					if(last[x/j]<z) cnt++;
					last[x/j] = i;
				}
			}
		}

		printf("%d\n",cnt);
	}

	return 0;
}


#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <memory.h>

using namespace std;

int n,x,y;
int last[100001];

int main() {
	scanf("%d",&n);

	memset(last,-1,sizeof(last));

	for(int i=0; i<n; i++) {
		scanf("%d%d",&x,&y);
		int z = max(0,i-y);
		int cnt = 0;

		for(int j=1; j*j<=x; j++) {
			if(x%j==0) {
				if(last[j]<z) cnt++;
				last[j] = i;
				if(x/j != j) {
					if(last[x/j]<z) cnt++;
					last[x/j] = i;
				}
			}
		}

		printf("%d\n",cnt);
	}

	return 0;
}


#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define pb push_back
vector<int > G[111111];
vector<int > pos[111111];
int main(){
#ifndef ONLINE_JUDGE
	freopen("G:/in.txt","r",stdin);
	//freopen("G:/myout.txt","w",stdout);
#endif
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		int x,y;
		cin>>x>>y;
		int cnt=0;
		for(int j=1;j*j<=x;j++){
            if(x%j==0){
                for(int t=1;t<=1+(j*j!=x);t++){
                    int div;
                    t==1?div=j:div=x/j;
                    int index1=lower_bound(pos[div].begin(),pos[div].end(),i-y-1)-pos[div].begin();
                    int index2=lower_bound(pos[div].begin(),pos[div].end(),i)-pos[div].begin();

                    if(index1+1>=index2){
                        bool ok=true;
                        if(index1<pos[div].size()){
                            if(pos[div][index1]>=i-y && pos[div][index1]<=i-1)
                                ok=false;
                        }
                        if(ok)
                            cnt++;
                    }
                    pos[div].pb(i);
                }
            }
		}
		cout<<cnt<<endl;
	}
}


#include <bits/stdc++.h>
#define in_arr(n,A)                     for(int i=0;i<n;i++)cin>>A[i];
#define IOS                             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define vi                              vector <int>
#define vl                              vector <ll>
#define out_arr(n,A)                    for(int i=0;i<n;i++)cout<<A[i]<<" ";
#define LINE                            cout << endl
#define SPACE                           cout << " "
#define pb                              push_back
#define Fr                              first
#define Sc                              second
#define YES                             cout << "YES"
#define NO                              cout << "NO"
#define wrong                           cout << -1
#define pll                             pair <ll, ll>
#define pii                             pair <int, int>
#define OO                              INT_MAX
#define SMALL                           INT_MIN
#define BIGx2                           LONG_LONG_MAX
#define sz                              size()
//BIT_OP
#define isOn(s, j)                      (s & (1<<j))
#define setBit(s, j)                    (s |= ( 1<< j))
#define clearBit(s, j)                  (s &= ~( 1 << j ))
#define lowBit(s)                       (s & (-s))
#define setAll(s, n)                    ( s = ( 1 << n ) - 1)
#define modulo(s, n)                    ((s) & ( n - 1 ))
#define isPowerOfTwo(s)                 (!(s & (s - 1)))
#define nearestPowerOfTwo(s)            ((int)pow(2.0, (int)((log((double)s) / log(2.0)) + 50. )))
#define nextnearestPowerOfTwo(s)        (1<<(32 - __builtin_clz(s)))
#define turnoffLastBit(s)               ((s) & (s - 1))
#define turnonLastZero(s)               ((S) | (s + 1))
#define turnoffLastConsecutiveBits(s)   ((s) & (s + 1))
typedef long long ll;
using namespace std;
int T, Mx = -1;
int Cnt = 1;
int x, y;
int Visited[200200];
vector <int> Divisor[200300];
int main()
{
    IOS
    for(int i = 1 ; i <= 200200 ; i++)
    {
        for(int j = i ; j <= 200200 ; j += i)
            Divisor[j].pb(i);
    }
    cin >> T;
    while(T--)
    {
        int Ans = 0;
        cin >> x >> y;
        for(auto i : Divisor[x])
        {
            if(Visited[i] < Cnt - y)
                Ans++;
        }
        cout << Ans << endl;
        for(auto i : Divisor[x])
            Visited[i] = Cnt;
        Cnt++;
    }
}


#include <bits/stdc++.h>
#define in_arr(n,A)                     for(int i=0;i<n;i++)cin>>A[i];
#define IOS                             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define vi                              vector <int>
#define vl                              vector <ll>
#define out_arr(n,A)                    for(int i=0;i<n;i++)cout<<A[i]<<" ";
#define LINE                            cout << endl
#define SPACE                           cout << " "
#define pb                              push_back
#define Fr                              first
#define Sc                              second
#define YES                             cout << "YES"
#define NO                              cout << "NO"
#define wrong                           cout << -1
#define pll                             pair <ll, ll>
#define pii                             pair <int, int>
#define OO                              INT_MAX
#define SMALL                           INT_MIN
#define BIGx2                           LONG_LONG_MAX
#define sz                              size()
//BIT_OP
#define isOn(s, j)                      (s & (1<<j))
#define setBit(s, j)                    (s |= ( 1<< j))
#define clearBit(s, j)                  (s &= ~( 1 << j ))
#define lowBit(s)                       (s & (-s))
#define setAll(s, n)                    ( s = ( 1 << n ) - 1)
#define modulo(s, n)                    ((s) & ( n - 1 ))
#define isPowerOfTwo(s)                 (!(s & (s - 1)))
#define nearestPowerOfTwo(s)            ((int)pow(2.0, (int)((log((double)s) / log(2.0)) + 50. )))
#define nextnearestPowerOfTwo(s)        (1<<(32 - __builtin_clz(s)))
#define turnoffLastBit(s)               ((s) & (s - 1))
#define turnonLastZero(s)               ((S) | (s + 1))
#define turnoffLastConsecutiveBits(s)   ((s) & (s + 1))
typedef long long ll;
using namespace std;
int T, Mx = -1;
int Cnt = 1;
int x, y;
int Visited[200200];
vector <int> Divisor[200200];
int main()
{
    IOS
    for(int i = 1 ; i <= 200200 ; i++)
    {
        for(int j = i ; j <= 200200 ; j += i)
            Divisor[j].pb(i);
    }
    cin >> T;
    while(T--)
    {
        int Ans = 0;
        cin >> x >> y;
        for(auto i : Divisor[x])
        {
            if(Visited[i] < Cnt - y)
                Ans++;
        }
        cout << Ans << endl;
        for(auto i : Divisor[x])
            Visited[i] = Cnt;
        Cnt++;
    }
}


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

#define f first
#define s second
#define ll long long
#define ld long double
#define pf push front
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pint pair<int,int>
#define gcd(a,b) __gcd(a,b)
#define pq priority_queue<int,vector<int>,greater<int> >
#define pq1 priority_queue<pint,vector<pint>,greater<pint> >

const int mod = 1e9+7;

std::vector<int>adjlist[100005];

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;

	for (int i = 0; i < n; ++i)
	{
		int x,y;
		cin>>x>>y;
		int ans = 0;
		for (int j = 1; j*j <= x; ++j)
		{
			if(x%j==0){
				if(lower_bound(adjlist[j].begin(),adjlist[j].end(),i-y) == adjlist[j].end()) ans++;
				if(x/j != j && lower_bound(adjlist[x/j].begin(),adjlist[x/j].end(),i-y) == adjlist[x/j].end()) ans++;
				adjlist[j].pb(i);
				adjlist[x/j].pb(i);
			}
		}
		cout<<ans<<endl;
	}
	return 0;

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+5;
const int mod = 1e9+7;
ll qpow(ll a,ll b){ll res = 1;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int last[maxn];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i = 1,x,y;i <= n;++i){
        scanf("%d%d",&x,&y);
        y = i-y;
        int ans = 0;
        for(int j = 1;j*j <= x;++j){
            if(x%j==0){
                int k = x/j;
                if(last[k]<y)
                    ans++;
                last[k]=i;
                if(last[j]<y)
                    ans++;
                last[j]=i;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define SIZE_N 100005
#define SIZE_P 100000

bool flag[SIZE_N+5];
int primes[SIZE_P+5];

int seive()
{
    int i,j,total=0,val;
    for(i=2; i<=SIZE_N; i++) flag[i]=1;
    val=sqrt(SIZE_N)+1;
    for(i=2; i<val; i++){
        if(flag[i]){
            for(j=i; j*i<=SIZE_N; j++) flag[i*j]=0;
        }
    }

    for(i=2; i<=SIZE_N; i++){
        if(flag[i]) primes[total++]=i;
    }

    return total;
}

int store_primes[100],freq_primes[100], store_divisor[10000], Total_Prime, ans;

void divisor(int N)
{
    int i,val,ct;

    val=sqrt(N)+1;
    Total_Prime=0;
    for(i=0; primes[i]<val; i++){
        if(N%primes[i]==0){
            ct=0;
            while(N%primes[i]==0){
                N/=primes[i];
                ct++;
            }
            store_primes[Total_Prime]=primes[i];
            freq_primes[Total_Prime]=ct;
            Total_Prime++;
            val=sqrt(N)+1;
        }
    }
    if(N>1){
        store_primes[Total_Prime]=N;
        freq_primes[Total_Prime]=1;
        Total_Prime++;
    }
}
void Generate(int cur,int num)
{
    int i,val;

    if(cur==Total_Prime){
        store_divisor[ans++]=num;
    }
    else
    {
        val=1;
        for(i=0; i<=freq_primes[cur]; i++){
            Generate(cur+1,num*val);
            val=val*store_primes[cur];
        }
    }
}

set<int> tree[100005];
void update(int node,int l, int r, int pos, set<int> st){
    if(l>pos || r<pos) return ;
    for(auto it=st.begin();it!=st.end();it++){
        int val=*it;
        tree[node].insert(val);
    }
    if(l==r){
        return;
    }
    int left=node*2;
    int right=left+1;
    int mid=(l+r)/2;
    update(left,l,mid,pos,st);
    update(right,mid+1,r,pos,st);
}

set<int> query(int node,int l,int r, int m, int n)
{
    //cout<<"m: "<<m<<"  n: "<<n<<endl;
    //cout<<"l : "<<l<<"  r: "<<r<<endl;
    if(l>=m && r<=n){
        return tree[node];
    }
    set<int> st,st1,st2;
    if(r<m || l>n) return st;
    int left=node*2;
    int right=left+1;
    int mid=(l+r)/2;
    st1=query(left,l,mid,m,n);
    st2=query(right,mid+1,r,m,n);
    //cout<<node<<": "<<l<<"  -- "<<r<<endl;
    for(auto it=st1.begin();it!=st1.end();it++){
        int val=*it;
        //cout<<"st1: "<<val<<"\n";
        st.insert(val);
    }
    for(auto it=st2.begin();it!=st2.end();it++){
        int val=*it;
        //cout<<"st2: "<<val<<"\n";
        st.insert(val);
    }
    return tree[node]=st;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    seive();
    int n;
    cin>>n;
    map<int,int> mp;
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        divisor(a);
        ans=0;
        Generate(0,1);
        if(b==0){
            cout<<ans<<"\n";
        }
        else{
            int ct=0;
            set<int> st=query(1,1,n,i+1-b,i);
            //cout<<"set: "<<"\n";
            //for(auto it=st.begin();it!=st.end();it++){
           ////     cout<<*it<<"\n";
            //}
            for(int ii=0;ii<ans;ii++){
                if(st.find(store_divisor[ii])==st.end()) ct++;

            }
            cout<<ct<<"\n";
        }
        set<int> st;
        for(int ii=0;ii<ans;ii++){
            //cout<<store_divisor[ii]<<"\n";
            st.insert(store_divisor[ii]);
            update(1,1,n,i+1,st);
        }
        //cout<<"ans: "<<ans<<"\n";
    }

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int ara[100005];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    memset(ara,-1,sizeof ara);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        int a,b;
        cin>>a>>b;
        int x=sqrt(a);
        int ct=0;
        for(int j=1;j<=x;j++){
            if(a%j!=0) continue;
            //cout<<j<<"  - "<<ara[j]<<endl;
            if(ara[j]<i-b){
                ct++;

            }
            ara[j]=i;
            int k=a/j;
            //cout<<k<<"  - "<<ara[k]<<endl;
            if(k!=j){
                if(ara[k]<i-b){
                    ct++;

                }
            }
            ara[k]=i;

        }
        cout<<ct<<"\n";
    }

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int ara[100005];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    memset(ara,-1,sizeof ara);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        int a,b;
        cin>>a>>b;
        int x=sqrt(a);
        int ct=0;
        for(int j=1;j<=x;j++){
            if(a%j!=0) continue;
            if(ara[j]<i-b){
                ct++;
                ara[j]=i;
            }
            int k=a/j;
            if(k!=j){
                if(ara[k]<i-b){
                    ct++;
                    ara[k]=i;
                }
            }
        }
        cout<<ct<<"\n";
    }

}


#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <functional>
#include <numeric>
#include <utility>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cassert>
#include <climits>

using namespace std;

#define endl       '\n'
#define spc        printf(" ")
#define nln        printf("\n")                     ///printnewline
#define fast_IO    ios_base::sync_with_stdio(false);
#define Max(a,b,c) max(a,max(b,c))                  ///3 ta theke max
#define Min(a,b,c) min(a,min(b,c))                  ///3 ta theke min
#define sqr(x)     (x)*(x)

#define z(x)       fabs(x)<EPS
#define iqu(x,y)   z(fabs(x-y))

#define rep(i,a,b)  for(i=a;i<=b;i++)
#define rep0(i,n)   for(i=0;i<n;i++)
#define rep1(i,n)   for(i=1;i<=n;i++)               ///looping
#define rev(i,a,b)  for(i=a;i>=b;i--)
#define rev0(i,n)   for(i=n-1;i>=0;i--)
#define rev1(i,n)   for(i=n;i>=1;i--)
#define forstl(i,v) for(i=0;i<v.size();i++)
#define forit(it,v) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define all(p)      p.begin(),p.end()

#define SET(p)     memset(p,-1,sizeof(p))
#define CLR(p)     memset(p,0,sizeof(p))            ///memset
#define MEM(p,v)   memset(p,v,sizeof(p))

#define READ(f)    freopen(f, "r", stdin)           /// file
#define WRITE(f)   freopen(f, "w", stdout)

#define sz(c)      (int)c.size()
#define pb(x)      push_back(x)                     ///STL defines
#define mp(x,y)    make_pair(x,y)
#define xx         first
#define yy         second
#define _itr(v)    __typeof(v.begin())

#define LLI        long long int
#define i64        long long int
#define i64u       unsigned long long int
#define LLU        unsigned long long int
#define Double     long double
#define PI         acos(-1.0)                        ///PI er value

typedef vector<int>     vi;
typedef vector<i64>     vll;
typedef vector<string>  vs;
typedef pair<int, int>  pii;
typedef pair<i64, i64>  pll;

#define check(n, pos)  (bool)(n & (1LL<<(pos)))      ///CHECK
#define biton(n, pos)  (n | (1LL<<(pos)))            ///ON     }-bit opr.
#define bitoff(n, pos) (n & ~(1LL<<(pos)))           ///OFF

// reading and writing case
#define readcase  int cas,kase=0;CI(cas);while((cas--)&&(++kase))
#define printcase printf("Case %d:",kase)

//debugging infinite variable
bool deb_mode = 0;
#define debug(a...) if(deb_mode){cout<<"Line= "<<__LINE__<<" -> ";Dbug,a,#a;Dbug.printall();cout<<endl;}
class debugger {
    vector<string> vars;
public:
    template<typename T> debugger& operator , ( const T v ) { stringstream ss; ss << v, vars.push_back( ss.str() ); return *this; }
    void printall() { int j = 0, l = vars.size(); for( int i = 0; i < ( l - 1 ); i++ ) { if( i )cout << ", "; for( j; j < vars[l - 1].size(); j++ ) { if( vars[l - 1][j] == ',' ) {j++; break;} cout << vars[l - 1][j]; } cout << " = " << vars[i]; } vars.clear(); }
} Dbug;

///STL printing output stream overloading
template <typename T1, typename T2> inline ostream& operator << ( ostream& os, const pair<T1, T2>& p ) { return os << "(" << p.first << "," << p.second << ")"; }
template <typename T> inline ostream &operator << ( ostream & os, const vector<T>& v ) { bool first = true; os << "{"; for( unsigned int i = 0; i < v.size(); i++ ) { if( !first ) os << ","; os << v[i]; first = false; } return os << "}"; }
template <typename T> inline ostream &operator << (  ostream & os, const set<T>& v ) { bool first = true; os << "{"; for ( typename set<T>::const_iterator ii = v.begin(); ii != v.end(); ++ii ) { if( !first ) os << ","; os << *ii; first = false; } return os << "}"; }
template <typename T1, typename T2> inline ostream &operator << ( ostream & os, const map<T1, T2>& v ) { bool first = true; os << "{"; for ( typename map<T1, T2>::const_iterator ii = v.begin(); ii != v.end(); ++ii ) { if( !first ) os << ","; os << *ii ; first = false; } return os << "}"; }

template <typename T> void getarray( T a[], int b, int e ) { for( int i = b; i < e + b; i++ ) cin >> a[i]; }
template <typename T> void printarray( T a[], int b, int e ) { for( int i = b; i < e - 1 + b; i++ ) cout << a[i] << " "; if( e - 1 + b >= 0 ) cout << a[e - 1 + b] << endl; }
template <typename T> void printV( vector<T> v ) { int sz = v.size(); if( sz ) cout << v[0]; for( int i = 1; i < sz; i++ ) cout << " " << v[i]; nln; }

template <typename T> T gcd( T a, T b ) { if( b == 0 ) return a; return gcd( b, a % b ); }
template <typename T> T BigMod ( T b, T p, T m ) { if ( p == 0 ) return 1; if ( p % 2 == 0 ) { T s = BigMod( b, p / 2, m ); return ( ( s % m ) * ( s % m ) ) % m; } return ( ( b % m ) * ( BigMod( b, p - 1, m ) % m ) ) % m; }
template <typename T> T ModInv ( T b, T m ) { return BigMod( b, m - 2, m ); }

template<class T> inline void read( T &x ) { bool Minus = 0; char c; for( c = getchar(); c <= 32; c = getchar() ) ; if( c == '-' ) Minus = 1, c = getchar(); for( x = 0; c > 32; c = getchar() ) x = x * 10 + c - '0'; if( Minus ) x = -x; }
char getc() { char c; for( c = getchar(); c <= 32; c = getchar() ); return c; }  ///input char with buffering
int CI( int &_x ) { return scanf( "%d", &_x ); }
int CI( int &_x, int &_y ) { return scanf( "%d %d", &_x, &_y ); }
int CI( int &_x, int &_y, int &_z ) { return scanf( "%d %d %d", &_x, &_y, &_z ); }
int CI( int &_a, int &_b, int &_c, int &_d ) { return scanf( "%d %d %d %d", &_a, &_b, &_c, &_d ); }

template <class T> string toString( T n ) { ostringstream oss; oss << n; return oss.str(); }
int toInt( string s ) { int r = 0; istringstream sin( s ); sin >> r; return r; }
i64 toLong( string s ) { i64 r = 0; istringstream sin( s ); sin >> r; return r; }
bool isVowel( char ch ) { ch = tolower( ch ); if( ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' )return true; return false; }
bool isUpper( char c ) { return c >= 'A' && c <= 'Z'; }
bool isLower( char c ) { return c >= 'a' && c <= 'z'; }

int dr8[8] = { +1, -1, +0, +0, +1, -1, -1, +1};   ///8 direction move
int dc8[8] = { +0, +0, -1, +1, +1, +1, -1, -1};
int dr4[4] = { +0, +0, +1, -1};                   ///4 direction move
int dc4[4] = { -1, +1, +0, +0};                   ///or adjacent dir.
int kn8r[8] = { +1, +2, +2, +1, -1, -2, -2, -1};  ///knight moves
int kn8c[8] = { +2, +1, -1, -2, -2, -1, +1, +2};

const double EPS = 1e-9;                         ///constants
const int INF = ( 1 << 30 ) - 1;
const i64 LINF = ( 1ll << 62 ) - 1;
const int mod = ( int )1e9 + 7;
const int MAX = ( int )1e5;
///____________________________Main Coding Starts From Here________________________///

int X[MAX + 7], Y[MAX + 7];
int cut[MAX + 7];

int main() {
#ifndef ONLINE_JUDGE
//    READ("in.txt");
//    WRITE("out.txt");
    deb_mode = 1;
#endif
    if( deb_mode )
        srand( int( time( NULL ) ) );

    int i, j, k, l, n, m, q, a, b, c;
    cin >> n;
    rep1( i, n ) {
        CI( X[i], Y[i] );
        int t = max( 1, i - Y[i] );
        set< int > st;
        int lim = sqrt( X[i] ), cnt = 0;
        for( j = 1; j <= lim; j++ ) {
            if( X[i] % j == 0 ) {
                if( cut[j] < t ) {
                    cnt++;
                    cut[j] = i;
                }
                else cut[j] = i;
                if( j == lim && lim * lim == X[i] ) {
                    ;
                }
                else {
                    int p = X[i] / j;
                    if( cut[p] < t ) {
                        cnt++;
                        cut[p] = i;
                    }
                    else cut[p] = i;
                }
            }
        }
        cout << cnt << "\n";
    }

    if( deb_mode )
        cerr << "TIME = " << clock() << " ms" << endl;
    return 0;
}