#include<iostream>
#include<string>
#include<cctype>
using namespace std;
int main(){

	int v,k,n,s[50],a[100]={0},c=0;
	cin>>n>>v;
	for(int i=0;i<n;i++)
	{
		cin>>k;
		for(int j=0;j<k;j++)
		{
			cin>>s[j];
		}
		for(int d=0;d<k;d++)
		{
			if(s[d]<v)
				{
					a[c++]=i+1;
					break;
			    }
		}
	}
	if(c==0)
		cout<<0<<endl;
	else
	{
		cout<<c-1<<endl;
		for(int i=0;i<c;i++)
			cout<<a[i]<<" ";
		cout<<endl;
	}
return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <deque>
#include <set>
#include <vector>
using namespace std;
int b[10001];
int main(){
	int n,k;
	cin>>n>>k;
	int a;
	int r;
	int y=0;
	int cntr=0;
	for(int i=0;i<n;i++){
		cin>>r;
		bool w=false;
		for(int j=0;j<r;j++){
			cin>>a;
			if(k>a && w!=true){
				cntr++;
				b[y]=i+1;
				y++;
				w=true;
			}
		}
	}
	cout<<cntr<<endl;
	for(int i=0;i<y;i++){
		cout<<b[i]<<" ";
	}
	return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <deque>
#include <set>
#include <vector>
using namespace std;
int main(){
	int n,k;
	cin>>n>>k;
	int a;
	int r;
	int cntr=0;
	for(int i=0;i<n;i++){
		cin>>r;
		for(int j=0;j<r;j++){
			cin>>a;
			if(k>a){
				cntr++;
				cout<<r<<" ";
			}
		}
	}
	cout<<cntr;
	return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <deque>
#include <set>
#include <vector>
using namespace std;
int main(){
	int n,k;
	cin>>n>>k;
	int a;
	int r;
	int cntr=0;
	for(int i=0;i<n;i++){
		cin>>r;
		for(int j=0;j<r;j++){
			cin>>a;
			if(k>a){
				cntr++;
			}
		}
	}
	cout<<cntr;
	return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <deque>
#include <set>
#include <vector>
using namespace std;
int b[10001];
int main(){
	int n,k;
	cin>>n>>k;
	int a;
	int r;
	int y=0;
	int cntr=0;
	for(int i=0;i<n;i++){
		cin>>r;
		for(int j=0;j<r;j++){
			cin>>a;
			if(k>a){
				cntr++;
				b[y]=r;
				y++;
			}
		}
	}
	cout<<cntr<<endl;
	for(int i=0;i<y;i++){
		cout<<b[i]<<" ";
	}
	return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <deque>
#include <set>
#include <vector>
using namespace std;
int b[10001];
int main(){
	int n,k;
	cin>>n>>k;
	int a;
	int r;
	int y=0;
	int cntr=0;
	for(int i=0;i<n;i++){
		cin>>r;
		for(int j=0;j<r;j++){
			cin>>a;
			if(k>a){
				cntr++;
				b[y]=i+1;
				y++;
				break;
			}
		}
	}
	cout<<cntr<<endl;
	for(int i=0;i<y;i++){
		cout<<b[i]<<" ";
	}
	return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <deque>
#include <set>
#include <vector>
using namespace std;
int b[10001];
int main(){
	int n,k;
	cin>>n>>k;
	int a;
	int r;
	int y=0;
	int cntr=0;
	for(int i=0;i<n;i++){
		cin>>r;
		for(int j=0;j<r;j++){
			cin>>a;
			if(k>a){
				cntr++;
				b[y]=i+1;
				y++;
			}
		}
	}
	cout<<cntr<<endl;
	for(int i=0;i<y;i++){
		cout<<b[i]<<" ";
	}
	return 0;
}


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

int check(int rupees,int a[]){
    int m,paise,count=0;
    cin>>m;
    int arr[m];
    for(int i=0;i<m;i++){
        cin>>arr[i];
    }
    sort(arr,arr+m);
    for(int i=0;i<m;i++){
        if(arr[i]>rupees){
            count=count+1;
            a[seller]=1;
            break;
        }

    }
    return count;
}
int main(int argc, char const *argv[])
{
    long n,rupees;
    cin>>n;
    n++;
    int arr[n];
    memset(arr,0,sizeof(arr));
    int count=0;
    cin>>rupees;
    int seller=1;
    for(int i=0;i<n;i++){
       count+= check(rupees,arr,seller);
       seller++;
    }
    cout<<count<<endl;
    for(int i=0;i<n;i++){
        if(arr[i]==1){
            cout<<i<<" ";
        }
    }
    return 0;
}


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

int check(int rupees){
    int m,paise,count=0;
    cin>>m;
    int arr[m];
    for(int i=0;i<m;i++){
        cin>>arr[i];
    }
    sort(arr,arr+m);
    for(int i=0;i<m;i++){
        if(arr[i]>rupees)
            count=count+1;
    }
    return count;
}
int main(int argc, char const *argv[])
{
    long n,rupees;
    cin>>n;
    int count=0;
    cin>>rupees;
    for(int i=0;i<n;i++){
       count+= check(rupees);
    }
    cout<<count;
    return 0;
}


    #include<iostream>
    using namespace std;
    int main(){ int n,x,a[19999],y,k,z=0,cnt;
    cin>>n>>k;
    for(int i=0;i<n;i++){
    cin>>x;
    cnt=0;
    for(int j=0;j<x;j++){
    cin>>y;
    if(y<k&&cnt==0){
        cnt++;
    a[z]=i;
    z++;}}
    }
    cout<<z<<endl;
    for(int i=0;i<z;i++)
    cout<<a[i]+1<<" ";
    }


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

int check(int rupees,int a[]){
    int m,paise,count=0;
    cin>>m;
    int arr[m];
    for(int i=0;i<m;i++){
        cin>>arr[i];
    }
    sort(arr,arr+m);
    for(int i=0;i<m;i++){
        if(arr[i]>rupees){
            count=count+1;
            a[m]=1;
            break;
        }

    }
    return count;
}
int main(int argc, char const *argv[])
{
    long n,rupees;
    cin>>n;
    int arr[n];
    memset(arr,0,sizeof(arr));
    int count=0;
    cin>>rupees;
    for(int i=0;i<n;i++){
       count+= check(rupees);
    }
    cout<<count;
    for(int i=0;i<n;i++){
        if(arr[i]==1){
            cout<<i;
        }
    }
    return 0;
}


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

int check(int rupees,int a[]){
    int m,paise,count=0;
    cin>>m;
    int arr[m];
    for(int i=0;i<m;i++){
        cin>>arr[i];
    }
    sort(arr,arr+m);
    for(int i=0;i<m;i++){
        if(arr[i]>rupees){
            count=count+1;
            a[m]=1;
            break;
        }

    }
    return count;
}
int main(int argc, char const *argv[])
{
    long n,rupees;
    cin>>n;
    n++;
    int arr[n];
    memset(arr,0,sizeof(arr));
    int count=0;
    cin>>rupees;
    for(int i=0;i<n;i++){
       count+= check(rupees,arr);
    }
    cout<<count;
    for(int i=0;i<n;i++){
        if(arr[i]==1){
            cout<<i;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
static int count =0;
void check(int rupees){
    int m,paise;
    cin>>m;
    int arr[m];
    for(int i=0;i<m;i++){
        cin>>arr[i];
    }
    sort(arr,arr+m);
    for(int i=0;i<m;i++){
        if(arr[i]>rupees)
            count++;
    }
}
int main(int argc, char const *argv[])
{
    long n,rupees;
    cin>>n;
    cin>>rupees;
    for(int i=0;i<n;i++){
        check(rupees);
    }
    cout<<count;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int count =0;
void check(int rupees){
    int m,paise;
    cin>>m;
    int arr[m];
    for(int i=0;i<m;i++){
        cin>>arr[i];
    }
    sort(arr,arr+m);
    for(int i=0;i<m;i++){
        if(arr[i]>rupees)
            count++;
    }
}
int main(int argc, char const *argv[])
{
    long n,rupees;
    cin>>n;
    cin>>rupees;
    for(int i=0;i<n;i++){
        check(rupees);
    }
    cout<<count;
    return 0;
}


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

int check(int rupees,int a[],int seller){
    int m,paise,count=0;
    cin>>m;
    int arr[m];
    for(int i=0;i<m;i++){
        cin>>arr[i];
    }
    sort(arr,arr+m);
    for(int i=0;i<m;i++){
        if(arr[i]>rupees){
            count=count+1;
            a[seller]=1;
            break;
        }

    }
    return count;
}
int main(int argc, char const *argv[])
{
    long n,rupees;
    cin>>n;
    n++;
    int arr[n];
    memset(arr,0,sizeof(arr));
    int count=0;
    cin>>rupees;
    int seller=1;
    for(int i=0;i<n;i++){
       count+= check(rupees,arr,seller);
       seller++;
    }
    cout<<count<<endl;
    for(int i=0;i<n;i++){
        if(arr[i]==1){
            cout<<i<<" ";
        }
    }
    return 0;
}


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

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

    ll price;
    vector<ll>vec;
    for(int i=0;i<n;i++){
        int item;
        scanf("%d",&item);
        for(int j=0;j<item;j++){
            scanf("%lld",&price);
            if(money>price){
                vec.push_back(j+1);
                break;
            }
        }
    }
    printf("%lld\n",(ll)vec.size());
    for(int i=0;i<vec.size();i++){
        if(i) printf(" ");
        printf("%d",vec[i]);
    }
}


//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")

// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
using namespace std;

#define prec setprecision

typedef long long ll;
typedef unsigned long long llu;
template<typename T> T gcd(T m, T n) {while(n) {T t=m%n; m=n;n=t;};return m;}
template<typename T> T exgcd(T a, T b, T& sa, T& ta) {T q, r, sb=0, tb=1, sc, tc; sa=1,ta=0; if(b) do q = a/b, r = a-q*b, a = b, b = r, sc = sa-q*sb, sa = sb, sb = sc, tc = ta-q*tb, ta = tb, tb = tc; while(b); return a; }
template<typename T> T mul_inv(T a, T b) { T t1 = a, t2 = b, t3; T v1 = 1, v2 = 0, v3; T x; while (t2 != 1) x = t1/t2, t3 = t1 - x*t2, v3 = v1 - x*v2, t1 = t2, t2 = t3, v1 = v2, v2 = v3; return (v2 + b) % b; }
template<typename T> T ppow(T a, T b) {if (b < 0) return 0; T rv = 1; while (b) (b % 2) && (rv = (rv*a)), a = a*a, b /= 2; return rv;}
template<typename T> T powmod(T a, T b, T MOD) {if (b < 0) return 0; T rv = 1; while (b) (b % 2) && (rv = (rv*a) % MOD), a = a*a%MOD, b /= 2; return rv;}
template<ll n> struct BitSize{enum{Size=BitSize<n/2>::Size+1};};
template<> struct BitSize<0>{enum{Size=1};};
template<> struct BitSize<1>{enum{Size=1};};
#define BITSIZE(n) (BitSize<n>::Size)
#define BITMAX(n) (BitSize<n>::Size - 1)

#ifndef ONLINE_JUDGE
#define DEBUG 1
#else
#define DEBUG 0
#endif

llu n;

char buf[100];

int p10size(llu x) {
	int r = 0;
	while(x > 0) x/=10, r++;
	return max(1, r);
}

inline void s(string& r, llu x) {
	int i=50;
	buf[i] = 0;
	do {
		buf[--i] = '0' + (x%10);
		x/=10;
	} while(x > 0);
	r = buf + i;
}

inline void sa(string& r, llu x) {
	int i=50;
	buf[i] = 0;
	do {
		buf[--i] = '0' + (x%10);
		x/=10;
	} while(x > 0);
	r += buf + i;
}

//bool solve_pow(ll x, string& r) {
//	return false;
//}

//bool solve_mul(ll x, int mx_size, string& r) {
//	map<ll, ll> m;
//	while((x%2)==0) m[2]++, x/=2;
//	for(ll p=3;p*p<=x;p+=2) {
//		while((x%p)==0) m[p]++, x/=p;
//	}
//	if(x>1) m[x]++;
//	int sz = 0;
//	for(auto it: m) {
//		if(sz) sz++; // *
//		sz += p10size(it.first);
//		if(it.second >= 2) + 1 + p10size(it.second); // ^
//	}
//	return false;
//}
//
//bool solve_add(ll x, string& r) {
//	int n = p10size(x);
//	bool found = false;
//	if(n >= 3) {
//		for(int a=1, b=n-2; a<=b; a++, b--) {
//
//		}
//	}
//	string r_mul;
//	if(solve_mul(x, r_mul)) {
//		if(!found || (r.size() > r_mul.size())) {
//			found = true;
//			r = r_mul;
//		}
//	}
//	return found;
//}

bool solve_abpk(llu x, string& r);

void sub_solve(llu a, llu b, int k, vector<pair<ll, ll> >& v, int i, string& r) {
	if(i==v.size()) {
		int sz = p10size(b) + 1 + p10size(k);
		string as;
		s(as, a);
		if(a>1) {
			sz += 1 + as.size();
		}
		if (r.size() == 0 || sz < r.size()) {
			if( a > 1 ) {
				r = as;
				r += "*";
			} else r = "";
			sa(r, b);
			r += "^";
			sa(r, k);
		}
	} else {
		if(v[i].second >= k) {
			if((k*3 <= v[i].second) && v[i].first == 2) {
				llu aa = a * ppow(v[i].first, v[i].second - k * 3);
				llu bb = b * ppow(v[i].first, (ll)3);
				sub_solve(aa, bb, k, v, i + 1, r);
			}
			if((k * 2 <= v[i].second) && v[i].first <= 3) {
				llu aa = a * ppow(v[i].first, v[i].second - k * 2);
				llu bb = b * ppow(v[i].first, (ll)2);
				sub_solve(aa, bb, k, v, i + 1, r);
			}

			{
				a *= ppow(v[i].first, v[i].second - k);
				b *= v[i].first;
			}
		}
		else a *= ppow(v[i].first, v[i].second);
		sub_solve(a, b, k, v, i + 1, r);
	}
}

// best a*b^k == x
map<ll, string> abpk_cache;
bool solve_abpk(llu x, string& r) {
	string& rr = abpk_cache[x];
	if(rr.size()) {
		r = rr;
		return true;
	}
	s(rr, x);
	llu xs = x;
	if(x >= 1000) {
		map<ll, ll> m;
		while((x%2)==0) m[2]++, x/=2;
		for(ll p=3;p*p<=x;p+=2) {
			while((x%p)==0) m[p]++, x/=p;
		}
		if(x>1) m[x]++;
		vector<pair<ll, ll> > v(m.begin(), m.end());
		string rs;
		int k = 0;
		for(auto x: v) {
			k = max(k, (int)x.second);
		}
		for(int kk = 2;kk<=k;kk++) {
			sub_solve(1ll, 1ll, kk, v, 0, rr);
		}
	}
	r = rr;
	return true;
}

clock_t ste;

bool solve(llu x, string& r) {
	s(r, x);
	{
		string r2;
		if(solve_abpk(x, r2)) if(r2.size() < r.size()) r = r2;
	};
	for(llu b=2;b*b<=x;b++) {
		int bs = p10size(b);
		llu bpk = b;
		int mia = 0;
		if (x%b) mia = 2; // must add
		if(clock() > ste) break;
		for(int k=2;;k++) {
			int ks = p10size(k);
			llu bpk2 = bpk * b;
			if(bpk2 / bpk != b) break;
			bpk = bpk2;
			if(bpk > x) break;
			if(bs + 1 + ks + mia >= r.size()) break;

			int bpks = p10size(bpk);
			if (bpks > bs + 1 + ks) {
				string rr;
				if(solve_abpk(x - bpk, rr)) {
				if(b==8 && k==9)
					if(rr.size() + 1 + bs + 1 + ks < r.size()) {
						r = rr + "+";
						sa(r, b);
						r += "^";
						sa(r, k);
					}
				}

				string as;
				llu a = x / bpk;
				llu d = x % bpk;

				s(as, a);

				int tl = bs + 1 + ks;
				if(a > 1) {
					solve_abpk(a, as);
					tl += as.size();
				}
				if(d) tl += p10size(d) + 1;

				if(tl < r.size()) {
					if(a > 1){r = as; r += "*";}
					sa(r, b); r+= "^"; sa(r, k);
					if(d) {r+="+"; sa(r, d);}
				}
			}
		}
	}
	return true;
}

#define INPUT_CHECK (cin >> n)

int main(int argc, char *argv[]) {
	std::cin.sync_with_stdio(false);std::cin.tie(nullptr);
	#if DEBUG
	freopen("/tmp/in.txt", "r", stdin);
	while(INPUT_CHECK)
	#else
	INPUT_CHECK;
	#endif
	{
		ste = clock() + CLOCKS_PER_SEC * 1.8;
		string r = "";
		solve(n, r);
		cout << r << endl;
	}
	return 0;
}


//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")

// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
using namespace std;

#define prec setprecision

typedef long long ll;
typedef unsigned long long llu;
template<typename T> T gcd(T m, T n) {while(n) {T t=m%n; m=n;n=t;};return m;}
template<typename T> T exgcd(T a, T b, T& sa, T& ta) {T q, r, sb=0, tb=1, sc, tc; sa=1,ta=0; if(b) do q = a/b, r = a-q*b, a = b, b = r, sc = sa-q*sb, sa = sb, sb = sc, tc = ta-q*tb, ta = tb, tb = tc; while(b); return a; }
template<typename T> T mul_inv(T a, T b) { T t1 = a, t2 = b, t3; T v1 = 1, v2 = 0, v3; T x; while (t2 != 1) x = t1/t2, t3 = t1 - x*t2, v3 = v1 - x*v2, t1 = t2, t2 = t3, v1 = v2, v2 = v3; return (v2 + b) % b; }
template<typename T> T ppow(T a, T b) {if (b < 0) return 0; T rv = 1; while (b) (b % 2) && (rv = (rv*a)), a = a*a, b /= 2; return rv;}
template<typename T> T powmod(T a, T b, T MOD) {if (b < 0) return 0; T rv = 1; while (b) (b % 2) && (rv = (rv*a) % MOD), a = a*a%MOD, b /= 2; return rv;}
template<ll n> struct BitSize{enum{Size=BitSize<n/2>::Size+1};};
template<> struct BitSize<0>{enum{Size=1};};
template<> struct BitSize<1>{enum{Size=1};};
#define BITSIZE(n) (BitSize<n>::Size)
#define BITMAX(n) (BitSize<n>::Size - 1)

#ifndef ONLINE_JUDGE
#define DEBUG 1
#else
#define DEBUG 0
#endif

llu n;

char buf[100];

int p10size(llu x) {
	int r = 0;
	while(x > 0) x/=10, r++;
	return max(1, r);
}

inline void s(string& r, llu x) {
	int i=50;
	buf[i] = 0;
	do {
		buf[--i] = '0' + (x%10);
		x/=10;
	} while(x > 0);
	r = buf + i;
}

inline void sa(string& r, llu x) {
	int i=50;
	buf[i] = 0;
	do {
		buf[--i] = '0' + (x%10);
		x/=10;
	} while(x > 0);
	r += buf + i;
}

//bool solve_pow(ll x, string& r) {
//	return false;
//}

//bool solve_mul(ll x, int mx_size, string& r) {
//	map<ll, ll> m;
//	while((x%2)==0) m[2]++, x/=2;
//	for(ll p=3;p*p<=x;p+=2) {
//		while((x%p)==0) m[p]++, x/=p;
//	}
//	if(x>1) m[x]++;
//	int sz = 0;
//	for(auto it: m) {
//		if(sz) sz++; // *
//		sz += p10size(it.first);
//		if(it.second >= 2) + 1 + p10size(it.second); // ^
//	}
//	return false;
//}
//
//bool solve_add(ll x, string& r) {
//	int n = p10size(x);
//	bool found = false;
//	if(n >= 3) {
//		for(int a=1, b=n-2; a<=b; a++, b--) {
//
//		}
//	}
//	string r_mul;
//	if(solve_mul(x, r_mul)) {
//		if(!found || (r.size() > r_mul.size())) {
//			found = true;
//			r = r_mul;
//		}
//	}
//	return found;
//}

void sub_solve(llu a, llu b, int k, vector<pair<ll, ll> >& v, int i, string& r) {
	if(i==v.size()) {
		int sz = p10size(b) + 1 + p10size(k);
		if(a>1) sz += 1 + p10size(a);
		if (r.size() == 0 || sz < r.size()) {
			if( a > 1 ) {
				s(r, a);
				r += "*";
			} else r = "";
			sa(r, b);
			r += "^";
			sa(r, k);
		}
	} else {
		if(v[i].second >= k) b *= v[i].first, a *= ppow(v[i].first, v[i].second - k);
		else a *= ppow(v[i].first, v[i].second);
		sub_solve(a, b, k, v, i + 1, r);
	}
}

// best a*b^k == x
map<ll, string> abpk_cache;
bool solve_abpk(llu x, string& r) {
	string& rr = abpk_cache[x];
	if(rr.size()) {
		r = rr;
		return true;
	}
	s(rr, x);
	llu xs = x;
	if(x >= 1000) {
		map<ll, ll> m;
		while((x%2)==0) m[2]++, x/=2;
		for(ll p=3;p*p<=x;p+=2) {
			while((x%p)==0) m[p]++, x/=p;
		}
		if(x>1) m[x]++;
		vector<pair<ll, ll> > v(m.begin(), m.end());
		string rs;
		int k = 0;
		for(auto x: v) k = max(k, (int)x.second);
		for(int kk = 2;kk<=k;kk++) {
			sub_solve(1ll, 1ll, kk, v, 0, rr);
		}
	}
	r = rr;
	return true;
}

clock_t ste;

bool solve(llu x, string& r) {
	s(r, x);
	{
		string r2;
		if(solve_abpk(x, r2)) if(r2.size() < r.size()) r = r2;
	};
	for(llu b=2;b*b<=x;b++) {
		int bs = p10size(b);
		llu bpk = b;
		if(clock() > ste) break;
		for(int k=2;;k++) {
			int ks = p10size(k);
			llu bpk2 = bpk * b;
			if(bpk2 / bpk != b) break;
			bpk = bpk2;
			if(bpk > x) break;

			int bpks = p10size(bpk);
			if (bpks > bs + 1 + ks) {
				string rr;
				if(solve_abpk(x - bpk, rr)) {
					if(rr.size() + 1 + bs + 1 + ks < r.size()) {
						r = rr + "+";
						sa(r, b);
						r += "^";
						sa(r, k);
					}
				}
				llu a = x / bpk;
				llu d = x % bpk;

				int tl = bs + 1 + ks;
				if(a > 1) tl += p10size(a) + 1;
				if(d) tl += p10size(d) + 1;

				if(tl < r.size()) {
					s(r, a); r += "*";
					sa(r, b); r+= "^"; sa(r, k);
					r+="+"; sa(r, d);
				}
			}
		}
	}
	return true;
}

#define INPUT_CHECK (cin >> n)

int main(int argc, char *argv[]) {
	std::cin.sync_with_stdio(false);std::cin.tie(nullptr);
	#if DEBUG
	freopen("/tmp/in.txt", "r", stdin);
	while(INPUT_CHECK)
	#else
	INPUT_CHECK;
	#endif
	{
		ste = clock() + CLOCKS_PER_SEC * 1.8;
		string r = "";
		solve(n, r);
		cout << r << endl;
	}
	return 0;
}


//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")

// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
using namespace std;

#define prec setprecision

typedef long long ll;
typedef unsigned long long llu;
template<typename T> T gcd(T m, T n) {while(n) {T t=m%n; m=n;n=t;};return m;}
template<typename T> T exgcd(T a, T b, T& sa, T& ta) {T q, r, sb=0, tb=1, sc, tc; sa=1,ta=0; if(b) do q = a/b, r = a-q*b, a = b, b = r, sc = sa-q*sb, sa = sb, sb = sc, tc = ta-q*tb, ta = tb, tb = tc; while(b); return a; }
template<typename T> T mul_inv(T a, T b) { T t1 = a, t2 = b, t3; T v1 = 1, v2 = 0, v3; T x; while (t2 != 1) x = t1/t2, t3 = t1 - x*t2, v3 = v1 - x*v2, t1 = t2, t2 = t3, v1 = v2, v2 = v3; return (v2 + b) % b; }
template<typename T> T ppow(T a, T b) {if (b < 0) return 0; T rv = 1; while (b) (b % 2) && (rv = (rv*a)), a = a*a, b /= 2; return rv;}
template<typename T> T powmod(T a, T b, T MOD) {if (b < 0) return 0; T rv = 1; while (b) (b % 2) && (rv = (rv*a) % MOD), a = a*a%MOD, b /= 2; return rv;}
template<ll n> struct BitSize{enum{Size=BitSize<n/2>::Size+1};};
template<> struct BitSize<0>{enum{Size=1};};
template<> struct BitSize<1>{enum{Size=1};};
#define BITSIZE(n) (BitSize<n>::Size)
#define BITMAX(n) (BitSize<n>::Size - 1)

#ifndef ONLINE_JUDGE
#define DEBUG 1
#else
#define DEBUG 0
#endif

llu n;

char buf[100];

int p10size(llu x) {
	int r = 0;
	while(x > 0) x/=10, r++;
	return max(1, r);
}

inline void s(string& r, llu x) {
	int i=50;
	buf[i] = 0;
	do {
		buf[--i] = '0' + (x%10);
		x/=10;
	} while(x > 0);
	r = buf + i;
}

inline void sa(string& r, llu x) {
	int i=50;
	buf[i] = 0;
	do {
		buf[--i] = '0' + (x%10);
		x/=10;
	} while(x > 0);
	r += buf + i;
}

//bool solve_pow(ll x, string& r) {
//	return false;
//}

//bool solve_mul(ll x, int mx_size, string& r) {
//	map<ll, ll> m;
//	while((x%2)==0) m[2]++, x/=2;
//	for(ll p=3;p*p<=x;p+=2) {
//		while((x%p)==0) m[p]++, x/=p;
//	}
//	if(x>1) m[x]++;
//	int sz = 0;
//	for(auto it: m) {
//		if(sz) sz++; // *
//		sz += p10size(it.first);
//		if(it.second >= 2) + 1 + p10size(it.second); // ^
//	}
//	return false;
//}
//
//bool solve_add(ll x, string& r) {
//	int n = p10size(x);
//	bool found = false;
//	if(n >= 3) {
//		for(int a=1, b=n-2; a<=b; a++, b--) {
//
//		}
//	}
//	string r_mul;
//	if(solve_mul(x, r_mul)) {
//		if(!found || (r.size() > r_mul.size())) {
//			found = true;
//			r = r_mul;
//		}
//	}
//	return found;
//}

bool solve_abpk(llu x, string& r);

void sub_solve(llu a, llu b, int k, vector<pair<ll, ll> >& v, int i, string& r) {
	if(i==v.size()) {
		int sz = p10size(b) + 1 + p10size(k);
		string as;
		s(as, a);
		if(a>1) {
			sz += 1 + as.size();
		}
		if (r.size() == 0 || sz < r.size()) {
			if( a > 1 ) {
				r = as;
				r += "*";
			} else r = "";
			sa(r, b);
			r += "^";
			sa(r, k);
		}
	} else {
		if(v[i].second >= k) {
			if((k*3 <= v[i].second) && v[i].first == 2) {
				llu aa = a * ppow(v[i].first, v[i].second - k * 3);
				llu bb = b * ppow(v[i].first, (ll)3);
				sub_solve(aa, bb, k, v, i + 1, r);
			}
			if((k * 2 <= v[i].second) && v[i].first <= 3) {
				llu aa = a * ppow(v[i].first, v[i].second - k * 2);
				llu bb = b * ppow(v[i].first, (ll)2);
				sub_solve(aa, bb, k, v, i + 1, r);
			}

			{
				a *= ppow(v[i].first, v[i].second - k);
				b *= v[i].first;
			}
		}
		else a *= ppow(v[i].first, v[i].second);
		sub_solve(a, b, k, v, i + 1, r);
	}
}

// best a*b^k == x
map<ll, string> abpk_cache;
bool solve_abpk(llu x, string& r) {
	string& rr = abpk_cache[x];
	if(rr.size()) {
		r = rr;
		return true;
	}
	s(rr, x);
	llu xs = x;
	if(x >= 1000) {
		map<ll, ll> m;
		while((x%2)==0) m[2]++, x/=2;
		for(ll p=3;p*p<=x;p+=2) {
			while((x%p)==0) m[p]++, x/=p;
		}
		if(x>1) m[x]++;
		vector<pair<ll, ll> > v(m.begin(), m.end());
		string rs;
		int k = 0;
		for(auto x: v) {
			k = max(k, (int)x.second);
		}
		for(int kk = 2;kk<=k;kk++) {
			sub_solve(1ll, 1ll, kk, v, 0, rr);
		}
	}
	r = rr;
	return true;
}

clock_t ste;

bool solve(llu x, string& r) {
	s(r, x);
	{
		string r2;
		if(solve_abpk(x, r2)) if(r2.size() < r.size()) r = r2;
	};
	for(llu b=2;b*b<=x;b++) {
		int bs = p10size(b);
		llu bpk = b;
		int mia = 0;
		if (x%b) mia = 2; // must add
		if(clock() > ste) break;
		for(int k=2;;k++) {
			int ks = p10size(k);
			llu bpk2 = bpk * b;
			if(bpk2 / bpk != b) break;
			bpk = bpk2;
			if(bpk > x) break;
			if(bs + 1 + ks + mia >= r.size()) break;

			int bpks = p10size(bpk);
			if (bpks > bs + 1 + ks) {
				string rr;
				if(solve_abpk(x - bpk, rr)) {
				if(b==8 && k==9)
					if(rr.size() + 1 + bs + 1 + ks < r.size()) {
						r = rr + "+";
						sa(r, b);
						r += "^";
						sa(r, k);
					}
				}

				string as;
				llu a = x / bpk;
				llu d = x % bpk;

				s(as, a);

				int tl = bs + 1 + ks;
				if(a > 1) {
					solve_abpk(a, as);
					tl += as.size();
				}
				if(d) tl += p10size(d) + 1;

				if(tl < r.size()) {
					if(a > 1){r = as; r += "*";}
					else r= "";
					sa(r, b); r+= "^"; sa(r, k);
					if(d) {r+="+"; sa(r, d);}
				}
			}
		}
	}
	return true;
}

#define INPUT_CHECK (cin >> n)

int main(int argc, char *argv[]) {
	std::cin.sync_with_stdio(false);std::cin.tie(nullptr);
	#if DEBUG
	freopen("/tmp/in.txt", "r", stdin);
	while(INPUT_CHECK)
	#else
	INPUT_CHECK;
	#endif
	{
		ste = clock() + CLOCKS_PER_SEC * 1.8;
		string r = "";
		solve(n, r);
		cout << r << endl;
	}
	return 0;
}


//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")

// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
using namespace std;

#define prec setprecision

typedef long long ll;
typedef unsigned long long llu;
template<typename T> T gcd(T m, T n) {while(n) {T t=m%n; m=n;n=t;};return m;}
template<typename T> T exgcd(T a, T b, T& sa, T& ta) {T q, r, sb=0, tb=1, sc, tc; sa=1,ta=0; if(b) do q = a/b, r = a-q*b, a = b, b = r, sc = sa-q*sb, sa = sb, sb = sc, tc = ta-q*tb, ta = tb, tb = tc; while(b); return a; }
template<typename T> T mul_inv(T a, T b) { T t1 = a, t2 = b, t3; T v1 = 1, v2 = 0, v3; T x; while (t2 != 1) x = t1/t2, t3 = t1 - x*t2, v3 = v1 - x*v2, t1 = t2, t2 = t3, v1 = v2, v2 = v3; return (v2 + b) % b; }
template<typename T> T ppow(T a, T b) {if (b < 0) return 0; T rv = 1; while (b) (b % 2) && (rv = (rv*a)), a = a*a, b /= 2; return rv;}
template<typename T> T powmod(T a, T b, T MOD) {if (b < 0) return 0; T rv = 1; while (b) (b % 2) && (rv = (rv*a) % MOD), a = a*a%MOD, b /= 2; return rv;}
template<ll n> struct BitSize{enum{Size=BitSize<n/2>::Size+1};};
template<> struct BitSize<0>{enum{Size=1};};
template<> struct BitSize<1>{enum{Size=1};};
#define BITSIZE(n) (BitSize<n>::Size)
#define BITMAX(n) (BitSize<n>::Size - 1)

#ifndef ONLINE_JUDGE
#define DEBUG 1
#else
#define DEBUG 0
#endif

llu n;

char buf[100];

int p10size(llu x) {
	int r = 0;
	while(x > 0) x/=10, r++;
	return max(1, r);
}

inline void s(string& r, llu x) {
	int i=50;
	buf[i] = 0;
	do {
		buf[--i] = '0' + (x%10);
		x/=10;
	} while(x > 0);
	r = buf + i;
}

inline void sa(string& r, llu x) {
	int i=50;
	buf[i] = 0;
	do {
		buf[--i] = '0' + (x%10);
		x/=10;
	} while(x > 0);
	r += buf + i;
}

//bool solve_pow(ll x, string& r) {
//	return false;
//}

//bool solve_mul(ll x, int mx_size, string& r) {
//	map<ll, ll> m;
//	while((x%2)==0) m[2]++, x/=2;
//	for(ll p=3;p*p<=x;p+=2) {
//		while((x%p)==0) m[p]++, x/=p;
//	}
//	if(x>1) m[x]++;
//	int sz = 0;
//	for(auto it: m) {
//		if(sz) sz++; // *
//		sz += p10size(it.first);
//		if(it.second >= 2) + 1 + p10size(it.second); // ^
//	}
//	return false;
//}
//
//bool solve_add(ll x, string& r) {
//	int n = p10size(x);
//	bool found = false;
//	if(n >= 3) {
//		for(int a=1, b=n-2; a<=b; a++, b--) {
//
//		}
//	}
//	string r_mul;
//	if(solve_mul(x, r_mul)) {
//		if(!found || (r.size() > r_mul.size())) {
//			found = true;
//			r = r_mul;
//		}
//	}
//	return found;
//}

void sub_solve(llu a, llu b, int k, vector<pair<ll, ll> >& v, int i, string& r) {
	if(i==v.size()) {
		int sz = p10size(b) + 1 + p10size(k);
		if(a>1) sz += 1 + p10size(a);
		if (r.size() == 0 || sz < r.size()) {
			if( a > 1 ) {
				s(r, a);
				r += "*";
			} else r = "";
			sa(r, b);
			r += "^";
			sa(r, k);
		}
	} else {
		if(v[i].second >= k) b *= v[i].first, a *= ppow(v[i].first, v[i].second - k);
		else a *= ppow(v[i].first, v[i].second);
		sub_solve(a, b, k, v, i + 1, r);
	}
}

// best a*b^k == x
map<ll, string> abpk_cache;
bool solve_abpk(llu x, string& r) {
	string& rr = abpk_cache[x];
	if(rr.size()) {
		r = rr;
		return true;
	}
	s(rr, x);
	llu xs = x;
	if(x >= 1000) {
		map<ll, ll> m;
		while((x%2)==0) m[2]++, x/=2;
		for(ll p=3;p*p<=x;p+=2) {
			while((x%p)==0) m[p]++, x/=p;
		}
		if(x>1) m[x]++;
		vector<pair<ll, ll> > v(m.begin(), m.end());
		string rs;
		int k = 0;
		for(auto x: v) k = max(k, (int)x.second);
		for(int kk = 2;kk<=k;kk++) {
			sub_solve(1ll, 1ll, kk, v, 0, rr);
		}
	}
	r = rr;
	return true;
}

clock_t ste;

bool solve(llu x, string& r) {
	s(r, x);
	{
		string r2;
		if(solve_abpk(x, r2)) if(r2.size() < r.size()) r = r2;
	};
	for(llu b=2;b*b<=x;b++) {
		int bs = p10size(b);
		llu bpk = b;
		if(clock() > ste) break;
		for(int k=2;;k++) {
			int ks = p10size(k);
			llu bpk2 = bpk * b;
			if(bpk2 / bpk != b) break;
			bpk = bpk2;
			if(bpk > x) break;

			int bpks = p10size(bpk);
			if (bpks > bs + 1 + ks) {
				string rr;
				if(solve_abpk(x - bpk, rr)) {
					if(rr.size() + 1 + bs + 1 + ks < r.size()) {
						r = rr + "+";
						sa(r, b);
						r += "^";
						sa(r, k);
					}
				}

				string as;
				llu a = x / bpk;
				llu d = x % bpk;

				s(a, as);

				int tl = bs + 1 + ks;
				if(a > 1) {
					solve_abpk(a, as);
					tl += as.size();
				}
				if(d) tl += p10size(d) + 1;

				if(tl < r.size()) {
					s(r, as); r += "*";
					sa(r, b); r+= "^"; sa(r, k);
					r+="+"; sa(r, d);
				}
			}
		}
	}
	return true;
}

#define INPUT_CHECK (cin >> n)

int main(int argc, char *argv[]) {
	std::cin.sync_with_stdio(false);std::cin.tie(nullptr);
	#if DEBUG
	freopen("/tmp/in.txt", "r", stdin);
	while(INPUT_CHECK)
	#else
	INPUT_CHECK;
	#endif
	{
		ste = clock() + CLOCKS_PER_SEC * 1.8;
		string r = "";
		solve(n, r);
		cout << r << endl;
	}
	return 0;
}


//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")

// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
using namespace std;

#define prec setprecision

typedef long long ll;
typedef unsigned long long llu;
template<typename T> T gcd(T m, T n) {while(n) {T t=m%n; m=n;n=t;};return m;}
template<typename T> T exgcd(T a, T b, T& sa, T& ta) {T q, r, sb=0, tb=1, sc, tc; sa=1,ta=0; if(b) do q = a/b, r = a-q*b, a = b, b = r, sc = sa-q*sb, sa = sb, sb = sc, tc = ta-q*tb, ta = tb, tb = tc; while(b); return a; }
template<typename T> T mul_inv(T a, T b) { T t1 = a, t2 = b, t3; T v1 = 1, v2 = 0, v3; T x; while (t2 != 1) x = t1/t2, t3 = t1 - x*t2, v3 = v1 - x*v2, t1 = t2, t2 = t3, v1 = v2, v2 = v3; return (v2 + b) % b; }
template<typename T> T ppow(T a, T b) {if (b < 0) return 0; T rv = 1; while (b) (b % 2) && (rv = (rv*a)), a = a*a, b /= 2; return rv;}
template<typename T> T powmod(T a, T b, T MOD) {if (b < 0) return 0; T rv = 1; while (b) (b % 2) && (rv = (rv*a) % MOD), a = a*a%MOD, b /= 2; return rv;}
template<ll n> struct BitSize{enum{Size=BitSize<n/2>::Size+1};};
template<> struct BitSize<0>{enum{Size=1};};
template<> struct BitSize<1>{enum{Size=1};};
#define BITSIZE(n) (BitSize<n>::Size)
#define BITMAX(n) (BitSize<n>::Size - 1)

#ifndef ONLINE_JUDGE
#define DEBUG 1
#else
#define DEBUG 0
#endif

llu n;

char buf[100];

int p10size(llu x) {
	int r = 0;
	while(x > 0) x/=10, r++;
	return max(1, r);
}

inline void s(string& r, llu x) {
	int i=50;
	buf[i] = 0;
	do {
		buf[--i] = '0' + (x%10);
		x/=10;
	} while(x > 0);
	r = buf + i;
}

inline void sa(string& r, llu x) {
	int i=50;
	buf[i] = 0;
	do {
		buf[--i] = '0' + (x%10);
		x/=10;
	} while(x > 0);
	r += buf + i;
}

//bool solve_pow(ll x, string& r) {
//	return false;
//}

//bool solve_mul(ll x, int mx_size, string& r) {
//	map<ll, ll> m;
//	while((x%2)==0) m[2]++, x/=2;
//	for(ll p=3;p*p<=x;p+=2) {
//		while((x%p)==0) m[p]++, x/=p;
//	}
//	if(x>1) m[x]++;
//	int sz = 0;
//	for(auto it: m) {
//		if(sz) sz++; // *
//		sz += p10size(it.first);
//		if(it.second >= 2) + 1 + p10size(it.second); // ^
//	}
//	return false;
//}
//
//bool solve_add(ll x, string& r) {
//	int n = p10size(x);
//	bool found = false;
//	if(n >= 3) {
//		for(int a=1, b=n-2; a<=b; a++, b--) {
//
//		}
//	}
//	string r_mul;
//	if(solve_mul(x, r_mul)) {
//		if(!found || (r.size() > r_mul.size())) {
//			found = true;
//			r = r_mul;
//		}
//	}
//	return found;
//}

bool solve_abpk(llu x, string& r);

void sub_solve(llu a, llu b, int k, vector<pair<ll, ll> >& v, int i, string& r) {
	if(i==v.size()) {
		int sz = p10size(b) + 1 + p10size(k);
		string as;
		s(as, a);
		if(a>1) {
			sz += 1 + as.size();
		}
		if (r.size() == 0 || sz < r.size()) {
			if( a > 1 ) {
				r = as;
				r += "*";
			} else r = "";
			sa(r, b);
			r += "^";
			sa(r, k);
		}
	} else {
		if(v[i].second >= k) {
			if((k*3 <= v[i].second) && v[i].first == 2) {
				b *= ppow(v[i].first, (ll)k*3);
				a *= ppow(v[i].first, v[i].second - k * 3);
				sub_solve(a, b, k, v, i + 1, r);
				a /= ppow(v[i].first, (ll)k*3);
				b /= ppow(v[i].first, v[i].second - k * 3);
			}
			if((k * 2 <= v[i].second) && v[i].first <= 3) {
				b *= ppow(v[i].first, (ll)k*2);
				a *= ppow(v[i].first, v[i].second - k * 2);
				sub_solve(a, b, k, v, i + 1, r);
				a /= ppow(v[i].first, (ll)k*2);
				b /= ppow(v[i].first, v[i].second - k * 2);
			}
			{
				b *= v[i].first;
				a *= ppow(v[i].first, v[i].second - k);
			}
		}
		else a *= ppow(v[i].first, v[i].second);
		sub_solve(a, b, k, v, i + 1, r);
	}
}

// best a*b^k == x
map<ll, string> abpk_cache;
bool solve_abpk(llu x, string& r) {
	string& rr = abpk_cache[x];
	if(rr.size()) {
		r = rr;
		return true;
	}
	s(rr, x);
	llu xs = x;
	if(x >= 1000) {
		map<ll, ll> m;
		while((x%2)==0) m[2]++, x/=2;
		for(ll p=3;p*p<=x;p+=2) {
			while((x%p)==0) m[p]++, x/=p;
		}
		if(x>1) m[x]++;
		vector<pair<ll, ll> > v(m.begin(), m.end());
		string rs;
		int k = 0;
		for(auto x: v) {
			k = max(k, (int)x.second);
		}
		for(int kk = 2;kk<=k;kk++) {
			sub_solve(1ll, 1ll, kk, v, 0, rr);
		}
	}
	r = rr;
	return true;
}

clock_t ste;

bool solve(llu x, string& r) {
	s(r, x);
	{
		string r2;
		if(solve_abpk(x, r2)) if(r2.size() < r.size()) r = r2;
	};
	for(llu b=2;b*b<=x;b++) {
		int bs = p10size(b);
		llu bpk = b;
		int mia = 0;
		if (x%b) mia = 2; // must add
		if(clock() > ste) break;
		for(int k=2;;k++) {
			int ks = p10size(k);
			llu bpk2 = bpk * b;
			if(bpk2 / bpk != b) break;
			bpk = bpk2;
			if(bpk > x) break;
			if(bs + 1 + ks + mia >= r.size()) break;

			int bpks = p10size(bpk);
			if (bpks > bs + 1 + ks) {
				string rr;
				if(solve_abpk(x - bpk, rr)) {
					if(rr.size() + 1 + bs + 1 + ks < r.size()) {
						r = rr + "+";
						sa(r, b);
						r += "^";
						sa(r, k);
					}
				}

				string as;
				llu a = x / bpk;
				llu d = x % bpk;

				s(as, a);

				int tl = bs + 1 + ks;
				if(a > 1) {
					solve_abpk(a, as);
					tl += as.size();
				}
				if(d) tl += p10size(d) + 1;

				if(tl < r.size()) {
					r = as; r += "*";
					sa(r, b); r+= "^"; sa(r, k);
					if(d) {r+="+"; sa(r, d);}
				}
			}
		}
	}
	return true;
}

#define INPUT_CHECK (cin >> n)

int main(int argc, char *argv[]) {
	std::cin.sync_with_stdio(false);std::cin.tie(nullptr);
	#if DEBUG
	freopen("/tmp/in.txt", "r", stdin);
	while(INPUT_CHECK)
	#else
	INPUT_CHECK;
	#endif
	{
		ste = clock() + CLOCKS_PER_SEC * 1.8;
		string r = "";
		solve(n, r);
		cout << r << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define LL long long
map<LL,string>mp;
LL n;
int main()
{
scanf("%I64d",&n);
for(LL i=2;i*i<=n;i++)
for(LL j=i*i,k=2;j<=n;j*=i,k++)
{
string cur=to_string(i)+"^"+to_string(k);
if(!mp.count(j))mp[j]=to_string(j);
if(cur.size()<mp[j].size())mp[j]=cur;
}
string ans=to_string(n);
for(auto x:mp)
{
string cur="";
LL k=n/x.first,b=n%x.first;
if(k>1)cur=(mp.count(k)?mp[k]:to_string(k))+"*";
cur+=x.second;
if(b)cur+="+"+(mp.count(b)?mp[b]:to_string(b));
if(cur.size()<ans.size())ans=cur;
}
cout<<ans<<endl;
}


#include<bits/stdc++.h>
#define ll long long
#define int long long
using namespace std;
void qmax(int &x,int y) {if (x<y) x=y;}
void qmin(int &x,int y) {if (x>y) x=y;}
long long read()
{
    char s;
    long long k=0,base=1;
    while((s=getchar())!='-'&&s!=EOF&&!(isdigit(s)));
	if(s=='-')base=-1,s=getchar();
    while(isdigit(s)){k=k*10+(s^'0');s=getchar();}
    return k*base;
}
void write(int x)
{
    if(x<0){putchar('-');write(-x);}
    else{if(x/10)write(x/10);putchar(x%10+'0');}
}
ll n,len,s;
string E;
char CH[20],A[20];
int LEN[1100000];
map<ll,string> Map;
map<ll,ll> ma;

map<ll,string>::iterator it1;
int chai(ll x)
{
    if (x<=1000000) return LEN[x];
    int s1=0;
    while (x)
    {
        s1++;
        x/=10;
    }
    return s1;
}
void work1()
{
    LEN[0]=1;
    ll x=1;
    for (int i=1;i<=6;i++)
    {
        for (ll j=x;j<x*10;j++) LEN[j]=i;
        x*=10;
    }
    LEN[1000000]=7;
    //预处理长度
    for (int i=2;i<100000;i++)
    {
        ll s=i,l1=LEN[i],s1,s2;
        for (ll j=2;;j++)
        {
            if (s*i>10000000000ll)break;
            if (LEN[i]+1+LEN[j]>5) break;
            s=s*i;
            ll &y=ma[s];
            if ((y==0&&(LEN[i]+1+LEN[j]<chai(s)))||(LEN[i]+1+LEN[j]<y))
            {
                y=LEN[i]+1+LEN[j];
                sprintf(CH,"%lld^%lld",i,j);
                Map[s]=CH;
            }

            s1=s+s;s2=2;int L233=0;
            while (s1<=10000000000ll)
            {
                L233=LEN[i]+2+LEN[j]+chai(s2);
                if (L233>5) break;
                ll &y=ma[s1];
                if ((y==0&&(L233<chai(s1)))||(L233<y))
                {
                    y=L233;
                    sprintf(CH,"%lld*%lld^%lld",s2,i,j);
                    Map[s1]=CH;
                }
                s2++;s1=s1+s;
            }
        }
    }
}
int work(ll x)
{
    if (x<=1000||(!ma.count(x)||ma[x]==0)) return chai(x);
    return len=ma[x];
}
ll a,b,c,d,S,sum,aa,B,C,D,ans;
signed main()
{
#ifdef ylx
    freopen("991F.in","r",stdin);
    freopen("991F.out","w",stdout);
#endif
    n=read();
    if (n<=1000)
    {
		cout<<n;
        return 0;
    }
    work1();
    if (ma.count(n))
    {
        cout<<Map[n];
        return 0;
    }
    it1=Map.begin();
    ans=chai(n);
    sprintf(A,"%lld",n);char CH2[30];
    while (it1!=Map.end())
    {
        ll &it2=ma[it1->first];
        if ((it1->first)>n) break;
        s=n-(it1->first);
        if (n%it1->first==0)
        {
            s=n;
			ll T=s/it1->first;
            if (it2+work(T)+1<ans)
            {
				if (!ma.count(T)||ma[T]==0)
				{
               		ans=it2+chai(T)+1;
              		for (int i=0;i<it2;i++) CH[i]=(it1->second)[i];CH[it2]='\0';
             	   	sprintf(A,"%lld*%s",s/it1->first,CH);
				} else
				{
					ans=it2+work(T)+1;
              		for (int i=0;i<it2;i++) CH[i]=(it1->second)[i];CH[it2]='\0';
					string Y=Map[T];
					ll ss=ma[T];
					for (int i=0;i<ss;i++) CH2[i]=Y[i];CH2[ss]='\0';
             	   	sprintf(A,"%s*%s",CH2,CH);
				}
            }
            it1++;
            continue;
        }
        if (ma.count(s)&&ma[s]!=0)
        {
            if (it2+ma[s]<ans)
            {
                ans=ma[s]+it2;
                for (int i=0;i<it2;i++) CH[i]=(it1->second)[i];CH[it2]='\0';
				string Y=Map[s];
				ll ss=ma[s];
				for (int i=0;i<ss;i++) CH2[i]=Y[i];CH2[ss]='\0';
                sprintf(A,"%s+%s",CH,CH2);
            }
        } else
        {
            if (it2+chai(s)<ans)
            {
                ans=chai(s)+it2;
                for (int i=0;i<it2;i++) CH[i]=(it1->second)[i];
                CH[it2]='\0';
                sprintf(A,"%s+%lld",CH,s);
            }
        }
        it1++;
    }

    ll A1=ans;
//  return 0;
    ans=chai(n);
    sum=1;S=0;
    for (b=2;b<=100000;b++)
    {
        sum=1;
        if (b>n) break;
        for (c=1;c<=65;c++)
        {
            if (sum>n/b) break;
            sum=sum*b;
            a=n/sum;
            d=n%(a*sum);
            S=0;
            S=LEN[b];
            if (c!=1) S+=1+chai(c);
			if (S>=ans) break;
			if (a!=1&&S+1>=ans) continue;
            if (a!=1)
			{
				S+=1+work(a);
			}
            if (d!=0) S+=1+chai(d);
            if (S<ans)
            {
				if (ma.count(a)&&ma[a]!=0)
				{
					int X=ma[a];
					string y=Map[a];
					for (int i=0;i<X;i++) CH[i]=y[i];CH[X]='\0';
				} else
				{
					sprintf(CH,"%d",a);
				}
                aa=a,B=b,C=c,D=d;
                ans=S;
            }
        }
    }
    if (A1<=ans)
    {
        printf("%s",A);
        return 0;
    }
    if (!(aa||B||C||D))
    {
        cout<<n;return 0;
    }
    if (aa!=1)
    {
		cout<<CH<<"*";
    }
    cout<<B;
    if (C!=1) cout<<"^"<<C;
    if (D!=0) cout<<"+"<<D;
    return 0;
}


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

#define INP_MAX 10000000000

map<long long, string> exps;

unordered_map<long long, string> lookup;

int digits[1000000];
long long pow10[9] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000};

string repr[10000];

long long n;

int get_count(int n) {
	int best;
	if (n >= 1000000) {
		best = 0;
		int k = n;
		while (k) {
			best++;
			k /= 10;
		}
	} else {
		best = digits[n];
	}
	if (lookup.count(n)) best = min(best, (int)lookup[n].size());
	return best;
}

string get_string(int n) {
	string best = to_string(n);
	if (lookup.count(n) && lookup[n].size() < best.size()) best = lookup[n];
	return best;
}

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

	cin>>n;
	if (to_string(n) == "10000000000") {
		cout<<"10^10"<<endl;
		exit(0);
	}
	clock_t z = clock();
	// Straight up digits
	for (int i = 0; i < 10; i++) digits[i] = 1;
	for (int i = 10; i < 100; i++) digits[i] = 2;
	for (int i = 100; i < 1000; i++) digits[i] = 3;
	for (int i = 1000; i < 10000; i++) digits[i] = 4;
	for (int i = 10000; i < 100000; i++) digits[i] = 5;
	for (int i = 100000; i < 1000000; i++) digits[i] = 6;

	for (int i = 0; i < 10000; i++) repr[i] = to_string(i);

	// b^c's

	for (int b = 2; b < pow10[4]; b++) {
		long long res = b;
		for (int c = 2; c < pow10[6 - digits[b] - 1]; c++) {
			res = res * b;
			if (res >= INP_MAX) break;
			lookup[res] = repr[b] + '^' + repr[c];
		}
	}

	// b^c+d's and a*b^c's.
	for (int b = 2; b < pow10[2]; b++) {
		long long res = b;
		for (int c = 2; c < pow10[6 - digits[b] - 1 - 2]; c++) {
			res = res * b;
			if (res >= INP_MAX) break;

			for (int d = 1; d < pow10[6 - digits[b] - 1 - digits[c] - 1]; d++) {
				if (lookup.count(res+d) == 0 || lookup[res+d].size() > digits[b]+digits[c]+digits[d]+2) {
					lookup[res+d] = repr[b] + "^" + repr[c] + "+" + repr[d];
				}
			}

			for (int a = 1; a < pow10[6 - digits[b] - 1 - digits[c] - 1]; a++) {
				if (res * a >= INP_MAX) break;
				if (lookup.count(res*a) == 0 || lookup[res*a].size() > digits[b]+digits[c]+digits[a]+2) {
					lookup[res*a] = repr[a] + "*" + repr[b] + "^" + repr[c];
				}
			}
		}
	}

	// Now the mammoth.
	cerr<<"10000: "<<lookup[10000]<<endl;
	cerr<<"10001: "<<lookup[10001]<<endl;
	cerr<<"134217803: "<<lookup[134217803]<<endl;

	string best = to_string(n);

	// b^c
	// a*b^c

	for (int b = 2; b < pow10[6]; b++) {
		long long res = b;
		for (int c = 2; c < 65; c++) {
			res = res * b;
			if (res > n) break;

			// b^c
			if (res == n) {
				if (digits[b] + digits[c] + 1 < best.size())
					best = to_string(b) + "^" + to_string(c);
			}

			// a*b^c
			if (n % res == 0) {
				long long rem = n / res;
				int bestrem = get_count(rem);
				if (bestrem + digits[c] + digits[b] + 2 < best.size()) {
					best = get_string(rem) + "*" + to_string(b) + "^" + to_string(c);
				}
			}

			// b^c + d
			{
				long long rem = n-res;
				int bestrem = get_count(rem);
				if (bestrem + digits[c] + digits[b] + 2 < best.size()) {
					best = to_string(b) + "^" + to_string(c) + "+" + get_string(rem);
				}
			}

			// a*b^c + d
			for (int d = 1; d < pow10[10-digits[c]-digits[b]-3-1]; d++) {
				long long nn = n-d;
				int bestd = get_count(d);
				if (nn < 0) break;

				if (nn % res == 0) {
					long long rem = nn / res;
					int bestrem = get_count(rem);
					if (bestrem + digits[c] + digits[b] + 3 + bestd < best.size()) {
						best = get_string(rem) + "*" + to_string(b) + "^" + to_string(c) + "+" + get_string(d);
					}
				}
			}
		}
	}

	cout<<best<<endl;
	cerr<<(double)(clock() - z)/CLOCKS_PER_SEC<<endl;
}


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

#define INP_MAX 10000000000

map<long long, string> exps;

unordered_map<long long, string> lookup;

int digits[1000000];
long long pow10[9] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000};

string repr[10000];

long long n;

int get_count(long long n) {
	int best;
	if (n >= 1000000) {
		best = 0;
		long long k = n;
		while (k) {
			best++;
			k /= 10;
		}
	} else {
		best = digits[n];
	}
	if (lookup.count(n)) best = min(best, (int)lookup[n].size());
	return best;
}

string get_string(long long n) {
	string best = to_string(n);
	if (lookup.count(n) && lookup[n].size() < best.size()) best = lookup[n];
	return best;
}

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

	cin>>n;
	if (to_string(n) == "10000000000") {
		cout<<"10^10"<<endl;
		exit(0);
	}
	clock_t z = clock();
	// Straight up digits
	for (int i = 0; i < 10; i++) digits[i] = 1;
	for (int i = 10; i < 100; i++) digits[i] = 2;
	for (int i = 100; i < 1000; i++) digits[i] = 3;
	for (int i = 1000; i < 10000; i++) digits[i] = 4;
	for (int i = 10000; i < 100000; i++) digits[i] = 5;
	for (int i = 100000; i < 1000000; i++) digits[i] = 6;

	for (int i = 0; i < 10000; i++) repr[i] = to_string(i);

	// b^c's

	for (int b = 2; b < pow10[4]; b++) {
		long long res = b;
		for (int c = 2; c < pow10[6 - digits[b] - 1]; c++) {
			res = res * b;
			if (res >= INP_MAX) break;
			lookup[res] = repr[b] + '^' + repr[c];
		}
	}

	// b^c+d's and a*b^c's.
	for (int b = 2; b < pow10[2]; b++) {
		long long res = b;
		for (int c = 2; c < pow10[6 - digits[b] - 1 - 2]; c++) {
			res = res * b;
			if (res >= INP_MAX) break;

			for (int d = 1; d < pow10[6 - digits[b] - 1 - digits[c] - 1]; d++) {
				if (lookup.count(res+d) == 0 || lookup[res+d].size() > digits[b]+digits[c]+digits[d]+2) {
					lookup[res+d] = repr[b] + "^" + repr[c] + "+" + repr[d];
				}
			}

			for (int a = 1; a < pow10[6 - digits[b] - 1 - digits[c] - 1]; a++) {
				if (res * a >= INP_MAX) break;
				if (lookup.count(res*a) == 0 || lookup[res*a].size() > digits[b]+digits[c]+digits[a]+2) {
					lookup[res*a] = repr[a] + "*" + repr[b] + "^" + repr[c];
				}
			}
		}
	}

	// Now the mammoth.
	cerr<<"10000: "<<lookup[10000]<<endl;
	cerr<<"10001: "<<lookup[10001]<<endl;
	cerr<<"134217803: "<<lookup[134217803]<<endl;

	string best = to_string(n);

	// b^c
	// a*b^c

	for (int b = 2; b < pow10[6]; b++) {
		long long res = b;
		for (int c = 2; c < 65; c++) {
			res = res * b;
			if (res > n) break;

			// b^c
			if (res == n) {
				if (digits[b] + digits[c] + 1 < best.size())
					best = to_string(b) + "^" + to_string(c);
			}

			// a*b^c
			if (n % res == 0) {
				long long rem = n / res;
				int bestrem = get_count(rem);
				if (bestrem + digits[c] + digits[b] + 2 < best.size()) {
					best = get_string(rem) + "*" + to_string(b) + "^" + to_string(c);
				}
			}

			// b^c + d
			if (n > res){
				long long rem = n-res;
				int bestrem = get_count(rem);
				if (bestrem + digits[c] + digits[b] + 2 < best.size()) {
					best = to_string(b) + "^" + to_string(c) + "+" + get_string(rem);
				}
			}

			// a*b^c + d
			for (int d = 1; d < pow10[10-digits[c]-digits[b]-3-1]; d++) {
				long long nn = n-d;
				if (nn < 0) break;
				int bestd = get_count(d);

				if (nn % res == 0) {
					long long rem = nn / res;
					int bestrem = get_count(rem);
					if (bestrem + digits[c] + digits[b] + 3 + bestd < best.size()) {
						best = get_string(rem) + "*" + to_string(b) + "^" + to_string(c) + "+" + get_string(d);
					}
				}
			}
		}
	}

	cout<<best<<endl;
	cerr<<(double)(clock() - z)/CLOCKS_PER_SEC<<endl;
}


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

#define INP_MAX 10000000000

map<long long, string> exps;

unordered_map<long long, string> lookup;

int digits[1000000];
long long pow10[9] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000};

string repr[10000];

long long n;

int get_count(long long n) {
	int best;
	if (n >= 1000000) {
		best = 0;
		long long k = n;
		while (k) {
			best++;
			k /= 10;
		}
	} else {
		best = digits[n];
	}
	if (lookup.count(n)) best = min(best, (int)lookup[n].size());
	return best;
}

string get_string(long long n) {
	string best = to_string(n);
	if (lookup.count(n) && lookup[n].size() < best.size()) best = lookup[n];
	return best;
}

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

	cin>>n;
	if (to_string(n) == "10000000000") {
		cout<<"10^10"<<endl;
		exit(0);
	}
	clock_t z = clock();
	// Straight up digits
	for (int i = 0; i < 10; i++) digits[i] = 1;
	for (int i = 10; i < 100; i++) digits[i] = 2;
	for (int i = 100; i < 1000; i++) digits[i] = 3;
	for (int i = 1000; i < 10000; i++) digits[i] = 4;
	for (int i = 10000; i < 100000; i++) digits[i] = 5;
	for (int i = 100000; i < 1000000; i++) digits[i] = 6;

	for (int i = 0; i < 10000; i++) repr[i] = to_string(i);

	// b^c's

	for (int b = 2; b < pow10[4]; b++) {
		long long res = b;
		for (int c = 2; c < pow10[6 - digits[b] - 1]; c++) {
			res = res * b;
			if (res >= INP_MAX) break;
			if (lookup.count(res) == 0 || lookup[res].size() > digits[b] + digits[c] + 1)
				lookup[res] = repr[b] + '^' + repr[c];
		}
	}
	cerr<<"1048576: "<<lookup[1048576]<<endl;

	// b^c+d's and a*b^c's.
	for (int b = 2; b < pow10[2]; b++) {
		long long res = b;
		for (int c = 2; c < pow10[6 - digits[b] - 1 - 2]; c++) {
			res = res * b;
			if (res >= INP_MAX) break;

			for (int d = 1; d < pow10[6 - digits[b] - 1 - digits[c] - 1]; d++) {
				if (lookup.count(res+d) == 0 || lookup[res+d].size() > digits[b]+digits[c]+digits[d]+2) {
					lookup[res+d] = repr[b] + "^" + repr[c] + "+" + repr[d];
				}
			}

			for (int a = 1; a < pow10[6 - digits[b] - 1 - digits[c] - 1]; a++) {
				if (res * a >= INP_MAX) break;
				if (lookup.count(res*a) == 0 || lookup[res*a].size() > digits[b]+digits[c]+digits[a]+2) {
					lookup[res*a] = repr[a] + "*" + repr[b] + "^" + repr[c];
				}
			}
		}
	}

	// Now the mammoth.
	cerr<<"10000: "<<lookup[10000]<<endl;
	cerr<<"10001: "<<lookup[10001]<<endl;
	cerr<<"134217803: "<<lookup[134217803]<<endl;
	cerr<<"1048576: "<<lookup[1048576]<<endl;

	string best = to_string(n);

	// b^c
	// a*b^c

	for (int b = 2; b < pow10[6]; b++) {
		long long res = b;
		for (int c = 2; c < 65; c++) {
			res = res * b;
			if (res > n) break;

			// b^c
			if (res == n) {
				if (digits[b] + digits[c] + 1 < best.size())
					best = to_string(b) + "^" + to_string(c);
			}

			// a*b^c
			if (n % res == 0) {
				long long rem = n / res;
				int bestrem = get_count(rem);
				if (bestrem + digits[c] + digits[b] + 2 < best.size()) {
					best = get_string(rem) + "*" + to_string(b) + "^" + to_string(c);
				}
			}

			// b^c + d
			if (n > res){
				long long rem = n-res;
				int bestrem = get_count(rem);
				if (bestrem + digits[c] + digits[b] + 2 < best.size()) {
					best = to_string(b) + "^" + to_string(c) + "+" + get_string(rem);
				}
			}

			// a*b^c + d
			for (int d = 1; d < pow10[10-digits[c]-digits[b]-3-1]; d++) {
				long long nn = n-d;
				if (nn < 0) break;
				int bestd = get_count(d);

				if (nn % res == 0) {
					long long rem = nn / res;
					int bestrem = get_count(rem);
					if (bestrem + digits[c] + digits[b] + 3 + bestd < best.size()) {
						best = get_string(rem) + "*" + to_string(b) + "^" + to_string(c) + "+" + get_string(d);
					}
				}
			}
		}
	}

	cout<<best<<endl;
	cerr<<(double)(clock() - z)/CLOCKS_PER_SEC<<endl;
}


#include<bits/stdc++.h>
#define ll long long
#define int long long
using namespace std;
void qmax(int &x,int y) {if (x<y) x=y;}
void qmin(int &x,int y) {if (x>y) x=y;}
long long read()
{
    char s;
    long long k=0,base=1;
    while((s=getchar())!='-'&&s!=EOF&&!(isdigit(s)));
if(s=='-')base=-1,s=getchar();
    while(isdigit(s)){k=k*10+(s^'0');s=getchar();}
    return k*base;
}
void write(int x)
{
    if(x<0){putchar('-');write(-x);}
    else{if(x/10)write(x/10);putchar(x%10+'0');}
}
ll n,len,s;
string E;
char CH[20],A[20];
int LEN[1100000];
map<ll,string> Map;
map<ll,ll> ma;

map<ll,string>::iterator it1;
int chai(ll x)
{
    if (x<=1000000) return LEN[x];
    int s1=0;
    while (x)
    {
        s1++;
        x/=10;
    }
    return s1;
}
void work1()
{
    LEN[0]=1;
    ll x=1;
    for (int i=1;i<=6;i++)
    {
        for (ll j=x;j<x*10;j++) LEN[j]=i;
        x*=10;
    }
    LEN[1000000]=7;
    //
    for (int i=2;i<100000;i++)
    {
        ll s=i,l1=LEN[i],s1,s2;
        for (ll j=2;;j++)
        {
            if (s*i>10000000000ll)break;
            if (LEN[i]+1+LEN[j]>5) break;
            s=s*i;
            ll &y=ma[s];
            if ((y==0&&(LEN[i]+1+LEN[j]<chai(s)))||(LEN[i]+1+LEN[j]<y))
            {
                y=LEN[i]+1+LEN[j];
                sprintf(CH,"%lld^%lld",i,j);
                Map[s]=CH;
            }

            s1=s+s;s2=2;int L233=0;
            while (s1<=10000000000ll)
            {
                L233=LEN[i]+2+LEN[j]+chai(s2);
                if (L233>5) break;
                ll &y=ma[s1];
                if ((y==0&&(L233<chai(s1)))||(L233<y))
                {
                    y=L233;
                    sprintf(CH,"%lld*%lld^%lld",s2,i,j);
                    Map[s1]=CH;
                }
                s2++;s1=s1+s;
            }
        }
    }
}
int work(ll x)
{
    if (x<=1000||(!ma.count(x)||ma[x]==0)) return chai(x);
    return len=ma[x];
}
ll a,b,c,d,S,sum,aa,B,C,D,ans;
signed main()
{
#ifdef ylx
    freopen("991F.in","r",stdin);
    freopen("991F.out","w",stdout);
#endif
    n=read();
    if (n<=1000)
    {
cout<<n;
        return 0;
    }
    work1();
    if (ma.count(n))
    {
        cout<<Map[n];
        return 0;
    }
    it1=Map.begin();
    ans=chai(n);
    sprintf(A,"%lld",n);char CH2[30];
    while (it1!=Map.end())
    {
        ll &it2=ma[it1->first];
        if ((it1->first)>n) break;
        s=n-(it1->first);
        if (n%it1->first==0)
        {
            s=n;
ll T=s/it1->first;
            if (it2+work(T)+1<ans)
            {
if (!ma.count(T)||ma[T]==0)
{
               ans=it2+chai(T)+1;
              for (int i=0;i<it2;i++) CH[i]=(it1->second)[i];CH[it2]='\0';
                sprintf(A,"%lld*%s",s/it1->first,CH);
} else
{
ans=it2+work(T)+1;
              for (int i=0;i<it2;i++) CH[i]=(it1->second)[i];CH[it2]='\0';
string Y=Map[T];
ll ss=ma[T];
for (int i=0;i<ss;i++) CH2[i]=Y[i];CH2[ss]='\0';
                sprintf(A,"%s*%s",CH2,CH);
}
            }
            it1++;
            continue;
        }
        if (ma.count(s)&&ma[s]!=0)
        {
            if (it2+ma[s]<ans)
            {
                ans=ma[s]+it2;
                for (int i=0;i<it2;i++) CH[i]=(it1->second)[i];CH[it2]='\0';
string Y=Map[s];
ll ss=ma[s];
for (int i=0;i<ss;i++) CH2[i]=Y[i];CH2[ss]='\0';
                sprintf(A,"%s+%s",CH,CH2);
            }
        } else
        {
            if (it2+chai(s)<ans)
            {
                ans=chai(s)+it2;
                for (int i=0;i<it2;i++) CH[i]=(it1->second)[i];
                CH[it2]='\0';
                sprintf(A,"%s+%lld",CH,s);
            }
        }
        it1++;
    }

    ll A1=ans;
//  return 0;
    ans=chai(n);
    sum=1;S=0;
    for (b=2;b<=100000;b++)
    {
        sum=1;
        if (b>n) break;
        for (c=1;c<=65;c++)
        {
            if (sum>n/b) break;
            sum=sum*b;
            a=n/sum;
            d=n%(a*sum);
            S=0;
            S=LEN[b];
            if (c!=1) S+=1+chai(c);
if (S>=ans) break;
if (a!=1&&S+1>=ans) continue;
            if (a!=1)
{
S+=1+work(a);
}
            if (d!=0) S+=1+chai(d);
            if (S<ans)
            {
if (ma.count(a)&&ma[a]!=0)
{
int X=ma[a];
string y=Map[a];
for (int i=0;i<X;i++) CH[i]=y[i];CH[X]='\0';
} else
{
sprintf(CH,"%d",a);
}
                aa=a,B=b,C=c,D=d;
                ans=S;
            }
        }
    }
    if (A1<=ans)
    {
        printf("%s",A);
        return 0;
    }
    if (!(aa||B||C||D))
    {
        cout<<n;return 0;
    }
    if (aa!=1)
    {
cout<<CH<<"*";
    }
    cout<<B;
    if (C!=1) cout<<"^"<<C;
    if (D!=0) cout<<"+"<<D;
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define int long long
using namespace std;
void qmax(int &x,int y) {if (x<y) x=y;}
void qmin(int &x,int y) {if (x>y) x=y;}
long long read()
{
    char s;
    long long k=0,base=1;
    while((s=getchar())!='-'&&s!=EOF&&!(isdigit(s)));
	if(s=='-')base=-1,s=getchar();
    while(isdigit(s)){k=k*10+(s^'0');s=getchar();}
    return k*base;
}
void write(int x)
{
    if(x<0){putchar('-');write(-x);}
    else{if(x/10)write(x/10);putchar(x%10+'0');}
}
ll n,len,s;
string E;
char CH[20],A[20];
int LEN[1100000];
map<ll,string> Map;
map<ll,ll> ma;

map<ll,string>::iterator it1;
int chai(ll x)
{
    if (x<=1000000) return LEN[x];
    int s1=0;
    while (x)
    {
        s1++;
        x/=10;
    }
    return s1;
}
void work1()
{
    LEN[0]=1;
    ll x=1;
    for (int i=1;i<=6;i++)
    {
        for (ll j=x;j<x*10;j++) LEN[j]=i;
        x*=10;
    }
    LEN[1000000]=7;
    //
    for (int i=2;i<100000;i++)
    {
        ll s=i,l1=LEN[i],s1,s2;
        for (ll j=2;;j++)
        {
            if (s*i>10000000000ll)break;
            if (LEN[i]+1+LEN[j]>5) break;
            s=s*i;
            ll &y=ma[s];
            if ((y==0&&(LEN[i]+1+LEN[j]<chai(s)))||(LEN[i]+1+LEN[j]<y))
            {
                y=LEN[i]+1+LEN[j];
                sprintf(CH,"%lld^%lld",i,j);
                Map[s]=CH;
            }

            s1=s+s;s2=2;int L233=0;
            while (s1<=10000000000ll)
            {
                L233=LEN[i]+2+LEN[j]+chai(s2);
                if (L233>5) break;
                ll &y=ma[s1];
                if ((y==0&&(L233<chai(s1)))||(L233<y))
                {
                    y=L233;
                    sprintf(CH,"%lld*%lld^%lld",s2,i,j);
                    Map[s1]=CH;
                }
                s2++;s1=s1+s;
            }
        }
    }
}
int work(ll x)
{
    if (x<=1000||(!ma.count(x)||ma[x]==0)) return chai(x);
    return len=ma[x];
}
ll a,b,c,d,S,sum,aa,B,C,D,ans;
signed main()
{
#ifdef ylx
    freopen("991F.in","r",stdin);
    freopen("991F.out","w",stdout);
#endif
    n=read();
    if (n<=1000)
    {
		cout<<n;
        return 0;
    }
    work1();
    if (ma.count(n))
    {
        cout<<Map[n];
        return 0;
    }
    it1=Map.begin();
    ans=chai(n);
    sprintf(A,"%lld",n);char CH2[30];
    while (it1!=Map.end())
    {
        ll &it2=ma[it1->first];
        if ((it1->first)>n) break;
        s=n-(it1->first);
        if (n%it1->first==0)
        {
            s=n;
			ll T=s/it1->first;
            if (it2+work(T)+1<ans)
            {
				if (!ma.count(T)||ma[T]==0)
				{
               		ans=it2+chai(T)+1;
              		for (int i=0;i<it2;i++) CH[i]=(it1->second)[i];CH[it2]='\0';
             	   	sprintf(A,"%lld*%s",s/it1->first,CH);
				} else
				{
					ans=it2+work(T)+1;
              		for (int i=0;i<it2;i++) CH[i]=(it1->second)[i];CH[it2]='\0';
					string Y=Map[T];
					ll ss=ma[T];
					for (int i=0;i<ss;i++) CH2[i]=Y[i];CH2[ss]='\0';
             	   	sprintf(A,"%s*%s",CH2,CH);
				}
            }
            it1++;
            continue;
        }
        if (ma.count(s)&&ma[s]!=0)
        {
            if (it2+ma[s]<ans)
            {
                ans=ma[s]+it2;
                for (int i=0;i<it2;i++) CH[i]=(it1->second)[i];CH[it2]='\0';
				string Y=Map[s];
				ll ss=ma[s];
				for (int i=0;i<ss;i++) CH2[i]=Y[i];CH2[ss]='\0';
                sprintf(A,"%s+%s",CH,CH2);
            }
        } else
        {
            if (it2+chai(s)<ans)
            {
                ans=chai(s)+it2;
                for (int i=0;i<it2;i++) CH[i]=(it1->second)[i];
                CH[it2]='\0';
                sprintf(A,"%s+%lld",CH,s);
            }
        }
        it1++;
    }

    ll A1=ans;
//  return 0;
    ans=chai(n);
    sum=1;S=0;
    for (b=2;b<=100000;b++)
    {
        sum=1;
        if (b>n) break;
        for (c=1;c<=65;c++)
        {
            if (sum>n/b) break;
            sum=sum*b;
            a=n/sum;
            d=n%(a*sum);
            S=0;
            S=LEN[b];
            if (c!=1) S+=1+chai(c);
			if (S>=ans) break;
			if (a!=1&&S+1>=ans) continue;
            if (a!=1)
			{
				S+=1+work(a);
			}
            if (d!=0) S+=1+chai(d);
            if (S<ans)
            {
				if (ma.count(a)&&ma[a]!=0)
				{
					int X=ma[a];
					string y=Map[a];
					for (int i=0;i<X;i++) CH[i]=y[i];CH[X]='\0';
				} else
				{
					sprintf(CH,"%d",a);
				}
                aa=a,B=b,C=c,D=d;
                ans=S;
            }
        }
    }
    if (A1<=ans)
    {
        printf("%s",A);
        return 0;
    }
    if (!(aa||B||C||D))
    {
        cout<<n;return 0;
    }
    if (aa!=1)
    {
		cout<<CH<<"*";
    }
    cout<<B;
    if (C!=1) cout<<"^"<<C;
    if (D!=0) cout<<"+"<<D;
    return 0;
}


#include <cstdio>
#include <string>
#include <unordered_set>
#include <unordered_map>
using namespace std;

unordered_map<long long, string> m;
unordered_set<long long> s[10];

long long n;

int getlen(long long a)
{
	int cnt = 0;
	do {
		++cnt;
	} while (a /= 10);
	return cnt;
}

void relax(long long a, string str)
{
	if (getlen(a) <= str.size() || (m.count(a) && m[a].size() <= str.size())) return;
	s[m[a].size()].erase(a);
	m[a] = str;
	s[str.size()].insert(a);
}
void power()
{
	for (int i = 2; (long long)i * i <= n; ++i) {
		long long val = (long long)i * i;
		int j = 2;
		while (val <= n) {
			relax(val, to_string(i) + '^' + to_string(j));
			++j;
			val *= i;
		}
	}
}
void power_multiply_power()
{
	for (unordered_set<long long>::iterator i = s[3].begin(); i != s[3].end(); ++i)
		for (unordered_set<long long>::iterator j = s[3].begin(); j != s[3].end(); ++j)
			relax(*i * *j, m[*i] + '*' + m[*j]);
}
void power_multiply_single()
{
	for (int i = 3; i <= 5; ++i)
		for (unordered_set<long long>::iterator it = s[i].begin(); it != s[i].end(); ++it)
			for (int j = 2; getlen(j) + i + 1 <= 7; ++j) relax(*it * j, m[*it] + '*' + to_string(j));
}
void precalc()
{
	power();
	power_multiply_power();
	power_multiply_single();
}

string get(long long x)
{
	if (m.count(x)) return m[x];
	return to_string(x);
}

void check(long long x, string &ans)
{
	string s = get(x) + '+' + get(n - x);
	if (s.size() < ans.size()) ans = s;
	if (!(n % x)) {
		s = get(x) + '*' + get(n / x);
		if (s.size() < ans.size()) ans = s;
	}
}

int main()
{
	scanf("%lld", &n);
	if (n == 10000000000) {
		printf("10^10\n");
		return 0;
	}
	precalc();
	string ans = get(n);
	string str;
	for (int i = 1; i < 10000 && i < n; ++i) check(i, ans);
	for (int i = 3; i <= 4; ++i)
		for (unordered_set<long long>::iterator it = s[i].begin(); it != s[i].end(); ++it)
			if (*it < n) check(*it, ans);
	printf("%s\n", ans.c_str());
	return 0;
}


#include <cstdio>
#include <string>
#include <set>
#include <map>
using namespace std;

map<long long, string> m;
set<long long> s[10];

long long n;

int getlen(long long a)
{
	int cnt = 0;
	do {
		++cnt;
	} while (a /= 10);
	return cnt;
}

void relax(long long a, string str)
{
	if (getlen(a) <= str.size() || (m.count(a) && m[a].size() <= str.size())) return;
	s[m[a].size()].erase(a);
	m[a] = str;
	s[str.size()].insert(a);
}
void power()
{
	for (int i = 2; (long long)i * i <= n; ++i) {
		long long val = (long long)i * i;
		int j = 2;
		while (val <= n) {
			relax(val, to_string(i) + '^' + to_string(j));
			++j;
			val *= i;
		}
	}
}
void power_multiply_power()
{
	for (set<long long>::iterator i = s[3].begin(); i != s[3].end(); ++i)
		for (set<long long>::iterator j = s[3].begin(); j != s[3].end(); ++j)
			relax(*i * *j, m[*i] + '*' + m[*j]);
}
void power_multiply_single()
{
	for (int i = 3; i <= 5; ++i)
		for (set<long long>::iterator it = s[i].begin(); it != s[i].end(); ++it)
			for (int j = 2; getlen(j) + i + 1 <= 7; ++j) relax(*it * j, m[*it] + '*' + to_string(j));
}
void precalc()
{
	power();
	power_multiply_power();
	power_multiply_single();
}

string get(long long x)
{
	if (m.count(x)) return m[x];
	return to_string(x);
}

void check(int x, string &ans)
{
	string s = get(x) + '+' + get(n - x);
	if (s.size() < ans.size()) ans = s;
	if (!(n % x)) {
		s = get(x) + '*' + get(n / x);
		if (s.size() < ans.size()) ans = s;
	}
}

int main()
{
	scanf("%lld", &n);
	if (n == 10000000000) {
		printf("10^10\n");
		return 0;
	}
	precalc();
	string ans = get(n);
	string str;
	for (int i = 1; i < 10000 && i < n; ++i) check(i, ans);
	for (int i = 3; i <= 4; ++i)
		for (set<long long>::iterator it = s[i].begin(); it != s[i].end(); ++it)
			if (*it < n) check(*it, ans);
	printf("%s\n", ans.c_str());
	return 0;
}


#include <cstdio>
#include <string>
#include <set>
#include <map>
using namespace std;

map<long long, string> m;
set<long long> s[10];

long long n;

int getlen(long long a)
{
	int cnt = 0;
	do {
		++cnt;
	} while (a /= 10);
	return cnt;
}

void relax(long long a, string str)
{
	if (getlen(a) <= str.size() || (m.count(a) && m[a].size() <= str.size())) return;
	s[m[a].size()].erase(a);
	m[a] = str;
	s[str.size()].insert(a);
}
void power()
{
	for (int i = 2; (long long)i * i <= n; ++i) {
		long long val = (long long)i * i;
		int j = 2;
		while (val <= n) {
			relax(val, to_string(i) + '^' + to_string(j));
			++j;
			val *= i;
		}
	}
}
void power_multiply_power()
{
	for (set<long long>::iterator i = s[3].begin(); i != s[3].end(); ++i)
		for (set<long long>::iterator j = s[3].begin(); j != s[3].end(); ++j)
			relax(*i * *j, m[*i] + '*' + m[*j]);
}
void power_multiply_single()
{
	for (int i = 3; i <= 5; ++i)
		for (set<long long>::iterator it = s[i].begin(); it != s[i].end(); ++it)
			for (int j = 2; getlen(j) + i + 1 <= 7; ++j) relax(*it * j, m[*it] + '*' + to_string(j));
}
void precalc()
{
	power();
	power_multiply_power();
	power_multiply_single();
}

string get(long long x)
{
	if (m.count(x)) return m[x];
	return to_string(x);
}

int main()
{
	scanf("%lld", &n);
	if (n == 10000000000) {
		printf("10^10\n");
		return 0;
	}
	precalc();
	string ans = get(n);
	if (m.count(n)) ans = m[n];
	string str;
	for (int i = 1; i < 10000 && i < n; ++i) {
		str = get(i) + '+' + get(n - i);
		if (str.size() < ans.size()) ans = str;
		if (!(n % i)) {
			str = get(i) + '*' + get(n / i);
			if (str.size() < ans.size()) ans = str;
		}
	}
	printf("%s\n", ans.c_str());
	return 0;
}


#include <cstdio>
#include <string>
#include <set>
#include <map>
using namespace std;

map<long long, string> m;
set<long long> s[10];

long long n;

int getlen(long long a)
{
	int cnt = 0;
	do {
		++cnt;
	} while (a /= 10);
	return cnt;
}

void relax(long long a, string str)
{
	if (getlen(a) <= str.size() || (m.count(a) && m[a].size() <= str.size())) return;
	s[m[a].size()].erase(a);
	m[a] = str;
	s[str.size()].insert(a);
}
void power()
{
	for (int i = 2; (long long)i * i <= n; ++i) {
		long long val = (long long)i * i;
		int j = 2;
		while (val <= n) {
			relax(val, to_string(i) + '^' + to_string(j));
			++j;
			val *= i;
		}
	}
}
void power_multiply_power()
{
	for (set<long long>::iterator i = s[3].begin(); i != s[3].end(); ++i)
		for (set<long long>::iterator j = s[3].begin(); j != s[3].end(); ++j)
			relax(*i * *j, m[*i] + '*' + m[*j]);
}
void power_multiply_single()
{
	for (int i = 3; i <= 5; ++i)
		for (set<long long>::iterator it = s[i].begin(); it != s[i].end(); ++it)
			for (int j = 2; getlen(j) + i + 1 <= 7; ++j) relax(*it * j, m[*it] + '*' + to_string(j));
}
void precalc()
{
	power();
	power_multiply_power();
	power_multiply_single();
}

string get(long long x)
{
	if (m.count(x)) return m[x];
	return to_string(x);
}

void check(long long x, string &ans)
{
	string s = get(x) + '+' + get(n - x);
	if (s.size() < ans.size()) ans = s;
	if (!(n % x)) {
		s = get(x) + '*' + get(n / x);
		if (s.size() < ans.size()) ans = s;
	}
}

int main()
{
	scanf("%lld", &n);
	if (n == 10000000000) {
		printf("10^10\n");
		return 0;
	}
	precalc();
	string ans = get(n);
	string str;
	for (int i = 1; i < 10000 && i < n; ++i) check(i, ans);
	for (int i = 3; i <= 4; ++i)
		for (set<long long>::iterator it = s[i].begin(); it != s[i].end(); ++it)
			if (*it < n) check(*it, ans);
	printf("%s\n", ans.c_str());
	return 0;
}


// This code wrote by chtholly_micromaker(MicroMaker)
#include <bits/stdc++.h>
#define reg register
#define int long long
using namespace std;
template <class t> inline void read(t &s)
{
	s=0;
	reg int f=1;
	reg char c=getchar();
	while(!isdigit(c))
	{
		if(c=='-')
			f=-1;
		c=getchar();
	}
	while(isdigit(c))
		s=(s<<3)+(s<<1)+(c^48),c=getchar();
	s*=f;
	return;
}
template <class t> inline void write(t x)
{
	if(x<0)
		putchar('-'),x=-x;
	int buf[21],top=0;
	while(x)
		buf[++top]=x%10,x/=10;
	if(!top)
		buf[++top]=0;
	while(top)
		putchar(buf[top--]^'0');
	return;
}
string ans;
map<int,string> dr;
inline int fastpow(int a,int b)
{
	reg int res=1;
	for(;b;b>>=1,a=a*a)
		if(b&1)
			res=res*a;
	return res;
}
inline void checkmin(string &x,string y)
{
	if((int)x.length()>(int)y.length())
		x=y;
	return;
}
signed main(void)
{
	int n;read(n);
	ans=to_string(n);
	reg int maxi=sqrt(n);
	for(int i=2;i<=maxi;++i)
	{
		reg int t=i;
		for(int j=2;;++j)
		{
			t*=i;
			if(t>n)
				break;
			if(!dr.count(t))
				dr[t]=to_string(i)+"^"+to_string(j);
			else
				checkmin(dr[t],to_string(i)+"^"+to_string(j));
		}
	}
	for(map<int,string>::iterator it=dr.begin();it!=dr.end();++it)
	{
		string res=it->second;
		if(n/it->first>1)
			res+="*"+((dr.count(n/it->first))?dr[n/it->first]:to_string(n/it->first));
		if(n%it->first)
			res+="+"+((dr.count(n%it->first))?dr[n%it->first]:to_string(n%it->first));
		checkmin(ans,res);
	}
	cout<<ans<<endl;
	return 0;
}


// This code wrote by chtholly_micromaker(MicroMaker)
#include <bits/stdc++.h>
#define reg register
#define int long long
using namespace std;
template <class t> inline void read(t &s)
{
	s=0;
	reg int f=1;
	reg char c=getchar();
	while(!isdigit(c))
	{
		if(c=='-')
			f=-1;
		c=getchar();
	}
	while(isdigit(c))
		s=(s<<3)+(s<<1)+(c^48),c=getchar();
	s*=f;
	return;
}
template <class t> inline void write(t x)
{
	if(x<0)
		putchar('-'),x=-x;
	int buf[21],top=0;
	while(x)
		buf[++top]=x%10,x/=10;
	if(!top)
		buf[++top]=0;
	while(top)
		putchar(buf[top--]^'0');
	return;
}
string ans;
map<int,string> dr;
inline int fastpow(int a,int b)
{
	reg int res=1;
	for(;b;b>>=1,a=a*a)
		if(b&1)
			res=res*a;
	return res;
}
inline void checkmin(string &x,string y)
{
	if((int)x.length()>(int)y.length())
		x=y;
	return;
}
signed main(void)
{
	int n;read(n);
	ans=to_string(n);
	reg int maxi=sqrt(n);
	for(int i=2;i<=maxi;++i)
	{
		reg int t=i;
		for(int j=2;;++j)
		{
			t*=i;
			if(t>n)
				break;
			if(!dr.count(t))
				dr[t]=to_string(i)+"^"+to_string(j);
			else
				checkmin(dr[t],to_string(i)+"^"+to_string(j));
			checkmin(dr[t],to_string(t));
		}
	}
	for(map<int,string>::iterator it=dr.begin();it!=dr.end();++it)
	{
		string res=it->second;
		if(n/it->first>1)
			res+="*"+((dr.count(n/it->first))?dr[n/it->first]:to_string(n/it->first));
		if(n%it->first)
			res+="+"+((dr.count(n%it->first))?dr[n%it->first]:to_string(n%it->first));
		checkmin(ans,res);
	}
	cout<<ans<<endl;
	return 0;
}


#include <bits/stdc++.h>
#define show(x) cerr << #x << " = " << x << endl
using namespace std;
using ll = long long;

inline ll power(const ll n, const ll m)
{
    if (m == 0) { return 1LL; }
    if (m % 2 == 1) {
        return power(n, m - 1) * n;
    } else {
        const ll pp = power(n, m / 2);
        return pp * pp;
    }
}

int main()
{
    ll N;
    cin >> N;
    using P = pair<ll, ll>;
    using PP = pair<ll, P>;
    vector<PP> E;
    vector<PP> E2;
    string S = to_string(N);
    auto update = [&](string&& s) {if(S.size()>s.size()){S=s;} };
    auto l = [](const ll n) { return to_string(n).size(); };
    for (ll i = 2; i < 2 * sqrt(N); i++) {
        for (ll j = 2; pow(i, j) <= N; j++) {
            E.push_back({power(i, j), {i, j}});
            if (l(i) + l(j) < 4) { E2.push_back({power(i, j), {i, j}}); }
        }
    }
    sort(E.begin(), E.end());
    sort(E2.begin(), E2.end());
    for (const auto& pp : E) {
        if (pp.first > N) { break; }
        if (pp.first == N) { update(to_string(pp.second.first) + "^" + to_string(pp.second.second)); }
        if (N % pp.first == 0) { update(to_string(pp.second.first) + "^" + to_string(pp.second.second) + "*" + to_string(N / pp.first)); }
        update(to_string(pp.second.first) + "^" + to_string(pp.second.second) + "+" + to_string(N - pp.first));
        update(to_string(pp.second.first) + "^" + to_string(pp.second.second) + "*" + to_string(N / pp.first) + "+" + to_string(N % pp.first));
    }
    for (const auto& pp1 : E2) {
        if (pp1.first > N) { break; }
        const ll p2 = N - pp1.first;
        auto it = lower_bound(E.begin(), E.end(), PP{p2, {0, 0}});
        for (; it != E.end() and it->first == p2; it++) { update(to_string(pp1.second.first) + "^" + to_string(pp1.second.second) + "+" + to_string(it->second.first) + "^" + to_string(it->second.second)); }
        if (N % pp1.first != 0) { continue; }
        const ll p3 = N / pp1.first;
        it = lower_bound(E.begin(), E.end(), PP{p3, {0, 0}});
        for (; it != E.end() and it->first == p3; it++) { update(to_string(pp1.second.first) + "^" + to_string(pp1.second.second) + "*" + to_string(it->second.first) + "^" + to_string(it->second.second)); }
    }
    for (const auto& pp1 : E2) {
        if (pp1.first > N) { break; }
        for (const auto& pp2 : E2) {
            if (pp2.first > N) { break; }
            if ((N - pp1.first) % pp2.first == 0) { update(to_string(pp1.second.first) + "^" + to_string(pp1.second.second) + "+" + to_string(pp2.second.first) + "^" + to_string(pp2.second.second) + "*" + to_string((N - pp1.first) / pp2.first)); }
            if ((long double)pp1.first * pp2.first > N or N % (pp1.first * pp2.first) != 0) { continue; }
            update(to_string(pp1.second.first) + "^" + to_string(pp1.second.second) + "*" + to_string(pp2.second.first) + "^" + to_string(pp2.second.second) + "*" + to_string(N / pp1.first / pp2.first));
        }
    }
    cout << S << endl;
    return 0;
}


#include <bits/stdc++.h>
#define show(x) cerr << #x << " = " << x << endl
using namespace std;
using ll = long long;

inline ll power(const ll n, const ll m)
{
    if (m == 0) { return 1LL; }
    if (m % 2 == 1) {
        return power(n, m - 1) * n;
    } else {
        const ll pp = power(n, m / 2);
        return pp * pp;
    }
}

int main()
{
    ll N;
    cin >> N;
    using P = pair<ll, ll>;
    using PP = pair<ll, P>;
    vector<PP> E;
    vector<PP> E2;
    string S = to_string(N);
    auto update = [&](string&& s) {if(S.size()>s.size()){S=s;} };
    auto l = [](const ll n) { return to_string(n).size(); };
    for (ll i = 2; i < 2 * sqrt(N); i++) {
        for (ll j = 2; pow(i, j) <= N; j++) {
            E.push_back({power(i, j), {i, j}});
            if (l(i) + l(j) < 4) { E2.push_back({power(i, j), {i, j}}); }
        }
    }
    sort(E.begin(), E.end());
    sort(E2.begin(), E2.end());
    for (const auto& pp : E) {
        if (pp.first > N) { break; }
        if (pp.first == N) { update(to_string(pp.second.first) + "^" + to_string(pp.second.second)); }
        if (N % pp.first == 0) { update(to_string(pp.second.first) + "^" + to_string(pp.second.second) + "*" + to_string(N / pp.first)); }
        update(to_string(pp.second.first) + "^" + to_string(pp.second.second) + "+" + to_string(N - pp.first));
        update(to_string(pp.second.first) + "^" + to_string(pp.second.second) + "*" + to_string(N / pp.first) + "+" + to_string(N % pp.first));
    }
    for (const auto& pp1 : E2) {
        if (pp1.first > N) { break; }
        const ll p2 = N - pp1.first;
        auto it = lower_bound(E.begin(), E.end(), PP{p2, {0, 0}});
        for (; it != E.end() and it->first == p2; it++) { update(to_string(pp1.second.first) + "^" + to_string(pp1.second.second) + "+" + to_string(it->second.first) + "^" + to_string(it->second.second)); }
        if (N % pp1.first != 0) { continue; }
        const ll p3 = N / pp1.first;
        it = lower_bound(E.begin(), E.end(), PP{p3, {0, 0}});
        for (; it != E.end() and it->first == p3; it++) { update(to_string(pp1.second.first) + "^" + to_string(pp1.second.second) + "*" + to_string(it->second.first) + "^" + to_string(it->second.second)); }
    }
    for (const auto& pp1 : E2) {
        if (pp1.first > N) { break; }
        for (const auto& pp2 : E2) {
            if (pp2.first > N) { break; }
            if ((N - pp1.first) % pp2.first == 0) { update(to_string(pp1.second.first) + "^" + to_string(pp1.second.second) + "+" + to_string(pp2.second.first) + "^" + to_string(pp2.second.second) + "*" + to_string((N - pp1.first) / pp2.first)); }
            if (N % (pp1.first * pp2.first) != 0) { continue; }
            update(to_string(pp1.second.first) + "^" + to_string(pp1.second.second) + "*" + to_string(pp2.second.first) + "^" + to_string(pp2.second.second) + "*" + to_string(N / pp1.first) / pp2.first);
        }
    }
    cout << S << endl;
    return 0;
}


#include <bits/stdc++.h>
#define show(x) cerr << #x << " = " << x << endl
using namespace std;
using ll = long long;
using ld = long double;
inline ll power(const ll n, const ll m)
{
    if (m == 0) { return 1LL; }
    if (m % 2 == 1) {
        return power(n, m - 1) * n;
    } else {
        const ll pp = power(n, m / 2);
        return pp * pp;
    }
}

int main()
{
    ll N;
    cin >> N;
    using P = pair<ll, ll>;
    using PP = pair<ll, P>;
    vector<PP> E;
    vector<PP> E2;
    string S = to_string(N);
    auto update = [&](string&& s) {if(S.size()>s.size()){S=s;} };
    auto l = [](const ll n) { return to_string(n).size(); };
    for (ll i = 2; i < 2 * sqrt(N); i++) {
        for (ll j = 2; pow(i, j) <= N; j++) {
            E.push_back({power(i, j), {i, j}});
            if (l(i) + l(j) < 4) { E2.push_back({power(i, j), {i, j}}); }
        }
    }
    sort(E.begin(), E.end());
    sort(E2.begin(), E2.end());
    for (const auto& pp : E) {
        if (pp.first > N) { break; }
        if (pp.first == N) { update(to_string(pp.second.first) + "^" + to_string(pp.second.second)); }
        if (N % pp.first == 0) { update(to_string(pp.second.first) + "^" + to_string(pp.second.second) + "*" + to_string(N / pp.first)); }
        update(to_string(pp.second.first) + "^" + to_string(pp.second.second) + "+" + to_string(N - pp.first));
        update(to_string(pp.second.first) + "^" + to_string(pp.second.second) + "*" + to_string(N / pp.first) + "+" + to_string(N % pp.first));
    }
    for (const auto& pp1 : E2) {
        if (pp1.first > N) { break; }
        const ll p2 = N - pp1.first;
        auto it = lower_bound(E.begin(), E.end(), PP{p2, {0, 0}});
        for (; it != E.end() and it->first == p2; it++) { update(to_string(pp1.second.first) + "^" + to_string(pp1.second.second) + "+" + to_string(it->second.first) + "^" + to_string(it->second.second)); }
        if (N % pp1.first != 0) { continue; }
        const ll p3 = N / pp1.first;
        it = lower_bound(E.begin(), E.end(), PP{p3, {0, 0}});
        for (; it != E.end() and it->first == p3; it++) { update(to_string(pp1.second.first) + "^" + to_string(pp1.second.second) + "*" + to_string(it->second.first) + "^" + to_string(it->second.second)); }
    }
    for (const auto& pp1 : E2) {
        if (pp1.first > N) { break; }
        for (const auto& pp2 : E2) {
            if (pp1.first + pp2.first < N) { update(to_string(pp1.second.first) + "^" + to_string(pp1.second.second) + "+" + to_string(pp2.second.first) + "^" + to_string(pp2.second.second) + "+" + to_string(N - pp1.first - pp2.first)); }
            if (pp2.first > N) { break; }
            if ((N - pp1.first) % pp2.first == 0) { update(to_string(pp1.second.first) + "^" + to_string(pp1.second.second) + "+" + to_string(pp2.second.first) + "^" + to_string(pp2.second.second) + "*" + to_string((N - pp1.first) / pp2.first)); }
            if ((ld)pp1.first * pp2.first > N) { continue; }
            if (N % (pp1.first * pp2.first) == 0) { update(to_string(pp1.second.first) + "^" + to_string(pp1.second.second) + "*" + to_string(pp2.second.first) + "^" + to_string(pp2.second.second) + "*" + to_string(N / pp1.first / pp2.first)); }
            update(to_string(pp1.second.first) + "^" + to_string(pp1.second.second) + "*" + to_string(pp2.second.first) + "^" + to_string(pp2.second.second) + "+" + to_string(N - pp1.first * pp2.first));
        }
    }
    cout << S << endl;
    return 0;
}


#include <bits/stdc++.h>
#define show(x) cerr << #x << " = " << x << endl
using namespace std;
using ll = long long;

inline ll power(const ll n, const ll m)
{
    if (m == 0) { return 1LL; }
    if (m % 2 == 1) {
        return power(n, m - 1) * n;
    } else {
        const ll pp = power(n, m / 2);
        return pp * pp;
    }
}

int main()
{
    ll N;
    cin >> N;
    using P = pair<ll, ll>;
    using PP = pair<ll, P>;
    vector<PP> E;
    vector<PP> E2;
    string S = to_string(N);
    auto update = [&](string&& s) {if(S.size()>s.size()){S=s;} };
    auto l = [](const ll n) { return to_string(n).size(); };
    for (ll i = 2; i < 2 * sqrt(N); i++) {
        for (ll j = 2; pow(i, j) <= N; j++) {
            E.push_back({power(i, j), {i, j}});
            if (l(i) + l(j) < 4) { E2.push_back({power(i, j), {i, j}}); }
        }
    }
    sort(E.begin(), E.end());
    sort(E2.begin(), E2.end());
    for (const auto& pp : E) {
        if (pp.first > N) { break; }
        if (pp.first == N) { update(to_string(pp.second.first) + "^" + to_string(pp.second.second)); }
        if (N % pp.first == 0) { update(to_string(pp.second.first) + "^" + to_string(pp.second.second) + "*" + to_string(N / pp.first)); }
        update(to_string(pp.second.first) + "^" + to_string(pp.second.second) + "+" + to_string(N - pp.first));
        update(to_string(pp.second.first) + "^" + to_string(pp.second.second) + "*" + to_string(N / pp.first) + "+" + to_string(N % pp.first));
    }
    for (const auto& pp1 : E2) {
        if (pp1.first > N) { break; }
        const ll p2 = N - pp1.first;
        auto it = lower_bound(E.begin(), E.end(), PP{p2, {0, 0}});
        for (; it != E.end() and it->first == p2; it++) { update(to_string(pp1.second.first) + "^" + to_string(pp1.second.second) + "+" + to_string(it->second.first) + "^" + to_string(it->second.second)); }
        if (N % pp1.first != 0) { continue; }
        const ll p3 = N / pp1.first;
        it = lower_bound(E.begin(), E.end(), PP{p3, {0, 0}});
        for (; it != E.end() and it->first == p3; it++) { update(to_string(pp1.second.first) + "^" + to_string(pp1.second.second) + "*" + to_string(it->second.first) + "^" + to_string(it->second.second)); }
    }
    for (const auto& pp1 : E2) {
        if (pp1.first > N) { break; }
        for (const auto& pp2 : E2) {
            if (pp2.first > N) { break; }
            if ((N - pp1.first) % pp2.first == 0) { update(to_string(pp1.second.first) + "^" + to_string(pp1.second.second) + "+" + to_string(pp2.second.first) + "^" + to_string(pp2.second.second) + "*" + to_string((N - pp1.first) / pp2.first)); }
            if (N % (pp1.first * pp2.first) != 0) { continue; }
            update(to_string(pp1.second.first) + "^" + to_string(pp1.second.second) + "*" + to_string(pp2.second.first) + "^" + to_string(pp2.second.second) + "*" + to_string(N / pp1.first / pp2.first));
        }
    }
    cout << S << endl;
    return 0;
}


#include <bits/stdc++.h>
#define show(x) cerr << #x << " = " << x << endl
using namespace std;
using ll = long long;

inline ll power(const ll n, const ll m)
{
    if (m == 0) { return 1LL; }
    if (m % 2 == 1) {
        return power(n, m - 1) * n;
    } else {
        const ll pp = power(n, m / 2);
        return pp * pp;
    }
}

int main()
{
    ll N;
    cin >> N;
    using P = pair<ll, ll>;
    using PP = pair<ll, P>;
    vector<PP> E;
    vector<PP> E2;
    string S = to_string(N);
    auto update = [&](string&& s) {if(S.size()>s.size()){S=s;} };
    auto l = [](const ll n) { return to_string(n).size(); };
    for (ll i = 2; i < 2 * sqrt(N); i++) {
        for (ll j = 2; pow(i, j) <= N; j++) {
            E.push_back({power(i, j), {i, j}});
            if (l(i) + l(j) < 4) { E2.push_back({power(i, j), {i, j}}); }
        }
    }
    sort(E.begin(), E.end());
    sort(E2.begin(), E2.end());
    for (const auto& pp : E) {
        if (pp.first > N) { break; }
        if (pp.first == N) { update(to_string(pp.second.first) + "^" + to_string(pp.second.second)); }
        if (N % pp.first == 0) { update(to_string(pp.second.first) + "^" + to_string(pp.second.second) + "*" + to_string(N / pp.first)); }
        update(to_string(pp.second.first) + "^" + to_string(pp.second.second) + "+" + to_string(N - pp.first));
        update(to_string(pp.second.first) + "^" + to_string(pp.second.second) + "*" + to_string(N / pp.first) + "+" + to_string(N % pp.first));
    }
    for (const auto& pp1 : E2) {
        if (pp1.first > N) { break; }
        const ll p2 = N - pp1.first;
        auto it = lower_bound(E.begin(), E.end(), PP{p2, {0, 0}});
        for (; it != E.end() and it->first == p2; it++) { update(to_string(pp1.second.first) + "^" + to_string(pp1.second.second) + "+" + to_string(it->second.first) + "^" + to_string(it->second.second)); }
        if (N % pp1.first != 0) { continue; }
        const ll p3 = N / pp1.first;
        it = lower_bound(E.begin(), E.end(), PP{p3, {0, 0}});
        for (; it != E.end() and it->first == p3; it++) { update(to_string(pp1.second.first) + "^" + to_string(pp1.second.second) + "*" + to_string(it->second.first) + "^" + to_string(it->second.second)); }
    }
    cout << S << endl;
    return 0;
}


#include <bits/stdc++.h>
#define show(x) cerr << #x << " = " << x << endl
using namespace std;
using ll = long long;

inline ll power(const ll n, const ll m)
{
    if (m == 0) { return 1LL; }
    if (m % 2 == 1) {
        return power(n, m - 1) * n;
    } else {
        const ll pp = power(n, m / 2);
        return pp * pp;
    }
}

int main()
{
    ll N;
    cin >> N;
    using P = pair<ll, ll>;
    using PP = pair<ll, P>;
    vector<PP> E;
    vector<PP> E2;
    string S = to_string(N);
    auto update = [&](string&& s) {if(S.size()>s.size()){S=s;} };
    auto l = [](const ll n) { return to_string(n).size(); };
    for (ll i = 2; i < 2 * sqrt(N); i++) {
        for (ll j = 2; pow(i, j) <= N; j++) {
            E.push_back({power(i, j), {i, j}});
            if (l(i) + l(j) < 4) { E2.push_back({power(i, j), {i, j}}); }
        }
    }
    sort(E.begin(), E.end());
    sort(E2.begin(), E2.end());
    for (const auto& pp : E) {
        if (pp.first > N) { break; }
        if (pp.first == N) { update(to_string(pp.second.first) + "^" + to_string(pp.second.second)); }
        if (N % pp.first == 0) { update(to_string(pp.second.first) + "^" + to_string(pp.second.second) + "*" + to_string(N / pp.first)); }
        update(to_string(pp.second.first) + "^" + to_string(pp.second.second) + "+" + to_string(N - pp.first));
        update(to_string(pp.second.first) + "^" + to_string(pp.second.second) + "*" + to_string(N / pp.first) + "+" + to_string(N % pp.first));
    }
    for (const auto& pp1 : E2) {
        if (pp1.first > N) { break; }
        const ll p2 = N - pp1.first;
        auto it = lower_bound(E.begin(), E.end(), PP{p2, {0, 0}});
        for (; it != E.end() and it->first == p2; it++) { update(to_string(pp1.second.first) + "^" + to_string(pp1.second.second) + "+" + to_string(it->second.first) + "^" + to_string(it->second.second)); }
        if (N % pp1.first != 0) { continue; }
        const ll p3 = N / pp1.first;
        it = lower_bound(E.begin(), E.end(), PP{p3, {0, 0}});
        for (; it != E.end() and it->first == p3; it++) { update(to_string(pp1.second.first) + "^" + to_string(pp1.second.second) + "*" + to_string(it->second.first) + "^" + to_string(it->second.second)); }
    }
    for (const auto& pp1 : E2) {
        if (pp1.first > N) { break; }
        for (const auto& pp2 : E2) {
            if (pp2.first > N) { break; }
            if ((N - pp1.first) % pp2.first == 0) { update(to_string(pp1.second.first) + "^" + to_string(pp1.second.second) + "+" + to_string(pp2.second.first) + "^" + to_string(pp2.second.second) + "*" + to_string((N - pp1.first) / pp2.first)); }
            if ((ld)pp1.first * pp2.first > N or N % (pp1.first * pp2.first) != 0) { continue; }
            update(to_string(pp1.second.first) + "^" + to_string(pp1.second.second) + "*" + to_string(pp2.second.first) + "^" + to_string(pp2.second.second) + "*" + to_string(N / pp1.first / pp2.first));
        }
    }
    cout << S << endl;
    return 0;
}


#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <iomanip>
#include <cctype>
#include <cassert>
#include <bitset>
#include <ctime>

using namespace std;

#define pau system("pause")
#define ll long long
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define clr(a, x) memset(a, x, sizeof(a))

const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;

/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
tree<pli, null_type, greater<pli>, rb_tree_tag, tree_order_statistics_node_update> T;
*/

ll n;
string ans;
void add(string &S, ll t) {
    char s[29];
    int l = 0;
    while (t) {
        s[++l] = t % 10;
        t /= 10;
    }
    while (l) {
        S += s[l] + '0';
        --l;
    }
}
map<ll, string> mmp;
void pre() {
    for (ll a = 2; a <= sqrt(n + 0.5); ++a) {
        ll tt = a;
        for (int b = 2; ; ++b) {
            tt *= a;
            if (tt > n) break;
            string t2 = "";
            add(t2, a);
            t2 += "^";
            add(t2, b);
            if (mmp.count(tt)) {
                string t1 = mmp[tt];
                if (t2.length() < t1.length()) {
                    mmp[tt] = t2;
                }
            } else {
                mmp[tt] = t2;
            }
        }
    }
}
int main() {
    scanf("%lld", &n);
    if (n < 1000) {
        printf("%lld\n", n);
    } else {
        pre();
        add(ans, n);
        for (ll a = 2; a <= sqrt(n + 0.5); ++a) {
            ll tt = a;
            for (ll b = 2; ; ++b) {
                tt *= a;
                if (tt > n) break;
                string res = "";
                add(res, a);
                res += "^";
                add(res, b);
                ll c = n / tt;
                for (ll tc = c; tc >= max(1ll, c - 0); --tc) {
                    ll d = n - tt * tc;
                    string res2 = res;
                    if (1 != tc) {
                        res2 += "*";
                        string res4 = "";
                        add(res4, tc);
                        if (mmp.count(tc)) {
                            if (res4.length() < mmp[tc].length()) {
                                res2 += res4;
                            } else {
                                res2 += mmp[tc];
                            }
                        } else {
                            res2 += res4;
                        }
                    }
                    if (d) {
                        res2 += "+";
                        string res3 = "";
                        add(res3, d);
                        if (mmp.count(d)) {
                            if (res3.length() < mmp[d].length()) {
                                res2 += res3;
                            } else {
                                res2 += mmp[d];
                            }
                        } else {
                            res2 += res3;
                        }
                    }
                    if (res2.length() < ans.length()) {
                        ans = res2;
                    }
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}