output_description: Print `delicious` if Takahashi found the food delicious; print `safe` if he
  neither found it delicious nor got a stomachache; print `dangerous` if he got
  a stomachache.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      X A B
attempt: import heapq
  
  
  class UnionFind:
      def __init__(self, n):
          self.n = n
          self.parent = [i for i in range(n)]
          self.rank = [0] * n
  
      def find(self, x):
          if self.parent[x] != x:
              self.parent[x] = self.find(self.parent[x])
          return self.parent[x]
  
      def union(self, x, y):
          x, y = self.find(x), self.find(y)
          if x == y:
              return
  
          if self.rank[x] < self.rank[y]:
              self.parent[x] = y
          else:
              self.parent[y] = x
              self.rank[x] += self.rank[x] == self.rank[y]
  
  
  def kruskal(n, edge):
      ans = 0
      uf = UnionFind(n)
      for i in range(len(edge)):
          d, v, u = heapq.heappop(edge)
  
          if uf.find(v) != uf.find(u):
              uf.union(v, u)
              n -= 1
              ans += d
          if n < 1:
              return ans
      return ans
  
  
  n = int(input())
  x, y = [None] * n, [None] * n
  dist = [[0] * n for _ in range(n)]
  
  for i in range(n):
      a, b = map(int, input().split())
      x[i] = (a, i)
      y[i] = (b, i)
  
  x.sort(key=lambda x: x[0])
  y.sort(key=lambda y: y[0])
  
  edge = []
  for i in range(n - 1):
      heapq.heappush(edge, (x[i + 1][0] - x[i][0], x[i][1], x[i + 1][1]))
      heapq.heappush(edge, (y[i + 1][0] - y[i][0], y[i][1], y[i + 1][1]))
  
  del x, y
  print(kruskal(n, edge))
  
problem_description: Statement
  
  Takahashi has a strong stomach. He never gets a stomachache from eating
  something whose "best-by" date is at most X days earlier. He gets a
  stomachache if the "best-by" date of the food is X+1 or more days earlier,
  though.
  
  Other than that, he finds the food delicious if he eats it not later than the
  "best-by" date. Otherwise, he does not find it delicious.
  
  Takahashi bought some food A days before the "best-by" date, and ate it B days
  after he bought it.
  
  Write a program that outputs `delicious` if he found it delicious, `safe` if
  he did not found it delicious but did not get a stomachache either, and
  `dangerous` if he got a stomachache.
samples: [{"input": "4 3 6", "output": "safe\n    \n\nHe ate the food three days after the \"best-by\" date. It was not delicious or\nharmful for him.\n\n* * *"}, {"input": "6 5 1", "output": "delicious\n    \n\nHe ate the food by the \"best-by\" date. It was delicious for him.\n\n* * *"}, {"input": "3 7 12", "output": "dangerous\n    \n\nHe ate the food five days after the \"best-by\" date. It was harmful for him."}]