1.  The local contest director must conduct the contest on April 8. Exceptions, made only in extreme circumstances, would have to be made by contacting the director.


2.   The local contest director must have scheduled five contiguous hours for the contestants to write their programs. If you have more than one contestant, all should write their programs during the same five-hour period if possible.


3.   If this is impossible, the times when two groups solve the problems should overlap.  It is important to keep the problems confidential. Do not communicate or let your students talk with with anyone about the problems via any means (e.g., e-mail, verbally, FAX, telephone) until at least 24 hours after the contest has ended.


4.   Students must work independently and without outside assistance, except as outlined here.


5.   The names on the outside of the sealed envelop is the list of students who are qualified to participate.  When the five hour time period begins, open up the sealed envelope and pass out a copy of the questions to each student. There is also a copy for you.


6.   Provide each contestant with a blank, formatted 3.5" disk (IBM) on which to store and submit his or her programs. Please have them write: USACO 1998, Name, Address, City, State, Zip,email address on the disk. A header form will be needed for each program submitted. The form of this header is provided at the end of this document.


7.      After the five-hour contest is complete, ask each contestant to stop programming and to save their work to the floppy disk.


8.   Fill out and return all the forms provided. Please print clearly.


9.   If you have many students participating from your site, you may copy the work of each participant into a folder and submit many folders on one disk.


10. Students should turn in exactly one program file for each problem that they solve.  That is, don't use multiple C files or Pascal Units that aren't included in Turbo Pascal.


11. The source code names for the problems must be P1.CPP, P2.CPP, P3.CPP, and P4.CPP (for C or C++ programs) or P1.PAS, P2.PAS, P3.PAS, and P4.PAS (for Pascal programs).


12. Do not append program output to the program source files.  They must be able to be compiled as submitted.


13. Do not submit program source code printed on paper. All work must be in electronic form. Each participant is given the list of things to include on his or disk.


14. For each contestant return the filled out Contestant Information Sheet .


15. Mail this material with the disk in a packet that includes the Local Coordinator Information Sheet. We must receive your entries no later than Wednesday, April 17, 1998.


16. All students who submit work to be graded will have their results sent out to all members of the hs-computing list. It is not necessary to return the results of students who do not wish to have their work evaluated and listed.





1.   If a student has questions about a programming or system command, you may provide this information personally or provide a reference book to answer these questions. Of course, students may use paper and pencil to work out their ideas. No calculators are allowed.


2.   All electronic on-line reference material that comes with your compiler is allowed. For example, Borland's Pascal and C/C++ include some on-line reference material that is all you will have available at IOI or at the Final Competition of the USACO in Wisconsin.


3.   If your compiler does not come with this on-line material but only a printed reference book (user's guide) then, of course, you may use this book.


4.   What is not allowed are copies of books or disks (usually programming texts) that contain algorithms for solving specific problems. Books and articles (e.g., programming texts) and disks are not allowed.


5.   You are not required to memorize all the stdlib functions.  You may use the unix man pages.  You may use a Think Pascal Manual but not a Think Pascal Textbook. Generally, refer to books for compiler- or machine-specific information. Do not refer to any references for algorithms or techniques.


6.   We will accept solutions in other versions of  Pascal, C, and C++, but if we can't run the  programs, we can't consider them.  We must be able to test all programs with additional test cases.


8.   If the code fails to compile under Borland C/C++ 4.0, the graders will try compiling under Borland C/C++ 3.1.  If that fails, you haven't written compatible C code.  In particular, don't use the ‘bool' type which is specific to Borland C/C++ 5.0.  If you can compile your code under ANSI C, you're more than safe.




More rules


  • 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!
  • Don Piele 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 or We will reply by e-mail ASAP. Questions judged to be germane to the entire hs-computing list will be summarized and posted there.
  • 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.


  • 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 youthful Rob 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 later submissions):### 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 the state. If your school system uses a notation like `Form 6' for older students, please pro-rate your `Grade' by calculating the equivalent USA school grade. In the USA: grade 10 students begin around age 15;grade 11 students begin around age 16; grade 12 students begin around age 17.Here is the PASCAL header (with compiler options) filled out for a youthful Rob Kolstad (my 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 for each problem with your own data (why not save it in a file on your computer for easy inclusion on later submissions):
  • ### 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.)}




Thank you for your cooperation.  Deadline for material to be in our hands is Wednesday, April 17, 1998. The top 12-16 contestants will be announced on our hs-computing list ( and on our WWW page (


If you have any questions, please contact the contest director, Don Piele, at TEL: 414-634-0868 or 414-595-2231; e-mail:



Mail to:

Dr. Don Piele


University of Wisconsin-Parkside

900 Wood Rd.

Kenosha, WI  53141