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

struct summand
{
	int koef;
	string incr;
	bool used;
};
vector<summand> vec;
int FindMinKoef(int& a)
{
	int min = 100*100*100;
	int minInd = 0;
	for(int i = 0; i < vec.size(); i++)
	{
		if(vec[i].koef < min && vec[i].used == 1)
		{
			min = vec[i].koef;
			minInd = i;
		}
	}
	int temp = min;
	if(vec[minInd].incr.size() == 3)
	{
		if(vec[minInd].incr[0] == '+')
		{
			temp *= a + 1;
		}
		else
		{
			temp *=a;
		}
	}
	vec[minInd].used = 0;
	if(vec[minInd].incr.size() == 3)
		a++;
	else
		a = a + 2;
	return temp;
}
void Check(int a)
{
	int otrCount = 0;
	int polCount = 0;
	for(int i = 0; i < vec.size(); i++)
	{
		vec[i].used = 1;
		if(vec[i].koef < 0)
			otrCount++;
		else
			polCount++;
	}
        int ans = 0;
        while(polCount + otrCount > 0)
        {
				ans += FindMinKoef(a);
                polCount--;
        }
        cout << ans;
}
void Parse(string& str)
{
	int s = str.size();
	bool minus = false;
	for(int i = 0; i < s; i++)
	{
		char ch = str[i];
		summand sd;
		if(ch == '-')
		{
			minus = true;
		}
		else if(isdigit(ch))
		{
			string koef;
			koef += ch;
			while(i < str.size() - 1 && isdigit(ch))
			{
				i++;
				ch = str[i];
				if(isdigit(ch))
				{
					koef += ch;
				}
				else
					i--;
			}
			int tens = 1;
			for(int i = 0; i < koef.size() - 1; i++)
			{
				tens *= 10;
			}
			int koef2 = 0;
			for(int i = 0; i < koef.size(); i++)
			{
				char ch2 = koef[i];
				int t = (ch2 - '0') * tens;
				tens /= 10;
				koef2 += t;
			}
			if(minus)
				koef2 = (-1)*koef2;
			sd.koef = koef2;
			i++; // *
			i++;
			string incr;
			if(isalpha(char(str[i])))
			{
				incr += str[i];
				int p = 1;
				while(p <= 2)
				{
					incr += str[i + p++];
				}
				i = i + p-1;
			}
			else if((char)str[i] == '+')
			{
				incr += str[i];
				int p = 1;
				while(p <= 2)
				{
					incr += str[i + p++];
				}
				i = i + p - 1;
			}
			sd.incr = incr;
			vec.push_back(sd);
			minus = false;

		}
		else if (isalpha(ch))
		{
			string incr;
			incr += ch;
			int p = 1;
			while(p <= 2)
			{
				incr += str[i + p++];
			}
			i = i + p - 1;
			sd.incr = incr;
			if(!minus)
				sd.koef = 1;
			else
				sd.koef = -1;
			minus = false;
			vec.push_back(sd);
		}
		else if(ch == '+')
		{
			if(isalpha((char)str[i+1]) || isdigit((char)str[i+1]) || (str[i+1] == '+' && str[i+2] =='+'))
			{
				continue;
			}
			string incr;
			incr += ch;
			int p = 1;
			while(p <= 2)
			{
				incr += str[i + p++];
			}
			i = i + p - 1;
			sd.incr = incr;
			if(!minus)
				sd.koef = 1;
			else
				sd.koef = -1;
			minus = false;
			vec.push_back(sd);
		}
	}

	//cout << endl;
	//for(int i = 0; i < vec.size(); i++)
	//	cout << vec[i].incr << " " << vec[i].koef << endl;
}
int main()
{
	//freopen("input.txt", "r", stdin);
	int a;
	cin >> a;
	string str;
	cin >> str;
	Parse(str);
	Check(a);
	return 0;
}


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

//int main()
//{
//	int x1, y1, z1;
//	cin >> x1 >> y1 >> z1;
//	int x2, y2, z2;
//	cin >> x2 >> y2 >> z2;
//	if(abs(x1-x2)+abs(y1-y2) + abs(z1-z2) == 3)
//		cout << "NO";
//	else
//		cout << "YES";
//	return 0;
//}
//int main()
//{
//	int n;
//	cin >> n;
//	vector< vector<string > > vec;
//	vec.resize(n - 1);
//	for(int i = 0; i < n - 1; i++)
//	{
//		vec[i].resize(n-1);
//	}
//
//	for(int i = 0; i < n - 1; i++)
//	{
//		vec[i][0] = (i + 1) + '0';
//		vec[0][i] = (i + 1)  + '0';
//	}
//	for(int i = 1; i < n -1; i++)
//	{
//		for(int j = 1; j < n -1; j++)
//		{
//			vector<char> t;
//			const char* ch1 = vec[i][0].c_str();
//			char ch11 = ch1[0];
//			int p1 =  ch11 - '0';
//
//			const char* ch2 = vec[0][j].c_str();
//			char ch22 = ch2[0];
//			int p2 =  ch22 - '0';
//
//			int temp = p1 * p2;
//			while(temp > 0)
//			{
//
//				t.push_back((temp % n) + '0');
//				temp /= n;
//			}
//			reverse(t.begin(), t.end());
//			for(int p = 0; p < t.size(); p++)
//			{
//				vec[i][j] += t[p];
//			}
//		}
//	}
//	for(int i = 0; i < n - 1; i++)
//	{
//		for(int j = 0; j < n - 1 ; j++)
//			cout << vec[i][j] << " ";
//		cout << endl;
//	}
//	return 0;
////}
struct summand
{
	int koef;
	string incr;
	bool used;
};
vector<summand> vec;
int FindMin(int& a, bool fl)
{
	int min = 100*100*100;
	int minInd =0;
	for(int i = 0; i < vec.size(); i++)
	{
		int temp = 100*100*100;
		if(!fl && vec[i].koef > 0 && vec[i].used == 1)
		{
			temp = vec[i].koef;
			if(vec[i].incr.size() == 3)
			{
				if(vec[i].incr[0] == '+')
				{
					//a++;
					temp *= a+1;
				}
				else
				{
					temp *=a;
					//a++;
				}
			}
			else
			{
				//a++;
				temp *=a+1;
				temp++;
			}
		}
		else if(fl && vec[i].koef < 0 && vec[i].used == 1)
		{
			temp = abs(vec[i].koef);
			if(vec[i].incr.size() == 3)
			{
				if(vec[i].incr[0] == '+')
				{
					//a++;
					temp *= a+1;
				}
				else
				{
					temp *=a;
					//a++;
				}
			}
			else
			{
				//a++;
				temp *=a+1;
				temp++;
			}
		}
		if(temp < min)
		{
			min = temp;
			minInd = i;
		}
	}
	vec[minInd].used = 0;
	if(vec[minInd].incr.size() == 3)
		a++;
	else
		a = a + 2;
	if(fl)
		return -min;
	else
		return min;
}
int FindMax(int& a, bool fl)
{
	int max = -100*100*100;
	int maxInd = 0;
	for(int i = 0; i < vec.size(); i++)
	{
		int temp = -100*100*100;
		if(fl && vec[i].koef < 0 && vec[i].used == 1)
		{
			temp = abs(vec[i].koef);
			if(vec[i].incr.size() == 3)
			{
				if(vec[i].incr[0] == '+')
				{
					//a++;
					temp *= a + 1;
				}
				else
				{
					temp *=a;
					//a++;
				}
			}
			else
			{
				//a++;
				temp *=a+ 1;
				temp++;
			}
		}
		else if(!fl && vec[i].koef > 0 && vec[i].used == 1)
		{
			temp = abs(vec[i].koef);
			if(vec[i].incr.size() == 3)
			{
				if(vec[i].incr[0] == '+')
				{
					//a++;
					temp *= a + 1;
				}
				else
				{
					temp *=a;
					//a++;
				}
			}
			else
			{
				//a++;
				temp *=a+ 1;
				temp++;
			}
		}
		if(temp > max)
		{
			max = temp;
			maxInd = i;
		}
	}
	vec[maxInd].used = 0;
	if(vec[maxInd].incr.size() == 3)
		a++;
	else
		a = a + 2;
	if(fl)
		return -max;
	else
		return max;
}
int cmp(summand a1, summand a2)
{
	if(a1.koef < a2.koef)
		return 1;
	else if(a1.koef > a2.koef)
		return -1;
	else
		return 0;
}
void Check(int a)
{
	int otrCount = 0;
	int polCount = 0;
	for(int i = 0; i < vec.size(); i++)
	{
		vec[i].used = 1;
		if(vec[i].koef < 0)
			otrCount++;
		else
			polCount++;
	}
	int ans = 0;
	if(a >= 0)
	{
		while(otrCount > 0)
		{
			ans += FindMax(a,true);
			otrCount--;
		}
		//cout << ans;
		while(polCount > 0)
		{
			ans += FindMin(a,false);
			polCount--;
		}
			cout << ans;

	}
	else
	{
		int tempA = a;
		int ans1 = 0;
		while(otrCount > 0)
		{
			ans1 += FindMax(a,true);
			otrCount--;
		}
		//cout << ans;
		while(polCount > 0)
		{
			ans1 += FindMin(a,false);
			polCount--;
		}

		//int ans2 = 0;
		//while(otrCount > 0)
		//{
		//	ans += FindMin(a,true);
		//	otrCount--;
		//}
		//while(polCount > 0)
		//{
		//	ans2 += FindMax(a,false);
		//	polCount--;
		//}
		//if(ans1 > ans2)
		//	cout << ans1;
		//else
		//	cout << ans2;
		cout << ans1;

	}
}
void Parse(string& str)
{
	int s = str.size();
	bool minus = false;
	for(int i = 0; i < s; i++)
	{
		char ch = str[i];
		summand sd;
		if(ch == '-')
		{
			//vec.push_back(sd);
			minus = true;
		}
		else if(isdigit(ch))
		{
			string koef;
			koef += ch;
			while(i < str.size() - 1 && isdigit(ch))
			{
				i++;
				ch = str[i];
				if(isdigit(ch))
				{
					koef += ch;
				}
				else
					i--;
			}
			int tens = 1;
			for(int i = 0; i < koef.size() - 1; i++)
			{
				tens *= 10;
			}
			int koef2 = 0;
			for(int i = 0; i < koef.size(); i++)
			{
				char ch2 = koef[i];
				int t = (ch2 - '0') * tens;
				tens /= 10;
				koef2 += t;
			}
			if(minus)
				koef2 = (-1)*koef2;
			sd.koef = koef2;
			//cout << "k \n";
			//cout << koef2;
			i++; // *
			i++;
			string incr;
			if(isalpha(char(str[i])))
			{
				incr += str[i];
				int p = 1;
				while(p <= 2)
				{
					incr += str[i + p++];
				}
				i = i + p-1;
			}
			else if((char)str[i] == '+')
			{
				incr += str[i];
				int p = 1;
				while(p <= 2)
				{
					incr += str[i + p++];
				}
				i = i + p - 1;
				if(i+1 < str.size() && i+2 < str.size() && ((char)str[i+1] == '+' && (char)str[i+2] == '+'))
				{
					int p = 1;
					while(p <= 2)
					{
						incr += str[i + p++];
					}
					i = i + p-1;
				}
			}
			sd.incr = incr;
			//cout << incr;
			vec.push_back(sd);
			minus = false;

		}
		else if (isalpha(ch))
		{
			string incr;
			incr += ch;
			int p = 1;
			while(p <= 2)
			{
				incr += str[i + p++];
			}
			i = i + p - 1;
			//cout << incr;
			sd.incr = incr;
			if(!minus)
				sd.koef = 1;
			else
				sd.koef = -1;
			minus = false;
			vec.push_back(sd);
		}
		else if(ch == '+')
		{
			if(isalpha((char)str[i+1]) || isdigit((char)str[i+1]) || (str[i+1] == '+' && str[i+2] =='+'))
			{
				//vec.push_back(sd);
				continue;
			}
			string incr;
			incr += ch;
			int p = 1;
			while(p <= 2)
			{
				incr += str[i + p++];
			}
			i = i + p - 1;
			if(i+1 < str.size() && (char)str[i+1] == '+')
			{
				int p = 1;
				while(p <= 2)
				{
					incr += str[i + p++];
				}
				i = i + p;
			}
			//cout << incr;
			sd.incr = incr;
			if(!minus)
				sd.koef = 1;
			else
				sd.koef = -1;
			minus = false;
			vec.push_back(sd);
		}
	}

	//cout << endl;
	//for(int i = 0; i < vec.size(); i++)
		//cout << vec[i].incr << " " << vec[i].koef << endl;
}
int main()
{
	//freopen("input.txt", "r", stdin);
	int a;
	cin >> a;
	string str;
	cin >> str;
	Parse(str);
	Check(a);
	return 0;
}


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

//int main()
//{
//	int x1, y1, z1;
//	cin >> x1 >> y1 >> z1;
//	int x2, y2, z2;
//	cin >> x2 >> y2 >> z2;
//	if(abs(x1-x2)+abs(y1-y2) + abs(z1-z2) == 3)
//		cout << "NO";
//	else
//		cout << "YES";
//	return 0;
//}
//int main()
//{
//	int n;
//	cin >> n;
//	vector< vector<string > > vec;
//	vec.resize(n - 1);
//	for(int i = 0; i < n - 1; i++)
//	{
//		vec[i].resize(n-1);
//	}
//
//	for(int i = 0; i < n - 1; i++)
//	{
//		vec[i][0] = (i + 1) + '0';
//		vec[0][i] = (i + 1)  + '0';
//	}
//	for(int i = 1; i < n -1; i++)
//	{
//		for(int j = 1; j < n -1; j++)
//		{
//			vector<char> t;
//			const char* ch1 = vec[i][0].c_str();
//			char ch11 = ch1[0];
//			int p1 =  ch11 - '0';
//
//			const char* ch2 = vec[0][j].c_str();
//			char ch22 = ch2[0];
//			int p2 =  ch22 - '0';
//
//			int temp = p1 * p2;
//			while(temp > 0)
//			{
//
//				t.push_back((temp % n) + '0');
//				temp /= n;
//			}
//			reverse(t.begin(), t.end());
//			for(int p = 0; p < t.size(); p++)
//			{
//				vec[i][j] += t[p];
//			}
//		}
//	}
//	for(int i = 0; i < n - 1; i++)
//	{
//		for(int j = 0; j < n - 1 ; j++)
//			cout << vec[i][j] << " ";
//		cout << endl;
//	}
//	return 0;
////}
struct summand
{
	int koef;
	string incr;
	bool used;
};
vector<summand> vec;
int FindMin(int& a, bool fl)
{
	int min = 100*100*100;
	int minInd =0;
	for(int i = 0; i < vec.size(); i++)
	{
		int temp = 100*100*100;
		if(!fl && vec[i].koef > 0 && vec[i].used == 1)
		{
			temp = vec[i].koef;
			if(vec[i].incr.size() == 3)
			{
				if(vec[i].incr[0] == '+')
				{
					//a++;
					temp *= a+1;
				}
				else
				{
					temp *=a;
					//a++;
				}
			}
			else
			{
				//a++;
				temp *=a+1;
				temp++;
			}
		}
		else if(fl && vec[i].koef < 0 && vec[i].used == 1)
		{
			temp = abs(vec[i].koef);
			if(vec[i].incr.size() == 3)
			{
				if(vec[i].incr[0] == '+')
				{
					//a++;
					temp *= a+1;
				}
				else
				{
					temp *=a;
					//a++;
				}
			}
			else
			{
				//a++;
				temp *=a+1;
				temp++;
			}
		}
		if(temp < min)
		{
			min = temp;
			minInd = i;
		}
	}
	vec[minInd].used = 0;
	if(vec[minInd].incr.size() == 3)
		a++;
	else
		a = a + 2;
	if(fl)
		return -min;
	else
		return min;
}
int FindMax(int& a, bool fl)
{
	int max = -100*100*100;
	int maxInd = 0;
	for(int i = 0; i < vec.size(); i++)
	{
		int temp = -100*100*100;
		if(fl && vec[i].koef < 0 && vec[i].used == 1)
		{
			temp = abs(vec[i].koef);
			if(vec[i].incr.size() == 3)
			{
				if(vec[i].incr[0] == '+')
				{
					//a++;
					temp *= a + 1;
				}
				else
				{
					temp *=a;
					//a++;
				}
			}
			else
			{
				//a++;
				temp *=a+ 1;
				temp++;
			}
		}
		else if(!fl && vec[i].koef > 0 && vec[i].used == 1)
		{
			temp = abs(vec[i].koef);
			if(vec[i].incr.size() == 3)
			{
				if(vec[i].incr[0] == '+')
				{
					//a++;
					temp *= a + 1;
				}
				else
				{
					temp *=a;
					//a++;
				}
			}
			else
			{
				//a++;
				temp *=a+ 1;
				temp++;
			}
		}
		if(temp > max)
		{
			max = temp;
			maxInd = i;
		}
	}
	vec[maxInd].used = 0;
	if(vec[maxInd].incr.size() == 3)
		a++;
	else
		a = a + 2;
	if(fl)
		return -max;
	else
		return max;
}
int cmp(summand a1, summand a2)
{
	if(a1.koef < a2.koef)
		return 1;
	else if(a1.koef > a2.koef)
		return -1;
	else
		return 0;
}
void Check(int a)
{
	int otrCount = 0;
	int polCount = 0;
	for(int i = 0; i < vec.size(); i++)
	{
		vec[i].used = 1;
		if(vec[i].koef < 0)
			otrCount++;
		else
			polCount++;
	}
	int ans = 0;
	if(a >= 0)
	{
		while(otrCount > 0)
		{
			ans += FindMax(a,true);
			otrCount--;
		}
		//cout << ans;
		while(polCount > 0)
		{
			ans += FindMin(a,false);
			polCount--;
		}
			cout << ans;

	}
	else
	{
		int tempA = a;
		int ans1 = 0;
		while(otrCount > 0)
		{
			ans1 += FindMax(a,true);
			otrCount--;
		}
		//cout << ans;
		while(polCount > 0)
		{
			ans1 += FindMin(a,false);
			polCount--;
		}

		int ans2 = 0;
		while(otrCount > 0)
		{
			ans += FindMin(a,true);
			otrCount--;
		}
		while(polCount > 0)
		{
			ans2 += FindMax(a,false);
			polCount--;
		}
		if(ans1 > ans2)
			cout << ans1;
		else
			cout << ans2;

	}
}
void Parse(string& str)
{
	int s = str.size();
	bool minus = false;
	for(int i = 0; i < s; i++)
	{
		char ch = str[i];
		summand sd;
		if(ch == '-')
		{
			//vec.push_back(sd);
			minus = true;
		}
		else if(isdigit(ch))
		{
			string koef;
			koef += ch;
			while(i < str.size() - 1 && isdigit(ch))
			{
				i++;
				ch = str[i];
				if(isdigit(ch))
				{
					koef += ch;
				}
				else
					i--;
			}
			int tens = 1;
			for(int i = 0; i < koef.size() - 1; i++)
			{
				tens *= 10;
			}
			int koef2 = 0;
			for(int i = 0; i < koef.size(); i++)
			{
				char ch2 = koef[i];
				int t = (ch2 - '0') * tens;
				tens /= 10;
				koef2 += t;
			}
			if(minus)
				koef2 = (-1)*koef2;
			sd.koef = koef2;
			//cout << "k \n";
			//cout << koef2;
			i++; // *
			i++;
			string incr;
			if(isalpha(char(str[i])))
			{
				incr += str[i];
				int p = 1;
				while(p <= 2)
				{
					incr += str[i + p++];
				}
				i = i + p-1;
			}
			else if((char)str[i] == '+')
			{
				incr += str[i];
				int p = 1;
				while(p <= 2)
				{
					incr += str[i + p++];
				}
				i = i + p - 1;
				if(i+1 < str.size() && i+2 < str.size() && ((char)str[i+1] == '+' && (char)str[i+2] == '+'))
				{
					int p = 1;
					while(p <= 2)
					{
						incr += str[i + p++];
					}
					i = i + p-1;
				}
			}
			sd.incr = incr;
			//cout << incr;
			vec.push_back(sd);
			minus = false;

		}
		else if (isalpha(ch))
		{
			string incr;
			incr += ch;
			int p = 1;
			while(p <= 2)
			{
				incr += str[i + p++];
			}
			i = i + p - 1;
			//cout << incr;
			sd.incr = incr;
			if(!minus)
				sd.koef = 1;
			else
				sd.koef = -1;
			minus = false;
			vec.push_back(sd);
		}
		else if(ch == '+')
		{
			if(isalpha((char)str[i+1]) || isdigit((char)str[i+1]) || (str[i+1] == '+' && str[i+2] =='+'))
			{
				//vec.push_back(sd);
				continue;
			}
			string incr;
			incr += ch;
			int p = 1;
			while(p <= 2)
			{
				incr += str[i + p++];
			}
			i = i + p - 1;
			if(i+1 < str.size() && (char)str[i+1] == '+')
			{
				int p = 1;
				while(p <= 2)
				{
					incr += str[i + p++];
				}
				i = i + p;
			}
			//cout << incr;
			sd.incr = incr;
			if(!minus)
				sd.koef = 1;
			else
				sd.koef = -1;
			minus = false;
			vec.push_back(sd);
		}
	}

	//cout << endl;
	//for(int i = 0; i < vec.size(); i++)
		//cout << vec[i].incr << " " << vec[i].koef << endl;
}
int main()
{
	//freopen("input.txt", "r", stdin);
	int a;
	cin >> a;
	string str;
	cin >> str;
	Parse(str);
	Check(a);
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <ctime>
#include <cmath>
#include <algorithm>

using namespace std;

typedef long double ldb;
typedef long long int64;

double const pi = 3.1415926535897932384626433832795;
int const inf = (int) 1e9;
int64 const inf64 = (int64) 2e18;

#define y1 qqqqqqq
#define forn(i, n) for (int i = 0; i < (int) n; i++)
#define seta(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define pii pair < int, int >
#define all(a) (a).begin(), (a).end()
#define mp make_pair
#define fs first
#define sc second

const string task = "";

char s[100000];
int a, l, zn, d[1010][1010];
vector <int> q[2];

void get()
{
	int k = 0;
	if (s[l] >= '0' && s[l] <= '9')
	{
		while (s[l] != '*')
		{
			k = k * 10 + s[l] - '0';
			l++;
		}
		l++;
	}
	else k = 1;
	k *= zn;
	int tp;

	if (s[l] == 'a') tp = 0;
	else tp = 1;
	l += 3;

	q[tp].pb(k);
}

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	cin >> a;
	scanf("%s", s);
	s[strlen(s) + 1] = '\0';
	s[strlen(s)] = '@';
	l = 0, zn = 1;

	while (true)
	{
		get();
		if (s[l] == '@') break;
		if (s[l] == '+') zn = 1;
		else zn = -1;
		l++;
	}

	sort(all(q[0]));
	sort(all(q[1]));

	forn(i, q[0].size() + 1)
		forn(j, q[1].size() + 1)
			d[i][j] = -inf;
	d[0][0] = 0;

	forn(i, q[0].size() + 1)
		forn(j, q[1].size() + 1)
			if (d[i][j] == -inf)
			{
				if (i > 0) d[i][j] = max(d[i][j], d[i - 1][j] + q[0][i - 1] * (a + i + j - 1));
				if (j > 0) d[i][j] = max(d[i][j], d[i][j - 1] + q[1][j - 1] * (a + i + j));
			}

	cout << d[q[0].size()][q[1].size()] << endl;

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <ctime>
#include <cmath>
#include <algorithm>

using namespace std;

typedef long double ldb;
typedef long long int64;

double const pi = 3.1415926535897932384626433832795;
int const inf = (int) 1e9;
int64 const inf64 = (int64) 2e18;

#define y1 qqqqqqq
#define forn(i, n) for (int i = 0; i < (int) n; i++)
#define seta(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define pii pair < int, int >
#define all(a) (a).begin(), (a).end()
#define mp make_pair
#define fs first
#define sc second

const string task = "";

char s[100000];
int a, l, zn;
long long d[1010][1010];
vector <int> q[2];

void get()
{
	int k = 0;
	if (s[l] >= '0' && s[l] <= '9')
	{
		while (s[l] != '*')
		{
			k = k * 10 + s[l] - '0';
			l++;
		}
		l++;
	}
	else k = 1;
	k *= zn;
	int tp;

	if (s[l] == 'a') tp = 0;
	else tp = 1;
	l += 3;

	q[tp].pb(k);
}

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	cin >> a;
	scanf("%s", s);
	s[strlen(s) + 1] = '\0';
	s[strlen(s)] = '@';
	l = 0, zn = 1;

	while (true)
	{
		get();
		if (s[l] == '@') break;
		if (s[l] == '+') zn = 1;
		else zn = -1;
		l++;
	}

	sort(all(q[0]));
	sort(all(q[1]));

	forn(i, q[0].size() + 1)
		forn(j, q[1].size() + 1)
			d[i][j] = -inf64;
	d[0][0] = 0;

	forn(i, q[0].size() + 1)
		forn(j, q[1].size() + 1)
			if (d[i][j] == -inf64)
			{
				if (i > 0) d[i][j] = max(d[i][j], d[i - 1][j] + q[0][i - 1] * (a + i + j - 1));
				if (j > 0) d[i][j] = max(d[i][j], d[i][j - 1] + q[1][j - 1] * (a + i + j));
			}

	cout << d[q[0].size()][q[1].size()] << endl;

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <ctime>
#include <cmath>
#include <algorithm>

using namespace std;

typedef long double ldb;
typedef long long int64;

double const pi = 3.1415926535897932384626433832795;
int const inf = (int) 1e9;
int64 const inf64 = (int64) 2e18;

#define y1 qqqqqqq
#define forn(i, n) for (int i = 0; i < (int) n; i++)
#define seta(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define pii pair < int, int >
#define all(a) (a).begin(), (a).end()
#define mp make_pair
#define fs first
#define sc second

const string task = "";

char s[100000];
int a, l, zn;
long long d[1010][1010];
vector <int> q[2];

void get()
{
	int k = 0;
	if (s[l] >= '0' && s[l] <= '9')
	{
		while (s[l] != '*')
		{
			k = k * 10 + s[l] - '0';
			l++;
		}
		l++;
	}
	else k = 1;
	k *= zn;
	int tp;

	if (s[l] == 'a') tp = 0;
	else tp = 1;
	l += 3;

	q[tp].pb(k);
}

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

	cin >> a;
	scanf("%s", s);
	s[strlen(s) + 1] = '\0';
	s[strlen(s)] = '@';
	l = 0, zn = 1;

	while (true)
	{
		get();
		if (s[l] == '@') break;
		if (s[l] == '+') zn = 1;
		else zn = -1;
		l++;
	}

	sort(all(q[0]));
	sort(all(q[1]));

	forn(i, q[0].size() + 1)
		forn(j, q[1].size() + 1)
			d[i][j] = -inf64;
	d[0][0] = 0;

	forn(i, q[0].size() + 1)
		forn(j, q[1].size() + 1)
			if (d[i][j] == -inf64)
			{
				if (i > 0) d[i][j] = max(d[i][j], d[i - 1][j] + q[0][i - 1] * (a + i + j - 1));
				if (j > 0) d[i][j] = max(d[i][j], d[i][j - 1] + q[1][j - 1] * (a + i + j));
			}

	cout << d[q[0].size()][q[1].size()] << endl;

	return 0;
}


#include <cstdio>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>       //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>      //do setprecision
using namespace std;
#define PB push_back
#define LL long long
#define ULL unsigned LL
#define LD long double

#define MR 2000010
#define MS 2000

int a, n, iles;
char s[MR];

bool done[MS];

struct summand
{
    int wsp;
    bool pre;   //jaka inkrementacja
}t[MS];

bool cmp1(summand s1, summand s2)
{
    return s1.wsp < s2.wsp;
}
bool cmp2(summand s1, summand s2)
{
    return s1.pre < s2.pre;
}
bool cmp3(summand s1, summand s2)
{
    return s1.pre > s2.pre;
}

void processS(int p, int k, int sgn)
{
    int pom = 0;
    while(s[p] >= '0' && s[p] <= '9')
    {
        pom = 10 * pom + s[p]-'0';
        p++;
    }
    if(s[p] == 'a') //nie ma wsp
    {
        t[iles].pre = 0;
        t[iles++].wsp = 1;
        return;
    }
    if(s[p] == '+') //nie ma wsp
    {
        t[iles].pre = 1;
        t[iles++].wsp = 1;
        return;
    }
    t[iles].wsp = sgn * pom;
    t[iles++].pre = s[p+1] == '+';    //preinkrementacja
}

void processE(int p, int k)
{
    int ilep = 0;
    for(int i = k-1; i >= p; i--)
        if(s[i] == '-')
        {
            processE(p, i);
            processS(i+1, k, -1);
            return;
        }
        else if(s[i] == '+')
        {
            ilep++;
            if(ilep==3)
            {
                processE(p, i);
                processS(i+1, k, 1);
                return;
            }
        }
    processS(p, k, 1);
}//processE

int main()
{
    scanf("%d%s", &a, s);
    n = strlen(s);
    processE(0, n);
    int sum = 0;
    for(int i = 0; i < iles; i++)
    {
        int minv = MR, minnr;
        for(int j = 0; j < iles; j++)
            if(!done[j])
                if(t[j].wsp < minv
                    || (t[j].wsp == minv &&
                    (t[j].wsp > 0 && t[j].pre && !t[minnr].pre)||(t[j].wsp < 0 && !t[j].pre && t[minnr].pre)
                    ))
            {
                minv = t[j].wsp;
                minnr = j;
            }
        if(t[minnr].pre)
        {
            a++;
            sum += t[minnr].wsp * a;
        }
        else
        {
            sum += t[minnr].wsp * a;
            a++;
        }
        done[minnr] = 1;
    }
    printf("%d\n", sum);
    return 0;
}


#include <cstdio>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>       //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>      //do setprecision
using namespace std;
#define PB push_back
#define LL long long
#define ULL unsigned LL
#define LD long double

#define MR 2000010
#define MS 2000

int a, n, iles;
char s[MR];

bool done[MS];

struct summand
{
    int wsp;
    bool pre;   //jaka inkrementacja
}t[MS];

bool cmp1(summand s1, summand s2)
{
    return s1.wsp < s2.wsp;
}
bool cmp2(summand s1, summand s2)
{
    return s1.pre < s2.pre;
}
bool cmp3(summand s1, summand s2)
{
    return s1.pre > s2.pre;
}

void processS(int p, int k, int sgn)
{
    int pom = 0;
    while(s[p] >= '0' && s[p] <= '9')
        pom = 10 * pom + s[p]-'0';
    t[iles].wsp = sgn * pom;
    t[iles++].pre = s[p] == '+';    //preinkrementacja
}

void processE(int p, int k)
{
    int ilep = 0;
    for(int i = k-1; i >= p; i--)
        if(s[i] == '-')
        {
            processE(p, i);
            processS(i+1, k, -1);
            return;
        }
        else if(s[i] == '+')
        {
            ilep++;
            if(ilep==3)
            {
                processE(p, i);
                processS(i+1, k, 1);
                return;
            }
        }
}//processE

int main()
{
    scanf("%d%s", &a, s);
    n = strlen(s);
    processE(0, n);
    int sum = 0;
    for(int i = 0; i < iles; i++)
    {
        int minv = -MR, minnr;
        for(int j = 0; j < iles; j++)
            if(!done[j])
                if(t[j].wsp < minv
                    || (t[j].wsp == minv &&
                    (t[j].wsp > 0 && t[j].pre && !t[minnr].pre)||(t[j].wsp < 0 && !t[j].pre && t[minnr].pre)
                    ))
            {
                minv = t[j].wsp;
                minnr = j;
            }
        if(t[minnr].pre)
        {
            a++;
            sum += t[minnr].wsp * a;
        }
        else
        {
            sum += t[minnr].wsp * a;
            a++;
        }
        done[minnr] = 1;
    }
    printf("%d\n", sum);
    return 0;
}


#include <cstdio>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>       //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>      //do setprecision
using namespace std;
#define PB push_back
#define LL long long
#define ULL unsigned LL
#define LD long double

#define MR 2000010
#define MS 2000

int a, n, iles;
char s[MR];

bool done[MS];

struct summand
{
    int wsp;
    bool pre;   //jaka inkrementacja
}t[MS];

bool cmp1(summand s1, summand s2)
{
    return s1.wsp < s2.wsp;
}
bool cmp2(summand s1, summand s2)
{
    return s1.pre < s2.pre;
}
bool cmp3(summand s1, summand s2)
{
    return s1.pre > s2.pre;
}

void processS(int p, int k, int sgn)
{
    int pom = 0;
    while(s[p] >= '0' && s[p] <= '9')
    {
        pom = 10 * pom + s[p]-'0';
        p++;
    }
    t[iles].wsp = sgn * pom;
    t[iles++].pre = s[p] == '+';    //preinkrementacja
}

void processE(int p, int k)
{
    int ilep = 0;
    for(int i = k-1; i >= p; i--)
        if(s[i] == '-')
        {
            processE(p, i);
            processS(i+1, k, -1);
            return;
        }
        else if(s[i] == '+')
        {
            ilep++;
            if(ilep==3)
            {
                processE(p, i);
                processS(i+1, k, 1);
                return;
            }
        }
    processS(p, k, 1);
}//processE

int main()
{
    scanf("%d%s", &a, s);
    n = strlen(s);
    processE(0, n);
    int sum = 0;
    for(int i = 0; i < iles; i++)
    {
        int minv = -MR, minnr;
        for(int j = 0; j < iles; j++)
            if(!done[j])
                if(t[j].wsp < minv
                    || (t[j].wsp == minv &&
                    (t[j].wsp > 0 && t[j].pre && !t[minnr].pre)||(t[j].wsp < 0 && !t[j].pre && t[minnr].pre)
                    ))
            {
                minv = t[j].wsp;
                minnr = j;
            }
        if(t[minnr].pre)
        {
            a++;
            sum += t[minnr].wsp * a;
        }
        else
        {
            sum += t[minnr].wsp * a;
            a++;
        }
        done[minnr] = 1;
    }
    printf("%d\n", sum);
    return 0;
}


#include <cstdio>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>       //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>      //do setprecision
using namespace std;
#define PB push_back
#define LL long long
#define ULL unsigned LL
#define LD long double

#define MR 5000010
#define MS 2000

int a, n, iles;
char s[MR];

struct summand
{
    int wsp;
    bool pre;   //jaka inkrementacja
}t[MS];

bool cmp(summand s1, summand s2)
{
    return s1.wsp < s2.wsp;
}

void processS(int p, int k, int sgn)
{
    if(s[p] == 'a') //nie ma wsp
    {
        t[iles].pre = 0;
        t[iles++].wsp = 1;
        return;
    }
    if(s[p] == '+') //nie ma wsp
    {
        t[iles].pre = 1;
        t[iles++].wsp = 1;
        return;
    }
    int pom = 0;
    while(s[p] >= '0' && s[p] <= '9')
    {
        pom = 10 * pom + s[p]-'0';
        p++;
    }
    t[iles].wsp = sgn * pom;
    t[iles++].pre = s[p+1] == '+';    //preinkrementacja
}

void processE(int p, int k)
{
    int ilep = 0;
    for(int i = k-1; i >= p; i--)
        if(s[i] == '-')
        {
            processE(p, i);
            processS(i+1, k, -1);
            return;
        }
        else if(s[i] == '+')
        {
            ilep++;
            if(ilep==3)
            {
                processE(p, i);
                processS(i+1, k, 1);
                return;
            }
        }
    processS(p, k, 1);
}//processE

int main()
{
    scanf("%d%s", &a, s);
    n = strlen(s);
    processE(0, n);
    sort(t, t+iles, cmp);   //nie musimy przejmowac sie ++a czy a++
    //jak sa 2 te same wspolczynniki o roznych inkrementacjach to i tak w sumie
    //to samo bedzie
    int sum = 0;
    for(int i = 0; i < iles; i++)
        if(t[i].pre)
        {
            a++;
            sum += t[i].wsp * a;
        }
        else
        {
            sum += t[i].wsp * a;
            a++;
        }
    printf("%d\n", sum);
    return 0;
}


#include <cstdio>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>       //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>      //do setprecision
using namespace std;
#define PB push_back
#define LL long long
#define ULL unsigned LL
#define LD long double

#define MR 2000010
#define MS 2000

int a, n, iles;
char s[MR];

bool done[MS];

struct summand
{
    int wsp;
    bool pre;   //jaka inkrementacja
}t[MS];

bool cmp1(summand s1, summand s2)
{
    return s1.wsp < s2.wsp;
}
bool cmp2(summand s1, summand s2)
{
    return s1.pre < s2.pre;
}
bool cmp3(summand s1, summand s2)
{
    return s1.pre > s2.pre;
}

void processS(int p, int k, int sgn)
{
    int pom = 0;
    while(s[p] >= '0' && s[p] <= '9')
    {
        pom = 10 * pom + s[p]-'0';
        p--;
    }
    t[iles].wsp = sgn * pom;
    t[iles++].pre = s[p] == '+';    //preinkrementacja
}

void processE(int p, int k)
{
    int ilep = 0;
    for(int i = k-1; i >= p; i--)
        if(s[i] == '-')
        {
            processE(p, i);
            processS(i+1, k, -1);
            return;
        }
        else if(s[i] == '+')
        {
            ilep++;
            if(ilep==3)
            {
                processE(p, i);
                processS(i+1, k, 1);
                return;
            }
        }
    processS(0, k, 1);
}//processE

int main()
{
    scanf("%d%s", &a, s);
    n = strlen(s);
    processE(0, n);
    int sum = 0;
    for(int i = 0; i < iles; i++)
    {
        int minv = -MR, minnr;
        for(int j = 0; j < iles; j++)
            if(!done[j])
                if(t[j].wsp < minv
                    || (t[j].wsp == minv &&
                    (t[j].wsp > 0 && t[j].pre && !t[minnr].pre)||(t[j].wsp < 0 && !t[j].pre && t[minnr].pre)
                    ))
            {
                minv = t[j].wsp;
                minnr = j;
            }
        if(t[minnr].pre)
        {
            a++;
            sum += t[minnr].wsp * a;
        }
        else
        {
            sum += t[minnr].wsp * a;
            a++;
        }
        done[minnr] = 1;
    }
    printf("%d\n", sum);
    return 0;
}


#include <cstdio>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>       //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>      //do setprecision
using namespace std;
#define PB push_back
#define LL long long
#define ULL unsigned LL
#define LD long double

#define MR 1000010
#define MS 2000

int a, n, iles;
char s[MR];

struct summand
{
    int wsp;
    bool pre;   //jaka inkrementacja
}t[MS];

bool cmp(summand s1, summand s2)
{
    return s1.wsp < s2.wsp;
}

void processS(int p, int k, int sgn)
{
    if(s[p] == 'a') //nie ma wsp
    {
        t[iles].pre = 0;
        t[iles++].wsp = sgn;
        return;
    }
    if(s[p] == '+') //nie ma wsp
    {
        t[iles].pre = 1;
        t[iles++].wsp = sgn;
        return;
    }
    int pom = 0;
    while(s[p] >= '0' && s[p] <= '9')
    {
        pom = 10 * pom + s[p]-'0';
        p++;
    }
    t[iles].wsp = sgn * pom;
    t[iles++].pre = s[p+1] == '+';    //preinkrementacja
}

void processE(int p, int k)
{
    int ilep = 0;
    for(int i = k-1; i >= p; i--)
        if(s[i] == '-')
        {
            processE(p, i);
            processS(i+1, k, -1);
            return;
        }
        else if(s[i] == '+')
        {
            ilep++;
            if(ilep==3)
            {
                processE(p, i);
                processS(i+1, k, 1);
                return;
            }
        }
    processS(p, k, 1);
}//processE

int main()
{
    scanf("%d%s", &a, s);
    n = strlen(s);
    processE(0, n);
    sort(t, t+iles, cmp);   //nie musimy przejmowac sie ++a czy a++
    //jak sa 2 te same wspolczynniki o roznych inkrementacjach to i tak w sumie
    //to samo bedzie
    int sum = 0;
    for(int i = 0; i < iles; i++)
        if(t[i].pre)
        {
            a++;
            sum += t[i].wsp * a;
        }
        else
        {
            sum += t[i].wsp * a;
            a++;
        }
    printf("%d\n", sum);
    return 0;
}


#include <cstdio>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>       //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>      //do setprecision
using namespace std;
#define PB push_back
#define LL long long
#define ULL unsigned LL
#define LD long double

#define MR 5000010
#define MS 2000

int a, n, iles;
char s[MR];

struct summand
{
    int wsp;
    bool pre;   //jaka inkrementacja
}t[MS];

bool cmp(summand s1, summand s2)
{
    return s1.wsp < s2.wsp;
}

void processS(int p, int k, int sgn)
{
    int pom = 0;
    while(s[p] >= '0' && s[p] <= '9')
    {
        pom = 10 * pom + s[p]-'0';
        p++;
    }
    if(s[p] == 'a') //nie ma wsp
    {
        t[iles].pre = 0;
        t[iles++].wsp = 1;
        return;
    }
    if(s[p] == '+') //nie ma wsp
    {
        t[iles].pre = 1;
        t[iles++].wsp = 1;
        return;
    }
    t[iles].wsp = sgn * pom;
    t[iles++].pre = s[p+1] == '+';    //preinkrementacja
}

void processE(int p, int k)
{
    int ilep = 0;
    for(int i = k-1; i >= p; i--)
        if(s[i] == '-')
        {
            processE(p, i);
            processS(i+1, k, -1);
            return;
        }
        else if(s[i] == '+')
        {
            ilep++;
            if(ilep==3)
            {
                processE(p, i);
                processS(i+1, k, 1);
                return;
            }
        }
    processS(p, k, 1);
}//processE

int main()
{
    scanf("%d%s", &a, s);
    n = strlen(s);
    processE(0, n);
    sort(t, t+iles, cmp);   //nie musimy przejmowac sie ++a czy a++
    //jak sa 2 te same wspolczynniki o roznych inkrementacjach to i tak w sumie
    //to samo bedzie
    int sum = 0;
    for(int i = 0; i < iles; i++)
        if(t[i].pre)
        {
            a++;
            sum += t[i].wsp * a;
        }
        else
        {
            sum += t[i].wsp * a;
            a++;
        }
    printf("%d\n", sum);
    return 0;
}


#include <cstdio>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>       //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>      //do setprecision
using namespace std;
#define PB push_back
#define LL long long
#define ULL unsigned LL
#define LD long double

#define MR 2000010
#define MS 2000

int a, n, iles;
char s[MR];

struct summand
{
    int wsp;
    bool pre;   //jaka inkrementacja
}t[MS];

bool cmp(summand s1, summand s2)
{
    return s1.wsp < s2.wsp;
}

void processS(int p, int k, int sgn)
{
    int pom = 0;
    while(s[p] >= '0' && s[p] <= '9')
    {
        pom = 10 * pom + s[p]-'0';
        p++;
    }
    if(s[p] == 'a') //nie ma wsp
    {
        t[iles].pre = 0;
        t[iles++].wsp = 1;
        return;
    }
    if(s[p] == '+') //nie ma wsp
    {
        t[iles].pre = 1;
        t[iles++].wsp = 1;
        return;
    }
    t[iles].wsp = sgn * pom;
    t[iles++].pre = s[p+1] == '+';    //preinkrementacja
}

void processE(int p, int k)
{
    int ilep = 0;
    for(int i = k-1; i >= p; i--)
        if(s[i] == '-')
        {
            processE(p, i);
            processS(i+1, k, -1);
            return;
        }
        else if(s[i] == '+')
        {
            ilep++;
            if(ilep==3)
            {
                processE(p, i);
                processS(i+1, k, 1);
                return;
            }
        }
    processS(p, k, 1);
}//processE

int main()
{
    scanf("%d%s", &a, s);
    n = strlen(s);
    processE(0, n);
    sort(t, t+iles, cmp);   //nie musimy przejmowac sie ++a czy a++
    //jak sa 2 te same wspolczynniki o roznych inkrementacjach to i tak w sumie
    //to samo bedzie
    int sum = 0;
    for(int i = 0; i < iles; i++)
        if(t[i].pre)
        {
            a++;
            sum += t[i].wsp * a;
        }
        else
        {
            sum += t[i].wsp * a;
            a++;
        }
    printf("%d\n", sum);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;

string s;

int main()
{
    string s,g;
    int a,p;
    scanf("%d",&a);
    getline(cin,s);
    getline(cin,s);
    p=1;
    g="";
    bool fk=false;
    int i,koef=1,sign=1,koef_first[1003]={0},koef_second[1003]={0};
    for (i=0;i<s.size();i++)
    {
        g=s.substr(i,3);
        if (p==1 || p==5)
        {
            if (s[i]>='0' && s[i]<='9')
            {
                if (!fk)koef=0;
                koef=koef*10+(s[i]-'0');
                p=2;
                fk=true;
                continue;
            }
            if (g=="a++")
            {
                koef=koef*sign;
                koef_first[++koef_first[0]]=koef;
                koef=1;sign=1;fk=false;
                p=4;
                i++;i++;
                continue;
            }
            if (g=="++a")
            {
                koef=koef*sign;
                koef_second[++koef_second[0]]=koef;
                koef=1;sign=1;fk=false;
                p=4;
                i++;i++;
                continue;
            }
        }
        if (p==1 || p==2)
        {
            if (s[i]=='*')
            {
                p=5;
                continue;
            }
            if (s[i]>='0' && s[i]<='9')
            {
                koef=koef*10+(s[i]-'0');
                p=2;
                fk=true;
                continue;
            }
        }
        if (p==4)
        {
            if (s[i]=='+')
            {
                sign=+1;
            }
            if (s[i]=='-')
            {
                sign=-1;
            }
            p=1;
        }
    }
    int ans=0;
    sort(koef_first+1,koef_first+koef_first[0]+1);
    sort(koef_second+1,koef_second+koef_second[0]+1);
    int x=1,y=1;
    while (x+y!=koef_first[0]+koef_second[0]+2)
    {
        if ((koef_first[x]<=koef_second[y] || y>koef_second[0]) && x<=koef_first[0])
        {
            ans+=koef_first[x]*a;
            a++;
            x++;
        }
        else
        {
            a++;
            ans+=koef_second[y]*a;
            y++;
        }
    }
    printf("%d",ans);
}


#include <iostream>
#include <string>
#include <cstring>
#include <string.h>
#include <algorithm>
#include <vector>

using namespace std;

char s[2000000];
int x;

struct summ{
	int x;
	int type;
};

summ a[2000];
int ver=0;

void parse(){
	int k=strlen(s);
	for (int i=0; i<k; i++){
		if (i==0){
			int zn=0;
			int tp=0;
			if (s[i]-'0'>=0&&s[i]-'0'<10){
				while (s[i]-'0'>=0&&s[i]-'0'<10)
					zn*=10, zn+=s[i]-'0', i++;
				i++;
				if (s[i]=='+') tp=1;
				i+=2;
			} else
			{
				zn=1;
				if (s[i]=='+') tp=1;
				i+=2;
			}
			ver++;
			a[ver].type=tp;
			a[ver].x=zn;
			continue;
		} else
		if (s[i]=='+'){
			int zn=0;
			int tp=0;
			i++;
			if (s[i]-'0'>=0&&s[i]-'0'<10){
				while (s[i]-'0'>=0&&s[i]-'0'<10)
					zn*=10, zn+=s[i]-'0', i++;
				i++;
				if (s[i]=='+') tp=1;
				i+=2;
			} else
			{
				zn=1;
				if (s[i]=='+') tp=1;
				i+=2;
			}
			ver++;
			a[ver].type=tp;
			a[ver].x=zn;
		} else
		if (s[i]=='-')
		{
			int zn=0;
			int tp=0;
			i++;
			if (s[i]!='a'&&s[i]!='+'){
				while (s[i]-'0'>=0&&s[i]-'0'<10)
					zn*=10, zn+=s[i]-'0', i++;
				i++;
				if (s[i]=='+') tp=1;
				i+=2;
			} else
			{
				zn=1;
				if (s[i]=='+') tp=1;
				i+=2;
			}
			ver++;
			a[ver].type=tp;
			a[ver].x=-zn;
		}
	}
}

vector <summ> plus;
vector <summ> minus;
vector <summ> nules;

int cmp(summ a, summ b){
	return a.x<b.x;
}

int do_oper(vector <summ> a,int st,int tp){
	int res=0;
	if (tp==1){
		for (int i=0; i<(int)a.size(); i++){
			if (a[i].type==0) res+=a[i].x*st, st++; else
				st++, res+=a[i].x*st;
		}
	} else
	{
		vector <summ> b=a;
		reverse(b.begin(),b.end());
		res=do_oper(b,st,1);
	}
	return res;
}

int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);

	scanf("%d\n",&x);
	gets(s);
	parse();

	//for (int i=1; i<=ver; i++)
	//	printf("%d %d\n",a[i].x,a[i].type);

	for (int i=1; i<=ver; i++)
		if (a[i].x>0) plus.push_back(a[i]); else
			if (a[i].x<0) minus.push_back(a[i]); else
				nules.push_back(a[i]);

	sort(plus.begin(),plus.end(),cmp);
	sort(minus.begin(),minus.end(),cmp);
	sort(nules.begin(),nules.end(),cmp);

	int aa=(int)plus.size();
	int bb=(int)minus.size();
	int cc=(int)nules.size();

	int mxres=-2000000000;

	mxres=max(mxres,do_oper(plus,x,0)+do_oper(minus,x+aa,0)+do_oper(nules,x+aa+bb,0));
	mxres=max(mxres,do_oper(plus,x,0)+do_oper(minus,x+aa,0)+do_oper(nules,x+aa+bb,1));
	mxres=max(mxres,do_oper(plus,x,0)+do_oper(minus,x+aa,1)+do_oper(nules,x+aa+bb,0));
	mxres=max(mxres,do_oper(plus,x,0)+do_oper(minus,x+aa,1)+do_oper(nules,x+aa+bb,1));
	mxres=max(mxres,do_oper(plus,x,1)+do_oper(minus,x+aa,0)+do_oper(nules,x+aa+bb,0));
	mxres=max(mxres,do_oper(plus,x,1)+do_oper(minus,x+aa,0)+do_oper(nules,x+aa+bb,1));
	mxres=max(mxres,do_oper(plus,x,1)+do_oper(minus,x+aa,1)+do_oper(nules,x+aa+bb,0));
	mxres=max(mxres,do_oper(plus,x,1)+do_oper(minus,x+aa,1)+do_oper(nules,x+aa+bb,1));

	mxres=max(mxres,do_oper(plus,x,0)+do_oper(minus,x+aa+cc,0)+do_oper(nules,x+aa,0));
	mxres=max(mxres,do_oper(plus,x,0)+do_oper(minus,x+aa+cc,0)+do_oper(nules,x+aa,1));
	mxres=max(mxres,do_oper(plus,x,0)+do_oper(minus,x+aa+cc,1)+do_oper(nules,x+aa,0));
	mxres=max(mxres,do_oper(plus,x,0)+do_oper(minus,x+aa+cc,1)+do_oper(nules,x+aa,1));
	mxres=max(mxres,do_oper(plus,x,1)+do_oper(minus,x+aa+cc,0)+do_oper(nules,x+aa,0));
	mxres=max(mxres,do_oper(plus,x,1)+do_oper(minus,x+aa+cc,0)+do_oper(nules,x+aa,1));
	mxres=max(mxres,do_oper(plus,x,1)+do_oper(minus,x+aa+cc,1)+do_oper(nules,x+aa,0));
	mxres=max(mxres,do_oper(plus,x,1)+do_oper(minus,x+aa+cc,1)+do_oper(nules,x+aa,1));

	mxres=max(mxres,do_oper(plus,x+bb,0)+do_oper(minus,x,0)+do_oper(nules,x+aa+bb,0));
	mxres=max(mxres,do_oper(plus,x+bb,0)+do_oper(minus,x,0)+do_oper(nules,x+aa+bb,1));
	mxres=max(mxres,do_oper(plus,x+bb,0)+do_oper(minus,x,1)+do_oper(nules,x+aa+bb,0));
	mxres=max(mxres,do_oper(plus,x+bb,0)+do_oper(minus,x,1)+do_oper(nules,x+aa+bb,1));
	mxres=max(mxres,do_oper(plus,x+bb,1)+do_oper(minus,x,0)+do_oper(nules,x+aa+bb,0));
	mxres=max(mxres,do_oper(plus,x+bb,1)+do_oper(minus,x,0)+do_oper(nules,x+aa+bb,1));
	mxres=max(mxres,do_oper(plus,x+bb,1)+do_oper(minus,x,1)+do_oper(nules,x+aa+bb,0));
	mxres=max(mxres,do_oper(plus,x+bb,1)+do_oper(minus,x,1)+do_oper(nules,x+aa+bb,1));

	mxres=max(mxres,do_oper(plus,x+cc+bb,0)+do_oper(minus,x,0)+do_oper(nules,x+bb,0));
	mxres=max(mxres,do_oper(plus,x+cc+bb,0)+do_oper(minus,x,0)+do_oper(nules,x+bb,1));
	mxres=max(mxres,do_oper(plus,x+cc+bb,0)+do_oper(minus,x,1)+do_oper(nules,x+bb,0));
	mxres=max(mxres,do_oper(plus,x+cc+bb,0)+do_oper(minus,x,1)+do_oper(nules,x+bb,1));
	mxres=max(mxres,do_oper(plus,x+cc+bb,1)+do_oper(minus,x,0)+do_oper(nules,x+bb,0));
	mxres=max(mxres,do_oper(plus,x+cc+bb,1)+do_oper(minus,x,0)+do_oper(nules,x+bb,1));
	mxres=max(mxres,do_oper(plus,x+cc+bb,1)+do_oper(minus,x,1)+do_oper(nules,x+bb,0));
	mxres=max(mxres,do_oper(plus,x+cc+bb,1)+do_oper(minus,x,1)+do_oper(nules,x+bb,1));

	mxres=max(mxres,do_oper(plus,x+cc,0)+do_oper(minus,x+aa+cc,0)+do_oper(nules,x,0));
	mxres=max(mxres,do_oper(plus,x+cc,0)+do_oper(minus,x+aa+cc,0)+do_oper(nules,x,1));
	mxres=max(mxres,do_oper(plus,x+cc,0)+do_oper(minus,x+aa+cc,1)+do_oper(nules,x,0));
	mxres=max(mxres,do_oper(plus,x+cc,0)+do_oper(minus,x+aa+cc,1)+do_oper(nules,x,1));
	mxres=max(mxres,do_oper(plus,x+cc,1)+do_oper(minus,x+aa+cc,0)+do_oper(nules,x,0));
	mxres=max(mxres,do_oper(plus,x+cc,1)+do_oper(minus,x+aa+cc,0)+do_oper(nules,x,1));
	mxres=max(mxres,do_oper(plus,x+cc,1)+do_oper(minus,x+aa+cc,1)+do_oper(nules,x,0));
	mxres=max(mxres,do_oper(plus,x+cc,1)+do_oper(minus,x+aa+cc,1)+do_oper(nules,x,1));

	mxres=max(mxres,do_oper(plus,x+bb+cc,0)+do_oper(minus,x+cc,0)+do_oper(nules,x,0));
	mxres=max(mxres,do_oper(plus,x+bb+cc,0)+do_oper(minus,x+cc,0)+do_oper(nules,x,1));
	mxres=max(mxres,do_oper(plus,x+bb+cc,0)+do_oper(minus,x+cc,1)+do_oper(nules,x,0));
	mxres=max(mxres,do_oper(plus,x+bb+cc,0)+do_oper(minus,x+cc,1)+do_oper(nules,x,1));
	mxres=max(mxres,do_oper(plus,x+bb+cc,1)+do_oper(minus,x+cc,0)+do_oper(nules,x,0));
	mxres=max(mxres,do_oper(plus,x+bb+cc,1)+do_oper(minus,x+cc,0)+do_oper(nules,x,1));
	mxres=max(mxres,do_oper(plus,x+bb+cc,1)+do_oper(minus,x+cc,1)+do_oper(nules,x,0));
	mxres=max(mxres,do_oper(plus,x+bb+cc,1)+do_oper(minus,x+cc,1)+do_oper(nules,x,1));

	cout<<mxres<<endl;

	return 0;
}


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

using namespace std;

#define mp make_pair
typedef unsigned long long ull;
long long const INF = 2000000000;
long long const MAXN = 50001;
long long const P = 100000000000;

string str;

struct Sum
{
    int coef;
    bool pre;
    Sum(): coef(1) {}
};

Sum mas[1001];

bool operator <(const Sum& a, const Sum& b)
{
    if(a.coef != b.coef)
        return a.coef < b.coef;
    return a.pre < b.pre;
}

int main()
{
    freopen("readme.txt", "r", stdin);
    int a;

    cin >> a;
    cin >> str;
    str = "+" + str;
    int n = 0;
    for(int i=0; i<str.size(); ++i)
    {
        if(str[i++] == '-')
        {
            mas[n].coef *= -1;
        }
        int k = 0;
        bool has = false;
        while(isdigit(str[i]))
        {
            k*=10; k+=str[i++]-'0';
            has = true;
        }
        if(k==0 && !has)
        {
            mas[n].coef *= 1;
        }
        else
        {
            mas[n].coef *= k;
        }

        if(str[i] == '*')
            ++i;

        if(str[i]=='a')
        {
            mas[n].pre = false;
        }
        else
        {
            mas[n].pre = true;
        }
        i+=2;
        ++n;
    }

    sort(mas, mas+n);
    int sum = 0;
    for(int i=0; i<n; ++i)
    {
        if(mas[i].pre)
            ++a;

        sum+= a * mas[i].coef;

        if(!mas[i].pre)
            ++a;
    }

    cout << sum << endl;

    return 0;
}


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

using namespace std;

#define mp make_pair
typedef unsigned long long ull;
long long const INF = 2000000000;
long long const MAXN = 50001;
long long const P = 100000000000;

string str;

struct Sum
{
    int coef;
    bool pre;
    Sum(): coef(1) {}
};

Sum mas[1001];

bool operator <(const Sum& a, const Sum& b)
{
    if(a.coef != b.coef)
        return a.coef < b.coef;
    return a.pre < b.pre;
}

int main()
{
    //freopen("readme.txt", "r", stdin);
    int a;

    cin >> a;
    cin >> str;
    str = "+" + str;
    int n = 0;
    for(int i=0; i<str.size(); ++i)
    {
        if(str[i++] == '-')
        {
            mas[n].coef *= -1;
        }
        int k = 0;
        bool has = false;
        while(isdigit(str[i]))
        {
            k*=10; k+=str[i++]-'0';
            has = true;
        }
        if(k==0 && !has)
        {
            mas[n].coef *= 1;
        }
        else
        {
            mas[n].coef *= k;
        }

        if(str[i] == '*')
            ++i;

        if(str[i]=='a')
        {
            mas[n].pre = false;
        }
        else
        {
            mas[n].pre = true;
        }
        i+=2;
        ++n;
    }

    sort(mas, mas+n);
    int sum = 0;
    for(int i=0; i<n; ++i)
    {
        if(mas[i].pre)
            ++a;

        sum+= a * mas[i].coef;

        if(!mas[i].pre)
            ++a;
    }

    cout << sum << endl;

    return 0;
}


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

using namespace std;

#define mp make_pair
typedef unsigned long long ull;
long long const INF = 2000000000;
long long const MAXN = 50001;
long long const P = 100000000000;

string str;

struct Sum
{
    int coef;
    bool pre;
    Sum(): coef(1) {}
};

Sum mas[1001];

bool operator <(const Sum& a, const Sum& b)
{
    int vala = a.pre? 2 * a.coef : a.coef + 1, valb = b.pre? 2 * b.coef : b.coef + 1;
    return vala < valb;
}

int main()
{
    //freopen("readme.txt", "r", stdin);
    int a;

    cin >> a;
    cin >> str;
    str = "+" + str;
    int n = 0;
    for(int i=0; i<str.size(); ++i)
    {
        if(str[i++] == '-')
        {
            mas[n].coef *= -1;
        }
        int k = 0;
        while(str[i]>='0' && str[i]<='9')
        {
            k*=10; k+=str[i++]-'0';
        }
        mas[n].coef *= k?k:1;

        if(str[i] == '*')
            ++i;

        if(str[i]=='a')
        {
            mas[n].pre = false;
        }
        else
        {
            mas[n].pre = true;
        }
        i+=2;
        ++n;
    }

    sort(mas, mas+n);
    int sum = 0;
    for(int i=0; i<n; ++i)
    {
        if(mas[i].pre)
            ++a;

        sum+=a*mas[i].coef;

        if(!mas[i].pre)
            ++a;
    }

    cout << sum << endl;

    return 0;
}


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

using namespace std;

#define mp make_pair
typedef unsigned long long ull;
long long const INF = 2000000000;
long long const MAXN = 50001;
long long const P = 100000000000;

string str;

struct Sum
{
    int coef;
    bool pre;
    Sum(): coef(1) {}
};

Sum mas[1001];

bool operator <(const Sum& a, const Sum& b)
{
    return a.coef * (a.pre+1) < b.coef * (b.pre+1);
}

int main()
{
    //freopen("readme.txt", "r", stdin);
    int a;

    cin >> a;
    cin >> str;
    str = "+" + str;
    int n = 0;
    for(int i=0; i<str.size(); ++i)
    {
        if(str[i++] == '-')
        {
            mas[n].coef *= -1;
        }
        int k = 0;
        while(str[i]>='0' && str[i]<='9')
        {
            k*=10; k+=str[i++]-'0';
        }
        mas[n].coef *= k?k:1;

        if(str[i] == '*')
            ++i;

        if(str[i]=='a')
        {
            mas[n].pre = false;
        }
        else
        {
            mas[n].pre = true;
        }
        i+=2;
        ++n;
    }

    sort(mas, mas+n);
    int sum = 0;
    for(int i=0; i<n; ++i)
    {
        if(mas[i].pre)
            ++a;

        sum+=a*mas[i].coef;

        if(!mas[i].pre)
            ++a;
    }

    cout << sum << endl;
    return 0;
}


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

using namespace std;

#define mp make_pair
typedef unsigned long long ull;
long long const INF = 2000000000;
long long const MAXN = 50001;
long long const P = 100000000000;

string str;

struct Sum
{
    int coef;
    bool pre;
    Sum(): coef(1) {}
};

Sum mas[1001];

bool operator <(const Sum& a, const Sum& b)
{
    return a.coef * (a.pre+1) < b.coef * (a.pre+1);
}

int main()
{
    //freopen("readme.txt", "r", stdin);
    int a;

    cin >> a;
    cin >> str;
    str = "+" + str;
    int n = 0;
    for(int i=0; i<str.size(); ++i)
    {
        if(str[i++] == '-')
        {
            mas[n].coef *= -1;
        }
        int k = 0;
        while(str[i]>='0' && str[i]<='9')
        {
            k*=10; k+=str[i++]-'0';
        }
        mas[n].coef *= k?k:1;

        if(str[i] == '*')
            ++i;

        if(str[i]=='a')
        {
            mas[n].pre = false;
        }
        else
        {
            mas[n].pre = true;
        }
        i+=2;
        ++n;
    }

    sort(mas, mas+n);
    int sum = 0;
    for(int i=0; i<n; ++i)
    {
        if(mas[i].pre)
            ++a;

        sum+=a*mas[i].coef;

        if(!mas[i].pre)
            ++a;
    }

    cout << sum << endl;
    return 0;
}


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

using namespace std;

#define mp make_pair
typedef unsigned long long ull;
long long const INF = 2000000000;
long long const MAXN = 50001;
long long const P = 100000000000;

string str;

struct Sum
{
    int coef;
    bool pre;
    Sum(): coef(1) {}
};

Sum mas[1001];

bool operator <(const Sum& a, const Sum& b)
{
    if(a.coef != b.coef)
        return a.coef < b.coef;
    return a.pre < b.pre;
}

int main()
{
    //freopen("readme.txt", "r", stdin);
    int a;

    cin >> a;
    cin >> str;
    str = "+" + str;
    int n = 0;
    for(int i=0; i<str.size(); ++i)
    {
        if(str[i++] == '-')
        {
            mas[n].coef *= -1;
        }
        int k = 0;
        bool has = false;
        while(isdigit(str[i]))
        {
            k*=10; k+=str[i++]-'0';
            has = true;
        }
        mas[n].coef *= (k && !has)?k:1;

        if(str[i] == '*')
            ++i;

        if(str[i]=='a')
        {
            mas[n].pre = false;
        }
        else
        {
            mas[n].pre = true;
        }
        i+=2;
        ++n;
    }

    sort(mas, mas+n);
    int sum = 0;
    for(int i=0; i<n; ++i)
    {
        if(mas[i].pre)
            ++a;

        sum+= a * mas[i].coef;

        if(!mas[i].pre)
            ++a;
    }

    cout << sum << endl;

    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <sstream>
#include <cmath>
#include <cassert>
#include <memory.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define sz(a) (int)(a).size()
#define _(a,b) memset((a), (b), sizeof(a))

void prepare()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif
}

struct G
{
	int c;
	string s;
	G(){}
	G(string g)
	{
		string t;
		c = 1;
		if (g[0] == '-' || g[0] == '+')
		{
			if (g[0] == '-')
				c = -1;
			g = g.substr(1);
		}
		for (int i = 0; i < sz(g); i++)
		{
			if (!isdigit(g[i]))
			{
				s = g.substr(i);
				break;
			}
			t.pb(g[i]);
		}
		if (s.find('*') != string::npos)
		s.erase(s.find('*'), 1);
		if (t != "")
		c *= atoi(t.c_str());
	}
	bool operator < (const G &g) const
	{
		return c < g.c;
	}
};

vector<G> v;

void go(string s)
{
	if (s == "")
		return;
	int k = min(s.find("a++"), s.find("++a"));
	v.pb(G(s.substr(0, k + 3)));
	go(s.substr(k + 3));
}

void solve()
{
	int n;
	scanf("%d\n", &n);
	string s;
	getline(cin, s);
	go(s);
	sort(v.begin(), v.end());
	long long r = 0;
	for (int i = 0; i < sz(v); i++)
	{
		if (v[i].s == "a++")
		{
			r += (long long)v[i].c * n;
			n++;
		}
		else
		{
			n++;
			r += (long long)v[i].c * n;
		}
	}
	cout << r<< endl;
}

int main()
{
	prepare();
	solve();
	return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <queue>
#include <sstream>
#include <numeric>
#include <functional>
#include <set>
#include <cmath>
#include <stack>
#include <fstream>
#ifdef HOME_PC
#include <ctime>
#endif
using namespace std;

#pragma comment(linker,"/stack:16000000")
#pragma warning (disable : 4996)

#define ALL(v) v.begin(),v.end()
#define SZ(v) (int)v.size()
#define mset(A,x) memset((A),(x),sizeof(A))
#define FOR(i,start,N) for(int i=(start);i<(N);++i)
#define FORSZ(i,start,v) FOR(i,start,SZ(v))
#define REPSZ(i,v) FORSZ(i,0,v)
#define FORE(i,start,N) FOR(i,start,N+1)
#define make_unique(v) v.resize(unique(ALL(v))-v.begin())
#define debug(x) cout<<#x<<" = "<<x<<endl;
#define adebug(A,N) FOR(i,0,N) cout<<#A<<"["<<i<<"] = "<<A[i]<<endl;
#define adebug2d(a,n,m) FOR(i,0,n) { FOR(j,0,m) { cout<<a[i][j]<<" ";} cout<<endl;}
#define vdebug(v) REPSZ(i,v) cout<<#v<<"["<<i<<"] = "<<v[i]<<endl;
#define selfx(x,f,a) x = f(x,a)
#define sqr(x) ((x)*(x))

typedef pair<int,int> pii;
typedef long long i64;
typedef vector<int> VI; typedef vector< vector<int> > VVI;
typedef vector<string> VS;

const int inf = 1<<25;
const double eps = 1e-9;

struct Summand
{
    int coef,inc;

    Summand() {}
    Summand(int c,int i):coef(c),inc(i){}

    int eval(int a)
    {
        return coef*(a+inc);
    }

    bool operator<(const Summand& X) const
    {
        if(coef < X.coef) return true;
        if(coef > X.coef) return false;
        return coef<0?inc < X.inc : inc > X.inc;
    }
};

struct Parser
{
    string s;
    int pos;
    Parser(const string& ss):s(ss),pos(0){}

    bool parsed() { return pos>=s.size();}
    Summand nextSummand()
    {
        int sign = 1;
        // sign
        if(s[pos++] == '-')
            sign = -1;

        int coef = 1;
        if(isdigit(s[pos]))
            coef = parseCoef();
        int inc = 0;
        if(s[pos] == '+')
            inc = 1;
        pos+=3;

        return Summand(sign*coef,inc);
    }
private:
    int parseCoef()
    {
        int coef = 0;
        while(isdigit(s[pos++]))
            coef = coef*10 + s[pos-1]-'0';
        return coef;
    }
};

int main(int argc, char* argv[])
{
#ifdef HOME_PC
    //freopen ("input.txt","r",stdin);
    //freopen ("in.txt","r",stdin);
    //freopen ("output.txt","w",stdout);
#endif
    int a; cin>>a;
    string s; cin>>s;
    s = string("+") + s;
    i64 ans = 0;
    Parser P(s);
    vector<Summand> summands;

    while(!P.parsed())
        summands.push_back(P.nextSummand());

    sort(ALL(summands));
    REPSZ(i,summands)
    {
        ans+=summands[i].eval(a);
        ++a;
    }

    cout<<ans<<endl;

#ifdef HOME_PC
    cerr<<endl<<"Execution time = "<<clock()<<" ms"<<endl;
#endif
    return 0;
}


#include<stdio.h>
#include<vector>
#include<algorithm>
#include<sstream>
#include<string>
#include<string.h>
using namespace std;
vector<int> K;

int toInt(string s)
{
    stringstream ss;
    ss<<s;
    int k;
    ss>>k;
    return k;
}
bool nextPlus=true;
char *s;
int getNextTerm(int &resum)
{
    if(*s==0)return -1;
    string st;
    int I=0;
    int coef=0;
    while(isdigit(*(s+I))){st.push_back(*(s+I));++I;};
    if (st.length()==0)coef=1;else coef=toInt(st);
    if(st.length()!=0)I++;
    if(!nextPlus)
    {
        coef*=-1;
    }
    char next[4];
    next[0]=*(s+I);
    next[1]=*(s+I+1);
    next[2]=*(s+I+2);
    next[3]='\0';
    I+=3;
    if(strcmp(next,"++a")==0)resum+=coef;
    if(*(s+I)=='-')nextPlus=false;else nextPlus=true;
    if(*(s+I)=='\0')
    {
        I-=1;
    }
    ++I;
    s=s+I;
    K.push_back(coef);
    return 1;
}
int main()
{
    s=new char[5000];
    int inita;
    scanf("%d",&inita);

    int resum=0;
    scanf("%s",s);
    while(getNextTerm(resum)!=-1){};
    sort(K.begin(),K.end());
    for(int i=0;i<K.size();i++)
    {
        resum+=K[i]*inita;
        ++inita;
    }
    printf("%d\n",resum);

}


#include<stdio.h>
#include<vector>
#include<algorithm>
#include<sstream>
#include<string>
#include<string.h>
using namespace std;
vector<int> K;

int toInt(string s)
{
    stringstream ss;
    ss<<s;
    int k;
    ss>>k;
    return k;
}
bool nextPlus=true;
char *s;
int getNextTerm(int &resum)
{
    if(*s==0)return -1;
    string st;
    int I=0;
    int coef=0;
    while(isdigit(*(s+I))){st.push_back(*(s+I));++I;};
    if (st.length()==0)coef=1;else coef=toInt(st);
    if(st.length()!=0)I++;
    if(!nextPlus)
    {
        coef*=-1;
    }
    char next[4];
    next[0]=*(s+I);
    next[1]=*(s+I+1);
    next[2]=*(s+I+2);
    next[3]='\0';
    I+=3;
    if(strcmp(next,"++a")==0)resum+=coef;
    if(*(s+I)=='-')nextPlus=false;else nextPlus=true;
    if(*(s+I)=='\0')
    {
        I-=1;
    }
    ++I;
    s=s+I;
    K.push_back(coef);
    return 1;
}
int main()
{
    s=new char[100000];
    int inita;
    scanf("%d",&inita);

    int resum=0;
    scanf("%s",s);
    while(getNextTerm(resum)!=-1){};
    sort(K.begin(),K.end());
    for(int i=0;i<K.size();i++)
    {
        resum+=K[i]*inita;
        ++inita;
    }
    printf("%d\n",resum);

}


#if 1
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <sstream>
#include <stack>
#include <cstdlib>
#include <cassert>
#include <cstring>
#include <functional>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <cstdio>
#include <list>
using namespace std;

typedef long long LL;
typedef long double LD;
const LD eps = 1e-9;

typedef pair<int, int> pii;
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define iss istringstream
#define oss ostringstream
#define dbg(x) cerr << #x << " = " << x << endl;

int s2i(string s)
{
	istringstream is(s);
	int a; is >> a;
	return a;
}

LL calc(vector<int> toks, vector<int> order)
{
	LL cur = 0;
	for(int i = 0; i < toks.size(); ++i)
		if(toks[i] >= -1000 && toks[i] <= 1000)
		{
			int cnt = order[i];
			if(toks[i + 1] == -4444)
				cur += toks[i] * (cnt + 1);
			else
				cur += toks[i] * cnt;
		}
	return cur;
}

int main()
{
	int a; cin >> a;
	string s; cin >> s;
	vector<int> toks;
	for(int i = 0; i < s.length(); ++i)
		if(s[i] >= '0' && s[i] <= '9')
		{
			string t = "";
			while(i < s.length() && s[i] >= '0' && s[i] <= '9')
				t += s[i],
				++i;
			toks.pb(s2i(t));
		} else if(s[i] == '-')
		{
			toks.pb(-2222);

		} else if(s[i] == 'a')
		{
			if(toks.size() == 0 || toks.back() < 0)
			{
				toks.pb(1);
			}
				toks.pb(-3333);

			i += 2;
		} else if(s[i] == '+')
		{
			if(s[i+1] == '+' && s[i + 2] == 'a')
			{
					if(toks.size() == 0 || toks.back() < 0)
			{
				toks.pb(1);
			}
				toks.pb(-4444),
				i += 2;
			}
			else
				toks.pb(-1111);
		}

	vector<int> nt;
	for(int i = 0; i < toks.size(); ++i)
		if(toks[i] == -2222)
			toks[i] = -1111,
			toks[i + 1] = -toks[i + 1];
	vector<int> order(toks.size());
	vector<pii> e;
	for(int i = 0; i < toks.size(); ++i)
		if(toks[i] >= -1000 && toks[i] <= 1000)
			e.pb(mp(toks[i], i));
	sort(e.begin(), e.end());
	for(int i = 0; i < e.size(); ++i)
		order[e[i].Y] = i + a;

	LL res = calc(toks, order);
	cout << res << endl;

	return 0;
}
#endif


#if 1
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <sstream>
#include <stack>
#include <cstdlib>
#include <cassert>
#include <cstring>
#include <functional>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <cstdio>
#include <list>
using namespace std;

typedef long long LL;
typedef long double LD;
const LD eps = 1e-9;

typedef pair<int, int> pii;
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define iss istringstream
#define oss ostringstream
#define dbg(x) cerr << #x << " = " << x << endl;

vector< vector<int> > g;
vector<int> top;
int xabs(int a) { return a < 0 ? -a : +a; }
vector<bool> passed;
void dfs(int u)
{
	passed[u] = true;
	for(int i = 0; i < g[u].size(); ++i)
		if(!passed[g[u][i]])
			dfs(g[u][i]);
	top.pb(u);
}
vector<int> f, p;
int fn;
void finit(int n)
{
	fn = n;
	f.assign(n, -100);
	p.assign(n, 0);
}

void fmodify(int r, int v)
{
	for(int i = r; i < fn; i |= i + 1)
		if(v > f[i])
			f[i] = v,
			p[i] = r;
}
int fget(int r)
{
	int pos = p[r];
	int ee = f[r];
	for(int i = r; i >= 0; i &= i + 1, --i)
		if(f[i] > ee)
			ee = f[i],
			pos = p[i];
	return pos;
}

int main()
{
	int n;
	cin >> n;
	vector<int> c(n + 1);
	vector<int> r(n + 1);
	c[0] = 0;
	r[0] = 2000000001;
	for(int i = 1; i <= n; ++i)
		cin >> c[i] >> r[i];

	n++;
	g.resize(n);
	for(int i = 0; i < n; ++i)
		for(int j = 0; j < n; ++j) if(i != j)
			if(c[i] + r[i] >= c[j] + r[j] && c[i] - r[i] <= c[j] - r[j])
				g[i].pb(j);

	passed.assign(n, false);
	dfs(0);

	vector<int> dp(n);
	vector< vector<int> > add(n);
	for(int i = 0; i < n; ++i)
	{
		int u = top[i];
		vector< pii > s;
		for(int j = 0; j < g[u].size(); ++j)
			s.pb(mp(c[g[u][j]] + r[g[u][j]], g[u][j]));
		sort(s.begin(), s.end());
		vector<int> z(s.size(), -1), prev(s.size(), -1);
		finit(s.size());
		for(int i = 0; i < s.size(); ++i)
		{
			z[i] = dp[s[i].Y];

			int st = upper_bound(s.begin(), s.begin() + i, mp(s[i].X - 2 * r[s[i].Y], 1000000)) - s.begin();
			st--;

			if(st >= 0)
			{
				st = fget(st);
				z[i] = z[st] + dp[s[i].Y];
				prev[i] = st;
			}
			fmodify(i, z[i]);
		}
		int pos = max_element(z.begin(), z.end()) - z.begin();
		if(pos == z.size()) pos = -1;
		if(pos != -1)
			dp[u] = z[pos] + 1;
		else
			dp[u] = 1;

		vector<int> rr;
		while(pos >= 0)
		{
			rr.pb(s[pos].Y);
			pos = prev[pos];
		}
		add[u] = rr;

	}
	//cout << dp[0] << endl;
	vector<int> res;

	queue<int> q;
	q.push(0);
	while(q.size())
	{
		int u = q.front(); q.pop();
		for(int i = 0; i < add[u].size(); ++i)
			res.pb(add[u][i]),
			q.push(add[u][i]);
	}

	cout << res.size() << endl;
	for(int i = 0; i < res.size(); ++i)
	{
		if(i) cout << " ";
		cout << res[i];
	}
	cout << endl;
	return 0;
}
#endif


#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cmath>
#include <cctype>

#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <list>
#include <iterator>
#include <functional>

using namespace std;

template<typename T> struct Point
{
	T x, y; Point(){} Point(T xx, T yy): x(xx), y(yy){}
};
template<typename T> bool operator <(const Point<T> &p1, const Point<T> &p2)
{
	return p1.x < p2.x || p1.x == p2.x && p1.y < p2.y;
}
template<typename T> Point<T> operator -(const Point<T> &p1, const Point<T> &p2)
{
	return Point<T>(p1.x - p2.x, p1.y - p2.y);
}
template<typename T> T operator ^(const Point<T> &p1, const Point<T> &p2)
{
	return p1.x*p2.y - p2.x*p1.y;
}

#define mp make_pair
#define pb push_back
#define forn(i, n) for(int (i)=0; (i)<n; i++)
#define all(x) x.begin(), x.end()
#define zero(a) memset(a, 0, sizeof(a))

typedef long long int64;
typedef vector<int> vint;
typedef Point<int> pint;

struct Smd
{
	bool pre;
	int coef;
};
bool operator <(const Smd &e1, const Smd &e2)
{
	return e1.coef < e2.coef || e1.coef == e2.coef && e1.pre < e2.pre;
}

vector<Smd> v;

string s, b;
int main()
{
	int a;
	cin >> a;
	cin >> s;
	s = "+" + s;
	forn(i, s.size())
	{
		Smd e;
		bool sign;
		sign = (s[i++] == '+');
		e.coef = 1;
		if (isdigit(s[i]))
		{
			b = "";
			for(; isdigit(s[i]); i++)
			{
				b.push_back(s[i]);
			}
			e.coef = atol(b.c_str());
			i++;
		}
		if (s[i] == '+')
		{
			e.pre = 1;
			i+=2;
		}
		else if (s[i] == 'a')
		{
			e.pre = 0;
			i+=2;
		}

		if (!sign)
			e.coef*=-1;
		v.push_back(e);
	}
	sort(all(v));

	int64 res = 0;
	forn(i, v.size())
	{
		if (v[i].pre)
			a++;

		res += v[i].coef*a;

		if (!v[i].pre)
			a++;
	}
	cout << res;

	return 0;
}
/*

abbababaabbbabab
abbababaabbbaaa

*/


#define _CRT_SECURE_NO_DEPRECATE

#include <string>
#include <vector>
#include <map>
#include <list>
#include <set>
#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>

using namespace std;

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define RFOR(i, b, a) for(int i = b - 1; i >= a; --i)
#define REP(i, N) FOR(i, 0, N)
#define RREP(i, N) RFOR(i, N, 0)

#define MIN(A, B) ((A) < (B) ? (A) : (B))
#define MAX(A, B) ((A) > (B) ? (A) : (B))
#define ABS(A) ((A) < 0 ? (-(A)) : (A))
#define ALL(V) V.begin(), V.end()
#define SIZE(V) (int)V.size()
#define pb push_back
#define mp make_pair
#define EPS 1e-7
#define Pi 3.14159265358979

typedef long long Long;
typedef unsigned long long ULong;
typedef unsigned int Uint;
typedef unsigned char Uchar;
typedef vector <int> VI;
typedef pair <int, int> PI;

int a;

char s[1 << 20];

VI v[2];

void parse_1(int &cur, int sign);
void parse_2(int &cur, int sign, int x);

void parse_0(int &cur)
{
	parse_1(cur, 1);
	while (s[cur] == '+' || s[cur] == '-')
	{
		int sign = s[cur] == '+' ? 1 : -1;
		++cur;
		parse_1(cur, sign);
	}
}

void parse_1(int &cur, int sign)
{
	int x = 1;
	if(isdigit(s[cur]))
	{
		x = 0;
		while(isdigit(s[cur]))
			x = x * 10 + s[cur++] - '0';
		if(s[cur] != '*')
			throw -1;
		++cur;
	}
	parse_2(cur, sign, x);
}

void parse_2(int &cur, int sign, int x)
{
	if(s[cur] == 'a')
	{
		if(s[cur + 1] != '+' || s[cur + 2] != '+')
			throw -1;
		v[0].pb(sign * x);
		cur += 3;
		return;
	}
	if(s[cur] == '+')
	{
		if(s[cur + 1] != '+' || s[cur + 2] != 'a')
			throw -1;
		v[1].pb(sign * x);
		cur += 3;
		return;
	}
}

int ans[1 << 10][1 << 10];

int main()
{
	scanf("%d\n", &a);
	gets(s);
	int cur = 0;
	parse_0(cur);
	sort(ALL(v[0]));
	sort(ALL(v[1]));
	int n = (int)v[0].size();
	int m = (int)v[1].size();
	REP(i, n + 1)
		REP(j, m + 1)
		{
			if(i == 0 && j == 0)
				continue;
			else if(i == 0)
				ans[i][j] = ans[i][j - 1] + (a + i + j) * v[1][j - 1];
			else if(j == 0)
				ans[i][j] = ans[i - 1][j] + (a + i + j - 1) * v[0][i - 1];
			else
				ans[i][j] = max(ans[i][j - 1] + (a + i + j) * v[1][j - 1], ans[i - 1][j] + (a + i + j - 1) * v[0][i - 1]);
		}
	printf("%d\n", ans[n][m]);
	return 0;
}


#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;

#define ll __int64
#define ls rt<<1
#define rs ls|1
#define lson l,mid,ls
#define rson mid+1,r,rs
#define middle (l+r)>>1
#define clr_all(x,c) memset(x,c,sizeof(x))
#define clr(x,c,n) memset(x,c,sizeof(x[0])*(n+1))
#define eps (1e-8)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define PI (acos(-1.0))
#pragma comment(linker, "/STACK:102400000,102400000")
template <class T> T _max(T x,T y){return x>y? x:y;}
template <class T> T _min(T x,T y){return x<y? x:y;}
template <class T> T _abs(T x){return (x < 0)? -x:x;}
template <class T> T _mod(T x,T y){return (x > 0)? x%y:((x%y)+y)%y;}
template <class T> void _swap(T &x,T &y){T t=x;x=y;y=t;}
template <class T> void getmax(T& x,T y){x=(y > x)? y:x;}
template <class T> void getmin(T& x,T y){x=(x<0 || y<x)? y:x;}
int TS,cas=1;
const int M=1000+5;
int a;
struct node{
    int num;
    bool flag;
    bool operator < (const node & t)const{
        return num < t.num;
    }
    void setNum(int n,bool f,char c){
        if(f) num=-n;
        else num=n;
        if(c=='a') flag=0;
        else flag=1;
    }
}p[M];
char str[M<<4];

void run(){
    int i,j;
    scanf("%s",str);
    int tot=0;
    bool flag=false;
    for(i=0;str[i];i++){
        if(isdigit(str[i])){
            int num=0;
            for(;str[i] && isdigit(str[i]);i++){
                num=num*10+(str[i]-'0');
            }

            if(str[i]!='*') while(1);//break point

            p[tot].setNum(num,flag,str[i+1]);
            flag=false,tot++;
            i+=3;
        }else if(str[i]=='a'){
            p[tot].setNum(1,flag,str[i]);
            flag=false,tot++;
            i+=2;
        }else if(str[i]=='+' && str[i+2]=='a'){
            p[tot].setNum(1,flag,str[i]);
            flag=false,tot++;
            i+=2;
        }else if(str[i]=='-') flag=true;
    }
    sort(p,p+tot);
    int ret=0;
    for(i=0;i<tot;i++){
        if(p[i].flag) ret+=p[i].num*(++a);
        else ret+=p[i].num*(a++);
        //printf("..%d %d\n",p[i].num,p[i].flag? 1:0);
    }
    printf("%d\n",ret);
}

void preSof(){
}

int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    preSof();
    //run();
    while((~scanf("%d",&a))) run();
    //for(scanf("%d",&TS);cas<=TS;cas++) run();
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

char s[100500];

int main()
{
	vector<pair<int, int> > vec;
	int a;
	scanf("%d%s", &a, s);
	int n = strlen(s);
	int sgn = 1;
	for(int i = 0; i < n; i++)
	{
		int v = 1, bit;
		if(isdigit(s[i]))
		{
			sscanf(s + i, "%d", &v);
			while(isdigit(s[i]) )
			{
				i++;
			}
			i++;
		}
		if(s[i] == '+')
		{
			bit = 'L';
		}
		else
		{
			bit = 'R';
		}
		i += 3;
		vec.push_back(make_pair(v * sgn, bit) );
		if(s[i] == '-')
		{
			sgn = -1;
		}
		else
		{
			sgn = 1;
		}
	}
	sort(vec.begin(), vec.end());
	int res = 0;
	for(int i = 0; i < vec.size(); i++)
	{
		if(vec[i].second == 'L')
		{
			a++;
			res += vec[i].first * a;
		}
		else
		{
			res += vec[i].first * a;
			a++;
		}
	}
	printf("%d\n", res);
	return 0;
}


#include <queue>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;
typedef long long LL;
typedef vector<int> vi;
#define FOR(i, n) for(int i = 0; i < (int)(n); ++i)

const int inf = 1 << 29;

struct MinCost
{
	int n, s, t;
	struct edge
	{
		int a, b, cost, cap, next;
	};
	vector<edge> e;
	vi g, d, p, f, flag;
	void SetN(int nn)
	{
		n = nn;
		s = n - 1;
		t = n - 2;
		g.assign(n, 0);
		d.assign(n, 0);
		p.assign(n, 0);
		f.assign(n, 0);
		flag.assign(n, 0);
		e.resize(2);
	}
	void AddE(int a, int b, int cap, int cost)
	{
		edge ee;

		ee.a = a;
		ee.b = b;
		ee.cap = cap;
		ee.cost = cost;
		ee.next = g[a];
		g[a] = e.size();
		e.push_back(ee);

		ee.a = b;
		ee.b = a;
		ee.cap = 0;
		ee.cost = -cost;
		ee.next = g[b];
		g[b] = e.size();
		e.push_back(ee);
	}
	bool Dij(vi& f, vi&d)
	{
		flag.assign(n, 0);
		d.assign(n, inf);
		d[s] = 0;
		set<pair<int, int> > q;
		q.insert(make_pair(0, s));
		int cnt = 0;
		while (q.size())
		{
			cnt++;
			if (cnt > 10000)
				++*(int*)0;
			//int Min = inf;
			//int x = -1;
			//FOR(i, n)
			//	if (!flag[i] && Min > d[i])
			//	{
			//		Min = d[i];
			//		x = i;
			//	}
			//if (Min == inf) break;
			int Min = q.begin()->first;
			int x = q.begin()->second;
			q.erase(q.begin());
			//flag[x] = 1;
			for (int r = g[x]; r; r = e[r].next)
				if (e[r].cap > 0)
					if (d[e[r].b] > Min + f[e[r].a] - f[e[r].b] + e[r].cost)
					{
						q.erase(make_pair(d[e[r].b], e[r].b));
						d[e[r].b] = Min + f[e[r].a] - f[e[r].b] + e[r].cost;
						q.insert(make_pair(d[e[r].b], e[r].b));
						p[e[r].b] = r;
//						flag[e[r].b] = 0;
					}
		}
		FOR(i, n)
			f[i] = min(inf, f[i] + d[i]);
		return d[t] != inf;
	}
	void Aug()
	{
		int x = t;
		while (x != s)
		{
			int r = p[x];
			e[r].cap--;
			e[r ^ 1].cap++;
			x = e[r].a;
		}
	}
	int Calc()
	{
		Dij(d, f);
		while (Dij(f, d))
			Aug();
		int res = 0;
		for (int r = 3; r < e.size(); r += 2)
			res -= e[r].cap * e[r].cost;
		return res;
	}
};

MinCost mc;
char s[1 << 20];

int main()
{
	int a;
	scanf("%d", &a);
	scanf("%s", s);
	int zn = 1;
	vi v;
	vi vt;
	int p = 0;
	int len = strlen(s);
	while (p < len)
	{
		int x = 1;
		if (s[p] >= '0' && s[p] <= '9')
		{
			x = 0;
			while (s[p] >= '0' && s[p] <= '9')
			{
				x = x * 10 + s[p] - '0';
				p++;
			}
			p++;
		}
		x = x * zn;
		v.push_back(x);
		vt.push_back(s[p] != 'a');
		p += 3;
		if (p < len)
		{
			if (s[p] == '+')
				zn = 1;
			else
				zn = -1;
			p++;
		}
	}
	mc.SetN(v.size() * 2 + 2);
	mc.e.reserve(v.size() * v.size() * 4);

	FOR(i, v.size())
	{
		mc.AddE(mc.s, i, 1, 1);
		mc.AddE(v.size() + i, mc.t, 1, 1);
	}
	FOR(i, v.size())
		FOR(j, v.size())
			mc.AddE(i, v.size() + j, 1, -v[i] * (a + j + vt[i]) + 2000000);

	int res = -mc.Calc() + v.size() * 2 - 2000000 * v.size();

	printf("%d\n", res);

	return 0;
}


#include <queue>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;
typedef long long LL;
typedef vector<int> vi;
#define FOR(i, n) for(int i = 0; i < (int)(n); ++i)

void ASS(int b)
{
	if (!b)
		++*(int*)0;
}

vi v0, v1;
int a;
const LL inf = 1LL << 60;

char f[1024][1024];
LL dp[1024][1024];

LL D(int p0, int p1)
{
	if (p0 == v0.size() && p1 == v1.size()) return 0;
	if (f[p0][p1])
		return dp[p0][p1];
	f[p0][p1] = 1;
	LL res = -inf;
	if (p0 < v0.size())
		res = max(res, D(p0 + 1, p1) + v0[p0] * (a + p0 + p1));
	if (p1 < v1.size())
		res = max(res, D(p0, p1 + 1) + v1[p1] * (a + p0 + p1 + 1));
	dp[p0][p1] = res;
	return res;
}

char s[1 << 20];

int main()
{
	scanf("%d", &a);
	scanf("%s", s);
	int zn = 1;
	int p = 0;
	int len = strlen(s);
	while (p < len)
	{
		int x = 1;
		if (s[p] >= '0' && s[p] <= '9')
		{
			x = 0;
			while (s[p] >= '0' && s[p] <= '9')
			{
				x = x * 10 + s[p] - '0';
				p++;
			}
			p++;
		}
		x = x * zn;
//		v.push_back(x);
//		vt.push_back(s[p] != 'a');
		if (s[p] == 'a')
			v0.push_back(x);
		else
			v1.push_back(x);
		p += 3;
		if (p < len)
		{
			if (s[p] == '+')
				zn = 1;
			else
				zn = -1;
			p++;
		}
	}

	sort(v0.begin(), v0.end());
	sort(v1.begin(), v1.end());

	ASS(v0.size() < 1000);
	ASS(v1.size() < 1000);

	LL res = D(0, 0);

	printf("%I64d\n", res);

	return 0;
}


#include <queue>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;
typedef long long LL;
typedef vector<int> vi;
#define FOR(i, n) for(int i = 0; i < (int)(n); ++i)

const int inf = 1 << 29;

struct MinCost
{
	int n, s, t;
	struct edge
	{
		int a, b, cost, cap, next;
	};
	vector<edge> e;
	vi g, d, p, f, flag;
	void SetN(int nn)
	{
		n = nn;
		s = n - 1;
		t = n - 2;
		g.assign(n, 0);
		d.assign(n, 0);
		p.assign(n, 0);
		f.assign(n, 0);
		flag.assign(n, 0);
		e.resize(2);
	}
	void AddE(int a, int b, int cap, int cost)
	{
		edge ee;

		ee.a = a;
		ee.b = b;
		ee.cap = cap;
		ee.cost = cost;
		ee.next = g[a];
		g[a] = e.size();
		e.push_back(ee);

		ee.a = b;
		ee.b = a;
		ee.cap = 0;
		ee.cost = -cost;
		ee.next = g[b];
		g[b] = e.size();
		e.push_back(ee);
	}
	bool Dij(vi& f, vi&d)
	{
		flag.assign(n, 0);
		d.assign(n, inf);
		d[s] = 0;
		//set<pair<int, int> > q;
		//q.insert(make_pair(0, s));
		int cnt = 0;
		while (1)
		{
			cnt++;
			if (cnt > 5000)
				++*(int*)0;
			int Min = inf;
			int x = -1;
			FOR(i, n)
				if (!flag[i] && Min > d[i])
				{
					Min = d[i];
					x = i;
				}
			if (Min == inf) break;
			//int Min = q.begin()->first;
			//int x = q.begin()->second;
			//q.erase(q.begin());
			flag[x] = 1;
			for (int r = g[x]; r; r = e[r].next)
				if (e[r].cap > 0)
					if (d[e[r].b] > Min + f[e[r].a] - f[e[r].b] + e[r].cost)
					{
//						q.erase(make_pair(d[e[r].b], e[r].b));
						d[e[r].b] = Min + f[e[r].a] - f[e[r].b] + e[r].cost;
//						q.insert(make_pair(d[e[r].b], e[r].b));
						p[e[r].b] = r;
						//flag[e[r].b] = 0;
					}
		}
		FOR(i, n)
			f[i] = min(inf, f[i] + d[i]);
		return d[t] != inf;
	}
	void Aug()
	{
		int x = t;
		while (x != s)
		{
			int r = p[x];
			e[r].cap--;
			e[r ^ 1].cap++;
			x = e[r].a;
		}
	}
	int Calc()
	{
		Dij(d, f);
		while (Dij(f, d))
			Aug();
		int res = 0;
		for (int r = 3; r < e.size(); r += 2)
			res -= e[r].cap * e[r].cost;
		return res;
	}
};

MinCost mc;
char s[1 << 20];

int main()
{
	int a;
	scanf("%d", &a);
	scanf("%s", s);
	int zn = 1;
	vi v;
	vi vt;
	int p = 0;
	int len = strlen(s);
	while (p < len)
	{
		int x = 1;
		if (s[p] >= '0' && s[p] <= '9')
		{
			x = 0;
			while (s[p] >= '0' && s[p] <= '9')
			{
				x = x * 10 + s[p] - '0';
				p++;
			}
			p++;
		}
		x = x * zn;
		v.push_back(x);
		vt.push_back(s[p] != 'a');
		p += 3;
		if (p < len)
		{
			if (s[p] == '+')
				zn = 1;
			else
				zn = -1;
			p++;
		}
	}
	mc.SetN(v.size() * 2 + 2);
	mc.e.reserve(v.size() * v.size() * 4);

	FOR(i, v.size())
	{
		mc.AddE(mc.s, i, 1, 1);
		mc.AddE(v.size() + i, mc.t, 1, 1);
	}
	FOR(i, v.size())
		FOR(j, v.size())
			mc.AddE(i, v.size() + j, 1, -v[i] * (a + j + vt[i]) + 2000000);

	int res = -mc.Calc() + v.size() * 2 + 2000000 * v.size();

	printf("%d\n", res);

	return 0;
}


#include <queue>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;
typedef long long LL;
typedef vector<int> vi;
#define FOR(i, n) for(int i = 0; i < (int)(n); ++i)

vi v0, v1;
int a;
const int inf = 1 << 29;

char f[1024][1024];
int dp[1024][1024];

int D(int p0, int p1)
{
	if (p0 == v0.size() && p1 == v1.size()) return 0;
	if (f[p0][p1])
		return dp[p0][p1];
	f[p0][p1] = 1;
	int res = -inf;
	if (p0 < v0.size())
		res = max(res, D(p0 + 1, p1) + v0[p0] * (a + p0 + p1));
	if (p1 < v1.size())
		res = max(res, D(p0, p1 + 1) + v1[p1] * (a + p0 + p1 + 1));
	dp[p0][p1] = res;
	return res;
}

char s[1 << 20];

int main()
{
	scanf("%d", &a);
	scanf("%s", s);
	int zn = 1;
	int p = 0;
	int len = strlen(s);
	while (p < len)
	{
		int x = 1;
		if (s[p] >= '0' && s[p] <= '9')
		{
			x = 0;
			while (s[p] >= '0' && s[p] <= '9')
			{
				x = x * 10 + s[p] - '0';
				p++;
			}
			p++;
		}
		x = x * zn;
//		v.push_back(x);
//		vt.push_back(s[p] != 'a');
		if (s[p] == 'a')
			v0.push_back(x);
		else
			v1.push_back(x);
		p += 3;
		if (p < len)
		{
			if (s[p] == '+')
				zn = 1;
			else
				zn = -1;
			p++;
		}
	}

	sort(v0.begin(), v0.end());
	sort(v1.begin(), v1.end());

	int res = D(0, 0);

	printf("%d\n", res);

	return 0;
}


#include <queue>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;
typedef long long LL;
typedef vector<int> vi;
#define FOR(i, n) for(int i = 0; i < (int)(n); ++i)

const int inf = 1 << 29;

struct MinCost
{
	int n, s, t;
	struct edge
	{
		int a, b, cost, cap, next;
	};
	vector<edge> e;
	vi g, d, p, f, flag;
	void SetN(int nn)
	{
		n = nn;
		s = n - 1;
		t = n - 2;
		g.assign(n, 0);
		p.assign(n, 0);
		f.assign(n, 0);
		flag.assign(n, 0);
		e.resize(2);
	}
	void AddE(int a, int b, int cap, int cost)
	{
		edge ee;

		ee.a = a;
		ee.b = b;
		ee.cap = cap;
		ee.cost = cost;
		ee.next = g[a];
		g[a] = e.size();
		e.push_back(ee);

		ee.a = b;
		ee.b = a;
		ee.cap = 0;
		ee.cost = -cost;
		ee.next = g[b];
		g[b] = e.size();
		e.push_back(ee);
	}
	bool Dij()
	{
		flag.assign(n, 0);
		d.assign(n, inf);
		d[s] = 0;
		set<pair<int, int> > q;
		q.insert(make_pair(0, s));
		while (q.size())
		{
			//int Min = inf;
			//int x = -1;
			//FOR(i, n)
			//	if (!flag[i] && Min > d[i])
			//	{
			//		Min = d[i];
			//		x = i;
			//	}
			//if (Min == inf) break;
			int Min = q.begin()->first;
			int x = q.begin()->second;
			q.erase(q.begin());
			flag[x] = 1;
			for (int r = g[x]; r; r = e[r].next)
				if (e[r].cap > 0)
					if (d[e[r].b] > Min + f[e[r].a] - f[e[r].b] + e[r].cost)
					{
						q.erase(make_pair(d[e[r].b], e[r].b));
						d[e[r].b] = Min + f[e[r].a] - f[e[r].b] + e[r].cost;
						q.insert(make_pair(d[e[r].b], e[r].b));
						p[e[r].b] = r;
//						flag[e[r].b] = 0;
					}
		}
		FOR(i, n)
			f[i] = min(inf, f[i] + d[i]);
		return d[t] != inf;
	}
	void Aug()
	{
		int x = t;
		while (x != s)
		{
			int r = p[x];
			e[r].cap--;
			e[r ^ 1].cap++;
			x = e[r].a;
		}
	}
	int Calc()
	{
		while (Dij())
			Aug();
		int res = 0;
		for (int r = 3; r < e.size(); r += 2)
			res -= e[r].cap * e[r].cost;
		return res;
	}
};

MinCost mc;
char s[1 << 20];

int main()
{
	int a;
	scanf("%d", &a);
	scanf("%s", s);
	int zn = 1;
	vi v;
	vi vt;
	int p = 0;
	int len = strlen(s);
	while (p < len)
	{
		int x = 1;
		if (s[p] >= '0' && s[p] <= '9')
		{
			x = 0;
			while (s[p] >= '0' && s[p] <= '9')
			{
				x = x * 10 + s[p] - '0';
				p++;
			}
			p++;
		}
		x = x * zn;
		v.push_back(x);
		vt.push_back(s[p] != 'a');
		p += 3;
		if (p < len)
		{
			if (s[p] == '+')
				zn = 1;
			else
				zn = -1;
			p++;
		}
	}
	mc.SetN(v.size() * 2 + 2);
	mc.e.reserve(v.size() * v.size() * 4);

	FOR(i, v.size())
	{
		mc.AddE(mc.s, i, 1, 0);
		mc.AddE(v.size() + i, mc.t, 1, 0);
	}
	FOR(i, v.size())
		FOR(j, v.size())
			mc.AddE(i, v.size() + j, 1, -v[i] * (a + j + vt[i]));

	int res = -mc.Calc();

	printf("%d\n", res);

	return 0;
}


#include <queue>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;
typedef long long LL;
typedef vector<int> vi;
#define FOR(i, n) for(int i = 0; i < (int)(n); ++i)

const int inf = 1 << 29;

struct MinCost
{
	int n, s, t;
	struct edge
	{
		int a, b, cost, cap, next;
	};
	vector<edge> e;
	vi g, d, p, f, flag;
	void SetN(int nn)
	{
		n = nn;
		s = n - 1;
		t = n - 2;
		g.assign(n, 0);
		d.assign(n, 0);
		p.assign(n, 0);
		f.assign(n, 0);
		flag.assign(n, 0);
		e.resize(2);
	}
	void AddE(int a, int b, int cap, int cost)
	{
		edge ee;

		ee.a = a;
		ee.b = b;
		ee.cap = cap;
		ee.cost = cost;
		ee.next = g[a];
		g[a] = e.size();
		e.push_back(ee);

		ee.a = b;
		ee.b = a;
		ee.cap = 0;
		ee.cost = -cost;
		ee.next = g[b];
		g[b] = e.size();
		e.push_back(ee);
	}
	bool Dij(vi& f, vi&d)
	{
		flag.assign(n, 0);
		d.assign(n, inf);
		d[s] = 0;
		set<pair<int, int> > q;
		q.insert(make_pair(0, s));
		int cnt = 0;
		while (q.size())
		{
			cnt++;
			if (cnt > 10000)
				++*(int*)0;
			//int Min = inf;
			//int x = -1;
			//FOR(i, n)
			//	if (!flag[i] && Min > d[i])
			//	{
			//		Min = d[i];
			//		x = i;
			//	}
			//if (Min == inf) break;
			int Min = q.begin()->first;
			int x = q.begin()->second;
			q.erase(q.begin());
			//flag[x] = 1;
			for (int r = g[x]; r; r = e[r].next)
				if (e[r].cap > 0)
					if (d[e[r].b] > Min + f[e[r].a] - f[e[r].b] + e[r].cost)
					{
						q.erase(make_pair(d[e[r].b], e[r].b));
						d[e[r].b] = Min + f[e[r].a] - f[e[r].b] + e[r].cost;
						q.insert(make_pair(d[e[r].b], e[r].b));
						p[e[r].b] = r;
//						flag[e[r].b] = 0;
					}
		}
		FOR(i, n)
			f[i] = min(inf, f[i] + d[i]);
		return d[t] != inf;
	}
	void Aug()
	{
		int x = t;
		while (x != s)
		{
			int r = p[x];
			e[r].cap--;
			e[r ^ 1].cap++;
			x = e[r].a;
		}
	}
	int Calc()
	{
		Dij(d, f);
		while (Dij(f, d))
			Aug();
		int res = 0;
		for (int r = 3; r < e.size(); r += 2)
			res -= e[r].cap * e[r].cost;
		return res;
	}
};

MinCost mc;
char s[1 << 20];

int main()
{
	int a;
	scanf("%d", &a);
	scanf("%s", s);
	int zn = 1;
	vi v;
	vi vt;
	int p = 0;
	int len = strlen(s);
	while (p < len)
	{
		int x = 1;
		if (s[p] >= '0' && s[p] <= '9')
		{
			x = 0;
			while (s[p] >= '0' && s[p] <= '9')
			{
				x = x * 10 + s[p] - '0';
				p++;
			}
			p++;
		}
		x = x * zn;
		v.push_back(x);
		vt.push_back(s[p] != 'a');
		p += 3;
		if (p < len)
		{
			if (s[p] == '+')
				zn = 1;
			else
				zn = -1;
			p++;
		}
	}
	mc.SetN(v.size() * 2 + 2);
	mc.e.reserve(v.size() * v.size() * 4);

	FOR(i, v.size())
	{
		mc.AddE(mc.s, i, 1, 1);
		mc.AddE(v.size() + i, mc.t, 1, 1);
	}
	FOR(i, v.size())
		FOR(j, v.size())
			mc.AddE(i, v.size() + j, 1, -v[i] * (a + j + vt[i]) + 2000000);

	int res = -mc.Calc() + v.size() * 2 + 2000000 * v.size();

	printf("%d\n", res);

	return 0;
}


#include <queue>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;
typedef long long LL;
typedef vector<int> vi;
#define FOR(i, n) for(int i = 0; i < (int)(n); ++i)

const int inf = 1 << 29;

struct MinCost
{
	int n, s, t;
	struct edge
	{
		int a, b, cost, cap, next;
	};
	vector<edge> e;
	vi g, d, p, f, flag;
	void SetN(int nn)
	{
		n = nn;
		s = n - 1;
		t = n - 2;
		g.assign(n, 0);
		d.assign(n, 0);
		p.assign(n, 0);
		f.assign(n, 0);
		flag.assign(n, 0);
		e.resize(2);
	}
	void AddE(int a, int b, int cap, int cost)
	{
		edge ee;

		ee.a = a;
		ee.b = b;
		ee.cap = cap;
		ee.cost = cost;
		ee.next = g[a];
		g[a] = e.size();
		e.push_back(ee);

		ee.a = b;
		ee.b = a;
		ee.cap = 0;
		ee.cost = -cost;
		ee.next = g[b];
		g[b] = e.size();
		e.push_back(ee);
	}
	bool Dij(vi& f, vi&d)
	{
		flag.assign(n, 0);
		d.assign(n, inf);
		d[s] = 0;
		//set<pair<int, int> > q;
		//q.insert(make_pair(0, s));
		int cnt = 0;
		while (1)
		{
			cnt++;
			if (cnt > 5000)
				++*(int*)0;
			int Min = inf;
			int x = -1;
			FOR(i, n)
				if (!flag[i] && Min > d[i])
				{
					Min = d[i];
					x = i;
				}
			if (Min == inf) break;
			//int Min = q.begin()->first;
			//int x = q.begin()->second;
			//q.erase(q.begin());
			flag[x] = 1;
			for (int r = g[x]; r; r = e[r].next)
				if (e[r].cap > 0)
					if (d[e[r].b] > Min + f[e[r].a] - f[e[r].b] + e[r].cost)
					{
//						q.erase(make_pair(d[e[r].b], e[r].b));
						d[e[r].b] = Min + f[e[r].a] - f[e[r].b] + e[r].cost;
//						q.insert(make_pair(d[e[r].b], e[r].b));
						p[e[r].b] = r;
						flag[e[r].b] = 0;
					}
		}
		FOR(i, n)
			f[i] = min(inf, f[i] + d[i]);
		return d[t] != inf;
	}
	void Aug()
	{
		int x = t;
		while (x != s)
		{
			int r = p[x];
			e[r].cap--;
			e[r ^ 1].cap++;
			x = e[r].a;
		}
	}
	int Calc()
	{
		Dij(d, f);
		while (Dij(f, d))
			Aug();
		int res = 0;
		for (int r = 3; r < e.size(); r += 2)
			res -= e[r].cap * e[r].cost;
		return res;
	}
};

MinCost mc;
char s[1 << 20];

int main()
{
	int a;
	scanf("%d", &a);
	scanf("%s", s);
	int zn = 1;
	vi v;
	vi vt;
	int p = 0;
	int len = strlen(s);
	while (p < len)
	{
		int x = 1;
		if (s[p] >= '0' && s[p] <= '9')
		{
			x = 0;
			while (s[p] >= '0' && s[p] <= '9')
			{
				x = x * 10 + s[p] - '0';
				p++;
			}
			p++;
		}
		x = x * zn;
		v.push_back(x);
		vt.push_back(s[p] != 'a');
		p += 3;
		if (p < len)
		{
			if (s[p] == '+')
				zn = 1;
			else
				zn = -1;
			p++;
		}
	}
	mc.SetN(v.size() * 2 + 2);
	mc.e.reserve(v.size() * v.size() * 4);

	FOR(i, v.size())
	{
		mc.AddE(mc.s, i, 1, 1);
		mc.AddE(v.size() + i, mc.t, 1, 1);
	}
	FOR(i, v.size())
		FOR(j, v.size())
			mc.AddE(i, v.size() + j, 1, -v[i] * (a + j + vt[i]) + 2000000);

	int res = -mc.Calc() + v.size() * 2 + 2000000 * v.size();

	printf("%d\n", res);

	return 0;
}


#include <queue>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;
typedef long long LL;
typedef vector<int> vi;
#define FOR(i, n) for(int i = 0; i < (int)(n); ++i)

const int inf = 1 << 29;

struct MinCost
{
	int n, s, t;
	struct edge
	{
		int a, b, cost, cap, next;
	};
	vector<edge> e;
	vi g, d, p, f, flag;
	void SetN(int nn)
	{
		n = nn;
		s = n - 1;
		t = n - 2;
		g.assign(n, 0);
		d.assign(n, 0);
		p.assign(n, 0);
		f.assign(n, 0);
		flag.assign(n, 0);
		e.resize(2);
	}
	void AddE(int a, int b, int cap, int cost)
	{
		edge ee;

		ee.a = a;
		ee.b = b;
		ee.cap = cap;
		ee.cost = cost;
		ee.next = g[a];
		g[a] = e.size();
		e.push_back(ee);

		ee.a = b;
		ee.b = a;
		ee.cap = 0;
		ee.cost = -cost;
		ee.next = g[b];
		g[b] = e.size();
		e.push_back(ee);
	}
	bool Dij(vi& f, vi&d)
	{
		flag.assign(n, 0);
		d.assign(n, inf);
		d[s] = 0;
		set<pair<int, int> > q;
		q.insert(make_pair(0, s));
		int cnt = 0;
		while (q.size())
		{
			cnt++;
			if (cnt > 1000)
				++*(int*)0;
			//int Min = inf;
			//int x = -1;
			//FOR(i, n)
			//	if (!flag[i] && Min > d[i])
			//	{
			//		Min = d[i];
			//		x = i;
			//	}
			//if (Min == inf) break;
			int Min = q.begin()->first;
			int x = q.begin()->second;
			q.erase(q.begin());
			flag[x] = 1;
			for (int r = g[x]; r; r = e[r].next)
				if (e[r].cap > 0)
					if (d[e[r].b] > Min + f[e[r].a] - f[e[r].b] + e[r].cost)
					{
						q.erase(make_pair(d[e[r].b], e[r].b));
						d[e[r].b] = Min + f[e[r].a] - f[e[r].b] + e[r].cost;
						q.insert(make_pair(d[e[r].b], e[r].b));
						p[e[r].b] = r;
//						flag[e[r].b] = 0;
					}
		}
		FOR(i, n)
			f[i] = min(inf, f[i] + d[i]);
		return d[t] != inf;
	}
	void Aug()
	{
		int x = t;
		while (x != s)
		{
			int r = p[x];
			e[r].cap--;
			e[r ^ 1].cap++;
			x = e[r].a;
		}
	}
	int Calc()
	{
		Dij(d, f);
		while (Dij(f, d))
			Aug();
		int res = 0;
		for (int r = 3; r < e.size(); r += 2)
			res -= e[r].cap * e[r].cost;
		return res;
	}
};

MinCost mc;
char s[1 << 20];

int main()
{
	int a;
	scanf("%d", &a);
	scanf("%s", s);
	int zn = 1;
	vi v;
	vi vt;
	int p = 0;
	int len = strlen(s);
	while (p < len)
	{
		int x = 1;
		if (s[p] >= '0' && s[p] <= '9')
		{
			x = 0;
			while (s[p] >= '0' && s[p] <= '9')
			{
				x = x * 10 + s[p] - '0';
				p++;
			}
			p++;
		}
		x = x * zn;
		v.push_back(x);
		vt.push_back(s[p] != 'a');
		p += 3;
		if (p < len)
		{
			if (s[p] == '+')
				zn = 1;
			else
				zn = -1;
			p++;
		}
	}
	mc.SetN(v.size() * 2 + 2);
	mc.e.reserve(v.size() * v.size() * 4);

	FOR(i, v.size())
	{
		mc.AddE(mc.s, i, 1, 0);
		mc.AddE(v.size() + i, mc.t, 1, 0);
	}
	FOR(i, v.size())
		FOR(j, v.size())
			mc.AddE(i, v.size() + j, 1, -v[i] * (a + j + vt[i]));

	int res = -mc.Calc();

	printf("%d\n", res);

	return 0;
}


#include <queue>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;
typedef long long LL;
typedef vector<int> vi;
#define FOR(i, n) for(int i = 0; i < (int)(n); ++i)

const int inf = 1 << 29;

struct MinCost
{
	int n, s, t;
	struct edge
	{
		int a, b, cost, cap, next;
	};
	vector<edge> e;
	vi g, d, p, f, flag;
	void SetN(int nn)
	{
		n = nn;
		s = n - 1;
		t = n - 2;
		g.assign(n, 0);
		d.assign(n, 0);
		p.assign(n, 0);
		f.assign(n, 0);
		flag.assign(n, 0);
		e.resize(2);
	}
	void AddE(int a, int b, int cap, int cost)
	{
		edge ee;

		ee.a = a;
		ee.b = b;
		ee.cap = cap;
		ee.cost = cost;
		ee.next = g[a];
		g[a] = e.size();
		e.push_back(ee);

		ee.a = b;
		ee.b = a;
		ee.cap = 0;
		ee.cost = -cost;
		ee.next = g[b];
		g[b] = e.size();
		e.push_back(ee);
	}
	bool Dij(vi& f, vi&d)
	{
		flag.assign(n, 0);
		d.assign(n, inf);
		d[s] = 0;
		set<pair<int, int> > q;
		q.insert(make_pair(0, s));
		int cnt = 0;
		while (q.size())
		{
			cnt++;
			if (cnt > 1000)
				++*(int*)0;
			//int Min = inf;
			//int x = -1;
			//FOR(i, n)
			//	if (!flag[i] && Min > d[i])
			//	{
			//		Min = d[i];
			//		x = i;
			//	}
			//if (Min == inf) break;
			int Min = q.begin()->first;
			int x = q.begin()->second;
			q.erase(q.begin());
			flag[x] = 1;
			for (int r = g[x]; r; r = e[r].next)
				if (e[r].cap > 0)
					if (d[e[r].b] > Min + f[e[r].a] - f[e[r].b] + e[r].cost)
					{
						q.erase(make_pair(d[e[r].b], e[r].b));
						d[e[r].b] = Min + f[e[r].a] - f[e[r].b] + e[r].cost;
						q.insert(make_pair(d[e[r].b], e[r].b));
						p[e[r].b] = r;
//						flag[e[r].b] = 0;
					}
		}
		FOR(i, n)
			f[i] = min(inf, f[i] + d[i]);
		return d[t] != inf;
	}
	void Aug()
	{
		int x = t;
		while (x != s)
		{
			int r = p[x];
			e[r].cap--;
			e[r ^ 1].cap++;
			x = e[r].a;
		}
	}
	int Calc()
	{
		Dij(d, f);
		while (Dij(f, d))
			Aug();
		int res = 0;
		for (int r = 3; r < e.size(); r += 2)
			res -= e[r].cap * e[r].cost;
		return res;
	}
};

MinCost mc;
char s[1 << 20];

int main()
{
	int a;
	scanf("%d", &a);
	scanf("%s", s);
	int zn = 1;
	vi v;
	vi vt;
	int p = 0;
	int len = strlen(s);
	while (p < len)
	{
		int x = 1;
		if (s[p] >= '0' && s[p] <= '9')
		{
			x = 0;
			while (s[p] >= '0' && s[p] <= '9')
			{
				x = x * 10 + s[p] - '0';
				p++;
			}
			p++;
		}
		x = x * zn;
		v.push_back(x);
		vt.push_back(s[p] != 'a');
		p += 3;
		if (p < len)
		{
			if (s[p] == '+')
				zn = 1;
			else
				zn = -1;
			p++;
		}
	}
	mc.SetN(v.size() * 2 + 2);
	mc.e.reserve(v.size() * v.size() * 4);

	FOR(i, v.size())
	{
		mc.AddE(mc.s, i, 1, 1);
		mc.AddE(v.size() + i, mc.t, 1, 1);
	}
	FOR(i, v.size())
		FOR(j, v.size())
			mc.AddE(i, v.size() + j, 1, -v[i] * (a + j + vt[i]));

	int res = -mc.Calc() + v.size() * 2;

	printf("%d\n", res);

	return 0;
}