Esempio n. 1
0
        public static void Solve()
        {
            var N = Scanner.Scan <int>();
            var P = Scanner.ScanEnumerable <int>().ToArray();
            var Q = Scanner.ScanEnumerable <int>().ToArray();

            long F(IEnumerable <int> items)
            {
                var array = items.ToArray();
                var list  = items.ToList();

                list.Sort();
                var ret = 0L;

                for (var i = 0; i < array.Length; i++)
                {
                    var value = array[i];
                    ret += Enumeration.Fractorial(array.Length - i - 1) * list.IndexOf(value);
                    list.Remove(value);
                }
                return(ret);
            }

            Console.WriteLine(Math.Abs(F(P) - F(Q)));
        }
Esempio n. 2
0
        public static void Solve()
        {
            var(N, M) = Scanner.Scan <int, int>();
            var p      = (long)1e9 + 7;
            var answer = 0L;

            if (Math.Abs(N - M) < 2)
            {
                var npn = Enumeration.Fractorial(N, p);
                var mpm = Enumeration.Fractorial(M, p);
                answer = npn * mpm % p;
                if (N == M)
                {
                    answer *= 2;
                    answer %= p;
                }
            }
            Console.WriteLine(answer);
        }