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: from sys import stdin
  from collections import namedtuple
  from heapq import heappush, heappop
  
  input = stdin.readline
  
  
  class UnionFind:
      def __init__(self, n):
          self.par = [i for i in range(n + 1)]
          self.size = [1] * (n + 1)
  
      def is_same(self, a, b):
          return self.find(a) == self.find(b)
  
      def unite(self, a, b):
          a = self.find(a)
          b = self.find(b)
          if self.size[a] < self.size[b]:
              a, b = b, a
          self.par[b] = a
          self.size[a] += self.size[b]
  
      def size_of(self, a):
          return self.size[self.find(a)]
  
      def find(self, a):
          if a == self.par[a]:
              return a
          self.par[a] = self.find(self.par[a])
          return self.par[a]
  
  
  Edge = namedtuple("Edge", "w s t")
  X = namedtuple("X", "x i")
  Y = namedtuple("Y", "y i")
  
  N = int(input())
  
  edges = []
  xg = []
  yg = []
  
  for i in range(N):
      x, y = map(int, input().split())
      xg.append(X(x, i))
      yg.append(Y(y, i))
  
  xg.sort()
  yg.sort()
  
  for i in range(N - 1):
      x1, a = xg[i]
      x2, b = xg[i + 1]
      heappush(edges, Edge(abs(x1 - x2), a, b))
  
  for i in range(N - 1):
      y1, a = yg[i]
      y2, b = yg[i + 1]
      heappush(edges, Edge(abs(y1 - y2), a, b))
  
  u = UnionFind(N)
  cost = 0
  
  while edges:
      if u.size_of(0) >= N:
          break
  
      w, s, t = heappop(edges)
      if u.is_same(s, t):
          continue
      u.unite(s, t)
      cost += w
  
  print(cost)
  
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."}]