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 Microsoft Visual C# Compiler version (codename Roslyn) which is included in Visual Studio 2017. It implements C# language version 7.1 and targets to .NET Framework 4.7. The compiler is invoked with the following arguments:

csc /o+ /d:ONLINE_JUDGE /r:System.Numerics.dll

The default stack size is set to 64 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 the Microsoft Visual C# 2005 Compiler 8.00.50727.42 (.NET 2.0) was used.
  • Before August 4, 2010 the Microsoft Visual C# 2008 Compiler version 3.5.30729.1 (.NET 3.5) was used.
  • Before September 1, 2017 the 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.