#include <iostream>
#include <fstream>
#include <vector>

int main(void)
{
	auto& datafile = std::cin;
	
	if (!datafile) {
	    std::cerr << "Could not open \'foo.txt\', make sure it is in the correct directory." << std::endl;
	    exit(-1);
	}
	
	int num_entries;
	// this tests whether the number was gotten successfully
	if (!(datafile >> num_entries)) {
	    std::cerr << "The first item in the file must be the number of entries." << std::endl;
	    exit(-1);
	}
	
	// here we range check the input... never trust that information from the user is reasonable!
	if (num_entries < 0) {
	    std::cerr << "Number of entries cannot be negative." << std::endl;
	    exit(-2);
	}
	
	// here we allocate an array of the requested size.
	// vector will take care of freeing the memory when we're done with it (the vector goes out of scope)
	std::vector<int> ints(num_entries);
	int sum = 0;
	for( int i = 0; i < num_entries; ++i ) {
	    // again, we'll check if there was any problem reading the numbers
	    if (!(datafile >> ints[i])) {
	        std::cerr << "Error reading entry #" << i << std::endl;
	        exit(-3);
	    }
	    sum += ints[i];
	}
	
	std::cout << "Read " << num_entries << " numbers having a sum of " << sum << std::endl;
	return 0;
}
