#include <bits/stdc++.h>

using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using piii = pair<int, pii>;
using plll = pair<ll, pll>;
using pib = pair<int, bool>;
using pdi = pair<double, int>;
using pid = pair<int, double>;
using ld = long double;
using piiii = pair<pii, pii>;

#define endl "\n"
#define inf 0x3f3f3f3f3f
#define f first
#define s second

ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}

int n, q;
ll k, psa[100001];

int main() {
    //freopen("cowmbat.in", "r", stdin);
    //freopen("cowmbat.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    ll t = 0;
    for (int i=1; i<=n; i++){
        cin >> psa[i];
    }
    sort(psa+1, psa+1+n);
    for (int i=1; i<=n; i++){
        psa[i] += psa[i-1];
        if (i<n) t += psa[i];
    }
    cin >> q;
    for (int i=0; i<q; i++){
        cin >> k;
        if (k==1){
            cout << t << endl;
        }else{
            ll ans = 0;
            int idx = n-1;
            ll cur = k;
            while (true){
                if (idx<=cur){
                    ans += psa[idx];
                    break;
                }else{
                    ans += psa[idx];
                    idx -= cur;
                    cur *= k;
                }
            }
            cout << ans << endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using piii = pair<int, pii>;
using plll = pair<ll, pll>;
using pib = pair<int, bool>;
using pdi = pair<double, int>;
using pid = pair<int, double>;
using ld = long double;
using piiii = pair<pii, pii>;

#define endl "\n"
#define inf 0x3f3f3f3f3f
#define f first
#define s second

ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}

int n, q;
ll k, psa[100001];

int main() {
    //freopen("cowmbat.in", "r", stdin);
    //freopen("cowmbat.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    ll t = 0;
    for (int i=1; i<=n; i++){
        cin >> psa[i];
    }
    sort(psa+1, psa+1+n);
    for (int i=1; i<=n; i++){
        psa[i] += psa[i-1];
        if (i<n) t += psa[i];
    }
    cin >> q;
    for (int i=0; i<q; i++){
        cin >> k;
        if (k==1){
            cout << t << endl;
        }else{
            ll ans = 0;
            int idx = n-1;
            ll cur = k;
            while (true){
                if (idx<=cur){
                    ans += psa[idx];
                    break;
                }else{
                    ans += psa[idx];
                    idx -= k;
                    cur *= k;
                }
            }
            cout << ans << endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using piii = pair<int, pii>;
using plll = pair<ll, pll>;
using pib = pair<int, bool>;
using pdi = pair<double, int>;
using pid = pair<int, double>;
using ld = long double;
using piiii = pair<pii, pii>;

#define endl "\n"
#define inf 0x3f3f3f3f3f
#define f first
#define s second

ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}

int n, q, k;
ll psa[100001];

int main() {
    //freopen("cowmbat.in", "r", stdin);
    //freopen("cowmbat.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    ll t = 0;
    for (int i=1; i<=n; i++){
        cin >> psa[i];
    }
    sort(psa+1, psa+1+n);
    for (int i=1; i<=n; i++){
        psa[i] += psa[i-1];
        t += psa[i];
    }
    cin >> q;
    for (int i=0; i<q; i++){
        cin >> k;
        if (k==1){
            cout << t << endl;
        }else{
            ll ans = 0;
            int idx = n-1;
            int cur = k;
            while (true){
                if (idx<=cur){
                    ans += psa[idx];
                    break;
                }else{
                    ans += psa[idx];
                    idx -= k;
                    cur *= k;
                }
            }
            cout << ans << endl;
        }
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#define Long long long int
using namespace std;
const int N = 100 * 1000 + 1;
int n, q;
Long ary [N];
Long sum [N];
Long cost[N];
Long ans [N];

void read();
void initialize();
void readQueries();
void print();
void initializeSum();
void initializeAns();

int main(){
    read();
    sort(ary + 1, ary + n + 1);
    initialize();
    readQueries();
    print();
    return 0;
}

void read(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    for(int i=1; i<=n; i++)
        cin>>ary[i];
}

void initialize(){
    initializeSum();
    initializeAns();
}

void readQueries(){
    cin>>q;
    for(int i=0; i<q; i++){
        int k;
        cin>>k;
        ans[i] = cost[k];
    }
}

void print(){
    for(int i=0; i<q; i++)
        cout<<ans[i]<<' ';
    cout<<endl;
}

void initializeSum(){
    for(int i=1; i<=n; i++)
        sum[i] = sum[i-1] + ary[i];
}

void initializeAns(){
    for(int k=1; k<=N; k++){
        if(k < n){
            Long ind = n;
            Long num = 1;
            while(ind - num > 0){
                ind -= num;
                cost[k] += sum[ind];
                num *= k;
            }
        }
        else
            cost[k] = cost[k-1];
    }
}


#include <iostream>
#include <algorithm>
#define Long long long int
using namespace std;
const int N = 100 * 1000 + 1;
int n, q;
Long ary [N];
Long sum [N];
Long cost[N];
Long ans [N];

void read();
void initialize();
void readQueries();
void print();
void initializeSum();
void initializeAns();

int main(){
    read();
    sort(ary + 1, ary + n + 1);
    initialize();
    readQueries();
    print();
    return 0;
}

void read(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    for(int i=1; i<=n; i++)
        cin>>ary[i];
}

void initialize(){
    initializeSum();
    initializeAns();
}

void readQueries(){
    cin>>q;
    for(int i=0; i<q; i++){
        int k;
        cin>>k;
        ans[i] = cost[k];
    }
}

void print(){
    for(int i=0; i<q; i++)
        cout<<ans[i]<<' ';
    cout<<endl;
}

void initializeSum(){
    for(int i=1; i<=n; i++)
        sum[i] = sum[i-1] + ary[i];
}

void initializeAns(){
    for(int k=1; k<=n; k++){
        Long ind = n;
        Long num = 1;
        while(ind - num > 0){
            ind -= num;
            cost[k] += sum[ind];
            num *= k;
        }
    }
}


#define rep(i, a, b) for (int i = a; i < b; ++i)
#define repr(i,a,b) for (int i = a; i > b; --i)
#define mm(lamb, tttt) memset(lamb, tttt, sizeof lamb)

#define null NULL
#define eps 0.000000001
#define mod 1000000007
#define PI 3.14159265358979323846
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define sz(V) (int)V.size()
#define _ <<" "<<

#include <iostream>
#include <fstream>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <iterator>
#include <bitset>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <limits.h>
#include <iomanip>
#include <cctype>
#include <numeric>
#include <complex>

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef pair <int, int> ii;
typedef pair<int, pair<int,int> > iii;
typedef vector<ii> vii;

int n;
int data[100100];

int main()
{
	cin>>n;
	rep(i, 0, n) cin>>data[i];
	sort(data, data + n, greater<int>());
	rep(i, 0, n-1) data[i] = data[i+1];
	ll ans1 = 0;
	rep(i, 0, n-1)
	{
		ans1 += 1ll * (i+1) * data[i];
	}
	rep(i, 1, n-1)
		data[i] = data[i-1] + data[i];
	repr(i, n-2, -1)
		data[i+1] = data[i];
	data[0] = 0;
	int q;
	cin>>q;
	while(q--)
	{
		int ques;cin>>ques;
		if (ques == 1)
		{
			cout<<ans1<<" ";
		}
		else
		{
			ll ans = 0;
			int rem = n-1;
			ll val = ques;
			int i = 1;
			while(1)
			{
				if (rem < val)
				{
					int rsum = data[n-1] - data[n-rem-1];
					ans += 1ll * rsum * i;
					break;
				}
				int rsum = data[n-rem-1 + val] - data[n-rem-1];
				ans += 1ll * rsum * i;
				i++;
				rem -= val;
				val *= ques;
			}
			cout<<ans<<" ";
		}
	}
	cout<<"\n";
	return 0;
}


#define rep(i, a, b) for (ll i = a; i < b; ++i)
#define repr(i,a,b) for (ll i = a; i > b; --i)
#define mm(lamb, tttt) memset(lamb, tttt, sizeof lamb)

#define null NULL
#define eps 0.000000001
#define mod 1000000007
#define PI 3.14159265358979323846
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define sz(V) (ll)V.size()
#define _ <<" "<<

#include <iostream>
#include <fstream>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <iterator>
#include <bitset>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <limits.h>
#include <iomanip>
#include <cctype>
#include <numeric>
#include <complex>

using namespace std;

typedef long long ll;
typedef vector <ll> vi;
typedef pair <ll, ll> ii;
typedef pair<ll, pair<ll,ll> > iii;
typedef vector<ii> vii;

ll n;
ll data[100100];

int main()
{
	cin>>n;
	rep(i, 0, n) cin>>data[i];
	sort(data, data + n, greater<ll>());
	rep(i, 0, n-1) data[i] = data[i+1];
	ll ans1 = 0;
	rep(i, 0, n-1)
	{
		ans1 += 1ll * (i+1) * data[i];
	}
	rep(i, 1, n-1)
		data[i] = data[i-1] + data[i];
	repr(i, n-2, -1)
		data[i+1] = data[i];
	data[0] = 0;
	ll q;
	cin>>q;
	while(q--)
	{
		ll ques;cin>>ques;
		if (ques == 1)
		{
			cout<<ans1<<" ";
		}
		else
		{
			ll ans = 0;
			ll rem = n-1;
			ll val = ques;
			ll i = 1;
			while(1)
			{
				if (rem < val)
				{
					ll rsum = data[n-1] - data[n-rem-1];
					ans += 1ll * rsum * i;
					break;
				}
				ll rsum = data[n-rem-1 + val] - data[n-rem-1];
				ans += 1ll * rsum * i;
				i++;
				rem -= val;
				val *= ques;
			}
			cout<<ans<<" ";
		}
	}
	cout<<"\n";
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#define INF 0x3f3f3f3f
#define MAX 99999000
using namespace std;
long long int a[MAX];
long long int sum[MAX] = {0};
int main()
{
    int n, m, q;
    scanf("%d", &n);
    a[0] = 0;
    for(int i=1;i<=n;i++)
        scanf("%I64d", a+i);
    sort(a+1, a+n+1);
    for(int i=1;i<=n;i++)
        a[i] += a[i-1];
    for(int i=1;i<=n;i++)
    {
        q = n - 1;
        m = i;
        while(q>=1)
        {
            sum[i] += a[q];
            q -= m;
            m *= i;
        }
    }
    scanf("%d", &m);
    while(m--)
    {
        scanf("%d", &q);
        printf("%I64d ", sum[min(n, q)]);
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#define INF 0x3f3f3f3f
#define MAX 9999900
using namespace std;
long long int a[MAX];
long long int sum[MAX] = {0};
int main()
{
    int n, m, q;
    scanf("%d", &n);
    a[0] = 0;
    for(int i=1;i<=n;i++)
        scanf("%I64d", a+i);
    sort(a+1, a+n+1);
    for(int i=1;i<=n;i++)
        a[i] += a[i-1];
    for(int i=1;i<=n;i++)
    {
        q = n - 1;
        m = i;
        while(q>=1)
        {
            sum[i] += a[q];
            q -= m;
            m *= i;
        }
    }
    scanf("%d", &m);
    while(m--)
    {
        scanf("%d", &q);
        printf("%I64d ", sum[min(n, q)]);
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#define INF 0x3f3f3f3f
#define MAX 999990
using namespace std;
long long int a[MAX] = {0};
long long int sum[MAX] = {0};
long long int m, q;
long long int mind(long long int a, long long int b)
{
    return a<b?a:b;
}
int main()
{
    int n;
    cin>>n;
    a[0] = 0;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    sort(a+1, a+n+1);
    for(int i=1;i<=n;i++)
        a[i] += a[i-1];
    for(int i=1;i<=n;i++)
    {
        q = n - 1;
        m = i;
        while(q>=1)
        {
            sum[i] += a[q];
            q -= m;
            m *= i;
        }
    }
    cin>>m;
    while(m--)
    {
        cin>>q;
        printf("%I64d ", sum[mind(n, q)]);
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#define INF 0x3f3f3f3f
#define MAX 99999
using namespace std;
long long int a[MAX];
long long int sum[MAX] = {0};
int main()
{
    int n, m, q;
    scanf("%d", &n);
    a[0] = 0;
    for(int i=1;i<=n;i++)
        scanf("%I64d", a+i);
    sort(a+1, a+n+1);
    for(int i=1;i<=n;i++)
        a[i] += a[i-1];
    for(int i=1;i<=n;i++)
    {
        q = n - 1;
        m = i;
        while(q>=1)
        {
            sum[i] += a[q];
            q -= m;
            m *= i;
        }
    }
    scanf("%d", &m);
    while(m--)
    {
        scanf("%d", &q);
        printf("%I64d ", sum[min(n, q)]);
    }
    return 0;
}


#include<iostream>
#include<algorithm>
#include<queue>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<set>
#include<cstring>
#include<ctime>
#include<cmath>
#include<limits>
#include<iterator>
#include<functional>
#include<unordered_map>
#include<stack>
#include<bitset>

#define all(v) v.begin(), v.end()
#define setv(ar, val) memset(ar, val, sizeof(ar));
#define ll long long int
#define ull unsigned long long int
#define PI 3.1415926535897932384626433832795
#pragma comment(linker, "/STACK:536870912")
#pragma warning(disable:4996)
using namespace std;

const int N = 1e5 + 100;
ll a[N], g[N], s[N];

int n;

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	scanf("%d", &n);

	for (int i = 0; i < n; i++) {
		scanf("%lld", &a[i]);
	}

	sort(a, a + n, greater<ll>());

	for (int i = 0; i < n; i++) {
		s[i + 1] = s[i] + a[i];
	}

	for (int i = 1; i < n; i++) {
		ll d = 1, h = 0;
		for (ll j = 1; j <= n; j += d, d *= i, h++) {
			g[i] += (s[min((ll)n, j + d - 1)] - s[j - 1]) * h;
		}
	}

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

	while (q--) {
		int k;
		scanf("%d", &k);
		printf("%lld ", g[min(k, n - 1)]);
	}

	return 0;
}


#include<iostream>
#include<algorithm>
#include<queue>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<set>
#include<cstring>
#include<ctime>
#include<cmath>
#include<limits>
#include<iterator>
#include<functional>
#include<unordered_map>
#include<stack>
#include<bitset>

#define all(v) v.begin(), v.end()
#define setv(ar, val) memset(ar, val, sizeof(ar));
#define ll long long int
#define ull unsigned long long int
#define PI 3.1415926535897932384626433832795
#pragma comment(linker, "/STACK:1073741824")
#pragma warning(disable:4996)
using namespace std;

const int N = 1e5 + 100;
ll a[N], g[N], s[N];

int n;

ll f(int i, int d) {
	if (i + d > n)
		return 0;
	return s[min(n, i + d)] - s[i] + f(i + d, d);
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	scanf("%d", &n);

	for (int i = 1; i <= n; i++) {
		scanf("%lld", &a[i]);
		s[i] = s[i - 1] + a[i];
	}

	for (int i = 1; i < n; i++) {
		g[i] = f(1, i);
	}

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

	while (q--) {
		int k;
		scanf("%d", &k);
		printf("%lld ", g[min(k, n - 1)]);
	}

	return 0;
}


#include<iostream>
#include<algorithm>
#include<queue>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<set>
#include<cstring>
#include<ctime>
#include<cmath>
#include<limits>
#include<iterator>
#include<functional>
#include<unordered_map>
#include<stack>
#include<bitset>

#define all(v) v.begin(), v.end()
#define setv(ar, val) memset(ar, val, sizeof(ar));
#define ll long long int
#define ull unsigned long long int
#define PI 3.1415926535897932384626433832795
#pragma comment(linker, "/STACK:536870912")
#pragma warning(disable:4996)
using namespace std;

const int N = 1e5 + 100;
ll a[N], g[N], s[N];

int n;

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	scanf("%d", &n);

	for (int i = 0; i < n; i++) {
		scanf("%lld", &a[i]);
	}

	sort(a, a + n, greater<ll>());

	for (int i = 0; i < n; i++) {
		s[i + 1] = s[i] + a[i];
	}

	for (int i = 1; i < n; i++) {
		int d = 1, h = 0;
		for (int j = 1; j <= n; j += d, d *= i, h++) {
			g[i] += (s[min(n, j + d - 1)] - s[j - 1]) * h;
		}
	}

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

	while (q--) {
		int k;
		scanf("%d", &k);
		printf("%lld ", g[min(k, n - 1)]);
	}

	return 0;
}


#include<iostream>
#include<algorithm>
#include<queue>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<set>
#include<cstring>
#include<ctime>
#include<cmath>
#include<limits>
#include<iterator>
#include<functional>
#include<unordered_map>
#include<stack>
#include<bitset>

#define all(v) v.begin(), v.end()
#define setv(ar, val) memset(ar, val, sizeof(ar));
#define ll long long int
#define ull unsigned long long int
#define PI 3.1415926535897932384626433832795
#pragma comment(linker, "/STACK:1073741824")
#pragma warning(disable:4996)
using namespace std;

const int N = 1e5 + 100;
ll a[N], g[N], s[N];

int n;

ll f(int i, int d) {
	if (i > n)
		return 0;
	return s[min(n, i + d - 1)] - s[i] + s[n] - s[min(n, i + d - 1)] + f(i + d, d);
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	scanf("%d", &n);

	for (int i = 0; i < n; i++) {
		scanf("%lld", &a[i]);
	}

	sort(a, a + n, greater<ll>());

	for (int i = 0; i < n; i++) {
		s[i + 1] = s[i] + a[i];
	}

	for (int i = 1; i < n; i++) {
		g[i] = f(1, i);
	}

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

	while (q--) {
		int k;
		scanf("%d", &k);
		printf("%lld ", g[min(k, n - 1)]);
	}

	return 0;
}


#include<iostream>
#include<algorithm>
#include<queue>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<set>
#include<cstring>
#include<ctime>
#include<cmath>
#include<limits>
#include<iterator>
#include<functional>
#include<unordered_map>
#include<stack>
#include<bitset>

#define all(v) v.begin(), v.end()
#define setv(ar, val) memset(ar, val, sizeof(ar));
#define ll long long int
#define ull unsigned long long int
#define PI 3.1415926535897932384626433832795
#pragma comment(linker, "/STACK:1073741824")
#pragma warning(disable:4996)
using namespace std;

const int N = 1e5 + 100;
ll a[N], g[N], s[N];

int n;

pair<ll, ll> f(int i, int d) {
	if (i > n)
		return { 0, 0 };
	auto p = f(i + d, d);
	return { p.first + p.second + s[min(n, i + d - 1)] - s[i], s[n] - s[i - 1]};
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	scanf("%d", &n);

	for (int i = 0; i < n; i++) {
		scanf("%lld", &a[i]);
	}

	sort(a, a + n, greater<ll>());

	for (int i = 0; i < n; i++) {
		s[i + 1] = s[i] + a[i];
	}

	for (int i = 1; i < n; i++) {
		g[i] = f(1, i).first;
	}

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

	while (q--) {
		int k;
		scanf("%d", &k);
		printf("%lld ", g[min(k, n - 1)]);
	}

	return 0;
}


#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int arr[MAXN];
unsigned long long par[MAXN],ans[MAXN];
int main(){
	#ifndef ONLINE_JUDGE
    freopen("file.in", "r", stdin);
	#endif
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",arr+i);
	sort(arr+1,arr+n+1);
	for(int i=1;i<=n;i++)
		par[i]=par[i-1]+arr[i];
	for(int i=1;i<MAXN;i++){
		if(i>=n-1){
			ans[i]=par[n-1];
			continue;
		}ll cnt=1;
		for(int j=n-1;j>=1;j-=i)
			ans[i]+=cnt*1LL*(par[j]-par[max(0,j-i)]),cnt++;
	}
	int q;
	scanf("%d",&q);
	while(q--){
		int k;
		scanf("%d",&k);
		printf("%lld ",ans[k]);
	}puts("");
	return 0;
}


#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int arr[MAXN];
ll par[MAXN],ans[MAXN];
int main(){
	#ifndef ONLINE_JUDGE
    freopen("file.in", "r", stdin);
	#endif
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",arr+i);
	sort(arr+1,arr+n+1);
	for(int i=1;i<=n;i++)
		par[i]=par[i-1]+arr[i];
	for(int i=1;i<MAXN;i++){
		if(i>=n-1){
			ans[i]=par[n-1];
			continue;
		}ll cnt=1;
		for(int j=n-1;j>=1;j-=i)
			ans[i]+=cnt*1LL*(par[j]-par[max(0,j-i)]),cnt++;
	}
	int q;
	scanf("%d",&q);
	while(q--){
		int k;
		scanf("%d",&k);
		printf("%lld ",ans[k]);
	}puts("");
	return 0;
}


#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int arr[MAXN];
ll par[MAXN],ans[MAXN];
ll Fe(int x,int y){
	if(!y)
		return 1;
	ll h=Fe(x,y/2);
	if(y&1)
		return h*h*x;
	return h*h;
}
int main(){
	#ifndef ONLINE_JUDGE
    freopen("file.in", "r", stdin);
	#endif
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",arr+i);
	sort(arr+1,arr+n+1);
	for(int i=1;i<=n;i++)
		par[i]=par[i-1]+arr[i];
	for(int i=1;i<MAXN;i++){
		if(i>=n-1){
			ans[i]=par[n-1];
			continue;
		}ll cnt=1,now=1;
		for(int j=n-1;j>=1;j-=i){
			ans[i]+=cnt*1LL*(par[j]-par[max(0,j-i)]);
			now--;
			if(!now)
				now=Fe(i,cnt),cnt++;
		}
	}
	int q;
	scanf("%d",&q);
	while(q--){
		int k;
		scanf("%d",&k);
		printf("%lld ",ans[k]);
	}puts("");
	return 0;
}


#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int arr[MAXN];
ll par[MAXN],ans[MAXN];
int main(){
	#ifndef ONLINE_JUDGE
    freopen("file.in", "r", stdin);
	#endif
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",arr+i);
	sort(arr+1,arr+n+1);
	for(int i=1;i<=n;i++)
		par[i]=par[i-1]+arr[i];
	for(int i=1;i<MAXN;i++){
		if(i>=n-1){
			ans[i]=par[n-1];
			continue;
		}int cnt=1;
		for(int j=n-1;j>=1;j-=i)
			ans[i]+=cnt*1LL*(par[j]-par[max(0,j-i)]),cnt++;
	}
	int q;
	scanf("%d",&q);
	while(q--){
		int k;
		scanf("%d",&k);
		printf("%lld ",ans[k]);
	}puts("");
	return 0;
}


#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int arr[MAXN];
unsigned long long par[MAXN],ans[MAXN];
int main(){
	#ifndef ONLINE_JUDGE
    freopen("file.in", "r", stdin);
	#endif
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",arr+i);
	sort(arr+1,arr+n+1);
	for(int i=1;i<=n;i++)
		par[i]=par[i-1]+arr[i];
	for(int i=1;i<MAXN;i++){
		if(i>=n-1){
			ans[i]=par[n-1];
			continue;
		}ll cnt=1,now=1;
		for(int j=n-1;j>=1;j-=i){
			ans[i]+=cnt*1LL*(par[j]-par[max(0,j-i)]);
			now--;
			if(!now)
				cnt++,now=cnt;
		}
	}
	int q;
	scanf("%d",&q);
	while(q--){
		int k;
		scanf("%d",&k);
		printf("%lld ",ans[k]);
	}puts("");
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 111111;
int n, a[N], q, k;
long long s[N], f[N];

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  sort(a, a + n);
  reverse(a, a + n);
  for (int i = 0; i < n; ++i) s[i] = a[i] + (i > 0 ? s[i - 1] : 0);
  for (k = 1; k <= (int)1e5; ++k) {
    f[k] = 0;
    for (int beg = 1, len = k, cnt = 1; beg < n; len *= k, ++cnt) {
      int end = min(beg + len - 1, n - 1);
      f[k] += 1LL * cnt * (s[end] - s[beg - 1]);
      beg = end + 1;
    }
  }
  scanf("%d", &q);
  while (q--) {
    scanf("%d", &k);
    printf("%lld\n", f[k]);
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 111111;
int n, a[N], q, k;
long long s[N], f[N];

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  sort(a, a + n);
  reverse(a, a + n);
  for (int i = 0; i < n; ++i) s[i] = a[i] + (i > 0 ? s[i - 1] : 0);
  for (k = 1; k <= (int)1e5; ++k) {
    f[k] = 0;
    for (long long beg = 1, len = k, cnt = 1; beg < n; len *= k, ++cnt) {
      long long end = min(beg + len - 1, 0LL + n - 1);
      f[k] += 1LL * cnt * (s[end] - s[beg - 1]);
      beg = end + 1;
    }
  }
  scanf("%d", &q);
  while (q--) {
    scanf("%d", &k);
    printf("%lld\n", f[k]);
  }
  return 0;
}


#include<bits/stdc++.h>
#define nl ('\n')
#define pb push_back
#define MOD 1000000007
#define MAX 100000
typedef long long ll;
using namespace std;
//ll expo(ll x,ll y,ll M){ if(y==0) return 1; ll z = expo(x,y/2,M); if(y&1) return (1ll * ((1ll * x * z)%M) * z)%M; else return (1ll * z * z)%M;}
//ll gcd(ll x,ll y){ if(x==0) return y; return gcd(y%x,x); }
ll A[MAX+5],S[MAX+5];
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);
	ll i,j,n,q,k;
	cin>>n;
	for(i=0;i<n;i++)
		cin>>A[i];
	sort(A,A+n);
	reverse(A,A+n);
	S[0] = A[0];
	ll ans1 = 0 ;
	for(i=1;i<n;i++){
		S[i] = S[i-1] + A[i];
		ans1 += (1ll * i * A[i]);
	}
	cin>>q;
	while(q--)
	{
		cin>>k;
		if(k==1)
			cout<<ans1<<' ';
		else{
			ll x = k ; ll cur = 1; int it = 1;ll ans = 0;
			while(cur < n)
			{
				ans = ans + (1ll * it * (S[min(cur+x-1,n-1)]-S[cur-1]));
				cur = cur + x;
				x = 1ll * x * k;
				it++;
			}
			cout<<ans<<' ';
		}
	}
	cout<<nl;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <set>
#include <queue>
#include <cmath>
#include <unordered_set>
#include <string>
using namespace std;

long long n;
long long a[100000];
long long ans[100001];

int main() {
	ios_base::sync_with_stdio(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	reverse(a, a + n);
	for (int i = 1; i < n; i++) {
		a[i] += a[i - 1];
	}

	for (int q = 2; q <= 100000; q++) {
		long long maxPow = 0;
		long long curr = 1;
		long long currAns = 0;
		while (curr < n - 1 || (curr == 1 && n != 1)) {
			maxPow++;
			curr *= q;
		}
		long long processed = 1;
		long long pw = 1;
		for (int j = 1; j <= maxPow; j++) {
			pw *= q;
			currAns += j * (a[min(processed + pw - 1, n - 1)] - a[processed - 1]);
			processed = min(processed + pw, n - 1);
		}
		ans[q] = currAns;
	}

	for (int i = 1; i < n; i++) {
		ans[1] += (a[i] - a[i - 1]) * i;
	}

	int q;
	cin >> q;
	for (int i = 0; i < q; i++) {
		int currQ;
		cin >> currQ;
		cout << ans[currQ] << " ";
	}

	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <set>
#include <queue>
#include <cmath>
#include <unordered_set>
#include <string>
using namespace std;

int n;
long long a[100000];
long long ans[100001];

int main() {
	ios_base::sync_with_stdio(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	reverse(a, a + n);
	for (int i = 1; i < n; i++) {
		a[i] += a[i - 1];
	}

	for (int q = 2; q <= 100000; q++) {
		int maxPow = 0;
		long long curr = 1;
		long long currAns = 0;
		while (curr < n - 1 || (curr == 1 && n != 1)) {
			maxPow++;
			curr *= q;
		}
		int processed = 1;
		int pw = 1;
		for (int j = 1; j <= maxPow; j++) {
			pw *= q;
			currAns += j * (a[min(processed + pw - 1, n - 1)] - a[processed - 1]);
			processed += pw;
		}
		ans[q] = currAns;
	}

	for (int i = 1; i < n; i++) {
		ans[1] += (a[i] - a[i - 1]) * i;
	}

	int q;
	cin >> q;
	for (int i = 0; i < q; i++) {
		int currQ;
		cin >> currQ;
		cout << ans[currQ] << " ";
	}

	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <set>
#include <queue>
#include <cmath>
#include <unordered_set>
#include <string>
using namespace std;

int n;
long long a[100000];
long long ans[100001];

int main() {
	ios_base::sync_with_stdio(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	reverse(a, a + n);
	for (int i = 1; i < n; i++) {
		a[i] += a[i - 1];
	}

	for (int q = 2; q <= 100000; q++) {
		int maxPow = 0;
		int curr = 1;
		long long currAns = 0;
		while (curr < n - 1 || (curr == 1 && n != 1)) {
			maxPow++;
			curr *= q;
		}
		int processed = 1;
		int pw = 1;
		for (int j = 1; j <= maxPow; j++) {
			pw *= q;
			currAns += j * (a[min(processed + pw - 1, n - 1)] - a[processed - 1]);
			processed += pw;
		}
		ans[q] = currAns;
	}

	for (int i = 1; i < n; i++) {
		ans[1] += (a[i] - a[i - 1]) * i;
	}

	int q;
	cin >> q;
	for (int i = 0; i < q; i++) {
		int currQ;
		cin >> currQ;
		cout << ans[currQ] << " ";
	}

	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <set>
#include <queue>
#include <cmath>
#include <unordered_set>
#include <string>
using namespace std;

int n;
long long a[100000];
long long ans[100000];

int main() {
	ios_base::sync_with_stdio(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	reverse(a, a + n);
	for (int i = 1; i < n; i++) {
		a[i] += a[i - 1];
	}
	for (int q = 2; q <= 100000; q++) {
		int maxPow = 0;
		int curr = 1;
		long long currAns = 0;
		while (curr < n - 1) {
			maxPow++;
			curr *= q;
		}
		int processed = 1;
		int pw = 1;
		for (int j = 1; j <= maxPow; j++) {
			pw *= q;
			currAns += j * (a[min(processed + pw - 1, n - 1)] - a[processed - 1]);
			processed += pw;
		}
		ans[q] = currAns;
	}

	for (int i = 1; i < n; i++) {
		ans[1] += (a[i] - a[i - 1]) * i;
	}

	int q;
	cin >> q;
	for (int i = 0; i < q; i++) {
		int currQ;
		cin >> currQ;
		cout << ans[currQ] << " ";
	}

	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <set>
#include <queue>
#include <cmath>
#include <unordered_set>
#include <string>
using namespace std;

long long n;
long long a[100000];
long long ans[100001];

int main() {
	ios_base::sync_with_stdio(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	reverse(a, a + n);
	for (int i = 1; i < n; i++) {
		a[i] += a[i - 1];
	}

	for (int q = 2; q <= 100000; q++) {
		int maxPow = 0;
		long long curr = 1;
		long long currAns = 0;
		while (curr < n - 1 || (curr == 1 && n != 1)) {
			maxPow++;
			curr *= q;
		}
		long long processed = 1;
		int pw = 1;
		for (int j = 1; j <= maxPow; j++) {
			pw *= q;
			currAns += j * (a[min(processed + pw - 1, n - 1)] - a[processed - 1]);
			processed = min(processed + pw, n - 1);
		}
		ans[q] = currAns;
	}

	for (int i = 1; i < n; i++) {
		ans[1] += (a[i] - a[i - 1]) * i;
	}

	int q;
	cin >> q;
	for (int i = 0; i < q; i++) {
		int currQ;
		cin >> currQ;
		cout << ans[currQ] << " ";
	}

	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <set>
#include <queue>
#include <cmath>
#include <unordered_set>
#include <string>
using namespace std;

long long n;
long long a[100000];
long long ans[100001];

int main() {
	ios_base::sync_with_stdio(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	reverse(a, a + n);
	for (int i = 1; i < n; i++) {
		a[i] += a[i - 1];
	}

	for (int q = 2; q <= 100000; q++) {
		long long maxPow = 0;
		long long curr = 1;
		long long currAns = 0;
		while (curr < n - 1 || (curr == 1 && n != 1)) {
			maxPow++;
			curr *= q;
		}
		long long processed = 0;
		long long pw = 1;
		for (int j = 1; j <= maxPow; j++) {
			pw *= q;
			currAns += j * (a[min(processed + pw, n - 1)] - a[processed]);
			//cout << currAns << endl;
			processed = min(processed + pw, n - 1);
		}
		ans[q] = currAns;
	}

	for (int i = 1; i < n; i++) {
		ans[1] += (a[i] - a[i - 1]) * i;
	}

	int q;
	cin >> q;
	for (int i = 0; i < q; i++) {
		int currQ;
		cin >> currQ;
		cout << ans[currQ] << " ";
	}

	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <set>
#include <queue>
#include <cmath>
#include <unordered_set>
#include <string>
using namespace std;

long long n;
long long a[100000];
long long ans[100001];

int main() {
	ios_base::sync_with_stdio(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	reverse(a, a + n);
	for (int i = 1; i < n; i++) {
		a[i] += a[i - 1];
	}

	for (int q = 2; q <= 100000; q++) {
		long long maxPow = 0;
		long long curr = 1;
		long long currAns = 0;
		while (curr < n - 1 || (curr == 1 && n != 1)) {
			maxPow++;
			curr *= q;
		}
		long long processed = 1;
		long long pw = 1;
		for (int j = 1; j <= maxPow; j++) {
			pw *= q;
			currAns += j * (a[min(processed + pw - 1, n - 1)] - a[processed - 1]);
			processed = min(processed + pw - 1, n - 1);
		}
		ans[q] = currAns;
	}

	for (int i = 1; i < n; i++) {
		ans[1] += (a[i] - a[i - 1]) * i;
	}

	int q;
	cin >> q;
	for (int i = 0; i < q; i++) {
		int currQ;
		cin >> currQ;
		cout << ans[currQ] << " ";
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
#define int long long
int n , k;
int v[100005];

int32_t main(){
	scanf("%lld" , &n );
	for(int i = 1 ; i <= n; i ++){
		scanf("%lld" , &v[i]);
	}
	sort(v + 1 , v + 1 + n , [&](int a , int b){
		return a > b;
	});
	int ans1 = 0;
	for(int i = 1 ; i <= n; i ++){
		ans1 += v[i] * (i-1);
		v[i] += v[i-1];
	}

	int q;
	scanf("%lld" , &q);
	while(q--){
		int x;
		scanf("%lld" , &x);
		if(x == 1){
			printf("%lld " , ans1);
		}
		else{
			int ans = 0;
			int curr = 0;
			int i  = 1, r = 1;
			while(i <= n){
				ans += (v[min(n , i + r -1)] - v[i-1]) * curr;
				i += r;
				r *= x;
				curr++;
			}
			printf("%lld " , ans);
		}
	}
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <map>
#define x first
#define y second
#define FOR(x,y) for(int x=0;x<y;x++)
using namespace std;
typedef long long ll;
const int MX=(int)1e6+5;
int N,q,k;
ll a[MX],pre[MX],dep[MX];
ll ans1;

int main()
{
    scanf("%d",&N);
    FOR(i,N)scanf("%lld",&a[i]),a[i]=-a[i];
    sort(a,a+N);
    FOR(i,N)a[i]=-a[i];
    FOR(i,N){pre[i+1]=a[i]+pre[i];dep[i]=1;}
    FOR(i,N){
        ans1+=i*a[i];
    }
    scanf("%d",&q);
    FOR(i,q){
        scanf("%d",&k);
        if(k==1){
            printf("%lld\n",ans1);
            continue;
        }
        ll ans=0;
        ll t=1;
        ll topt=0;
        for(int j=0;topt<=N;j++){
            topt+=t;
            dep[j]=min(t,N-topt+t);
            t*=k;

        }
        int ct=0;
        for(int j=0;ct<N;j++){
                //printf("%d\n",dep[j]);
            ans+=(pre[min((int)dep[j]+ct,N)]-pre[ct])*j;
            ct+=dep[j];
        }
        printf("%lld\n",ans);
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <map>
#define x first
#define y second
#define FOR(x,y) for(int x=0;x<y;x++)
using namespace std;
typedef long long ll;
const int MX=(int)1e5+5;
int N,q,k;
ll a[MX],pre[MX],dep[MX];
ll ans1;

int main()
{
    scanf("%d",&N);
    FOR(i,N)scanf("%lld",&a[i]),a[i]=-a[i];
    sort(a,a+N);
    FOR(i,N)a[i]=-a[i];
    FOR(i,N){pre[i+1]=a[i]+pre[i];dep[i]=1;}
    FOR(i,N){
        ans1+=i*a[i];
    }
    scanf("%d",&q);
    FOR(i,q){
        scanf("%d",&k);
        if(k==1){
            printf("%lld\n",ans1);
            continue;
        }
        ll ans=0;
        int t=1;
        for(int j=0;t<N;j++){
            dep[j]=t;
            t*=k;
        }
        int ct=0;
        for(int j=0;ct<N;j++){
                //printf("%d\n",dep[j]);
            ans+=(pre[min((int)dep[j]+ct,N)]-pre[ct])*j;
            ct+=dep[j];
        }
        printf("%lld\n",ans);
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <map>
#define x first
#define y second
#define FOR(x,y) for(int x=0;x<y;x++)
using namespace std;
typedef long long ll;
const int MX=(int)1e5+5;
int N,q,k;
ll a[MX],pre[MX],dep[MX];
ll ans1;

int main()
{
    scanf("%d",&N);
    FOR(i,N)scanf("%lld",&a[i]),a[i]=-a[i];
    sort(a,a+N);
    FOR(i,N)a[i]=-a[i];
    FOR(i,N){pre[i+1]=a[i]+pre[i];dep[i]=1;}
    FOR(i,N){
        ans1+=i*a[i];
    }
    scanf("%d",&q);
    FOR(i,q){
        scanf("%d",&k);
        if(k==1){
            printf("%lld\n",ans1);
            continue;
        }
        ll ans=0;
        ll t=1;
        ll topt=0;
        for(int j=0;topt<=N;j++){
            topt+=t;
            dep[j]=t;
            t*=k;

        }
        int ct=0;
        for(int j=0;ct<N;j++){
                //printf("%d\n",dep[j]);
            ans+=(pre[min((int)dep[j]+ct,N)]-pre[ct])*j;
            ct+=dep[j];
        }
        printf("%lld\n",ans);
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <map>
#define x first
#define y second
#define FOR(x,y) for(int x=0;x<y;x++)
using namespace std;
typedef long long ll;
const int MX=(int)1e5+5;
int N,q,k;
ll a[MX],pre[MX],dep[MX];
ll ans1;

int main()
{
    scanf("%d",&N);
    FOR(i,N)scanf("%lld",&a[i]),a[i]=-a[i];
    sort(a,a+N);
    FOR(i,N)a[i]=-a[i];
    FOR(i,N){pre[i+1]=a[i]+pre[i];dep[i]=1;}
    FOR(i,N){
        ans1+=i*a[i];
    }
    scanf("%d",&q);
    FOR(i,q){
        scanf("%d",&k);
        if(k==1){
            printf("%lld\n",ans1);
            continue;
        }
        ll ans=0;
        ll t=1;
        ll topt=1;
        for(int j=0;topt<N;j++){
            dep[j]=t;
            t*=k;
            topt+=t;
        }
        int ct=0;
        for(int j=0;ct<N;j++){
                //printf("%d\n",dep[j]);
            ans+=(pre[min((int)dep[j]+ct,N)]-pre[ct])*j;
            ct+=dep[j];
        }
        printf("%lld\n",ans);
    }
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#define ll long long
using namespace std;
const int maxn=1e5+10;
ll a[maxn],sum[maxn];
ll ans[maxn];
int n,q;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    sort(a+1,a+n+1);
    for(int i=1;i<=n;i++)
        sum[i]=sum[i-1]+a[i];
    cin>>q;
    while(q--)
    {
        int k;
        cin>>k;
        if(ans[k]!=0)
        {
            cout<<ans[k]<<" ";
            continue;
        }
        int l=n-1;
        int step=1;
        int num=k;
        while(1)
        {
            //cout<<step<<" "<<l<<endl;
            if(l-num+1>=1)
            {
                ans[k]+=(sum[l]-sum[l-num])*step;
                l-=num;
                step++;
                num*=k;
                cout<<l<<endl;
                if(l==0) break;
            }
            else
            {
                ans[k]+=(sum[l]-sum[1]+a[1])*step;
                cout<<l<<endl;
                break;
            }
            if(l<=0) break;
        }
        cout<<ans[k]<<" ";
    }
    cout<<endl;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#define ll long long
using namespace std;
const int maxn=1e5+10;
ll a[maxn],sum[maxn];
ll ans[maxn];
int n,q;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    sort(a+1,a+n+1);
    for(int i=1;i<=n;i++)
        sum[i]=sum[i-1]+a[i];
    cin>>q;
    while(q--)
    {
        int k;
        cin>>k;
        if(ans[k]!=0)
        {
            cout<<ans[k]<<" ";
            continue;
        }
        ll l=n-1;
        ll step=1;
        ll num=k;
        while(1)
        {
            //cout<<step<<" "<<l<<endl;
            if(l-num+1>=1)
            {
                ans[k]+=(sum[l]-sum[l-num])*step;
                l-=num;
                step++;
                num*=k;
                //cout<<l<<endl;
                if(l==0) break;
            }
            else
            {
                ans[k]+=(sum[l]-sum[1]+a[1])*step;
                //cout<<l<<endl;
                break;
            }
            if(l<=0) break;
        }
        cout<<ans[k]<<" ";
    }
    cout<<endl;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#define ll long long
using namespace std;
const int maxn=1e5+10;
ll a[maxn],sum[maxn];
ll ans[maxn];
int n,q;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    sort(a+1,a+n+1);
    for(int i=1;i<=n;i++)
        sum[i]=sum[i-1]+a[i];
    cin>>q;
    while(q--)
    {
        int k;
        cin>>k;
        if(ans[k]!=0)
        {
            cout<<ans[k]<<" ";
            continue;
        }
        int l=n-1;
        int step=1;
        int num=k;
        while(1)
        {
            //cout<<step<<" "<<l<<endl;
            if(l-num+1>=1)
            {
                ans[k]+=(sum[l]-sum[l-num])*step;
                l-=num;
                step++;
                num*=k;
                //cout<<l<<endl;
                if(l==0) break;
            }
            else
            {
                ans[k]+=(sum[l]-sum[1]+a[1])*step;
                //cout<<l<<endl;
                break;
            }
            if(l<=0) break;
        }
        cout<<ans[k]<<" ";
    }
    cout<<endl;
}


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

using namespace __gnu_pbds;
using namespace std;

#define inf 1013161010
#define ninf -1013161010
#define mod 1000000007
#define ll long long
#define lf long double
#define in(x) scanf("%d",&x);
#define sz(x) ((int)x.size())
#define lld l64d
#define rep(i,n) for(i=0;i<n;i++)
#define rrep(i,n) for(i=n-1;i>=0;i--)
#define rep1(i,a,b) for(i=a;i<=b;i++)
#define rrep1(i,a,b) for(i=a;i>=b;i--)
#define stlfor(i,t) for(auto i =t.begin();i!=t.end();i++)
#define fr freopen("x.txt","r",stdin)
#define frc freopen("y.txt","w",stdout)
#define all(x) x.begin(),x.end()
#define set0(x) memset(x,0,sizeof(x))
#define dbg cout<<"yo "<<endl;
#define pset(n) fixed<<showpoint<<setprecision(n)

#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpii vector<pair<int,int> >
#define si set<int>
#define mii map<int,int>
#define umii unordered_map<int,int>
#define vi vector<int>
#define pb push_back
#define ff first
#define ss second
#define mp make_pair

typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> OST;

ll toint(const string &s) { stringstream ss; ss << s; ll x; ss >> x; return x; }
string tostring ( ll number ){  stringstream ss; ss<< number; return ss.str();}

const lf pi = 2*acos(0);
const int nn = 2123456;

ll gcd(ll a,ll b){return (b==0)? a:gcd(b,a%b); }
void nope(int num = 0){ if(num==0) cout<<"NO"; else cout<<"-1"; exit(0); }

ll a[nn],res[nn],sum[nn];
void solve()
{
    ll i,j,n,q,r,ans,x,mul=1;

    cin>>n;
    rep1(i,1,n)
        cin>>a[i];

    sort(a+1,a+n+1);

    sum[1]=a[1];
    for(i=2;i<=n;i++)
        sum[i]= sum[i-1] + a[i];

    ll lim;
    for(i=1;i<=100000;i++)
    {
        //cout<<i<<endl;
        if(n-1<=i)
        {
            res[i] = sum[n-1];
            continue;
        }
        lim = i;
        mul = 1LL;
        r = n-1;
        ans = 0;
        while(true)
        {
            ans+=(mul*(sum[r]-sum[max(r-lim,0LL)]));
            r=max(r-lim,0LL);
            mul++;
            lim*=i;
            if(r==0)
                break;
        }
        res[i] = ans;
    }

    cin>>q;
    while(q--)
    {
        cin>>x;
        cout<<res[x]<<" ";
    }
    cout<<endl;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    ll i,j,n,tt;
    tt=1;
    //cin>>tt;
    while(tt--)
    {
        solve();
    }
    return 0;
}


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

using namespace __gnu_pbds;
using namespace std;

#define inf 1013161010
#define ninf -1013161010
#define mod 1000000007
#define ll long long
#define lf long double
#define in(x) scanf("%d",&x);
#define sz(x) ((int)x.size())
#define lld l64d
#define rep(i,n) for(i=0;i<n;i++)
#define rrep(i,n) for(i=n-1;i>=0;i--)
#define rep1(i,a,b) for(i=a;i<=b;i++)
#define rrep1(i,a,b) for(i=a;i>=b;i--)
#define stlfor(i,t) for(auto i =t.begin();i!=t.end();i++)
#define fr freopen("x.txt","r",stdin)
#define frc freopen("y.txt","w",stdout)
#define all(x) x.begin(),x.end()
#define set0(x) memset(x,0,sizeof(x))
#define dbg cout<<"yo "<<endl;
#define pset(n) fixed<<showpoint<<setprecision(n)

#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpii vector<pair<int,int> >
#define si set<int>
#define mii map<int,int>
#define umii unordered_map<int,int>
#define vi vector<int>
#define pb push_back
#define ff first
#define ss second
#define mp make_pair

typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> OST;

ll toint(const string &s) { stringstream ss; ss << s; ll x; ss >> x; return x; }
string tostring ( ll number ){  stringstream ss; ss<< number; return ss.str();}

const lf pi = 2*acos(0);
const int nn = 2123456;

ll gcd(ll a,ll b){return (b==0)? a:gcd(b,a%b); }
void nope(int num = 0){ if(num==0) cout<<"NO"; else cout<<"-1"; exit(0); }

ll a[nn],sum[nn];
void solve()
{
    ll i,j,n,q,r,ans,x,mul=1;
    cin>>n;
    rep1(i,1,n)
        cin>>a[i];

    sort(a+1,a+n+1);

    sum[1]=a[1];
    for(i=2;i<=n;i++)
        sum[i]= sum[i-1] + a[i];
    ll lim;
    cin>>q;
    while(q--)
    {
        cin>>x;
        mul = 1;
        r = n-1;
        lim = x;
        ans = 0;
        while(true)
        {
            ans+=(mul*(sum[r]-sum[max(r-lim,0LL)]));
            r=max(r-lim,0LL);
            mul++;
            lim*=x;
            if(r==0)
                break;
        }
        cout<<ans<<" ";
    }

}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    ll i,j,n,tt;
    tt=1;
    //cin>>tt;
    while(tt--)
    {
        solve();
    }
    return 0;
}


////////////////////////////////////////////    _LeMur_
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cassert>
#include <chrono>
#include <random>
#include <bitset>
#include <cstdio>
#include <vector>
#include <string>
#include <ctime>
#include <stack>
#include <queue>
#include <cmath>
#include <list>
#include <map>
#include <set>

using namespace std;

const int N = 200005;
const int inf = 1000 * 1000 * 1000;
const int mod = 7340033;

int n , q;
int a[N];

long long pref[N];
long long pat;

long long solve(int k){
    if(k == 1)return pat;
    long long answ = 0;
    int r = n;
    int x = 1;
    int h = 0;
    while(r){
        int l = r - x + 1;
        l = max(l , 1);
        answ += (pref[r] - pref[l - 1]) * 1ll * h;
        ///
        ++h;
        r = l - 1;
        x *= k;
    }
    return answ;
}

int main(){
	mt19937 myrand(chrono::steady_clock::now().time_since_epoch().count());
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    sort(a + 1 , a + n + 1);
    for(int i=1;i<=n;i++){
        pref[i] = pref[i - 1] + a[i];
        pat += (n - i) * 1ll * a[i];
    }
    scanf("%d",&q);
    while(q--){
        int k;
        scanf("%d",&k);
        printf("%lld\n",solve(k));
    }
	return 0;
}


////////////////////////////////////////////    _LeMur_
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cassert>
#include <chrono>
#include <random>
#include <bitset>
#include <cstdio>
#include <vector>
#include <string>
#include <ctime>
#include <stack>
#include <queue>
#include <cmath>
#include <list>
#include <map>
#include <set>

using namespace std;

const long long N = 200005;
const long long inf = 1000 * 1000 * 1000;
const long long mod = 7340033;

long long n , q;
long long a[N];

long long pref[N];
long long pat;

long long solve(long long k){
    if(k == 1)return pat;
    long long answ = 0;
    long long r = n;
    long long x = 1;
    long long h = 0;
    while(r){
        long long l = r - x + 1;
        l = max(l , 1ll);
        answ += (pref[r] - pref[l - 1]) * 1ll * h;
        ///
        ++h;
        r = l - 1;
        x *= k;
    }
    return answ;
}

int main(){
	mt19937 myrand(chrono::steady_clock::now().time_since_epoch().count());
    scanf("%lld",&n);
    for(long long i=1;i<=n;i++){
        scanf("%lld",&a[i]);
    }
    sort(a + 1 , a + n + 1);
    for(long long i=1;i<=n;i++){
        pref[i] = pref[i - 1] + a[i];
        pat += (n - i) * 1ll * a[i];
    }
    scanf("%lld",&q);
    while(q--){
        long long k;
        scanf("%lld",&k);
        printf("%lld\n",solve(k));
    }
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define N 200005
ll a[N], n, res = 0, p[N], q, x, special = 0;
ll ans(ll x, ll y)
{
	if (x <= 0)
		return p[y];
	return p[y] - p[x];
}
void in()
{
	scanf("%lld", &n);
	for (int i = 1; i <= n; i++)
		scanf("%lld", &a[i]);
}
void solve()
{
	sort(a + 1, a + (n + 1));
	for (int i = 1; i <= n; i++)
		p[i] = p[i - 1] + a[i], special += (p[i] * (i!=n));
	/*for (int i = 1; i <= n; i++)
		cout << a[i] << endl;*/
	//cout << "dljdflkgdfg\n";
	scanf("%lld", &q);
	while (q--)
	{
		scanf("%lld", &x);
		res = 0;
		if (x == 1)
			res = special;
		else
			for (int i = n - 1, j = x, k = 1; i > 0; i -= j, j *= x, k++)
			{
				if(i>0)
				res += (k*ans(i - j, i));
				//cout << k << " " << ans(i - j + 1, i) << endl;
			}
		printf("%lld", res);
		if (q != 0)
			printf(" ");
		else
			printf("\n");
	}
}
int main()
{
	in();
	solve();
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define N 2000006
ll a[N], n, res = 0, p[N], q, x, special = 0, ans[N];
void go()
{
	scanf("%lld", &n);
	for (int i = 0; i < n; i++)
		scanf("%lld", &a[i]);
}
void solve()
{
	sort(a, a + n);
	for (int i = 1; i <= n; i++)
		p[i] = p[i - 1] + a[i - 1], special += (p[i] * (i!=n));
	/*for (int i = 1; i <= n; i++)
		cout << a[i] << endl;*/
	//cout << "dljdflkgdfg\n";
	scanf("%lld", &q);
	for (int t = 0; t < q;t++)
	{
		scanf("%lld", &x);
		res = 0;
		if (x == 1)
			res = special;
		else
			for (int i = n - 1, j = x, k = 1; i > 0; i -= j, j *= x, k++)
			{
				if (i - j >= 0)
					res += (p[i] - p[i - j])*k;
				else if(i >= 0)
					res += p[i] * k;
				//cout << k << " " << ans(i - j + 1, i) << endl;
			}
		ans[t] = res;
	}
	printf("%lld", ans[0]);
	for (int i = 1; i < q;i++)
		printf(" %lld", ans[i]);
	printf("\n");
}
int main()
{
	go();
	solve();
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long unsigned int ll;
#define N 2000006
ll a[N], n, res = 0, p[N], q, x, special = 0, ans[N];
void go()
{
	scanf("%llu", &n);
	for (int i = 0; i < n; i++)
		scanf("%llu", &a[i]);
}
void solve()
{
	sort(a, a + n);
	for (int i = 1; i <= n; i++)
		p[i] = p[i - 1] + a[i - 1], special += (p[i] * (i!=n));
	/*for (int i = 1; i <= n; i++)
		cout << a[i] << endl;*/
	//cout << "dljdflkgdfg\n";
	scanf("%llu", &q);
	for (int t = 0; t < q;t++)
	{
		scanf("%llu", &x);
		res = 0;
		if (x == 1)
			res = special;
		else
			for (int i = n - 1, j = x, k = 1; i > 0; i -= j, j *= x, k++)
			{
				if (i - j >= 0)
					res += (p[i] - p[i - j])*k;
				else if(i >= 0)
					res += p[i] * k;
				//cout << k << " " << ans(i - j + 1, i) << endl;
			}
		ans[t] = res;
	}
	printf("%llu", ans[0]);
	for (int i = 1; i < q;i++)
		printf(" %llu", ans[i]);
	printf("\n");
}
int main()
{
	go();
	solve();
	return 0;
}


#include <iostream>

using namespace std;

int main()

{
	int n;
	scanf("%d",&n);
	if (n%2==0) for (int i=1; i<=n/2; i++)
			printf("1");
	else {
		printf("7");
		for (int j=1; j<n/2; j++)
		printf("1");
	}
	return 0;
}


#include <iostream>
//#include <string>
using namespace std;

int main()
{
	int n;
	cin>>n;
	if (n%2==0) for (int i=1; i<=n/2; i++) cout<<"1";
	else {
		if (n%2==1) {
		for (int i=1; i<n/2; i++) cout<<"1";
			cout<<"7";
		}
	}
	return 0;
}


#include <iostream>
#include <string>
using namespace std;

int main()
{
	int n,m,k,c1,c2,s=0,l=0;
	cin>>n;
	if (n%2==0) for (int i=1; i<=n/6; i++) cout<<"1";
	else {
		if (n%1==1) {
		for (int i=1; i<n/6; i++) cout<<"9";
			cout<<"7";
		}

	}
	return 0;
}


#include <iostream>

using namespace std;

int main()

{
	int n;
	scanf("%d",&n);
	if (n%2==0) for (int i=1; i<=n/2; i++)
			printf("1");
	else {
		for (int j=1; j<n/2; j++)
		printf("1");
		printf("7");
	}
	return 0;
}


#include <stdio.h>
int main(void)
{
    int n,i;
    scanf("%d",&n);
    if (n%2) {
        for (i=0;i<n/2-1;i++) printf("1");
        printf("7\n");
    } else {
        for (i=0;i<n/2;i++) printf("1");
        printf("\n");
    }
    return 0;
}


#include <stdio.h>
int main(void)
{
    int n,i;
    scanf("%d",&n);
    if (n%2) {
            printf("7\n");
        for (i=0;i<n/2-1;i++) printf("1");

    } else {
        for (i=0;i<n/2;i++) printf("1");
        printf("\n");
    }
    return 0;
}


#include <stdio.h>
int main(void)
{
    int n,i;
    scanf("%d",&n);
    if (n%2) {
            printf("7");
        for (i=0;i<n/2-1;i++) printf("1");
        printf("\n");

    } else {
        for (i=0;i<n/2;i++) printf("1");
        printf("\n");
    }
    return 0;
}


#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <cassert>
#include <set>
#include <string.h>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <time.h>
#include <complex>
#include <climits>
#include <stdarg.h>
#include <iomanip>
#include <initializer_list>
#include <fstream>

using namespace std;

#define gcd __gcd
#define fill(A, val) memset(A,val,sizeof(A))
#define rep(i, a, n) for (long long i=a;i<n;++i)
#define per(i, n, a) for (long long i=n-1;i>=a;--i)
#define all(V) V.begin(),V.end()
#define SZ(V) (int)V.size()
#define pb push_back
//#define mp make_pair
#define ff first
#define ss second
#define min3(a, b, c)     min(a,min(b,c))
#define max3(a, b, c)     max(a,max(b,c))
#define min4(a, b, c, d)   min(min(a,b),min(c,d))
#define max4(a, b, c, d)   max(max(a,b),max(c,d))
#define max5(a, b, c, d, e) max(max3(a,b,c),max(d,e))
#define min5(a, b, c, d, e) min(min3(a,b,c),min(d,e))
#define max6(a, b, c, d, e, f) max(max3(a,b,c),max3(d,e,f))
#define min6(a, b, c, d, e, f) min(min3(a,b,c),min3(d,e,f))

typedef long long LL;
typedef long double DD;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<DD, DD> PDD;
typedef map<int, int> MII;
typedef map<LL, LL> MLL;

const double eps = 1e-8;
const double Pi = 3.14159265358979323846264338327950288419716939937510;
const long long INF = 1LL << 60;
//const int INF=10000000000;
const long long MAX5 = 100001;
const long long MAX6 = 1000001;
const long long MOD = 1e9 + 7;

//1.0000000000000000001

long long minn(initializer_list<LL> list) {
    long long mn = INF;
    for (LL e: list)mn = min(mn, e);
    return mn;
}

long long maxn(initializer_list<LL> list) {
    long long mx = -INF;
    for (LL e: list)mx = max(mx, e);
    return mx;
}

//ax+by=gcd(a,b)
inline LL egcd(LL a, LL b, LL &x, LL &y) {
    if (!a) {
        x = 0;
        y = 1;
        return b;
    }
    LL x1, y1;
    LL d = egcd(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}

inline LL addMod(LL a, LL b, LL m = MOD) {
    return ((int64_t) a + b) % m;
}

inline LL mulMod(LL a, LL b, LL m = MOD) {
    return ((int64_t) a * b) % m;
}

inline LL divMod(LL a, LL b, int m = MOD) {
    LL x, y;
    LL g = egcd(b, m, x, y);
    if (g != 1) {
        cerr << "Bad gcd!" << endl;
    }
    x = (x % m + m) % m;
    return mulMod(a, x, m);
}

LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }

LL min(LL a, LL b) { return a < b ? a : b; }

LL max(LL a, LL b) { return a < b ? b : a; }

string ekv(string a) {
    if (a.size() & 1)return a;
    string x = ekv(a.substr(0, a.size() / 2));
    string y = ekv(a.substr(a.size() / 2));
    return min(x + y, y + x);
}

string ups(string s) {
    transform(s.begin(), s.end(), s.begin(), ::toupper);
    return s;
}

string lows(string s) {
    transform(s.begin(), s.end(), s.begin(), ::tolower);
    return s;
}

bool isPow2(LL a) { return !(a & (a - 1)); }

LL poww(LL a, LL b) {
    if (b == 0)return 1;
    if (b % 2 == 0)return poww(a, b / 2) * poww(a, b / 2);
    else return poww(a, b - 1) * a;
}

inline LL bSearch(LL *arr, LL v, LL l, LL r) {
    LL m;
    while (l < r) {
        m = l + (r - l) / 2;
        v <= arr[m] ? r = m : l = m + 1;
    }
    if (arr[r] == v)return r; else return INF;
}

inline LL low_bound(LL *arr, LL v, LL l, LL r) {
    LL m;
    while (l < r) {
        m = l + (r - l) / 2;

        if (v < arr[m])
            r = m;
        else l = m + 1;
    }
    if (arr[l] < v)return l; else return INF;
}

long long divpole(LL a, LL b) {
    return a * poww(b, MOD - 2) % MOD;
}

bool isInteger(DD d) { return !(ceil(d) - LL(d)); }

LL mod(LL a) {
    a %= MOD;
    if (a < 0)a += MOD;
    return a;
}

inline bool isPrime(LL n) {
    for (int i = 2; i * i <= n; ++i)if (n % i == 0)return false;
    return true;
}

bool cmpr(string a, string b) {

}

//
//vector<char> prime (n+1, true);
//prime[0] = prime[1] = false;
//for (int i=2; i*i<=n; ++i)
//if (prime[i])
//for (int j=2; j<=n/i; j++)
//if (prime[i*j]) prime[i*j] = false;

//LL A[2 * MAX6];
//LL B[2 * MAX6];
//LL C[2 * MAX6];

LL maxSubArraySum(LL a[], LL size) {
    LL max_so_far = INT_MIN, max_ending_here = 0;

    for (int i = 1; i < size; ++i) {
        max_ending_here = max_ending_here + a[i];
        if (max_so_far < max_ending_here)
            max_so_far = max_ending_here;

        if (max_ending_here < 0)
            max_ending_here = 0;
    }
    return max_so_far;
}

map<LL, LL> mp;
vector<LL> v;
string res = "0";

string bigStr(string a, string b) {

    if (a.size() > b.size())return a;
    else if (b.size() > a.size())return b;
    else {

        for (int i = 0; i < a.size(); ++i)
            if ((a[i] - '0') < (b[i] - '0')) {
                return b;
            }
        return a;
    }

}

void r(LL sz, string s) {
    if (sz == 0) {
        res = bigStr(res, s);
        reverse(all(s));
        res=bigStr(res,s);
        return;
    } else {

        for (int i = v.size() - 1; i >= 0; --i) {

            if (sz >= v[i]) {
                string c = "_";
                c[0] = (char) (mp[v[i]] + '0');
                string t = s + c;

                r(sz - v[i], t);
            }

        }

    }

}

int main() {
    ios_base::sync_with_stdio(false);
    //cin.tie();
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    mp[2] = 1;
    mp[4] = 4;
    mp[5] = 5;
    mp[3] = 7;
    mp[7] = 8;
    mp[6] = 9;

    v.pb(2);
    v.pb(4);
    v.pb(5);
    v.pb(3);
    v.pb(7);
    v.pb(6);

    LL n;
    cin >> n;

    r(n, "");

    cout << res;

}


#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <cassert>
#include <set>
#include <string.h>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <time.h>
#include <complex>
#include <climits>
#include <stdarg.h>
#include <iomanip>
#include <initializer_list>
#include <fstream>

using namespace std;

#define gcd __gcd
#define fill(A, val) memset(A,val,sizeof(A))
#define rep(i, a, n) for (long long i=a;i<n;++i)
#define per(i, n, a) for (long long i=n-1;i>=a;--i)
#define all(V) V.begin(),V.end()
#define SZ(V) (int)V.size()
#define pb push_back
//#define mp make_pair
#define ff first
#define ss second
#define min3(a, b, c)     min(a,min(b,c))
#define max3(a, b, c)     max(a,max(b,c))
#define min4(a, b, c, d)   min(min(a,b),min(c,d))
#define max4(a, b, c, d)   max(max(a,b),max(c,d))
#define max5(a, b, c, d, e) max(max3(a,b,c),max(d,e))
#define min5(a, b, c, d, e) min(min3(a,b,c),min(d,e))
#define max6(a, b, c, d, e, f) max(max3(a,b,c),max3(d,e,f))
#define min6(a, b, c, d, e, f) min(min3(a,b,c),min3(d,e,f))

typedef long long LL;
typedef long double DD;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<DD, DD> PDD;
typedef map<int, int> MII;
typedef map<LL, LL> MLL;

const double eps = 1e-8;
const double Pi = 3.14159265358979323846264338327950288419716939937510;
const long long INF = 1LL << 60;
//const int INF=10000000000;
const long long MAX5 = 100001;
const long long MAX6 = 1000001;
const long long MOD = 1e9 + 7;

//1.0000000000000000001

long long minn(initializer_list<LL> list) {
    long long mn = INF;
    for (LL e: list)mn = min(mn, e);
    return mn;
}

long long maxn(initializer_list<LL> list) {
    long long mx = -INF;
    for (LL e: list)mx = max(mx, e);
    return mx;
}

//ax+by=gcd(a,b)
inline LL egcd(LL a, LL b, LL &x, LL &y) {
    if (!a) {
        x = 0;
        y = 1;
        return b;
    }
    LL x1, y1;
    LL d = egcd(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}

inline LL addMod(LL a, LL b, LL m = MOD) {
    return ((int64_t) a + b) % m;
}

inline LL mulMod(LL a, LL b, LL m = MOD) {
    return ((int64_t) a * b) % m;
}

inline LL divMod(LL a, LL b, int m = MOD) {
    LL x, y;
    LL g = egcd(b, m, x, y);
    if (g != 1) {
        cerr << "Bad gcd!" << endl;
    }
    x = (x % m + m) % m;
    return mulMod(a, x, m);
}

LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }

LL min(LL a, LL b) { return a < b ? a : b; }

LL max(LL a, LL b) { return a < b ? b : a; }

string ekv(string a) {
    if (a.size() & 1)return a;
    string x = ekv(a.substr(0, a.size() / 2));
    string y = ekv(a.substr(a.size() / 2));
    return min(x + y, y + x);
}

string ups(string s) {
    transform(s.begin(), s.end(), s.begin(), ::toupper);
    return s;
}

string lows(string s) {
    transform(s.begin(), s.end(), s.begin(), ::tolower);
    return s;
}

bool isPow2(LL a) { return !(a & (a - 1)); }

LL poww(LL a, LL b) {
    if (b == 0)return 1;
    if (b % 2 == 0)return poww(a, b / 2) * poww(a, b / 2);
    else return poww(a, b - 1) * a;
}

inline LL bSearch(LL *arr, LL v, LL l, LL r) {
    LL m;
    while (l < r) {
        m = l + (r - l) / 2;
        v <= arr[m] ? r = m : l = m + 1;
    }
    if (arr[r] == v)return r; else return INF;
}

inline LL low_bound(LL *arr, LL v, LL l, LL r) {
    LL m;
    while (l < r) {
        m = l + (r - l) / 2;

        if (v < arr[m])
            r = m;
        else l = m + 1;
    }
    if (arr[l] < v)return l; else return INF;
}

long long divpole(LL a, LL b) {
    return a * poww(b, MOD - 2) % MOD;
}

bool isInteger(DD d) { return !(ceil(d) - LL(d)); }

LL mod(LL a) {
    a %= MOD;
    if (a < 0)a += MOD;
    return a;
}

inline bool isPrime(LL n) {
    for (int i = 2; i * i <= n; ++i)if (n % i == 0)return false;
    return true;
}

bool cmpr(string a, string b) {

    if(a.size()>b.size())return a>b;
    else{

        for(int i = 0; i < a.size(); ++i)
        if ((a[i] - '0') < (b[i] - '0'))
        {
            return b>a;
        }
        return a>b;

    }

}

//
//vector<char> prime (n+1, true);
//prime[0] = prime[1] = false;
//for (int i=2; i*i<=n; ++i)
//if (prime[i])
//for (int j=2; j<=n/i; j++)
//if (prime[i*j]) prime[i*j] = false;

//LL A[2 * MAX6];
//LL B[2 * MAX6];
//LL C[2 * MAX6];

LL maxSubArraySum(LL a[], LL size)
{
    LL max_so_far = INT_MIN, max_ending_here = 0;

    for (int i = 1; i <size; ++i)
    {
        max_ending_here = max_ending_here + a[i];
        if (max_so_far < max_ending_here)
            max_so_far = max_ending_here;

        if (max_ending_here < 0)
            max_ending_here = 0;
    }
    return max_so_far;
}

map<LL,LL>mp;
vector<LL> v;
vector<string>res;

void r(LL sz, string s)
{
    if(sz==0){
        res.pb(s);
        return;
    }else{

        for(int i=v.size()-1;i>=0;--i){

            if(sz>=v[i])
            {
                string c="_";
                c[0]= (char) (mp[v[i]] + '0');
                string t=s+c;

                r(sz-v[i], t);
            }

        }

    }

}

int main() {
    ios_base::sync_with_stdio(false);
    //cin.tie();
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    mp[2]=1;
    mp[4]=4;
    mp[5]=5;
    mp[3]=7;
    mp[7]=8;
    mp[6]=9;

    v.pb(2);
    v.pb(4);
    v.pb(5);
    v.pb(3);
    v.pb(7);
    v.pb(6);

    LL n;
    cin>>n;

    r(n,"");

    sort(all(res),cmpr);

    //for(string s:res)
    //    cout<<s<<"\n";

    string t=res[res.size()-1];
    reverse(all(res[res.size()-1]));
    cout<<max(res[res.size()-1], t);

}


#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <cassert>
#include <set>
#include <string.h>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <time.h>
#include <complex>
#include <climits>
#include <stdarg.h>
#include <iomanip>
#include <initializer_list>
#include <fstream>

using namespace std;

#define gcd __gcd
#define fill(A, val) memset(A,val,sizeof(A))
#define rep(i, a, n) for (long long i=a;i<n;++i)
#define per(i, n, a) for (long long i=n-1;i>=a;--i)
#define all(V) V.begin(),V.end()
#define SZ(V) (int)V.size()
#define pb push_back
//#define mp make_pair
#define ff first
#define ss second
#define min3(a, b, c)     min(a,min(b,c))
#define max3(a, b, c)     max(a,max(b,c))
#define min4(a, b, c, d)   min(min(a,b),min(c,d))
#define max4(a, b, c, d)   max(max(a,b),max(c,d))
#define max5(a, b, c, d, e) max(max3(a,b,c),max(d,e))
#define min5(a, b, c, d, e) min(min3(a,b,c),min(d,e))
#define max6(a, b, c, d, e, f) max(max3(a,b,c),max3(d,e,f))
#define min6(a, b, c, d, e, f) min(min3(a,b,c),min3(d,e,f))

typedef long long LL;
typedef long double DD;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<DD, DD> PDD;
typedef map<int, int> MII;
typedef map<LL, LL> MLL;

const double eps = 1e-8;
const double Pi = 3.14159265358979323846264338327950288419716939937510;
const long long INF = 1LL << 60;
//const int INF=10000000000;
const long long MAX5 = 100001;
const long long MAX6 = 1000001;
const long long MOD = 1e9 + 7;

//1.0000000000000000001

long long minn(initializer_list<LL> list) {
    long long mn = INF;
    for (LL e: list)mn = min(mn, e);
    return mn;
}

long long maxn(initializer_list<LL> list) {
    long long mx = -INF;
    for (LL e: list)mx = max(mx, e);
    return mx;
}

//ax+by=gcd(a,b)
inline LL egcd(LL a, LL b, LL &x, LL &y) {
    if (!a) {
        x = 0;
        y = 1;
        return b;
    }
    LL x1, y1;
    LL d = egcd(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}

inline LL addMod(LL a, LL b, LL m = MOD) {
    return ((int64_t) a + b) % m;
}

inline LL mulMod(LL a, LL b, LL m = MOD) {
    return ((int64_t) a * b) % m;
}

inline LL divMod(LL a, LL b, int m = MOD) {
    LL x, y;
    LL g = egcd(b, m, x, y);
    if (g != 1) {
        cerr << "Bad gcd!" << endl;
    }
    x = (x % m + m) % m;
    return mulMod(a, x, m);
}

LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }

LL min(LL a, LL b) { return a < b ? a : b; }

LL max(LL a, LL b) { return a < b ? b : a; }

string ekv(string a) {
    if (a.size() & 1)return a;
    string x = ekv(a.substr(0, a.size() / 2));
    string y = ekv(a.substr(a.size() / 2));
    return min(x + y, y + x);
}

string ups(string s) {
    transform(s.begin(), s.end(), s.begin(), ::toupper);
    return s;
}

string lows(string s) {
    transform(s.begin(), s.end(), s.begin(), ::tolower);
    return s;
}

bool isPow2(LL a) { return !(a & (a - 1)); }

LL poww(LL a, LL b) {
    if (b == 0)return 1;
    if (b % 2 == 0)return poww(a, b / 2) * poww(a, b / 2);
    else return poww(a, b - 1) * a;
}

inline LL bSearch(LL *arr, LL v, LL l, LL r) {
    LL m;
    while (l < r) {
        m = l + (r - l) / 2;
        v <= arr[m] ? r = m : l = m + 1;
    }
    if (arr[r] == v)return r; else return INF;
}

inline LL low_bound(LL *arr, LL v, LL l, LL r) {
    LL m;
    while (l < r) {
        m = l + (r - l) / 2;

        if (v < arr[m])
            r = m;
        else l = m + 1;
    }
    if (arr[l] < v)return l; else return INF;
}

long long divpole(LL a, LL b) {
    return a * poww(b, MOD - 2) % MOD;
}

bool isInteger(DD d) { return !(ceil(d) - LL(d)); }

LL mod(LL a) {
    a %= MOD;
    if (a < 0)a += MOD;
    return a;
}

inline bool isPrime(LL n) {
    for (int i = 2; i * i <= n; ++i)if (n % i == 0)return false;
    return true;
}

bool cmpr(string a, string b) {

}

//
//vector<char> prime (n+1, true);
//prime[0] = prime[1] = false;
//for (int i=2; i*i<=n; ++i)
//if (prime[i])
//for (int j=2; j<=n/i; j++)
//if (prime[i*j]) prime[i*j] = false;

//LL A[2 * MAX6];
//LL B[2 * MAX6];
//LL C[2 * MAX6];

LL maxSubArraySum(LL a[], LL size) {
    LL max_so_far = INT_MIN, max_ending_here = 0;

    for (int i = 1; i < size; ++i) {
        max_ending_here = max_ending_here + a[i];
        if (max_so_far < max_ending_here)
            max_so_far = max_ending_here;

        if (max_ending_here < 0)
            max_ending_here = 0;
    }
    return max_so_far;
}

map<int,int> mp;
vector<int> v;

int main() {
    ios_base::sync_with_stdio(false);
    //cin.tie();
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    LL n;
    cin>>n;
    if(n%2==0)
    {
        rep(i,0,n/2)cout<<1;
    }
    else{
        cout<<7;
        rep(i,0,n/2-1)cout<<1;
    }

}


#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <cassert>
#include <set>
#include <string.h>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <time.h>
#include <complex>
#include <climits>
#include <stdarg.h>
#include <iomanip>
#include <initializer_list>
#include <fstream>

using namespace std;

#define gcd __gcd
#define fill(A, val) memset(A,val,sizeof(A))
#define rep(i, a, n) for (long long i=a;i<n;++i)
#define per(i, n, a) for (long long i=n-1;i>=a;--i)
#define all(V) V.begin(),V.end()
#define SZ(V) (int)V.size()
#define pb push_back
//#define mp make_pair
#define ff first
#define ss second
#define min3(a, b, c)     min(a,min(b,c))
#define max3(a, b, c)     max(a,max(b,c))
#define min4(a, b, c, d)   min(min(a,b),min(c,d))
#define max4(a, b, c, d)   max(max(a,b),max(c,d))
#define max5(a, b, c, d, e) max(max3(a,b,c),max(d,e))
#define min5(a, b, c, d, e) min(min3(a,b,c),min(d,e))
#define max6(a, b, c, d, e, f) max(max3(a,b,c),max3(d,e,f))
#define min6(a, b, c, d, e, f) min(min3(a,b,c),min3(d,e,f))

typedef long long LL;
typedef long double DD;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<DD, DD> PDD;
typedef map<int, int> MII;
typedef map<LL, LL> MLL;

const double eps = 1e-8;
const double Pi = 3.14159265358979323846264338327950288419716939937510;
const long long INF = 1LL << 60;
//const int INF=10000000000;
const long long MAX5 = 100001;
const long long MAX6 = 1000001;
const long long MOD = 1e9 + 7;

//1.0000000000000000001

long long minn(initializer_list<LL> list) {
    long long mn = INF;
    for (LL e: list)mn = min(mn, e);
    return mn;
}

long long maxn(initializer_list<LL> list) {
    long long mx = -INF;
    for (LL e: list)mx = max(mx, e);
    return mx;
}

//ax+by=gcd(a,b)
inline LL egcd(LL a, LL b, LL &x, LL &y) {
    if (!a) {
        x = 0;
        y = 1;
        return b;
    }
    LL x1, y1;
    LL d = egcd(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}

inline LL addMod(LL a, LL b, LL m = MOD) {
    return ((int64_t) a + b) % m;
}

inline LL mulMod(LL a, LL b, LL m = MOD) {
    return ((int64_t) a * b) % m;
}

inline LL divMod(LL a, LL b, int m = MOD) {
    LL x, y;
    LL g = egcd(b, m, x, y);
    if (g != 1) {
        cerr << "Bad gcd!" << endl;
    }
    x = (x % m + m) % m;
    return mulMod(a, x, m);
}

LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }

LL min(LL a, LL b) { return a < b ? a : b; }

LL max(LL a, LL b) { return a < b ? b : a; }

string ekv(string a) {
    if (a.size() & 1)return a;
    string x = ekv(a.substr(0, a.size() / 2));
    string y = ekv(a.substr(a.size() / 2));
    return min(x + y, y + x);
}

string ups(string s) {
    transform(s.begin(), s.end(), s.begin(), ::toupper);
    return s;
}

string lows(string s) {
    transform(s.begin(), s.end(), s.begin(), ::tolower);
    return s;
}

bool isPow2(LL a) { return !(a & (a - 1)); }

LL poww(LL a, LL b) {
    if (b == 0)return 1;
    if (b % 2 == 0)return poww(a, b / 2) * poww(a, b / 2);
    else return poww(a, b - 1) * a;
}

inline LL bSearch(LL *arr, LL v, LL l, LL r) {
    LL m;
    while (l < r) {
        m = l + (r - l) / 2;
        v <= arr[m] ? r = m : l = m + 1;
    }
    if (arr[r] == v)return r; else return INF;
}

inline LL low_bound(LL *arr, LL v, LL l, LL r) {
    LL m;
    while (l < r) {
        m = l + (r - l) / 2;

        if (v < arr[m])
            r = m;
        else l = m + 1;
    }
    if (arr[l] < v)return l; else return INF;
}

long long divpole(LL a, LL b) {
    return a * poww(b, MOD - 2) % MOD;
}

bool isInteger(DD d) { return !(ceil(d) - LL(d)); }

LL mod(LL a) {
    a %= MOD;
    if (a < 0)a += MOD;
    return a;
}

inline bool isPrime(LL n) {
    for (int i = 2; i * i <= n; ++i)if (n % i == 0)return false;
    return true;
}

bool cmpr(string a, string b) {

}

//
//vector<char> prime (n+1, true);
//prime[0] = prime[1] = false;
//for (int i=2; i*i<=n; ++i)
//if (prime[i])
//for (int j=2; j<=n/i; j++)
//if (prime[i*j]) prime[i*j] = false;

//LL A[2 * MAX6];
//LL B[2 * MAX6];
//LL C[2 * MAX6];

LL maxSubArraySum(LL a[], LL size) {
    LL max_so_far = INT_MIN, max_ending_here = 0;

    for (int i = 1; i < size; ++i) {
        max_ending_here = max_ending_here + a[i];
        if (max_so_far < max_ending_here)
            max_so_far = max_ending_here;

        if (max_ending_here < 0)
            max_ending_here = 0;
    }
    return max_so_far;
}

map<int,int> mp;
vector<int> v;
string res = "0";

string bigStr(string a, string b) {

    if (a.size() > b.size())return a;
    else if (b.size() > a.size())return b;
    else {

        for (int i = 0; i < a.size(); ++i)
            if ((a[i] - '0') < (b[i] - '0')) {
                return b;
            }
        return a;
    }

}

void r(int sz, string s) {
    if (sz == 0) {
        res = bigStr(res, s);
        reverse(all(s));
        res=bigStr(res,s);
        return;
    } else {

        int ans=false;

        for (int i = v.size() - 1; i >= 0; --i) {

            if (sz >= v[i]) {
                ans=true;
                string c = "_";
                c[0] = (char) (mp[v[i]] + '0');
                string t = s + c;

                r(sz - v[i], t);
                break;
            }

        }
        if(!ans){
            res = bigStr(res, s);
            reverse(all(s));
            res=bigStr(res,s);
            return;
        }

    }

}

int main() {
    ios_base::sync_with_stdio(false);
    //cin.tie();
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    mp[2] = 1;
    mp[4] = 4;
    mp[5] = 5;
    mp[3] = 7;
    mp[7] = 8;
    mp[6] = 9;

    v.pb(2);
    v.pb(3);
    v.pb(4);
    v.pb(5);
    v.pb(6);
    v.pb(7);

    int n;
    cin >> n;

    r(n, "");

    cout << res;

}


#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <cassert>
#include <set>
#include <string.h>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <time.h>
#include <complex>
#include <climits>
#include <stdarg.h>
#include <iomanip>
#include <initializer_list>
#include <fstream>

using namespace std;

#define gcd __gcd
#define fill(A, val) memset(A,val,sizeof(A))
#define rep(i, a, n) for (long long i=a;i<n;++i)
#define per(i, n, a) for (long long i=n-1;i>=a;--i)
#define all(V) V.begin(),V.end()
#define SZ(V) (int)V.size()
#define pb push_back
//#define mp make_pair
#define ff first
#define ss second
#define min3(a, b, c)     min(a,min(b,c))
#define max3(a, b, c)     max(a,max(b,c))
#define min4(a, b, c, d)   min(min(a,b),min(c,d))
#define max4(a, b, c, d)   max(max(a,b),max(c,d))
#define max5(a, b, c, d, e) max(max3(a,b,c),max(d,e))
#define min5(a, b, c, d, e) min(min3(a,b,c),min(d,e))
#define max6(a, b, c, d, e, f) max(max3(a,b,c),max3(d,e,f))
#define min6(a, b, c, d, e, f) min(min3(a,b,c),min3(d,e,f))

typedef long long LL;
typedef long double DD;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<DD, DD> PDD;
typedef map<int, int> MII;
typedef map<LL, LL> MLL;

const double eps = 1e-8;
const double Pi = 3.14159265358979323846264338327950288419716939937510;
const long long INF = 1LL << 60;
//const int INF=10000000000;
const long long MAX5 = 100001;
const long long MAX6 = 1000001;
const long long MOD = 1e9 + 7;

//1.0000000000000000001

long long minn(initializer_list<LL> list) {
    long long mn = INF;
    for (LL e: list)mn = min(mn, e);
    return mn;
}

long long maxn(initializer_list<LL> list) {
    long long mx = -INF;
    for (LL e: list)mx = max(mx, e);
    return mx;
}

//ax+by=gcd(a,b)
inline LL egcd(LL a, LL b, LL &x, LL &y) {
    if (!a) {
        x = 0;
        y = 1;
        return b;
    }
    LL x1, y1;
    LL d = egcd(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}

inline LL addMod(LL a, LL b, LL m = MOD) {
    return ((int64_t) a + b) % m;
}

inline LL mulMod(LL a, LL b, LL m = MOD) {
    return ((int64_t) a * b) % m;
}

inline LL divMod(LL a, LL b, int m = MOD) {
    LL x, y;
    LL g = egcd(b, m, x, y);
    if (g != 1) {
        cerr << "Bad gcd!" << endl;
    }
    x = (x % m + m) % m;
    return mulMod(a, x, m);
}

LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }

LL min(LL a, LL b) { return a < b ? a : b; }

LL max(LL a, LL b) { return a < b ? b : a; }

string ekv(string a) {
    if (a.size() & 1)return a;
    string x = ekv(a.substr(0, a.size() / 2));
    string y = ekv(a.substr(a.size() / 2));
    return min(x + y, y + x);
}

string ups(string s) {
    transform(s.begin(), s.end(), s.begin(), ::toupper);
    return s;
}

string lows(string s) {
    transform(s.begin(), s.end(), s.begin(), ::tolower);
    return s;
}

bool isPow2(LL a) { return !(a & (a - 1)); }

LL poww(LL a, LL b) {
    if (b == 0)return 1;
    if (b % 2 == 0)return poww(a, b / 2) * poww(a, b / 2);
    else return poww(a, b - 1) * a;
}

inline LL bSearch(LL *arr, LL v, LL l, LL r) {
    LL m;
    while (l < r) {
        m = l + (r - l) / 2;
        v <= arr[m] ? r = m : l = m + 1;
    }
    if (arr[r] == v)return r; else return INF;
}

inline LL low_bound(LL *arr, LL v, LL l, LL r) {
    LL m;
    while (l < r) {
        m = l + (r - l) / 2;

        if (v < arr[m])
            r = m;
        else l = m + 1;
    }
    if (arr[l] < v)return l; else return INF;
}

long long divpole(LL a, LL b) {
    return a * poww(b, MOD - 2) % MOD;
}

bool isInteger(DD d) { return !(ceil(d) - LL(d)); }

LL mod(LL a) {
    a %= MOD;
    if (a < 0)a += MOD;
    return a;
}

inline bool isPrime(LL n) {
    for (int i = 2; i * i <= n; ++i)if (n % i == 0)return false;
    return true;
}

bool cmpr(string a, string b) {

    if(a.size()>b.size())return a>b;
    else{

        for(int i = 0; i < a.size(); ++i)
        if ((a[i] - '0') < (b[i] - '0'))
        {
            return b>a;
        }
        return a>b;

    }

}

//
//vector<char> prime (n+1, true);
//prime[0] = prime[1] = false;
//for (int i=2; i*i<=n; ++i)
//if (prime[i])
//for (int j=2; j<=n/i; j++)
//if (prime[i*j]) prime[i*j] = false;

LL A[2 * MAX6];
LL B[2 * MAX6];
LL C[2 * MAX6];

LL maxSubArraySum(LL a[], LL size)
{
    LL max_so_far = INT_MIN, max_ending_here = 0;

    for (int i = 1; i <size; ++i)
    {
        max_ending_here = max_ending_here + a[i];
        if (max_so_far < max_ending_here)
            max_so_far = max_ending_here;

        if (max_ending_here < 0)
            max_ending_here = 0;
    }
    return max_so_far;
}

map<LL,LL>mp;
vector<LL> v;
vector<string>res;

void r(LL sz, string s)
{
    if(sz==0){
        res.pb(s);
        return;
    }else{

        for(int i=v.size()-1;i>=0;--i){

            if(sz>=v[i])
            {
                string c="_";
                c[0]= (char) (mp[v[i]] + '0');
                string t=s+c;

                r(sz-v[i], t);
            }

        }

    }

}

int main() {
    ios_base::sync_with_stdio(false);
    //cin.tie();
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    mp[2]=1;
    mp[4]=4;
    mp[5]=5;
    mp[3]=7;
    mp[7]=8;
    mp[6]=9;

    v.pb(2);
    v.pb(4);
    v.pb(5);
    v.pb(3);
    v.pb(7);
    v.pb(6);

    LL n;
    cin>>n;

    r(n,"");

    sort(all(res),cmpr);

    //for(string s:res)
    //    cout<<s<<"\n";

    string t=res[res.size()-1];
    reverse(all(res[res.size()-1]));
    cout<<max(res[res.size()-1], t);

}


#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <cassert>
#include <set>
#include <string.h>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <time.h>
#include <complex>
#include <climits>
#include <stdarg.h>
#include <iomanip>
#include <initializer_list>
#include <fstream>

using namespace std;

#define gcd __gcd
#define fill(A, val) memset(A,val,sizeof(A))
#define rep(i, a, n) for (long long i=a;i<n;++i)
#define per(i, n, a) for (long long i=n-1;i>=a;--i)
#define all(V) V.begin(),V.end()
#define SZ(V) (int)V.size()
#define pb push_back
//#define mp make_pair
#define ff first
#define ss second
#define min3(a, b, c)     min(a,min(b,c))
#define max3(a, b, c)     max(a,max(b,c))
#define min4(a, b, c, d)   min(min(a,b),min(c,d))
#define max4(a, b, c, d)   max(max(a,b),max(c,d))
#define max5(a, b, c, d, e) max(max3(a,b,c),max(d,e))
#define min5(a, b, c, d, e) min(min3(a,b,c),min(d,e))
#define max6(a, b, c, d, e, f) max(max3(a,b,c),max3(d,e,f))
#define min6(a, b, c, d, e, f) min(min3(a,b,c),min3(d,e,f))

typedef long long LL;
typedef long double DD;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<DD, DD> PDD;
typedef map<int, int> MII;
typedef map<LL, LL> MLL;

const double eps = 1e-8;
const double Pi = 3.14159265358979323846264338327950288419716939937510;
const long long INF = 1LL << 60;
//const int INF=10000000000;
const long long MAX5 = 100001;
const long long MAX6 = 1000001;
const long long MOD = 1e9 + 7;

//1.0000000000000000001

long long minn(initializer_list<LL> list) {
    long long mn = INF;
    for (LL e: list)mn = min(mn, e);
    return mn;
}

long long maxn(initializer_list<LL> list) {
    long long mx = -INF;
    for (LL e: list)mx = max(mx, e);
    return mx;
}

//ax+by=gcd(a,b)
inline LL egcd(LL a, LL b, LL &x, LL &y) {
    if (!a) {
        x = 0;
        y = 1;
        return b;
    }
    LL x1, y1;
    LL d = egcd(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}

inline LL addMod(LL a, LL b, LL m = MOD) {
    return ((int64_t) a + b) % m;
}

inline LL mulMod(LL a, LL b, LL m = MOD) {
    return ((int64_t) a * b) % m;
}

inline LL divMod(LL a, LL b, int m = MOD) {
    LL x, y;
    LL g = egcd(b, m, x, y);
    if (g != 1) {
        cerr << "Bad gcd!" << endl;
    }
    x = (x % m + m) % m;
    return mulMod(a, x, m);
}

LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }

LL min(LL a, LL b) { return a < b ? a : b; }

LL max(LL a, LL b) { return a < b ? b : a; }

string ekv(string a) {
    if (a.size() & 1)return a;
    string x = ekv(a.substr(0, a.size() / 2));
    string y = ekv(a.substr(a.size() / 2));
    return min(x + y, y + x);
}

string ups(string s) {
    transform(s.begin(), s.end(), s.begin(), ::toupper);
    return s;
}

string lows(string s) {
    transform(s.begin(), s.end(), s.begin(), ::tolower);
    return s;
}

bool isPow2(LL a) { return !(a & (a - 1)); }

LL poww(LL a, LL b) {
    if (b == 0)return 1;
    if (b % 2 == 0)return poww(a, b / 2) * poww(a, b / 2);
    else return poww(a, b - 1) * a;
}

inline LL bSearch(LL *arr, LL v, LL l, LL r) {
    LL m;
    while (l < r) {
        m = l + (r - l) / 2;
        v <= arr[m] ? r = m : l = m + 1;
    }
    if (arr[r] == v)return r; else return INF;
}

inline LL low_bound(LL *arr, LL v, LL l, LL r) {
    LL m;
    while (l < r) {
        m = l + (r - l) / 2;

        if (v < arr[m])
            r = m;
        else l = m + 1;
    }
    if (arr[l] < v)return l; else return INF;
}

long long divpole(LL a, LL b) {
    return a * poww(b, MOD - 2) % MOD;
}

bool isInteger(DD d) { return !(ceil(d) - LL(d)); }

LL mod(LL a) {
    a %= MOD;
    if (a < 0)a += MOD;
    return a;
}

inline bool isPrime(LL n) {
    for (int i = 2; i * i <= n; ++i)if (n % i == 0)return false;
    return true;
}

bool cmpr(string a, string b) {

}

//
//vector<char> prime (n+1, true);
//prime[0] = prime[1] = false;
//for (int i=2; i*i<=n; ++i)
//if (prime[i])
//for (int j=2; j<=n/i; j++)
//if (prime[i*j]) prime[i*j] = false;

//LL A[2 * MAX6];
//LL B[2 * MAX6];
//LL C[2 * MAX6];

LL maxSubArraySum(LL a[], LL size)
{
    LL max_so_far = INT_MIN, max_ending_here = 0;

    for (int i = 1; i <size; ++i)
    {
        max_ending_here = max_ending_here + a[i];
        if (max_so_far < max_ending_here)
            max_so_far = max_ending_here;

        if (max_ending_here < 0)
            max_ending_here = 0;
    }
    return max_so_far;
}

map<LL,LL>mp;
vector<LL> v;
string res="0";

string bigStr(string a,string b)
{

    if(a.size()>b.size())return a;
    else{

        for(int i = 0; i < a.size(); ++i)
            if ((a[i] - '0') < (b[i] - '0'))
            {
                return b;
            }
        return a;
    }

}

void r(LL sz, string s)
{
    if(sz==0){
        res=bigStr(res,s);
        return;
    }else{

        for(int i=v.size()-1;i>=0;--i){

            if(sz>=v[i])
            {
                string c="_";
                c[0]= (char) (mp[v[i]] + '0');
                string t=s+c;

                r(sz-v[i], t);
            }

        }

    }

}

int main() {
    ios_base::sync_with_stdio(false);
    //cin.tie();
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    mp[2]=1;
    mp[4]=4;
    mp[5]=5;
    mp[3]=7;
    mp[7]=8;
    mp[6]=9;

    v.pb(2);
    v.pb(4);
    v.pb(5);
    v.pb(3);
    v.pb(7);
    v.pb(6);

    LL n;
    cin>>n;

    r(n,"");

    cout<<res;

}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,x,i;
    scanf("%d",&n);
    if(n>=3)
        printf("7");
    else if(n>=2)
        printf("1");

}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,x,i;
    scanf("%d",&n);
    while(n>1){
        if(n>=3) {
            printf("7");
            n=n-3;
        }
        else if(n>=2){
            printf("1");
            n=n-2;
        }
    }
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,x,i;
    scanf("%d",&n);
    if(n%2==0) {
        for(i=0;i<n/2;i++) cout<<1;
    }
    else {
        for(i=0;i<n/2-1;i++) cout<<1;
        cout<<7;
    }
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,x,i;
    scanf("%d",&n);
    if(n%2==0) {
        for(i=0;i<n/2;i++) cout<<1;
    }
    else {
        cout<<7;
        for(i=0;i<n/2-1;i++) cout<<1;
    }
}


// be name khoda ...
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define LOCAL_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define Rep(i,first_val,end_val) for(ll i=first_val;i<end_val;i+=1)
#define Rep_1(i,first_val,end_val) for(ll i=first_val;i<=end_val;i+=1)
#define Rep_s(i,first_val,end_val,step) for(ll i=first_val;i<=end_val;i+=step)

int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	ll n; cin >> n;
	string res = "";
	while(n>=2)
	{
		if(n == 3)
		{
			res = res + "7";
			n-=3;
		}
		else
		{
			res = res + "1";
			n-=2;
		}
	}
	cout << res;
	return 0;
}


// be name khoda ...
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define LOCAL_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define Rep(i,first_val,end_val) for(ll i=first_val;i<end_val;i+=1)
#define Rep_1(i,first_val,end_val) for(ll i=first_val;i<=end_val;i+=1)
#define Rep_s(i,first_val,end_val,step) for(ll i=first_val;i<=end_val;i+=step)

int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	ll n; cin >> n;
	string res = "";
	while(n>=2)
	{
		if(n == 3)
		{
			res = "7" + res;
			n-=3;
		}
		else
		{
			res = res + "1";
			n-=2;
		}
	}
	cout << res;
	return 0;
}


// be name khoda ...
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define LOCAL_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define Rep(i,first_val,end_val) for(ll i=first_val;i<end_val;i+=1)
#define Rep_1(i,first_val,end_val) for(ll i=first_val;i<=end_val;i+=1)
#define Rep_s(i,first_val,end_val,step) for(ll i=first_val;i<=end_val;i+=step)

int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	ll n; cin >> n;
	string res = "";
	while(n>=6)
	{
		res = res + "9";
		n-=6;
	}
	while(n>=3)
	{
		res = res + "7";
		n-=3;
	}
	while(n>=2)
	{
		res = res + "1";
		n-=2;
	}
	cout << res;
}


#include <iostream>
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include <cstring>
#include <conio.h>
#include <math.h>
#include <map>
#include <vector>
#include <algorithm>
#include <set>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define V vector<int>
#define B begin()
#define E end()
typedef long long ll;
typedef long double ld;
using namespace std;

int main()
{
	int n;
	vector<ll>x;
	cin>>n;
	while(n)
	{

		if(n%2==0)
		{
				x.pb(1);
				n-=2;
		}
	else{
			n-=3;
			x.pb(7);
		}

	}

	for(int i=0;i<x.size();i++)
	cout<<x[i];

}


#include <iostream>
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include <cstring>
#include <conio.h>
#include <math.h>
#include <map>
#include <vector>
#include <algorithm>
#include <set>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define V vector<int>
#define B begin()
#define E end()
typedef long long ll;
typedef long double ld;
using namespace std;

int main()
{
	int n;
	vector<ll>x;
	cin>>n;
	while(n)
	{
		if(n==2){
			n-=2;
		x.pb(1);
		}
		else if(n==3)
		{
			n-=3;
		x.pb(7);
		}
	else if(n==4)
		{
			x.pb(1);
			x.pb(1);
			n-=4;
		}
		else if(n==10)
		{
			x.pb(7);
			x.pb(7);
			n-=6;
		}
	else{
			n-=3;
			x.pb(7);
		}

	}

	for(int i=0;i<x.size();i++)
	cout<<x[i];

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,n;
    cin>>n;
    for(i=0;i<(n-2)/2;i++)  cout<<1;
    if(n&1) puts("7");
    else    puts("1");
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,n;
    cin>>n;
    if(n&1) cout<<7;
    else    cout<<1;
    for(i=0;i<(n-2)/2;i++)  cout<<1;
    return 0;
}


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

int main (){
	long int N, n;
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>N;
	n=0;
	if (N>=3&&N%2!=0){
		n+=7;
		N-=3;
	}
	while (N>=2){
		n*=10;
		n+=1;
		N-=2;
	}
	cout<<n;
}


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

int main (){
	long int N, n;
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>N;
	n=0;
	if (N>=3){
		n+=7;
		N-=3;
	}
	while (N>=2){
		n*=10;
		n+=1;
		N-=2;
	}
	cout<<n;
}


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

int main (){
	long int N;
	string a="";
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>N;
	if (N>=3&&N%2!=0){
		a+='7';
		N-=3;
	}
	while (N>=2){
		a+='1';
		N-=2;
	}
	cout<<a;
}


#include <bits/stdc++.h>
using namespace std;
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main()
{
	int a[] = {7,2,5,5,4,5,6,3,7,5};
	int n;
	string s = "";
	int re;
	scanf("%d",&n);
	int ni;
	if(n  & 1)
	{
		cout<<7;
		n -= 3;

	}
	ni = n / 2;
	while(ni > 0)
	{
		cout<<1;
		ni--;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main()
{
	int a[] = {7,2,5,5,4,5,6,3,7,5};
	int n;
	string s = "";
	int re;
	scanf("%d",&n);
	int ni;
	if(n  & 1)
	{
		cout<<7;
		n - 3;

	}
	ni = n / 2;
	while(ni > 0)
	{
		cout<<1;
		ni--;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main()
{
	int a[] = {7,2,5,5,4,5,6,3,7,5};
	int n;
	string s = "";
	int re;
	scanf("%d",&n);
	while(n > 0)
	{
		for(int i = 9 ; i >= 0;i--)
		{
			re = n - a[i];
			if(n >= a[i] && re != 1)
			{
				//cout<<i<<" "<<re<<endl;
				n =  re;
				cout<<i;
				break;
			}
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define mx 200005
using namespace std;
int main()
{
   ll n,i,r,j,t;

   while(cin>>n)
   {
       if(n%2==0)
       {
           for(i=1;i<=n/2;i++)printf("1");
       }
       else
       {
           r=n%3;

           for(i=1;i<=n/3;i++)printf("7");
           if(r)cout<<"1";
       }
       cout<<endl;
   }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define mx 100005
using namespace std;
int main()
{
   ll n,i,r,j,t;
   map<ll,ll>mp;
   mp[8]=0;
   mp[2]=1;
   mp[5]=5;
   mp[4]=4;
   mp[3]=7;
   mp[6]=9;
   mp[7]=8;
   while(cin>>n)
   {
         r=n%3;

       if(n%2==0)
       {
           for(i=1;i<=n/2;i++)printf("1");
       }

      else if(r==1){
            printf("7");
       for(i=1;i<=(n/2)-1;i++)
       {
           printf("1");

       }

       }

       else
       {

           for(i=1;i<=n/3;i++)printf("7");
           if(r)cout<<"1";
       }
       cout<<endl;
   }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define mx 200005
using namespace std;
int main()
{
   ll n,i,r,j,t;
   while(cin>>n)
   {
         r=n%3;

       if(n%2==0)
       {
           for(i=1;i<=n/2;i++)printf("1");
       }

      else if(r==1){
            printf("7");
       for(i=1;i<=(n/2)-1;i++)
       {
           printf("1");

       }

       }

       else
       {

           for(i=1;i<=n/3;i++)printf("7");
           if(r)cout<<"1";
       }
       cout<<endl;
   }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define mx 200005
using namespace std;
int main()
{
    ll n,i,r,j,t;
    while(cin>>n)
    {
        if(n%2==0)
        {
            for(i=1; i<=n/2; i++)printf("1");
        }

        else
        {

                printf("7");
            for(i=1; i<=(n/2)-1; i++)
            {
                printf("1");

            }

        }

        cout<<endl;
    }
    return 0;
}


#include<stdio.h>
#include<iostream>
using namespace std;
int main(void)
{
	int n;
	int a[10]={6,2,5,5,4,5,6,3,7,6};
	while(cin>>n)
	{
		int max=-1;
		for(int i=0;i<10;i++)
		{
			if(a[i]<=n)
			{
				max=i;
			}
		}
		cout<<max<<endl;

	}

}


#include<stdio.h>
#include<iostream>
using namespace std;
int main(void)
{
	int n;
	while(cin>>n)
	{
		if(n<5)
		{
			if(n==3)
				printf("7\n");
			if(n==4)
				printf("11\n");
			if(n==2)
				printf("1\n");
		}
		else
		{
			int x=n%2;
			int y=n/2;
			if(x==1)
			{
				    printf("7");
					for(int i=0;i<y-1;i++)
					{
						printf("1");
					}
					printf("\n");

					//cout<<"7";
					//cout<<endl;

			}
			else
			{
				for(int i=0;i<y;i++)
				{
					printf("1");
				}
				printf("\n");
			}
		}

	}

}