#include<iostream>
#include <iomanip>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,a,b) for(int i=a;i<b;i++)
#define it(x,b)  for(auto &x:b)
#define NUM 1000000007
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
#define endl "\n"
long long binpow(long long a, long long b) {
    if (b == 0)
        return 1;
    long long res = binpow(a, b / 2)%NUM;
    if (b % 2)
        return (((res * res)%NUM)* a)%NUM;
    else
        return (res * res)%NUM;
}
struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};//unordered_map<pair<long long, long long>, bool, hash_pair> um;
long long fact(long long n)
{
    long long res = 1;
    for (long long i = 2; i <= n; i++)
        res = (res * i)%NUM;
    return (res)%NUM;
}
bool isPrime(long long n) {
    if (n == 1)return false;
    if (n == 2)return true;
    for (long long i = 2; i * i <= n; i++)
        if (n % i == 0)return false;
    return true;
}
ll ceil(ll a, ll b)
{
    if(a%b==0)
    {
        return a/b;
    }
    else
    {
        return ((a/b)+1);
    }
}
ll min(ll a,ll b)
{
    if(a>b)
    {
        return b;
    }
    return a;
}
ll max(ll a, ll b)
{
    if(a>b)
        return a;
    return b;
}
long long dif(long long a,long long b)
{
    if(a>b)
        return a-b;
    return b-a;
}
long long gcd(long long a,long long b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}
long long lcm(long long a,long long b)
{
    long long k=gcd(a,b);
    return (a*b)/k;
}
void read(ll arr[],long long n)
{
    for(long long i=0;i<n;i++)
    {
        cin>>arr[i];
    }
}
void addedge(vector<vector<long long>>&v,long long p1,long long p2) {
    v[p1].push_back({p2});
    v[p2].push_back({p1});
}
bool mycmp(pair<long long ,float>p1,pair<long long ,float>p2)
{
    return p1.first<p2.first;
}
void print(ll arr[],ll n)
{
    for (long long i = 0; i < n; ++i) {
        cout<<arr[i]<<" ";
    }
    cout<<endl;
}
bool mycmp2(pair<long long ,pair<long long ,long long >>&p1,pair<long long ,pair<long long ,long long >>&p2)
{
    if(p1.second.first==p2.second.first)
    {
        return p1.first>p2.first;
    }
    else
    {
        return p1.second.first<p2.second.first;
    }
}
vector<long long >prime;
void sieveOferatosthenes(long long  MAX)
{
    bool pri[MAX + 1];
    memset(pri, true, sizeof(pri));
    pri[1] = false;

    for (long long  p = 2; p * p <= MAX; p++) {

        // If prime[p] is not changed, then it is a prime
        if (pri[p]) {

            // Set all multiples of p to non-prime
            for (long long  i = p * 2; i <= MAX; i += p)
                pri[i] = false;
        }
    }
    for(long long  i=1;i<=MAX;i++)
    {
        if(pri[i])
        {
            prime.push_back(i);
        }
    }
}
bool mycmp3(pair<long long,long long>&p1,pair<long long,long long>&p2)
{
    if(p1.first==p2.first)
    {
        return p1.second<p2.second;
    }
    return p1.first<p2.first;
}
#define tr first
#define fa second
void solve()
{
    int n;cin>>n;
    vector<string>v;
    for(int i=0;i<n;i++)
    {
        string s;cin>>s;
        v.push_back(s);
    }
    pair<ll,ll>p[n+1];
    p[0].tr=1;p[0].fa=1;
    for(int i=1;i<=n;i++)
    {
        if(v[i-1]=="AND")
        {
            p[i].tr=p[i-1].tr;
            p[i].fa=p[i-1].tr+2*(p[i-1].fa);
        }
        else
        {
            p[i].fa=p[i-1].fa;
            p[i].tr=p[i-1].fa+2*(p[i-1].tr);
        }
    }
    cout<<p[n].first<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;t=1;
    //cin>>t;
    // WE WILL WIN.
    while(t--)
    {
        solve();
    }
}
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <climits>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <bits/stdc++.h>
using namespace std;

#define lson 2*i  
#define rson 2*i+1  
#define LS l,mid,lson  
#define RS mid+1,r,rson  
#define UP(i,x,y) for(i=x;i<=y;i++)  
#define DOWN(i,x,y) for(i=x;i>=y;i--)  
#define MEM(a,x) memset(a,x,sizeof(a))  
#define W(a) while(a)  
#define gcd(a,b) __gcd(a,b)  
#define ll long long  
#define MAX 1000005  
#define MOD 1000000007  
#define EXP 1e-8  
#define lowbit(x) (x&-x)  
// const int INF = 0x1fffffffffffffff;
const int INF = INT_MAX;
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
void chmin(ll& a, ll b){ if(a > b) a = b; }
void chmax(ll& a, ll b){ if(a < b) a = b; }

void dfs(int u, unordered_map<int, int> &cls, vector<vector<int>> &adjl, vector<int> &visited, vector<int> &color, unordered_map<int, int> &no) {
    for (auto &v : adjl[u]) {
        if (visited[v]) continue;
        visited[v] = 1;
        if (cls[color[v]] > 0) no[v] = 1;
        cls[color[v]]++;
        dfs(v, cls, adjl, visited, color, no);
        cls[color[v]]--;
    }
}
int main () {
    ll n, m, x, y;
    ll a, b; ll t, k;
    cin >> n;
    vector<int> color(n+1, -1);
    for (int i = 0; i < n; ++i) cin >> color[i];

    vector<vector<int>> adjl(n+1, vector<int> (0));
    
    m = n-1;
    for (ll i = 0; i < m; ++i) {
        cin >> a >> b; a--, b--;
        adjl[a].push_back(b);
        adjl[b].push_back(a);
    }

    typedef pair<int, set<int>> dist;
    auto cmp = [](const dist &a, const dist &b) {return a.second > b.second;};
    queue<dist> q;
    vector<dist> dists(n+1);
    vector<int> visited(n+1, 0);

    unordered_map<int, int> pre;
    unordered_map<int, int> no;
    for (ll i = 0; i <= n; ++i) 
        dists[i] = make_pair(i, set<int> {});
    x = 0;
    dists[x] = make_pair(x, set<int> {});
    q.push(dists[x]);
    visited[x] = 1;

    unordered_map<int, int> color_cnt; 
    color_cnt[color[0]] = 1;
    dfs(0, color_cnt, adjl, visited, color, no);

    for (int i = 0; i < n; ++i) {
        if (no[i] == 1) continue;
        else cout << i+1<<endl;
        // int flag = 1, start_color = color[i], u = i;
        // while (pre.count(u)) {
        //     u = pre[u];
        //     // cout << i << ' ' << u << ' ' << color[u] << ' ' << color[i] <<endl;
        //     if (color[u] == start_color) {
        //         flag = 0; break;
        //     }
        // }
        // if (flag) cout << i+1 <<endl;
    }
    return 0;
}