text: a, b = open("data.txt").read().split("\n")
  a, b = [x.split(",") for x in [a, b]]
  
  dir_x = {'L': -1, 'R': 1, 'U': 0, 'D': 0}
  dir_y = {'L': 0, 'R': 0, 'U': 1, 'D': -1}
  
  
  def get_coords(data):
      x = 0
      y = 0
      length = 0
      ans = {}
      for move in data:
          direction = move[0]
          number = int(move[1:])
          for i in range(number):
              x += dir_x[direction]
              y += dir_y[direction]
              length += 1
              if (x, y) not in ans:
                  ans[(x, y)] = length
      return ans
  
  
  a_coords = get_coords(a)
  b_coords = get_coords(b)
  
  both = set(a_coords.keys()) & set(b_coords.keys())
  part1 = min([abs(x) + abs(y) for (x, y) in both])
  part2 = min([a_coords[p] + b_coords[p] for p in both])
  print(part1, part2)
  