C# program is giving runtime error. What is wrong here

I faced this issue (runtime error)in several contests.
Every time I try to solve problems using C# language it throws me a runtime error.
Let’s take example:

Today I tried to solve easy program from Overnite Coding contest » Transitions.
Here is the solution:

using System;
using System.Linq;

namespace CodeOverflow_1._1
    public class TRNSN
        public static void Main(string[] args)
            int length = Convert.ToInt32(Console.ReadLine());
            var result = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse).Distinct().Count() - 1;

or without any linq operations

using System;
using System.Linq;
using System.Collections.Generic;
public class Test
	public static void Main()

            int length = Convert.ToInt32(Console.ReadLine());
            var inputs = Console.ReadLine().Split(' ');

            List<long> list = new List<long>();
            long count = 0;
            foreach (var input in inputs)
            for (int i = 0; i < length - 1; i++)
                if (list[i] != list[i + 1])

Other solutions:


When I check others solution, they used the same logic but with a different language. Why this code is not working? the logic seems correct to me.

Any help would really appreciated.

There were some extra white-spaces in a test-case which went overlooked while testing. I think that is what might’ve caused the problem to happen. Apologies for the inconvenience.

Hey @ kevinmathew, Thanks for your reply but I faced same issues in other contest as well. When I try to solve it with C#, linq and other built-in functions of C# it get failed.

Is there any specific reason for it. If I faced similar kind of issues then whom I should contact? As I have seen few people(like 2-3) prefer C# as a language to solve problems in such contest.

Sorry about the late reply, I hadn’t seen your reply.

I’m not much familiar with C#, but I can guarantee that you will very rarely find contests which have been tested for solutions in C#. In fact ICPC recommends using Java, Kotlin, Python or C/C++. So I would strongly recommend shifting to one of these for CP, and avoid such disadvantage. C++ is the safest option.

1 Like

Thanks for your @kevinmathew, really appreciated your response. It will be difficult to move from one language to other (after having 5 years of experience).
I love to participate in competitions, so I will go with Python will try to solve problems.

Once again, thanks for your help