title: Find lost cards (faster solution)
body: <p>We're given N (3 &lt;= N &lt;= 50000) cards with unique numbers from 1 to N.
  We lost some 3 cards and our goal is to find them.</p>
  
  <p><em>Input</em>: first line contains number of cards N.
  Second line contains 3 numbers: sum of all left cards we have, sum of their squares and sum of their cubes.</p>
  
  <p><em>Output</em>: numbers of 3 lost cards in any order.</p>
  
  <p>Here what I tried: I found the same 3 sums for lost cards and then check of possible numbers until three of them satisfy our sums.</p>
  
  <p>Is there a faster solution? I have to pass 2sec time limit in Python with max N = 50000.</p>
  
  <pre><code>N = int(input())
  lst = list(range(1, N+1))
  s_rest, s2_rest, s3_rest = list(map(int, input().split()))
  
  s = sum(lst)
  s2 = sum([x**2 for x in lst])
  s3 = sum([x**3 for x in lst])
  # sums of 3 lost numbers
  s_lost = s - s_rest
  s2_lost = s2 - s2_rest
  s3_lost = s3 - s3_rest
  
  
  def find_numbers():
      """Find first appropriate option"""
      for num1 in range(s_lost):
          for num2 in range(s_lost):
              for num3 in range(s_lost):
                  if (num1 + num2 + num3 == s_lost) and (num1**2 + num2**2 + num3**2 == s2_lost)\
                          and (num1**3 + num2**3 + num3**3 == s3_lost):
                      return (num1, num2, num3)
  
  answer = find_numbers()
  print(answer[0], answer[1], answer[2])
  </code></pre>
  
  <p><strong>Examples</strong></p>
  
  <p><em>Input</em>:</p>
  
  <p>4</p>
  
  <p>1 1 1</p>
  
  <p>Output:</p>
  
  <p>2 3 4</p>
  
  <hr>
  
  <p><em>Input</em>:</p>
  
  <p>5</p>
  
  <p>6 26 126</p>
  
  <p>Output:</p>
  
  <p>2 3 4</p>