結果

問題 No.5007 Steiner Space Travel
ユーザー g4np0ng4np0n
提出日時 2022-07-30 17:03:23
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 968 ms / 1,000 ms
コード長 23,585 bytes
コンパイル時間 8,548 ms
実行使用メモリ 173,084 KB
スコア 8,231,976
最終ジャッジ日時 2022-07-30 17:04:08
合計ジャッジ時間 40,376 ms
ジャッジサーバーID
(参考情報)
judge10 / judge11
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 964 ms
40,272 KB
testcase_01 AC 966 ms
40,312 KB
testcase_02 AC 965 ms
40,620 KB
testcase_03 AC 965 ms
41,048 KB
testcase_04 AC 966 ms
40,408 KB
testcase_05 AC 966 ms
40,504 KB
testcase_06 AC 965 ms
41,200 KB
testcase_07 AC 965 ms
40,644 KB
testcase_08 AC 964 ms
40,788 KB
testcase_09 AC 968 ms
40,340 KB
testcase_10 AC 964 ms
40,948 KB
testcase_11 AC 965 ms
40,836 KB
testcase_12 AC 965 ms
41,240 KB
testcase_13 AC 963 ms
39,860 KB
testcase_14 AC 966 ms
40,340 KB
testcase_15 AC 968 ms
40,924 KB
testcase_16 AC 966 ms
40,480 KB
testcase_17 AC 966 ms
40,524 KB
testcase_18 AC 966 ms
40,504 KB
testcase_19 AC 965 ms
40,468 KB
testcase_20 AC 965 ms
40,560 KB
testcase_21 AC 963 ms
40,584 KB
testcase_22 AC 964 ms
40,504 KB
testcase_23 AC 964 ms
40,568 KB
testcase_24 AC 964 ms
40,432 KB
testcase_25 AC 965 ms
40,312 KB
testcase_26 AC 965 ms
40,360 KB
testcase_27 AC 965 ms
40,352 KB
testcase_28 AC 965 ms
40,444 KB
testcase_29 AC 965 ms
173,084 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  Determining projects to restore...
  Restored /home/judge/data/code/main.csproj (in 119 ms).
.NET 向け Microsoft (R) Build Engine バージョン 17.0.0-preview-21470-01+cb055d28f
Copyright (C) Microsoft Corporation.All rights reserved.

  プレビュー版の .NET を使用しています。https://aka.ms/dotnet-core-preview をご覧ください
/home/judge/data/code/Main.cs(132,17): warning CS0219: 変数 'min' は割り当てられていますが、その値は使用されていません [/home/judge/data/code/main.csproj]
/home/judge/data/code/Main.cs(18,17): warning CS0414: フィールド 'Program.A' が割り当てられていますが、値は使用されていません [/home/judge/data/code/main.csproj]
  main -> /home/judge/data/code/bin/Release/net6.0/main.dll
  main -> /home/judge/data/code/bin/Release/net6.0/publish/

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using static System.Math;

partial class Program
{
    static int[] dx = new int[] { 1, 0, -1, 0, 1, -1, -1, 1 };
    static int[] dy = new int[] { 0, 1, 0, -1, 1, 1, -1, -1 };
    const long mod = 1000000007;
    //const long mod = 998244353;
    static Random rnd = new Random();
    static Stopwatch sw = new Stopwatch();
    static long A = 5;

    public void Solve()
    {
        sw.Start();
        var (N, M) = io.GetMulti<int, int>();
        var planets = io.GetIntArray(N).Select((e, id) => new Pos(e[0], e[1], id)).ToArray();

        var stations = new Pos[M];
        stations[0] = new Pos(500, 500, N + 0);
        for (int i = 0; i < M - 1; i++)
        {
            stations[i + 1] = new Pos(500 + (long)(200 * Cos(2 * PI / 7 * i)), 500 + (long)(200 * Sin(2 * PI / 7 * i)), N + i + 1);
        }

        var G = (long.MaxValue / 3).Repeat(N + M, N + M);
        for (int i = 0; i < N + M; i++) G[i][i] = 0;
        var dijkstra = new Dijkstra(N);
        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j < N; j++)
            {
                if (i == j) continue;
                G[i][j] = planets[i].Length(planets[j]);
                dijkstra.AddDirectedEdge(i, j, planets[i].Length(planets[j]));
            }
        }
        var len = new long[N][];
        var path = new int[N][][];
        for (int i = 0; i < N; i++)
        {
            len[i] = dijkstra.GetDist(i);
            path[i] = new int[N][];
            for (int j = 0; j < N; j++) path[i][j] = dijkstra.GetPath(j);
        }

        var now = 0;
        var visited = new bool[N];
        visited[0] = true;
        var visitedCnt = 1;
        var ans = new List<Pos>();
        ans.Add(planets[0]);
        long S = 0;
        while (visitedCnt != N)
        {
            var next = -1;
            var min = long.MaxValue;
            for (int i = 0; i < N; i++)
            {
                if (visited[i]) continue;
                if (min.Chmin(len[now][i])) next = i;
            }
            S += min;
            ans.AddRange(path[now][next].Select(e => planets[e]));
            visited[next] = true;
            visitedCnt++;
            now = next;
        }
        ans.AddRange(path[now][0].Select(e => planets[e]));
        S += len[now][0];

        TSP(ans);
        var newAns = new List<Pos>();
        foreach (var a in ans)
        {
            if (newAns.Count == 0 || newAns.Last().id != a.id) newAns.Add(a);
        }
        ans = newAns;
        Console.Clear();

        var bestList = ans;
        var bestScore = Score(ans, stations);

        var yamaCnt = 0;
        while (sw.ElapsedMilliseconds < 900)
        {
            yamaCnt++;
            var sidx = rnd.Next(M);
            var oldX = stations[sidx].x;
            var oldY = stations[sidx].y;
            var delta = 400 * (int)((900 - sw.ElapsedMilliseconds) / sw.ElapsedMilliseconds);
            var nx = oldX + rnd.Next(-delta, delta);
            var ny = oldY + rnd.Next(-delta, delta);

            stations[sidx].x = nx;
            stations[sidx].y = ny;
            var ng = false;
            for(int i = 0; i < M; i++)
            {
                if (i == sidx) continue;
                if (stations[sidx].Length(stations[i]) < 10000) ng = true;
            }
            if (ng)
            {
                stations[sidx].x = oldX;
                stations[sidx].y = oldY;
                continue;
            }

            var score = Score(bestList, stations);
            if (!bestScore.Chmax(score))
            {
                stations[sidx].x = oldX;
                stations[sidx].y = oldY;
            }
        }

        newAns = new List<Pos>();
        newAns.Add(planets[0]);
        for (int i = 0; i < bestList.Count - 1; i++)
        {
            var p = planets[bestList[i].id];
            var next = planets[bestList[i + 1].id];
            var l = p.Length(next);
            var min = long.MaxValue;
            var s = -1;
            for (int j = 0; j < M; j++)
            {
                if (l.Chmin(p.Length(stations[j]))) s = j;
            }
            if (s != -1) newAns.Add(stations[s]);
            newAns.Add(next);
        }

        ans = newAns;
        TSP(ans);
        for (int i = 0; i < M; i++) io.Print($"{stations[i].x} {stations[i].y}");
        Console.WriteLine(ans.Count);
        for (int i = 0; i < ans.Count; i++) Console.WriteLine($"{1 + ans[i].id / N} {ans[i].id % N + 1}");

        //Console.WriteLine(yamaCnt);
    }

    long Score(long length)
    {
        return (long)Round(1000000000 / (1000 + Sqrt(length)));
    }

    long Score(List<Pos> arr, Pos[] stations)
    {
        long sum = 0;
        for (int i = 0; i < arr.Count - 1; i++)
        {
            var min = arr[i].Length(arr[i + 1]);
            for (int j = 0; j < 5; j++)
            {
                min.Chmin(arr[i].Length(stations[j]) + stations[j].Length(arr[i + 1]));
            }
            sum += min;
        }
        return Score(sum);
    }

    class Dijkstra
    {
        public Dijkstra(int V)
        {
            this.V = V;
            G = new List<(int to, long dist)>[V];
            for (int i = 0; i < V; i++)
            {
                G[i] = new List<(int to, long dist)>();
            }
            from = new int[this.V];
        }
        long _INF = long.MaxValue;
        int V;
        List<(int to, long dist)>[] G;
        int[] from;

        /// <summary>
        /// 無向辺を追加します。
        /// </summary>
        public void AddEdge(int u, int v, long dist)
        {
            G[u].Add((v, dist));
            G[v].Add((u, dist));
        }

        /// <summary>
        /// 有向辺を追加します。
        /// </summary>
        public void AddDirectedEdge(int from, int to, long dist)
        {
            G[from].Add((to, dist));
        }

        /// <summary>
        /// 各頂点への最短経路長を求めます。
        /// 計算量はO((E+V)logV)です。
        /// </summary>
        public long[] GetDist(int s)
        {
            var dist = new long[V];
            dist.AsSpan().Fill(_INF);
            from = new int[V];
            from.AsSpan().Fill(-1);
            var pq = new PriorityQueue<int>();
            dist[s] = 0;
            pq.Enqueue(0, s);
            while (pq.Count > 0)
            {
                var (d, v) = pq.Dequeue();
                if (dist[v] != d) continue;
                foreach (var edge in G[v])
                {
                    var alt = d + edge.dist;
                    if (alt >= dist[edge.to]) continue;
                    dist[edge.to] = alt;
                    from[edge.to] = v;
                    pq.Enqueue(alt, edge.to);
                }
            }
            for (int i = 0; i < V; i++) if (dist[i] == _INF) dist[i] = -1;
            return dist;
        }

        public int[] GetPath(int t)
        {
            var now = t;
            var ls = new List<int>();
            while (from[t] != -1)
            {
                ls.Add(t);
                t = from[t];
            }
            ls.Reverse();
            return ls.ToArray();
        }
    }

    class PriorityQueue<T>
    {
        /// <summary>
        /// 空の優先度付きキューを生成します。
        /// </summary>
        public PriorityQueue()
        {
            _keys = new List<long>();
            _elements = new List<T>();
        }
        List<long> _keys;
        List<T> _elements;

        /// <summary>
        /// 優先度付きキューに要素を追加します。
        /// 計算量は O(log(要素数)) です。
        /// </summary>
        public void Enqueue(long key, T elem)
        {
            var n = _elements.Count;
            _keys.Add(key);
            _elements.Add(elem);
            while (n != 0)
            {
                var i = (n - 1) / 2;
                if (_keys[n] < _keys[i])
                {
                    (_keys[n], _keys[i]) = (_keys[i], _keys[n]);
                    (_elements[n], _elements[i]) = (_elements[i], _elements[n]);
                }
                n = i;
            }
        }

        /// <summary>
        /// 頂点要素を返し、削除します。
        /// 計算量は O(log(要素数)) です。
        /// </summary>
        public (long key, T value) Dequeue()
        {
            var t = Peek();
            Pop();
            return t;
        }

        void Pop()
        {
            var n = _elements.Count - 1;
            _elements[0] = _elements[n];
            _elements.RemoveAt(n);
            _keys[0] = _keys[n];
            _keys.RemoveAt(n);
            for (int i = 0, j; (j = 2 * i + 1) < n;)
            {
                //左の子と右の子で右の子の方が優先度が高いなら右の子を処理したい
                if ((j != n - 1) && _keys[j] > _keys[j + 1]) j++;
                //親より子が優先度が高いなら親子を入れ替える
                if (_keys[i] > _keys[j])
                {
                    (_keys[i], _keys[j]) = (_keys[j], _keys[i]);
                    (_elements[i], _elements[j]) = (_elements[j], _elements[i]);
                }
                i = j;
            }
        }


        /// <summary>
        /// 頂点要素を返します。
        /// 計算量は O(1) です。
        /// </summary>
        public (long key, T value) Peek() => (_keys[0], _elements[0]);

        /// <summary>
        /// 優先度付きキューに格納されている要素の数を返します。
        /// 計算量は O(1) です。
        /// </summary>
        public int Count => _elements.Count;

        /// <summary>
        /// 要素が存在するかを返します。
        /// </summary>
        /// <returns></returns>
        public bool Any() => _elements.Any();
    }

    struct Pos
    {
        public long x;
        public long y;
        public int id;
        static private readonly long N = 100;
        public Pos(long _x, long _y, int _id)
        {
            x = _x;
            y = _y;
            id = _id;
        }

        public long Length(Pos pos)
        {
            return (id >= N ? 1 : 5) * (pos.id >= N ? 1 : 5) * ((pos.x - x) * (pos.x - x) + (pos.y - y) * (pos.y - y));
        }
        override public string ToString() => $"{x} {y}";
    }

    void TSP(List<Pos> pos)
    {
        var cnt = 0;
        var ccnt = 0;
        while (cnt < 100000)
        {
            cnt++;
            var a = rnd.Next(pos.Count - 1);
            var b = rnd.Next(pos.Count - 1);
            if (a == b) continue;
            if (a > b) (a, b) = (b, a);
            var ap = pos[a];
            var bp = pos[b];
            var cp = pos[(b + 1) % pos.Count];
            var dp = pos[a + 1];
            var diff = (ap.Length(dp) + bp.Length(cp) - ap.Length(bp) - cp.Length(dp));
            if (diff > 0)
            {
                ccnt++;
                var (x, y) = (a + 1, b);
                while (x < y)
                {
                    (pos[x], pos[y]) = (pos[y], pos[x]);
                    x++; y--;
                }
            }
        }
    }

    IO io = new IO();
    static void Main()
    {
        Console.SetIn(new StreamReader(Console.OpenStandardInput(8192)));
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        var program = new Program();
        //var t = new Thread(program.Solve, 134217728);
        //t.Start();
        //t.Join();
        program.Solve();
        Console.Out.Flush();
        Console.Read();
    }
}


//------------------------------------------------------------------------------------------------------------------

public static class Ex
{
    public static bool IsNullOrEmpty(this string s) { return string.IsNullOrEmpty(s); }
    public static void yesno(this bool b) => Console.WriteLine(b ? "yes" : "no");
    public static void YesNo(this bool b) => Console.WriteLine(b ? "Yes" : "No");
    public static void YESNO(this bool b) => Console.WriteLine(b ? "YES" : "NO");
    public static void Yes() => Console.WriteLine("Yes");
    public static void YES() => Console.WriteLine("YES");
    public static void No() => Console.WriteLine("No");
    public static void NO() => Console.WriteLine("NO");
    public static void M1() => Console.WriteLine("-1");
    public static void TakahashiAoki(this bool b) => Console.WriteLine(b ? "Takahashi" : "Aoki");

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool Chmax(ref this int a, int b)
    {
        if (a < b) { a = b; return true; }
        else return false;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool Chmin(ref this int a, int b)
    {
        if (a > b) { a = b; return true; }
        else return false;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool Chmax(ref this long a, long b)
    {
        if (a < b) { a = b; return true; }
        else return false;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool Chmin(ref this long a, long b)
    {
        if (a > b) { a = b; return true; }
        else return false;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool Chmin<T>(ref this long a, long b)
    {
        if (a > b) { a = b; return true; }
        else return false;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool Chmax<T>(ref this T a, T b) where T : struct, IComparable<T>
    {
        if (b.CompareTo(a) > 0) { a = b; return true; }
        else return false;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool Chmin<T>(ref this T a, T b) where T : struct, IComparable<T>
    {
        if (b.CompareTo(a) < 0) { a = b; return true; }
        else return false;
    }

    /// <summary>
    /// constraintを満たす最小のインデックスを返します。
    /// </summary>
    /// <param name="constraint">T key が満たすべき制約</param>
    /// <returns>制約を満たす最小のインデックス(0-indexed)</returns>
    public static int LowerBound<T>(this IList<T> ls, Func<T, bool> constraint)
    {
        var ng = -1;
        var ok = ls.Count;
        while (ok - ng > 1)
        {
            var mid = (ok + ng) / 2;
            if (constraint(ls[mid])) ok = mid;
            else ng = mid;
        }
        return ok;

    }

    public static void Swap(this IList<int> arr, int a, int b) => (arr[a], arr[b]) = (arr[b], arr[a]);

    public static long[] GetCum(this IList<long> ls)
    {
        var res = new long[ls.Count + 1];
        for (int i = 0; i < ls.Count; i++) res[i + 1] = res[i] + ls[i];
        return res;
    }

    public static T[] GetCum<T>(this IList<T> ls, bool fromLeft, T gen, Func<T, T, T> func)
    {
        var res = new T[ls.Count + 1];
        res.AsSpan().Fill(gen);
        if (fromLeft)
        {
            for (int i = 0; i < ls.Count; i++) res[i + 1] = func(res[i], ls[i]);
        }
        else
        {
            for (int i = ls.Count; i > 0; i--) res[i - 1] = func(res[i], ls[i - 1]);
        }
        return res;
    }

    public static T[] Repeat<T>(this T element, int N)
    {
        var res = new T[N];
        res.AsSpan().Fill(element);
        return res;
    }

    public static T[][] Repeat<T>(this T element, int H, int W)
    {
        var res = new T[H][];
        for (int i = 0; i < H; i++)
        {
            res[i] = new T[W];
            res[i].AsSpan().Fill(element);
        }
        return res;
    }

    public static T[][][] Repeat<T>(this T element, int H, int W, int R)
    {
        var res = new T[H][][];
        for (int i = 0; i < H; i++)
        {
            res[i] = new T[W][];
            for (int j = 0; j < W; j++)
            {
                res[i][j] = new T[R];
                res[i][j].AsSpan().Fill(element);
            }
        }
        return res;
    }

}

class IO
{
    public string GetStr() => Console.ReadLine().Trim();
    public char GetChar() => Console.ReadLine().Trim()[0];
    public int GetInt() => int.Parse(Console.ReadLine().Trim());
    public long GetLong() => long.Parse(Console.ReadLine().Trim());
    public double GetDouble() => double.Parse(Console.ReadLine().Trim());
    public decimal GetDecimal() => decimal.Parse(Console.ReadLine().Trim());
    public string[] GetStrArray() => Console.ReadLine().Trim().Split(' ');
    public string[][] GetStrArray(int N)
    {
        var res = new string[N][];
        for (int i = 0; i < N; i++) res[i] = Console.ReadLine().Trim().Split(' ');
        return res;
    }
    public int[] GetIntArray() => Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
    public int[][] GetIntArray(int N)
    {
        var res = new int[N][];
        for (int i = 0; i < N; i++) res[i] = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
        return res;
    }
    public long[] GetLongArray() => Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
    public long[][] GetLongArray(int N)
    {
        var res = new long[N][];
        for (int i = 0; i < N; i++) res[i] = Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
        return res;
    }
    public decimal[] GetDecimalArray() => Console.ReadLine().Trim().Split(' ').Select(decimal.Parse).ToArray();
    public decimal[][] GetDecimalArray(int N)
    {
        var res = new decimal[N][];
        for (int i = 0; i < N; i++) res[i] = Console.ReadLine().Trim().Split(' ').Select(decimal.Parse).ToArray();
        return res;
    }
    public char[] GetCharArray() => Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray();
    public double[] GetDoubleArray() => Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray();
    public double[][] GetDoubleArray(int N)
    {
        var res = new double[N][];
        for (int i = 0; i < N; i++) res[i] = Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray();
        return res;
    }
    public char[][] GetGrid(int H)
    {
        var res = new char[H][];
        for (int i = 0; i < H; i++) res[i] = Console.ReadLine().Trim().ToCharArray();
        return res;
    }

    public List<int>[] GetUnweightedAdjanceyList(int V, int E, bool isDirected, bool isNode_0indexed)
    {
        var ls = new List<int>[V];
        for (int i = 0; i < V; i++) ls[i] = new List<int>();
        for (int i = 0; i < E; i++)
        {
            var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            if (isNode_0indexed == false) { input[0]--; input[1]--; }
            ls[input[0]].Add(input[1]);
            if (isDirected == false) ls[input[1]].Add(input[0]);
        }
        return ls;
    }

    public List<(int to, long dist)>[] GetWeightedAdjacencyList(int V, int E, bool isDirected, bool isNode_0indexed)
    {
        var ls = new List<(int to, long dist)>[V];
        for (int i = 0; i < V; i++) ls[i] = new List<(int to, long dist)>();
        for (int i = 0; i < E; i++)
        {
            var hoge = Console.ReadLine().Split(' ');
            var a = int.Parse(hoge[0]);
            var b = int.Parse(hoge[1]);
            var c = long.Parse(hoge[2]);
            if (isNode_0indexed == false) { a--; b--; }
            ls[a].Add((b, c));
            if (isDirected == false) ls[b].Add((a, c));
        }
        return ls;
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    bool eq<T, U>() => typeof(T).Equals(typeof(U));
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
                       : eq<T, long>() ? ct<T, long>(long.Parse(s))
                       : eq<T, double>() ? ct<T, double>(double.Parse(s))
                       : eq<T, decimal>() ? ct<T, decimal>(decimal.Parse(s))
                       : eq<T, char>() ? ct<T, char>(s[0])
                       : ct<T, string>(s);
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    void Multi<T>(out T a) => a = cv<T>(GetStr());
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    void Multi<T, U>(out T a, out U b)
    {
        var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]);
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    void Multi<T, U, V>(out T a, out U b, out V c)
    {
        var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]);
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    void Multi<T, U, V, W>(out T a, out U b, out V c, out W d)
    {
        var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]);
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e)
    {
        var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]);
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f)
    {
        var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]);
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public (T, U) GetMulti<T, U>()
    {
        var ar = Console.ReadLine().Split(' ');
        return (cv<T>(ar[0]), cv<U>(ar[1]));
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public (T, U, V) GetMulti<T, U, V>()
    {
        var ar = Console.ReadLine().Split(' ');
        return (cv<T>(ar[0]), cv<U>(ar[1]), cv<V>(ar[2]));
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public (T, U, V, W) GetMulti<T, U, V, W>()
    {
        var ar = Console.ReadLine().Split(' ');
        return (cv<T>(ar[0]), cv<U>(ar[1]), cv<V>(ar[2]), cv<W>(ar[3]));
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public (T, U, V, W, X) GetMulti<T, U, V, W, X>()
    {
        var ar = Console.ReadLine().Split(' ');
        return (cv<T>(ar[0]), cv<U>(ar[1]), cv<V>(ar[2]), cv<W>(ar[3]), cv<X>(ar[4]));
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public (T, U, V, W, X, Y) GetMulti<T, U, V, W, X, Y>()
    {
        var ar = Console.ReadLine().Split(' ');
        return (cv<T>(ar[0]), cv<U>(ar[1]), cv<V>(ar[2]), cv<W>(ar[3]), cv<X>(ar[4]), cv<Y>(ar[5]));
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public void Print() => Console.WriteLine();
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public void Print<T>(T t) => Console.WriteLine(t);
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public void Print<T>(string separator, IList<T> ls) => Console.WriteLine(string.Join(separator, ls));
    public void Debug<T>(IList<T> ls)
    {
        Console.Error.WriteLine();
        Console.Error.WriteLine("[" + string.Join(",", ls) + "]");
    }
    public void Debug<T>(IList<IList<T>> ls)
    {
        Console.Error.WriteLine();
        foreach (var l in ls)
        {
            Console.Error.WriteLine("[" + string.Join(",", l) + "]");
        }
        Console.Error.WriteLine();
    }
}
0