output_description: For each diff question, print the difference between $a_x$ and $a_y$ $(a_y -
  a_x)$.
input_description: $n \; q$
      $query_1$
      $query_2$
      :
      $query_q$
      
  
  In the first line, $n$ and $q$ are given. Then, $q$ information/questions are
  given in the following format.
  
      
      
      0 $x \; y\; z$
      
  
  or
  
      
      
      1 $x \; y$
      
  
  where '0' of the first digit denotes the relate information and '1' denotes
  the diff question.
attempt: import sys
  
  sys.setrecursionlimit(50000)
  
  
  def findSet(x, element, weight):
      if x != element[x]:
          element[x], s = findSet(element[x], element, weight)
          weight[x] += s
  
      return element[x], weight[x]
  
  
  def union(x, y, element, weight, w):
      x, wx = findSet(x, element, weight)
      y, wy = findSet(y, element, weight)
  
      link(x, wx, y, wy, w, element)
  
  
  def link(x, wx, y, wy, z, element):
      z = z + wy - wx
  
      element[x] = y
      weight[x] = z
  
  
  n, q = map(int, input().split())
  
  element = [i for i in range(n)]
  weight = [0 for i in range(n)]
  
  for i in range(q):
      inp = map(int, input().split())
      inp = list(inp)
  
      if inp[0] == 0:
          x, y, w = inp[1], inp[2], inp[3]
          union(x, y, element, weight, w)
      else:
          x, y = inp[1], inp[2]
          x, wx = findSet(x, element, weight)
          y, wy = findSet(y, element, weight)
  
          if x == y:
              print(wx - wy)
          else:
              print("?")
  
problem_description: Weighted Union Find Trees
  
  There is a sequence $A = a_0, a_1, ..., a_{n-1}$. You are given the following
  information and questions.
  
    * relate$(x, y, z)$: $a_y$ is greater than $a_x$ by $z$
    * diff$(x, y)$: report the difference between $a_x$ and $a_y$ $(a_y - a_x)$
samples: [{"input": "6\n    0 0 2 5\n    0 1 2 3\n    1 0 1\n    1 1 3\n    0 1 4 8\n    1 0 4", "output": "?\n    10"}]