output_description: Print the maximum possible number of times the operation can be performed.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      S
attempt: N = int(input())
  
  X = [[] for i in range(N)]
  P = [-1] * N
  
  for i in range(N - 1):
      x, y = map(int, input().split())
      X[x - 1].append(y - 1)
      X[y - 1].append(x - 1)
  
  
  def set_parent(i):
      # print(i)
      for a in X[i]:
          if a != P[i]:
              P[a] = i
              # print(a)
              X[a].remove(i)
              set_parent(a)
  
  
  set_parent(0)
  
  B = [-1] * N
  
  
  def set_block(i):
      for a in X[i]:
          B[a] = max(i, B[i])
          set_block(a)
  
  
  B_id = [-1] * N
  B_id_cnt = [0] * N
  
  
  def BID(i):
      for a in X[i]:
          if a > B[i]:
              B_id[a] = a
          else:
              B_id[a] = B_id[i]
  
          # print(a, B_id)
          B_id_cnt[B_id[a]] += 1
          BID(a)
  
  
  Ans = [1] * N
  
  
  def flow(i):
      for a in X[i]:
          if B_id[a] == B_id[i]:
              Ans[a] = Ans[i]
          else:
              Ans[a] = Ans[i] + B_id_cnt[a]
          flow(a)
  
  
  set_block(0)
  
  
  # print("X=", X) # 子リスト
  # print("P=", P) # 親
  # print("B=", B) # Block
  # print(B_id) # BlockのID
  # print(B_id_cnt) # BlockのID
  # print(Ans)
  print(" ".join(map(str, Ans[1:])))
  
problem_description: Statement
  
  There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc
  with a black side and a white side.) The state of each piece is represented by
  a string S of length N. If S_i=`B`, the i-th piece from the left is showing
  black; If S_i=`W`, the i-th piece from the left is showing white.
  
  Consider performing the following operation:
  
    * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black.
  
  Find the maximum possible number of times this operation can be performed.
samples: [{"input": "BBW", "output": "2\n    \n\nThe operation can be performed twice, as follows:\n\n  * Flip the second and third pieces from the left.\n  * Flip the first and second pieces from the left.\n\n* * *"}, {"input": "BWBWBW", "output": "6"}]