#include <stdio.h>

#define MAX(a, b) ((a)>(b))?(a):(b)
#define MIN(a, b) ((a)<(b))?(a):(b)


const long long int z = 1000000000000000ULL;

int a[200000];
char b[200000];

long long int dpmax[100000][100000];
long long int dpmin[100000][100000];

void solve(int i, int j){
  long long int x, y;
  if(dpmax[i][j] != z) return;

  solve(i+1, j);
  solve(i, j-1);

  if(b[i]) x = a[i] - dpmin[i+1][j];
  else     x = a[i] + dpmax[i+1][j];

  if(b[j-1]) y = dpmax[i][j-1] - a[j];
  else       y = dpmax[i][j-1] + a[j];

  dpmax[i][j] = MAX(x, y);

  if(b[i]) x = a[i] - dpmax[i+1][j];
  else     x = a[i] + dpmin[i+1][j];

  if(b[j-1]) y = dpmin[i][j-1] - a[j];
  else       y = dpmin[i][j-1] + a[j];

  dpmin[i][j] = MIN(x, y);

//  if(b[i] && b[j-1]) dp[i][j] = MAX(dp[i][j], a[i] - solve(i+1,j-1) - a[j]);

printf("dpmax %d, %d = %lld\n", i, j, dpmax[i][j]);
printf("dpmin %d, %d = %lld\n", i, j, dpmin[i][j]);

//  return dp[i][j];
}

int main(){
  int i, j;
  int n;
  scanf("%d", &n);
  for(i=0;i<n-1;i++){
    scanf("%d ", a+i);
    scanf("%c", b+i);
    b[i] &= 0x4;
  }
  scanf("%d", a+n-1);

  for(i=0;i<n;i++){
    printf("a[%d] = %d\n", i, a[i]);
  }
  for(i=0;i<n-1;i++){
    printf("b[%d] = %d\n", i, b[i]);
  }

  for(i=0;i<n;i++){
    dpmax[i][i] = dpmin[i][i] = a[i];
    if(b[i]) dpmax[i][i+1] = dpmin[i][i+1] = a[i] - a[i+1];
    else     dpmax[i][i+1] = dpmin[i][i+1] = a[i] + a[i+1];
    for(j=i+2;j<n;j++){
      dpmax[i][j] = dpmin[i][j] = z;
    }
  }

  solve(0, n-1);

  printf("%lld", dpmax[0][n-1]);
}
