#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vp;
typedef set<ll> si;
typedef map<string, ll> msi;
#define REP(i,a,b) \
for(ll i=ll(a);i<=ll(b);i++)
#define DEP(i,a,b) \
for(ll i=ll(a);i>=ll(b);i--)
#define TR(c, it) \
for (auto it = (c).begin(); it != (c).end(); it++)
#define mp make_pair
#define pb push_back
#define F first
#define S second
ll mod = 1e9+7;
vector<ll> c(100001);
vector<ll> adj[100001];
vector<bool> visited(100001,false);
vector<ll> color(100001,0);
vector<ll> ans;
void dfs(ll v){
  visited[v]=true;
  if(color[c[v]]==0)ans.push_back(v);
      color[c[v]]++;
  for(auto x:adj[v]){
    if(visited[x]==false){
      dfs(x);
    }
  }
  color[c[v]]--;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  
  int T;
  T=1;
  while(T--)
  {
      ll n,i,j,k,l,m;
      cin>>n;
      REP(i,1,n)cin>>c[i];
      REP(i,1,n-1){
        cin>>j>>k;
        adj[j].pb(k);
        adj[k].pb(j);
      }
      dfs(1);
      sort(ans.begin(),ans.end());
    for(auto x: ans)cout<<x<<endl;
  }
  return 0;
}
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007
#define endl "\n"
#define test ll txtc; cin>>txtc; while(txtc--)
typedef long long int ll;
typedef long double ld;
int main() {
    FIO;
    //test
    {
      string s; cin>>s;
      ll n=(ll)s.length();
      vector<vector<ll>>dp(n,vector<ll>(26,0));
      dp[0][s[0]-'a']++;
      for(ll i=1;i<n;i++){
          dp[i][s[i]-'a']++;
          for(ll j=0;j<26;j++){
              dp[i][j]+=dp[i-1][j];
          }
      }
      ll ans=0,last=n,op=-1;
      for(ll i=n-2;i>=1;i--){
          ll ch=s[i]-'a';
          if(s[i]==s[i-1]){
              if(op!=ch){
                  ans+=(n-last);
              }
              //cout<<ans<<endl;
              ans-=(dp[last-1][ch]-dp[i][ch]);
              //cout<<ans<<endl;
              ans+=(last-i-1);
              //cout<<ans<<endl;
              op=ch;
              last=i;
          }
      }
      cout<<ans<<endl;
    }
	return 0;
}
