/************************************************
Grundlegende Algorithmen mit Java,
http://algorithmen-und-problemloesungen.de/
Copyright @2007-2009 by Doina Logofatu
************************************************/

import java.io.*;
import java.util.*;

public class P07SameSums {
  private static final String FileInputName = "numbers.in";
  private static final String FileOutputName = "numbers.out";
  
  private static final int MinusEins = -1;

  public static void main(String[] args) throws IOException {
    Scanner scanner = null;
    PrintStream out = null;
    try {
      scanner = new Scanner(new File(FileInputName));
      out = new PrintStream(new File(FileOutputName));
      int start = scanner.nextInt();
      List<Integer> vElem = new ArrayList<Integer>();
      while (scanner.hasNextInt()) {
        vElem.add(scanner.nextInt());
      }
      int vLast[] = new int[1000];
      Arrays.fill(vLast, MinusEins);
      for (int i = 0; i < vElem.size(); i++) {
        int aux = vElem.get(i);
        if (MinusEins == vLast[aux % 1000]) {
          vLast[aux % 1000] = i;
        }
        for (int j = 0; j < 1000; j++) {
          if (vLast[j] != MinusEins && j != aux % 1000 && vLast[j] != i) {
            int sum = (aux + j) % 1000;
            if (MinusEins == vLast[sum]) {
              vLast[sum] = i;
            }
          }
        }
      }
      int i = start % 1000;
      if (i != 0)
        vLast[0] = MinusEins;
      if (vLast[i] != MinusEins) {
        while (vLast[i] >= 0) {
          out.print(' ');
          out.print(vElem.get(vLast[i]));
          int j = i;
          if (i < vElem.get(vLast[i]) % 1000) {
            i = 1000 + i - vElem.get(vLast[i]) % 1000;
          } else {
            i = i - vElem.get(vLast[i]) % 1000;
          }
          vLast[j] = MinusEins;
        }
      } else
        out.print("keine Loesung!");
    } finally {
      if (scanner != null) {
        scanner.close();
      }
      if (out != null) {
        out.close();
      }
    }
  }
}

