2017-09-13 18:00 CEST

Wed Sept 13


2017-09-13 20:20 CEST
The end is near!
Contest is over.
Not yet started.
Contest is starting in -7 days 2:28:31

Time elapsed


Time remaining


Language: Java

General information

You start out by finding a suitable problem to solve. Then you write code to solve the problem. After this, you submit the code to us for review. We will then compile your code and run it on some secret input. After some careful deliberation, you will get a judgement informing you whether your code behaved as expected or not.


Your program should read its input from standard input and produce output on standard output. This can for instance be done using / System.out. Anything written on standard error (System.err) will be ignored. This can be used for debugging your program during development (i.e., you do not have to remove debug output before submitting if you use standard error for debug output). Of course, writing to standard error will take some runtime.

Input will always follow the input specification (so you do not need to validate the input). Your output must follow the output specification.

Compiler settings

For Java, we use OpenJDK version javac 1.8.0_131 with the following flags: -encoding UTF-8 -sourcepath {path} -d {path} {files}.

Runtime settings

For Java, we use the following runtime flags: -XX:+UseSerialGC -Xss64m -Xms{memlim}m -Xmx{memlim}m -Dfile.encoding=UTF-8 -cp {path}.

Here {memlim} is the actual memory limit for the problem you are submitting to.

System libraries

You are allowed to use all standard libraries included with Java.


We are currently running on a Dell PowerEdge R620 server with 16 Intel Xeon E5-2660 CPUs and 128GB RAM. A 64-bit Linux kernel is used.


We will inspect the exit code of your program. If it is non-zero, we will judge your submission as Run Time Error.

Solving a problem

Now lets get down to business and write some code. The short tutorial below goes through the solution of A Different Problem.

  1. The problem
  2. Reading the input
  3. Computing the answer
  4. The solution

Step 1: The problem

You are tasked with writing a program that computes the difference between integers. Sounds simple, doesn't it? Well, as we will see, the problem still holds some small difficulties.

Step 2: Reading the input

One thing to note is that the integers can be fairly large, as large as 1015, which is a lot larger than the maximum value of an int (which is 231−1). Luckily, there is a 64 bit integer type in Java, long.

Now that we have determined a suitable type, we just have to read the data. Reading is done from standard input. In this problem, we should read until the end of the file (in other problems, there might be an integer at the beginning of the input, specifying how much to read, or there might be a special indicator denoting that there is nothing more to read). Using a Scanner (which needs to be imported, since it is in the java.util package), we can do e.g.:

Scanner sc = new Scanner(; while (sc.hasNextLong()) { long a = sc.nextLong(), b = sc.nextLong(); // solve test case and output answer }

Step 3: Computing the answer

Now that we've read the input, it's time to actually solve the problem. Since 0 ≤ a, b ≤ 1015, we have that −(1015) ≤ ab ≤ 1015, which means that there is no danger of overflow involved in just subtracting the two numbers a and b. Then, we can just take the absolute value by using the Math.abs function.

Finally, it's time to print the result. Using system.out.println() (assuming the long variable r holds the result):


Step 4: The solution

Now we are basically done, all that remains is to combine the above parts.

Here is a version of the complete solution.

Frequently asked questions


I keep getting rejected but my solution works on the provided cases

The sample data provided in the problem statement is just there to help you make sure you understood what the problem asks for, and the input/output format. When you submit your solution, we will run it on an extensive set of additional test data to verify that it solves the problem correctly and efficiently.

When we run your solution, the first case(s) are always the sample case(s). If you fail on these, make sure that:

  1. You are not printing any output other than the one specified in the problem.
  2. You have not misspelled any part of the output (copy-paste is your friend).
  3. You are printing real-valued numbers with the precision requested in the problem.
If this does not help you get past the sample cases, make sure that there isn't a difference in system and compiler that causes your solution to behave differently when run on the judge machine.

I keep failing on testcase X. Can you please share it with me?

Sorry, no. We can't share the secret testdata.

There is an error in the sample data of the problem, can you please fix it?

The sample data is used to illustrate and clarify the problem. If you believe there is an error in the sample data, your interpretation of the problem is probably wrong. Consider if there is an alternative interpretation which matches the sample data.

How does judging work, and what do the different judgements mean, precisely?

See the judgements page.

Interacting with the judge system

Can I test my solution before I submit?

No, however we allow you to submit your solution multiple times so you can test your way to the right solution.

Do you store my submissions?

Yes, we store your submissions. Occasionally a problem is found with one of the problems (no pun intended) or a time limit is changed (this should not happen frequently) and then we need to rejudge all submissions on that problem. We also use the code to check for plagiarism.

I found a bug? / I have a question that is not answered in the documentation. / I think this or that would be much better if it worked like this instead.

Please contact us and tell us about it.

Java-specific questions

What happens with Java exceptions?

Uncaught java exceptions will almost always be judged as Run Time Errors with some extra information. For a few exceptions, you will get to know what the exception was (but no stack trace or line number), for most you will just be informed that you got an uncaught exception. Exceptions relating to memory exhaustion will be judged Memory Limit Exceeded, for obvious reasons.

What is the mainclass for Java? Why do I get "Unknown mainclass"?

The mainclass is the class containing the entry point (main method) of your program. It is a method that looks like this:

public static void main(String[] args)

As you can submit multiple classes, there can potentially be multiple such methods. Therefore you need to specify which class contains the main method we should use. Note that the mainclass must contain the full name of the class. If you declare a package, it must be included (or we will not find your class). For example, if your class name is "Solution" and it is in package "fuzzy" your mainclass should be "fuzzy.Solution".

Specifying the wrong mainclass will give you a Compile Error telling you what happened.

I'm having trouble with I/O performance. What can I do about it?

It is, as far as we are aware, impossible to do fast I/O in Java without going through immense pains. If you know better, we'd be very grateful to hear about it. It is, however, quite possible to get decent I/O speeds with only small efforts.

There are several things which will cause input in Java to be slow. One such thing is the Scanner class, which even though it is quite handy and easy to use, tends to be very slow even for such a simple task as reading a stream of integers.

Another very important thing is to always make sure that both input and output are buffered, by using e.g. the BufferedReader and BufferedOutputStream classes.

To simplify matters, we have written a small utility class for you, called This class provides both input and output functionality, and will be fast enough for any problem on the Judge.

What locale is used (useful for e.g. printf in Java)?

The following lines:

System.out.println(Locale.getDefault()); System.out.println(String.format("%f", 1000 * Math.PI)); System.out.printf("%f\n", 1000 * Math.PI);


en_US 3141.592654 3141.592654

External documentation

  1. Java SE