ENG  RUSTimus Online Judge
Online Judge
Online contests
About Online Judge
Frequently asked questions
Site news
Problem set
Submit solution
Judge status
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests

How to write C# solutions

Programs written in C# language are compiled on the server with Visual C# 2019. Compiler version: Roslyn 3.6.0. It supports C# language version 8.0 and targets to .NET Core 3.1. The compiler is invoked with the following arguments:

csc /o+ /d:ONLINE_JUDGE %1

The default stack size is set to 1 MB.

Examples of solving problems

This is a sample solution for the A + B problem in the C# language:

using System;

public class Sum
    private static void Main()
        string[] tokens = Console.ReadLine().Split(' ');
        Console.WriteLine(int.Parse(tokens[0]) + int.Parse(tokens[1]));

Here is an example of a simple solution for the Reverse root problem in the C# language. It demonstrates some language features but it’s not the most efficient one. With character by character input you can get much less working time and memory usage.

using System;
using System.Globalization;

public class ReverseRoot
   private static void Main()
      NumberFormatInfo nfi = NumberFormatInfo.InvariantInfo;
      string[] input = Console.In.ReadToEnd().Split(
         new char[] {' ', '\t', '\n', '\r'},
      for (int i = input.Length - 1; i >= 0; i--)
         double root = Math.Sqrt(double.Parse(input[i], nfi));
         Console.WriteLine(string.Format(nfi, "{0:F4}", root));


The standard input/output methods like Console.ReadLine, String.Split and Console.WriteLine are not always sufficient. In some problems it’s necessary to manually implement fast input reading or output formatting.

In some problems numbers are not necessarily separated with single space. Instead of

Console.ReadLine().Trim().Split(' ')

use this code

Console.ReadLine().Split(new char[] {' ', '\t'},

Do not forget that the program can have any default culture. This is important when you need to read or write floating-point numbers: decimal separator can be configured in the system equal to either “.” or “,”. Currently the separator is set to “.” on the server, but it may be changed in the future. In order not to face culture problems pass invariant culture to all parse/formatting operation or set default culture for whole program:

Thread.CurrentThread.CurrentCulture =

Earlier compilers

  • Since December 31, 2006 till February 8, 2009, Microsoft Visual C# 2005 Compiler 8.00.50727.42 (.NET 2.0) was used.
  • Before August 4, 2010, Microsoft Visual C# 2008 Compiler version 3.5.30729.1 (.NET 3.5) was used.
  • Before September 1, 2017, Microsoft Visual C# 2010 Compiler version 4.0.30319.1 (.NET 4.0) was used.
  • Since February 18, 2013 till September 1, 2017, Microsoft Visual Basic 2010 (.NET 4.0) was used.
  • Before September 1, 2020, Visual C# 2017 (Roslyn 2.3.2 / C# 7.1 / .NET 4.7) was used.