#nullable enable using System.Numerics; void Run() { var n = Int(); var az = n.Repeat(Int).AsSpan(); var bag = new Bag(); foreach (var a in az) bag.Add(a); var ans = 0L; az.Sort(); foreach (var (k, c) in bag._dictionary) { var s = k * 2; var pass = -1; var fail = n; while (fail - pass > 1) { var mid = (pass + fail) >> 1; if (az[mid] < s) pass = mid; else fail = mid; } ans += (long)(pass - c + 1) * c * (c - 1) / 2; } Out(ans); } #region AtCoderIO _io_; var _backend_ = new StandardIOBackend(); _io_ = new(){ Backend = _backend_ }; Run(); _backend_.Flush(); string String() => _io_.Next(); int Int() => int.Parse(String()); void Out(object? x, string? sep = null) => _io_.Out(x, sep); class AtCoderIO { public required StandardIOBackend Backend { get; init; } Memory _input = Array.Empty(); int _iter = 0; public string Next() { while (_iter >= _input.Length) (_input, _iter) = (Backend.ReadLine().Split(' '), 0); return _input.Span[_iter++]; } public void Out(object? x, string? separator = null) { if (x == null) return; separator ??= Environment.NewLine; if (x is System.Collections.IEnumerable a and not string) { var objects = a.Cast(); if (separator == Environment.NewLine && !objects.Any()) return; x = string.Join(separator, objects); } Backend.WriteLine(x); } } class StandardIOBackend { readonly StreamReader _sr = new(Console.OpenStandardInput()); readonly StreamWriter _sw = new(Console.OpenStandardOutput()) { AutoFlush = false }; public string ReadLine() => _sr.ReadLine()!; public void WriteLine(object? value) => _sw.WriteLine(value); public void Flush() => _sw.Flush(); } #endregion static class Extensions { public static T[] Repeat(this int time, Func F) => Enumerable.Range(0, time).Select(_ => F()).ToArray(); } class Bag where K : notnull { public readonly Dictionary _dictionary = new(); public void Add(K key) { var dictionary = _dictionary; if (dictionary.TryGetValue(key, out var count)) dictionary[key] = count + 1; else dictionary[key] = 1; } public void Remove(K key) { var dictionary = _dictionary; if (!dictionary.TryGetValue(key, out var count)) return; if (count == 1) dictionary.Remove(key); else dictionary[key] = count - 1; } public int this[K key] => _dictionary.TryGetValue(key, out var count) ? count : 0; public int CountKeys => _dictionary.Count; }