WHAT: The USA Computer Olympiad Fall Open is a computer programming contest open to all pre-college students throughout the world who have access to the mailing list. Five problems are presented for solution. Results of this contest and other contests will be among the data used to choose delegates to the USA training camp and potentially to the IOI. Gold Division winners will receive a handsome plaque at the end of the season; Silver Division winners receive a nicely inscribed certificate. Each contestant self-classifies himself/herself as to which division to enter. Pick the right one! You get to see the problems before you decide; how hard could it be?

HOW: Problems and rules will be posted to the hs-computing mailing list. Solutions must be written in Borland C/C++ or Turbo Pascal and must be returned via e-mail by the contest completion deadline. Choosing a non-Borland Pascal compiler will potentially cause a solution to not compile on the judges' machines. After you have completed the contest, feel free to take your final solution to a Borland Pascal equipped machine to ensure it will work. Do not charge this `repair' time against your coding time limit. Choosing a non-Borland C/C++ compiler has a greater chance of working out okay: make sure you use no library functions other than those provided by the following header files (i.e., don't #include anything but these files -- not all of which are usually needed, of course): assert.h io.h mem.h string.h ctype.h iostream.h stdio.h values.h fstream.h math.h stdlib.h If you use an ANSI compiler and use (at most) only these headers, your program should compile fine under our compilers. Remember that we are running the judging under MS-DOS and are thus subject to its memory requirements. The specific compilers used are as follows. * Turbo Pascal 7.0 * Borland C/C++ 3.1

WHO: All pre-college students who have access to the hs-computing mailing list are eligible. This is an individual contest, not a team contest.

WHERE: Students can work on problem solutions anywhere they wish, including school and home.

WHEN: Problems will be posted to the mailing list between 0730 and 0800 a.m. US Mountain Standard Time (1430-1500 GMT) on Wednesday, November 4, 1998. All results are due by 0800 am US Mountain Standard Time (1500 GMT) Wednesday, November 11, 1998. Late solutions will not be accepted.

PRIZES: Winners will receive a handsome plaque and have their names immortalized on the USACO Web Pages.

FEES: No entry fees are charged.

No special registration form is required. Each problem solution has, withinits submission, an entry form (see below). You enter when you send inyour solution.

  • Consultation with people other than the contest director is prohibited.
  • Do not work in a team environment.
  • Submit questions to who will try to fathom an appropriate answer for you (and post it to the hs-computing list, if appropriate). Many times, the reply will often be a suggestion to read the problem more carefully.
  • Any amount of consultation with written materials (such as programming books) is allowed (but this doesn't mean you can ask someone to write an article on how to solve a problem, of course). Do not ask someone where to look up an answer though, that counts as `consultation with people.'
  • Spend no more than three sessions solving problems (i.e., if you work one hour in a session, take a one hour break, and then work another hour, you have worked for two sessions).
  • Spend no more than a total of five hours solving problems.
  • Submit source code for the problems to the contest coordinators via e-mail to (see below for format). *
  • Solutions will be judged for correctness by running them against several (usually 5-15) different sets of input data. Points are accrued for correct solutions. Some datasets for a problem will be worth more points than others. Solutions to some problems will be worth more points. Judging will be performed expeditiously but could take two weeks to complete. *
  • Unless otherwise stated, your program must run no longer than 5 seconds for any test case on the judge's computer (approximately 200 MHz PentiumII).
  • It is NOT guaranteed that all possible legal datasets will be solvable within the time limit. * The judges reserve the right to increase time limits during grading.
  • Judges will not test all datasets against a program that crashes the computer for initial datasets.
  • Decision of the judges is final.
  • Do not cheat; it's no fun for anyone.
  • Do not use inline assembler statements.
  • Do not submit programs that use data files that aren't supplied by the contest coordinators.
  • Do not use `temporary' data files.
  • Keep in mind that this is neither a `tricky input' nor a `tricky output' contest, in general. Input and output formats are straightforward, though the input values may cause your program difficulty.
  • Problems are intended to be algorithmic in nature, meaning clever algorithms and/or data structures may be needed to score full marks.
  • All problems are intended to be straightforward (yet challenging); no problems are intended to have `hidden tricks' in them.
  • Nevertheless, legal but complex datasets are fair game for testing.
  • If you find a problem with wording or an ambiguity, document your assumptions carefully and move on. Send e-mail; we'll reply if we can.NOTES: * We will be using automated grading procedures.
  • The registration information at the front of the solution should be in precisely the same format as requested below. Otherwise, your solution could be lost. Be sure that each program has the same registration information.
  • Programs that consist of essentially nothing more than print statements will not be graded.
  • Submitters of programs that attempt to thwart grading procedures will be forever disqualified from USACO contests. Do not join this elite club!
  • Rob Kolstad is this contest's director.
  • Russ Cox is this contest's grader.
  • During the contest, feel free to send questions (one per e-mail please!) to He will reply by e-mail when he is available. Questions judged to be germane to the entire hs-computing list will be summarized and posted there, also. Be sure to check your e-mail occasionally for contest updates, should there be any. For fairness, sometimes your question will be answered with a null answer (`Sorry, I can't elaborate on that').
  • All programs read their input from file INPUT.TXT; do not specify a complete path name in your `open' statement, just `INPUT.TXT'.
  • All programs write their output to file OUTPUT.TXT; do not specify a path name in your `open' statement.
  • Remember that all your output should be written to the file OUTPUT.TXT. Do not clear the screen or print anything to the screen.
  • Note that test data run by the judges will almost surely be more challenging than the test data supplied with each problem.
  • We will assess scoring penalties when certain rules are abused.
  • Don't use any of C++'s Standard Template Library (STL) or any classes other than those provided by iostream.h and fstream.h. We're using a very old C++ compiler: it probably doesn't know about the special classes you want to use.
  • If your source code does not compile without changes, your program will not be graded. The only exception to this is: we will fix source codes mangled by mail agents' treatment of line wraps and the like.
  • Don't use C's ``bool'' type. That is specific to Borland C/C++ 5.0. If you can compile your code under ANSI C, you're probably safe.
  • The scorer will not compile with any command-line compiler options. You must set any relevant options using the appropriate method in the source file, as illustrated above. Note that not all command-line options are compiler options. In particular, don't bother specifying "-P" or "-P-" on the "#pragma option" line, as the compiler will not accept it.

Submit your answers to problems via e-mail to Please send precisely one problem's solution program per e-mail (i.e., send three separate e-mails for three problems, etc.). If you submit more than one solution for a single problem, only the last one received by our automatic mail reader will be graded. That means if you find a bugafter your submission, you can re-submit. This is dangerous ground, of course, since your newer program might, in fact, be worse than the previous one.Every e-mail is acknowledged almost instantly by an automated mail reader. If you do not receive an acknowledgment, double-check the address. Note that some networks connect to the Internet only occasionally.Each solution e-mail submission should have the following format for the e-mail message. SEND ASCII MESSAGES. DO NOT USE ATTACHMENTS or MIME ENCODING, fancy mail options, or anything else. The programs that read the mail are looking for just plain old ASCII (just like thismessage). Submissions that use some format other than ASCII might not be graded.Submissions must have special comments separating sections of the mail;you must insert the three `#'s and the word that follows them. These comment lines are surrounded by a single blank line. Here is the exact format for submitting solutions so the grading programs can read them (be sure you note that those ### things are important!):### Program... [any compiler options you use] ...... [header comments -- see below for format] ... ... [text of program in C or Pascal] ...### End


  • Put comments precisely like the ones below at the front of each and every solution (after the `### Program' marker).
  • These messages are read by a program; do not change the format.
  • Be sure your email address and name are always spelled precisely the same way. We use the combination of email address and name as a unique identifier for you.
  • Data after `### End' are ignored (e.g., signatures)
  • All registration lines (below) are required; your program won't be graded until they are filled in. * Do not insert any extra blanks or blank lines.
  • Put compiler directives just before the header (as shown below) but nevertheless after the `### Program' marker. Choose your directives based on your own experience.Here is the C/C++ header (with compiler options) filled out for a youthfulRob Kolstad (my explanatory comments on far right -- do not include them). Do not remove any blank lines -- the automatic grader uses them.You should fill out a header out for each problem with your own data(save it in a file on your computer for easy inclusion on latersubmissions):### Program#pragma option -O2/
  • Problem: 1 (single digit problem number)
    Name: Rob Kolstad (first name then last name)
    Email: (email address)
    School: Norman High School
    Grade: 12 (grade in school, numerical: 7, 8, 9, ..., 13)
    Age: 18
    CityState: Norman, OK
    Country: USA (three letters: CAN, COL, DEU, ROM, USA, etc.)
  • If you live somewhere that has a city but no state, please omit thestate. If your school system uses a notation like `Form 6' for olderstudents, please pro-rate your `Grade' by calculating the equivalentUSA school grade. In the USA: grade 10 students begin around age 15;grade 11 students begin around age 16; grade 12 students begin aroundage 17.Here is the PASCAL header (with compiler options) filled out for ayouthful Rob Kolstad (my comments on far right -- do not include them).Do not remove any blank lines -- the automatic grader uses them. Youshould fill out a header for each problem with your own data (why notsave it in a file on your computer for easy inclusion on latersubmissions):
  • ### Program{$G+,N+}{Problem: 1 (single digit problem number)
    Name: Rob Kolstad (first name then last name)
    Email: (email address)
    School: Norman High School
    Grade: 12 (grade in school, numerical: 7, 8, 9, ..., 13)
    Age: 18
    CityState: Norman, OK
    Country: USA (three letters: CAN, COL, DEU, ROM, USA, etc.)}
  • Watch your mailbox for a quick (automatically-generated) reply. If youdon't see one fairly soon (i.e., 15 minutes) after sending in your solution, send another e-mail to explaining thesituation (including which problem you submitted, when you sent it).