Avoid Package Declarations in Codeforces Java | Generated by AI

Home 2026.01

Question: What happens if I include a package declaration like package com.lzw.solutions.codeforces.p2190B1; at the top when submitting a Java solution to Codeforces? Will it cause a runtime error?

Answer:

Yes — it will cause a compilation error, not a runtime error.

Codeforces does not allow package declarations in submitted Java solutions.

When you submit code that starts with:

package com.lzw.solutions.codeforces.p2190B1;

Codeforces compiler will reject it with a message similar to:

Why this happens

Codeforces compiles your Java code in a very simple way:

Because of this:

Correct version (what you should submit)

Just remove the package line:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {

    private BufferedReader in;
    private PrintWriter out;

    public Main() {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
    }

    public static void main(String[] args) throws IOException {
        Main m = new Main();
        m.solve();
        m.close();
    }

    private void close() {
        out.flush();
        out.close();
    }

    private void solve() throws IOException {
        int t = Integer.parseInt(in.readLine());
        while (t-- > 0) {
            int n = Integer.parseInt(in.readLine());
            String s = in.readLine();
            // assert (s.length() == n);   ← remove or comment out in real submission
            out.println(s);
        }
    }
}

Quick summary — what to remember for Codeforces Java submissions

Good luck with your Codeforces problems!


Back

x-ai/grok-4.1-fast

Donate