// 種類
// 金額
// 目的額
// 10
// 1 5 10 50 100 500 1000 2000 5000 10000
// 108
// 555
// 9999
// 34567
// 98989
// 123456789
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
const int INF = 1 << 30;
int main()
{
int n;
cin >> n;
vector<int> v;
for (int i = 0; i < n; ++i)
{
int vv; cin >> vv;
v.push_back(vv);
}
sort(v.begin(), v.end());
int mv = v[n - 1];
vector<int> dp(mv * 2 + 1, INF);
vector<map<int, int> > dpp(mv * 2 + 1);
dp[0] = 0;
for (int i = 0; i <= mv * 2; ++i)
for (int j = 0; j < n; ++j)
if (i + v[j] <= mv * 2)
{
if (dp[i] + 1 < dp[i + v[j]])
{
dp[i + v[j]] = dp[i] + 1;
dpp[i + v[j]] = dpp[i];
++dpp[i + v[j]][j];
}
}
int t;
while (cin >> t)
{
int mn = t / mv;
int ct = t - mn * mv;
int re = INF;
int f = 0;
int b = 0;
for (int i = 0; i < ct; ++i)
if (dp[i] + dp[ct + i] < re)
{
re = dp[i] + dp[ct + i];
f = ct + i;
b = i;
}
cout << t << ":" << re + mn << endl;
cout << "-> " << f + mn * mv << " ( ";
for (int i = 0; i < n - 1; ++i)
if (dpp[f][i]) cout << v[i] << "x" << dpp[f][i] << " ";
if (mv <= f) ++mn;
if (mn) cout << mv << "x" << mn << " ";
cout << ")" << endl;
cout << "<- " << b << " ( ";
for (int i = 0; i < n - 1; ++i)
if (dpp[b][i]) cout << v[i] << "x" << dpp[b][i] << " ";
cout << ")" << endl;
}
return 0;
}
Ly8g56iu6aGeCi8vIOmHkemhjQovLyDnm67nmoTpoY0KLy8gMTAKLy8gMSA1IDEwIDUwIDEwMCA1MDAgMTAwMCAyMDAwIDUwMDAgMTAwMDAKLy8gMTA4Ci8vIDU1NQovLyA5OTk5Ci8vIDM0NTY3Ci8vIDk4OTg5Ci8vIDEyMzQ1Njc4OQoKI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZ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