#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct node{
        int v;
        struct node *next;
} NODE;

char f[100000];

void dfs(int n, NODE *e[], char v[], int mode){
     v[n] = 1;
     if (!mode && f[n] == 1)return;
     NODE *tmp = e[n];
     while (tmp){
           if (!v[tmp->v] && !(mode && f[tmp->v] == 1))
              dfs(tmp->v, e, v, mode);
           tmp = tmp->next;
     }
     return;
}

int main(){
    int n, m, i, j, x, y;
    char f1 = 0, f2 = 0, v1[100000] = {}, v2[100000] = {};
    NODE *e[100000] = {}, *b[100000] = {}, *tmp;
    scanf("%d%d", &n, &m);
    for (i = 0 ; i < n ; ++i){
        scanf("%d", f + i);
        if (f[i] == 1)f1 = 1;
        else if (f[i] == 2)f2 = 1;
    }
    if (!f1 || !f2){
       while (n--)puts("0");
       return 0;
    }

    for (i = 0 ; i < m ; ++i){
        scanf("%d%d", &x, &y);
        --x, --y;
        tmp = calloc(1, sizeof(NODE));
        tmp->v = y, tmp->next = e[x], e[x] = tmp;
        tmp = calloc(1, sizeof(NODE));
        tmp->v = x, tmp->next = b[y], b[y] = tmp;
    }
    for (i = 0 ; i < n ; ++i)
        if (f[i] == 1)
           dfs(i, e, v1, 1);
    for (i = 0 ; i < n ; ++i)
        if (f[i] == 2)
           dfs(i, b, v2, 0);
    for (i = 0 ; i < n ; ++i)
        printf("%d\n", v1[i] && v2[i]);
    scanf(" ");
    return 0;
}


#include <stdio.h>
#include <string.h>

#define N	100000

int md;

long long power(long long a, int k) {
	long long p = 1;

	while (k) {
		if (k & 1)
			p = p * a % md;
		a = a * a % md;
		k >>= 1;
	}
	return p;
}

int vv[N + 1], ff[N + 1], gg[N + 1];

void init() {
	int i;

	ff[0] = gg[0] = 1;
	for (i = 1; i <= N; i++) {
		vv[i] = i == 1 ? 1 : (long long) vv[i - md % i] * (md / i + 1) % md;
		ff[i] = (long long) ff[i - 1] * i % md;
		gg[i] = (long long) gg[i - 1] * vv[i] % md;
	}
}

int choose(int n, int k) {
	return k < 0 || k > n ? 0 : (long long) ff[n] * gg[k] % md * gg[n - k] % md;
}

int aa[N], cnt;

void brute(int i, int n) {
	if (i == n) {
		int b, c, d, i, j;

		for (b = 0; b < 1 << n; b++) {
			c = (1 << n) - 1;
			for (i = 0; i < n; i++)
				if ((b & 1 << i) != 0) {
					if ((c & 1 << aa[i]) == 0)
						goto out;
					c &= ~(1 << aa[i]);
				}
			for (i = 0; i < n; i++)
				if ((c & 1 << i) != 0 && (c & 1 << aa[i]) != 0)
					goto out;
			c = 0;
			for (i = 0; i < n; i++) {
				if ((c & 1 << i) != 0)
					continue;
				j = i, d = 0;
				while (((c | d) & 1 << j) == 0)
					d |= 1 << j, j = aa[j];
				if ((c & 1 << j) != 0) {
					c |= d;
					continue;
				}
				c |= d, d = 0;
				while ((d & 1 << j) == 0)
					d |= 1 << j, j = aa[j];
				if ((b & d) == d)
					goto out;
			}
			cnt++;
out:;
		}
		return;
	}
	for (aa[i] = 0; aa[i] < n; aa[i]++)
		if (aa[i] != i)
			brute(i + 1, n);
}

int slow(int n) {
	int k, l, ans;

	ans = 0;
	for (k = 1; k <= n; k++)
		for (l = k; l + k <= n; l++)
			ans = (ans + (long long) choose(n, l + k)
					* ff[l + k] % md
					* gg[k] % md
					* choose(l - 1, k - 1) % md
					* power(n - 1, k) % md
					* power(l, n - l - k)) % md;
	return ans;
}

int main() {
	int n, n1;

	scanf("%d%d", &n1, &md), init();
	for (n = n1; n <= n1; n++) {
#if 0
		cnt = 0, brute(0, n);
		printf("%d\n", cnt);
#else
		printf("%d\n", slow(n));
#endif
	}
	return 0;
}


#include <stdio.h>

#define N	1000000
#define MD	998244353
#define V2	499122177
#define V6	166374059

int f2(int n) {
	return (long long) n * (n + 1) % MD * V2 % MD;
}

int f3(int n) {
	return (long long) n * (n + 1) % MD * (n + 2) % MD * V6 % MD;
}

int main() {
	static int dp[N], dq[N];
	int n, i, x, y, z, single2, single3, pair, ans;

	scanf("%d", &n);
	dp[0] = dq[0] = 1;
	for (i = 1; i < n; i++) {
		dp[i] = (dp[i - 1] + f2(dp[i - 1]) + (i == 1 ? 0 : (long long) dp[i - 1] * dq[i - 2])) % MD;
		dq[i] = (dq[i - 1] + dp[i]) % MD;
	}
	x = dp[n - 1], y = n == 1 ? 0 : dq[n - 2];
	single2 = (f2(x) + (long long) x * y % MD) % MD;
	single3 = (f3(x) + (long long) f2(x) * y % MD + (long long) x * f2(y) % MD) % MD;
	pair = 0;
	for (i = 0; i < n; i++) {
		if (i == 0)
			z = 1;
		else {
			x = dp[i - 1], y = i == 1 ? 0 : dq[i - 2];
			z = (f2(x) + (long long) x * y % MD) % MD;
		}
		pair = (pair + (long long) z * dp[n - 1 - i]) % MD;
	}
	ans = ((long long) single2 * 2 + single3 * 2 + pair) % MD;
	if (ans < 0)
		ans += MD;
	printf("%d\n", ans);
	return 0;
}


#include <stdio.h>

#define N	400

int md;

int ff[N + 1];

void init() {
	int n;

	ff[0] = 1;
	for (n = 1; n <= N; n++)
		ff[n] = (long long) ff[n - 1] * n % md;
}

int main() {
	static int dp[N + 1];
	int n, i, j, ans;

	scanf("%d%d", &n, &md), init();
	ans = 0;
	dp[0] = 1;
	for (i = 1; i <= n; i++) {
		for (j = n; j >= 0; j--)
			dp[j] = ((j == 0 ? 0 : dp[j - 1]) + (long long) dp[j] * j * 2) % md;
		ans = (ans + (long long) dp[n - i + 1] * ff[n - i + 1]) % md;
	}
	printf("%d\n", ans);
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define N_LIMIT 1000003 // 1e6+3
typedef long long ll;

ll a_pows[N_LIMIT];

ll inv(ll x, ll p)
{
    ll result = 1, y;
    //printf("inverse of %lld is ", x);
    while (x != 1)
    {
        y = (x+p)/x;
        result *= y;
        result %= p;
        x = (x*y)%p;
    }
    //printf("%lld\n", result);
    return result;
}

int main(int argc, char *argv)
{
    ll a, b, p, x, d = 1;

    ll n, m, y, z;
    ll pdi;
    ll count;
    int i;
    scanf("%lld %lld %lld %lld", &a, &b, &p, &x);
    a_pows[0] = 1;
    a_pows[1] = a;
    while (a != 1)
    {
        d++;
        a = (a*a_pows[1]) % p;
        a_pows[d] = a;
    }
    //printf("d: %lld\n", d);
    count = 0;
    pdi = inv(p-d, p);
    for (m=0; m<d; m++)
    {
        n = (a_pows[d-m] * b) % p;
        z = (pdi * (m-n)) % p;
        if (z < 0)
        {
            z += p;
        }

        //printf("m:%lld n:%lld z:%lld count:%lld\n", m, n, z, count);
        count += (x-m)/(p*d);
        if (x%(p*d) >= z*d+m)
        {
            count += 1;
        }
    }
    printf("%lld\n", count);

    return 0;
}


#include <stdio.h>
#include <string.h>

#define MOD 998244353

int main() {
	int n, m;
	scanf("%d%d", &n, &m);

	static int c[10];

	for (int i = 0; i < m; ++i) {
		int u, v;
		scanf("%d%d", &u, &v);
		c[u] |= 1 << v;
		c[v] |= 1 << u;
	}

	for (int u = 0; u < 10; ++u) {
		c[u] |= 1 << u;
	}

	static int dp[1024];

	for (int u = 0; u < 10; ++u) {
		dp[1 << u] = 1;
	}

	while (--n) {
		static int tmp[1024];

		memset(tmp, 0, sizeof(tmp));

		for (int i = 0; i < 1024; ++i) {
			for (int x = 0; x < 10; ++x) {
				int j = i & c[x] | (1 << x);
				if (j & ((1 << x) - 1))
					continue;
				if ((tmp[j] += dp[i]) >= MOD)
					tmp[j] -= MOD;
			}
		}

		memcpy(dp, tmp, sizeof(dp));
	}

	int res = 0;
	for (int i = 0; i < 1024; ++i) {
		if ((res += dp[i]) >= MOD)
			res -= MOD;
	}

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


/* practice with Dukkha */
#include <stdio.h>

long long count2(int h) {
	return h % 2 == 1 ? (long long) (h + 1) / 2 * ((h + 1) / 2 + 1)
		: (long long) (h / 2 + 1) * (h / 2 + 1);
}

long long count1(int h, int r) {
	return count2(h) - (r >= h ? 0 : count2(h - 1 - r));
}

long long count(int h, int k, int r) {
	return count1(h, r) - (k == 0 ? 0 : count1(k - 1, r));
}

long long solve(int a, int b, int c, int h) {
	int k, l, r;

	if (a + 1 > b + c + h)
		return 0;
	k = a + 1 <= b + c ? 0 : a + 1 - (b + c);
	l = 1 - a - (c - b);
	r = a - 1 - (c - b);
	if (l >= 0)
		return count(h, k, r) - (l == 0 ? 0 : count(h, k, l - 1));
	if (r <= 0) {
		r = -r, l = -l;
		return count(h, k, l) - (r == 0 ? 0 : count(h, k, r - 1));
	}
	return count(h, k, -l) + count(h, k, r) - count(h, k, 0);
}

int main() {
	int a, b, c, l, l_;
	long long ans;

	scanf("%d%d%d%d", &a, &b, &c, &l);
	ans = 0;
	for (l_ = 0; l_ <= l; l_++)
		ans += solve(a + l_, b, c, l - l_);
	printf("%lld\n", ans);
	return 0;
}


#include<stdio.h>
#define min(a,b) a>b?b:a
main(){
	int a,b,c;
	int l,la,lb,lc,mn;
	scanf("%d%d%d%d",&a,&b,&c,&l);
	long long ans=0;
	for(la=0;la<=l;la++)
	{
		mn=min(l-la,a-b-c+la);
		if(mn<0)
		continue;
		ans=ans+1LL*(mn+1)*(mn+2)/2;
	}
		for(lb=0;lb<=l;lb++)
	{
		mn=min(l-lb,b-a-c+lb);
		if(mn<0)
		continue;
		ans=ans+1LL*(mn+1)*(mn+2)/2;
	}
		for(lc=0;lc<=l;lc++)
	{
		mn=min(l-lc,c-b-a+lc);
		if(mn<0)
		continue;
		ans=ans+1LL*(mn+1)*(mn+2)/2;
	}
	ans=1LL*(l+1)*(l+2)*(l+3)/6-ans;
	printf("%lld\n",ans);
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>
#include<math.h>
#include<string.h>

typedef int64_t i64;
typedef int32_t i32;

static void print_int(i64 n){if(n<0){putchar('-');n=-n;}if(n==0){putchar('0');return;}int s[20],len=0;while(n>0){s[len++]=n%10+'0';n/=10;}while(len>0){putchar(s[--len]);}}
static i64 read_int(void){int prev='\0';int c=getchar();while(!('0'<=c && c<='9')){prev=c;c=getchar();}i64 res=0;while('0'<=c && c<='9'){res=10*res+c-'0';c=getchar();}return prev=='-'?-res:res;}

const i32 mod = 1000000007;

i32 inv (i32 a) {
  i32 t = 1;
  while (a > 1) {
    t = (i64) t * (mod - mod / a) % mod;
    a = mod % a;
  }
  return t;
}

i32 mod_pow (i32 r, i32 n) {
  i32 t = 1;
  i32 s = r;
  while (n > 0) {
    if (n & 1) t = (i64) t * s % mod;
    s = (i64) s * s % mod;
    n >>= 1;
  }
  return t;
}

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

void matmul (i32 *c, i32 *a, i32 *b, i32 n) {
  static i32 *tmp = NULL;
  if (tmp == NULL) {
    tmp = (i32 *) calloc (n * n, sizeof (i32));
  }
  memset (tmp, 0, sizeof (i32) * n * n);
  for (i32 i = 0; i < n; ++i) {
    for (i32 k = 0; k < n; ++k) {
      for (i32 j = 0; j < n; ++j) {
	tmp[i * n + j] = (tmp[i * n + j] + (i64) a[i * n + k] * b[k * n + j]) % mod;
      }
    }
  }
  memcpy (c, tmp, sizeof (i32) * n * n);
}

void run (void) {
  i32 n = read_int();
  i32 k = read_int();
  i32 *a = (i32 *) calloc (n, sizeof (i32));
  i32 cnt[2] = {0, 0};
  for (i32 i = 0; i < n; ++i) {
    a[i] = read_int();
    cnt[a[i]]++;
  }
  if (cnt[0] == 0 || cnt[1] == 0) {
    puts("1");
    return;
  }
  i32 d = 0;
  for (i32 i = 0; i < cnt[0]; ++i) {
    d += a[i];
  }
  const i32 m = MIN(cnt[0], cnt[1]) + 1;
  i32 *t = (i32 *) calloc (m * m, sizeof (i32));
  i32 *s = (i32 *) calloc (m * m, sizeof (i32));
  for (i32 i = 0; i < m; ++i) {
    t[i * m + i] = 1;
    s[i * m + i] = cnt[0] * (cnt[0] - 1) / 2 + cnt[1] * (cnt[1] - 1) / 2 + (cnt[0] - i) * i + i * (cnt[1] - i);
    if (i + 1 < m) {
      s[i * m + i + 1] = (cnt[0] - i) * (cnt[1] - i);
    }
    if (i - 1 >= 0) {
      s[i * m + i - 1] = i * i;
    }
  }
  i32 p = inv (n * (n - 1) / 2);
  for (i32 i = 0; i < m * m; ++i) {
    s[i] = (i64) s[i] * p % mod;
  }
  while (k > 0) {
    if (k & 1) matmul (t, t, s, m);
    matmul (s, s, s, m);
    k >>= 1;
  }
  i32 ans = t[d * m + 0];
  print_int (ans);
  puts("");
}

int main (void) {
  run ();
  return 0;
}


/* practice with Dukkha */
#include <stdio.h>

#define N	5

int max(int a, int b) { return a > b ? a : b; }

double prob(int l, int r, int a) {
	return (double) max(r - max(l, a) + 1, 0) / (r - l + 1);
}

int main() {
	static int ll[N], rr[N];
	int n, i, j, a;
	double ans, p, q;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d%d", &ll[i], &rr[i]);
	ans = 0;
	for (a = 1; a <= 10000; a++) {
		p = 1;
		for (j = 0; j < n; j++)
			p *= 1 - prob(ll[j], rr[j], a);
		q = p;
		for (i = 0; i < n; i++) {
			p = prob(ll[i], rr[i], a);
			for (j = 0; j < n; j++)
				if (j != i)
					p *= 1 - prob(ll[j], rr[j], a);
			q += p;
		}
		ans += 1 - q;
	}
	printf("%.9f\n", ans);
	return 0;
}


#include <stdio.h>

double L[6], R[6];
int n;

int min(int a, double b_) {
    int b = b_;
    return (a < b ? a : b);
}
int max(int a, double b_) {
    int b = b_;
    return (a > b ? a : b);
}

double noHigherThan(int b) {
    int i, j, f;
    double p = 0.0, p1;
    for(i = 3; i < (1 << n); i++) {
        p1 = 1.0;
        f = 0;
        for(j = 0; j < n; j++) {
            if((i & (1 << j)) > 0) {
                if(!(L[j] <= b && b <= R[j])) {
                    p1 = 0;
                    break;
                }
                p1 *= (1.0 / (R[j] - L[j] + 1));
                f++;
            }
            else {
                if(L[j] >= b) {
                    p1 = 0;
                    break;
                }
                p1 *= ((min(b - 1, R[j]) - L[j] + 1) / (R[j] - L[j] + 1));
            }
        }
        if(f >= 2)
            p = p + p1;
    }
    return p;
}

double oneHigherThan(int b, int x) {
    if(b >= R[x]) return 0.0;
    double p = 0.0, p1;
    int i, j, f;
    for(i = 1; i < (1 << n); i++) {
        p1 = 1.0;
        f = 0;
        for(j = 0; j < n; j++) {
            if(j == x) continue;
            if((i & (1 << j)) > 0) {
                if(!(L[j] <= b && b <= R[j])) {
                    p1 = 0;
                    break;
                }
                p1 *= (1.0 / (R[j] - L[j] + 1));
                f++;
            }
            else {
                if(L[j] >= b) {
                    p1 = 0;
                    break;
                }
                p1 *= ((min(b - 1, R[j]) - L[j] + 1.0) / (R[j] - L[j] + 1.0));
            }
        }
        if(f == 0) p1 = 0;
        p = p + p1;
    }
    p /= 2.0;
    return p * ((R[x] - max(b + 1, L[x]) + 1.0) / (R[x] - L[x] + 1));
}

double P(int b) {
    double p = 0.0;
    p = noHigherThan(b);
    int i;
    for(i = 0; i < n; i++)
        p = p + oneHigherThan(b, i);
    return p;
}

int main(int argc, char const *argv[]) {
    int i, lim = 0;
    double ex = 0;
    scanf("%d", &n);
    for(i = 0; i < n; i++) {
        scanf("%lf%lf", &L[i], &R[i]);
        lim = max(lim, R[i]);
    }
    for(i = 1; i <= lim; i++) {
        ex = ex + i * P(i);
    }
    printf("%.10lf\n", ex);
    return 0;
}


#include <stdio.h>

#define N	250
#define MD	998244353

int vv[N + 1], ff[N + 1], gg[N + 1];

void init() {
	int i;

	ff[0] = gg[0] = 1;
	for (i = 1; i <= N; i++) {
		vv[i] = i == 1 ? 1 : (long long) vv[i - MD % i] * (MD / i + 1) % MD;
		ff[i] = (long long) ff[i - 1] * i % MD;
		gg[i] = (long long) gg[i - 1] * vv[i] % MD;
	}
}

int choose(int n, int k) {
	return (long long) ff[n] * gg[k] % MD * gg[n - k] % MD;
}

long long power(long long a, int k) {
	long long p = 1;

	while (k) {
		if (k & 1)
			p = p * a % MD;
		a = a * a % MD;
		k >>= 1;
	}
	return p;
}

int main() {
	static int dp[N];
	int n, k, c, i, j;

	init();
	scanf("%d%d", &n, &k);
	dp[0] = 1;
	for (c = 1; c <= k; c++)
		for (i = n - 1; i >= 0; i--)
			for (j = 0; j < i; j++)
				dp[i] = (dp[i] + (long long) dp[j] * choose(i, j) % MD * power(k - c + 1, i * (i - 1) / 2 - j * (j - 1) / 2)) % MD;
	printf("%d\n", dp[n - 1]);
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <sys/time.h>

#define N	35
#define N_	((N + 1) / 2)

unsigned int X;

void srand_() {
	struct timeval tv;

	gettimeofday(&tv, NULL);
	X = tv.tv_sec ^ tv.tv_usec | 1;
}

int rand_() {
	return (X *= 3) >> 1;
}

void multiply(char *aa, char *bb, char *md, int n) {
	static char cc[N * 2];
	int i, j;

	memset(cc, 0, n * 2 * sizeof *cc);
	for (i = 0; i < n; i++)
		for (j = 0; j < n; j++)
			if (aa[i] && bb[j])
				cc[i + j] ^= 1;
	for (i = n * 2 - 1; i >= n - 1; i--)
		if (cc[i])
			for (j = 0; j < n; j++)
				if (md[j])
					cc[i - (n - 1 - j)] ^= 1;
	memcpy(aa, cc, n * sizeof *cc);
}

char ppp[1 << N_][N]; int n;

int compare(int i, int j) {
	int c = memcmp(ppp[i], ppp[j], n * sizeof *ppp[j]);

	return c ? c : i - j;
}

void sort(int *ii, int l, int r) {
	while (l < r) {
		int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;

		while (j < k) {
			int c = compare(ii[j], i_);

			if (c == 0)
				j++;
			else if (c < 0) {
				tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
				i++, j++;
			} else {
				k--;
				tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;
			}
		}
		sort(ii, l, i);
		l = k;
	}
}

int search(int *ii, int m, char *pp) {
	int lower = -1, upper = m;

	while (upper - lower > 1) {
		int i = (lower + upper) / 2;

		if (memcmp(ppp[ii[i]], pp, n * sizeof *ppp[ii[i]]) >= 0)
			upper = i;
		else
			lower = i;
	}
	return upper < m && memcmp(pp, ppp[ii[upper]], n * sizeof *ppp[ii[upper]]) == 0 ? ii[upper] : -1;
}

int main() {
	static char cc_[N + 1], *cc, md[N], xx[N], vv[N], pp[N], pp_[N];
	static int rr[1 << N_];
	int n_, p, q, r, i, j, one;
	char tmp;

	srand_();
	scanf("%s", cc_), n = strlen(cc_);
	p = 0;
	while (p < n && cc_[p] == '0')
		p++;
	if (p == n) {
		printf("-1\n");
		return 0;
	}
	cc = cc_ + p, n -= p;
	while (cc[n - 1] == '0')
		n--;
	if (n == 1) {
		printf("%d %d\n", p + 1, p + 2);
		return 0;
	}
	n_ = (n + 1) / 2;
	cc[n] = 0;
	for (i = 0, j = n - 1; i < j; i++, j--)
		tmp = cc[i], cc[i] = cc[j], cc[j] = tmp;
	for (i = 0; i < n; i++)
		md[i] = cc[i] - '0';
	for (j = 0; j < n - 1; j++)
		vv[j] = md[j + 1];
	memset(pp, 0, n * sizeof *pp), pp[0] = 1;
	for (r = 0; r < 1 << n_; r++) {
		memcpy(ppp[r], pp, n * sizeof *pp);
		one = 1;
		for (i = 0; i < n; i++)
			if ((pp[i] == 1) != (i == 0)) {
				one = 0;
				break;
			}
		if (one && r != 0) {
			printf("%d %d\n", p + 1, p + 1 + r);
			return 0;
		}
		multiply(pp, vv, md, n);
	}
	for (r = 0; r < 1 << n_; r++)
		rr[r] = r;
	sort(rr, 0, 1 << n_);
	memset(pp_, 0, n * sizeof *pp_), pp_[0] = 1;
	xx[1] = 1, multiply(xx, pp_, md, n);
	for (r = 0; r < 1 << n_; r++)
		multiply(pp_, xx, md, n);
	memset(pp, 0, n * sizeof *pp), pp[0] = 1;
	for (q = 1; q <= 1 << n_; q++) {
		multiply(pp, pp_, md, n);
		if ((r = search(rr, 1 << n_, pp)) != -1) {
			printf("%d %lld\n", p + 1, p + 1 + ((long long) q << n_) + r);
			return 0;
		}
	}
	printf("-1\n");
	return 0;
}


#include<stdio.h>
long long  a[5],ans=1000000000000;
char p[4];
void dfs(int l)
{
    if(l==1)
    {
      long long  s;
        for( int i=1; i<=4; i++)
            if(a[i]!=-1)
            {
                s=a[i];
                break;
            }
        if(s<ans)
            ans=s;
        return;
    }
    for(int i=1; i<=4; i++)
        for( int j=i+1; j<=4; j++)
        {
            int k=4-l+1;
            if(a[i]==-1||a[j]==-1||p[k]=='-')
                continue;
            long long   x=a[i],y=a[j];
            char t=p[k];
            p[k]='-';
            a[j]=-1;
            if(t=='+')
                a[i]=x+y;
            else
                a[i]=x*y;
            dfs(l-1);
            a[i]=x;
            a[j]=y;
            p[k]=t;
        }
}
int main()
{
    for( int i=1; i<=4; i++)
       scanf("%lld",&a[i]);
    for(int i=1; i<=3; i++)
    {
        char c;
        c=getchar();
        if(c=='*'||c=='+')
            p[i]=c;
        else
            i--;
    }
    dfs(4);
    printf("%lld",ans);
    return 0;
}