#include <stdio.h>
long long n, t, arr[100005], cant=0, maxi, sum=0, x;
int main()
{
    scanf("%I64d%I64d", &n, &t);
    for(long long i=0; i<n; i++)
    {
        scanf("%I64d", &arr[i]);
        sum+=arr[i];
    }
    if(sum<t)
    {
        printf("0");
        return 0;
    }
    else if(sum==t)
    {
        printf("%I64d", n);
        return 0;
    }
    for(long long i=0; i<n-maxi; i++)
    {
        sum=0;
        cant=0;
        x=i;
        while(sum<=t and x<n)
        {
            sum+=arr[x];
            if(sum<=t)
            cant++;
            if(cant>maxi)
                maxi=cant;
            x++;
        }
    }
    printf("%I64d", maxi);
    return 0;
}


#include <stdio.h>
long long n, t, arr[100005], cant=0, maxi, sum=0, x;
int main()
{
    scanf("%I64d%I64d", &n, &t);
    for(long long i=0; i<n; i++)
        scanf("%I64d", &arr[i]);
    for(long long i=0; i<n; i++)
    {
        sum=arr[i];
        cant=0;
        x=i;
        while(sum<=t and x<n)
        {
            cant++;
            if(cant>maxi)
                maxi=cant;
            sum+=arr[x];
            x++;
        }
    }
    printf("%I64d", maxi);
    return 0;
}


#include <stdio.h>
long long  t, arr[100005], cant=0, maxi, sum=0, x, piv, piv2, med, y;
int n;
bool b1=true;
int main()
{
    scanf("%d%I64d", &n, &t);
    for(int i=0; i<n; i++)
    {
        scanf("%I64d", &arr[i]);
        if(arr[i]<=t)
            b1=false;
    }
    if(b1==true)
    {
        printf("0");
        return 0;
    }
    long long x=0, cant=0, may=0;
    sum=0;
    for(int i=0; i<n; i++)
    {
        //printf("%I64d %I64d ", sum, cant);
        sum+=arr[i];
        cant++;
        while(sum<t and x<n)
        {
            if(cant>may)
                    may=cant;
                x++;
                sum+=arr[x];
                cant++;
                if(sum>t)
                {
                    cant--;
                    sum-=arr[i];
                    //printf("%d\n", arr[i]);
                    break;
                }
        }

    }
        printf("%I64d", may);
    return 0;
}


#include <stdio.h>
long long n, t, arr[100005], cant=0, maxi, sum=0, x;
int main()
{
    scanf("%I64d%I64d", &n, &t);
    for(long long i=0; i<n; i++)
        scanf("%I64d", &arr[i]);
    for(long long i=0; i<n; i++)
    {
        sum=0;
        cant=0;
        x=i;
        while(sum<=t and x<n)
        {
            sum+=arr[x];
            if(sum<=t)
            cant++;
            if(cant>maxi)
                maxi=cant;
            x++;
        }
    }
    printf("%I64d", maxi);
    return 0;
}


#include <stdio.h>
long long  t, arr[100005], cant=0, sum=0, may=1;
int n, x;
bool b1=true;
int main()
{
    scanf("%d%I64d", &n, &t);
    for(int i=0; i<n; i++)
    {
        scanf("%I64d", &arr[i]);
        if(arr[i]<=t)
            b1=false;
    }
    if(b1==true)
    {
        printf("0");
        return 0;
    }
    sum=0;
    for(int i=0; i<n and x<n; i++)
    {
        //printf("%I64d %I64d ", sum, cant);
        if(sum<t)
        {
            while(sum<t and x<n)
            {
                    sum+=arr[x];
                    cant++;
                    x++;
                    if(sum>t)
                    {
                        //printf("sali%I64d %d ", sum, x);
                        cant--;
                        sum-=arr[i];
                        break;
                    }
                    if(cant>may)
                        may=cant;
            }

        }
        else
        {
            cant--;
            sum-=arr[i];
            if(sum<0)
                sum=0;
        }

    }
        printf("%I64d", may);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
    int n,t,i;
    cin>>n>>t;
    int arr[n];
    for(i=0;i<n;i++)
        cin>>arr[i];
    int count=0,sum,start,j,ans,temp;
    temp=0;
    start=0;
    count=0;
    for(i=0;i<n;i++)
    {
        sum+=arr[i];
        if(sum<=t)
            temp++;
        else
        if(sum>t)
        {
            count=max(count,temp);
            j=start;
            temp++;
            while(1)
            {
                sum-=arr[j];
                j++;
                temp--;
                if(sum<=t)
                    break;
                if(j>i)
                    break;

            }
            start=j;
        }

    }
    count=max(count,temp);
    cout<<count<<endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#define LL long int
using namespace std;
int main()
{
    LL n,t,i;
    cin>>n>>t;
    LL arr[n];
    for(i=0;i<n;i++)
        cin>>arr[i];
    LL count=0,sum=0,start,j,ans,temp;
    temp=0;
    start=0;
    count=0;
    for(i=0;i<n;i++)
    {
        sum+=arr[i];
        if(sum<=t)
            temp++;
        else
        if(sum>t)
        {
            count=max(count,temp);
            j=start;
            temp++;
            while(1)
            {
                sum-=arr[j];
                j++;
                temp--;
                if(sum<=t)
                    break;
                if(j>i)
                    break;

            }
            start=j;
        }

    }
    count=max(count,temp);
    cout<<count<<endl;
    return 0;


#include<iostream>
#include<cstdio>
#include<algorithm>
#define LL long int
using namespace std;

LL booktime[10000];
int main()
{
   LL books,times,sum=0,i,j,t,maxi=0,temp=0;
    scanf("%ld %ld",&books,&times);
    for(i=0;i<books;i++)
    scanf("%ld",&booktime[i]);

    for(int i=0;i<books;i++)
    {
        t=times;
        temp=0;
        for(j=i;j<books;j++)
        {
            if(booktime[j]<=t&&t>0)
                {temp++;t-=booktime[j];}
        }

        if(t<0)
            temp--;
        if(i==0||maxi<temp)
            maxi=temp;

    }
    printf("%ld",maxi);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#define LL long long int
using namespace std;
int main()
{
    LL n,t,i,max_count;
    cin>>n>>t;
    LL arr[n];
    for(i=0;i<n;i++)
        cin>>arr[i];
    LL count=0,sum,start,j,ans,temp;
    temp=1;
    sum=arr[0];
    start=0;
    count=0;
    for(i=1;i<n;i++)
    {
        sum+=arr[i];
        if(sum<=t)
            temp++;
        else
        if(sum>t)
        {
            count=max(count,temp);
            j=start;
            temp++;
            while(1)
            {
                sum-=arr[j];
                j++;
                temp--;
                if(sum<=t)
                    break;
                if(j>i)
                    break;

            }
            start=j;
            //cout<<"temp: "<<temp<<endl;
        }

    }
    count=max(count,temp);
    cout<<count<<endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#define LL long long int
using namespace std;

LL booktime[10000];
int main()
{
   LL books,times,sum=0,i,j,t,maxi=0,temp=0;
    scanf("%ld %ld",&books,&times);
    for(i=0;i<books;i++)
    scanf("%ld",&booktime[i]);

    for(int i=0;i<books;i++)
    {
        t=times;
        temp=0;
        for(j=i;j<books;j++)
        {
            if(booktime[j]<=t&&t>0)
                {temp++;t-=booktime[j];}
        }

        if(t<0)
            temp--;
        if(i==0||maxi<temp)
            maxi=temp;

    }
    printf("%ld",maxi);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#define LL long long int
using namespace std;
int main()
{
    LL n,t,i;
    cin>>n>>t;
    LL arr[n];
    for(i=0;i<n;i++)
        cin>>arr[i];
    LL count=0,sum,start,j,ans,temp;
    temp=0;
    start=0;
    count=0;
    for(i=0;i<n;i++)
    {
        sum+=arr[i];
        if(sum<=t)
            temp++;
        else
        if(sum>t)
        {
            count=max(count,temp);
            j=start;
            temp++;
            while(1)
            {
                sum-=arr[j];
                j++;
                temp--;
                if(sum<=t)
                    break;
                if(j>i)
                    break;

            }
            start=j;
            //cout<<"temp: "<<temp<<endl;
        }

    }
    count=max(count,temp);
    cout<<count<<endl;
    return 0;
}


#include<stdio.h>
#include<iostream>
using namespace std;
int book[10000];
int main(){
long long noOfB,noOfM,tt=0,bMAX=0,b=0;cin>>noOfB>>noOfM;
for(int n=1;n<=noOfB;n++)
{int h;cin>>h;book[n]=h;}
for(int j=1;j<=noOfB;j++){
    long long i=j,t=1;
    while(tt+book[i]<=(noOfM) && t<=noOfB){
        tt=tt+book[i++];
        t++;
        if(i>noOfB) i=1;
        b++;
    }
if(b>bMAX) {bMAX=b;}

}
cout<<b;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#define LL long long int
using namespace std;
int main()
{
    LL n,t,i;
    cin>>n>>t;
    LL arr[n];
    for(i=0;i<n;i++)
        cin>>arr[i];
    LL count=0,sum=0,start,j,ans,temp;
    temp=0;
    start=0;
    count=0;
    for(i=0;i<n;i++)
    {
        sum+=arr[i];
        if(sum<=t)
            temp++;
        else
        if(sum>t)
        {
            count=max(count,temp);
            j=start;
            temp++;
            while(1)
            {
                sum-=arr[j];
                j++;
                temp--;
                if(sum<=t)
                    break;
                if(j>i)
                    break;

            }
            start=j;
        }

    }
    count=max(count,temp);
    cout<<count<<endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#define LL long long int
using namespace std;
int main()
{
    LL n,t,i;
    cin>>n>>t;
    LL arr[n];
    for(i=0;i<n;i++)
        cin>>arr[i];
    LL count=0,sum,start,j,ans,temp;
    temp=0;
    start=0;
    count=0;
    for(i=0;i<n;i++)
    {
        sum+=arr[i];
        if(sum<=t)
            temp++;
        else
        if(sum>t)
        {
            count=max(count,temp);
            j=start;
            temp++;
            while(1)
            {
                sum-=arr[j];
                j++;
                temp--;
                if(sum<=t)
                    break;
                if(j>i)
                    break;

            }
            start=j;
        }

    }
    count=max(count,temp);
    cout<<count<<endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#define LL long long int
using namespace std;
int main()
{
    LL n,t,i,max_count;
    cin>>n>>t;
    LL arr[n];
    for(i=0;i<n;i++)
        cin>>arr[i];
    LL count=0,sum,start,j,ans,temp;
    temp=1;
    sum=arr[0];
    start=0;
    count=0;
    for(i=1;i<n;i++)
    {
        sum+=arr[i];
        if(sum<=t)
            temp++;
        else
        if(sum>t)
        {
            count=max(count,temp);
            j=start;
            while(sum>t && j<=i)
            {
                sum-=arr[j];
                j++;
                temp--;
            }
            temp++;
            start=j;
            //cout<<"start: "<<start<<endl;
        }

    }
    count=max(count,temp);
    cout<<count<<endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>

using namespace std;

long int booktime[100005];
int main()
{
    long int books,times,sum=0,i,j,maxi=0,temp=0;;
    scanf("%ld %ld",&books,&times);
    for(i=0;i<books;i++)
        scanf("%ld",&booktime[i]);

    for(i=0;i<books;i++)
    {
        sum=booktime[i];
        for(j=i;j<books&&sum<=times;j++)
            sum+=booktime[j];
        j--;
           temp=j-i+1;
        if(temp>maxi)
            maxi=temp;
    }
    printf("%ld",maxi);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#define LL long int
using namespace std;
int main()
{
    LL n,t,i;
    cin>>n>>t;
    LL arr[n];
    for(i=0;i<n;i++)
        cin>>arr[i];
    LL count=0,sum,start,j,ans,temp;
    temp=0;
    start=0;
    count=0;
    for(i=0;i<n;i++)
    {
        sum+=arr[i];
        if(sum<=t)
            temp++;
        else
        if(sum>t)
        {
            count=max(count,temp);
            j=start;
            temp++;
            while(1)
            {
                sum-=arr[j];
                j++;
                temp--;
                if(sum<=t)
                    break;
                if(j>i)
                    break;

            }
            start=j;
        }

    }
    count=max(count,temp);
    cout<<count<<endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#define LL long long int
using namespace std;
int main()
{
    LL n,t,i,max_count;
    cin>>n>>t;
    LL arr[n];
    for(i=0;i<n;i++)
        cin>>arr[i];
    LL count=0,sum,start,j,ans,temp;
    temp=1;
    sum=arr[0];
    start=0;
    count=0;
    for(i=1;i<n;i++)
    {
        sum+=arr[i];
        if(sum<=t)
            temp++;
        else
        if(sum>t)
        {
            count=max(count,temp);
            j=start;
            while(sum>t && j<=i)
            {
                sum-=arr[j];
                j++;
                temp--;
            }
            temp++;
            start=j-1;
        }
    }
    count=max(count,temp);
    cout<<count<<endl;
    return 0;
}


#include<iostream>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
int dax,waik,t,n,moas,i,daiw,max1;
int a[1000000];
int main()
{
    cin>>n>>t;
    moas=0;
    dax=0;
    max1=-1;
    for (i=1;i<=n;i++)
    {
        if (waik>max1) max1=waik;
        cin>>a[i];
        if (dax<t)
        {
         if (dax==0) daiw=i;
         dax+=a[i];
         waik++;
         }
         if (waik>max1) max1=waik;
       while (dax>t)
            {
             dax-=a[daiw];
             waik--;
             daiw++;
             }
             if (waik>max1) max1=waik;
     }
  cout<<max1;
  return 0;
}


#include<iostream>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
int dax,waik,t,n,moas,i,daiw,max1;
int a[1000000];
int main()
{

    cin>>n>>t;
    moas=0;
    dax=0;
    max1=-1;
    for (i=1;i<=n;i++)
    {
        if (waik>max1) max1=waik;
        cin>>a[i];
        if (dax<=t) if (waik>max1) max1=waik;
        if (dax+a[i]<=t)
        {
         if (dax==0) daiw=i;
         dax+=a[i];
         waik++;
         }
       if (dax<=t) if (waik>max1) max1=waik;
       while (dax>t)
            {
             dax-=a[daiw];
             waik--;
             daiw++;
             }
     }
  cout<<max1;
  return 0;
}


#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <functional>

using namespace std;

struct JiBenShi
{
	int n;
	bool first;
};

JiBenShi a[5000];

bool cmp(JiBenShi A, JiBenShi B)
{
	return A.n < B.n;
}

int main()
{
	int last = 0;
	int initvalue;
	scanf("%d\n", &initvalue);
	while (1)
	{
		int n = 1;
		char ch1 = 0, ch2 = 0, ch3 = 0;
		char cc[2] = {0};
		if (scanf("%1[-]", &cc) == EOF) break;
		char number[5000] = {0};
		if (scanf("%[0-9]", number) == EOF) break;
		if (strlen(number)) n = atoi(number);
		scanf("*");
		if (scanf("%c%c%c", &ch1, &ch2, &ch3) == EOF) break;
		if (cc[0] == '-')
		{
			n *= -1;
		}
		if (!ch1 || !ch2 || !ch3)
		{
			break;
		}
		a[++last].n = n;
		a[last].first = ch3 == 'a';
	}
	sort(a + 1, a + 1 + last, cmp);
	int ans = 0;
	for (int i = 1; i <= last; i++)
	{
		if (a[i].first)
		{
			++initvalue;
			ans += initvalue * a[i].n;
		}
		else
		{
			ans += initvalue * a[i].n;
			++initvalue;
		}
	}
	printf("%d\n", ans);
	return 0;
}


#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <functional>

using namespace std;

struct JiBenShi
{
	int n;
	bool first;
};

JiBenShi a[5000];

bool cmp(JiBenShi A, JiBenShi B)
{
	return A.n < B.n;
}

int main()
{
	int last = 0;
	int initvalue;
	scanf("%d\n", &initvalue);
	while (1)
	{
		int n = 1;
		char ch1 = 0, ch2 = 0, ch3 = 0;
		char cc[2] = {0};
		if (scanf("%1[+-]", &cc) == EOF) break;
		char number[5000] = {0};
		if (scanf("%[0-9]", number) == EOF) break;
		if (strlen(number)) n = atoi(number);
		if (scanf("%c%c%c", &ch1, &ch2, &ch3) == EOF) break;
		if (cc[0] == '-')
		{
			n *= -1;
		}
		if (!ch1 || !ch2 || !ch3)
		{
			break;
		}
		a[++last].n = n;
		a[last].first = ch3 == 'a';
	}
	sort(a + 1, a + 1 + last, cmp);
	int ans = 0;
	for (int i = 1; i <= last; i++)
	{
		if (a[i].first)
		{
			++initvalue;
			ans += initvalue * a[i].n;
		}
		else
		{
			ans += initvalue * a[i].n;
			++initvalue;
		}
	}
	printf("%d\n", ans);
	return 0;
}


#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <functional>

using namespace std;

struct JiBenShi
{
	int n;
	bool first;
};

JiBenShi a[5000];

bool cmp(JiBenShi A, JiBenShi B)
{
	return A.n < B.n;
}

int main()
{
	int last = 0;
	int initvalue;
	scanf("%d\n", &initvalue);
	while (1)
	{
		int n = 1;
		char ch1 = 0, ch2 = 0, ch3 = 0;
		char cc[2] = {0};
		if (scanf("%1[-]", &cc) == EOF) break;
		if (last && cc[0] == 0)
		{
			if (scanf("+") == EOF) break;
		}
		char number[5000] = {0};
		if (scanf("%[0-9]", number) == EOF) break;
		if (strlen(number)) n = atoi(number);
		scanf("*");
		if (scanf("%c%c%c", &ch1, &ch2, &ch3) == EOF) break;
		if (cc[0] == '-')
		{
			n *= -1;
		}
		if (!ch1 || !ch2 || !ch3)
		{
			break;
		}
		a[++last].n = n;
		a[last].first = ch3 == 'a';
	}
	sort(a + 1, a + 1 + last, cmp);
	int ans = 0;
	for (int i = 1; i <= last; i++)
	{
		if (a[i].first)
		{
			++initvalue;
			ans += initvalue * a[i].n;
		}
		else
		{
			ans += initvalue * a[i].n;
			++initvalue;
		}
	}
	printf("%d\n", ans);
	return 0;
}


#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <math.h>
#include <fstream>
#include <iostream>
#include <vector>
#include <deque>
#include <map>
#include <cstdlib>
using namespace std;

// Disable warning messages C4996.
//#pragma warning(disable:4996)

#define INPUT_FROM 0
#if INPUT_FROM
#define fromc from
#else
#define fromc cin
#endif

//int fr(vector<int>&, int);

int main(int argc, char **argv)
{
	ifstream from;
	//const int fin = 0;//0 - cin, 1 - from file
	const int err = 0;//0 - Ok, 1 - find error
	const long long nmin=1, nmax=1000, amin=-1000, amax=1000;
	long long n, m, res, rt, at, i, j, k, ax, bx, cx, dx, a, as;
	char ch;
	//string sres[2]={"YES", "NO"};
	//string s, st, ss, sb;
	//long double dt;

	if(INPUT_FROM) from.open("test.txt");
	fromc>>a;

	vector<long long> v, va;
	//map<long long, long long> mi;
	//map<long long, vector<long long> > mz;

	ax=bx=cx=dx=0;//ax-number of consequent '+' read
	as=rt=1;
	while(fromc>>ch){
		switch(ch){
			case '+': ax++; break;
			case '-': as=-1; break;
			case '*': break;
			case 'a': cx=1; break;
			default:
				ax=0;
				if(bx==0){
					bx=1;
					rt=ch-'0';
				}else rt=10*rt+(ch-'0');
		}
		if((ax==2)&&(dx==0)){
			dx=1;
			va.push_back(1-cx);
		}
		if((ax>=2)&&(cx==1)){
			v.push_back(as*rt);
			ax=bx=cx=dx=0;
			as=rt=1;
		}
	}
	n=v.size();

	for(i=0;i<n-1;i++){
		for(j=i+1;j<n;j++){
			if((v[j]>v[i])||((v[j]==v[i])&&(v[j]*va[j]>0)&&(va[i]==0))){
				rt=v[i];
				v[i]=v[j];
				v[j]=rt;
				rt=va[i];
				va[i]=va[j];
				va[j]=rt;
			}
		}
	}

	res=0;
	at=a;
	for(i=0;i<n;i++){
		rt=v.back();
		rt*=at+va.back();
		res+=rt;
		at++;
		v.pop_back();
		va.pop_back();
	}

	cout<<res<<endl;

	return 0;
}


#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <math.h>
#include <fstream>
#include <iostream>
#include <vector>
#include <deque>
#include <map>
#include <cstdlib>
using namespace std;

// Disable warning messages C4996.
//#pragma warning(disable:4996)

#define INPUT_FROM 0
#if INPUT_FROM
#define fromc from
#else
#define fromc cin
#endif

//int fr(vector<int>&, int);

int main(int argc, char **argv)
{
	ifstream from;
	//const int fin = 0;//0 - cin, 1 - from file
	const int err = 0;//0 - Ok, 1 - find error
	const long long nmin=1, nmax=1000, amin=-1000, amax=1000;
	long long n, m, res, rt, at, i, j, k, ax, bx, cx, dx, a, as;
	char ch;
	//string sres[2]={"YES", "NO"};
	//string s, st, ss, sb;
	//long double dt;

	if(INPUT_FROM) from.open("test.txt");
	fromc>>a;

	vector<long long> v, va;
	//map<long long, long long> mi;
	//map<long long, vector<long long> > mz;

	ax=bx=cx=dx=0;//ax-number of consequent '+' read
	as=rt=1;
	while(fromc>>ch){
		switch(ch){
			case '+': ax++; break;
			case '-': as=-1; break;
			case '*': break;
			case 'a': cx=1; break;
			default:
				ax=0;
				if(bx==0){
					bx=1;
					rt=ch-'0';
				}else rt=10*rt+(ch-'0');
		}
		if((ax==2)&&(dx==0)){
			dx=1;
			va.push_back(1-cx);
		}
		if((ax>=2)&&(cx==1)){
			v.push_back(as*rt);
			ax=bx=cx=dx=0;
			as=rt=1;
		}
	}
	n=v.size();

	for(i=0;i<n-1;i++){
		for(j=i+1;j<n;j++){
			if((v[j]>v[i])||((v[j]==v[i])&&(v[i]*va[i]>0)&&(va[j]==0))){
				rt=v[i];
				v[i]=v[j];
				v[j]=rt;
				rt=va[i];
				va[i]=va[j];
				va[j]=rt;
			}
		}
	}

	res=0;
	at=a;
	for(i=0;i<n;i++){
		rt=v.back();
		rt*=at+va.back();
		res+=rt;
		at++;
		v.pop_back();
		va.pop_back();
	}

	cout<<res<<endl;

	return 0;
}


#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <math.h>
#include <fstream>
#include <iostream>
#include <vector>
#include <deque>
#include <map>
#include <cstdlib>
using namespace std;

// Disable warning messages C4996.
//#pragma warning(disable:4996)

#define INPUT_FROM 0
#if INPUT_FROM
#define fromc from
#else
#define fromc cin
#endif

//int fr(vector<int>&, int);

int main(int argc, char **argv)
{
	ifstream from;
	//const int fin = 0;//0 - cin, 1 - from file
	const int err = 0;//0 - Ok, 1 - find error
	const long long nmin=1, nmax=1000, amin=-1000, amax=1000;
	long long n, m, res, rt, at, i, j, k, ax, bx, cx, dx, a, as;
	char ch;
	//string sres[2]={"YES", "NO"};
	//string s, st, ss, sb;
	//long double dt;

	if(INPUT_FROM) from.open("test.txt");
	fromc>>a;

	vector<long long> v, va;
	//map<long long, long long> mi;
	//map<long long, vector<long long> > mz;

	ax=bx=cx=dx=0;//ax-number of consequent '+' read
	as=rt=1;
	while(fromc>>ch){
		switch(ch){
			case '+': ax++; break;
			case '-': as=-1; break;
			case '*': break;
			case 'a': cx=1; ax=(ax<2)?0:2; break;
			default:
				ax=0;
				if(bx==0){
					bx=1;
					rt=ch-'0';
				}else rt=10*rt+(ch-'0');
		}
		if((ax==2)&&(dx==0)){
			dx=1;
			va.push_back(1-cx);
		}
		if((ax>=2)&&(cx==1)){
			v.push_back(as*rt);
			ax=bx=cx=dx=0;
			as=rt=1;
		}
	}
	n=v.size();

	for(i=0;i<n-1;i++){
		for(j=i+1;j<n;j++){
			//if((v[j]>v[i])||((v[j]==v[i])&&(v[i]*va[i]>0)&&(va[j]==0))){
			if(v[j]>v[i]){
				rt=v[i];
				v[i]=v[j];
				v[j]=rt;
				rt=va[i];
				va[i]=va[j];
				va[j]=rt;
			}
		}
	}

	res=0;
	at=a;
	for(i=0;i<n;i++){
		rt=v.back();
		rt*=at+va.back();
		res+=rt;
		at++;
		v.pop_back();
		va.pop_back();
	}

	cout<<res<<endl;

	return 0;
}


    #include <iostream>
    #include <fstream>
    #include <cstdio>
    #include <vector>
    #include <string>
    #include <algorithm>
    #include <map>
    #include <queue>
    #include <cmath>
    #include <deque>
    #include <sstream>
    #include <stack>
    #include <cctype>

    using namespace std;

    //#define REP(i,n) for (int (i) = 0; (i) < n; (i)++)
    #define REP(i,n) for (int i = 0; i < n; i++)
    #define mp(y,z) make_pair((y), (z))
    #define pb(z) push_back(z)
    #define all(v) (v).begin(), (v).end()
    #define sz(v) (v).size()
    #define sqr(n) (n)*(n)
    #define print(v) REP(i, sz(v)) cout << v[i] << "\n"; cout << "\n";
    //#define print(a,n) REP(i, n) cout << a[i] << " "; cout << "\n";

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

    //ifstream in ("input.txt"); ofstream out ("output.txt");

    //ifstream in ("decode.in"); ofstream out ("decode.out");

    int toInt (string s) {
        int a = 0;
        REP(i, sz(s)) {
            a = 10 * a + (int)(s[i] - '0');
        }
        return a;
    }

    int signm (int a) {
        if (a < 0) return -1;
        else return 1;
    }

    int main() {
        //freopen ("input.txt", "r", stdin); freopen ("output.txt", "w", stdout);
        int a;
        cin >> a;
        string s;
        cin >> s;
        s += "-";//sentinel
        vector <string> sums;
        vector <int> signs;
        string cur = "";
        int done = 0, sgn = 1;
        for (int i = 0; i < sz(s); i++) {
            if ((s[i] == '+') || (s[i] == '-')) {
                if (done == 2) {
                    sums.pb(cur);
                    signs.pb(sgn);
                    cur = "";
                    if (s[i] == '+') {
                        sgn = 1;
                    } else {
                        sgn = -1;
                    }
                    done = 0;
                } else {
                    cur += s[i];
                    done++;
                }
            } else {
                cur += s[i];
            }
        }
        /*REP(i, sz(sums)) {
            cout << signs[i] << " " << sums[i] << "\n";
        }*/
        vector <int> coef(sz(sums));
        vector <bool> bef(sz(sums)); //true if ++a; false otherwise
        REP(i, sz(sums)) {
            if (isdigit(sums[i][0])) {
                string z;
                int j = 0;
                while (isdigit(sums[i][j])) {
                    z += sums[i][j];
                    j++;
                }
                coef[i] = toInt(z);
            } else {
                coef[i] = 1;
            }
            bef[i] = (sums[i][sz(sums[i])-1] == 'a');
        }
        REP(i, sz(coef)) {
            coef[i] *= signs[i];
        }
        /*REP(i, sz(sums)) {
            cout << coef[i] << " " << sums[i] << " " << (bef[i]? 1: 0) << "\n";
        }*/
        vector <pair <int, pair <int, int> > > w(sz(coef));
        REP(i, sz(w)) {
            w[i] = make_pair(coef[i], make_pair((bef[i]? -1 * signm(coef[i]): 1 * signm(coef[i])), (bef[i]?-1:1)));
        }
        sort(all(w));
        int ans = 0;
        REP(i, sz(w)) {
            if (w[i].second.second == -1) {
                ++a;
                ans += a * w[i].first;
            } else {
                ans += a * w[i].first;
                ++a;
            }
        }
        cout << ans << "\n";
        /*REP(i, sz(w)) {
            cout << w[i].first << " " << (w[i].second.second? "++a": "a++") << "\n";
        }*/
        return 0;
    }


#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <sstream>
#include <algorithm>
using namespace std;
#define rep(_m,s,e) for(int _m=s;_m<e;_m++)
typedef long long ll;
int  toInt(string s)   {int r=0; istringstream sin(s); sin>>r; return r;}
ll   toInt64(string s) {ll r=0; istringstream sin(s); sin>>r; return r;}
double  toDouble(string s){double r=0; istringstream sin(s); sin>>r; return r;}
string toString(ll n) {string s,s1; while (n / 10 > 0){ s += (char)((n%10) + 48); n/=10;} s += (char)((n%10) + 48); n/=10; s1 = s; rep(i,0,s.length()) s1[(s.length()-1)-i] = s[i]; return s1;}
bool isUpperCase(char c){return c >= 'A' && c <= 'Z';}
bool isLowerCase(char c){return c >= 'a' && c <= 'z';}
bool isLetter(char c)   {return c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z';}
bool isDigit(char c)    {return c >= '0' && c <= '9';}
char toLowerCase(char c){return (isUpperCase(c))?(c + 32) : c;}
char toUpperCase(char c){return (isLowerCase(c))?(c - 32) : c;}
ll gcd(ll a, ll b) {if(!a) return b; return gcd(b%a, a);}

struct summand{
    int zarib, val, dif;
    summand(int a, int b, int c)
    {
        zarib = a;
        val = b;
        dif = c;
    }
    bool operator < (summand q) const
    {
        if (zarib == q.zarib)
            return dif+val < q.dif+q.val;
        return zarib < q.zarib;
    }
};

string s;
int n;

bool PPA(int i)
{
    if (i-2 >= 0)
        if (s[i-1] == '+' && s[i-2] == '+')
        {
            s[i-1] = s[i-2] = '!';
            return true;
        }
    return false;
}

bool APP(int i)
{
    if (i+2 < n)
        if (s[i+1] == '+' && s[i+2] == '+')
        {
            s[i+1] = s[i+2] = '!';
            return true;
        }
    return false;
}

int zarib(int i)
{
    if (i-1 >= 0)
    {
        if (s[i-1] == '*')
        {
            int q = i-2;
            string p = "";
            while (1)
            {
                p += s[q];
                q--;
                if (q < 0 || !isDigit(s[q]))
                    break;
            }
            reverse(p.begin(), p.end());
            int co = 1;
            if (q >= 0 && s[q] == '-') co = -1;
            return co*toInt(p);
        }
        else if (s[i-1] == '+')
            return 1;
        else if (s[i-1] == '-')
            return -1;
    }
    return 1;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a;
    cin >> a;
    cin >> s;
    n = s.size();
    vector<summand> exp;
    for (int i = 0; i < n; i++)
    {
        if (s[i] == 'a')
        {
            if (PPA(i))
            {
                exp.push_back(summand(zarib(i-2), 1, 0));
            }
            else if (APP(i))
            {
                exp.push_back(summand(zarib(i), 0, 1));
            }
            else {
                exp.push_back(summand(zarib(i), 0, 0));
            }
        }
        //else exp.push_back();
    }
    sort(exp.begin(), exp.end());
    ll cnt = 0;
    for (int i = 0; i < exp.size(); i++)
    {
        a += exp[i].val;
        cnt += a * exp[i].zarib;
        a += exp[i].dif;
    }
    cout << cnt << endl;
}


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

using namespace std;

#define PB push_back
#define MP make_pair
#define two(a) (1LL << (a))
#define contain(a, b)  ((a & two(b)) != 0)
#define SIZE(a) ((int)(a.size()))
#define lowbit(a) ((a) & -(a))
#define left(a) (((a) << 1) + 1)
#define right(a) (left(a) + 1)

#define pre(a) (((a) - 1) >> 1)

typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<double, double> PDD;
const double eps = 1e-7;
const double PI = 2 * acos(0.0);
using namespace std;

const int MAX = two(20);
char str[MAX];

int GetNumber(int &p)
{
    int x = 0;
    while(isdigit(str[p]))
    {
        x *= 10;
        x += str[p++] - '0';
    }
    p++;
    return x;
}

vector<PII> detach()
{
    vector<PII> rt;
    int p = 0, len = strlen(str);

    while(p < len)
    {
        int d = str[p++] == '-' ? -1 : 1, a = d;

        if(isdigit(str[p])) a = d * GetNumber(p);
        if(str[p] == 'a') rt.push_back(PII(a, 0));
        else rt.push_back(PII(a, 1));
        p += 3;
    }

    return rt;
}

int cal(PII x, int p)
{
    return x.first * (x.second + p);
}

int main()
{
    memset(str, 0, sizeof(str));
    int a;
    cin >> a >> (str + 1);
    str[0] = '+';
    vector<PII> t = detach();
    for(int i = 0; i < t.size(); i++) t[i].second += a;

    sort(t.begin(), t.end());

    int rt = 0;
    for(int i = 0; i < t.size(); i++) rt += cal(t[i], i);
    cout << rt << endl;
    return 0;
}


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

using namespace std;

#define PB push_back
#define MP make_pair
#define two(a) (1LL << (a))
#define contain(a, b)  ((a & two(b)) != 0)
#define SIZE(a) ((int)(a.size()))
#define lowbit(a) ((a) & -(a))
#define left(a) (((a) << 1) + 1)
#define right(a) (left(a) + 1)

#define pre(a) (((a) - 1) >> 1)

typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<double, double> PDD;
const double eps = 1e-7;
const double PI = 2 * acos(0.0);
using namespace std;

const int MAX = two(20);
char str[MAX];

int GetNumber(int &p)
{
    int x = 0;
    while(isdigit(str[p]))
    {
        x *= 10;
        x += str[p++] - '0';
    }
    p++;
    return x;
}

vector<PII> detach()
{
    vector<PII> rt;
    int p = 0, len = strlen(str);

    while(p < len)
    {
        int d = str[p++] == '-' ? -1 : 1, a = 1;

        if(isdigit(str[p])) a = d * GetNumber(p);
        if(str[p] == 'a') rt.push_back(PII(a, 0));
        else rt.push_back(PII(a, 1));
        p += 3;
    }

    return rt;
}

int cal(PII x, int p)
{
    return x.first * (x.second + p);
}

int main()
{
    memset(str, 0, sizeof(str));
    int a;
    cin >> a >> (str + 1);
    str[0] = '+';
    vector<PII> t = detach();
    for(int i = 0; i < t.size(); i++) t[i].second += a;

    int l = t.size();
    while(1)
    {
        bool flag = false;
        for(int i = 0; i < l; i++)
            for(int j = i + 1; j < l; j++) if(cal(t[i], j) + cal(t[j], i) > cal(t[i], i) + cal(t[j], j))
            {
                swap(t[i], t[j]);
                flag = true;
            }
        if(!flag) break;
    }

    int rt = 0;
    for(int i = 0; i < t.size(); i++) rt += cal(t[i], i);
    cout << rt << endl;
    return 0;
}


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

using namespace std;

#define PB push_back
#define MP make_pair
#define two(a) (1LL << (a))
#define contain(a, b)  ((a & two(b)) != 0)
#define SIZE(a) ((int)(a.size()))
#define lowbit(a) ((a) & -(a))
#define left(a) (((a) << 1) + 1)
#define right(a) (left(a) + 1)

#define pre(a) (((a) - 1) >> 1)

typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<double, double> PDD;
const double eps = 1e-7;
const double PI = 2 * acos(0.0);
using namespace std;

const int MAX = two(20);
char str[MAX];

int GetNumber(int &p)
{
    int x = 0;
    while(isdigit(str[p]))
    {
        x *= 10;
        x += str[p++] - '0';
    }
    p++;
    return x;
}

vector<PII> detach()
{
    vector<PII> rt;
    int p = 0, len = strlen(str);

    while(p < len)
    {
        int d = str[p++] == '-' ? -1 : 1, a = 1;

        if(isdigit(str[p])) a = d * GetNumber(p);
        if(str[p] == 'a') rt.push_back(PII(a, 0));
        else rt.push_back(PII(a, 1));
        p += 3;
    }

    return rt;
}

int cal(PII x, int p)
{
    return x.first * (x.second + p);
}

int main()
{
    memset(str, 0, sizeof(str));
    int a;
    cin >> a >> (str + 1);
    str[0] = '+';
    vector<PII> t = detach();
    for(int i = 0; i < t.size(); i++) t[i].second += a;

    sort(t.begin(), t.end());

    int rt = 0;
    for(int i = 0; i < t.size(); i++) rt += cal(t[i], i);
    cout << rt << endl;
    return 0;
}


#if 01
/*******************************************************************************
* Author       : Aman Taneja
* email        : aman (dot) taneja (dot) 2008 (at) gmail (dot) com
* copyright    : 2014 - 2015
* date         : 22 - 03 - 2015
*
* file name    : A.cpp
* version      : 1.0
*
* TERMS OF USE - Write a mail to the author before copying or reusing the content of this file
* seeking our permission for the same.
* Copying/reuse of the below code without the permission of the author is prohibited and illegal.
*
* All rights reserved by Aman Taneja.
******************************************************************************/

/*******************************************************************************
* some pointers on the logic/idea -
*
* .............
*******************************************************************************/

#pragma once
#ifndef _QL_PRECOMPILATION_BARE_MINIMUM_HPP_
#define _QL_PRECOMPILATION_BARE_MINIMUM_HPP_

// Include file for std::cout, std::cin
#include<iostream>
#include <fstream>

// for itoa - does not work on some compilers(despite including cstdlib)
#include <cstdlib>
// for getch()
#include<stdio.h>

// For clock time and time duration stats
#include <time.h>

#include <map>
#include <vector>
#include <string>
#include <cstring>

#include <set>
#include <algorithm>
#include <utility>
#include <list>
#include <queue>
#include <stack>
#include <limits.h>
#include <iomanip>
#include <math.h>
#include <cmath>
#include <assert.h>
#include <complex>
#include <valarray>
#include <iterator>

using namespace std;

namespace QoE_Library{

    namespace QL_Bare_Minimum{

        const double PI = 3.141592653589793238460;
        const long double E= 2.7182818284590452353;

#define SETZERO(a) memset(a,0,sizeof(a))
#define SETVAL(a,val) memset(a,val,sizeof(a))
#define SETDP(a) memset(a,-1,sizeof(a))

        // check whether indices in range of an array/matrix
#define in_bounds(x, y, r, c) (x < r && y < c && x >= 0 && y >= 0)

        // get min of 3 values
#define min3(a,b,c) (a<min(b,c))?a:min(b,c)

        // convert char into index
#define CHAR_TO_INDEX(c,startC) ((int)c - (int)startC)

        // Array size
#define SZ_ARR(A) sizeof(A)/sizeof(A[0])
        // STL MACROS -
#define SZ(C) C.size()

#define ALL(x) (x).begin(), (x).end()

        //pair
#define MKP(i,j) make_pair(i,j)
        // Map
#define M_Ins(_m_,i,j) _m_.insert(make_pair(i,j))

        // vector
#define PB(A,B) A.push_back(B);

        // STL sort()
#define SORT(A) sort( A.begin(),A.end() )

        // For loop
#define FOR(i, first, last, increment) for (int i = (first); i < (last); i = i + (increment))
#define QL_FOR FOR

#define DEBUGGING 1

        // Default For loop with variable name "i", first = 0, increment = 1
#define FOR_DEF(i, last) QL_FOR(i, 0, last, 1)
#define QL_FOR_DEF FOR_DEF

        // Dont care about the looping variable name
        // TODO : Need to solve the problem of generating a unique temp loop var, for now __i__ suffices
#define REPEAT(N) for (int __i__ = 0; __i__ < (N); ++__i__)

        // Reverse For loop
#define R_FOR(i, first, last, increment) for (int i = ((first) - 1); i >= (last); i = i - (increment))
#define QL_R_FOR R_FOR

        // Default For loop with variable name "i", first = 0, increment = 1
#define R_FOR_DEF(i, first) QL_R_FOR(i, first, 0, 1)
#define QL_R_FOR_DEF R_FOR_DEF

        // For loop for map
#define QL_M_FOR(m,it) for(map<int,int>::iterator it=m.begin();it!=m.end();++it)
#define QL_M_R_FOR(m,rit) for(map<int,int>::reverse_iterator rit=m.rbegin();rit!=m.rend();++rit)

        typedef unsigned long long int ulli_t;
        typedef ulli_t ULLI;
        typedef vector<ulli_t> uivector_t;
        typedef uivector_t::iterator uivector_it_t;
        typedef uivector_t::const_iterator uivector_cit_t;

        typedef long long int lli_t;
        typedef lli_t LLI;
        typedef vector<lli_t> ivector_t;
        typedef ivector_t::iterator ivector_it_t;
        typedef ivector_t::const_iterator ivector_cit_t;

        // pair
        typedef pair<int,int> p_ii_t;
        typedef p_ii_t P_II;
        typedef pair<LLI,LLI> p_llilli_t;
        typedef p_llilli_t P_LLILLI;

        // vector
        typedef vector<int> v_i_t;
        typedef v_i_t V_I;
        typedef vector<LLI> v_lli_t;
        typedef v_lli_t V_LLI;
        typedef vector<ULLI> v_ulli_t;
        typedef v_ulli_t V_ULLI;

        typedef vector<p_ii_t> v_p_ii_t;
        typedef v_p_ii_t V_P_II;

        typedef vector<v_i_t> vv_i_t;
        typedef vv_i_t VV_I;
        typedef vector<v_p_ii_t> vv_p_ii_t;
        typedef vv_p_ii_t VV_P_II;

        typedef vector<string> v_s_t;
        typedef v_s_t V_S;

        //map
        typedef map<int,int> M_II;
        typedef map<int,int>::iterator M_II_IT;

        //queue
        typedef queue<int> q_i_t;
        typedef q_i_t Q_I;

        typedef long double ld_t;
        typedef ld_t LD;

        /*  ------- BEWARE -    macros can't be overloaded i.e. both the 'read's below
        can't have the same name    ---------- */
#define read1(n) cin >> n;
#define read2(m, n) cin >> m >> n;
#define read3(m, n, o) cin >> m >> n >> o;
        // #define readArr(n, size) QL_FOR_DEF(i, size) { cin >> n[i]; }
#define readArr1D(n, size)  QL_FOR_DEF(i, size) \
        {                   \
        cin >> n[i];    \
        }

#define write1(n) cout << n;
#define write2(m, n) cout << m << n;
#define write3(m, n, o) cout << m << n << o;
#define writeArr1D(n, size) QL_FOR_DEF(i, size) \
        {                   \
        cout << n[i];   \
        }

#define DBG(x)              cout<<__LINE__<<" :: "<<#x<< ": "<<x<<endl;
#define DBG2(x, y)          cout<<__LINE__<<" :: "<<#x<< ": "<<x<<" | "<<#y<< ": "<<y<<endl;
#define DBG3(x, y, z)       cout<<__LINE__<<" :: "<<#x<< ": "<<x<<" | "<<#y<< ": "<<y<<" | "<<#z<<": "<<z<<endl;
#define DBG4(a, b, c, d)    cout<<__LINE__<<" :: "<<#a<< ": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;

        // const values
        const long double pi=10000*acos(-1.0L);

        inline void inpS(char *a){
            scanf("%s", a);
        }

        inline int inpLLI(LLI& lld){
            return scanf("%lld", &lld);
        }
        inline int inpULLI(ULLI& ulli){
            return scanf("%llu", &ulli);
        }

        // Fast reading Integer from stdin.
        inline int inpI(/*int &n*/) {
            int n = 0;
            int ch = getchar();
            // int ch = getchar_unlocked();
            int sign = 1;
            while(ch < '0' || ch > '9') {
                if (ch == '-') sign = -1;
                ch = getchar();
                // ch = getchar_unlocked();
            }
            while(ch >= '0' && ch <= '9')
                n = (n<<3) + (n<<1) + ch - '0', ch = getchar();
            // n = (n<<3) + (n<<1) + ch - '0', ch = getchar_unlocked();
            n = n*sign;

            return n;
        }
        inline void inpI2(int &a,int &b){
            a=inpI();
            b=inpI();
        }
        inline void inpI3(int &a,int &b,int &c){
            a=inpI();
            b=inpI();
            c=inpI();
        }

        inline double inpD() {
            double res = 0.0;
            char c;
            while(1) {
                c = getchar();
                // c = getchar_unlocked();
                if(c == ' ' || c == '\n') continue;
                else break;
            }
            res = c - '0';
            while(1) {
                c = getchar();
                // c = getchar_unlocked();
                if(c >= '0' && c <= '9') res = 10 * res + c - '0';
                else break;
            }
            if(c == '.') {
                double decimal = 0.0, divi = 1.0;
                while(1) {
                    c = getchar();
                    // c = getchar_unlocked();
                    if(c >= '0' && c <= '9') decimal += (c - '0') / (divi *= 10.0);
                    else break;
                }
                res += decimal;
            }
            return res;
        }

        inline void outpD(double N) {
            char buff[24],sz=0;
            int integer = N;
            int decimal = (N - integer) * 10000000;
            int tmp = decimal;

            while(decimal) {
                buff[sz++] = '0' + decimal % 10;
                decimal /= 10;
            }
            for(int decimal2 = 1000000; decimal2 > tmp; decimal2 /= 10) {
                buff[sz++] = '0';
            }
            buff[sz++] = '.';
            if(integer == 0) buff[sz++] = '0';
            while(integer) {
                buff[sz++] = '0' + integer % 10;
                integer /= 10;
            }
            while(--sz>=0)
                putchar(buff[sz]);
            // putchar_unlocked(buff[sz]);
            putchar(10);
            // putchar_unlocked(10);
        }
        inline int outpULLI(ULLI u){
            return printf("%llu\n",u);
        }
        inline int outpLLI(LLI lli){
            return printf("%lld\n",lli);
        }
        inline void outpI(int a) {
            char c;
            char snum[20];
            int i=0;
            int sign = 0;
            if(a < 0) sign = 1;
            a = abs(a);
            do {
                snum[i++]=a%10+48;
                a=a/10;
            } while(a!=0);
            i=i-1;
            if(sign)
                putchar('-');
            // putchar_unlocked('-');

            while(i>=0)
                putchar(snum[i--]);
            // putchar_unlocked(snum[i--]);
            putchar('\n');
            // putchar_unlocked('\n');
        }
        inline void outpI2(int a,int b){
            printf("%d ",a);
            outpI(b);
        }
        inline int outpS(char *s){
            return printf("%s\n",s);
        }
        /*  // Giving 'function defined twice' error while running Graph.cpp Code
        void reorderLLI(LLI &x, LLI& y){
        LLI xCopy, yCopy;
        if (x < y){
        y = xCopy;
        x = yCopy;
        }
        }

        void reorderI(int &x, int& y){
        int xCopy, yCopy;
        if (x < y){
        y = xCopy;
        x = yCopy;
        }
        }
        */
        template<typename T1> void QL_swap(T1 &x, T1 &y){
            /*  Below code is risky
            x = x+y;
            y = x-y;
            x = x-y;
            */
            T1 tmp;
            tmp=x;
            x=y;
            y=tmp;
        }

        // commented while using Graph class.
#if 0
        void QL_swapChars(char *a,char *b){
            char tmp=*a;
            *a=*b;
            *b=tmp;
        }
#endif

        /*  Note - Lesson Learnt - return type should also be promoted while overloading the operator,
        otherwise buggy code.
        Also, if a & b have return type ULLI and LLI, we'll get ambiguity error. Both types
        should be unsigned in order to make it unambiguous.
        As if int is promoted to ULLI, both would be promoted or both would not be.
        */
        /*  NOTE - gcd{a,b} = gcd{|a|, b} = gcd{a,|b|} = gcd{|a|, |b|}
        And gcd(a,0) = a.
        */
        template<typename T1> T1 gcd(T1 a, T1 b) {
            if (!b)
                return a;
            else
                return gcd(b, a%b);
        }
        LD euclideanDist(int x1,int y1,int x2,int y2){

            return sqrt( (x1-x2)*(x1-x2)/1. + (y1-y2)*(y1-y2)/1. );
        }
    }
}
#endif  // _QL_PRECOMPILATION_BARE_MINIMUM_HPP_

using namespace QoE_Library::QL_Bare_Minimum;

#define PRINT_TIME 0
#define GEN_TEST_CASES 0

bool revCmp(int a, int b){
    return a > b;
}

/*  Test cases -
input-

// this test case is a gift of RANDOM test cases generation. It helped in finding the bug.
6
82 28 62 92 96 43
correct answer-> 3 4
wrong answer-> 2 4

output-
*/
#if 01
int main(){
#if PRINT_TIME
    clock_t t = clock();
#endif
#if 0
    FILE *fIn = freopen("D:\\DUMP\\input.in", "r", stdin);
    FILE *fOut = freopen("D:\\DUMP\\output.out", "w", stdout);
    //FILE *fIn = freopen("input.txt", "r", stdin);
    //FILE *fOut = freopen("output.txt", "w", stdout);
    assert(fIn&&fOut);
#endif
    int a;
    string s;
    cin>>a>>s;

    /*  Let us parse the string of syntax -> sign[coeff*](++a) or sign[coeff*](a++).
        To make the string aligned with the syntax, add a '+' the beginning, if '-'
        is not already there.
    */
    if(s[0]!='-')s='+'+s;
    /*  Skip 3 places after reaching '++a' or 'a++'
    */
    int coeff[1001]={0},c=0,tot=0;
    QL_FOR(i,0,SZ(s),3){
        int sign=s[i]=='+'?1:-1;
        ++i;
        while(isdigit(s[i]))
            coeff[c]=coeff[c]*10+s[i++]-'0';
        if('*'==s[i])++i;
        else coeff[c]=1;
        /*  If pre-increment, then add coeff*(a-1), else don't add(in case of post-increment)
        */
        coeff[c]*=sign;
        tot+=(a-(s[i]=='a'))*coeff[c++];
    }
    sort(coeff,coeff+c);
    QL_FOR_DEF(i,c){
        tot+=(i+1)*coeff[i];
    }
    cout<<tot;

#if PRINT_TIME
    t = clock() - t;
    // printf("time = %Ld", (double)t/CLOCKS_PER_SEC);
    cout << "time = " << (double)t/CLOCKS_PER_SEC;
#endif
}
#endif
#endif


#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <cstring>

using namespace std;

const int maxN = 2000;
char s[100000];

struct Sum{
	int kf, inc;
	Sum(): kf(0), inc(-1){}
	Sum(int _kf, int _inc): kf(_kf), inc(_inc){}

	bool operator<(const Sum & other)
	{
		return kf < other.kf;
	}
};

Sum ar[maxN];
int uk = 0, l, num;

bool scan(int v)
{
	int kf, inc = -1;
	bool pos = true;
	num = 0;
	if (s[uk] == '-')
	{
		pos = false;
		uk++;
	}
	else
	{
		if (v > 0)
		{
			uk++;
		}
	}
	while (isdigit(s[uk]))
	{
		num = num * 10 + (s[uk] - '0');
		uk++;
	}
	if (s[uk] == 'a' || s[uk] == '+')
	{
		num = 1;
		uk--;
	}
	uk++;
	kf = num;
	if (!pos)
	{
		kf *= -1;
	}
	if (s[uk] == '+')
	{
		inc = 1;
	}
	if (s[uk] == 'a')
	{
		inc = 0;
	}
	uk += 3;
	ar[v] = Sum(kf, inc);
	return uk >= l ? false : true;
}

int len = 0, a;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	scanf("%d\n", &a);
	scanf("%s", &s);
	l = strlen(s);
	while (scan(len++));
	sort(ar, ar + len);
	int sum = 0;
	for (int i = 0; i < len; i++)
	{
		if (ar[i].inc == 0)
		{
			sum += a * ar[i].kf;
			a++;
		}
		else
		{
			sum += (a + 1) * ar[i].kf;
			a++;
		}
	}
	printf("%d", sum);
	return 0;
}


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

#define false 0
#define true  1

vector<pair<int, bool> > ps;
string s;
int a, coef, sign;
bool post;

bool IsDig(char c) {
    return (c>='0' && c<= '9');
}

int StrToInt(string s) {
    int res;
    sscanf(s.c_str(), "%d", &res);
    return res;
}

bool operator < (pair<int, bool> p1, pair<int, bool> p2) {
    return (p1.first < p2.first || p1.first == p2.first && (p1.first<0 && p1.second));
}

int main () {
    scanf("%d", &a);
    cin>>s;
    s = '+' + s;
    int i = 0, j;
    while(i<s.length()) {
        if(s[i] == '+')
            sign = 1;
        else
            sign = -1;
        i++;
        if(IsDig(s[i])) {
            j = i;
            while(IsDig(s[j++]));
            coef = StrToInt(s.substr(i, j-i));
            i = j;
        }
        else
            coef = 1;
        post = !(s[i] == '+');
        i += 3;
        coef *= sign;
        ps.push_back(make_pair(coef, post));
    }
    sort(ps.begin(), ps.end());
    int sum = 0;
    for(int i = 0; i<ps.size(); i++) {
        sum += ps[i].first * (ps[i].second ? a++ : ++a);
    }
    cout<<sum;
    return 0;
}


#include <cmath>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
struct ex{
    int koef;
    bool first_inc;
    bool last_inc;
    bool symbol_sum;
    ex (){
        first_inc = false;
        last_inc = false;
        koef = 1;
        symbol_sum = true;
    }
    ex (int k, bool f, bool s){
        koef = k;
        first_inc = f;
        symbol_sum = s;
    }
};
string s;
vector<ex> v;
int a;
string convertInt(int number)
{
   stringstream ss;//create a stringstream
   ss << number;//add number to the stream
   return ss.str();//return a string with the contents of the stream
}
bool pred(ex& v1, ex& v2){
    if (v1.symbol_sum && v2.symbol_sum){
        if (v1.first_inc == true && v2.first_inc == true)
            return (v1.koef > v2.koef);
        if (v1.first_inc == true && v2.first_inc == false)
            return true;
        if (v1.first_inc == false && v2.first_inc == true)
            return false;
        if (v1.first_inc == false && v2.first_inc == false)
            return (v1.koef > v2.koef);
    } else if (v1.symbol_sum && !v2.symbol_sum){
        return true;
    } else if (!v1.symbol_sum && v2.symbol_sum){
        return false;
    } else if (!v1.symbol_sum && !v2.symbol_sum){
        if (v1.first_inc == true && v2.first_inc == true)
            return (v1.koef < v2.koef);
        if (v1.first_inc == true && v2.first_inc == false)
            return false;
        if (v1.first_inc == false && v2.first_inc == true)
            return true;
        if (v1.first_inc == false && v2.first_inc == false)
            return (v1.koef < v2.koef);
    }

}
int main(){
    int found;
       //freopen("input.txt","r",stdin);
       //freopen("output.txt","w",stdout);
       cin >> a;
       cin >> s;
       found=s.find('a');

       while(found!=string::npos){
           ex temp = ex();
           int left = 0, right = found + 1;
           //cout << int(found) << "  a = " << a << endl;
           if (found > 1) {
                if(s.at(found-1) == '+' && s.at(found - 2) == '+'){
                    temp.first_inc = true;
                    left = found - 2;
                }
           }
           if (s.length() - found > 2 && !temp.first_inc)
                    if(s.at(found + 1) == '+' && s.at(found + 2) == '+'){
                        temp.last_inc = true;
                        right = found + 2;

                //cout << s <<endl;
           }
           int pos = (temp.first_inc ? found-3 : found - 1);
           int pos_end = (temp.last_inc ? found+3 : found + 1);

           int last;
           if (s.find("*",pos) != -1) {
               int last_s = s.find_last_of("+",pos - 1);
               int last_m = s.find_last_of("-",pos - 1);

               if (last_m != -1) temp.symbol_sum = false;

               last = max(last_s, last_m);
               left = last + 1;
               temp.koef = atoi(s.substr(last + 1, found -last - 1).c_str());
           } else if (s.find("*",pos_end,1) != -1){
               int last_s = s.find_first_of("+",pos_end + 1);
               int last_m = s.find_first_of("-",pos_end + 1);
               last = min(last_s, last_m);
               right = last + 1;
               temp.koef = atoi(s.substr(found + 1, last - found - 1).c_str());
           }
           v.push_back(temp);

           s.replace(0, right - left + 1, "");
           found = s.find('a');
       }
       sort(v.begin(), v.end(), pred);
       int summ = 0;
       int k = 1;
       for (int i = v.size() - 1; i>= 0 ; i--){
           if (v.at(i).first_inc ) ++a;
           if (!v.at(i).symbol_sum)k = -1;
           else k =1;
            summ += v.at(i).koef * a * k;
           if (v.at(i).last_inc) a++;
       }

    cout << summ;
}


#include <cmath>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
struct ex{
	int koef;
	bool first_inc;
	bool last_inc;
	bool symbol_sum;
	ex (){
		first_inc = false;
		last_inc = false;
		koef = 1;
		symbol_sum = true;
	}
	ex (int k, bool f, bool s){
		koef = k;
		first_inc = f;
		symbol_sum = s;
	}
};
string s;
vector<ex> v;
int a;
string convertInt(int number)
{
   stringstream ss;//create a stringstream
   ss << number;//add number to the stream
   return ss.str();//return a string with the contents of the stream
}
bool pred(ex& v1, ex& v2){
	int k1 = (v1.symbol_sum ? 1 : -1);
	int k2 = (v2.symbol_sum ? 1 : -1);
	return (v1.koef * k1 > v2.koef * k2);
	/*if (v1.symbol_sum && v2.symbol_sum){
		return (v1.koef > v2.koef);
	} else if (v1.symbol_sum && !v2.symbol_sum){
		return true;
	} else if (!v1.symbol_sum && v2.symbol_sum){
		return false;
	} else if (!v1.symbol_sum && !v2.symbol_sum){
		return (v1.koef < v2.koef);
	}*/

}
int main(){
	int found;
	   //freopen("input.txt","r",stdin);
	   //freopen("output.txt","w",stdout);
	   cin >> a;
	   cin >> s;
	   found=s.find('a');

	   while(found!=string::npos){
		   ex temp = ex();
		   int left = 0, right = found + 1;
		   //cout << int(found) << "  a = " << a << endl;
		   if (found > 1) {
				if(s.at(found-1) == '+' && s.at(found - 2) == '+'){
					temp.first_inc = true;
					left = found - 2;
				}
		   }
		   if (s.length() - found > 2 && !temp.first_inc)
					if(s.at(found + 1) == '+' && s.at(found + 2) == '+'){
						temp.last_inc = true;
						right = found + 3;

				//cout << s <<endl;
		   }
		   int pos = (temp.first_inc ? found-3 : found - 1);
		   //int pos_end = (temp.last_inc ? found+3 : found + 1);

		   int last;
		   int last_s = s.find_last_of("+",pos);
		   int last_m = s.find_last_of("-",pos);
		   last = max(last_s, last_m);

		   if (last_m != -1) {
			   temp.symbol_sum = false;
		   }
		  // if (s.find(("*",pos,1) != -1) {
		   if (pos > -1 && s[pos] == '*'){// (("*",pos,1) != -1) {
			   left = last + 1;
			   temp.koef = atoi(s.substr(last + 1, found -last - 1).c_str());
		   } /*else if (pos_end < s.length() && s.at(pos_end) == '*'){//.find("*",pos_end,1) != -1){
			   int last_s = s.find_first_of("+",pos_end + 1);
			   int last_m = s.find_first_of("-",pos_end + 1);
			   if (last_s == -1) last_s = s.length();
			   if (last_m == -1) last_m = s.length();
			   last = min(last_s, last_m);

			   right = last;
			   int g = (temp.last_inc ? found + 4 : found + 2);
			   temp.koef = atoi(s.substr(g, last - g).c_str());
		   }*/
		   v.push_back(temp);

		   s.replace(0, right, "");
		   found = s.find('a');
	   }
	   sort(v.begin(), v.end(), pred);
	   int summ = 0;
	   int k;
	   /*for (int i = 0; i < v.size() && a < 0; i++){
		   if (v.at(i).first_inc ) ++a;
		   if (!v.at(i).symbol_sum)k = -1;
		   else k =1;
		   summ += v.at(i).koef * a * k;
		   if (v.at(i).last_inc) a++;
		   x++;
	   }*/
	   for (int i = v.size() - 1; i>= 0; i--){
		   if (v.at(i).first_inc ) ++a;
		   if (!v.at(i).symbol_sum)k = -1;
		   else k = 1;
		   summ += v.at(i).koef * a * k;
		   //cout << (v.at(i).symbol_sum ? "+" : "-") << v.at(i).koef << endl;
		   if (v.at(i).last_inc) a++;
	   }

	cout << summ;
}


#include <cmath>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
struct ex{
    int koef;
    bool first_inc;
    bool last_inc;
    bool symbol_sum;
    ex (){
        first_inc = false;
        last_inc = false;
        koef = 1;
        symbol_sum = true;
    }
    ex (int k, bool f, bool s){
        koef = k;
        first_inc = f;
        symbol_sum = s;
    }
};
string s;
vector<ex> v;
int a;
string convertInt(int number)
{
   stringstream ss;//create a stringstream
   ss << number;//add number to the stream
   return ss.str();//return a string with the contents of the stream
}
bool pred(ex& v1, ex& v2){
    if (v1.symbol_sum && v2.symbol_sum){
        if (v1.first_inc == true && v2.first_inc == true)
            return (v1.koef > v2.koef);
        if (v1.first_inc == true && v2.first_inc == false)
            return true;
        if (v1.first_inc == false && v2.first_inc == true)
            return false;
        if (v1.first_inc == false && v2.first_inc == false)
            return (v1.koef > v2.koef);
    } else if (v1.symbol_sum && !v2.symbol_sum){
        return true;
    } else if (!v1.symbol_sum && v2.symbol_sum){
        return false;
    } else if (!v1.symbol_sum && !v2.symbol_sum){
        if (v1.first_inc == true && v2.first_inc == true)
            return (v1.koef < v2.koef);
        if (v1.first_inc == true && v2.first_inc == false)
            return false;
        if (v1.first_inc == false && v2.first_inc == true)
            return true;
        if (v1.first_inc == false && v2.first_inc == false)
            return (v1.koef < v2.koef);
    }

}
int main(){
    int found;
       //freopen("input.txt","r",stdin);
       //freopen("output.txt","w",stdout);
       cin >> a;
       cin >> s;
       found=s.find('a');

       while(found!=string::npos){
           ex temp = ex();
           int left = 0, right = found + 1;
           cout << int(found) << "  a = " << a << endl;
           if (found > 1) {
                if(s.at(found-1) == '+' && s.at(found - 2) == '+'){
                    temp.first_inc = true;
                    left = found - 2;
                }
           }
           if (s.length() - found > 2 && !temp.first_inc)
                    if(s.at(found + 1) == '+' && s.at(found + 2) == '+'){
                        temp.last_inc = true;
                        right = found + 2;

                cout << s <<endl;
           }
           int pos = (temp.first_inc ? found-3 : found - 1);
           int pos_end = (temp.last_inc ? found+3 : found + 1);

           int last;
           if (s.find("*",pos) != -1) {
               int last_s = s.find_last_of("+",pos - 1);
               int last_m = s.find_last_of("-",pos - 1);

               if (last_m != -1) temp.symbol_sum = false;

               last = max(last_s, last_m);
               left = last + 1;
               temp.koef = atoi(s.substr(last + 1, found -last - 1).c_str());
           } else if (s.find("*",pos_end,1) != -1){
               int last_s = s.find_first_of("+",pos_end + 1);
               int last_m = s.find_first_of("-",pos_end + 1);
               last = min(last_s, last_m);
               right = last + 1;
               temp.koef = atoi(s.substr(found + 1, last - found - 1).c_str());
           }
           v.push_back(temp);

           s.replace(0, right - left + 1, "");
           found = s.find('a');
       }
       sort(v.begin(), v.end(), pred);
       int summ = 0;
       int k = 1;
       for (int i = v.size() - 1; i>= 0 ; i--){
           if (v.at(i).first_inc ) ++a;
           if (!v.at(i).symbol_sum)k = -1;
           else k =1;
            summ += v.at(i).koef * a * k;
           if (v.at(i).last_inc) a++;
       }

    cout << summ;
}


#include <cmath>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
struct ex{
    int koef;
    bool first_inc;
    bool last_inc;
    bool symbol_sum;
    ex (){
        first_inc = false;
        last_inc = false;
        koef = 1;
        symbol_sum = true;
    }
    ex (int k, bool f, bool s){
        koef = k;
        first_inc = f;
        symbol_sum = s;
    }
};
string s;
vector<ex> v;
int a;
string convertInt(int number)
{
   stringstream ss;//create a stringstream
   ss << number;//add number to the stream
   return ss.str();//return a string with the contents of the stream
}
bool pred(ex& v1, ex& v2){
    if (v1.symbol_sum && v2.symbol_sum){
        return (v1.koef > v2.koef);
        /*if (v1.first_inc == true && v2.first_inc == true)
            return (v1.koef > v2.koef);
        if (v1.first_inc == true && v2.first_inc == false)
            return (v1.koef > v2.koef);
        if (v1.first_inc == false && v2.first_inc == true)
            return (v1.koef > v2.koef);
        if (v1.first_inc == false && v2.first_inc == false)
            return (v1.koef > v2.koef);*/
    } else if (v1.symbol_sum && !v2.symbol_sum){
        return true;
    } else if (!v1.symbol_sum && v2.symbol_sum){
        return false;
    } else if (!v1.symbol_sum && !v2.symbol_sum){
        return (v1.koef < v2.koef);
        /*if (v1.first_inc == true && v2.first_inc == true)
            return (v1.koef < v2.koef);
        if (v1.first_inc == true && v2.first_inc == false)
            return (v1.koef < v2.koef);
        if (v1.first_inc == false && v2.first_inc == true)
            return (v1.koef < v2.koef);
        if (v1.first_inc == false && v2.first_inc == false)
            return (v1.koef < v2.koef);*/
    }

}
int main(){
    int found;
       freopen("input.txt","r",stdin);
       freopen("output.txt","w",stdout);
       cin >> a;
       cin >> s;
       found=s.find('a');

       while(found!=string::npos){
           ex temp = ex();
           int left = 0, right = found + 1;
           //cout << int(found) << "  a = " << a << endl;
           if (found > 1) {
                if(s.at(found-1) == '+' && s.at(found - 2) == '+'){
                    temp.first_inc = true;
                    left = found - 2;
                }
           }
           if (s.length() - found > 2 && !temp.first_inc)
                    if(s.at(found + 1) == '+' && s.at(found + 2) == '+'){
                        temp.last_inc = true;
                        right = found + 3;

                //cout << s <<endl;
           }
           int pos = (temp.first_inc ? found-3 : found - 1);
           int pos_end = (temp.last_inc ? found+3 : found + 1);

           int last;
           int last_s = s.find_last_of("+",pos - 1);
           int last_m = s.find_last_of("-",pos - 1);

           if (last_m != -1) {
               temp.symbol_sum = false;
           }
           if (s.find("*",pos) != -1) {

               last = max(last_s, last_m);
               left = last + 1;
               temp.koef = atoi(s.substr(last + 1, found -last - 1).c_str());
           } else if (s.find("*",pos_end,1) != -1){
               int last_s = s.find_first_of("+",pos_end + 1);
               int last_m = s.find_first_of("-",pos_end + 1);
               last = min(last_s, last_m);
               right = last + 1;
               temp.koef = atoi(s.substr(found + 1, last - found - 1).c_str());
           }
           v.push_back(temp);

           s.replace(0, right, "");
           found = s.find('a');
       }
       sort(v.begin(), v.end(), pred);
       int summ = 0;
       int k = 1;
       for (int i = v.size() - 1; i>= 0 ; i--){
           if (v.at(i).first_inc ) ++a;
           if (!v.at(i).symbol_sum)k = -1;
           else k =1;
            summ += v.at(i).koef * a * k;
           if (v.at(i).last_inc) a++;
       }

    cout << summ;
}


#include <cmath>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
struct ex{
	int koef;
	bool first_inc;
	bool last_inc;
	bool symbol_sum;
	ex (){
		first_inc = false;
		last_inc = false;
		koef = 1;
		symbol_sum = true;
	}
	ex (int k, bool f, bool s){
		koef = k;
		first_inc = f;
		symbol_sum = s;
	}
};
string s;
vector<ex> v;
int a;
string convertInt(int number)
{
   stringstream ss;//create a stringstream
   ss << number;//add number to the stream
   return ss.str();//return a string with the contents of the stream
}
bool pred(ex& v1, ex& v2){
	if (v1.symbol_sum && v2.symbol_sum){
		return (v1.koef > v2.koef);
		/*if (v1.first_inc == true && v2.first_inc == true)
			return (v1.koef > v2.koef);
		if (v1.first_inc == true && v2.first_inc == false)
			return (v1.koef > v2.koef);
		if (v1.first_inc == false && v2.first_inc == true)
			return (v1.koef > v2.koef);
		if (v1.first_inc == false && v2.first_inc == false)
			return (v1.koef > v2.koef);*/
	} else if (v1.symbol_sum && !v2.symbol_sum){
		return true;
	} else if (!v1.symbol_sum && v2.symbol_sum){
		return false;
	} else if (!v1.symbol_sum && !v2.symbol_sum){
		return (v1.koef < v2.koef);
		/*if (v1.first_inc == true && v2.first_inc == true)
			return (v1.koef < v2.koef);
		if (v1.first_inc == true && v2.first_inc == false)
			return (v1.koef < v2.koef);
		if (v1.first_inc == false && v2.first_inc == true)
			return (v1.koef < v2.koef);
		if (v1.first_inc == false && v2.first_inc == false)
			return (v1.koef < v2.koef);*/
	}

}
int main(){
	int found;
	   //freopen("input.txt","r",stdin);
	   //freopen("output.txt","w",stdout);
	   cin >> a;
	   cin >> s;
	   found=s.find('a');

	   while(found!=string::npos){
		   ex temp = ex();
		   int left = 0, right = found + 1;
		   //cout << int(found) << "  a = " << a << endl;
		   if (found > 1) {
				if(s.at(found-1) == '+' && s.at(found - 2) == '+'){
					temp.first_inc = true;
					left = found - 2;
				}
		   }
		   if (s.length() - found > 2 && !temp.first_inc)
					if(s.at(found + 1) == '+' && s.at(found + 2) == '+'){
						temp.last_inc = true;
						right = found + 3;

				//cout << s <<endl;
		   }
		   int pos = (temp.first_inc ? found-3 : found - 1);
		   int pos_end = (temp.last_inc ? found+3 : found + 1);

		   int last;
		   int last_s = s.find_last_of("+",pos - 1);
		   int last_m = s.find_last_of("-",pos - 1);
		   last = max(last_s, last_m);

		   if (last_m != -1) {
			   temp.symbol_sum = false;
		   }
		  // if (s.find(("*",pos,1) != -1) {
		   if (pos > -1 && s[pos] == '*'){// (("*",pos,1) != -1) {

			   left = last + 1;
			   temp.koef = atoi(s.substr(last + 1, found -last - 1).c_str());
		   } else if (pos_end < s.length() && s.at(pos_end) == '*'){//.find("*",pos_end,1) != -1){
			   int last_s = s.find_first_of("+",pos_end + 1);
			   int last_m = s.find_first_of("-",pos_end + 1);
			   if (last_s == -1) last_s = s.length();
			   if (last_m == -1) last_m = s.length();
			   last = min(last_s, last_m);

			   right = last;
			   int g = (temp.last_inc ? found + 4 : found + 2);
			   temp.koef = atoi(s.substr(g, last - g).c_str());
		   }
		   v.push_back(temp);

		   s.replace(0, right, "");
		   found = s.find('a');
	   }
	   sort(v.begin(), v.end(), pred);
	   int summ = 0;
	   int k = 1;
	   for (int i = v.size() - 1; i>= 0 ; i--){
		   if (v.at(i).first_inc ) ++a;
		   if (!v.at(i).symbol_sum)k = -1;
		   else k =1;
		   //cout << "koef " << (v.at(i).symbol_sum ? "+" : "-")<< v.at(i).koef << endl;
			summ += v.at(i).koef * a * k;
		   if (v.at(i).last_inc) a++;
	   }

	cout << summ;
}


#include <cmath>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
struct ex{
	int koef;
	bool first_inc;
	bool last_inc;
	bool symbol_sum;
	ex (){
		first_inc = false;
		last_inc = false;
		koef = 1;
		symbol_sum = true;
	}
	ex (int k, bool f, bool s){
		koef = k;
		first_inc = f;
		symbol_sum = s;
	}
};
string s;
vector<ex> v;
int a;
string convertInt(int number)
{
   stringstream ss;//create a stringstream
   ss << number;//add number to the stream
   return ss.str();//return a string with the contents of the stream
}
bool pred(ex& v1, ex& v2){
	int k1 = (v1.symbol_sum ? 1 : -1);
	int k2 = (v2.symbol_sum ? 1 : -1);
	return (v1.koef * k1 > v2.koef * k2);
	/*if (v1.symbol_sum && v2.symbol_sum){
		return (v1.koef > v2.koef);
	} else if (v1.symbol_sum && !v2.symbol_sum){
		return true;
	} else if (!v1.symbol_sum && v2.symbol_sum){
		return false;
	} else if (!v1.symbol_sum && !v2.symbol_sum){
		return (v1.koef < v2.koef);
	}*/

}
int main(){
	int found;
	   //freopen("input.txt","r",stdin);
	   //freopen("output.txt","w",stdout);
	   cin >> a;
	   cin >> s;
	   found=s.find('a');

	   while(found!=string::npos){
		   ex temp = ex();
		   int left = 0, right = found + 1;
		   if (found > 1) {
				if(s.at(found-1) == '+' && s.at(found - 2) == '+'){
					temp.first_inc = true;
					left = found - 2;
				}
		   }
		   if (s.length() - found > 2 && !temp.first_inc)
					if(s.at(found + 1) == '+' && s.at(found + 2) == '+'){
						temp.last_inc = true;
						right = found + 3;
		   }
		   int pos = (temp.first_inc ? found-3 : found - 1);

		   int last;
		   if (pos > -1){
			   int last_s = s.find_last_of("+",pos);
			   int last_m = s.find_last_of("-",pos);
			   last = max(last_s, last_m);
			   if (last_m != -1) temp.symbol_sum = false;
			   if (s[pos] == '*'){
				   left = last + 1;
				   temp.koef = atoi(s.substr(last + 1, found -last - 1).c_str());
			   }

		   }
		   v.push_back(temp);

		   s.replace(0, right, "");
		   found = s.find('a');
	   }
	   sort(v.begin(), v.end(), pred);
	   int summ = 0;
	   int k;
	   for (int i = v.size() - 1; i>= 0; i--){
		   if (v.at(i).first_inc ) ++a;
		   if (!v.at(i).symbol_sum)k = -1;
		   else k = 1;
		   summ += v.at(i).koef * a * k;
		   //cout << (v.at(i).symbol_sum ? "+" : "-") << v.at(i).koef << endl;
		   if (v.at(i).last_inc) a++;
	   }

	cout << summ;
}


#include <cmath>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
struct ex{
    int koef;
    bool first_inc;
    bool last_inc;
    bool symbol_sum;
    ex (){
        first_inc = false;
        last_inc = false;
        koef = 1;
        symbol_sum = true;
    }
    ex (int k, bool f, bool s){
        koef = k;
        first_inc = f;
        symbol_sum = s;
    }
};
string s;
vector<ex> v;
int a;
string convertInt(int number)
{
   stringstream ss;//create a stringstream
   ss << number;//add number to the stream
   return ss.str();//return a string with the contents of the stream
}
bool pred(ex& v1, ex& v2){
    if (v1.symbol_sum && v2.symbol_sum){
        return (v1.koef > v2.koef);
        /*if (v1.first_inc == true && v2.first_inc == true)
            return (v1.koef > v2.koef);
        if (v1.first_inc == true && v2.first_inc == false)
            return (v1.koef > v2.koef);
        if (v1.first_inc == false && v2.first_inc == true)
            return (v1.koef > v2.koef);
        if (v1.first_inc == false && v2.first_inc == false)
            return (v1.koef > v2.koef);*/
    } else if (v1.symbol_sum && !v2.symbol_sum){
        return true;
    } else if (!v1.symbol_sum && v2.symbol_sum){
        return false;
    } else if (!v1.symbol_sum && !v2.symbol_sum){
        return (v1.koef < v2.koef);
        /*if (v1.first_inc == true && v2.first_inc == true)
            return (v1.koef < v2.koef);
        if (v1.first_inc == true && v2.first_inc == false)
            return (v1.koef < v2.koef);
        if (v1.first_inc == false && v2.first_inc == true)
            return (v1.koef < v2.koef);
        if (v1.first_inc == false && v2.first_inc == false)
            return (v1.koef < v2.koef);*/
    }

}
int main(){
    int found;
       //freopen("input.txt","r",stdin);
       //freopen("output.txt","w",stdout);
       cin >> a;
       cin >> s;
       found=s.find('a');

       while(found!=string::npos){
           ex temp = ex();
           int left = 0, right = found + 1;
           //cout << int(found) << "  a = " << a << endl;
           if (found > 1) {
                if(s.at(found-1) == '+' && s.at(found - 2) == '+'){
                    temp.first_inc = true;
                    left = found - 2;
                }
           }
           if (s.length() - found > 2 && !temp.first_inc)
                    if(s.at(found + 1) == '+' && s.at(found + 2) == '+'){
                        temp.last_inc = true;
                        right = found + 3;

                //cout << s <<endl;
           }
           int pos = (temp.first_inc ? found-3 : found - 1);
           int pos_end = (temp.last_inc ? found+3 : found + 1);

           int last;
           int last_s = s.find_last_of("+",pos - 1);
           int last_m = s.find_last_of("-",pos - 1);

           if (last_m != -1) {
               temp.symbol_sum = false;
           }
           if (s.find("*",pos) != -1) {

               last = max(last_s, last_m);
               left = last + 1;
               temp.koef = atoi(s.substr(last + 1, found -last - 1).c_str());
           } else if (s.find("*",pos_end,1) != -1){
               int last_s = s.find_first_of("+",pos_end + 1);
               int last_m = s.find_first_of("-",pos_end + 1);
               last = min(last_s, last_m);
               right = last + 1;
               temp.koef = atoi(s.substr(found + 1, last - found - 1).c_str());
           }
           v.push_back(temp);

           s.replace(0, right, "");
           found = s.find('a');
       }
       sort(v.begin(), v.end(), pred);
       int summ = 0;
       int k = 1;
       for (int i = v.size() - 1; i>= 0 ; i--){
           if (v.at(i).first_inc ) ++a;
           if (!v.at(i).symbol_sum)k = -1;
           else k =1;
            summ += v.at(i).koef * a * k;
           if (v.at(i).last_inc) a++;
       }

    cout << summ;
}


#include <cmath>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
struct ex{
    int koef;
    bool first_inc;
    bool last_inc;
    bool symbol_sum;
    ex (){
        first_inc = false;
        last_inc = false;
        koef = 1;
        symbol_sum = true;
    }
    ex (int k, bool f, bool s){
        koef = k;
        first_inc = f;
        symbol_sum = s;
    }
};
string s;
vector<ex> v;
int a;
string convertInt(int number)
{
   stringstream ss;//create a stringstream
   ss << number;//add number to the stream
   return ss.str();//return a string with the contents of the stream
}
bool pred(ex& v1, ex& v2){
    if (v1.symbol_sum && v2.symbol_sum){
        return (v1.koef > v2.koef);
        /*if (v1.first_inc == true && v2.first_inc == true)
            return (v1.koef > v2.koef);
        if (v1.first_inc == true && v2.first_inc == false)
            return (v1.koef > v2.koef);
        if (v1.first_inc == false && v2.first_inc == true)
            return (v1.koef > v2.koef);
        if (v1.first_inc == false && v2.first_inc == false)
            return (v1.koef > v2.koef);*/
    } else if (v1.symbol_sum && !v2.symbol_sum){
        return true;
    } else if (!v1.symbol_sum && v2.symbol_sum){
        return false;
    } else if (!v1.symbol_sum && !v2.symbol_sum){
        return (v1.koef < v2.koef);
        /*if (v1.first_inc == true && v2.first_inc == true)
            return (v1.koef < v2.koef);
        if (v1.first_inc == true && v2.first_inc == false)
            return (v1.koef < v2.koef);
        if (v1.first_inc == false && v2.first_inc == true)
            return (v1.koef < v2.koef);
        if (v1.first_inc == false && v2.first_inc == false)
            return (v1.koef < v2.koef);*/
    }

}
int main(){
    int found;
       //freopen("input.txt","r",stdin);
       //freopen("output.txt","w",stdout);
       cin >> a;
       cin >> s;
       found=s.find('a');

       while(found!=string::npos){
           ex temp = ex();
           int left = 0, right = found + 1;
           //cout << int(found) << "  a = " << a << endl;
           if (found > 1) {
                if(s.at(found-1) == '+' && s.at(found - 2) == '+'){
                    temp.first_inc = true;
                    left = found - 2;
                }
           }
           if (s.length() - found > 2 && !temp.first_inc)
                    if(s.at(found + 1) == '+' && s.at(found + 2) == '+'){
                        temp.last_inc = true;
                        right = found + 3;

                //cout << s <<endl;
           }
           int pos = (temp.first_inc ? found-3 : found - 1);
           int pos_end = (temp.last_inc ? found+3 : found + 1);

           int last;
           int last_s = s.find_last_of("+",pos - 1);
           int last_m = s.find_last_of("-",pos - 1);
           last = max(last_s, last_m);

           if (last_m != -1) {
               temp.symbol_sum = false;
           }
          // if (s.find(("*",pos,1) != -1) {
           if (pos > -1 && s[pos] == '*'){// (("*",pos,1) != -1) {

               left = last + 1;
               temp.koef = atoi(s.substr(last + 1, found -last - 1).c_str());
           } else if (s.at(pos_end) == '*'){//.find("*",pos_end,1) != -1){
               int last_s = s.find_first_of("+",pos_end + 1);
               int last_m = s.find_first_of("-",pos_end + 1);
               if (last_s == -1) last_s = s.length();
               if (last_m == -1) last_m = s.length();
               last = min(last_s, last_m);

               right = last;
               int g = (temp.last_inc ? found + 4 : found + 2);
               temp.koef = atoi(s.substr(g, last - g).c_str());
           }
           v.push_back(temp);

           s.replace(0, right, "");
           found = s.find('a');
       }
       sort(v.begin(), v.end(), pred);
       int summ = 0;
       int k = 1;
       for (int i = v.size() - 1; i>= 0 ; i--){
           if (v.at(i).first_inc ) ++a;
           if (!v.at(i).symbol_sum)k = -1;
           else k =1;
           cout << "koef " << (v.at(i).symbol_sum ? "+" : "-")<< v.at(i).koef << endl;
            summ += v.at(i).koef * a * k;
           if (v.at(i).last_inc) a++;
       }

    cout << summ;
}


#include <cmath>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
struct ex{
    int koef;
    bool first_inc;
    bool last_inc;
    bool symbol_sum;
    ex (){
        first_inc = false;
        last_inc = false;
        koef = 1;
        symbol_sum = true;
    }
    ex (int k, bool f, bool s){
        koef = k;
        first_inc = f;
        symbol_sum = s;
    }
};
string s;
vector<ex> v;
int a;
string convertInt(int number)
{
   stringstream ss;//create a stringstream
   ss << number;//add number to the stream
   return ss.str();//return a string with the contents of the stream
}
bool pred(ex& v1, ex& v2){
    if (v1.symbol_sum && v2.symbol_sum){
        return (v1.koef > v2.koef);
        /*if (v1.first_inc == true && v2.first_inc == true)
            return (v1.koef > v2.koef);
        if (v1.first_inc == true && v2.first_inc == false)
            return (v1.koef > v2.koef);
        if (v1.first_inc == false && v2.first_inc == true)
            return (v1.koef > v2.koef);
        if (v1.first_inc == false && v2.first_inc == false)
            return (v1.koef > v2.koef);*/
    } else if (v1.symbol_sum && !v2.symbol_sum){
        return true;
    } else if (!v1.symbol_sum && v2.symbol_sum){
        return false;
    } else if (!v1.symbol_sum && !v2.symbol_sum){
        return (v1.koef < v2.koef);
        /*if (v1.first_inc == true && v2.first_inc == true)
            return (v1.koef < v2.koef);
        if (v1.first_inc == true && v2.first_inc == false)
            return (v1.koef < v2.koef);
        if (v1.first_inc == false && v2.first_inc == true)
            return (v1.koef < v2.koef);
        if (v1.first_inc == false && v2.first_inc == false)
            return (v1.koef < v2.koef);*/
    }

}
int main(){
    int found;
       //freopen("input.txt","r",stdin);
       //freopen("output.txt","w",stdout);
       cin >> a;
       cin >> s;
       found=s.find('a');

       while(found!=string::npos){
           ex temp = ex();
           int left = 0, right = found + 1;
           //cout << int(found) << "  a = " << a << endl;
           if (found > 1) {
                if(s.at(found-1) == '+' && s.at(found - 2) == '+'){
                    temp.first_inc = true;
                    left = found - 2;
                }
           }
           if (s.length() - found > 2 && !temp.first_inc)
                    if(s.at(found + 1) == '+' && s.at(found + 2) == '+'){
                        temp.last_inc = true;
                        right = found + 3;

                //cout << s <<endl;
           }
           int pos = (temp.first_inc ? found-3 : found - 1);
           int pos_end = (temp.last_inc ? found+3 : found + 1);

           int last;
           int last_s = s.find_last_of("+",pos - 1);
           int last_m = s.find_last_of("-",pos - 1);
           last = max(last_s, last_m);

           if (last_m != -1) {
               temp.symbol_sum = false;
           }
          // if (s.find(("*",pos,1) != -1) {
           if (pos > -1 && s[pos] == '*'){// (("*",pos,1) != -1) {

               left = last + 1;
               temp.koef = atoi(s.substr(last + 1, found -last - 1).c_str());
           } /*else if (pos_end < s.length() && s.at(pos_end) == '*'){//.find("*",pos_end,1) != -1){
               int last_s = s.find_first_of("+",pos_end + 1);
               int last_m = s.find_first_of("-",pos_end + 1);
               if (last_s == -1) last_s = s.length();
               if (last_m == -1) last_m = s.length();
               last = min(last_s, last_m);

               right = last;
               int g = (temp.last_inc ? found + 4 : found + 2);
               temp.koef = atoi(s.substr(g, last - g).c_str());
           }*/
           v.push_back(temp);

           s.replace(0, right, "");
           found = s.find('a');
       }
       sort(v.begin(), v.end(), pred);
       int summ = 0;
       int k = 1;
       int x = 0;
       for (int i = 0; i < v.size() && a < 0; i++){
           if (v.at(i).first_inc ) ++a;
           if (!v.at(i).symbol_sum)k = -1;
           else k =1;
           summ += v.at(i).koef * a * k;
           if (v.at(i).last_inc) a++;
           x++;
       }
       for (int i = v.size() - 1; i>= x; i--){
           if (v.at(i).first_inc ) ++a;
           if (!v.at(i).symbol_sum)k = -1;
           else k =1;
           //cout << "koef " << (v.at(i).symbol_sum ? "+" : "-")<< v.at(i).koef << endl;
            summ += v.at(i).koef * a * k;
           if (v.at(i).last_inc) a++;
       }

    cout << summ;
}


#include <cmath>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
struct ex{
    int koef;
    bool first_inc;
    bool last_inc;
    bool symbol_sum;
    ex (){
        first_inc = false;
        last_inc = false;
        koef = 1;
        symbol_sum = true;
    }
    ex (int k, bool f, bool s){
        koef = k;
        first_inc = f;
        symbol_sum = s;
    }
};
string s;
vector<ex> v;
int a;
string convertInt(int number)
{
   stringstream ss;//create a stringstream
   ss << number;//add number to the stream
   return ss.str();//return a string with the contents of the stream
}
bool pred(ex& v1, ex& v2){
    int k1 = (v1.symbol_sum ? 1 : -1);
    int k2 = (v2.symbol_sum ? 1 : -1);
    return (v1.koef * k1 > v2.koef * k2);
    /*if (v1.symbol_sum && v2.symbol_sum){
        return (v1.koef > v2.koef);
    } else if (v1.symbol_sum && !v2.symbol_sum){
        return true;
    } else if (!v1.symbol_sum && v2.symbol_sum){
        return false;
    } else if (!v1.symbol_sum && !v2.symbol_sum){
        return (v1.koef < v2.koef);
    }*/

}
int main(){
    int found;
       //freopen("input.txt","r",stdin);
       //freopen("output.txt","w",stdout);
       cin >> a;
       cin >> s;
       found=s.find('a');

       while(found!=string::npos){
           ex temp = ex();
           int left = 0, right = found + 1;
           if (found > 1) {
                if(s.at(found-1) == '+' && s.at(found - 2) == '+'){
                    temp.first_inc = true;
                    left = found - 2;
                }
           }
           if (s.length() - found > 2 && !temp.first_inc)
                    if(s.at(found + 1) == '+' && s.at(found + 2) == '+'){
                        temp.last_inc = true;
                        right = found + 3;
           }
           int pos = (temp.first_inc ? found-3 : found - 1);

           int last;
           if (pos > -1){
               int last_s = s.find_last_of("+",pos);
               int last_m = s.find_last_of("-",pos);
               last = max(last_s, last_m);
               if (last_m != -1) {
               temp.symbol_sum = false;
               if (pos > -1 && s[pos] == '*'){
                   left = last + 1;
                   temp.koef = atoi(s.substr(last + 1, found -last - 1).c_str());
               }
           }
           }

           v.push_back(temp);

           s.replace(0, right, "");
           found = s.find('a');
       }
       sort(v.begin(), v.end(), pred);
       int summ = 0;
       int k;
       for (int i = v.size() - 1; i>= 0; i--){
           if (v.at(i).first_inc ) ++a;
           if (!v.at(i).symbol_sum)k = -1;
           else k = 1;
           summ += v.at(i).koef * a * k;
           //cout << (v.at(i).symbol_sum ? "+" : "-") << v.at(i).koef << endl;
           if (v.at(i).last_inc) a++;
       }

    cout << summ;
}


#include <cmath>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
struct ex{
    int koef;
    bool first_inc;
    bool last_inc;
    bool symbol_sum;
    ex (){
        first_inc = false;
        last_inc = false;
        koef = 1;
        symbol_sum = true;
    }
    ex (int k, bool f, bool s){
        koef = k;
        first_inc = f;
        symbol_sum = s;
    }
};
string s;
vector<ex> v;
int a;
string convertInt(int number)
{
   stringstream ss;//create a stringstream
   ss << number;//add number to the stream
   return ss.str();//return a string with the contents of the stream
}
bool pred(ex& v1, ex& v2){
    if (v1.symbol_sum && v2.symbol_sum){
        return (v1.koef > v2.koef);
        /*if (v1.first_inc == true && v2.first_inc == true)
            return (v1.koef > v2.koef);
        if (v1.first_inc == true && v2.first_inc == false)
            return (v1.koef > v2.koef);
        if (v1.first_inc == false && v2.first_inc == true)
            return (v1.koef > v2.koef);
        if (v1.first_inc == false && v2.first_inc == false)
            return (v1.koef > v2.koef);*/
    } else if (v1.symbol_sum && !v2.symbol_sum){
        return true;
    } else if (!v1.symbol_sum && v2.symbol_sum){
        return false;
    } else if (!v1.symbol_sum && !v2.symbol_sum){
        return (v1.koef < v2.koef);
        /*if (v1.first_inc == true && v2.first_inc == true)
            return (v1.koef < v2.koef);
        if (v1.first_inc == true && v2.first_inc == false)
            return (v1.koef < v2.koef);
        if (v1.first_inc == false && v2.first_inc == true)
            return (v1.koef < v2.koef);
        if (v1.first_inc == false && v2.first_inc == false)
            return (v1.koef < v2.koef);*/
    }

}
int main(){
    int found;
       //freopen("input.txt","r",stdin);
       //freopen("output.txt","w",stdout);
       cin >> a;
       cin >> s;
       found=s.find('a');

       while(found!=string::npos){
           ex temp = ex();
           int left = 0, right = found + 1;
           //cout << int(found) << "  a = " << a << endl;
           if (found > 1) {
                if(s.at(found-1) == '+' && s.at(found - 2) == '+'){
                    temp.first_inc = true;
                    left = found - 2;
                }
           }
           if (s.length() - found > 2 && !temp.first_inc)
                    if(s.at(found + 1) == '+' && s.at(found + 2) == '+'){
                        temp.last_inc = true;
                        right = found + 3;

                //cout << s <<endl;
           }
           int pos = (temp.first_inc ? found-3 : found - 1);
           int pos_end = (temp.last_inc ? found+3 : found + 1);

           int last;
           int last_s = s.find_last_of("+",pos - 1);
           int last_m = s.find_last_of("-",pos - 1);
           last = max(last_s, last_m);

           if (last_m != -1) {
               temp.symbol_sum = false;
           }
          // if (s.find(("*",pos,1) != -1) {
           if (pos > -1 && s[pos] == '*'){// (("*",pos,1) != -1) {

               left = last + 1;
               temp.koef = atoi(s.substr(last + 1, found -last - 1).c_str());
           } /*else if (pos_end < s.length() && s.at(pos_end) == '*'){//.find("*",pos_end,1) != -1){
               int last_s = s.find_first_of("+",pos_end + 1);
               int last_m = s.find_first_of("-",pos_end + 1);
               if (last_s == -1) last_s = s.length();
               if (last_m == -1) last_m = s.length();
               last = min(last_s, last_m);

               right = last;
               int g = (temp.last_inc ? found + 4 : found + 2);
               temp.koef = atoi(s.substr(g, last - g).c_str());
           }*/
           v.push_back(temp);

           s.replace(0, right, "");
           found = s.find('a');
       }
       sort(v.begin(), v.end(), pred);
       int summ = 0;
       int k = 1;
       int x = 0;
       /*for (int i = 0; i < v.size() && a < 0; i++){
           if (v.at(i).first_inc ) ++a;
           if (!v.at(i).symbol_sum)k = -1;
           else k =1;
           summ += v.at(i).koef * a * k;
           if (v.at(i).last_inc) a++;
           x++;
       }*/
       for (int i = v.size() - 1; i>= x; i--){
           if (v.at(i).first_inc ) ++a;
           if (!v.at(i).symbol_sum)k = -1;
           else k =1;
           summ += v.at(i).koef * a * k;
           if (v.at(i).last_inc) a++;
       }

    cout << summ;
}


#include <cmath>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
struct ex{
	int koef;
	bool first_inc;
	bool last_inc;
	bool symbol_sum;
	ex (){
		first_inc = false;
		last_inc = false;
		koef = 1;
		symbol_sum = true;
	}
	ex (int k, bool f, bool s){
		koef = k;
		first_inc = f;
		symbol_sum = s;
	}
};
string s;
vector<ex> v;
int a;
string convertInt(int number)
{
   stringstream ss;//create a stringstream
   ss << number;//add number to the stream
   return ss.str();//return a string with the contents of the stream
}
bool pred(ex& v1, ex& v2){
	int k1 = (v1.symbol_sum ? 1 : -1);
	int k2 = (v2.symbol_sum ? 1 : -1);
	return (v1.koef * k1 > v2.koef * k2);
	/*if (v1.symbol_sum && v2.symbol_sum){
		return (v1.koef > v2.koef);
	} else if (v1.symbol_sum && !v2.symbol_sum){
		return true;
	} else if (!v1.symbol_sum && v2.symbol_sum){
		return false;
	} else if (!v1.symbol_sum && !v2.symbol_sum){
		return (v1.koef < v2.koef);
	}*/

}
int main(){
	int found;
	   //freopen("input.txt","r",stdin);
	   //freopen("output.txt","w",stdout);
	   cin >> a;
	   cin >> s;
	   found=s.find('a');

	   while(found!=string::npos){
		   ex temp = ex();
		   int left = 0, right = found + 1;
		   if (found > 1) {
				if(s.at(found-1) == '+' && s.at(found - 2) == '+'){
					temp.first_inc = true;
					left = found - 2;
				}
		   }
		   if (s.length() - found > 2 && !temp.first_inc)
					if(s.at(found + 1) == '+' && s.at(found + 2) == '+'){
						temp.last_inc = true;
						right = found + 3;
		   }
		   int pos = (temp.first_inc ? found-3 : found - 1);

		   int last;
		   if (pos > 0){
			    int last_s = s.find_last_of("+",pos);
				int last_m = s.find_last_of("-",pos);
				last = max(last_s, last_m);
				if (last_m != -1) {
					temp.symbol_sum = false;
				}
		   } else last = 0;

		   if (pos > -1 && s[pos] == '*'){
			   left = last + 1;
			   temp.koef = atoi(s.substr(last + 1, found -last - 1).c_str());
		   }
		   v.push_back(temp);

		   s.replace(0, right, "");
		   found = s.find('a');
	   }
	   sort(v.begin(), v.end(), pred);
	   int summ = 0;
	   int k;
	   for (int i = v.size() - 1; i>= 0; i--){
		   if (v.at(i).first_inc ) ++a;
		   if (!v.at(i).symbol_sum)k = -1;
		   else k = 1;
		   summ += v.at(i).koef * a * k;
		   //cout << (v.at(i).symbol_sum ? "+" : "-") << v.at(i).koef << endl;
		   if (v.at(i).last_inc) a++;
	   }

	cout << summ;
}


#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE

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

using namespace std;

#pragma comment(linker, "/STACK:64000000")

#define problem "Khaustov"

typedef long long int64;
typedef unsigned char byte;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<int64, int64> pii64;
typedef pair<pii64, int> piii64;
typedef pair<double, int64> pdi;
typedef pair<pdi, int> pdii;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef list<int> li;
typedef stringstream ss;

#define left _dsfdsf
#define right _dfjdsj
#define link _tsu_sux
#define prime 1103
#define eps 1e-9
#define inf 123456789

struct sum
{
    int K;
    int TYPE; // 1 - ++a, 2 - a++

    void init(int k, int type)
    {
        K = k;
        TYPE = type;
    }

    bool operator < (const sum &b) const
    {
        if (K <= 0 && b.K > 0) return true;
        if (K > 0 && b.K <= 0) return false;
        if (K == 0 && b.K == 0) return false;
        if (K < b.K) return true;
        if (K > b.K) return false;
        if (K > 0) return (TYPE < b.TYPE);
        return TYPE > b.TYPE;
    }
};

int isSign(char c)
{
    return (c == '+' || c == '-');
}

int isDigit(char c)
{
    return (c >= '0' && c <= '9');
}

int64 A;
int64 res = 0;
int n, m;
string s;
sum a[1 << 15];

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

    m = 0;
    cin >> A;
    cin >> s;
    n = (int)s.length();

    int i = 0;
    while (i < n)
    {
        int sign = 1;
        if (isSign(s[i]))
        {
            if (s[i] == '-') sign = -1;
            ++i;
        }
        int num = 0;
        if (s[i] != '+' && s[i] != 'a')
        {
            while (isDigit(s[i]))
            {
                num = num * 10 + (int)(s[i] - '0');
                ++i;
            }
            ++i;
        } else num = 1;
        int type = 1;
        if (s[i] == 'a') type = 2;
        i += 3;
        a[m++].init(sign * num, type);
    }

    sort(a, a + m);
    for (int i = 0; i < m; ++i)
    {
        if (a[i].TYPE == 1)
            res += a[i].K * (++A);
        else res += a[i].K * (A++);
    }

    cout << res << endl;

    return 0;
}


#include <stdio.h>
#include <queue>
#include <time.h>

#define Pr(x) { fprintf(stderr, "%s = %d\n", #x, x); }

using std::queue;

struct Summand
{
    int K;
    bool Prefix;

    Summand()
    {
        K = 0;
        Prefix = false;
    }

    void Print()
    {
        printf("%d\t", K);
        if (Prefix)
            printf("prefix");
        printf("\n");
    }
};

int main()
{

    //OpenFiles
    //freopen ("input.txt", "r", stdin);
    //freopen ("output.txt", "w", stdout);

    int a;

    //Input
    scanf("%d\n", &a);

    char c;
    bool minus;
    c = getchar();
    int count = 0;
    Summand arr[1000];

    while (c != EOF && c != '\n')
    {
        Summand s;
        minus = false;

        if (c == '-')
        {
            minus = true;
            c = getchar();
        }
        else if (c == '+')
        {
            c = getchar();
        }

        while (c >= '0' && c <= '9')
        {
            s.K = 10*s.K + (c - '0');
            c = getchar();
        }

        if (c == '*')
            c = getchar();
        else
            s.K = 1;

        if (minus)
            s.K = -s.K;

        if (c == '+')
        {
            s.Prefix = true;
            c = getchar();
            c = getchar();
            c = getchar();
        }
        else if (c == 'a')
        {
            s.Prefix = false;
            c = getchar();
            c = getchar();
            c = getchar();
        }

        arr[count] = s;
        ++count;
    }

    Summand tmp;

    for (int i=0; i<count-1; ++i)
    {
        for (int j=i+1; j<count; ++j)
        {
            if (arr[i].K > arr[j].K)
            {
                tmp = arr[i];
                arr[i] = arr[j];
                arr[j] = tmp;
            }
        }
    }

    int Sum = 0;
    for (int i=0; i<count; ++i)
    {
        if (arr[i].Prefix)
            Sum += arr[i].K * ++a;
        else
            Sum += arr[i].K * a++;
    }

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

    //CloseFiles
    fclose (stdin);
    fclose (stdout);

    return 0;
}