Language: C++

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using static System.Math;

namespace CompetitionPrograming2
{
    public sealed class Program : BaseProgram
    {
        public static void Main(string[] args)
        {
            using (var sc = new SetConsole()) { Solve(); }
        }
        public static void Solve()
        {
            var n = GetNumber<int>();
            var ls = GetArray<int>().OrderBy(l => l).ToList();
            var count = 0;
            for (int bIndex = 1; bIndex < n; bIndex++)
            {
                for (int aIndex = 0; aIndex < bIndex; aIndex++)
                {
                    var upperLimit = ls.BinarySearch(ls[bIndex] + ls[aIndex]);
                    if (upperLimit < 0)
                    {
                        upperLimit = upperLimit * -1 - 1;
                    }
                    count += upperLimit - bIndex - 1;
                }
            }
            Write(count);
        }
    }

    public class BaseProgram
    {
        protected readonly static long divisor = 1000000007;

        protected static void Write(object obj) => Console.WriteLine(obj);
        protected static string GetString()
        {
            var str = Console.ReadLine();
            if (str == null) { throw new NullReferenceException("標準入力がnullです Solveメソッド内の解答コードが間違っています"); }
            return str;
        }
        protected static T GetNumber<T>() where T : IComparable, IComparable<T>, IConvertible, IEquatable<T>, IFormattable
        {
            var str = GetString();
            var t = typeof(T);
            if ((t == typeof(byte)))
            {
                return (T)(object)str.ToByte();
            }
            else if (t == typeof(int))
            {
                return (T)(object)str.ToInt();
            }
            else if (t == typeof(long))
            {
                return (T)(object)str.ToLong();
            }
            else if (t == typeof(double))
            {
                return (T)(object)str.ToDouble();
            }
            throw new NotSupportedException();
        }
        protected static T[] GetArray<T>() where T : IComparable, IComparable<T>, IConvertible, IEquatable<T>, IFormattable
        {
            return GetString().ToArray<T>();
        }
        protected static TResult[] GetArray<TResult>(Func<string, TResult> selector)
        {
            return (TResult[])(object)GetString().Split().Select(selector).ToArray();
        }
        protected static void Swap<T>(ref T item1, ref T item2)
        {
            var tmp = item1;
            item1 = item2;
            item2 = tmp;
        }
        protected sealed class SetConsole : IDisposable
        {
            readonly StreamWriter sw = new StreamWriter(Console.OpenStandardOutput());
            public SetConsole()
            {
                sw.AutoFlush = false;
                Console.SetOut(sw);
            }
            public void Dispose()
            {
                Console.Out.Flush();
                sw.AutoFlush = true;
                Console.SetOut(sw);
            }
        }
    }

    static class ExtentionsLibrary
    {
        public static T[,] CopyArray<T>(this T[,] array)
        {
            var firstDimentionLength = array.GetLength(0);
            var secondDimentionLength = array.GetLength(1);
            var newDArray = new T[firstDimentionLength, secondDimentionLength];
            Array.Copy(array, newDArray, firstDimentionLength * secondDimentionLength);
            return newDArray;
        }
        public static T[] ToArray<T>(this string str) where T : IComparable, IComparable<T>, IConvertible, IEquatable<T>, IFormattable
        {
            if (typeof(T) == typeof(string)) { return (T[])(object)str.Split(); }

            return str.ConvertEnumerator<T>().ToArray();
        }
        public static IEnumerable<T> ConvertEnumerator<T>(this string str) where T : IComparable, IComparable<T>, IConvertible, IEquatable<T>, IFormattable
        {
            var t = typeof(T);
            if (t == typeof(byte))
            {
                return (IEnumerable<T>)str.Split().Select(byte.Parse);
            }
            if (t == typeof(int))
            {
                return (IEnumerable<T>)str.Split().Select(int.Parse);
            }
            if (t == typeof(long))
            {
                return (IEnumerable<T>)str.Split().Select(long.Parse);
            }
            if (t == typeof(double))
            {
                return (IEnumerable<T>)str.Split().Select(double.Parse);
            }
            if (t == typeof(BigInteger))
            {
                return (IEnumerable<T>)str.Split().Select(BigInteger.Parse);
            }
            throw new NotSupportedException();
        }
        public static byte ToByte(this string str) => byte.Parse(str);
        public static byte ToByte(this char chr) => byte.Parse(chr.ToString());
        public static int ToInt(this string str) => int.Parse(str);
        public static int ToInt(this char chr) => int.Parse(chr.ToString());
        public static long ToLong(this string str) => long.Parse(str);
        public static double ToDouble(this string str) => double.Parse(str);
        public static BigInteger ToBigInteger(this string str) => BigInteger.Parse(str);
        public static DateTime ToDateTime(this string str) => DateTime.Parse(str);
        public static string StringJoin(this object[] array, string separator) => string.Join(separator, array);
        public static string StringJoin<T>(this IEnumerable<T> collection, string separator) => string.Join(separator, collection.Select(c => c.ToString()));
    }

    public sealed class Settings
    {
        public enum Priority : byte
        {
            Smaller = 0,
            Larger = 1
        }
    }
}


Compiler output:
a.cc:1:7: error: expected nested-name-specifier before 'System'
    1 | using System;
      |       ^~~~~~
a.cc:2:7: error: expected nested-name-specifier before 'System'
    2 | using System.Collections.Generic;
      |       ^~~~~~
a.cc:3:7: error: expected nested-name-specifier before 'System'
    3 | using System.IO;
      |       ^~~~~~
a.cc:4:7: error: expected nested-name-specifier before 'System'
    4 | using System.Linq;
      |       ^~~~~~
a.cc:5:7: error: expected nested-name-specifier before 'System'
    5 | using System.Numerics;
      |       ^~~~~~
a.cc:6:7: error: expected nested-name-specifier before 'static'
    6 | using static System.Math;
      |       ^~~~~~
a.cc:10:5: error: expected unqualified-id before 'public'
   10 |     public sealed class Program : BaseProgram
      |     ^~~~~~
a.cc:37:5: error: expected unqualified-id before 'public'
   37 |     public class BaseProgram
      |     ^~~~~~
a.cc:103:15: error: expected ':' before 'static'
  103 |         public static T[,] CopyArray<T>(this T[,] array)
      |               ^~~~~~~
      |               :
a.cc:103:23: error: 'T' does not name a type
  103 |         public static T[,] CopyArray<T>(this T[,] array)
      |                       ^
a.cc:111:15: error: expected ':' before 'static'
  111 |         public static T[] ToArray<T>(this string str) where T : IComparable, IComparable<T>, IConvertible, IEquatable<T>, IFormattable
      |               ^~~~~~~
      |               :
a.cc:111:23: error: 'T' does not name a type
  111 |         public static T[] ToArray<T>(this string str) where T : IComparable, IComparable<T>, IConvertible, IEquatable<T>, IFormattable
      |                       ^
a.cc:117:15: error: expected ':' before 'static'
  117 |         public static IEnumerable<T> ConvertEnumerator<T>(this string str) where T : IComparable, IComparable<T>, IConvertible, IEquatable<T>, IFormattable
      |               ^~~~~~~
      |               :
a.cc:117:23: error: 'IEnumerable' does not name a type
  117 |         public static IEnumerable<T> ConvertEnumerator<T>(this string str) where T : IComparable, IComparable<T>, IConvertible, IEquatable<T>, IFormattable
      |                       ^~~~~~~~~~~
a.cc:142:15: error: expected ':' before 'static'
  142 |         public static byte ToByte(this string str) => byte.Parse(str);
      |               ^~~~~~~
      |               :
a.cc:142:23: error: 'byte' does not name a type
  142 |         public static byte ToByte(this string str) => byte.Parse(str);
      |                       ^~~~
a.cc:143:15: error: expected ':' before 'static'
  143 |         public static byte ToByte(this char chr) => byte.Parse(chr.ToString());
      |               ^~~~~~~
      |               :
a.cc:143:23: error: 'byte' does not name a type
  143 |         public static byte ToByte(this char chr) => byte.Parse(chr.ToString());
      |                       ^~~~
a.cc:144:15: error: expected ':' before 'static'
  144 |         public static int ToInt(this string str) => int.Parse(str);
      |               ^~~~~~~
      |               :
a.cc:144:38: error: 'string' has not been declared
  144 |         public static int ToInt(this string str) => int.Parse(str);
      |                                      ^~~~~~
a.cc:144:53: error: invalid pure specifier (only '= 0' is allowed) before 'int'
  144 |         public static int ToInt(this string str) => int.Parse(str);
      |                                                     ^~~
a.cc:144:45: warning: explicit object member function only available with '-std=c++23' or '-std=gnu++23' [-Wc++23-extensions]
  144 |         public static int ToInt(this string str) => int.Parse(str);
      |                                 ~~~~~~~~~~~~^~~
a.cc:144:16: error: an explicit object member function cannot be 'static'
  144 |         public static int ToInt(this string str) => int.Parse(str);
      |                ^~~~~~
a.cc:144:45: note: explicit object parameter declared here
  144 |         public static int ToInt(this string str) => int.Parse(str);
      |                                 ~~~~~~~~~~~~^~~
a.cc:144:27: error: initializer specified for static member function 'int CompetitionPrograming2::ExtentionsLibrary::ToInt(this int)'
  144 |         public static int ToInt(this string str) => int.Parse(str);
      |                           ^~~~~
a.cc:145:15: error: expected ':' before 'static'
  145 |         public static int ToInt(this char chr) => int.Parse(chr.ToString());
      |               ^~~~~~~
      |               :
a.cc:145:51: error: invalid pure specifier (only '= 0' is allowed) before 'int'
  145 |         public static int ToInt(this char chr) => int.Parse(chr.ToString());
      |                                                   ^~~
a.cc:145:43: warning: explicit object member function only available with '-std=c++23' or '-std=gnu++23' [-Wc++23-extensions]
  145 |         public static int ToInt(this char chr) => int.Parse(chr.ToString());
      |                                 ~~~~~~~~~~^~~
a.cc:145:16: error: an explicit object member function cannot be 'static'
  145 |         public static int ToInt(this char chr) => int.Parse(chr.ToString());
      |                ^~~~~~
a.cc:145:43: note: explicit object parameter declared here
  145 |         public static int ToInt(this char chr) => int.Parse(chr.ToString());
      |                                 ~~~~~~~~~~^~~
a.cc:145:27: error: initializer specified for static member function 'int CompetitionPrograming2::ExtentionsLibrary::ToInt(this char)'
  145 |         public static int ToInt(this char chr) => int.Parse(chr.ToString());
      |                           ^~~~~
a.cc:146:15: error: expected ':' before 'static'
  146 |         public static long ToLong(this string str) => long.Parse(str);
      |               ^~~~~~~
      |               :
a.cc:146:40: error: 'string' has not been declared
  146 |         public static long ToLong(this string str) => long.Parse(str);
      |                                        ^~~~~~
a.cc:146:55: error: invalid pure specifier (only '= 0' is allowed) before 'long'
  146 |         public static long ToLong(this string str) => long.Parse(str);
      |                                                       ^~~~
a.cc:146:47: warning: explicit object member function only available with '-std=c++23' or '-std=gnu++23' [-Wc++23-extensions]
  146 |         public static long ToLong(this string str) => long.Parse(str);
      |                                   ~~~~~~~~~~~~^~~
a.cc:146:16: error: an explicit object member function cannot be 'static'
  146 |         public static long ToLong(this string str) => long.Parse(str);
      |                ^~~~~~
a.cc:146:47: note: explicit object parameter declared here
  146 |         public static long ToLong(this string str) => long.Parse(str);
      |                                   ~~~~~~~~~~~~^~~
a.cc:146:28: error: initializer specified for static member function 'long int CompetitionPrograming2::ExtentionsLibrary::ToLong(this int)'
  146 |         public static long ToLong(this string str) => long.Parse(str);
      |                            ^~~~~~
a.cc:147:15: error: expected ':' before 'static'
  147 |         public static double ToDouble(this string str) => double.Parse(str);
      |               ^~~~~~~
      |               :
a.cc:147:44: error: 'string' has not been declared
  147 |         public static double ToDouble(this string str) => double.Parse(str);
      |                                            ^~~~~~
a.cc:147:59: error: invalid pure specifier (only '= 0' is allowed) before 'double'
  147 |         public static double ToDouble(this string str) => double.Parse(str);
      |                                                           ^~~~~~
a.cc:147:51: warning: explicit object member function only available with '-std=c++23' or '-std=gnu++23' [-Wc++23-extensions]
  147 |         public static double ToDouble(this string str) => double.Parse(str);
      |                                       ~~~~~~~~~~~~^~~
a.cc:147:16: error: an explicit object member function cannot be 'static'
  147 |         public static double ToDouble(this string str) => double.Parse(str);
      |                ^~~~~~
a.cc:147:51: note: explicit object parameter declared here
  147 |         public static double ToDouble(this string str) => double.Parse(str);
      |                                       ~~~~~~~~~~~~^~~
a.cc:147:30: error: initializer specified for static member function 'double CompetitionPrograming2::ExtentionsLibrary::ToDouble(this int)'
  147 |         public static double ToDouble(this string str) => double.Parse(str);
      |                              ^~~~~~~~
a.cc:148:15: error: expected ':' before 'static'
  148 |         public static BigInteger ToBigInteger(this string str) => BigInteger.Parse(str);
      |               ^~~~~~~
      |               :
a.cc:148:23: error: 'BigInteger' does not name a type
  148 |         public static BigInteger ToBigInteger(this string str) => BigInteger.Parse(str);
      |                       ^~~~~~~~~~
a.cc:149:15: error: expected ':' before 'static'
  149 |         public static DateTime ToDateTime(this string str) => DateTime.Parse(str);
      |               ^~~~~~~
      |               :
a.cc:149:23: error: 'DateTime' does not name a type
  149 |         public static DateTime ToDateTime(this string str) => DateTime.Parse(str);
      |                       ^~~~~~~~
a.cc:150:15: error: expected ':' before 'static'
  150 |         public static string StringJoin(this object[] array, string separator) => string.Join(separator, array);
      |               ^~~~~~~
      |               :
a.cc:150:23: error: 'string' does not name a type
  150 |         public static string StringJoin(this object[] array, string separator) => string.Join(separator, array);
      |                       ^~~~~~
a.cc:151:15: error: expected ':' before 'static'
  151 |         public static string StringJoin<T>(this IEnumerable<T> collection, string separator) => string.Join(separator, collection.Select(c => c.ToString()));
      |               ^~~~~~~
      |