buggy_code
stringlengths
11
625k
fixed_code
stringlengths
17
625k
bug_type
stringlengths
2
4.45k
language
int64
0
8
token_count
int64
5
200k
change_count
int64
0
100
using System; using System.Linq; using System.Collections.Generic; namespace AtCoder { class Program { static void Main(string[] args) { MainStream(); } static void MainStream() { Scan sc = new Scan(); write wr = new write(); int n = sc.intarr[0]; int[] array = sc.intarr; Array.Sort(array); int alice = 0; int bob = 0; for (int i = 0; i < n; i++) { if (i % 2 == 0) { alice += array[i]; } else { bob += array[i]; } } Console.WriteLine(alice - bob); } } class Scan { public string str => Console.ReadLine(); public string[] strarr => str.Split(' '); public long[] longarr => strarr.Select(long.Parse).ToArray(); public int[] intarr => strarr.Select(int.Parse).ToArray(); public char[] chararr => str.ToArray(); } class write { public void wri<Type>(Type x) { Console.WriteLine(x); } } class Method { static public int max(params int[] nums) { int maxx = nums[0]; for (int i = 1; i < nums.Length; i++) { maxx = Math.Max(maxx, nums[i]); } return maxx; } } }
using System; using System.Linq; using System.Collections.Generic; namespace AtCoder { class Program { static void Main(string[] args) { MainStream(); } static void MainStream() { Scan sc = new Scan(); write wr = new write(); int n = sc.intarr[0]; int[] array = sc.intarr; Array.Sort(array); int alice = 0; int bob = 0; for (int i = 0; i < n; i++) { if (i % 2 == 0) { alice += array[i]; } else { bob += array[i]; } } Console.WriteLine(Math.Abs(alice - bob)); } } class Scan { public string str => Console.ReadLine(); public string[] strarr => str.Split(' '); public long[] longarr => strarr.Select(long.Parse).ToArray(); public int[] intarr => strarr.Select(int.Parse).ToArray(); public char[] chararr => str.ToArray(); } class write { public void wri<Type>(Type x) { Console.WriteLine(x); } } class Method { static public int max(params int[] nums) { int maxx = nums[0]; for (int i = 1; i < nums.Length; i++) { maxx = Math.Max(maxx, nums[i]); } return maxx; } } }
[["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
311
5
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ARC091B { class Program { static void Main(string[] args) { long[] input = Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray(); long N = input[0]; long K = input[1]; long ans = 0; if (K == 0) { ans = N * N; } else { for (int b = 0; b < N; b++) { if (b <= K) { continue; } long num = N / b; ans += num * (b - K); long remain = N % b; if (remain >= K) { ans += remain - K + 1; } } } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ARC091B { class Program { static void Main(string[] args) { long[] input = Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray(); long N = input[0]; long K = input[1]; long ans = 0; if (K == 0) { ans = N * N; } else { for (int b = 1; b <= N; b++) { if (b <= K) { continue; } long num = N / b; ans += num * (b - K); long remain = N % b; if (remain >= K) { ans += remain - K + 1; } } } Console.WriteLine(ans); } } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 57, 75, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 57, 75, 196, 0, 7, 15, 16, 17, 19]]
8
191
4
using System; using System.Collections.Generic; using System.Linq; namespace ziyuutyou { class Program { static void Main(string[] args) { var m = int.Parse(Console.ReadLine()); if (m >= 3) { Console.WriteLine(m % 3); } else { Console.WriteLine(0); } } } }
using System; using System.Collections.Generic; using System.Linq; namespace ziyuutyou { class Program { static void Main(string[] args) { var m = int.Parse(Console.ReadLine()); if (m >= 3) { Console.WriteLine(m / 3); } else { Console.WriteLine(0); } } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 109], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85]]
8
75
2
using System; namespace ConsoleApp1 { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); Console.WriteLine(n % 3); } } }
using System; namespace ConsoleApp1 { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); Console.WriteLine(n / 3); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 109], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85]]
8
45
2
using System; namespace AtCoder.ABC089 { public class A { public static void Solve() { string[] input = Console.ReadLine().Split(' '); int a = int.Parse(input[0]); Console.WriteLine(a % 3); } } } namespace AtCoder { class Program { static void Main(string[] args) { ABC089.A.Solve(); } } }
using System; namespace AtCoder.ABC089 { public class A { public static void Solve() { string[] input = Console.ReadLine().Split(' '); int a = int.Parse(input[0]); Console.WriteLine(a / 3); } } } namespace AtCoder { class Program { static void Main(string[] args) { ABC089.A.Solve(); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 109], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85]]
8
89
2
using System; public class Hello { public static void Main() { int n = int.Parse(System.Console.ReadLine()); System.Console.WriteLine(n % 3); } }
using System; public class Hello { public static void Main() { int n = int.Parse(System.Console.ReadLine()); System.Console.WriteLine(n / 3); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 109], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85]]
8
43
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder1_A { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); Console.WriteLine(n % 3); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder1_A { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); Console.WriteLine(n / 3); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 109], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85]]
8
69
2
using System; using System.Collections.Generic; using System.Linq; using static Atcoder; using System.Threading.Tasks; using System.ComponentModel; public class Hello { public static void Main() { int N = Cin(); Console.WriteLine(N % 3); } } public class Atcoder { static void Swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } public static int LCM(int a, int b) { int c = a * b; if (a < b) Swap(ref a, ref b); int d = a % b; while (d != 0) { a = b; b = d; d = a % b; } return c / b; } public static string strReverce(string s) { return new string(s.Reverse().ToArray()); } public static int Cin() { return int.Parse(Console.ReadLine()); } public static bool IsPrime(int n) { if (n < 2) return false; if (n == 2) return true; if (n % 2 == 0) return false; // double sqrtNum = Math.Sqrt(n); for (int i = 3; i < n; i += 2) { if (n % i == 0) return false; } return true; } public static string[] SpRead(char c) { return Console.ReadLine().Split(c); } }
using System; using System.Collections.Generic; using System.Linq; using static Atcoder; using System.Threading.Tasks; using System.ComponentModel; public class Hello { public static void Main() { int N = Cin(); Console.WriteLine(N / 3); } } public class Atcoder { static void Swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } public static int LCM(int a, int b) { int c = a * b; if (a < b) Swap(ref a, ref b); int d = a % b; while (d != 0) { a = b; b = d; d = a % b; } return c / b; } public static string strReverce(string s) { return new string(s.Reverse().ToArray()); } public static int Cin() { return int.Parse(Console.ReadLine()); } public static bool IsPrime(int n) { if (n < 2) return false; if (n == 2) return true; if (n % 2 == 0) return false; // double sqrtNum = Math.Sqrt(n); for (int i = 3; i < n; i += 2) { if (n % i == 0) return false; } return true; } public static string[] SpRead(char c) { return Console.ReadLine().Split(c); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 109], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85]]
8
304
2
using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { int n = int.Parse(ReadLine()); List<string> s = ReadLine().Split().ToList().ConvertAll(x => x.ToString()); var hashSet = new HashSet<string>(s); if (s.Count == 3) { WriteLine("Three"); } else { WriteLine("Four"); } } }
using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { int n = int.Parse(ReadLine()); List<string> s = ReadLine().Split().ToList().ConvertAll(x => x.ToString()); var hashSet = new HashSet<string>(s); if (hashSet.Count == 3) { WriteLine("Three"); } else { WriteLine("Four"); } } }
[["-", 8, 196, 0, 57, 15, 16, 31, 214, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 205, 22]]
8
116
2
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Numerics; namespace FertiLib.Contest.B { static class Program { public static void Solve(Scanner cin) { int n = cin.ReadInt(); if (cin.ReadIntArray(n).Distinct().Count() == 3) Console.WriteLine("Three"); else Console.WriteLine("Four"); } public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var cin = new Scanner(); Solve(cin); Console.Out.Flush(); } public static void YESNO(bool condition) => Console.WriteLine(condition ? "YES" : "NO"); public static void YesNo(bool condition) => Console.WriteLine(condition ? "Yes" : "No"); public static void yesno(bool condition) => Console.WriteLine(condition ? "yes" : "no"); public static bool Chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) >= 0) return false; a = b; return true; } public static bool Chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) <= 0) return false; a = b; return true; } } static class Util { public static string Join<T>(this IEnumerable<T> x, string separator = "") => string.Join(separator, x); } class Scanner { string[] s; int i; char[] separator = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string Read() => ReadString(); public string ReadString() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(separator, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return ReadString(); i = 0; return s[i++]; } public string[] ReadStringArray(int N) { string[] Array = new string[N]; for (int i = 0; i < N; i++) { Array[i] = ReadString(); } return Array; } public int ReadInt() { return int.Parse(ReadString()); } public int[] ReadIntArray(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = ReadInt() + add; } return Array; } public long ReadLong() { return long.Parse(ReadString()); } public long[] ReadLongArray(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = ReadLong() + add; } return Array; } public double ReadDouble() { return double.Parse(ReadString()); } public double[] ReadDoubleArray(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = ReadDouble() + add; } return Array; } public T1 ReadValue<T1>() => (T1)Convert.ChangeType(ReadString(), typeof(T1)); public (T1, T2) ReadValue<T1, T2>() { var inputs = ReadStringArray(2); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); return (v1, v2); } public (T1, T2, T3) ReadValue<T1, T2, T3>() { var inputs = ReadStringArray(3); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); return (v1, v2, v3); } public (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>() { var inputs = ReadStringArray(4); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); return (v1, v2, v3, v4); } public (T1, T2, T3, T4, T5) ReadValue<T1, T2, T3, T4, T5>() { var inputs = ReadStringArray(5); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); return (v1, v2, v3, v4, v5); } public (T1, T2, T3, T4, T5, T6) ReadValue<T1, T2, T3, T4, T5, T6>() { var inputs = ReadStringArray(6); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6)); return (v1, v2, v3, v4, v5, v6); } public (T1, T2, T3, T4, T5, T6, T7) ReadValue<T1, T2, T3, T4, T5, T6, T7>() { var inputs = ReadStringArray(7); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6)); var v7 = (T7)Convert.ChangeType(inputs[6], typeof(T7)); return (v1, v2, v3, v4, v5, v6, v7); } public T1[] ReadValueArray<T1>(int N) { var v1 = new T1[N]; for (int i = 0; i < N; i++) { v1[i] = ReadValue<T1>(); } return v1; } public (T1[], T2[]) ReadValueArray<T1, T2>(int N) { var (v1, v2) = (new T1[N], new T2[N]); for (int i = 0; i < N; i++) { var (t1, t2) = ReadValue<T1, T2>(); v1[i] = t1; v2[i] = t2; } return (v1, v2); } public (T1[], T2[], T3[]) ReadValueArray<T1, T2, T3>(int N) { var (v1, v2, v3) = (new T1[N], new T2[N], new T3[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3) = ReadValue<T1, T2, T3>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; } return (v1, v2, v3); } public (T1[], T2[], T3[], T4[]) ReadValueArray<T1, T2, T3, T4>(int N) { var (v1, v2, v3, v4) = (new T1[N], new T2[N], new T3[N], new T4[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4) = ReadValue<T1, T2, T3, T4>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; } return (v1, v2, v3, v4); } public (T1[], T2[], T3[], T4[], T5[]) ReadValueArray<T1, T2, T3, T4, T5>(int N) { var (v1, v2, v3, v4, v5) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5) = ReadValue<T1, T2, T3, T4, T5>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; } return (v1, v2, v3, v4, v5); } public (T1[], T2[], T3[], T4[], T5[], T6[]) ReadValueArray<T1, T2, T3, T4, T5, T6>(int N) { var (v1, v2, v3, v4, v5, v6) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5, t6) = ReadValue<T1, T2, T3, T4, T5, T6>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; v6[i] = t6; } return (v1, v2, v3, v4, v5, v6); } public (T1[], T2[], T3[], T4[], T5[], T6[], T7[]) ReadValueArray<T1, T2, T3, T4, T5, T6, T7>(int N) { var (v1, v2, v3, v4, v5, v6, v7) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N], new T7[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5, t6, t7) = ReadValue<T1, T2, T3, T4, T5, T6, T7>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; v6[i] = t6; v7[i] = t7; } return (v1, v2, v3, v4, v5, v6, v7); } } }
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Numerics; namespace FertiLib.Contest.B { static class Program { public static void Solve(Scanner cin) { int n = cin.ReadInt(); if (cin.ReadStringArray(n).Distinct().Count() == 3) Console.WriteLine("Three"); else Console.WriteLine("Four"); } public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var cin = new Scanner(); Solve(cin); Console.Out.Flush(); } public static void YESNO(bool condition) => Console.WriteLine(condition ? "YES" : "NO"); public static void YesNo(bool condition) => Console.WriteLine(condition ? "Yes" : "No"); public static void yesno(bool condition) => Console.WriteLine(condition ? "yes" : "no"); public static bool Chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) >= 0) return false; a = b; return true; } public static bool Chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) <= 0) return false; a = b; return true; } } static class Util { public static string Join<T>(this IEnumerable<T> x, string separator = "") => string.Join(separator, x); } class Scanner { string[] s; int i; char[] separator = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string Read() => ReadString(); public string ReadString() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(separator, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return ReadString(); i = 0; return s[i++]; } public string[] ReadStringArray(int N) { string[] Array = new string[N]; for (int i = 0; i < N; i++) { Array[i] = ReadString(); } return Array; } public int ReadInt() { return int.Parse(ReadString()); } public int[] ReadIntArray(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = ReadInt() + add; } return Array; } public long ReadLong() { return long.Parse(ReadString()); } public long[] ReadLongArray(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = ReadLong() + add; } return Array; } public double ReadDouble() { return double.Parse(ReadString()); } public double[] ReadDoubleArray(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = ReadDouble() + add; } return Array; } public T1 ReadValue<T1>() => (T1)Convert.ChangeType(ReadString(), typeof(T1)); public (T1, T2) ReadValue<T1, T2>() { var inputs = ReadStringArray(2); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); return (v1, v2); } public (T1, T2, T3) ReadValue<T1, T2, T3>() { var inputs = ReadStringArray(3); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); return (v1, v2, v3); } public (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>() { var inputs = ReadStringArray(4); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); return (v1, v2, v3, v4); } public (T1, T2, T3, T4, T5) ReadValue<T1, T2, T3, T4, T5>() { var inputs = ReadStringArray(5); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); return (v1, v2, v3, v4, v5); } public (T1, T2, T3, T4, T5, T6) ReadValue<T1, T2, T3, T4, T5, T6>() { var inputs = ReadStringArray(6); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6)); return (v1, v2, v3, v4, v5, v6); } public (T1, T2, T3, T4, T5, T6, T7) ReadValue<T1, T2, T3, T4, T5, T6, T7>() { var inputs = ReadStringArray(7); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6)); var v7 = (T7)Convert.ChangeType(inputs[6], typeof(T7)); return (v1, v2, v3, v4, v5, v6, v7); } public T1[] ReadValueArray<T1>(int N) { var v1 = new T1[N]; for (int i = 0; i < N; i++) { v1[i] = ReadValue<T1>(); } return v1; } public (T1[], T2[]) ReadValueArray<T1, T2>(int N) { var (v1, v2) = (new T1[N], new T2[N]); for (int i = 0; i < N; i++) { var (t1, t2) = ReadValue<T1, T2>(); v1[i] = t1; v2[i] = t2; } return (v1, v2); } public (T1[], T2[], T3[]) ReadValueArray<T1, T2, T3>(int N) { var (v1, v2, v3) = (new T1[N], new T2[N], new T3[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3) = ReadValue<T1, T2, T3>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; } return (v1, v2, v3); } public (T1[], T2[], T3[], T4[]) ReadValueArray<T1, T2, T3, T4>(int N) { var (v1, v2, v3, v4) = (new T1[N], new T2[N], new T3[N], new T4[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4) = ReadValue<T1, T2, T3, T4>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; } return (v1, v2, v3, v4); } public (T1[], T2[], T3[], T4[], T5[]) ReadValueArray<T1, T2, T3, T4, T5>(int N) { var (v1, v2, v3, v4, v5) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5) = ReadValue<T1, T2, T3, T4, T5>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; } return (v1, v2, v3, v4, v5); } public (T1[], T2[], T3[], T4[], T5[], T6[]) ReadValueArray<T1, T2, T3, T4, T5, T6>(int N) { var (v1, v2, v3, v4, v5, v6) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5, t6) = ReadValue<T1, T2, T3, T4, T5, T6>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; v6[i] = t6; } return (v1, v2, v3, v4, v5, v6); } public (T1[], T2[], T3[], T4[], T5[], T6[], T7[]) ReadValueArray<T1, T2, T3, T4, T5, T6, T7>(int N) { var (v1, v2, v3, v4, v5, v6, v7) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N], new T7[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5, t6, t7) = ReadValue<T1, T2, T3, T4, T5, T6, T7>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; v6[i] = t6; v7[i] = t7; } return (v1, v2, v3, v4, v5, v6, v7); } } }
[["-", 205, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 205, 213, 63, 214, 205, 213, 63, 214, 141, 22]]
8
2,665
2
using System; using System.Collections.Generic; using CompLib.Util; public class Program { public void Solve() { var sc = new Scanner(); var hs = new HashSet<char>(); int n = sc.NextInt(); for (int i = 0; i < n; i++) { hs.Add(sc.NextChar()); } if (hs.Count == 3) { Console.WriteLine("Three"); } if (hs.Count == '4') { Console.WriteLine("Four"); } } public static void Main(string[] args) => new Program().Solve(); } namespace CompLib.Util { using System; using System.Linq; class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
using System; using System.Collections.Generic; using CompLib.Util; public class Program { public void Solve() { var sc = new Scanner(); var hs = new HashSet<char>(); int n = sc.NextInt(); for (int i = 0; i < n; i++) { hs.Add(sc.NextChar()); } if (hs.Count == 3) { Console.WriteLine("Three"); } if (hs.Count == 4) { Console.WriteLine("Four"); } } public static void Main(string[] args) => new Program().Solve(); } namespace CompLib.Util { using System; using System.Linq; class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
[["-", 8, 196, 0, 57, 15, 16, 12, 252, 0, 104]]
8
450
2
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var N = sc.ReadInt(); var S = sc.ReadStr(); var ans = ""; if (S.Distinct().Count() == 3) { ans = "Three"; } else { ans = "Four"; } Console.WriteLine(ans); } static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var N = sc.ReadInt(); var S = sc.ReadCharArray(N); var ans = ""; if (S.Distinct().Count() == 3) { ans = "Three"; } else { ans = "Four"; } Console.WriteLine(ans); } static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22]]
8
605
3
using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace Asakatsu20200315A { class Input { /// <summary> /// 1行の入力を取得する /// </summary> /// <returns>文字列</returns> public void String(out string s) { s = Console.ReadLine(); } /// <summary> /// 複数行の入力を取得 /// </summary> /// <returns>文字列の配列</returns> public void String(long rowNumber, out string[] s) { s = new String[rowNumber]; for (long i = 0; i < rowNumber; i++) { String(out s[i]); } } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>int型の値</returns> public void Int(out int i) { string s; String(out s); i = int.Parse(s); } /// <summary> /// 1行の入力を取得 /// </summary> /// <param name="a"></param> public void Long(out long a) { string s; String(out s); a = long.Parse(s); } /// <summary> /// 2つの整数が1行に書かれている入力を、2つのlongで受け取る /// </summary> /// <param name="a"></param> /// <param name="b"></param> public void Long(out long a, out long b) { long[] lArr; Long(out lArr); a = lArr[0]; b = lArr[1]; } /// <summary> /// 3つの整数が1行に書かれている入力を、3つのlongで受け取る /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <param name="c"></param> public void Long(out long a, out long b, out long c) { long[] lArr; Long(out lArr); a = lArr[0]; b = lArr[1]; c = lArr[2]; } /// <summary> /// 4つの整数が1行に書かれている入力を、4つのlongで受け取る /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <param name="c"></param> /// <param name="d"></param> public void Long(out long a, out long b, out long c, out long d) { long[] lArr; Long(out lArr); a = lArr[0]; b = lArr[1]; c = lArr[2]; d = lArr[3]; } public void Long(out long[] lArr) { lArr = Split().Select(long.Parse).ToArray(); } public void Long(long rowNumber, out long[] lArr) { lArr = new long[rowNumber]; for (long i = 0; i < rowNumber; i++) { Long(out lArr[i]); } } /// <summary> /// 2つの整数が複数行に書かれている入力を、2つのlong[]で受け取る /// </summary> /// <param name="rowNumber"></param> /// <param name="a"></param> /// <param name="b"></param> public void Long(long rowNumber, out long[] a, out long[] b) { a = new long[rowNumber]; b = new long[rowNumber]; for (int i = 0; i < rowNumber; i++) { Long(out a[i], out b[i]); } } /// <summary> /// 3つの整数が複数行に書かれている入力を、3つのlong[]で受け取る /// </summary> /// <param name="rowNumber"></param> /// <param name="a"></param> /// <param name="b"></param> /// <param name="c"></param> public void Long(long rowNumber, out long[] a, out long[] b, out long[] c) { a = new long[rowNumber]; b = new long[rowNumber]; c = new long[rowNumber]; for (int i = 0; i < rowNumber; i++) { Long(out a[i], out b[i], out c[i]); } } /// <summary> /// 4つの整数が複数行に書かれている入力を、4つのlong[]で受け取る /// </summary> /// <param name="rowNumber"></param> /// <param name="a"></param> /// <param name="b"></param> /// <param name="c"></param> /// <param name="d"></param> public void Long(long rowNumber, out long[] a, out long[] b, out long[] c, out long[] d) { a = new long[rowNumber]; b = new long[rowNumber]; c = new long[rowNumber]; d = new long[rowNumber]; for (int i = 0; i < rowNumber; i++) { Long(out a[i], out b[i], out c[i], out d[i]); } } /// <summary> /// h行w列のLongのmapを入力する /// </summary> /// <param name="h"></param> /// <param name="w"></param> /// <param name="a"></param> public void Long(long h, long w, out long[][] a) { a = new long [h][]; for (long i = 0; i < h; i++) { Long(out a[i]); } } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>double型の値</returns> public void Double(out double d) { string s; String(out s); d = double.Parse(s); } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>double型の配列</returns> public void Double(out double[] dArr) { dArr = Split().Select(double.Parse).ToArray(); } private IEnumerable<string> Split() { string s; String(out s); return s.Split(' '); } } class Program { public static void Main(string[] args) { StreamWriter streamWriter = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(streamWriter); Solver solver = new Solver(); solver.Solve(); Console.Out.Flush(); } public static void Debug() { Solver solver = new Solver(); solver.Solve(); } } class Solver { private Input input; public Solver() { input = new Input(); input.Long(out N); input.String(out S); } private long N; private string S; public void Solve() { Console.WriteLine(S.Contains('Y') ? "Yes" : "No"); } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace Asakatsu20200315A { class Input { /// <summary> /// 1行の入力を取得する /// </summary> /// <returns>文字列</returns> public void String(out string s) { s = Console.ReadLine(); } /// <summary> /// 複数行の入力を取得 /// </summary> /// <returns>文字列の配列</returns> public void String(long rowNumber, out string[] s) { s = new String[rowNumber]; for (long i = 0; i < rowNumber; i++) { String(out s[i]); } } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>int型の値</returns> public void Int(out int i) { string s; String(out s); i = int.Parse(s); } /// <summary> /// 1行の入力を取得 /// </summary> /// <param name="a"></param> public void Long(out long a) { string s; String(out s); a = long.Parse(s); } /// <summary> /// 2つの整数が1行に書かれている入力を、2つのlongで受け取る /// </summary> /// <param name="a"></param> /// <param name="b"></param> public void Long(out long a, out long b) { long[] lArr; Long(out lArr); a = lArr[0]; b = lArr[1]; } /// <summary> /// 3つの整数が1行に書かれている入力を、3つのlongで受け取る /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <param name="c"></param> public void Long(out long a, out long b, out long c) { long[] lArr; Long(out lArr); a = lArr[0]; b = lArr[1]; c = lArr[2]; } /// <summary> /// 4つの整数が1行に書かれている入力を、4つのlongで受け取る /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <param name="c"></param> /// <param name="d"></param> public void Long(out long a, out long b, out long c, out long d) { long[] lArr; Long(out lArr); a = lArr[0]; b = lArr[1]; c = lArr[2]; d = lArr[3]; } public void Long(out long[] lArr) { lArr = Split().Select(long.Parse).ToArray(); } public void Long(long rowNumber, out long[] lArr) { lArr = new long[rowNumber]; for (long i = 0; i < rowNumber; i++) { Long(out lArr[i]); } } /// <summary> /// 2つの整数が複数行に書かれている入力を、2つのlong[]で受け取る /// </summary> /// <param name="rowNumber"></param> /// <param name="a"></param> /// <param name="b"></param> public void Long(long rowNumber, out long[] a, out long[] b) { a = new long[rowNumber]; b = new long[rowNumber]; for (int i = 0; i < rowNumber; i++) { Long(out a[i], out b[i]); } } /// <summary> /// 3つの整数が複数行に書かれている入力を、3つのlong[]で受け取る /// </summary> /// <param name="rowNumber"></param> /// <param name="a"></param> /// <param name="b"></param> /// <param name="c"></param> public void Long(long rowNumber, out long[] a, out long[] b, out long[] c) { a = new long[rowNumber]; b = new long[rowNumber]; c = new long[rowNumber]; for (int i = 0; i < rowNumber; i++) { Long(out a[i], out b[i], out c[i]); } } /// <summary> /// 4つの整数が複数行に書かれている入力を、4つのlong[]で受け取る /// </summary> /// <param name="rowNumber"></param> /// <param name="a"></param> /// <param name="b"></param> /// <param name="c"></param> /// <param name="d"></param> public void Long(long rowNumber, out long[] a, out long[] b, out long[] c, out long[] d) { a = new long[rowNumber]; b = new long[rowNumber]; c = new long[rowNumber]; d = new long[rowNumber]; for (int i = 0; i < rowNumber; i++) { Long(out a[i], out b[i], out c[i], out d[i]); } } /// <summary> /// h行w列のLongのmapを入力する /// </summary> /// <param name="h"></param> /// <param name="w"></param> /// <param name="a"></param> public void Long(long h, long w, out long[][] a) { a = new long [h][]; for (long i = 0; i < h; i++) { Long(out a[i]); } } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>double型の値</returns> public void Double(out double d) { string s; String(out s); d = double.Parse(s); } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>double型の配列</returns> public void Double(out double[] dArr) { dArr = Split().Select(double.Parse).ToArray(); } private IEnumerable<string> Split() { string s; String(out s); return s.Split(' '); } } class Program { public static void Main(string[] args) { StreamWriter streamWriter = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(streamWriter); Solver solver = new Solver(); solver.Solve(); Console.Out.Flush(); } public static void Debug() { Solver solver = new Solver(); solver.Solve(); } } class Solver { private Input input; public Solver() { input = new Input(); input.Long(out N); input.String(out S); } private long N; private string S; public void Solve() { Console.WriteLine(S.Contains('Y') ? "Four" : "Three"); } } }
[["-", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["-", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222]]
8
1,010
4
#pragma warning disable using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.Serialization.Formatters.Binary; using System.Text; using System.Diagnostics; using System.Collections; static class MainClass { public static void Main() { Console.ReadLine(); Console.WriteLine(Console.ReadLine() .SplittedStringToInt32List() .Where(x => x == 'Y') .Count() == 0 ? "Three" : "Four"); } #region ライブラリ #region 二分探索 public static int LowerBound<T>(this IEnumerable<T> ar, int start, int end, T value, IComparer<T> comparer) { var arr = ar.ToArray(); int low = start; int high = end; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) < 0) low = mid + 1; else high = mid; } return low; } public static int LowerBound<T>(this IEnumerable<T> arr, T value) where T : IComparable { return LowerBound(arr, 0, arr.Count(), value, Comparer<T>.Default); } public static int UpperBound<T>(this IEnumerable<T> ar, int start, int end, T value, IComparer<T> comparer) { var arr = ar.ToArray(); int low = start; int high = end; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) <= 0) low = mid + 1; else high = mid; } return low; } public static int UpperBound<T>(this IEnumerable<T> arr, T value) { return UpperBound(arr, 0, arr.Count(), value, Comparer<T>.Default); } #endregion #region bit全探索 /// <summary> /// Bit全探索用のライブラリ /// </summary> /// <param name="len">作る配列の長さ(lenが0以下だと(ry)</param> /// <returns>できた配列</returns> public static List<List<bool>> CreateBits(int len) { return CreateBitsPri(new List<List<bool>>(), len, 0); } private static List<List<bool>> CreateBitsPri(List<List<bool>> bits, int len, int count) { if (count == 0) { var lss = new List<bool>(); lss.Add(true); bits.Add(lss); var lx = new List<bool>(); lx.Add(false); bits.Add(lx); count++; return CreateBitsPri(bits, len, count); } if (len - count == 0) return bits; count++; var ls = new List<List<bool>>(); foreach (var item in bits) { var x = item.ToList(); x.Add(true); item.Add(false); ls.Add(item); ls.Add(x); } return CreateBitsPri(ls, len, count); } #endregion #region 文字列処理 public static int ToInt32(this string str) { return int.Parse(str); } public static List<string> SplittedStringToList(this string str) { return str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .ToList(); } public static List<int> SplittedStringToInt32List(this string str) { return str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .Select(x => int.Parse(x)) .ToList(); } #endregion #region エラトステネスの篩 /** * MIT License Copyright (c) 2018 gushwell Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. **/ public class BoundedBoolArray { private BitArray _array; private int _lower; public BoundedBoolArray(int lower, int upper) { _array = new BitArray(upper - lower + 1); _lower = lower; } public bool this[int index] { get { return _array[index - _lower]; } set { _array[index - _lower] = value; } } } public static IEnumerable<int> GeneratePrimes() { var primes = new List<int>() { 2, 3 }; foreach (var p in primes) yield return p; int ix = 0; while (true) { int prime1st = primes[ix]; int prime2nd = primes[++ix]; var lower = prime1st * prime1st; var upper = prime2nd * prime2nd - 1; var sieve = new BoundedBoolArray(lower, upper); foreach (var prime in primes.Take(ix)) { var start = (int)Math.Ceiling((double)lower / prime) * prime; for (int index = start; index <= upper; index += prime) sieve[index] = true; } for (int i = lower; i <= upper; i++) { if (sieve[i] == false) { primes.Add(i); yield return i; } } } } #endregion #region DeepClone public static T DeepClone<T>(this T src) { using (var memoryStream = new MemoryStream()) { var binaryFormatter = new BinaryFormatter(); binaryFormatter.Serialize(memoryStream, src); memoryStream.Seek(0, SeekOrigin.Begin); return (T)binaryFormatter.Deserialize(memoryStream); } } #endregion #region 順列を作るやつ public static List<List<int>> GeneratePermutations(int n) { if (n > 14) throw new ArgumentOutOfRangeException(); var ls = new List<List<int>>(); ls.Add(new List<int>() { 1 }); for (int i = 0; i < n - 1; i++) { var newls = new List<List<int>>(); ls.ForEach(x => { var len = x.Count; for (int j = 0; j <= len; j++) { var item = x.DeepClone(); item.Insert(j, i + 2); newls.Add(item); } }); ls = newls; } return ls; } #endregion #endregion }
#pragma warning disable using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.Serialization.Formatters.Binary; using System.Text; using System.Diagnostics; using System.Collections; static class MainClass { public static void Main() { Console.ReadLine(); Console.WriteLine(Console.ReadLine() .SplittedStringToList() .Where(x => x == "Y") .Count() == 0 ? "Three" : "Four"); } #region ライブラリ #region 二分探索 public static int LowerBound<T>(this IEnumerable<T> ar, int start, int end, T value, IComparer<T> comparer) { var arr = ar.ToArray(); int low = start; int high = end; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) < 0) low = mid + 1; else high = mid; } return low; } public static int LowerBound<T>(this IEnumerable<T> arr, T value) where T : IComparable { return LowerBound(arr, 0, arr.Count(), value, Comparer<T>.Default); } public static int UpperBound<T>(this IEnumerable<T> ar, int start, int end, T value, IComparer<T> comparer) { var arr = ar.ToArray(); int low = start; int high = end; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) <= 0) low = mid + 1; else high = mid; } return low; } public static int UpperBound<T>(this IEnumerable<T> arr, T value) { return UpperBound(arr, 0, arr.Count(), value, Comparer<T>.Default); } #endregion #region bit全探索 /// <summary> /// Bit全探索用のライブラリ /// </summary> /// <param name="len">作る配列の長さ(lenが0以下だと(ry)</param> /// <returns>できた配列</returns> public static List<List<bool>> CreateBits(int len) { return CreateBitsPri(new List<List<bool>>(), len, 0); } private static List<List<bool>> CreateBitsPri(List<List<bool>> bits, int len, int count) { if (count == 0) { var lss = new List<bool>(); lss.Add(true); bits.Add(lss); var lx = new List<bool>(); lx.Add(false); bits.Add(lx); count++; return CreateBitsPri(bits, len, count); } if (len - count == 0) return bits; count++; var ls = new List<List<bool>>(); foreach (var item in bits) { var x = item.ToList(); x.Add(true); item.Add(false); ls.Add(item); ls.Add(x); } return CreateBitsPri(ls, len, count); } #endregion #region 文字列処理 public static int ToInt32(this string str) { return int.Parse(str); } public static List<string> SplittedStringToList(this string str) { return str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .ToList(); } public static List<int> SplittedStringToInt32List(this string str) { return str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .Select(x => int.Parse(x)) .ToList(); } #endregion #region エラトステネスの篩 /** * MIT License Copyright (c) 2018 gushwell Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. **/ public class BoundedBoolArray { private BitArray _array; private int _lower; public BoundedBoolArray(int lower, int upper) { _array = new BitArray(upper - lower + 1); _lower = lower; } public bool this[int index] { get { return _array[index - _lower]; } set { _array[index - _lower] = value; } } } public static IEnumerable<int> GeneratePrimes() { var primes = new List<int>() { 2, 3 }; foreach (var p in primes) yield return p; int ix = 0; while (true) { int prime1st = primes[ix]; int prime2nd = primes[++ix]; var lower = prime1st * prime1st; var upper = prime2nd * prime2nd - 1; var sieve = new BoundedBoolArray(lower, upper); foreach (var prime in primes.Take(ix)) { var start = (int)Math.Ceiling((double)lower / prime) * prime; for (int index = start; index <= upper; index += prime) sieve[index] = true; } for (int i = lower; i <= upper; i++) { if (sieve[i] == false) { primes.Add(i); yield return i; } } } } #endregion #region DeepClone public static T DeepClone<T>(this T src) { using (var memoryStream = new MemoryStream()) { var binaryFormatter = new BinaryFormatter(); binaryFormatter.Serialize(memoryStream, src); memoryStream.Seek(0, SeekOrigin.Begin); return (T)binaryFormatter.Deserialize(memoryStream); } } #endregion #region 順列を作るやつ public static List<List<int>> GeneratePermutations(int n) { if (n > 14) throw new ArgumentOutOfRangeException(); var ls = new List<List<int>>(); ls.Add(new List<int>() { 1 }); for (int i = 0; i < n - 1; i++) { var newls = new List<List<int>>(); ls.ForEach(x => { var len = x.Count; for (int j = 0; j <= len; j++) { var item = x.DeepClone(); item.Insert(j, i + 2); newls.Add(item); } }); ls = newls; } return ls; } #endregion #endregion }
[["-", 205, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 205, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["-", 0, 28, 0, 218, 8, 16, 12, 252, 0, 104], ["+", 0, 28, 0, 218, 8, 16, 12, 5, 0, 62]]
8
1,256
6
using static System.Console; namespace For_Atcoder { class Program { static void Main(string[] args) { ReadLine(); WriteLine(ReadLine().IndexOf("Y") >= 0 ? "Four" : "There"); } } }
using static System.Console; namespace For_Atcoder { class Program { static void Main(string[] args) { ReadLine(); WriteLine(ReadLine().IndexOf("Y") >= 0 ? "Four" : "Three"); } } }
[["-", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222]]
8
53
2
using System; using System.Collections.Generic; using System.Linq; namespace Competitive { internal class Solution { public void Run() { int H, W, D; { bool isFour = Console.ReadLine().Split(' ').Any(s => s == "Y"); Console.WriteLine(isFour ? "Four" : "Three"); } } } internal class Program { public static void Main(string[] args) { var s = new Solution(); s.Run(); } } }
using System; using System.Collections.Generic; using System.Linq; namespace Competitive { internal class Solution { public void Run() { int H, W, D; { Console.ReadLine(); bool isFour = Console.ReadLine().Split(' ').Any(s => s == "Y"); Console.WriteLine(isFour ? "Four" : "Three"); } } } internal class Program { public static void Main(string[] args) { var s = new Solution(); s.Run(); } } }
[["+", 0, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 196, 0, 1, 0, 35]]
8
113
6
using System; using System.Collections.Generic; using System.Linq; namespace abc089_b { class program { static void Main(string[] args) { ChangeLocalDebugInput(); Console.ReadLine(); string[] s = Console.ReadLine().Split(' '); List<string> sl = new List<string>(); sl.AddRange(s); int num = sl.Distinct().Count(); string output = ""; if (num == 3) { output = "three"; } else if (num == 4) { output = "four"; } Console.WriteLine(output); } [System.Diagnostics.Conditional("LOCAL_DEBUG")] static void ChangeLocalDebugInput() { Console.SetIn(new System.IO.StreamReader("../../stdin.txt")); } } }
using System; using System.Collections.Generic; using System.Linq; namespace abc089_b { class program { static void Main(string[] args) { ChangeLocalDebugInput(); Console.ReadLine(); string[] s = Console.ReadLine().Split(' '); List<string> sl = new List<string>(); sl.AddRange(s); int num = sl.Distinct().Count(); string output = ""; if (num == 3) { output = "Three"; } else if (num == 4) { output = "Four"; } Console.WriteLine(output); } [System.Diagnostics.Conditional("LOCAL_DEBUG")] static void ChangeLocalDebugInput() { Console.SetIn(new System.IO.StreamReader("../../stdin.txt")); } } }
[["-", 64, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 11, 12, 5, 0, 222]]
8
174
4
using System; using System.Linq; class Program { static void Main(string[] args) { int a = int.Parse(Console.ReadLine()); // スペース区切りの整数の入力 string ans = (Console.ReadLine().IndexOf("Y") > 0) ? "Four" : "Three"; Console.WriteLine(ans); } }
using System; using System.Linq; class Program { static void Main(string[] args) { int a = int.Parse(Console.ReadLine()); // スペース区切りの整数の入力 string ans = (Console.ReadLine().IndexOf("Y") >= 0) ? "Four" : "Three"; Console.WriteLine(ans); } }
[["-", 0, 212, 0, 41, 15, 23, 0, 16, 17, 47], ["+", 0, 212, 0, 41, 15, 23, 0, 16, 17, 20]]
8
73
2
using System; using System.Linq; using System.Collections.Generic; using System.IO; namespace atcorder2 { class Program { public static long Read() { return long.Parse(Console.ReadLine()); } public static long[] Reads() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); } static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var n = Read(); var s = new string[n]; var ch = new char [n][]; var count = new int[] { 0, 0, 0, 0, 0 }; for (int i = 0; i < n; i++) { ch[i] = Console.ReadLine().ToCharArray(); if (ch[i][0] == 'M') count[0]++; if (ch[i][0] == 'A') count[1]++; if (ch[i][0] == 'R') count[2]++; if (ch[i][0] == 'C') count[3]++; if (ch[i][0] == 'H') count[4]++; } long ans = 0; for (int i = 0; i < 3; i++) { for (int j = i + 1; j < 4; j++) { for (int k = j + 1; k < 5; k++) { ans += count[i] * count[j] * count[k]; } } } Console.WriteLine(ans); Console.Out.Flush(); } } }
using System; using System.Linq; using System.Collections.Generic; using System.IO; namespace atcorder2 { class Program { public static long Read() { return long.Parse(Console.ReadLine()); } public static long[] Reads() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); } static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var n = Read(); var s = new string[n]; var ch = new char [n][]; var count = new long[] { 0, 0, 0, 0, 0 }; for (int i = 0; i < n; i++) { ch[i] = Console.ReadLine().ToCharArray(); if (ch[i][0] == 'M') count[0]++; if (ch[i][0] == 'A') count[1]++; if (ch[i][0] == 'R') count[2]++; if (ch[i][0] == 'C') count[3]++; if (ch[i][0] == 'H') count[4]++; } long ans = 0; for (int i = 0; i < 5; i++) { for (int j = i + 1; j < 5; j++) { for (int k = j + 1; k < 5; k++) { ans += count[i] * count[j] * count[k]; } } } Console.WriteLine(ans); Console.Out.Flush(); } } }
[["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 12, 203]]
8
382
6
using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { int n = int.Parse(ReadLine()); List<string> s = new List<string>(); for (int i = 0; i < n; i++) { s.Add(ReadLine()); } List<int> ans = new List<int>(); for (int i = 0; i < 5; i++) { ans.Add(0); } for (int i = 0; i < s.Count; i++) { if (s[i].Substring(0, 1) == "M") { ans[0] += 1; } else if (s[i].Substring(0, 1) == "A") { ans[1] += 1; } else if (s[i].Substring(0, 1) == "R") { ans[2] += 1; } else if (s[i].Substring(0, 1) == "C") { ans[3] += 1; } else if (s[i].Substring(0, 1) == "H") { ans[4] += 1; } } long answ = 0; for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { for (int k = 0; k < 5; k++) { // Write(i); // Write(j); // WriteLine(k); if (i != j && j != k && i != k) { answ += (ans[i] * ans[j] * ans[k]); } } } } // WriteLine(string.Join("",ans)); WriteLine(answ / 6); } }
using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { int n = int.Parse(ReadLine()); List<string> s = new List<string>(); for (int i = 0; i < n; i++) { s.Add(ReadLine()); } List<long> ans = new List<long>(); for (int i = 0; i < 5; i++) { ans.Add(0); } for (int i = 0; i < s.Count; i++) { if (s[i].Substring(0, 1) == "M") { ans[0] += 1; } else if (s[i].Substring(0, 1) == "A") { ans[1] += 1; } else if (s[i].Substring(0, 1) == "R") { ans[2] += 1; } else if (s[i].Substring(0, 1) == "C") { ans[3] += 1; } else if (s[i].Substring(0, 1) == "H") { ans[4] += 1; } } long answ = 0; for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { for (int k = 0; k < 5; k++) { // Write(i); // Write(j); // WriteLine(k); if (i != j && j != k && i != k) { answ += (ans[i] * ans[j] * ans[k]); } } } } // WriteLine(string.Join("",ans)); WriteLine(answ / 6); } }
[["-", 0, 197, 0, 198, 39, 236, 237, 238, 0, 199], ["+", 0, 197, 0, 198, 39, 236, 237, 238, 0, 199], ["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199]]
8
380
4
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; class MainClass : Scanner { static char[] CH = new char[5] { 'M', 'A', 'R', 'C', 'H' }; static void Main() { int N = RInt(); var dic = new Dictionary<char, int>(); dic.Add('M', 0); dic.Add('A', 0); dic.Add('R', 0); dic.Add('C', 0); dic.Add('H', 0); for (int i = 0; i < N; i++) { var r = RString()[0]; if (dic.ContainsKey(r)) { dic[r]++; } } long ans = 0; for (int i = 0; i < 3; i++) { for (int j = i + 1; j < 4; j++) { for (int k = j + 1; k < 5; k++) { ans += dic[CH[i]] * dic[CH[j]] * dic[CH[k]]; } } } WriteLine(ans); } } class Modular { private const int M = 1000000007; private long value; public Modular(long value = 0) { this.value = value; } public static implicit operator Modular(long a) { var m = a % M; return new Modular((m < 0) ? m + M : m); } public static Modular operator +(Modular a, Modular b) => a.value + b.value; public static Modular operator -(Modular a, Modular b) => a.value - b.value; public static Modular operator *(Modular a, Modular b) => a.value * b.value; public static Modular Pow(Modular a, int n) { switch (n) { case 0: return 1; case 1: return a; default: var p = Pow(a, n / 2); return p * p * Pow(a, n % 2); } } public static Modular operator /(Modular a, Modular b) { return a * Pow(b, M - 2); } private static readonly List<int> facs = new List<int> { 1 }; public static Modular Fac(int n) //階乗 { for (int i = facs.Count; i <= n; ++i) { facs.Add((int)(Math.BigMul(facs.Last(), i) % M)); } return facs[n]; } public static Modular Fac(int r, int n) { int temp = 1; for (int i = r; i <= n; i++) { temp = (int)(Math.BigMul(temp, i) % M); } return temp; } public static Modular Ncr(int n, int r) // nCr { return (n < r) ? 0 : (n == r) ? 1 : (n < 1000000) ? Fac(n) / (Fac(r) * Fac(n - r)) : Fac(n - r + 1, n) / Fac(r); } public static explicit operator int(Modular a) { return (int)a.value; } } class Scanner { public static int RInt() => int.Parse(Console.ReadLine()); public static long RLong() => long.Parse(Console.ReadLine()); public static string RString() => Console.ReadLine(); public static double RDouble() => double.Parse(Console.ReadLine()); public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse); public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray(); public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse); public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray(); public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse); public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray(); public static string[] RStrings() => Console.ReadLine().Split(); // public static string[] RStrings(Func<string, string> func) => // Console.ReadLine().Split().Select(func).ToArray(); public static T1 ReadStream<T1>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); return r1; } public static (T1, T2) ReadStream<T1, T2>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); return (r1, r2); } public static (T1, T2, T3) ReadStream<T1, T2, T3>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); var r3 = (T3)Convert.ChangeType(r[2], typeof(T3)); return (r1, r2, r3); } public static (T1, T2, T3, T4) ReadStream<T1, T2, T3, T4>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); var r3 = (T3)Convert.ChangeType(r[0], typeof(T3)); var r4 = (T4)Convert.ChangeType(r[0], typeof(T4)); return (r1, r2, r3, r4); } }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; class MainClass : Scanner { static char[] CH = new char[5] { 'M', 'A', 'R', 'C', 'H' }; static void Main() { int N = RInt(); var dic = new Dictionary<char, long>(); dic.Add('M', 0); dic.Add('A', 0); dic.Add('R', 0); dic.Add('C', 0); dic.Add('H', 0); for (int i = 0; i < N; i++) { var r = RString()[0]; if (dic.ContainsKey(r)) { dic[r]++; } } long ans = 0; for (int i = 0; i < 3; i++) { for (int j = i + 1; j < 4; j++) { for (int k = j + 1; k < 5; k++) { ans += dic[CH[i]] * dic[CH[j]] * dic[CH[k]]; } } } WriteLine(ans); } } class Modular { private const int M = 1000000007; private long value; public Modular(long value = 0) { this.value = value; } public static implicit operator Modular(long a) { var m = a % M; return new Modular((m < 0) ? m + M : m); } public static Modular operator +(Modular a, Modular b) => a.value + b.value; public static Modular operator -(Modular a, Modular b) => a.value - b.value; public static Modular operator *(Modular a, Modular b) => a.value * b.value; public static Modular Pow(Modular a, int n) { switch (n) { case 0: return 1; case 1: return a; default: var p = Pow(a, n / 2); return p * p * Pow(a, n % 2); } } public static Modular operator /(Modular a, Modular b) { return a * Pow(b, M - 2); } private static readonly List<int> facs = new List<int> { 1 }; public static Modular Fac(int n) //階乗 { for (int i = facs.Count; i <= n; ++i) { facs.Add((int)(Math.BigMul(facs.Last(), i) % M)); } return facs[n]; } public static Modular Fac(int r, int n) { int temp = 1; for (int i = r; i <= n; i++) { temp = (int)(Math.BigMul(temp, i) % M); } return temp; } public static Modular Ncr(int n, int r) // nCr { return (n < r) ? 0 : (n == r) ? 1 : (n < 1000000) ? Fac(n) / (Fac(r) * Fac(n - r)) : Fac(n - r + 1, n) / Fac(r); } public static explicit operator int(Modular a) { return (int)a.value; } } class Scanner { public static int RInt() => int.Parse(Console.ReadLine()); public static long RLong() => long.Parse(Console.ReadLine()); public static string RString() => Console.ReadLine(); public static double RDouble() => double.Parse(Console.ReadLine()); public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse); public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray(); public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse); public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray(); public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse); public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray(); public static string[] RStrings() => Console.ReadLine().Split(); // public static string[] RStrings(Func<string, string> func) => // Console.ReadLine().Split().Select(func).ToArray(); public static T1 ReadStream<T1>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); return r1; } public static (T1, T2) ReadStream<T1, T2>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); return (r1, r2); } public static (T1, T2, T3) ReadStream<T1, T2, T3>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); var r3 = (T3)Convert.ChangeType(r[2], typeof(T3)); return (r1, r2, r3); } public static (T1, T2, T3, T4) ReadStream<T1, T2, T3, T4>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); var r3 = (T3)Convert.ChangeType(r[0], typeof(T3)); var r4 = (T4)Convert.ChangeType(r[0], typeof(T4)); return (r1, r2, r3, r4); } }
[["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199]]
8
1,340
2
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using static System.Math; using System.Text; using System.Threading; namespace Program { public static class ABC089C { static public void Solve() { var N = NN; var SList = NSList(N); var sani = SList.Select(e => e[0]) .Where(e => new[] { 'M', 'A', 'R', 'C', 'H' }.Contains(e)) .ToArray(); var dic = new Dictionary<char, int>(); dic['M'] = 0; dic['A'] = 0; dic['R'] = 0; dic['C'] = 0; dic['H'] = 0; foreach (var item in sani) { dic[item]++; } var count = dic.Where(e => e.Value > 0).Count(); var ans = 0L; var march = new[] { 'M', 'A', 'R', 'C', 'H' }; for (var i = 0; i < 5; i++) { for (var j = i + 1; j < 5; j++) { for (var k = j + 1; k < 5; k++) { var item1 = march[i]; var item2 = march[j]; var item3 = march[k]; if (item1 == item2 || item2 == item3 || item1 == item3) continue; ans += dic[item1] * dic[item2] * dic[item3]; } } } Console.WriteLine(ans); } static public void Main(string[] args) { if (args.Length == 0) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } var t = new Thread(Solve, 134217728); t.Start(); t.Join(); Console.Out.Flush(); } static Random rand = new Random(); static class Console_ { static Queue<string> param = new Queue<string>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } } static long NN => long.Parse(Console_.NextString()); static double ND => double.Parse(Console_.NextString()); static string NS => Console_.NextString(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static IEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => rand.Next()); [MethodImpl(MethodImplOptions.AggressiveInlining)] static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n); [MethodImpl(MethodImplOptions.AggressiveInlining)] static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c); [MethodImpl(MethodImplOptions.AggressiveInlining)] static void RevSort<T>(T[] l) where T : IComparable { Array.Sort(l, (x, y) => y.CompareTo(x)); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static void RevSort<T>(T[] l, Comparison<T> comp) where T : IComparable { Array.Sort(l, (x, y) => comp(y, x)); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static IEnumerable<long> Primes(long x) { if (x < 2) yield break; yield return 2; var halfx = x / 2; var table = new bool[halfx + 1]; var max = (long)(Math.Sqrt(x) / 2); for (long i = 1; i <= max; ++i) { if (table[i]) continue; var add = 2 * i + 1; yield return add; for (long j = 2 * i * (i + 1); j <= halfx; j += add) table[j] = true; } for (long i = max + 1; i <= halfx; ++i) if (!table[i] && 2 * i + 1 <= x) yield return 2 * i + 1; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static IEnumerable<long> Factors(long x) { if (x < 2) yield break; while (x % 2 == 0) { x /= 2; yield return 2; } var max = (long)Math.Sqrt(x); for (long i = 3; i <= max; i += 2) while (x % i == 0) { x /= i; yield return i; } if (x != 1) yield return x; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static IEnumerable<long> Divisor(long x) { if (x < 1) yield break; var max = (long)Math.Sqrt(x); for (long i = 1; i <= max; ++i) { if (x % i != 0) continue; yield return i; if (i != x / i) yield return x / i; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] static long GCD(long a, long b) { while (b > 0) { var tmp = b; b = a % b; a = tmp; } return a; } static long LCM(long a, long b) => a * b / GCD(a, b); [MethodImpl(MethodImplOptions.AggressiveInlining)] static Mat<T> Pow<T>(Mat<T> x, long y) => Mat<T>.Pow(x, y); [MethodImpl(MethodImplOptions.AggressiveInlining)] static T Pow<T>(T x, long y) { T a = (dynamic)1; while (y != 0) { if ((y & 1) == 1) a *= (dynamic)x; x *= (dynamic)x; y >>= 1; } return a; } static List<long> _fact = new List<long>() { 1 }; [MethodImpl(MethodImplOptions.AggressiveInlining)] static void _B(long n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) _fact.Add(_fact[i - 1] * i); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static long Comb(long n, long k) { _B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static long Perm(long n, long k) { _B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static Func<TR> Lambda<TR>(Func<Func<TR>, TR> f) { Func<TR> t = () => default(TR); return t = () => f(t); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static Func<T1, TR> Lambda<T1, TR>(Func<T1, Func<T1, TR>, TR> f) { Func<T1, TR> t = x1 => default(TR); return t = x1 => f(x1, t); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static Func<T1, T2, TR> Lambda<T1, T2, TR>(Func<T1, T2, Func<T1, T2, TR>, TR> f) { Func<T1, T2, TR> t = (x1, x2) => default(TR); return t = (x1, x2) => f(x1, x2, t); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static Func<T1, T2, T3, TR> Lambda<T1, T2, T3, TR>(Func<T1, T2, T3, Func<T1, T2, T3, TR>, TR> f) { Func<T1, T2, T3, TR> t = (x1, x2, x3) => default(TR); return t = (x1, x2, x3) => f(x1, x2, x3, t); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static Func<T1, T2, T3, T4, TR> Lambda<T1, T2, T3, T4, TR>( Func<T1, T2, T3, T4, Func<T1, T2, T3, T4, TR>, TR> f) { Func<T1, T2, T3, T4, TR> t = (x1, x2, x3, x4) => default(TR); return t = (x1, x2, x3, x4) => f(x1, x2, x3, x4, t); } class PQ<T> where T : IComparable { List<T> h; Comparison<T> c; public T Peek => h[0]; public int Count => h.Count; [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(int cap, Comparison<T> c, bool asc = true) { h = new List<T>(cap); this.c = asc ? c : (x, y) => c(y, x); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(Comparison<T> c, bool asc = true) { h = new List<T>(); this.c = asc ? c : (x, y) => c(y, x); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(int cap, bool asc = true) : this(cap, (x, y) => x.CompareTo(y), asc) {} [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(bool asc = true) : this((x, y) => x.CompareTo(y), asc) {} [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Push(T v) { var i = h.Count; h.Add(v); while (i > 0) { var ni = (i - 1) / 2; if (c(v, h[ni]) >= 0) break; h[i] = h[ni]; i = ni; } h[i] = v; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Pop() { var r = h[0]; var v = h[h.Count - 1]; h.RemoveAt(h.Count - 1); if (h.Count == 0) return r; var i = 0; while (i * 2 + 1 < h.Count) { var i1 = i * 2 + 1; var i2 = i * 2 + 2; if (i2 < h.Count && c(h[i1], h[i2]) > 0) i1 = i2; if (c(v, h[i1]) <= 0) break; h[i] = h[i1]; i = i1; } h[i] = v; return r; } } class PQ<TK, TV> where TK : IComparable { PQ<Tuple<TK, TV>> q; public Tuple<TK, TV> Peek => q.Peek; public int Count => q.Count; [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(int cap, Comparison<TK> c, bool asc = true) { q = new PQ<Tuple<TK, TV>>(cap, (x, y) => c(x.Item1, y.Item1), asc); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(Comparison<TK> c, bool asc = true) { q = new PQ<Tuple<TK, TV>>((x, y) => c(x.Item1, y.Item1), asc); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(int cap, bool asc = true) : this(cap, (x, y) => x.CompareTo(y), asc) {} [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(bool asc = true) : this((x, y) => x.CompareTo(y), asc) {} [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Push(TK k, TV v) => q.Push(Tuple.Create(k, v)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<TK, TV> Pop() => q.Pop(); } public class UF { long[] d; [MethodImpl(MethodImplOptions.AggressiveInlining)] public UF(long s) { d = Repeat(-1L, s).ToArray(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Unite(long x, long y) { x = Root(x); y = Root(y); if (x != y) { if (d[y] < d[x]) { var t = y; y = x; x = t; } d[x] += d[y]; d[y] = x; } return x != y; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool IsSame(long x, long y) => Root(x) == Root(y); [MethodImpl(MethodImplOptions.AggressiveInlining)] public long Root(long x) => d[x] < 0 ? x : d[x] = Root(d[x]); [MethodImpl(MethodImplOptions.AggressiveInlining)] public long Count(long x) => -d[Root(d[x])]; } struct Mod : IEquatable<object> { static public long _mod = 1000000007; long _val; [MethodImpl(MethodImplOptions.AggressiveInlining)] public Mod(long x) { if (x < _mod && x >= 0) _val = x; else if ((_val = x % _mod) < 0) _val += _mod; } static public implicit operator Mod(long x) => new Mod(x); [MethodImpl(MethodImplOptions.AggressiveInlining)] static public implicit operator long(Mod x) => x._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod operator +(Mod x, Mod y) => x._val + y._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod operator -(Mod x, Mod y) => x._val - y._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod operator *(Mod x, Mod y) => x._val * y._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod operator /(Mod x, Mod y) => x._val * Inverse(y._val); [MethodImpl(MethodImplOptions.AggressiveInlining)] static public bool operator ==(Mod x, Mod y) => x._val == y._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public bool operator !=(Mod x, Mod y) => x._val != y._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public long Inverse(long x) { long b = _mod, r = 1, u = 0, t = 0; while (b > 0) { var q = x / b; t = u; u = r - q * u; r = t; t = b; b = x - q * b; x = t; } return r < 0 ? r + _mod : r; } [MethodImpl(MethodImplOptions.AggressiveInlining)] bool IEquatable<object>.Equals(object obj) => obj == null ? false : Equals((Mod)obj); [MethodImpl(MethodImplOptions.AggressiveInlining)] public override bool Equals(object obj) => obj == null ? false : Equals((Mod)obj); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Mod obj) => obj == null ? false : _val == obj._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() => _val.GetHashCode(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public override string ToString() => _val.ToString(); static List<Mod> _fact = new List<Mod>() { 1 }; [MethodImpl(MethodImplOptions.AggressiveInlining)] static void B(long n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) _fact.Add(_fact[i - 1] * i); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod Comb(long n, long k) { B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod Perm(long n, long k) { B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)]; } } struct Mat<T> { T[,] m; [MethodImpl(MethodImplOptions.AggressiveInlining)] public Mat(T[,] v) { m = (T[,])v.Clone(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public implicit operator Mat<T>(T[,] v) => new Mat<T>(v); public T this[int r, int c] { get { return m[r, c]; } set { m[r, c] = value; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> operator +(Mat<T> a, T x) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] += (dynamic)x; return tm; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> operator +(Mat<T> a, Mat<T> b) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] += (dynamic)b[r, c]; return tm; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> operator -(Mat<T> a, T x) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] -= (dynamic)x; return tm; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> operator -(Mat<T> a, Mat<T> b) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] -= (dynamic)b[r, c]; return tm; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> operator *(Mat<T> a, T x) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] *= (dynamic)x; return tm; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> operator *(Mat<T> a, Mat<T> b) { var nr = a.m.GetLength(0); var nc = b.m.GetLength(1); var tm = new T[nr, nc]; for (int i = 0; i < nr; ++i) for (int j = 0; j < nc; ++j) tm[i, j] = (dynamic)0; for (int r = 0; r < nr; ++r) for (int c = 0; c < nc; ++c) for (int i = 0; i < a.m.GetLength(1); ++i) tm[r, c] += a[r, i] * (dynamic)b[i, c]; return tm; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> Pow(Mat<T> x, long y) { var n = x.m.GetLength(0); var t = (Mat<T>)new T[n, n]; for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) t[i, j] = (dynamic)(i == j ? 1 : 0); while (y != 0) { if ((y & 1) == 1) t *= x; x *= x; y >>= 1; } return t; } } class Tree { long N; int l; List<long>[] p; int[] d; long[][] pr; long r; Tuple<long, long, int>[] e; Tuple<long, long>[] b; bool lca; bool euler; bool bfs; [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tree(List<long>[] p_, long r_) { N = p_.Length; p = p_; r = r_; lca = false; euler = false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<long, long>[] FromRoot() { if (!bfs) { var nb = new List<Tuple<long, long>>(); var q = new Queue<long>(); var d = new bool[N]; nb.Add(Tuple.Create(r, -1L)); d[r] = true; q.Enqueue(r); while (q.Count > 0) { var w = q.Dequeue(); foreach (var i in p[w]) { if (d[i]) continue; d[i] = true; q.Enqueue(i); nb.Add(Tuple.Create(i, w)); } } b = nb.ToArray(); bfs = true; } return b; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<long, long>[] FromLeaf() => FromRoot().Reverse().ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<long, long, int>[] Euler() { if (!euler) { var ne = new List<Tuple<long, long, int>>(); var s = new Stack<Tuple<long, long>>(); var d = new bool[N]; d[r] = true; s.Push(Tuple.Create(r, -1L)); while (s.Count > 0) { var w = s.Peek(); var ad = true; foreach (var i in p[w.Item1]) { if (d[i]) continue; d[i] = true; ad = false; s.Push(Tuple.Create(i, w.Item1)); } if (!ad || p[w.Item1].Count == 1) ne.Add(Tuple.Create(w.Item1, w.Item2, 1)); if (ad) { s.Pop(); ne.Add(Tuple.Create(w.Item1, w.Item2, -1)); } } e = ne.ToArray(); euler = true; } return e; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public long LCA(long u, long v) { if (!lca) { l = 0; while (N > (1 << l)) l++; d = new int[N]; pr = Repeat(0, l).Select(_ => new long[N]).ToArray(); d[r] = 0; pr[0][r] = -1; var q = new Stack<long>(); q.Push(r); while (q.Count > 0) { var w = q.Pop(); foreach (var i in p[w]) { if (i == pr[0][w]) continue; q.Push(i); d[i] = d[w] + 1; pr[0][i] = w; } } for (var k = 0; k + 1 < l; k++) for (var w = 0; w < N; w++) if (pr[k][w] < 0) pr[k + 1][w] = -1; else pr[k + 1][w] = pr[k][pr[k][w]]; lca = true; } if (d[u] > d[v]) { var t = u; u = v; v = t; } for (var k = 0; k < l; k++) if ((((d[v] - d[u]) >> k) & 1) != 0) v = pr[k][v]; if (u == v) return u; for (var k = l - 1; k >= 0; k--) if (pr[k][u] != pr[k][v]) { u = pr[k][u]; v = pr[k][v]; } return pr[0][u]; } } class BT<T> where T : IComparable { class Node { public Node l; public Node r; public T v; public bool b; } Comparison<T> c; Node r; bool ch; T lm; [MethodImpl(MethodImplOptions.AggressiveInlining)] public BT(Comparison<T> _c) { c = _c; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public BT() : this((x, y) => x.CompareTo(y)) {} [MethodImpl(MethodImplOptions.AggressiveInlining)] bool R(Node n) => n != null && !n.b; [MethodImpl(MethodImplOptions.AggressiveInlining)] bool B(Node n) => n != null && n.b; [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RtL(Node n) { Node m = n.r, t = m.l; m.l = n; n.r = t; return m; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RtR(Node n) { Node m = n.l, t = m.r; m.r = n; n.l = t; return m; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RtLR(Node n) { n.l = RtL(n.l); return RtR(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RtRL(Node n) { n.r = RtR(n.r); return RtL(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Add(T x) { r = A(r, x); r.b = true; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node A(Node n, T x) { if (n == null) { ch = true; return new Node() { v = x }; } if (c(x, n.v) < 0) n.l = A(n.l, x); else n.r = A(n.r, x); return Bl(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node Bl(Node n) { if (!ch) return n; if (!B(n)) return n; if (R(n.l) && R(n.l.l)) { n = RtR(n); n.l.b = true; } else if (R(n.l) && R(n.l.r)) { n = RtLR(n); n.l.b = true; } else if (R(n.r) && R(n.r.l)) { n = RtRL(n); n.r.b = true; } else if (R(n.r) && R(n.r.r)) { n = RtL(n); n.r.b = true; } else ch = false; return n; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Remove(T x) { r = Rm(r, x); if (r != null) r.b = true; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node Rm(Node n, T x) { if (n == null) { ch = false; return n; } var r = c(x, n.v); if (r < 0) { n.l = Rm(n.l, x); return BlL(n); } if (r > 0) { n.r = Rm(n.r, x); return BlR(n); } if (n.l == null) { ch = n.b; return n.r; } n.l = RmM(n.l); n.v = lm; return BlL(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RmM(Node n) { if (n.r != null) { n.r = RmM(n.r); return BlR(n); } lm = n.v; ch = n.b; return n.l; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node BlL(Node n) { if (!ch) return n; if (B(n.r) && R(n.r.l)) { var b = n.b; n = RtRL(n); n.b = b; n.l.b = true; ch = false; } else if (B(n.r) && R(n.r.r)) { var b = n.b; n = RtL(n); n.b = b; n.r.b = true; n.l.b = true; ch = false; } else if (B(n.r)) { ch = n.b; n.b = true; n.r.b = false; } else { n = RtL(n); n.b = true; n.l.b = false; n.l = BlL(n.l); ch = false; } return n; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node BlR(Node n) { if (!ch) return n; if (B(n.l) && R(n.l.r)) { var b = n.b; n = RtLR(n); n.b = b; n.r.b = true; ch = false; } else if (B(n.l) && R(n.l.l)) { var b = n.b; n = RtR(n); n.b = b; n.l.b = true; n.r.b = true; ch = false; } else if (B(n.l)) { ch = n.b; n.b = true; n.l.b = false; } else { n = RtR(n); n.b = true; n.r.b = false; n.r = BlR(n.r); ch = false; } return n; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Have(T x) { var t = FindUpper(x); return t.Item1 && t.Item2.CompareTo(x) == 0; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<bool, T> FindUpper(T x) { var v = FU(r, x); return v == null ? Tuple.Create(false, default(T)) : v; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Tuple<bool, T> FU(Node n, T x) { if (n == null) return null; var r = c(x, n.v); if (r < 0) { var v = FU(n.l, x); return v == null ? Tuple.Create(true, n.v) : v; } if (r > 0) return FU(n.r, x); return Tuple.Create(true, n.v); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<bool, T> FindLower(T x) { var v = FL(r, x); return v == null ? Tuple.Create(false, default(T)) : v; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Tuple<bool, T> FL(Node n, T x) { if (n == null) return null; var r = c(x, n.v); if (r < 0) return FL(n.l, x); if (r > 0) { var v = FL(n.r, x); return v == null ? Tuple.Create(true, n.v) : v; } return Tuple.Create(true, n.v); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Min() { Node n = r, p = null; while (n != null) { p = n; n = n.l; } return p == null ? default(T) : p.v; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Max() { Node n = r, p = null; while (n != null) { p = n; n = n.r; } return p == null ? default(T) : p.v; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any() => r != null; [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CountSlow() => L(r).Count(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public IEnumerable<T> List() => L(r); [MethodImpl(MethodImplOptions.AggressiveInlining)] IEnumerable<T> L(Node n) { if (n == null) yield break; foreach (var i in L(n.l)) yield return i; yield return n.v; foreach (var i in L(n.r)) yield return i; } } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using static System.Math; using System.Text; using System.Threading; namespace Program { public static class ABC089C { static public void Solve() { var N = NN; var SList = NSList(N); var sani = SList.Select(e => e[0]) .Where(e => new[] { 'M', 'A', 'R', 'C', 'H' }.Contains(e)) .ToArray(); var dic = new Dictionary<char, long>(); dic['M'] = 0; dic['A'] = 0; dic['R'] = 0; dic['C'] = 0; dic['H'] = 0; foreach (var item in sani) { dic[item]++; } var count = dic.Where(e => e.Value > 0).Count(); var ans = 0L; var march = new[] { 'M', 'A', 'R', 'C', 'H' }; for (var i = 0; i < 5; i++) { for (var j = i + 1; j < 5; j++) { for (var k = j + 1; k < 5; k++) { var item1 = march[i]; var item2 = march[j]; var item3 = march[k]; if (item1 == item2 || item2 == item3 || item1 == item3) continue; ans += dic[item1] * dic[item2] * dic[item3]; } } } Console.WriteLine(ans); } static public void Main(string[] args) { if (args.Length == 0) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } var t = new Thread(Solve, 134217728); t.Start(); t.Join(); Console.Out.Flush(); } static Random rand = new Random(); static class Console_ { static Queue<string> param = new Queue<string>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } } static long NN => long.Parse(Console_.NextString()); static double ND => double.Parse(Console_.NextString()); static string NS => Console_.NextString(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static IEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => rand.Next()); [MethodImpl(MethodImplOptions.AggressiveInlining)] static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n); [MethodImpl(MethodImplOptions.AggressiveInlining)] static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c); [MethodImpl(MethodImplOptions.AggressiveInlining)] static void RevSort<T>(T[] l) where T : IComparable { Array.Sort(l, (x, y) => y.CompareTo(x)); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static void RevSort<T>(T[] l, Comparison<T> comp) where T : IComparable { Array.Sort(l, (x, y) => comp(y, x)); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static IEnumerable<long> Primes(long x) { if (x < 2) yield break; yield return 2; var halfx = x / 2; var table = new bool[halfx + 1]; var max = (long)(Math.Sqrt(x) / 2); for (long i = 1; i <= max; ++i) { if (table[i]) continue; var add = 2 * i + 1; yield return add; for (long j = 2 * i * (i + 1); j <= halfx; j += add) table[j] = true; } for (long i = max + 1; i <= halfx; ++i) if (!table[i] && 2 * i + 1 <= x) yield return 2 * i + 1; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static IEnumerable<long> Factors(long x) { if (x < 2) yield break; while (x % 2 == 0) { x /= 2; yield return 2; } var max = (long)Math.Sqrt(x); for (long i = 3; i <= max; i += 2) while (x % i == 0) { x /= i; yield return i; } if (x != 1) yield return x; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static IEnumerable<long> Divisor(long x) { if (x < 1) yield break; var max = (long)Math.Sqrt(x); for (long i = 1; i <= max; ++i) { if (x % i != 0) continue; yield return i; if (i != x / i) yield return x / i; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] static long GCD(long a, long b) { while (b > 0) { var tmp = b; b = a % b; a = tmp; } return a; } static long LCM(long a, long b) => a * b / GCD(a, b); [MethodImpl(MethodImplOptions.AggressiveInlining)] static Mat<T> Pow<T>(Mat<T> x, long y) => Mat<T>.Pow(x, y); [MethodImpl(MethodImplOptions.AggressiveInlining)] static T Pow<T>(T x, long y) { T a = (dynamic)1; while (y != 0) { if ((y & 1) == 1) a *= (dynamic)x; x *= (dynamic)x; y >>= 1; } return a; } static List<long> _fact = new List<long>() { 1 }; [MethodImpl(MethodImplOptions.AggressiveInlining)] static void _B(long n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) _fact.Add(_fact[i - 1] * i); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static long Comb(long n, long k) { _B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static long Perm(long n, long k) { _B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static Func<TR> Lambda<TR>(Func<Func<TR>, TR> f) { Func<TR> t = () => default(TR); return t = () => f(t); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static Func<T1, TR> Lambda<T1, TR>(Func<T1, Func<T1, TR>, TR> f) { Func<T1, TR> t = x1 => default(TR); return t = x1 => f(x1, t); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static Func<T1, T2, TR> Lambda<T1, T2, TR>(Func<T1, T2, Func<T1, T2, TR>, TR> f) { Func<T1, T2, TR> t = (x1, x2) => default(TR); return t = (x1, x2) => f(x1, x2, t); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static Func<T1, T2, T3, TR> Lambda<T1, T2, T3, TR>(Func<T1, T2, T3, Func<T1, T2, T3, TR>, TR> f) { Func<T1, T2, T3, TR> t = (x1, x2, x3) => default(TR); return t = (x1, x2, x3) => f(x1, x2, x3, t); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static Func<T1, T2, T3, T4, TR> Lambda<T1, T2, T3, T4, TR>( Func<T1, T2, T3, T4, Func<T1, T2, T3, T4, TR>, TR> f) { Func<T1, T2, T3, T4, TR> t = (x1, x2, x3, x4) => default(TR); return t = (x1, x2, x3, x4) => f(x1, x2, x3, x4, t); } class PQ<T> where T : IComparable { List<T> h; Comparison<T> c; public T Peek => h[0]; public int Count => h.Count; [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(int cap, Comparison<T> c, bool asc = true) { h = new List<T>(cap); this.c = asc ? c : (x, y) => c(y, x); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(Comparison<T> c, bool asc = true) { h = new List<T>(); this.c = asc ? c : (x, y) => c(y, x); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(int cap, bool asc = true) : this(cap, (x, y) => x.CompareTo(y), asc) {} [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(bool asc = true) : this((x, y) => x.CompareTo(y), asc) {} [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Push(T v) { var i = h.Count; h.Add(v); while (i > 0) { var ni = (i - 1) / 2; if (c(v, h[ni]) >= 0) break; h[i] = h[ni]; i = ni; } h[i] = v; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Pop() { var r = h[0]; var v = h[h.Count - 1]; h.RemoveAt(h.Count - 1); if (h.Count == 0) return r; var i = 0; while (i * 2 + 1 < h.Count) { var i1 = i * 2 + 1; var i2 = i * 2 + 2; if (i2 < h.Count && c(h[i1], h[i2]) > 0) i1 = i2; if (c(v, h[i1]) <= 0) break; h[i] = h[i1]; i = i1; } h[i] = v; return r; } } class PQ<TK, TV> where TK : IComparable { PQ<Tuple<TK, TV>> q; public Tuple<TK, TV> Peek => q.Peek; public int Count => q.Count; [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(int cap, Comparison<TK> c, bool asc = true) { q = new PQ<Tuple<TK, TV>>(cap, (x, y) => c(x.Item1, y.Item1), asc); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(Comparison<TK> c, bool asc = true) { q = new PQ<Tuple<TK, TV>>((x, y) => c(x.Item1, y.Item1), asc); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(int cap, bool asc = true) : this(cap, (x, y) => x.CompareTo(y), asc) {} [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(bool asc = true) : this((x, y) => x.CompareTo(y), asc) {} [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Push(TK k, TV v) => q.Push(Tuple.Create(k, v)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<TK, TV> Pop() => q.Pop(); } public class UF { long[] d; [MethodImpl(MethodImplOptions.AggressiveInlining)] public UF(long s) { d = Repeat(-1L, s).ToArray(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Unite(long x, long y) { x = Root(x); y = Root(y); if (x != y) { if (d[y] < d[x]) { var t = y; y = x; x = t; } d[x] += d[y]; d[y] = x; } return x != y; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool IsSame(long x, long y) => Root(x) == Root(y); [MethodImpl(MethodImplOptions.AggressiveInlining)] public long Root(long x) => d[x] < 0 ? x : d[x] = Root(d[x]); [MethodImpl(MethodImplOptions.AggressiveInlining)] public long Count(long x) => -d[Root(d[x])]; } struct Mod : IEquatable<object> { static public long _mod = 1000000007; long _val; [MethodImpl(MethodImplOptions.AggressiveInlining)] public Mod(long x) { if (x < _mod && x >= 0) _val = x; else if ((_val = x % _mod) < 0) _val += _mod; } static public implicit operator Mod(long x) => new Mod(x); [MethodImpl(MethodImplOptions.AggressiveInlining)] static public implicit operator long(Mod x) => x._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod operator +(Mod x, Mod y) => x._val + y._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod operator -(Mod x, Mod y) => x._val - y._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod operator *(Mod x, Mod y) => x._val * y._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod operator /(Mod x, Mod y) => x._val * Inverse(y._val); [MethodImpl(MethodImplOptions.AggressiveInlining)] static public bool operator ==(Mod x, Mod y) => x._val == y._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public bool operator !=(Mod x, Mod y) => x._val != y._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public long Inverse(long x) { long b = _mod, r = 1, u = 0, t = 0; while (b > 0) { var q = x / b; t = u; u = r - q * u; r = t; t = b; b = x - q * b; x = t; } return r < 0 ? r + _mod : r; } [MethodImpl(MethodImplOptions.AggressiveInlining)] bool IEquatable<object>.Equals(object obj) => obj == null ? false : Equals((Mod)obj); [MethodImpl(MethodImplOptions.AggressiveInlining)] public override bool Equals(object obj) => obj == null ? false : Equals((Mod)obj); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Mod obj) => obj == null ? false : _val == obj._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() => _val.GetHashCode(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public override string ToString() => _val.ToString(); static List<Mod> _fact = new List<Mod>() { 1 }; [MethodImpl(MethodImplOptions.AggressiveInlining)] static void B(long n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) _fact.Add(_fact[i - 1] * i); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod Comb(long n, long k) { B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod Perm(long n, long k) { B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)]; } } struct Mat<T> { T[,] m; [MethodImpl(MethodImplOptions.AggressiveInlining)] public Mat(T[,] v) { m = (T[,])v.Clone(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public implicit operator Mat<T>(T[,] v) => new Mat<T>(v); public T this[int r, int c] { get { return m[r, c]; } set { m[r, c] = value; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> operator +(Mat<T> a, T x) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] += (dynamic)x; return tm; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> operator +(Mat<T> a, Mat<T> b) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] += (dynamic)b[r, c]; return tm; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> operator -(Mat<T> a, T x) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] -= (dynamic)x; return tm; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> operator -(Mat<T> a, Mat<T> b) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] -= (dynamic)b[r, c]; return tm; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> operator *(Mat<T> a, T x) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] *= (dynamic)x; return tm; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> operator *(Mat<T> a, Mat<T> b) { var nr = a.m.GetLength(0); var nc = b.m.GetLength(1); var tm = new T[nr, nc]; for (int i = 0; i < nr; ++i) for (int j = 0; j < nc; ++j) tm[i, j] = (dynamic)0; for (int r = 0; r < nr; ++r) for (int c = 0; c < nc; ++c) for (int i = 0; i < a.m.GetLength(1); ++i) tm[r, c] += a[r, i] * (dynamic)b[i, c]; return tm; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> Pow(Mat<T> x, long y) { var n = x.m.GetLength(0); var t = (Mat<T>)new T[n, n]; for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) t[i, j] = (dynamic)(i == j ? 1 : 0); while (y != 0) { if ((y & 1) == 1) t *= x; x *= x; y >>= 1; } return t; } } class Tree { long N; int l; List<long>[] p; int[] d; long[][] pr; long r; Tuple<long, long, int>[] e; Tuple<long, long>[] b; bool lca; bool euler; bool bfs; [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tree(List<long>[] p_, long r_) { N = p_.Length; p = p_; r = r_; lca = false; euler = false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<long, long>[] FromRoot() { if (!bfs) { var nb = new List<Tuple<long, long>>(); var q = new Queue<long>(); var d = new bool[N]; nb.Add(Tuple.Create(r, -1L)); d[r] = true; q.Enqueue(r); while (q.Count > 0) { var w = q.Dequeue(); foreach (var i in p[w]) { if (d[i]) continue; d[i] = true; q.Enqueue(i); nb.Add(Tuple.Create(i, w)); } } b = nb.ToArray(); bfs = true; } return b; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<long, long>[] FromLeaf() => FromRoot().Reverse().ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<long, long, int>[] Euler() { if (!euler) { var ne = new List<Tuple<long, long, int>>(); var s = new Stack<Tuple<long, long>>(); var d = new bool[N]; d[r] = true; s.Push(Tuple.Create(r, -1L)); while (s.Count > 0) { var w = s.Peek(); var ad = true; foreach (var i in p[w.Item1]) { if (d[i]) continue; d[i] = true; ad = false; s.Push(Tuple.Create(i, w.Item1)); } if (!ad || p[w.Item1].Count == 1) ne.Add(Tuple.Create(w.Item1, w.Item2, 1)); if (ad) { s.Pop(); ne.Add(Tuple.Create(w.Item1, w.Item2, -1)); } } e = ne.ToArray(); euler = true; } return e; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public long LCA(long u, long v) { if (!lca) { l = 0; while (N > (1 << l)) l++; d = new int[N]; pr = Repeat(0, l).Select(_ => new long[N]).ToArray(); d[r] = 0; pr[0][r] = -1; var q = new Stack<long>(); q.Push(r); while (q.Count > 0) { var w = q.Pop(); foreach (var i in p[w]) { if (i == pr[0][w]) continue; q.Push(i); d[i] = d[w] + 1; pr[0][i] = w; } } for (var k = 0; k + 1 < l; k++) for (var w = 0; w < N; w++) if (pr[k][w] < 0) pr[k + 1][w] = -1; else pr[k + 1][w] = pr[k][pr[k][w]]; lca = true; } if (d[u] > d[v]) { var t = u; u = v; v = t; } for (var k = 0; k < l; k++) if ((((d[v] - d[u]) >> k) & 1) != 0) v = pr[k][v]; if (u == v) return u; for (var k = l - 1; k >= 0; k--) if (pr[k][u] != pr[k][v]) { u = pr[k][u]; v = pr[k][v]; } return pr[0][u]; } } class BT<T> where T : IComparable { class Node { public Node l; public Node r; public T v; public bool b; } Comparison<T> c; Node r; bool ch; T lm; [MethodImpl(MethodImplOptions.AggressiveInlining)] public BT(Comparison<T> _c) { c = _c; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public BT() : this((x, y) => x.CompareTo(y)) {} [MethodImpl(MethodImplOptions.AggressiveInlining)] bool R(Node n) => n != null && !n.b; [MethodImpl(MethodImplOptions.AggressiveInlining)] bool B(Node n) => n != null && n.b; [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RtL(Node n) { Node m = n.r, t = m.l; m.l = n; n.r = t; return m; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RtR(Node n) { Node m = n.l, t = m.r; m.r = n; n.l = t; return m; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RtLR(Node n) { n.l = RtL(n.l); return RtR(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RtRL(Node n) { n.r = RtR(n.r); return RtL(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Add(T x) { r = A(r, x); r.b = true; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node A(Node n, T x) { if (n == null) { ch = true; return new Node() { v = x }; } if (c(x, n.v) < 0) n.l = A(n.l, x); else n.r = A(n.r, x); return Bl(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node Bl(Node n) { if (!ch) return n; if (!B(n)) return n; if (R(n.l) && R(n.l.l)) { n = RtR(n); n.l.b = true; } else if (R(n.l) && R(n.l.r)) { n = RtLR(n); n.l.b = true; } else if (R(n.r) && R(n.r.l)) { n = RtRL(n); n.r.b = true; } else if (R(n.r) && R(n.r.r)) { n = RtL(n); n.r.b = true; } else ch = false; return n; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Remove(T x) { r = Rm(r, x); if (r != null) r.b = true; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node Rm(Node n, T x) { if (n == null) { ch = false; return n; } var r = c(x, n.v); if (r < 0) { n.l = Rm(n.l, x); return BlL(n); } if (r > 0) { n.r = Rm(n.r, x); return BlR(n); } if (n.l == null) { ch = n.b; return n.r; } n.l = RmM(n.l); n.v = lm; return BlL(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RmM(Node n) { if (n.r != null) { n.r = RmM(n.r); return BlR(n); } lm = n.v; ch = n.b; return n.l; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node BlL(Node n) { if (!ch) return n; if (B(n.r) && R(n.r.l)) { var b = n.b; n = RtRL(n); n.b = b; n.l.b = true; ch = false; } else if (B(n.r) && R(n.r.r)) { var b = n.b; n = RtL(n); n.b = b; n.r.b = true; n.l.b = true; ch = false; } else if (B(n.r)) { ch = n.b; n.b = true; n.r.b = false; } else { n = RtL(n); n.b = true; n.l.b = false; n.l = BlL(n.l); ch = false; } return n; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node BlR(Node n) { if (!ch) return n; if (B(n.l) && R(n.l.r)) { var b = n.b; n = RtLR(n); n.b = b; n.r.b = true; ch = false; } else if (B(n.l) && R(n.l.l)) { var b = n.b; n = RtR(n); n.b = b; n.l.b = true; n.r.b = true; ch = false; } else if (B(n.l)) { ch = n.b; n.b = true; n.l.b = false; } else { n = RtR(n); n.b = true; n.r.b = false; n.r = BlR(n.r); ch = false; } return n; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Have(T x) { var t = FindUpper(x); return t.Item1 && t.Item2.CompareTo(x) == 0; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<bool, T> FindUpper(T x) { var v = FU(r, x); return v == null ? Tuple.Create(false, default(T)) : v; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Tuple<bool, T> FU(Node n, T x) { if (n == null) return null; var r = c(x, n.v); if (r < 0) { var v = FU(n.l, x); return v == null ? Tuple.Create(true, n.v) : v; } if (r > 0) return FU(n.r, x); return Tuple.Create(true, n.v); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<bool, T> FindLower(T x) { var v = FL(r, x); return v == null ? Tuple.Create(false, default(T)) : v; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Tuple<bool, T> FL(Node n, T x) { if (n == null) return null; var r = c(x, n.v); if (r < 0) return FL(n.l, x); if (r > 0) { var v = FL(n.r, x); return v == null ? Tuple.Create(true, n.v) : v; } return Tuple.Create(true, n.v); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Min() { Node n = r, p = null; while (n != null) { p = n; n = n.l; } return p == null ? default(T) : p.v; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Max() { Node n = r, p = null; while (n != null) { p = n; n = n.r; } return p == null ? default(T) : p.v; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any() => r != null; [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CountSlow() => L(r).Count(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public IEnumerable<T> List() => L(r); [MethodImpl(MethodImplOptions.AggressiveInlining)] IEnumerable<T> L(Node n) { if (n == null) yield break; foreach (var i in L(n.l)) yield return i; yield return n.v; foreach (var i in L(n.r)) yield return i; } } } }
[["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199]]
8
7,639
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); int n = sc.NextInt(); int[] names = new int[5]; for (int i = 0; i < n; i++) { string name = sc.Next(); if (name.StartsWith("M")) { names[0]++; } if (name.StartsWith("A")) { names[1]++; } if (name.StartsWith("R")) { names[2]++; } if (name.StartsWith("C")) { names[3]++; } if (name.StartsWith("H")) { names[4]++; } } long answer = 0; for (int i = 0; i < Math.Pow(2, 5); i++) { int count = 0; for (int j = 0; j < 5; j++) { if ((1 & (i >> j)) == 1) { count++; } } if (count != 3) { continue; } long tmpAnswer = 1; for (int j = 0; j < n; j++) { if ((1 & (i >> j)) == 1) { tmpAnswer *= names[j]; } } answer += tmpAnswer; } Console.WriteLine(answer); } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); int n = sc.NextInt(); int[] names = new int[5]; for (int i = 0; i < n; i++) { string name = sc.Next(); if (name.StartsWith("M")) { names[0]++; } if (name.StartsWith("A")) { names[1]++; } if (name.StartsWith("R")) { names[2]++; } if (name.StartsWith("C")) { names[3]++; } if (name.StartsWith("H")) { names[4]++; } } long answer = 0; for (int i = 0; i < Math.Pow(2, 5); i++) { int count = 0; for (int j = 0; j < 5; j++) { if ((1 & (i >> j)) == 1) { count++; } } if (count != 3) { continue; } long tmpAnswer = 1; for (int j = 0; j < 5; j++) { if ((1 & (i >> j)) == 1) { tmpAnswer *= names[j]; } } answer += tmpAnswer; } Console.WriteLine(answer); } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
[["-", 0, 7, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 12, 203]]
8
607
2
using System; using System.Diagnostics; using System.IO; using System.Text; using System.Linq; using System.Collections.Generic; using System.Text.RegularExpressions; class Program { const string Yes = "Yes"; const string No = "No"; const long Mod = 1000000007; static void Main(string[] args) { #if DEBUG MyDebugger.Test(process, "../TextFile1.txt"); #else object ret = process(new StreamReader(Console.OpenStandardInput())); Console.WriteLine(ret); #endif } static object process(TextReader input) { var n = int.Parse(input.ReadLine()); var hash = new Dictionary<char, int>() { { 'M', 0 }, { 'A', 0 }, { 'R', 0 }, { 'C', 0 }, { 'H', 0 }, }; var ss = new List<string>(); for (int i = 0; i < n; i++) { var s = input.ReadLine(); if (hash.ContainsKey(s[0])) { hash[s[0]]++; } } Func<char, char, char, long> f = (i1, i2, i3) => { return hash[i1] * hash[i2] * hash[i3]; }; long x = 0; x += f('M', 'A', 'R'); x += f('M', 'A', 'C'); x += f('M', 'A', 'H'); x += f('M', 'R', 'C'); x += f('M', 'R', 'H'); x += f('M', 'C', 'H'); x += f('A', 'R', 'C'); x += f('A', 'R', 'H'); x += f('A', 'C', 'H'); x += f('R', 'C', 'H'); return x; } static int[] ToIntArray(string strs, int n) { var ret = new int[n]; var spl = strs.Split(' '); for (int i = 0; i < n; i++) ret[i] = int.Parse(spl[i]); return ret; } }
using System; using System.Diagnostics; using System.IO; using System.Text; using System.Linq; using System.Collections.Generic; using System.Text.RegularExpressions; class Program { const string Yes = "Yes"; const string No = "No"; const long Mod = 1000000007; static void Main(string[] args) { #if DEBUG MyDebugger.Test(process, "../TextFile1.txt"); #else object ret = process(new StreamReader(Console.OpenStandardInput())); Console.WriteLine(ret); #endif } static object process(TextReader input) { var n = int.Parse(input.ReadLine()); var hash = new Dictionary<char, long>() { { 'M', 0 }, { 'A', 0 }, { 'R', 0 }, { 'C', 0 }, { 'H', 0 }, }; var ss = new List<string>(); for (int i = 0; i < n; i++) { var s = input.ReadLine(); if (hash.ContainsKey(s[0])) { hash[s[0]]++; } } Func<char, char, char, long> f = (i1, i2, i3) => { return hash[i1] * hash[i2] * hash[i3]; }; long x = 0; x += f('M', 'A', 'R'); x += f('M', 'A', 'C'); x += f('M', 'A', 'H'); x += f('M', 'R', 'C'); x += f('M', 'R', 'H'); x += f('M', 'C', 'H'); x += f('A', 'R', 'C'); x += f('A', 'R', 'H'); x += f('A', 'C', 'H'); x += f('R', 'C', 'H'); return x; } static int[] ToIntArray(string strs, int n) { var ret = new int[n]; var spl = strs.Split(' '); for (int i = 0; i < n; i++) ret[i] = int.Parse(spl[i]); return ret; } }
[["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199]]
8
536
2
using System; using System.Collections.Generic; using System.Linq; class Program { static Scanner sc = new Scanner(); static void Main(string[] args) { var N = sc.ReadInt(); var S = sc.ReadStrArray(N); var m = 0; var a = 0; var r = 0; var c = 0; var h = 0; for (int i = 0; i < N; i++) { if (S[i][0] == 'M') m++; else if (S[i][0] == 'A') a++; else if (S[i][0] == 'R') r++; else if (S[i][0] == 'C') c++; else if (S[i][0] == 'H') h++; } var counts = new int[5] { m, a, r, c, h }; if (counts.Count(x => x == 0) >= 3) { Console.WriteLine(0); } else { var ans = 0L; var seq = counts.Where(x => x != 0).ToArray(); for (int i = 0; i < seq.Count(); i++) { for (int j = i + 1; j < seq.Count(); j++) { for (int k = j + 1; k < seq.Count(); k++) { checked { ans += seq[i] * seq[j] * seq[k]; } } } } Console.WriteLine(ans); } } } class Modulo { public readonly int MOD; private readonly List<int> Facs = new List<int>() { 1 }; public Modulo(int mod = 1000000007) { this.MOD = mod; } public int Mul(int a, int b) { return (int)(Math.BigMul(a, b) % MOD); } public int Div(int a, int b) { return Mul(a, Pow(b, MOD - 2)); } public int Pow(int a, int n) { switch (n) { case 0: return 1; case 1: return a; default: int p1 = Pow(a, n / 2); int p2 = Mul(p1, p1); return ((n % 2) == 0) ? p2 : Mul(p2, a); } } public int Fac(int n) { for (int i = this.Facs.Count; i <= n; i++) { this.Facs.Add(Mul(i, Facs[i - 1])); } return this.Facs[n]; } public int nPr(int n, int r) => Div(Fac(n), Fac(n - r)); public int nCr(int n, int r) { if (n < r) return 0; if (n == r) return 1; int res = Fac(n); res = Div(res, Fac(r)); res = Div(res, Fac(n - r)); return res; } } class Debug { public static void Dump<T>(T[,] array) { Console.WriteLine(); var h = array.GetLength(0); var w = array.GetLength(1); for (int r = 0; r < h; r++) { for (int c = 0; c < w; c++) { Console.Write(array[r, c]); Console.Write(" "); } Console.WriteLine(); } Console.WriteLine(); } public static void Dump<T>(T[] array) { Console.WriteLine(); Console.WriteLine(string.Join(" ", array)); Console.WriteLine(); } } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } } class HashMap<K, V> : Dictionary<K, V> where V : new() { private V DefaltValue = new V(); public HashMap() {} public HashMap(V defaultValue) { this.DefaltValue = new V(); } new public V this[K i] { get { V v; return TryGetValue(i, out v) ? v : base[i] = this.DefaltValue; } set { base[i] = value; } } }
using System; using System.Collections.Generic; using System.Linq; class Program { static Scanner sc = new Scanner(); static void Main(string[] args) { var N = sc.ReadInt(); var S = sc.ReadStrArray(N); var m = 0L; var a = 0L; var r = 0L; var c = 0L; var h = 0L; for (int i = 0; i < N; i++) { if (S[i][0] == 'M') m++; else if (S[i][0] == 'A') a++; else if (S[i][0] == 'R') r++; else if (S[i][0] == 'C') c++; else if (S[i][0] == 'H') h++; } var counts = new long[5] { m, a, r, c, h }; if (counts.Count(x => x == 0) >= 3) { Console.WriteLine(0); } else { var ans = 0L; var seq = counts.Where(x => x != 0).ToArray(); for (int i = 0; i < seq.Count(); i++) { for (int j = i + 1; j < seq.Count(); j++) { for (int k = j + 1; k < seq.Count(); k++) { checked { ans += seq[i] * seq[j] * seq[k]; } } } } Console.WriteLine(ans); } } } class Modulo { public readonly int MOD; private readonly List<int> Facs = new List<int>() { 1 }; public Modulo(int mod = 1000000007) { this.MOD = mod; } public int Mul(int a, int b) { return (int)(Math.BigMul(a, b) % MOD); } public int Div(int a, int b) { return Mul(a, Pow(b, MOD - 2)); } public int Pow(int a, int n) { switch (n) { case 0: return 1; case 1: return a; default: int p1 = Pow(a, n / 2); int p2 = Mul(p1, p1); return ((n % 2) == 0) ? p2 : Mul(p2, a); } } public int Fac(int n) { for (int i = this.Facs.Count; i <= n; i++) { this.Facs.Add(Mul(i, Facs[i - 1])); } return this.Facs[n]; } public int nPr(int n, int r) => Div(Fac(n), Fac(n - r)); public int nCr(int n, int r) { if (n < r) return 0; if (n == r) return 1; int res = Fac(n); res = Div(res, Fac(r)); res = Div(res, Fac(n - r)); return res; } } class Debug { public static void Dump<T>(T[,] array) { Console.WriteLine(); var h = array.GetLength(0); var w = array.GetLength(1); for (int r = 0; r < h; r++) { for (int c = 0; c < w; c++) { Console.Write(array[r, c]); Console.Write(" "); } Console.WriteLine(); } Console.WriteLine(); } public static void Dump<T>(T[] array) { Console.WriteLine(); Console.WriteLine(string.Join(" ", array)); Console.WriteLine(); } } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } } class HashMap<K, V> : Dictionary<K, V> where V : new() { private V DefaltValue = new V(); public HashMap() {} public HashMap(V defaultValue) { this.DefaltValue = new V(); } new public V this[K i] { get { V v; return TryGetValue(i, out v) ? v : base[i] = this.DefaltValue; } set { base[i] = value; } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199]]
8
1,359
12
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { static class Program { static void Main() { var N = GetInt(); Dictionary<char, int> march = new Dictionary<char, int>(); var C = new char[] { 'M', 'A', 'R', 'C', 'H' }; foreach (var c in C) { march.Add(c, 0); } var S = new char[N]; for (int i = 0; i < N; i++) { S[i] = GetStr()[0]; } foreach (var s in S) { if (march.ContainsKey(s)) march[s]++; } long ans = 0; var keys = march.Keys.ToArray(); for (int i = 0; i < 3; i++) { for (int j = i + 1; j < 4; j++) { for (int k = j + 1; k < 5; k++) { ans += march[keys[i]] * march[keys[j]] * march[keys[k]]; } } } Console.WriteLine(ans); Console.ReadKey(); } static void Solve() {} static public string GetStr() { return Console.ReadLine().Trim(); } static public int GetInt() { return int.Parse(Console.ReadLine()); } static public long GetLong() { return long.Parse(Console.ReadLine()); } static public string[] GetStrArray() { return Console.ReadLine().Split(' '); } static public int[] GetIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } static public long[] GetLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } static public char[] GetCharArray() { return Console.ReadLine().Split(' ').Select(char.Parse).ToArray(); } static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); } static public void WriteObjects<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } } static string yesno(this bool b) { return b ? "yes" : "no"; } static string YesNo(this bool b) { return b ? "Yes" : "No"; } static string YESNO(this bool b) { return b ? "YES" : "NO"; } static bool eq<T, U>() => typeof(T).Equals(typeof(U)); static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); static 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, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); static void Multi<T>(out T a) => a = cv<T>(GetStr()); static void Multi<T, U>(out T a, out U b) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); } static 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]); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { static class Program { static void Main() { var N = GetInt(); Dictionary<char, long> march = new Dictionary<char, long>(); var C = new char[] { 'M', 'A', 'R', 'C', 'H' }; foreach (var c in C) { march.Add(c, 0); } var S = new char[N]; for (int i = 0; i < N; i++) { S[i] = GetStr()[0]; } foreach (var s in S) { if (march.ContainsKey(s)) march[s]++; } long ans = 0; var keys = march.Keys.ToArray(); for (int i = 0; i < 3; i++) { for (int j = i + 1; j < 4; j++) { for (int k = j + 1; k < 5; k++) { ans += march[keys[i]] * march[keys[j]] * march[keys[k]]; } } } Console.WriteLine(ans); Console.ReadKey(); } static void Solve() {} static public string GetStr() { return Console.ReadLine().Trim(); } static public int GetInt() { return int.Parse(Console.ReadLine()); } static public long GetLong() { return long.Parse(Console.ReadLine()); } static public string[] GetStrArray() { return Console.ReadLine().Split(' '); } static public int[] GetIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } static public long[] GetLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } static public char[] GetCharArray() { return Console.ReadLine().Split(' ').Select(char.Parse).ToArray(); } static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); } static public void WriteObjects<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } } static string yesno(this bool b) { return b ? "yes" : "no"; } static string YesNo(this bool b) { return b ? "Yes" : "No"; } static string YESNO(this bool b) { return b ? "YES" : "NO"; } static bool eq<T, U>() => typeof(T).Equals(typeof(U)); static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); static 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, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); static void Multi<T>(out T a) => a = cv<T>(GetStr()); static void Multi<T, U>(out T a, out U b) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); } static 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]); } } }
[["-", 0, 197, 0, 198, 39, 236, 237, 238, 0, 199], ["+", 0, 197, 0, 198, 39, 236, 237, 238, 0, 199], ["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199]]
8
927
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp93 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); var S = new string[N]; var num_array = new int[5]; for (int i = 0; i < N; i++) { S[i] = Console.ReadLine(); } num_array[0] = S.Where(x => x[0] == 'M').Count(); num_array[1] = S.Where(x => x[0] == 'A').Count(); num_array[2] = S.Where(x => x[0] == 'R').Count(); num_array[3] = S.Where(x => x[0] == 'C').Count(); num_array[4] = S.Where(x => x[0] == 'H').Count(); int ans = 0; for (int i = 0; i < 5; i++) { for (int j = i + 1; j < 5; j++) { for (int k = j + 1; k < 5; k++) { ans += num_array[i] * num_array[j] * num_array[k]; } } } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp93 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); var S = new string[N]; var num_array = new int[5]; for (int i = 0; i < N; i++) { S[i] = Console.ReadLine(); } num_array[0] = S.Where(x => x[0] == 'M').Count(); num_array[1] = S.Where(x => x[0] == 'A').Count(); num_array[2] = S.Where(x => x[0] == 'R').Count(); num_array[3] = S.Where(x => x[0] == 'C').Count(); num_array[4] = S.Where(x => x[0] == 'H').Count(); long ans = 0; for (int i = 0; i < 5; i++) { for (int j = i + 1; j < 5; j++) { for (int k = j + 1; k < 5; k++) { ans += (long)num_array[i] * num_array[j] * num_array[k]; } } } Console.WriteLine(ans); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 11, 12, 16, 31, 16, 31, 74, 0, 24], ["+", 0, 11, 12, 16, 31, 16, 31, 74, 39, 199], ["+", 0, 11, 12, 16, 31, 16, 31, 74, 0, 25]]
8
311
5
using System; using System.Collections.Generic; namespace MyProgram { class AtCoder { static void Main() { int N = int.Parse(Console.ReadLine()); string[] S = new string[N]; for (var i = 0; i < N; i++) { S[i] = Console.ReadLine(); } int[] march = { 0, 0, 0, 0, 0 }; for (var i = 0; i < N; i++) { switch (S[i][0]) { case 'M': march[0]++; break; case 'A': march[1]++; break; case 'R': march[2]++; break; case 'C': march[3]++; break; case 'H': march[4]++; break; default: break; } } long sum = 0; for (var i = 0; i < 3; i++) { for (var j = i + 1; j < 4; j++) { for (var k = j + 1; k < 5; k++) { sum += march[i] * march[j] * march[k]; } } } Console.WriteLine(sum); } } }
using System; using System.Collections.Generic; namespace MyProgram { class AtCoder { static void Main() { int N = int.Parse(Console.ReadLine()); string[] S = new string[N]; for (var i = 0; i < N; i++) { S[i] = Console.ReadLine(); } long[] march = { 0, 0, 0, 0, 0 }; for (var i = 0; i < N; i++) { switch (S[i][0]) { case 'M': march[0]++; break; case 'A': march[1]++; break; case 'R': march[2]++; break; case 'C': march[3]++; break; case 'H': march[4]++; break; default: break; } } long sum = 0; for (var i = 0; i < 3; i++) { for (var j = i + 1; j < 4; j++) { for (var k = j + 1; k < 5; k++) { sum += march[i] * march[j] * march[k]; } } } Console.WriteLine(sum); } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199]]
8
272
2
using System; using System.Collections; using System.Collections.Generic; using System.Text; using System.IO; using System.Linq; using static System.Console; using static System.Math; namespace abc_91_c { class Program { static void Main(string[] args) { int n = int.Parse(ReadLine()); int[][] red = new int [n][]; int[][] blue = new int [n][]; for (int i = 0; i < n; i++) { int[] input = ReadLine().Split().Select(int.Parse).ToArray(); red[i] = input; } for (int i = 0; i < n; i++) { int[] input = ReadLine().Split().Select(int.Parse).ToArray(); blue[i] = input; } red = red.OrderByDescending(a => a[1]).ToArray(); blue = blue.OrderBy(a => a[0]).ToArray(); int count = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (red[j] == null) continue; if (red[j][0] < blue[j][0] && red[j][1] < blue[j][1]) { count++; red[j] = null; break; } } } WriteLine(count); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Text; using System.IO; using System.Linq; using static System.Console; using static System.Math; namespace abc_91_c { class Program { static void Main(string[] args) { int n = int.Parse(ReadLine()); int[][] red = new int [n][]; int[][] blue = new int [n][]; for (int i = 0; i < n; i++) { int[] input = ReadLine().Split().Select(int.Parse).ToArray(); red[i] = input; } for (int i = 0; i < n; i++) { int[] input = ReadLine().Split().Select(int.Parse).ToArray(); blue[i] = input; } red = red.OrderByDescending(a => a[1]).ToArray(); blue = blue.OrderBy(a => a[0]).ToArray(); int count = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (red[j] == null) continue; if (red[j][0] < blue[i][0] && red[j][1] < blue[i][1]) { count++; red[j] = null; break; } } } WriteLine(count); } } }
[["-", 12, 204, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 12, 204, 205, 204, 206, 207, 0, 28, 0, 22]]
8
334
4
using System.Linq; using System; public class P { public int x { get; set; } public int y { get; set; } public bool del { get; set; } } public class Hello { public static void Main() { var n = int.Parse(Console.ReadLine().Trim()); var red = setArray(n); var blue = setArray(n); var count = 0; foreach (var x in blue.OrderBy(y => y.x)) { var t = red.Where(z => z.x < x.x && z.y < x.y && !z.del) .OrderByDescending(z => z.x); if (t.Count() > 0) { t.First().del = true; count++; } } Console.WriteLine(count); } public static P[] setArray(int n) { var w = new P[n]; for (int i = 0; i < n; i++) { string[] line = Console.ReadLine().Trim().Split(' '); var c = int.Parse(line[0]); var d = int.Parse(line[1]); w[i] = new P { x = c, y = d }; } return w; } }
using System.Linq; using System; public class P { public int x { get; set; } public int y { get; set; } public bool del { get; set; } } public class Hello { public static void Main() { var n = int.Parse(Console.ReadLine().Trim()); var red = setArray(n); var blue = setArray(n); var count = 0; foreach (var x in blue.OrderBy(y => y.x)) { var t = red.Where(z => z.x < x.x && z.y < x.y && !z.del) .OrderByDescending(z => z.y); if (t.Count() > 0) { t.First().del = true; count++; } } Console.WriteLine(count); } public static P[] setArray(int n) { var w = new P[n]; for (int i = 0; i < n; i++) { string[] line = Console.ReadLine().Trim().Split(' '); var c = int.Parse(line[0]); var d = int.Parse(line[1]); w[i] = new P { x = c, y = d }; } return w; } }
[["-", 3, 4, 0, 28, 0, 218, 8, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 214, 141, 22]]
8
287
2
using System; using System.Collections; using System.Collections.Generic; class Program { public static int N; public static List<int>[] list = new List<int>[110]; static void Main(string[] args) { int[] rx = new int[110]; int[] ry = new int[110]; int[] bx = new int[110]; int[] by = new int[110]; // スペース区切りの整数の入力 N = int.Parse(Console.ReadLine()); for (int i = 0; i < N; i++) { string[] input = Console.ReadLine().Split(' '); rx[i] = int.Parse(input[0]); ry[i] = int.Parse(input[1]); } for (int i = 0; i < N; i++) { string[] input = Console.ReadLine().Split(' '); bx[i] = int.Parse(input[0]); by[i] = int.Parse(input[1]); } int lastvalue = 0; for (int j = 0; j < N; j++) { // xでソート for (int i = 1; i < N; i++) { if (bx[i] < bx[i - 1]) { int tmp = bx[i - 1]; bx[i - 1] = bx[i]; bx[i] = tmp; tmp = by[i - 1]; by[i - 1] = by[i]; by[i] = tmp; } } } for (int j = 0; j < N; j++) { // yでソート for (int i = 1; i < N; i++) { if (ry[i] > ry[i - 1]) { int tmp = ry[i - 1]; ry[i - 1] = ry[i]; ry[i] = tmp; tmp = ry[i - 1]; rx[i - 1] = rx[i]; rx[i] = tmp; } } } // for (int i = 0; i < N; i++) { //リスト追加 // list[i] = new List<int>(); // for (int j = 0; j < N; j++) { // if (rx[j] < bx[i] && ry[j] < by[i] ) { // list[i].Add(j); // } // } // } bool[] chked = new bool[110]; int count = 0; // for (int i = 0; i < N; i++) { // if (list[i].Count!=0){ // for (int j = 0; j < list[i].Count; j++) { // if (chked[list[i][j]]!=true){ // chked[list[i][j]]=true; // count++; // } // } // } // } for (int i = 0; i < N; i++) { //リスト追加 for (int j = 0; j < N; j++) { if (rx[j] < bx[i] && ry[j] < by[i] && chked[j] == false) { count++; chked[j] = true; break; } } } // Console.WriteLine("rr"); // for (int i = 0; i < N; i++) { // Console.WriteLine(""+rx[i]+","+ry[i]); // } // Console.WriteLine("bb"); // for (int i = 0; i < N; i++) { // Console.WriteLine(""+bx[i]+","+by[i]); // } // search( 0); Console.WriteLine(count); } // public static int ctr=0; // public static bool[] chk = new bool[110]; // public static int maxv=0; // public static int[] lastAdd = new int[110]; // public static void search( int b ) { // if (ctr == N) { // if (lastAdd[ctr-1]!=-1)chk[lastAdd[ctr-1]] = false; // if (maxv<b)maxv=b; // ctr--; // return; // } // for (int i = 0; i < list[ctr].Count; i++) { // if (list[ctr][i] != -1 && !chk[list[ctr][i]] ) { // lastAdd[ctr] = list[ctr][i]; // chk[list[ctr][i]] = true; // ctr++; // search( b + 1); // }else{ // lastAdd[ctr] = -1; // ctr++; // search( b ); // } // } // if (ctr>0)if (lastAdd[ctr-1]!=-1)chk[lastAdd[ctr-1]] = false; // ctr--; // return; // } }
using System; using System.Collections; using System.Collections.Generic; class Program { public static int N; public static List<int>[] list = new List<int>[110]; static void Main(string[] args) { int[] rx = new int[110]; int[] ry = new int[110]; int[] bx = new int[110]; int[] by = new int[110]; // スペース区切りの整数の入力 N = int.Parse(Console.ReadLine()); for (int i = 0; i < N; i++) { string[] input = Console.ReadLine().Split(' '); rx[i] = int.Parse(input[0]); ry[i] = int.Parse(input[1]); } for (int i = 0; i < N; i++) { string[] input = Console.ReadLine().Split(' '); bx[i] = int.Parse(input[0]); by[i] = int.Parse(input[1]); } int lastvalue = 0; for (int j = 0; j < N; j++) { // xでソート for (int i = 1; i < N; i++) { if (bx[i] < bx[i - 1]) { int tmp; tmp = bx[i - 1]; bx[i - 1] = bx[i]; bx[i] = tmp; tmp = by[i - 1]; by[i - 1] = by[i]; by[i] = tmp; } } } for (int j = 0; j < N; j++) { // yでソート for (int i = 1; i < N; i++) { if (ry[i] > ry[i - 1]) { int tmp = ry[i - 1]; ry[i - 1] = ry[i]; ry[i] = tmp; tmp = rx[i - 1]; rx[i - 1] = rx[i]; rx[i] = tmp; } } } // Console.WriteLine("rr"); // for (int i = 0; i < N; i++) { // Console.WriteLine(""+rx[i]+","+ry[i]); // } // Console.WriteLine("bb"); // for (int i = 0; i < N; i++) { // Console.WriteLine(""+bx[i]+","+by[i]); // } bool[] chked = new bool[110]; int count = 0; for (int i = 0; i < N; i++) { //リスト追加 for (int j = 0; j < N; j++) { if (rx[j] < bx[i] && ry[j] < by[i] && chked[j] == false) { count++; chked[j] = true; break; } } } // search( 0); Console.WriteLine(count); } // public static int ctr=0; // public static bool[] chk = new bool[110]; // public static int maxv=0; // public static int[] lastAdd = new int[110]; // public static void search( int b ) { // if (ctr == N) { // if (lastAdd[ctr-1]!=-1)chk[lastAdd[ctr-1]] = false; // if (maxv<b)maxv=b; // ctr--; // return; // } // for (int i = 0; i < list[ctr].Count; i++) { // if (list[ctr][i] != -1 && !chk[list[ctr][i]] ) { // lastAdd[ctr] = list[ctr][i]; // chk[list[ctr][i]] = true; // ctr++; // search( b + 1); // }else{ // lastAdd[ctr] = -1; // ctr++; // search( b ); // } // } // if (ctr>0)if (lastAdd[ctr-1]!=-1)chk[lastAdd[ctr-1]] = false; // ctr--; // return; // } }
[["+", 8, 196, 0, 57, 64, 196, 0, 197, 0, 35], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 204, 205, 22]]
8
610
4
using System; using System.Collections.Generic; using System.Linq; namespace Atcoder { class Program { static void Main(string[] args) { var a = ReadStringToCharArray(); var b = ReadStringToCharArray(); var c = ReadStringToCharArray(); Console.WriteLine(a[0] + b[1] + c[2]); } static int[] ReadInt() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); } static char[] ReadStringToCharArray() { return Console.ReadLine().ToArray(); } } }
using System; using System.Collections.Generic; using System.Linq; namespace Atcoder { class Program { static void Main(string[] args) { var a = ReadStringToCharArray(); var b = ReadStringToCharArray(); var c = ReadStringToCharArray(); Console.WriteLine("{0}{1}{2}", a[0], b[1], c[2]); } static int[] ReadInt() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); } static char[] ReadStringToCharArray() { return Console.ReadLine().ToArray(); } } }
[["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 17, 72], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72]]
8
134
8
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Diagnostics; class Myon { public Myon() {} public static int Main() { new Myon().calc(); return 0; } Scanner cin; Func cin2; void calc() { cin = new Scanner(); cin2 = new Func(); string s = cin.next(); string s1 = cin.next(); string s2 = cin.next(); Console.WriteLine(s[0] + s1[1] + s2[2]); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } class Answer { public void Int2DArrayAns(int[,] x, char c) { for (int i = 0; i < x.GetLength(0); i++) { for (int j = 0; j < x.GetLength(1) - 1; j++) { Console.Write(x[i, j]); Console.Write(c); } Console.WriteLine(x[i, x.GetLength(1) - 1]); } } public void Char2DArrayAns(char[,] x, char c) { for (int i = 0; i < x.GetLength(0); i++) { for (int j = 0; j < x.GetLength(1) - 1; j++) { Console.Write(x[i, j]); Console.Write(c); } Console.WriteLine(x[i, x.GetLength(1) - 1]); } } } class Func { public long GCDLong(long a, long b) { while (a != 0) { long t = a; a = b % a; b = t; } return b; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Diagnostics; class Myon { public Myon() {} public static int Main() { new Myon().calc(); return 0; } Scanner cin; Func cin2; void calc() { cin = new Scanner(); cin2 = new Func(); string s = cin.next(); string s1 = cin.next(); string s2 = cin.next(); Console.WriteLine(s[0] + "" + s1[1] + s2[2]); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } class Answer { public void Int2DArrayAns(int[,] x, char c) { for (int i = 0; i < x.GetLength(0); i++) { for (int j = 0; j < x.GetLength(1) - 1; j++) { Console.Write(x[i, j]); Console.Write(c); } Console.WriteLine(x[i, x.GetLength(1) - 1]); } } public void Char2DArrayAns(char[,] x, char c) { for (int i = 0; i < x.GetLength(0); i++) { for (int j = 0; j < x.GetLength(1) - 1; j++) { Console.Write(x[i, j]); Console.Write(c); } Console.WriteLine(x[i, x.GetLength(1) - 1]); } } } class Func { public long GCDLong(long a, long b) { while (a != 0) { long t = a; a = b % a; b = t; } return b; } }
[["+", 0, 16, 31, 16, 31, 16, 12, 5, 0, 62], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 72]]
8
730
3
using System; using System.Collections.Generic; using System.Linq; using static System.Math; namespace ConsoleApp1 { class Program { static void Main(string[] args) { A(); } static void A() { var a = Read(); var b = Read(); var c = Read(); Println($"{a[1]}{b[1]}{c[1]}"); } static List<long> ReadLines(long n) { var l = new List<long>(); for (long i = 0; i < n; i++) { l.Add(ReadLong()); } return l; } static IEnumerable<int> Range(int start, int stop) { if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0)) return new List<int>(); return Enumerable.Range(start, stop - start); } static bool IsDigit(string str) { var i = 0; return int.TryParse(str, out i); } static int SumDigits(long num) { return num.ToString().Select(x => x.ToString()).Sum(int.Parse); } static int[] ToIntArray(string str) { return str.Select(x => x.ToString()).Select(int.Parse).ToArray(); } static long Gcd(long a, long b) => b == 0 ? a : Gcd(b, a % b); static long Lcm(long a, long b) => a / Gcd(a, b) * b; static bool IsPrime(int x) { if (x <= 1 || (x != 2 && x % 2 == 0)) return false; if (x == 2) return true; for (int i = 3; i < x; i += 2) if (x % i == 0) return false; return true; } static string Read() => Console.ReadLine(); static int ReadInt() => int.Parse(Read()); static long ReadLong() => long.Parse(Read()); static List<string> ReadSplit() => Read().Split().ToList(); static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList(); static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList(); static void Print(object value) => Console.Write(value.ToString()); static void Println(object value) => Console.WriteLine(value.ToString()); static string Join<T>(IEnumerable<T> list) => string.Join("", list); } public static class MyExtensions { public static string Slice(this string str, int start = 0, int stop = 0) { if (start > str.Length || stop > str.Length || start < 0 || stop < 0) return ""; if (stop == 0) stop = str.Length; return str.Substring(start, stop - start); } } }
using System; using System.Collections.Generic; using System.Linq; using static System.Math; namespace ConsoleApp1 { class Program { static void Main(string[] args) { A(); } static void A() { var a = Read(); var b = Read(); var c = Read(); Println($"{a[0]}{b[1]}{c[2]}"); } static List<long> ReadLines(long n) { var l = new List<long>(); for (long i = 0; i < n; i++) { l.Add(ReadLong()); } return l; } static IEnumerable<int> Range(int start, int stop) { if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0)) return new List<int>(); return Enumerable.Range(start, stop - start); } static bool IsDigit(string str) { var i = 0; return int.TryParse(str, out i); } static int SumDigits(long num) { return num.ToString().Select(x => x.ToString()).Sum(int.Parse); } static int[] ToIntArray(string str) { return str.Select(x => x.ToString()).Select(int.Parse).ToArray(); } static long Gcd(long a, long b) => b == 0 ? a : Gcd(b, a % b); static long Lcm(long a, long b) => a / Gcd(a, b) * b; static bool IsPrime(int x) { if (x <= 1 || (x != 2 && x % 2 == 0)) return false; if (x == 2) return true; for (int i = 3; i < x; i += 2) if (x % i == 0) return false; return true; } static string Read() => Console.ReadLine(); static int ReadInt() => int.Parse(Read()); static long ReadLong() => long.Parse(Read()); static List<string> ReadSplit() => Read().Split().ToList(); static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList(); static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList(); static void Print(object value) => Console.Write(value.ToString()); static void Println(object value) => Console.WriteLine(value.ToString()); static string Join<T>(IEnumerable<T> list) => string.Join("", list); } public static class MyExtensions { public static string Slice(this string str, int start = 0, int stop = 0) { if (start > str.Length || stop > str.Length || start < 0 || stop < 0) return ""; if (stop == 0) stop = str.Length; return str.Substring(start, stop - start); } } }
[["-", 0, 284, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 284, 0, 204, 206, 207, 0, 28, 0, 203]]
8
676
4
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; class Program { static void Main() { //入力 // int[] input = Console.ReadLine().Split().Select(i => // int.Parse(i)).ToArray(); string input= Console.ReadLine(); string[] input = new string[3]; for (int a = 0; a < 3; a++) { input[a] = Console.ReadLine(); } // int input =int.Parse(input[0]+""+input[3+1]+""+input[3*2+2]); Console.WriteLine( int.Parse(input[0][0] + "" + input[1][1] + "" + input[2][2])); /* //処理速度計測 var sw = new System.Diagnostics.Stopwatch(); sw.Start(); //解法 //処理速度表示 sw.Stop(); TimeSpan ts = sw.Elapsed; Console.WriteLine((int)(Math.Floor((ts).TotalMilliseconds))+"ms"); */ Console.ReadLine(); } }
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; class Program { static void Main() { //入力 // int[] input = Console.ReadLine().Split().Select(i => // int.Parse(i)).ToArray(); string input= Console.ReadLine(); string[] input = new string[3]; for (int a = 0; a < 3; a++) { input[a] = Console.ReadLine(); } // int input =int.Parse(input[0]+""+input[3+1]+""+input[3*2+2]); Console.WriteLine(input[0][0] + "" + input[1][1] + "" + input[2][2]); /* //処理速度計測 var sw = new System.Diagnostics.Stopwatch(); sw.Start(); //解法 //処理速度表示 sw.Stop(); TimeSpan ts = sw.Elapsed; Console.WriteLine((int)(Math.Floor((ts).TotalMilliseconds))+"ms"); */ Console.ReadLine(); } }
[["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 199], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
126
5
using System; using System.Collections.Generic; using System.Linq; using static Atcoder; using System.Threading.Tasks; using System.ComponentModel; public class Hello { public static void Main() { string s0 = Console.ReadLine(); string s1 = Console.ReadLine(); string s2 = Console.ReadLine(); Console.WriteLine(s0[0] + s1[1] + s2[2]); } } public class Atcoder { static void Swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } public static int LCM(int a, int b) { int c = a * b; if (a < b) Swap(ref a, ref b); int d = a % b; while (d != 0) { a = b; b = d; d = a % b; } return c / b; } public static string strReverce(string s) { return new string(s.Reverse().ToArray()); } public static int Cin() { return int.Parse(Console.ReadLine()); } public static bool IsPrime(int n) { if (n < 2) return false; if (n == 2) return true; if (n % 2 == 0) return false; // double sqrtNum = Math.Sqrt(n); for (int i = 3; i < n; i += 2) { if (n % i == 0) return false; } return true; } public static string[] SpRead(char c) { return Console.ReadLine().Split(c); } }
using System; using System.Collections.Generic; using System.Linq; using static Atcoder; using System.Threading.Tasks; using System.ComponentModel; public class Hello { public static void Main() { string s0 = Console.ReadLine(); string s1 = Console.ReadLine(); string s2 = Console.ReadLine(); Console.WriteLine("" + s0[0] + s1[1] + s2[2]); } } public class Atcoder { static void Swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } public static int LCM(int a, int b) { int c = a * b; if (a < b) Swap(ref a, ref b); int d = a % b; while (d != 0) { a = b; b = d; d = a % b; } return c / b; } public static string strReverce(string s) { return new string(s.Reverse().ToArray()); } public static int Cin() { return int.Parse(Console.ReadLine()); } public static bool IsPrime(int n) { if (n < 2) return false; if (n == 2) return true; if (n % 2 == 0) return false; // double sqrtNum = Math.Sqrt(n); for (int i = 3; i < n; i += 2) { if (n % i == 0) return false; } return true; } public static string[] SpRead(char c) { return Console.ReadLine().Split(c); } }
[["+", 0, 16, 31, 16, 31, 16, 31, 5, 0, 62], ["+", 0, 28, 0, 16, 31, 16, 31, 16, 17, 72]]
8
335
3
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; namespace Contest { class Scanner { private string[] line = new string[0]; private int index = 0; public string Next() { if (line.Length <= index) { line = Console.ReadLine().Split(' '); index = 0; } var res = line[index]; index++; return res; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public string[] Array() { line = Console.ReadLine().Split(' '); index = line.Length; return line; } public int[] IntArray() { return Array().Select(int.Parse).ToArray(); } public long[] LongArray() { return Array().Select(long.Parse).ToArray(); } } struct P { public int X, Y; public P(int x, int y) { X = x; Y = y; } } class Program { private void Scan() { var sc = new Scanner(); for (int i = 0; i < 3; i++) { Console.Write(sc.Next()[i]); Console.WriteLine(); } } public void Solve() { Scan(); } static void Main(string[] args) { new Program().Solve(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; namespace Contest { class Scanner { private string[] line = new string[0]; private int index = 0; public string Next() { if (line.Length <= index) { line = Console.ReadLine().Split(' '); index = 0; } var res = line[index]; index++; return res; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public string[] Array() { line = Console.ReadLine().Split(' '); index = line.Length; return line; } public int[] IntArray() { return Array().Select(int.Parse).ToArray(); } public long[] LongArray() { return Array().Select(long.Parse).ToArray(); } } struct P { public int X, Y; public P(int x, int y) { X = x; Y = y; } } class Program { private void Scan() { var sc = new Scanner(); for (int i = 0; i < 3; i++) { Console.Write(sc.Next()[i]); } Console.WriteLine(); } public void Solve() { Scan(); } static void Main(string[] args) { new Program().Solve(); } } }
[["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46]]
8
340
2
using System; using System.Collections.Generic; using System.Linq; using static System.Console; class Program { static void Main() { var s = ReadLine(); var d = ReadLine(); var f = ReadLine(); WriteLine(s[0] + d[1] + f[2]); } }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; class Program { static void Main() { var s = ReadLine(); var d = ReadLine(); var f = ReadLine(); WriteLine(s[0] + "" + d[1] + f[2]); } }
[["+", 0, 16, 31, 16, 31, 16, 12, 5, 0, 62], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 72]]
8
71
3
using System; namespace AtCoder { internal static class Program { private static void Main() { int[] AB = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); int res = 0; for (int i = 0; i < AB[1] - AB[0]; i++) { string temp = (i + AB[0]).ToString(); bool palindrome = true; for (int y = 0; y < temp.Length; y++) if (temp[y] != temp[temp.Length - 1 - y]) { palindrome = false; break; } if (palindrome) res++; } Console.WriteLine(res); } } }
using System; namespace AtCoder { internal static class Program { private static void Main() { int[] AB = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); int res = 0; for (int i = 0; i < AB[1] - AB[0] + 1; i++) { string temp = (i + AB[0]).ToString(); bool palindrome = true; for (int y = 0; y < temp.Length; y++) if (temp[y] != temp[temp.Length - 1 - y]) { palindrome = false; break; } if (palindrome) res++; } Console.WriteLine(res); } } }
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
151
2
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Security.Cryptography.X509Certificates; using System.Text.RegularExpressions; using Console = System.Console; namespace Atcoder { class Program { static void Main(string[] args) { var l = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var A = l[0]; var B = l[1]; int count = 0; for (int i = A; i < B; i++) { var checkTarget = i.ToString().ToCharArray(); if (checkTarget[0] == checkTarget[4] && checkTarget[1] == checkTarget[3]) { count++; } } Console.WriteLine(count); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Security.Cryptography.X509Certificates; using System.Text.RegularExpressions; using Console = System.Console; namespace Atcoder { class Program { static void Main(string[] args) { var l = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var A = l[0]; var B = l[1]; int count = 0; for (int i = A; i <= B; i++) { var checkTarget = i.ToString().ToCharArray(); if (checkTarget[0] == checkTarget[4] && checkTarget[1] == checkTarget[3]) { count++; } } Console.WriteLine(count); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
173
2
using System; namespace ABC090 { class B { static void Main(string[] args) { string[] input = Console.ReadLine().Split(); int A = int.Parse(input[0]); int B = int.Parse(input[1]); int count = 0; string s; for (int i = A; i < B; i++) { s = i.ToString(); if (s[0] == s[s.Length - 1] && s[1] == s[s.Length - 2]) { count++; } } Console.WriteLine(count); } } }
using System; namespace ABC090 { class B { static void Main(string[] args) { string[] input = Console.ReadLine().Split(); int A = int.Parse(input[0]); int B = int.Parse(input[1]); int count = 0; string s; for (int i = A; i <= B; i++) { s = i.ToString(); if (s[0] == s[s.Length - 1] && s[1] == s[s.Length - 2]) { count++; } } Console.WriteLine(count); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
137
2
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using static System.Console; using static System.Math; namespace AtCoder { class Program { static void Main(string[] args) { var ab = ReadInts(); var ans = 0; for (int i = ab[0]; i < ab[1]; i++) { var str = i.ToString(); if (str[0] == str[4] && str[1] == str[3]) { ans++; } } WriteLine(ans); } private static string Read() { return ReadLine(); } private static string[] Reads() { return (Read().Split()); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } public static bool IsPrime(int num) { if (num < 2) return false; else if (num == 2) return true; else if (num % 2 == 0) return false; double sqrtNum = Sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) { return false; } } return true; } //最大公約数 public static int Gcd(int a, int b) { if (a < b) { return Gcd(b, a); } while (b != 0) { var reminder = a % b; a = b; b = reminder; } return a; } //最小公倍数 public static int Lcm(int a, int b) { return a * b / Gcd(a, b); } //文字数を数える public static int CountChar(string s, char c) { return s.Length - s.Replace(c.ToString(), "").Length; } public static void debuglist(List<int> x) { foreach (var item in x) { WriteLine(item); } } public static void debuglist(List<string> x) { foreach (var item in x) { WriteLine(item); } } public static void debugarray(int[] x) { foreach (var item in x) { WriteLine(item); } } public static void debugarray(string[] x) { foreach (var item in x) { WriteLine(item); } } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using static System.Console; using static System.Math; namespace AtCoder { class Program { static void Main(string[] args) { var ab = ReadInts(); var ans = 0; for (int i = ab[0]; i <= ab[1]; i++) { var str = i.ToString(); if (str[0] == str[4] && str[1] == str[3]) { ans++; } } WriteLine(ans); } private static string Read() { return ReadLine(); } private static string[] Reads() { return (Read().Split()); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } public static bool IsPrime(int num) { if (num < 2) return false; else if (num == 2) return true; else if (num % 2 == 0) return false; double sqrtNum = Sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) { return false; } } return true; } //最大公約数 public static int Gcd(int a, int b) { if (a < b) { return Gcd(b, a); } while (b != 0) { var reminder = a % b; a = b; b = reminder; } return a; } //最小公倍数 public static int Lcm(int a, int b) { return a * b / Gcd(a, b); } //文字数を数える public static int CountChar(string s, char c) { return s.Length - s.Replace(c.ToString(), "").Length; } public static void debuglist(List<int> x) { foreach (var item in x) { WriteLine(item); } } public static void debuglist(List<string> x) { foreach (var item in x) { WriteLine(item); } } public static void debugarray(int[] x) { foreach (var item in x) { WriteLine(item); } } public static void debugarray(string[] x) { foreach (var item in x) { WriteLine(item); } } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
608
2
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace MyProgram { public class Program { public static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int a = int.Parse(input[0]); int b = int.Parse(input[1]); int cnt = 0; for (int i = a; i < b; i++) { if (Check(i)) cnt++; } Console.WriteLine(cnt); } public static bool Check(int target) { string s = target.ToString(); char[] c = s.ToCharArray(); string s2 = ""; for (int i = s.Length - 1; i >= 0; i--) { s2 += c[i]; } if (s == s2) return true; else return false; } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace MyProgram { public class Program { public static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int a = int.Parse(input[0]); int b = int.Parse(input[1]); int cnt = 0; for (int i = a; i <= b; i++) { if (Check(i)) cnt++; } Console.WriteLine(cnt); } public static bool Check(int target) { string s = target.ToString(); char[] c = s.ToCharArray(); string s2 = ""; for (int i = s.Length - 1; i >= 0; i--) { s2 += c[i]; } if (s == s2) return true; else return false; } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
199
2
using System; namespace ABC090_B_Palindromic_Numbers { internal class Program { public static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int a = int.Parse(input[0]); int b = int.Parse(input[1]); int count = 0; for (int i = a; i <= b; i++) { string firstword = i.ToString().Substring(0, 1); string secondWord = i.ToString().Substring(1, 1); string beforeLastWord = i.ToString().Substring(3, 1); string lastWord = i.ToString().Substring(4, 1); if (firstword == beforeLastWord && secondWord == lastWord) { count++; } } Console.WriteLine(count); } } }
using System; namespace ABC090_B_Palindromic_Numbers { internal class Program { public static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int a = int.Parse(input[0]); int b = int.Parse(input[1]); int count = 0; for (int i = a; i <= b; i++) { string firstword = i.ToString().Substring(0, 1); string secondWord = i.ToString().Substring(1, 1); string beforeLastWord = i.ToString().Substring(3, 1); string lastWord = i.ToString().Substring(4, 1); if (firstword == lastWord && secondWord == beforeLastWord) { count++; } } Console.WriteLine(count); } } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22]]
8
175
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace test { class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); var A = input[0]; var B = input[1]; var ans = 0; for (var i = A; i < B; i++) { var S = i.ToString(); if (S[0] == S[4] && S[1] == S[3]) ans++; } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace test { class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); var A = input[0]; var B = input[1]; var ans = 0; for (var i = A; i <= B; i++) { var S = i.ToString(); if (S[0] == S[4] && S[1] == S[3]) ans++; } Console.WriteLine(ans); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
156
2
using System; using System.Linq; using System.Diagnostics; using System.Collections.Generic; class P { static void Main() { int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray(); int res = 0; for (int i = a[0]; i < a[1]; i++) { var s = i.ToString(); if (s[0] == s[4] && s[1] == s[3]) res++; } Console.WriteLine(res); } }
using System; using System.Linq; using System.Diagnostics; using System.Collections.Generic; class P { static void Main() { int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray(); int res = 0; for (int i = a[0]; i <= a[1]; i++) { var s = i.ToString(); if (s[0] == s[4] && s[1] == s[3]) res++; } Console.WriteLine(res); } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
125
2
using System; using System.Collections.Generic; using System.Linq; using static System.Console; class Program { static void Main() { var n = ReadLine().Split().Select(int.Parse).ToArray(); int c = 0; for (int i = n[0]; i <= n[1]; i++) { var s = n.ToString(); if (s[0] == s[4] && s[1] == s[3]) c++; } WriteLine(c); } }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; class Program { static void Main() { var n = ReadLine().Split().Select(int.Parse).ToArray(); int c = 0; for (int i = n[0]; i <= n[1]; i++) { var s = i.ToString(); if (s[0] == s[4] && s[1] == s[3]) c++; } WriteLine(c); } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22]]
8
120
2
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Numerics; namespace FertiLib.Contest.C { static class Program { public static void Solve(Scanner cin) { var (n, m) = cin.ReadValue<int, int>(); Console.WriteLine(Math.Abs((n - 2) * (m - 2))); } public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var cin = new Scanner(); Solve(cin); Console.Out.Flush(); } public static void YESNO(bool condition) => Console.WriteLine(condition ? "YES" : "NO"); public static void YesNo(bool condition) => Console.WriteLine(condition ? "Yes" : "No"); public static void yesno(bool condition) => Console.WriteLine(condition ? "yes" : "no"); public static bool Chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) >= 0) return false; a = b; return true; } public static bool Chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) <= 0) return false; a = b; return true; } } static class Util { public static string Join<T>(this IEnumerable<T> x, string separator = "") => string.Join(separator, x); } class Scanner { string[] s; int i; char[] separator = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string Read() => ReadString(); public string ReadString() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(separator, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return ReadString(); i = 0; return s[i++]; } public string[] ReadStringArray(int N) { string[] Array = new string[N]; for (int i = 0; i < N; i++) { Array[i] = ReadString(); } return Array; } public int ReadInt() { return int.Parse(ReadString()); } public int[] ReadIntArray(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = ReadInt() + add; } return Array; } public long ReadLong() { return long.Parse(ReadString()); } public long[] ReadLongArray(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = ReadLong() + add; } return Array; } public double ReadDouble() { return double.Parse(ReadString()); } public double[] ReadDoubleArray(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = ReadDouble() + add; } return Array; } public T1 ReadValue<T1>() => (T1)Convert.ChangeType(ReadString(), typeof(T1)); public (T1, T2) ReadValue<T1, T2>() { var inputs = ReadStringArray(2); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); return (v1, v2); } public (T1, T2, T3) ReadValue<T1, T2, T3>() { var inputs = ReadStringArray(3); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); return (v1, v2, v3); } public (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>() { var inputs = ReadStringArray(4); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); return (v1, v2, v3, v4); } public (T1, T2, T3, T4, T5) ReadValue<T1, T2, T3, T4, T5>() { var inputs = ReadStringArray(5); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); return (v1, v2, v3, v4, v5); } public (T1, T2, T3, T4, T5, T6) ReadValue<T1, T2, T3, T4, T5, T6>() { var inputs = ReadStringArray(6); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6)); return (v1, v2, v3, v4, v5, v6); } public (T1, T2, T3, T4, T5, T6, T7) ReadValue<T1, T2, T3, T4, T5, T6, T7>() { var inputs = ReadStringArray(7); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6)); var v7 = (T7)Convert.ChangeType(inputs[6], typeof(T7)); return (v1, v2, v3, v4, v5, v6, v7); } public T1[] ReadValueArray<T1>(int N) { var v1 = new T1[N]; for (int i = 0; i < N; i++) { v1[i] = ReadValue<T1>(); } return v1; } public (T1[], T2[]) ReadValueArray<T1, T2>(int N) { var (v1, v2) = (new T1[N], new T2[N]); for (int i = 0; i < N; i++) { var (t1, t2) = ReadValue<T1, T2>(); v1[i] = t1; v2[i] = t2; } return (v1, v2); } public (T1[], T2[], T3[]) ReadValueArray<T1, T2, T3>(int N) { var (v1, v2, v3) = (new T1[N], new T2[N], new T3[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3) = ReadValue<T1, T2, T3>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; } return (v1, v2, v3); } public (T1[], T2[], T3[], T4[]) ReadValueArray<T1, T2, T3, T4>(int N) { var (v1, v2, v3, v4) = (new T1[N], new T2[N], new T3[N], new T4[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4) = ReadValue<T1, T2, T3, T4>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; } return (v1, v2, v3, v4); } public (T1[], T2[], T3[], T4[], T5[]) ReadValueArray<T1, T2, T3, T4, T5>(int N) { var (v1, v2, v3, v4, v5) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5) = ReadValue<T1, T2, T3, T4, T5>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; } return (v1, v2, v3, v4, v5); } public (T1[], T2[], T3[], T4[], T5[], T6[]) ReadValueArray<T1, T2, T3, T4, T5, T6>(int N) { var (v1, v2, v3, v4, v5, v6) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5, t6) = ReadValue<T1, T2, T3, T4, T5, T6>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; v6[i] = t6; } return (v1, v2, v3, v4, v5, v6); } public (T1[], T2[], T3[], T4[], T5[], T6[], T7[]) ReadValueArray<T1, T2, T3, T4, T5, T6, T7>(int N) { var (v1, v2, v3, v4, v5, v6, v7) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N], new T7[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5, t6, t7) = ReadValue<T1, T2, T3, T4, T5, T6, T7>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; v6[i] = t6; v7[i] = t7; } return (v1, v2, v3, v4, v5, v6, v7); } } }
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Numerics; namespace FertiLib.Contest.C { static class Program { public static void Solve(Scanner cin) { var (n, m) = cin.ReadValue<long, long>(); Console.WriteLine(Math.Abs((n - 2) * (m - 2))); } public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var cin = new Scanner(); Solve(cin); Console.Out.Flush(); } public static void YESNO(bool condition) => Console.WriteLine(condition ? "YES" : "NO"); public static void YesNo(bool condition) => Console.WriteLine(condition ? "Yes" : "No"); public static void yesno(bool condition) => Console.WriteLine(condition ? "yes" : "no"); public static bool Chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) >= 0) return false; a = b; return true; } public static bool Chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) <= 0) return false; a = b; return true; } } static class Util { public static string Join<T>(this IEnumerable<T> x, string separator = "") => string.Join(separator, x); } class Scanner { string[] s; int i; char[] separator = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string Read() => ReadString(); public string ReadString() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(separator, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return ReadString(); i = 0; return s[i++]; } public string[] ReadStringArray(int N) { string[] Array = new string[N]; for (int i = 0; i < N; i++) { Array[i] = ReadString(); } return Array; } public int ReadInt() { return int.Parse(ReadString()); } public int[] ReadIntArray(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = ReadInt() + add; } return Array; } public long ReadLong() { return long.Parse(ReadString()); } public long[] ReadLongArray(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = ReadLong() + add; } return Array; } public double ReadDouble() { return double.Parse(ReadString()); } public double[] ReadDoubleArray(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = ReadDouble() + add; } return Array; } public T1 ReadValue<T1>() => (T1)Convert.ChangeType(ReadString(), typeof(T1)); public (T1, T2) ReadValue<T1, T2>() { var inputs = ReadStringArray(2); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); return (v1, v2); } public (T1, T2, T3) ReadValue<T1, T2, T3>() { var inputs = ReadStringArray(3); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); return (v1, v2, v3); } public (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>() { var inputs = ReadStringArray(4); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); return (v1, v2, v3, v4); } public (T1, T2, T3, T4, T5) ReadValue<T1, T2, T3, T4, T5>() { var inputs = ReadStringArray(5); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); return (v1, v2, v3, v4, v5); } public (T1, T2, T3, T4, T5, T6) ReadValue<T1, T2, T3, T4, T5, T6>() { var inputs = ReadStringArray(6); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6)); return (v1, v2, v3, v4, v5, v6); } public (T1, T2, T3, T4, T5, T6, T7) ReadValue<T1, T2, T3, T4, T5, T6, T7>() { var inputs = ReadStringArray(7); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6)); var v7 = (T7)Convert.ChangeType(inputs[6], typeof(T7)); return (v1, v2, v3, v4, v5, v6, v7); } public T1[] ReadValueArray<T1>(int N) { var v1 = new T1[N]; for (int i = 0; i < N; i++) { v1[i] = ReadValue<T1>(); } return v1; } public (T1[], T2[]) ReadValueArray<T1, T2>(int N) { var (v1, v2) = (new T1[N], new T2[N]); for (int i = 0; i < N; i++) { var (t1, t2) = ReadValue<T1, T2>(); v1[i] = t1; v2[i] = t2; } return (v1, v2); } public (T1[], T2[], T3[]) ReadValueArray<T1, T2, T3>(int N) { var (v1, v2, v3) = (new T1[N], new T2[N], new T3[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3) = ReadValue<T1, T2, T3>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; } return (v1, v2, v3); } public (T1[], T2[], T3[], T4[]) ReadValueArray<T1, T2, T3, T4>(int N) { var (v1, v2, v3, v4) = (new T1[N], new T2[N], new T3[N], new T4[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4) = ReadValue<T1, T2, T3, T4>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; } return (v1, v2, v3, v4); } public (T1[], T2[], T3[], T4[], T5[]) ReadValueArray<T1, T2, T3, T4, T5>(int N) { var (v1, v2, v3, v4, v5) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5) = ReadValue<T1, T2, T3, T4, T5>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; } return (v1, v2, v3, v4, v5); } public (T1[], T2[], T3[], T4[], T5[], T6[]) ReadValueArray<T1, T2, T3, T4, T5, T6>(int N) { var (v1, v2, v3, v4, v5, v6) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5, t6) = ReadValue<T1, T2, T3, T4, T5, T6>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; v6[i] = t6; } return (v1, v2, v3, v4, v5, v6); } public (T1[], T2[], T3[], T4[], T5[], T6[], T7[]) ReadValueArray<T1, T2, T3, T4, T5, T6, T7>(int N) { var (v1, v2, v3, v4, v5, v6, v7) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N], new T7[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5, t6, t7) = ReadValue<T1, T2, T3, T4, T5, T6, T7>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; v6[i] = t6; v7[i] = t7; } return (v1, v2, v3, v4, v5, v6, v7); } } }
[["-", 0, 213, 63, 214, 141, 236, 237, 238, 0, 199], ["+", 0, 213, 63, 214, 141, 236, 237, 238, 0, 199]]
8
2,658
4
using System; using System.Collections.Generic; using System.Linq; class Program { public static void Main() { var input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int M = input[1]; long ans = 0; if (N == 1 && M == 1) ans = 1; if (N == 1 || M == 1) ans = Math.Max(N, M) - 2; if (N > 2 && M > 2) ans = 1L * (N - 2) * (M - 2); Console.WriteLine(ans); } }
using System; using System.Collections.Generic; using System.Linq; class Program { public static void Main() { var input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int M = input[1]; long ans = 0; if (N == 1 && M == 1) ans = 1; else if (N == 1 || M == 1) ans = Math.Max(N, M) - 2; else if (N > 2 && M > 2) ans = 1L * (N - 2) * (M - 2); Console.WriteLine(ans); } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 95]]
8
142
2
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; namespace C { public class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } public static void Solve() { var NM = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); var N = NM[0]; var M = NM[1]; var answer = 0L; if (N == 1 || M == 1) { answer = N == M ? 1 : N * M - 2; } else { var edge = 2 * (N + M - 2); answer = N * M - edge; } Console.WriteLine(answer); } } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; namespace C { public class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } public static void Solve() { var NM = Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); var N = NM[0]; var M = NM[1]; var answer = 0L; if (N == 1 || M == 1) { answer = N == M ? 1 : N * M - 2; } else { var edge = 2 * (N + M - 2); answer = N * M - edge; } Console.WriteLine(answer); } } }
[["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199]]
8
199
2
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using static System.Console; using static System.Math; namespace Atcoder { class Program { static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; static void Main(string[] args) { try { SetOut(sw); Solve.Answer(); Out.Flush(); } catch (Exception ex) { WriteLine(ex.ToString()); } } } public class Solve { public static void Answer() { var nm = IO.RSInt; if (nm[0] == 1 && nm[1] == 1) { WriteLine(1); return; } if (nm[0] == 1) { WriteLine(nm[1] - 2); return; } if (nm[1] == 1) { WriteLine(nm[0] - 2); return; } // 2*2以上では外周に隣接するマスは4or6回ひっくり返すので必ず表 WriteLine((nm[0] - 2) * (nm[1] - 2)); } } public class IO { #region Input public static int RInt => int.Parse(ReadLine()); public static long RLong => long.Parse(ReadLine()); public static double RDouble => double.Parse(ReadLine()); public static string[] RSString => ReadLine().Split(); public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray(); public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray(); public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray(); #endregion #region Output public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list)); public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No"); public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO"); #endregion } public class Mod { #region private readonly static long M = 1000000007; public static long Add(long a, long b) => (a * b) % M; public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M; public static long Multi(long a, long b) => (a * b) % M; #endregion } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using static System.Console; using static System.Math; namespace Atcoder { class Program { static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; static void Main(string[] args) { try { SetOut(sw); Solve.Answer(); Out.Flush(); } catch (Exception ex) { WriteLine(ex.ToString()); } } } public class Solve { public static void Answer() { var nm = IO.RSLong; if (nm[0] == 1 && nm[1] == 1) { WriteLine(1); return; } if (nm[0] == 1) { WriteLine(nm[1] - 2); return; } if (nm[1] == 1) { WriteLine(nm[0] - 2); return; } // 2*2以上では外周に隣接するマスは4or6回ひっくり返すので必ず表 WriteLine((nm[0] - 2) * (nm[1] - 2)); } } public class IO { #region Input public static int RInt => int.Parse(ReadLine()); public static long RLong => long.Parse(ReadLine()); public static double RDouble => double.Parse(ReadLine()); public static string[] RSString => ReadLine().Split(); public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray(); public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray(); public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray(); #endregion #region Output public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list)); public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No"); public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO"); #endregion } public class Mod { #region private readonly static long M = 1000000007; public static long Add(long a, long b) => (a * b) % M; public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M; public static long Multi(long a, long b) => (a * b) % M; #endregion } }
[["-", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22]]
8
564
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); long n = sc.NextLong(); long m = sc.NextLong(); long answer = 0; if (n == 1 && m == 1) { answer = 1; } else if (n == 1) { answer = m - 2; } else if (m == 2) { answer = n - 2; } else { answer = n * m - 2 * n - 2 * m + 4; } Console.WriteLine(answer); } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); long n = sc.NextLong(); long m = sc.NextLong(); long answer = 0; if (n == 1 && m == 1) { answer = 1; } else if (n == 1) { answer = m - 2; } else if (m == 1) { answer = n - 2; } else { answer = n * m - 2 * n - 2 * m + 4; } Console.WriteLine(answer); } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
[["-", 0, 57, 75, 57, 75, 57, 15, 16, 12, 203], ["+", 0, 57, 75, 57, 75, 57, 15, 16, 12, 203]]
8
429
2
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { var t = Array.ConvertAll(Console.ReadLine().Split(new[] { ' ' }), number => int.Parse(number)); var n = t[0] == 1 ? 1 : t[0] - 2; var m = t[1] == 1 ? 1 : t[1] - 2; Console.WriteLine(n * m); //デバッグ実行での確認用。そのまま提出しても問題なし Console.ReadKey(); } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { var t = Array.ConvertAll(Console.ReadLine().Split(new[] { ' ' }), number => long.Parse(number)); var n = t[0] == 1 ? 1 : t[0] - 2; var m = t[1] == 1 ? 1 : t[1] - 2; Console.WriteLine(n * m); //デバッグ実行での確認用。そのまま提出しても問題なし Console.ReadKey(); } }
[["-", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199], ["+", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199]]
8
115
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp93 { class Program { static void Main(string[] args) { var st = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = st[0]; int M = st[1]; if (N >= 2 && M >= 2) { Console.WriteLine((N - 2) * (M - 2)); } else if (N == 1 && M == 1) { Console.WriteLine(1); } else { Console.WriteLine(Math.Max(N, M) - 2); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp93 { class Program { static void Main(string[] args) { var st = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = st[0]; int M = st[1]; if (N >= 2 && M >= 2) { Console.WriteLine((long)(N - 2) * (M - 2)); } else if (N == 1 && M == 1) { Console.WriteLine(1); } else { Console.WriteLine(Math.Max(N, M) - 2); } } } }
[["+", 3, 4, 0, 28, 0, 16, 31, 74, 39, 199], ["+", 3, 4, 0, 28, 0, 16, 31, 74, 0, 25], ["+", 0, 28, 0, 16, 31, 74, 51, 23, 0, 24]]
8
154
3
using System; using System.Collections.Generic; using System.IO; using System.Linq; class Program { #region library static int n = 0; static int m = 0; static int r = 0; static int c = 0; static int x = 0; static int y = 0; static string s = ""; static string[] ss; static long sum = 0; static long cnt = 0; static long max = -1; static long min = 2147483647; static bool flg = false; static bool flg2 = false; static string alpha = "abcdefghijklmnopqrstuvwxyz"; static int mod = 1000000007; static long[] arr; static char[,] map; static int[,] imap; public class Input { static readonly char[] separator = { ' ', '\r', '\n' }; readonly StreamReader sr; readonly Queue<string> queue; public Input(string path = "") { queue = new Queue<string>(); if (string.IsNullOrEmpty(path)) { sr = new StreamReader(Console.OpenStandardInput()); } else { sr = new StreamReader(path); } } public void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } public bool SetText(string s) { if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { queue.Enqueue(elem); } return true; } public bool Any() { return queue.Any() || Read(); } bool Read() { if (!SetText(sr.ReadLine())) return false; if (!queue.Any()) return Read(); return queue.Any(); } public string Next() { if (!queue.Any() && !Read()) { return ""; } return queue.Dequeue(); } bool Accumulate(int n) { while (queue.Count() < n) { if (!Read()) return false; } return true; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } T[] NextT<T>(int n, T offset, Func<string, T> parse, Func<T, T, T> add) { if (!Accumulate(n)) return null; var a = new T[n]; for (int i = 0; i < n; i++) a[i] = add(parse(queue.Dequeue()), offset); return a; } public string[] Next(int n) { return NextT(n, "", x => x, (x, y) => x); } public int[] NextInt(int n, int offset = 0) { return NextT(n, offset, int.Parse, (x, y) => x + y); } public long[] NextLong(int n, long offset = 0) { return NextT(n, offset, long.Parse, (x, y) => x + y); } public double[] NextDouble(int n, double offset = 0.0) { return NextT(n, offset, double.Parse, (x, y) => x + y); } } static Input input; static int Int() { return input.NextInt(); } static long Long() { return input.NextLong(); } static double Double() { return input.NextDouble(); } static string Text() { return input.Next(); } static void wl(object obj = null) { Console.WriteLine(obj); } static void w(object obj) { Console.Write(obj); } static void Yes() { wl("YES"); } static void No() { wl("NO"); } static void Sum() { wl(sum); } static void Cnt() { wl(cnt); } static void SetArray(long num = -1) { if (n == 0) { n = Int(); } arr = new long[n]; for (int i = 0; i < n; i++) { if (num == -1) arr[i] = Int(); else arr[i] = num; } } static void SetMap(char def = '@') { if (r == 0 && c == 0) { r = Int(); c = Int(); } map = new char[r, c]; for (int i = 0; i < r; i++) { if (def == '@') s = Text(); for (int j = 0; j < c; j++) { map[i, j] = (def == '@') ? s[j] : def; } } } static void SetIMap(int def = -1) { if (r == 0 && c == 0) { r = Int(); c = Int(); } imap = new int[r, c]; for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { imap[i, j] = (def == -1) ? Int() : def; } } } #endregion static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); input = new Input(); Solve(); Console.Out.Flush(); } public static void Solve() { int a = Int(); int b = Int(); if (a != 1) a -= 2; if (b != 1) b -= 2; wl(a * b); } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; class Program { #region library static int n = 0; static int m = 0; static int r = 0; static int c = 0; static int x = 0; static int y = 0; static string s = ""; static string[] ss; static long sum = 0; static long cnt = 0; static long max = -1; static long min = 2147483647; static bool flg = false; static bool flg2 = false; static string alpha = "abcdefghijklmnopqrstuvwxyz"; static int mod = 1000000007; static long[] arr; static char[,] map; static int[,] imap; public class Input { static readonly char[] separator = { ' ', '\r', '\n' }; readonly StreamReader sr; readonly Queue<string> queue; public Input(string path = "") { queue = new Queue<string>(); if (string.IsNullOrEmpty(path)) { sr = new StreamReader(Console.OpenStandardInput()); } else { sr = new StreamReader(path); } } public void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } public bool SetText(string s) { if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { queue.Enqueue(elem); } return true; } public bool Any() { return queue.Any() || Read(); } bool Read() { if (!SetText(sr.ReadLine())) return false; if (!queue.Any()) return Read(); return queue.Any(); } public string Next() { if (!queue.Any() && !Read()) { return ""; } return queue.Dequeue(); } bool Accumulate(int n) { while (queue.Count() < n) { if (!Read()) return false; } return true; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } T[] NextT<T>(int n, T offset, Func<string, T> parse, Func<T, T, T> add) { if (!Accumulate(n)) return null; var a = new T[n]; for (int i = 0; i < n; i++) a[i] = add(parse(queue.Dequeue()), offset); return a; } public string[] Next(int n) { return NextT(n, "", x => x, (x, y) => x); } public int[] NextInt(int n, int offset = 0) { return NextT(n, offset, int.Parse, (x, y) => x + y); } public long[] NextLong(int n, long offset = 0) { return NextT(n, offset, long.Parse, (x, y) => x + y); } public double[] NextDouble(int n, double offset = 0.0) { return NextT(n, offset, double.Parse, (x, y) => x + y); } } static Input input; static int Int() { return input.NextInt(); } static long Long() { return input.NextLong(); } static double Double() { return input.NextDouble(); } static string Text() { return input.Next(); } static void wl(object obj = null) { Console.WriteLine(obj); } static void w(object obj) { Console.Write(obj); } static void Yes() { wl("YES"); } static void No() { wl("NO"); } static void Sum() { wl(sum); } static void Cnt() { wl(cnt); } static void SetArray(long num = -1) { if (n == 0) { n = Int(); } arr = new long[n]; for (int i = 0; i < n; i++) { if (num == -1) arr[i] = Int(); else arr[i] = num; } } static void SetMap(char def = '@') { if (r == 0 && c == 0) { r = Int(); c = Int(); } map = new char[r, c]; for (int i = 0; i < r; i++) { if (def == '@') s = Text(); for (int j = 0; j < c; j++) { map[i, j] = (def == '@') ? s[j] : def; } } } static void SetIMap(int def = -1) { if (r == 0 && c == 0) { r = Int(); c = Int(); } imap = new int[r, c]; for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { imap[i, j] = (def == -1) ? Int() : def; } } } #endregion static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); input = new Input(); Solve(); Console.Out.Flush(); } public static void Solve() { long a = Int(); long b = Int(); if (a != 1) a -= 2; if (b != 1) b -= 2; wl(a * b); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
1,268
4
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Program { static void Main(string[] args) { //[summary]C - Flip,Flip, and Flip...... var line = ReadLine(); int N = line[0]; int M = line[1]; long ans; if (N == 2 | M == 2) { ans = 0; } else if (N == 1 | M == 1) { ans = Math.Max(N, M) - 2; // N,Mが両方とも"1"のケースを考慮 ans = Math.Max(ans, 1); } else { ans = (N - 2) * (M - 2); } Console.WriteLine(ans); } static List<int> ReadLine() { var line = Console.ReadLine(); var arr = line.Split(' '); return arr.Select(x => int.Parse(x)).ToList(); } } }
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Program { static void Main(string[] args) { //[summary]C - Flip,Flip, and Flip...... var line = ReadLine(); long N = line[0]; long M = line[1]; long ans; if (N == 2 | M == 2) { ans = 0; } else if (N == 1 | M == 1) { ans = Math.Max(N, M) - 2; // N,Mが両方とも"1"のケースを考慮 ans = Math.Max(ans, 1); } else { ans = (N - 2) * (M - 2); } Console.WriteLine(ans); } static List<int> ReadLine() { var line = Console.ReadLine(); var arr = line.Split(' '); return arr.Select(x => int.Parse(x)).ToList(); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
189
4
using System; class C { static void Main() { var h = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); Console.WriteLine(Math.Abs((h[0] - 2) * (h[1] - 2))); } }
using System; class C { static void Main() { var h = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); Console.WriteLine(Math.Abs((h[0] - 2) * (h[1] - 2))); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 205, 199]]
8
64
2
using System; using System.Text; using System.Collections.Generic; using System.Linq; using E = System.Linq.Enumerable; class Program { static void Main(string[] args) { //入力を受け取る var NM = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); var N = NM[0]; var M = NM[1]; if (N > 2 && M > 2) { Console.WriteLine((N - 2) * (M - 2)); } else if (N == 1 && M == 1) { Console.WriteLine(0); } else if (N == 1) { Console.WriteLine(M - 2); } else if (M == 1) { Console.WriteLine(N - 2); } else { Console.WriteLine(0); } } }
using System; using System.Text; using System.Collections.Generic; using System.Linq; using E = System.Linq.Enumerable; class Program { static void Main(string[] args) { //入力を受け取る var NM = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); var N = NM[0]; var M = NM[1]; if (N > 2 && M > 2) { Console.WriteLine((N - 2) * (M - 2)); } else if (N == 1 && M == 1) { Console.WriteLine(1); } else if (N == 1) { Console.WriteLine(M - 2); } else if (M == 1) { Console.WriteLine(N - 2); } else { Console.WriteLine(0); } } }
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203]]
8
188
2
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var N = sc.ReadInt(); var M = sc.ReadInt(); if (N > M) { var tmp = N; N = M; M = tmp; } if (N == 1 && M == 1) { Console.WriteLine(1); return; } else if (N == 1) { Console.WriteLine(M - 2); return; } else if (N == 2) { Console.WriteLine(0); return; } long c = (N - 2) * (M - 2); Console.WriteLine(c); } static int MOD = (int)1e9 + 7; static int INF = (int)1e7 + 1; static long LINF = (long)1e13 + 1; static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var N = sc.ReadLong(); var M = sc.ReadLong(); if (N > M) { var tmp = N; N = M; M = tmp; } if (N == 1 && M == 1) { Console.WriteLine(1); return; } else if (N == 1) { Console.WriteLine(M - 2); return; } else if (N == 2) { Console.WriteLine(0); return; } long c = (N - 2) * (M - 2); Console.WriteLine(c); } static int MOD = (int)1e9 + 7; static int INF = (int)1e7 + 1; static long LINF = (long)1e13 + 1; static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22]]
8
696
4
using System; public class Program { public void Solve() { var sc = new Scanner(); int n = sc.NextInt(); int m = sc.NextInt(); Console.WriteLine(n == 1 ? (m == 1 ? 1 : m - 2) : (m == 1 ? n - 2 : (n - 2) * (m - 2))); } public static void Main(string[] args) { new Program().Solve(); } } class Scanner { public Scanner() { _pos = 0; _line = new string[0]; } const char Separator = ' '; private int _pos; private string[] _line; #region スペース区切りで取得 public string Next() { if (_pos >= _line.Length) { _line = Console.ReadLine().Split(Separator); _pos = 0; } return _line[_pos++]; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } #endregion #region 型変換 private int[] ToIntArray(string[] array) { var result = new int[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = int.Parse(array[i]); } return result; } private long[] ToLongArray(string[] array) { var result = new long[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = long.Parse(array[i]); } return result; } private double[] ToDoubleArray(string[] array) { var result = new double[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = double.Parse(array[i]); } return result; } #endregion #region 配列取得 public string[] Array() { if (_pos >= _line.Length) _line = Console.ReadLine().Split(Separator); _pos = _line.Length; return _line; } public int[] IntArray() { return ToIntArray(Array()); } public long[] LongArray() { return ToLongArray(Array()); } public double[] DoubleArray() { return ToDoubleArray(Array()); } #endregion }
using System; public class Program { public void Solve() { var sc = new Scanner(); long n = sc.NextInt(); long m = sc.NextInt(); Console.WriteLine(n == 1 ? (m == 1 ? 1 : m - 2) : (m == 1 ? n - 2 : (n - 2) * (m - 2))); } public static void Main(string[] args) { new Program().Solve(); } } class Scanner { public Scanner() { _pos = 0; _line = new string[0]; } const char Separator = ' '; private int _pos; private string[] _line; #region スペース区切りで取得 public string Next() { if (_pos >= _line.Length) { _line = Console.ReadLine().Split(Separator); _pos = 0; } return _line[_pos++]; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } #endregion #region 型変換 private int[] ToIntArray(string[] array) { var result = new int[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = int.Parse(array[i]); } return result; } private long[] ToLongArray(string[] array) { var result = new long[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = long.Parse(array[i]); } return result; } private double[] ToDoubleArray(string[] array) { var result = new double[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = double.Parse(array[i]); } return result; } #endregion #region 配列取得 public string[] Array() { if (_pos >= _line.Length) _line = Console.ReadLine().Split(Separator); _pos = _line.Length; return _line; } public int[] IntArray() { return ToIntArray(Array()); } public long[] LongArray() { return ToLongArray(Array()); } public double[] DoubleArray() { return ToDoubleArray(Array()); } #endregion }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
522
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; namespace Contest { class Scanner { private string[] line = new string[0]; private int index = 0; public string Next() { if (line.Length <= index) { line = Console.ReadLine().Split(' '); index = 0; } var res = line[index]; index++; return res; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public string[] Array() { line = Console.ReadLine().Split(' '); index = line.Length; return line; } public int[] IntArray() { return Array().Select(int.Parse).ToArray(); } public long[] LongArray() { return Array().Select(long.Parse).ToArray(); } } class Program { private int N, M; private void Scan() { var sc = new Scanner(); N = sc.NextInt(); M = sc.NextInt(); } public void Solve() { Scan(); if (M < N) { var T = N; N = M; M = T; } if (N == 1) { if (M == 1) { Console.WriteLine(1); return; } else { Console.WriteLine(M - 2); return; } } else { Console.WriteLine((N - 2) * (M - 2)); } } static void Main(string[] args) { new Program().Solve(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; namespace Contest { class Scanner { private string[] line = new string[0]; private int index = 0; public string Next() { if (line.Length <= index) { line = Console.ReadLine().Split(' '); index = 0; } var res = line[index]; index++; return res; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public string[] Array() { line = Console.ReadLine().Split(' '); index = line.Length; return line; } public int[] IntArray() { return Array().Select(int.Parse).ToArray(); } public long[] LongArray() { return Array().Select(long.Parse).ToArray(); } } class Program { private long N, M; private void Scan() { var sc = new Scanner(); N = sc.NextInt(); M = sc.NextInt(); } public void Solve() { Scan(); if (M < N) { var T = N; N = M; M = T; } if (N == 1) { if (M == 1) { Console.WriteLine(1); return; } else { Console.WriteLine(M - 2); return; } } else { Console.WriteLine((N - 2) * (M - 2)); } } static void Main(string[] args) { new Program().Solve(); } } }
[["-", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["+", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199]]
8
377
2
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text.RegularExpressions; using System.Text; using System.Diagnostics; using static System.Math; using static System.Array; // var input = Console.ReadLine().Split().Select(int.Parse).ToArray(); namespace AtCoderSolve { class Solve { const int mod = 1000000007; const int INF = 2147483647; const long SINF = 9223372036854775807; static int N, M; public static void Input() { var cin = new Scanner(); var input = cin.SplitReader(); Sort(input); N = input[0]; M = input[1]; } static void Main(string[] args) { Input(); // var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = // false }; Console.SetOut(sw); long ans = 0; if (N == 1) { if (M == 1) { ans = 1; } else { ans = M - 2; } } else // N>=2 { ans = (N - 2) * (M - 2); } Console.WriteLine(ans); // Console.Out.Flush(); } } public class Scanner { public int[] SplitReader() { int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray(); return array; } public long[] SplitReaderL() { long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray(); return array; } } public class Graph {} }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text.RegularExpressions; using System.Text; using System.Diagnostics; using static System.Math; using static System.Array; // var input = Console.ReadLine().Split().Select(int.Parse).ToArray(); namespace AtCoderSolve { class Solve { const int mod = 1000000007; const int INF = 2147483647; const long SINF = 9223372036854775807; static long N, M; public static void Input() { var cin = new Scanner(); var input = cin.SplitReaderL(); Sort(input); N = input[0]; M = input[1]; } static void Main(string[] args) { Input(); // var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = // false }; Console.SetOut(sw); long ans = 0; if (N == 1) { if (M == 1) { ans = 1; } else { ans = M - 2; } } else // N>=2 { ans = (N - 2) * (M - 2); } Console.WriteLine(ans); // Console.Out.Flush(); } } public class Scanner { public int[] SplitReader() { int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray(); return array; } public long[] SplitReaderL() { long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray(); return array; } } public class Graph {} }
[["-", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["+", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22]]
8
289
4
using System; using System.Collections.Generic; using System.Text; namespace AtCoder { class QuestionC { public static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); long n = int.Parse(input[0]); long m = int.Parse(input[1]); double result = 0; if (n == 1 && m == 1) { result = 1; } else if (m == 1 || n == 1) { result = Math.Max(n, m) - 2; } else { result = (n - 2L) * (m - 2L); } Console.WriteLine(result); } } }
using System; using System.Collections.Generic; using System.Text; namespace AtCoder { class QuestionC { public static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); long n = int.Parse(input[0]); long m = int.Parse(input[1]); long result = 0; if (n == 1 && m == 1) { result = 1; } else if (m == 1 || n == 1) { result = Math.Max(n, m) - 2; } else { result = (n - 2L) * (m - 2L); } Console.WriteLine(result); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
150
2
using System; using System.Linq; using System.Collections.Generic; namespace Algorithm { class Program { static void Main(string[] args) { var l = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = l[0], M = l[1]; var ans = 0L; if (N == 1 && M == 1) ans = 1; else if (N == 1 && M > 1) ans = M - 2; else if (N > 1 && M == 1) ans = N - 2; else if (N >= 3 && M >= 3) ans = (M - 2) * (N - 2); Console.WriteLine(ans); } } }
using System; using System.Linq; using System.Collections.Generic; namespace Algorithm { class Program { static void Main(string[] args) { var l = Console.ReadLine().Split().Select(int.Parse).ToArray(); long N = l[0], M = l[1]; var ans = 0L; if (N == 1 && M == 1) ans = 1; else if (N == 1 && M > 1) ans = M - 2; else if (N > 1 && M == 1) ans = N - 2; else if (N >= 3 && M >= 3) ans = (M - 2) * (N - 2); Console.WriteLine(ans); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
158
2
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; namespace ABC090.C { using static Util; public class Solver : SolverBase { public void Run() { var ary = ReadLongArray(); var N = ary[0]; var M = ary[1]; var minS = Math.Min(N, M); var maxS = Math.Max(N, M); if (minS == 1) { if (maxS == 1) WriteLine(1); else WriteLine(maxS - 2); } else if (minS == 2) { WriteLine(maxS * 2 - 4); } else { WriteLine((maxS - 2) * (minS - 2)); } } #if !MYHOME public static void Main(string[] args) { new Solver().Run(); } #endif } public class XY : IComparable<XY>, IFormattable { public readonly int X; public readonly int Y; public XY() { } public XY(int x, int y) { X = x; Y = y; } public XY(int[] ary) { X = ary[0]; Y = ary[1]; } public int CompareTo(XY other) { var dx = this.X - other.X; if (0 < dx) return 1; else if (dx < 0) return -1; else { var dy = this.Y - other.Y; if (0 < dy) return 1; else if (dy < 0) return -1; else return 0; } } public override string ToString() { return ToString(null, null); } // format等の引数は一切無視 public string ToString(string format, IFormatProvider formatProvider) { return $"({X}, {Y})"; } } public static class Util { public static int Gcd(int a, int b) { if (a < b) // 引数を入替えて自分を呼び出す return Gcd(b, a); while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } public readonly static long MOD = 1000000007; public static string DumpToString<T>(IEnumerable<T> array) where T : IFormattable { var sb = new StringBuilder(); foreach (var item in array) { sb.Append(item); sb.Append(", "); } return sb.ToString(); } public static void InitArray<T>(T[] ary, T value) { for (int i = 0; i < ary.Length; i++) { ary[i] = value; } } public static void InitDP2<T>(T[,] dp, T value) { for (int i = 0; i < dp.GetLength(0); i++) { for (int j = 0; j < dp.GetLength(1); j++) { dp[i, j] = value; } } } public static void InitDP3<T>(T[,,] dp, T value) { for (int i = 0; i < dp.GetLength(0); i++) { for (int j = 0; j < dp.GetLength(1); j++) { for (int k = 0; k < dp.GetLength(2); k++) { dp[i, j, k] = value; } } } } public static T Max<T>(params T[] nums) where T : IComparable { if (nums.Length == 0) return default(T); T max = nums[0]; for (int i = 1; i < nums.Length; i++) { max = max.CompareTo(nums[i]) > 0 ? max : nums[i]; } return max; } public static T Min<T>(params T[] nums) where T : IComparable { if (nums.Length == 0) return default(T); T min = nums[0]; for (int i = 1; i < nums.Length; i++) { min = min.CompareTo(nums[i]) < 0 ? min : nums[i]; } return min; } /// <summary> /// ソート済み配列 ary に同じ値の要素が含まれている? /// ※ソート順は昇順/降順どちらでもよい /// </summary> public static bool HasDuplicateInSortedArray<T>(T[] ary) where T : IComparable, IComparable<T> { if (ary.Length <= 1) return false; var lastNum = ary[ary.Length - 1]; foreach (var n in ary) { if (lastNum.CompareTo(n) == 0) { return true; } else { lastNum = n; } } return false; } public static void ReplaceIfBigger<T>(ref T r, T v) where T : IComparable { if (r.CompareTo(v) < 0) r = v; } public static void ReplaceIfSmaller<T>(ref T r, T v) where T : IComparable { if (0 < r.CompareTo(v)) r = v; } /// <summary> /// 二分探索 /// ※条件を満たす最小のidxを返す /// ※満たすものがない場合は ary.Length を返す /// ※『aryの先頭側が条件を満たさない、末尾側が条件を満たす』という前提 /// ただし、IsOK(...)の戻り値を逆転させれば、逆でも同じことが可能。 /// </summary> /// <param name="ary">探索対象配列 ★ソート済みであること</param> /// <param name="key">探索値 ※これ以上の値を持つ(IsOKがtrueを返す)最小のindexを返す</param> public static int BinarySearch<T>(T[] ary, T key) where T : IComparable, IComparable<T> { int left = -1; int right = ary.Length; while (1 < right - left) { var mid = left + (right - left) / 2; if (IsOK(ary, mid, key)) { right = mid; } else { left = mid; } } // left は条件を満たさない最大の値、right は条件を満たす最小の値になっている return right; } public static bool IsOK<T>(T[] ary, int idx, T key) where T : IComparable, IComparable<T> { // key <= ary[idx] と同じ意味 return key.CompareTo(ary[idx]) <= 0; } } public class SolverBase { virtual protected string ReadLine() => Console.ReadLine(); virtual protected int ReadInt() => int.Parse(ReadLine()); //virtual protected void ReadInt2(out int x, out int y) { // var aryS = ReadLine().Split(' '); // x = int.Parse(aryS[0]); // y = int.Parse(aryS[1]); //} virtual protected long ReadLong() => long.Parse(ReadLine()); virtual protected string[] ReadStringArray() => ReadLine().Split(' '); virtual protected int[] ReadIntArray() => ReadLine().Split(' ').Select<string, int>(s => int.Parse(s)).ToArray(); virtual protected long[] ReadLongArray() => ReadLine().Split(' ').Select<string, long>(s => long.Parse(s)).ToArray(); virtual protected double[] ReadDoubleArray() => ReadLine().Split(' ').Select<string, double>(s => double.Parse(s)).ToArray(); virtual protected void WriteLine(string line) => Console.WriteLine(line); virtual protected void WriteLine(double d) => Console.WriteLine($"{d:F9}"); virtual protected void WriteLine<T>(T value) where T : IFormattable => Console.WriteLine(value); [Conditional("DEBUG")] protected void Dump(string s) => Console.WriteLine(s); [Conditional("DEBUG")] protected void Dump(char c) => Console.WriteLine(c); [Conditional("DEBUG")] protected void Dump(double d) => Console.WriteLine($"{d:F9}"); [Conditional("DEBUG")] protected void Dump<T>(IEnumerable<T> array) where T : IFormattable { string s = Util.DumpToString(array); // Consoleに出力すると、UnitTestの邪魔をしないというメリットあり。 Console.WriteLine(s); //_writer.WriteLine(s); } [Conditional("DEBUG")] protected void DumpGrid<T>(IEnumerable<IEnumerable<T>> arrayOfArray) where T : IFormattable { var sb = new StringBuilder(); foreach (var a in arrayOfArray) { sb.AppendLine(Util.DumpToString(a)); } // Consoleに出力すると、UnitTestの邪魔をしないというメリットあり。 Console.WriteLine(sb.ToString()); //_writer.WriteLine(sb.ToString()); } [Conditional("DEBUG")] protected void DumpDP<T>(T[,] dp) where T : IFormattable { var sb = new StringBuilder(); for (int i = 0; i < dp.GetLength(0); i++) { for (int j = 0; j < dp.GetLength(1); j++) { sb.Append(dp[i, j]); sb.Append(", "); } sb.AppendLine(); } Console.WriteLine(sb.ToString()); } } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; namespace ABC090.C { using static Util; public class Solver : SolverBase { public void Run() { var ary = ReadLongArray(); var N = ary[0]; var M = ary[1]; var minS = Math.Min(N, M); var maxS = Math.Max(N, M); if (minS == 1) { if (maxS == 1) WriteLine(1); else WriteLine(maxS - 2); } else if (minS == 2) { WriteLine(0); } else { WriteLine((maxS - 2) * (minS - 2)); } } #if !MYHOME public static void Main(string[] args) { new Solver().Run(); } #endif } public class XY : IComparable<XY>, IFormattable { public readonly int X; public readonly int Y; public XY() { } public XY(int x, int y) { X = x; Y = y; } public XY(int[] ary) { X = ary[0]; Y = ary[1]; } public int CompareTo(XY other) { var dx = this.X - other.X; if (0 < dx) return 1; else if (dx < 0) return -1; else { var dy = this.Y - other.Y; if (0 < dy) return 1; else if (dy < 0) return -1; else return 0; } } public override string ToString() { return ToString(null, null); } // format等の引数は一切無視 public string ToString(string format, IFormatProvider formatProvider) { return $"({X}, {Y})"; } } public static class Util { public static int Gcd(int a, int b) { if (a < b) // 引数を入替えて自分を呼び出す return Gcd(b, a); while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } public readonly static long MOD = 1000000007; public static string DumpToString<T>(IEnumerable<T> array) where T : IFormattable { var sb = new StringBuilder(); foreach (var item in array) { sb.Append(item); sb.Append(", "); } return sb.ToString(); } public static void InitArray<T>(T[] ary, T value) { for (int i = 0; i < ary.Length; i++) { ary[i] = value; } } public static void InitDP2<T>(T[,] dp, T value) { for (int i = 0; i < dp.GetLength(0); i++) { for (int j = 0; j < dp.GetLength(1); j++) { dp[i, j] = value; } } } public static void InitDP3<T>(T[,,] dp, T value) { for (int i = 0; i < dp.GetLength(0); i++) { for (int j = 0; j < dp.GetLength(1); j++) { for (int k = 0; k < dp.GetLength(2); k++) { dp[i, j, k] = value; } } } } public static T Max<T>(params T[] nums) where T : IComparable { if (nums.Length == 0) return default(T); T max = nums[0]; for (int i = 1; i < nums.Length; i++) { max = max.CompareTo(nums[i]) > 0 ? max : nums[i]; } return max; } public static T Min<T>(params T[] nums) where T : IComparable { if (nums.Length == 0) return default(T); T min = nums[0]; for (int i = 1; i < nums.Length; i++) { min = min.CompareTo(nums[i]) < 0 ? min : nums[i]; } return min; } /// <summary> /// ソート済み配列 ary に同じ値の要素が含まれている? /// ※ソート順は昇順/降順どちらでもよい /// </summary> public static bool HasDuplicateInSortedArray<T>(T[] ary) where T : IComparable, IComparable<T> { if (ary.Length <= 1) return false; var lastNum = ary[ary.Length - 1]; foreach (var n in ary) { if (lastNum.CompareTo(n) == 0) { return true; } else { lastNum = n; } } return false; } public static void ReplaceIfBigger<T>(ref T r, T v) where T : IComparable { if (r.CompareTo(v) < 0) r = v; } public static void ReplaceIfSmaller<T>(ref T r, T v) where T : IComparable { if (0 < r.CompareTo(v)) r = v; } /// <summary> /// 二分探索 /// ※条件を満たす最小のidxを返す /// ※満たすものがない場合は ary.Length を返す /// ※『aryの先頭側が条件を満たさない、末尾側が条件を満たす』という前提 /// ただし、IsOK(...)の戻り値を逆転させれば、逆でも同じことが可能。 /// </summary> /// <param name="ary">探索対象配列 ★ソート済みであること</param> /// <param name="key">探索値 ※これ以上の値を持つ(IsOKがtrueを返す)最小のindexを返す</param> public static int BinarySearch<T>(T[] ary, T key) where T : IComparable, IComparable<T> { int left = -1; int right = ary.Length; while (1 < right - left) { var mid = left + (right - left) / 2; if (IsOK(ary, mid, key)) { right = mid; } else { left = mid; } } // left は条件を満たさない最大の値、right は条件を満たす最小の値になっている return right; } public static bool IsOK<T>(T[] ary, int idx, T key) where T : IComparable, IComparable<T> { // key <= ary[idx] と同じ意味 return key.CompareTo(ary[idx]) <= 0; } } public class SolverBase { virtual protected string ReadLine() => Console.ReadLine(); virtual protected int ReadInt() => int.Parse(ReadLine()); //virtual protected void ReadInt2(out int x, out int y) { // var aryS = ReadLine().Split(' '); // x = int.Parse(aryS[0]); // y = int.Parse(aryS[1]); //} virtual protected long ReadLong() => long.Parse(ReadLine()); virtual protected string[] ReadStringArray() => ReadLine().Split(' '); virtual protected int[] ReadIntArray() => ReadLine().Split(' ').Select<string, int>(s => int.Parse(s)).ToArray(); virtual protected long[] ReadLongArray() => ReadLine().Split(' ').Select<string, long>(s => long.Parse(s)).ToArray(); virtual protected double[] ReadDoubleArray() => ReadLine().Split(' ').Select<string, double>(s => double.Parse(s)).ToArray(); virtual protected void WriteLine(string line) => Console.WriteLine(line); virtual protected void WriteLine(double d) => Console.WriteLine($"{d:F9}"); virtual protected void WriteLine<T>(T value) where T : IFormattable => Console.WriteLine(value); [Conditional("DEBUG")] protected void Dump(string s) => Console.WriteLine(s); [Conditional("DEBUG")] protected void Dump(char c) => Console.WriteLine(c); [Conditional("DEBUG")] protected void Dump(double d) => Console.WriteLine($"{d:F9}"); [Conditional("DEBUG")] protected void Dump<T>(IEnumerable<T> array) where T : IFormattable { string s = Util.DumpToString(array); // Consoleに出力すると、UnitTestの邪魔をしないというメリットあり。 Console.WriteLine(s); //_writer.WriteLine(s); } [Conditional("DEBUG")] protected void DumpGrid<T>(IEnumerable<IEnumerable<T>> arrayOfArray) where T : IFormattable { var sb = new StringBuilder(); foreach (var a in arrayOfArray) { sb.AppendLine(Util.DumpToString(a)); } // Consoleに出力すると、UnitTestの邪魔をしないというメリットあり。 Console.WriteLine(sb.ToString()); //_writer.WriteLine(sb.ToString()); } [Conditional("DEBUG")] protected void DumpDP<T>(T[,] dp) where T : IFormattable { var sb = new StringBuilder(); for (int i = 0; i < dp.GetLength(0); i++) { for (int j = 0; j < dp.GetLength(1); j++) { sb.Append(dp[i, j]); sb.Append(", "); } sb.AppendLine(); } Console.WriteLine(sb.ToString()); } } }
[["-", 3, 4, 0, 28, 0, 16, 31, 16, 31, 22], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 17, 48], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 12, 203], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203]]
8
1,749
6
using System; using System.Collections.Generic; using System.Linq; using static System.Math; using static AtCoderTemplate.MyExtensions; using static AtCoderTemplate.MyInputOutputs; using static AtCoderTemplate.MyNumericFunctions; namespace AtCoderTemplate { public class Program { public static void Main(string[] args) { var NM = ReadLongs(); var N = NM[0]; var M = NM[1]; if (N == 1 && M == 1) { Print(0); } else if (N > 1 && M > 1) { Print((N - 2) * (M - 2)); } else { Print(Max(N, M) - 2); } } } static class MyInputOutputs { /* Input & Output*/ public static int ReadInt() { return int.Parse(Console.ReadLine()); } public static long ReadLong() { return long.Parse(Console.ReadLine()); } public static List<int> ReadInts() { return Console.ReadLine().Split(' ').Select(c => int.Parse(c)).ToList(); } public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(c => long.Parse(c)).ToList(); } public static List<List<int>> ReadIntColumns(int n) { /* 入力例 A1 B1 A2 B2 ... An Bn 出力例 [[A1,A2,...,An], [B1,B2,...,Bn]] */ var rows = Enumerable.Range(0, n).Select(i => ReadInts()).ToList(); var m = rows.FirstOrDefault()?.Count() ?? 0; return Enumerable.Range(0, m) .Select(i => rows.Select(items => items[i]).ToList()) .ToList(); } public static List<List<long>> ReadLongColumns(int n) { /* 入力例 A1 B1 A2 B2 ... An Bn 出力例 [[A1,A2,...,An], [B1,B2,...,Bn]] */ var rows = Enumerable.Range(0, n).Select(i => ReadLongs()).ToList(); var m = rows.FirstOrDefault()?.Count() ?? 0; return Enumerable.Range(0, m) .Select(i => rows.Select(items => items[i]).ToList()) .ToList(); } public static void Print<T>(T item) { Console.WriteLine(item); } public static void PrintIf<T1, T2>(bool condition, T1 trueResult, T2 falseResult) { if (condition) { Console.WriteLine(trueResult); } else { Console.WriteLine(falseResult); } } public static void PrintRow<T>(IEnumerable<T> list) { /* 横ベクトルで表示 A B C D ... */ if (!list.IsEmpty()) { Console.Write(list.First()); foreach (var item in list.Skip(1)) { Console.Write($" {item}"); } } Console.Write("\n"); } public static void PrintColomn<T>(IEnumerable<T> list) { /* 縦ベクトルで表示 A B C D ... */ foreach (var item in list) { Console.WriteLine(item); } } public static void Print2DArray<T>(IEnumerable<IEnumerable<T>> sources) { foreach (var row in sources) { PrintRow(row); } } } static class MyNumericFunctions { public static bool isEven(int a) { return a % 2 == 0; } public static bool isEven(long a) { return a % 2 == 0; } public static bool isOdd(int a) { return !isEven(a); } public static bool isOdd(long a) { return !isEven(a); } public static long nPk(int n, int k) { if (k > n) { return 0; } else { return Enumerable.Range(n - k + 1, k) .Aggregate((long)1, ((i, m) => i * m)); } } public static long Fact(int n) { return nPk(n, n); } public static long nCk(int n, int k) { if (k > n) { return 0; } else { return nPk(n, k) / Fact(k); } } // 最大公約数 public static long GCD(long m, long n) { if (m < n) { return GCD(n, m); } else if (n == 0) { return m; } else { return GCD(n, m % n); } } // 最小公倍数 public static long LCM(long m, long n) { if (m < n) { return LCM(n, m); } else { return (m * n) / GCD(m, n); } } } static class MyExtensions { // AppendとPrependが、.NET Standard 1.6からの追加で、Mono 4.6.2 // はそれに対応して仕様はあるが、実装がない public static IEnumerable<T> Append<T>(this IEnumerable<T> source, T element) { return source.Concat(Enumerable.Repeat(element, 1)); } public static IEnumerable<T> Prepend<T>(this IEnumerable<T> source, T element) { return Enumerable.Repeat(element, 1).Concat(source); } // TakeLastとSkipLastが、.Net Standard 2.1からの追加で、Mono 4.6.2 // はそれに対応していない public static IEnumerable<T> TakeLast<T>(this IEnumerable<T> source, int count) { return source.Skip(source.Count() - count); } public static IEnumerable<T> SkipLast<T>(this IEnumerable<T> source, int count) { return source.Take(source.Count() - count); } public static bool IsEmpty<T>(this IEnumerable<T> source) { return !source.Any(); } /// <summary> /// インデックスiの位置の要素からk個取り除く /// O(N) /// </summary> public static IEnumerable<T> TakeAwayRange<T>(this IEnumerable<T> source, int i, int count) { return source.Take(i).Concat(source.Skip(i + count)); } /// <summary> /// インデックスiの位置の要素を取り除く /// O(N) /// </summary> public static IEnumerable<T> TakeAwayAt<T>(this IEnumerable<T> source, int i) { return source.TakeAwayRange(i, 1); } /// <summary> /// インデックスiの位置にシーケンスを挿入する /// O(N + K) /// </summary> public static IEnumerable<T> InsertEnumAt<T>(this IEnumerable<T> source, int i, IEnumerable<T> inserted) { return source.Take(i).Concat(inserted).Concat(source.Skip(i)); } /// <summary> /// 順列を得る /// O(N!) /// </summary> public static IEnumerable<IEnumerable<T>> Perm<T>(this IEnumerable<T> source, int n) { if (n == 0 || source.IsEmpty() || source.Count() < n) { return Enumerable.Empty<IEnumerable<T>>(); } else if (n == 1) { return source.Select(i => new List<T> { i }); } else { var nexts = source.Select( (x, i) => new { next = source.Take(i).Concat(source.Skip(i + 1)), selected = source.Take(i + 1).Last() }); return nexts.SelectMany( next => Perm(next.next, n - 1) .Select(item => item.Prepend(next.selected))); } } /// <summary> /// シーケンスの隣り合う要素を2引数の関数に適用したシーケンスを得る /// </summary> /// <para>O(N)</para> /// <param name="source">元のシーケンス</param> /// <param name="func">2引数関数</param> /// <example>[1,2,3,4].MapAdjacent(f) => [f(1,2), f(2,3), f(3,4)]</example> public static IEnumerable<TR> MapAdjacent<T1, TR>(this IEnumerable<T1> source, Func<T1, T1, TR> func) { var list = source.ToList(); return Enumerable.Range(1, list.Count - 1) .Select(i => func(list[i], list[i - 1])); } /// <summary> /// 累積項を要素にもつシーケンスを得る(初項は、first) /// <para>O(N)</para> /// </summary> /// <param name="source">元のシーケンス</param> /// <param name="func">2引数関数f</param> /// <param name="first">func(first, source[0])のための初項</param> /// <example> [1,2,3].Scanl1(f,0) => [0, f(0,1), f(f(0,1),2), /// f(f(f(0,1),2),3)]</example> public static IEnumerable<TR> Scanl<T, TR>(this IEnumerable<T> source, TR first, Func<TR, T, TR> func) { var list = source.ToList(); var result = new List<TR> { first }; foreach (var i in Enumerable.Range(0, source.Count())) { result.Add(func(result[i], list[i])); } return result; } /// <summary> /// 累積項を要素にもつシーケンスを得る(初項は、source.First()) /// <para>O(N)</para> /// </summary> /// <param name="source">元のシーケンス</param> /// <param name="func">2引数関数f</param> /// <example> [1,2,3].Scanl1(f) => [1, f(1,2), f(f(1,2),3)]</example> public static IEnumerable<T> Scanl1<T>(this IEnumerable<T> source, Func<T, T, T> func) { var list = source.ToList(); var result = new List<T> { list[0] }; foreach (var i in Enumerable.Range(1, source.Count() - 1)) { result.Add(func(result[i - 1], list[i])); } return result; } /// <summary> /// 昇順にソートしたインデックスを得る /// </summary> /// <para>O(N * log N)</para> public static IEnumerable<int> SortIndex<T>(this IEnumerable<T> source) { return source.Select((item, i) => new { Item = item, Index = i }) .OrderBy(x => x.Item) .Select(x => x.Index); } } }
using System; using System.Collections.Generic; using System.Linq; using static System.Math; using static AtCoderTemplate.MyExtensions; using static AtCoderTemplate.MyInputOutputs; using static AtCoderTemplate.MyNumericFunctions; namespace AtCoderTemplate { public class Program { public static void Main(string[] args) { var NM = ReadLongs(); var N = NM[0]; var M = NM[1]; if (N == 1 && M == 1) { Print(1); } else if (N > 1 && M > 1) { Print((N - 2) * (M - 2)); } else { Print(Max(N, M) - 2); } } } static class MyInputOutputs { /* Input & Output*/ public static int ReadInt() { return int.Parse(Console.ReadLine()); } public static long ReadLong() { return long.Parse(Console.ReadLine()); } public static List<int> ReadInts() { return Console.ReadLine().Split(' ').Select(c => int.Parse(c)).ToList(); } public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(c => long.Parse(c)).ToList(); } public static List<List<int>> ReadIntColumns(int n) { /* 入力例 A1 B1 A2 B2 ... An Bn 出力例 [[A1,A2,...,An], [B1,B2,...,Bn]] */ var rows = Enumerable.Range(0, n).Select(i => ReadInts()).ToList(); var m = rows.FirstOrDefault()?.Count() ?? 0; return Enumerable.Range(0, m) .Select(i => rows.Select(items => items[i]).ToList()) .ToList(); } public static List<List<long>> ReadLongColumns(int n) { /* 入力例 A1 B1 A2 B2 ... An Bn 出力例 [[A1,A2,...,An], [B1,B2,...,Bn]] */ var rows = Enumerable.Range(0, n).Select(i => ReadLongs()).ToList(); var m = rows.FirstOrDefault()?.Count() ?? 0; return Enumerable.Range(0, m) .Select(i => rows.Select(items => items[i]).ToList()) .ToList(); } public static void Print<T>(T item) { Console.WriteLine(item); } public static void PrintIf<T1, T2>(bool condition, T1 trueResult, T2 falseResult) { if (condition) { Console.WriteLine(trueResult); } else { Console.WriteLine(falseResult); } } public static void PrintRow<T>(IEnumerable<T> list) { /* 横ベクトルで表示 A B C D ... */ if (!list.IsEmpty()) { Console.Write(list.First()); foreach (var item in list.Skip(1)) { Console.Write($" {item}"); } } Console.Write("\n"); } public static void PrintColomn<T>(IEnumerable<T> list) { /* 縦ベクトルで表示 A B C D ... */ foreach (var item in list) { Console.WriteLine(item); } } public static void Print2DArray<T>(IEnumerable<IEnumerable<T>> sources) { foreach (var row in sources) { PrintRow(row); } } } static class MyNumericFunctions { public static bool isEven(int a) { return a % 2 == 0; } public static bool isEven(long a) { return a % 2 == 0; } public static bool isOdd(int a) { return !isEven(a); } public static bool isOdd(long a) { return !isEven(a); } public static long nPk(int n, int k) { if (k > n) { return 0; } else { return Enumerable.Range(n - k + 1, k) .Aggregate((long)1, ((i, m) => i * m)); } } public static long Fact(int n) { return nPk(n, n); } public static long nCk(int n, int k) { if (k > n) { return 0; } else { return nPk(n, k) / Fact(k); } } // 最大公約数 public static long GCD(long m, long n) { if (m < n) { return GCD(n, m); } else if (n == 0) { return m; } else { return GCD(n, m % n); } } // 最小公倍数 public static long LCM(long m, long n) { if (m < n) { return LCM(n, m); } else { return (m * n) / GCD(m, n); } } } static class MyExtensions { // AppendとPrependが、.NET Standard 1.6からの追加で、Mono 4.6.2 // はそれに対応して仕様はあるが、実装がない public static IEnumerable<T> Append<T>(this IEnumerable<T> source, T element) { return source.Concat(Enumerable.Repeat(element, 1)); } public static IEnumerable<T> Prepend<T>(this IEnumerable<T> source, T element) { return Enumerable.Repeat(element, 1).Concat(source); } // TakeLastとSkipLastが、.Net Standard 2.1からの追加で、Mono 4.6.2 // はそれに対応していない public static IEnumerable<T> TakeLast<T>(this IEnumerable<T> source, int count) { return source.Skip(source.Count() - count); } public static IEnumerable<T> SkipLast<T>(this IEnumerable<T> source, int count) { return source.Take(source.Count() - count); } public static bool IsEmpty<T>(this IEnumerable<T> source) { return !source.Any(); } /// <summary> /// インデックスiの位置の要素からk個取り除く /// O(N) /// </summary> public static IEnumerable<T> TakeAwayRange<T>(this IEnumerable<T> source, int i, int count) { return source.Take(i).Concat(source.Skip(i + count)); } /// <summary> /// インデックスiの位置の要素を取り除く /// O(N) /// </summary> public static IEnumerable<T> TakeAwayAt<T>(this IEnumerable<T> source, int i) { return source.TakeAwayRange(i, 1); } /// <summary> /// インデックスiの位置にシーケンスを挿入する /// O(N + K) /// </summary> public static IEnumerable<T> InsertEnumAt<T>(this IEnumerable<T> source, int i, IEnumerable<T> inserted) { return source.Take(i).Concat(inserted).Concat(source.Skip(i)); } /// <summary> /// 順列を得る /// O(N!) /// </summary> public static IEnumerable<IEnumerable<T>> Perm<T>(this IEnumerable<T> source, int n) { if (n == 0 || source.IsEmpty() || source.Count() < n) { return Enumerable.Empty<IEnumerable<T>>(); } else if (n == 1) { return source.Select(i => new List<T> { i }); } else { var nexts = source.Select( (x, i) => new { next = source.Take(i).Concat(source.Skip(i + 1)), selected = source.Take(i + 1).Last() }); return nexts.SelectMany( next => Perm(next.next, n - 1) .Select(item => item.Prepend(next.selected))); } } /// <summary> /// シーケンスの隣り合う要素を2引数の関数に適用したシーケンスを得る /// </summary> /// <para>O(N)</para> /// <param name="source">元のシーケンス</param> /// <param name="func">2引数関数</param> /// <example>[1,2,3,4].MapAdjacent(f) => [f(1,2), f(2,3), f(3,4)]</example> public static IEnumerable<TR> MapAdjacent<T1, TR>(this IEnumerable<T1> source, Func<T1, T1, TR> func) { var list = source.ToList(); return Enumerable.Range(1, list.Count - 1) .Select(i => func(list[i], list[i - 1])); } /// <summary> /// 累積項を要素にもつシーケンスを得る(初項は、first) /// <para>O(N)</para> /// </summary> /// <param name="source">元のシーケンス</param> /// <param name="func">2引数関数f</param> /// <param name="first">func(first, source[0])のための初項</param> /// <example> [1,2,3].Scanl1(f,0) => [0, f(0,1), f(f(0,1),2), /// f(f(f(0,1),2),3)]</example> public static IEnumerable<TR> Scanl<T, TR>(this IEnumerable<T> source, TR first, Func<TR, T, TR> func) { var list = source.ToList(); var result = new List<TR> { first }; foreach (var i in Enumerable.Range(0, source.Count())) { result.Add(func(result[i], list[i])); } return result; } /// <summary> /// 累積項を要素にもつシーケンスを得る(初項は、source.First()) /// <para>O(N)</para> /// </summary> /// <param name="source">元のシーケンス</param> /// <param name="func">2引数関数f</param> /// <example> [1,2,3].Scanl1(f) => [1, f(1,2), f(f(1,2),3)]</example> public static IEnumerable<T> Scanl1<T>(this IEnumerable<T> source, Func<T, T, T> func) { var list = source.ToList(); var result = new List<T> { list[0] }; foreach (var i in Enumerable.Range(1, source.Count() - 1)) { result.Add(func(result[i - 1], list[i])); } return result; } /// <summary> /// 昇順にソートしたインデックスを得る /// </summary> /// <para>O(N * log N)</para> public static IEnumerable<int> SortIndex<T>(this IEnumerable<T> source) { return source.Select((item, i) => new { Item = item, Index = i }) .OrderBy(x => x.Item) .Select(x => x.Index); } } }
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203]]
8
1,821
2
using System; class Program { static void Main(string[] args) { var nm = Console.ReadLine().Split(' '); var n = int.Parse(nm[0]); var m = int.Parse(nm[1]); if (1 < n) n -= 2; if (1 < m) m -= 2; Console.WriteLine(n * m); } }
using System; class Program { static void Main(string[] args) { var nm = Console.ReadLine().Split(' '); var n = long.Parse(nm[0]); var m = long.Parse(nm[1]); if (1 < n) n -= 2; if (1 < m) m -= 2; Console.WriteLine(n * m); } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
8
89
4
using System; using System.Collections.Generic; using System.Linq; namespace CSharpSample01 { class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); long N = long.Parse(str[0]); long M = long.Parse(str[1]); if (N == 1 && M == 1) Console.WriteLine(1); if (N == 1) Console.WriteLine(M - 2); else if (M == 1) Console.WriteLine(N - 2); else Console.WriteLine((N - 2) * (M - 2)); } } }
using System; using System.Collections.Generic; using System.Linq; namespace CSharpSample01 { class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); long N = long.Parse(str[0]); long M = long.Parse(str[1]); if (N == 1 && M == 1) Console.WriteLine(1); else if (N == 1) Console.WriteLine(M - 2); else if (M == 1) Console.WriteLine(N - 2); else Console.WriteLine((N - 2) * (M - 2)); } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95]]
8
144
1
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC_C { class C090 { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); int N = int.Parse(s[0]), M = int.Parse(s[1]); long c = 0; if (N == 1) { if (M == 1) c = 1; else c = M - 2; } else if (M == 1) { c = N - 2; } else { c = (N - 2) * (M - 2); } Console.WriteLine(c); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC_C { class C090 { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); int N = int.Parse(s[0]), M = int.Parse(s[1]); long c = 0; if (N == 1) { if (M == 1) c = 1; else c = M - 2; } else if (M == 1) { c = N - 2; } else { c = (long)(N - 2) * (M - 2); } Console.WriteLine(c); } } }
[["+", 0, 1, 0, 11, 12, 16, 31, 74, 39, 199], ["+", 0, 1, 0, 11, 12, 16, 31, 74, 0, 25], ["+", 0, 11, 12, 16, 31, 74, 51, 23, 0, 24]]
8
158
3
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp3 { class Program { static void Main(string[] args) { int[] n = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = n[0]; int M = n[1]; long ans; if (N == 1 && M == 1) ans = 1; else if ((N == 1 && M != 1 && M != 2) || (M == 1 && N != 1 && N != 2)) ans = Math.Max(N - 2, M - 2); else if (N == 2 || M == 2) ans = 0; else ans = (N - 2) * (M - 2); Console.WriteLine(ans); Console.ReadLine(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp3 { class Program { static void Main(string[] args) { long[] n = Console.ReadLine().Split().Select(long.Parse).ToArray(); long N = n[0]; long M = n[1]; long ans = 0; if (N == 1 && M == 1) ans = 1; else if ((N == 1 && M != 1 && M != 2) || (M == 1 && N != 1 && N != 2)) ans = Math.Max(N - 2, M - 2); else if (N == 2 || M == 2) ans = 0; else ans = (N - 2) * (M - 2); Console.WriteLine(ans); Console.ReadLine(); } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
8
194
10
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main() { int[] nm = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int row = nm[0] >= 2 ? (nm[0] - 2) : 1; int column = nm[1] >= 2 ? (nm[1] - 2) : 1; Console.WriteLine(row * column); } }
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main() { long[] nm = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); long row = nm[0] >= 2 ? (nm[0] - 2) : 1; long column = nm[1] >= 2 ? (nm[1] - 2) : 1; Console.WriteLine(row * column); } }
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
106
8
using System; using System.Collections.Generic; using System.Linq; public class Hello { public static void Main() { var a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int N = a[0]; int M = a[1]; if (N == 1 && M == 1) { Console.WriteLine(1); } else if (N == 1 || M == 1) { Console.WriteLine(M * N - 2); } else { Console.WriteLine((N - 2) * (M - 2)); } } }
using System; using System.Collections.Generic; using System.Linq; public class Hello { public static void Main() { var a = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); var N = a[0]; var M = a[1]; if (N == 1 && M == 1) { Console.WriteLine(1); } else if (N == 1 || M == 1) { Console.WriteLine(M * N - 2); } else { Console.WriteLine((N - 2) * (M - 2)); } } }
[["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217]]
8
134
6
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoderBS { class Program { static void Main(string[] args) { // input int[] nm = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int n = nm[0]; int m = nm[1]; // Solve,Output if (n == 1 && m == 1) { Console.Write(1); } else if (n == 1 || m == 1) { Console.Write(n * m - 2); } else { Console.Write((n - 2) * (m - 2)); } Console.Read(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoderBS { class Program { static void Main(string[] args) { // input long[] nm = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); long n = nm[0]; long m = nm[1]; // Solve,Output if (n == 1 && m == 1) { Console.Write(1); } else if (n == 1 || m == 1) { Console.Write(n * m - 2); } else { Console.Write((n - 2) * (m - 2)); } Console.Read(); } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
162
8
using System; using System.Collections; using System.Collections.Generic; using System.Text; using System.IO; using System.Linq; using System.Diagnostics; using System.Globalization; using static System.Console; using static System.Math; namespace abc91_c { class Program { static void Main(string[] args) { int[] input = ReadLine().Split().Select(int.Parse).ToArray(); int x = input[0]; int y = input[1]; if (x >= 2 && y >= 2) { WriteLine((x - 2) * (y - 2)); } else if (x == 1 && y != 1) { WriteLine(y - 2); } else if (x != 1 && y == 1) { WriteLine(x - 2); } else if (x == 1 && y == 1) { WriteLine(1); } } } }
using System; using System.Collections; using System.Collections.Generic; using System.Text; using System.IO; using System.Linq; using System.Diagnostics; using System.Globalization; using static System.Console; using static System.Math; namespace abc91_c { class Program { static void Main(string[] args) { long[] input = ReadLine().Split().Select(long.Parse).ToArray(); long x = input[0]; long y = input[1]; if (x >= 2 && y >= 2) { WriteLine((x - 2) * (y - 2)); } else if (x == 1 && y != 1) { WriteLine(y - 2); } else if (x != 1 && y == 1) { WriteLine(x - 2); } else if (x == 1 && y == 1) { WriteLine(1); } } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
196
8
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace AtCoder { class Program { static void Main(string[] args) { var nm = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); if (nm.All(i => i == 1)) Console.WriteLine(0); else if (nm.Any(i => i == 1)) Console.WriteLine(nm.Max() - 2); else Console.WriteLine(nm[0] * nm[1] - 2 * (nm.Sum()) + 4); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace AtCoder { class Program { static void Main(string[] args) { var nm = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); if (nm.All(i => i == 1)) Console.WriteLine(1); else if (nm.Any(i => i == 1)) Console.WriteLine(nm.Max() - 2); else Console.WriteLine(nm[0] * nm[1] - 2 * (nm.Sum()) + 4); } } }
[["-", 64, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 1, 0, 213, 3, 4, 0, 28, 0, 203]]
8
136
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace abc090c { class Program { static void Main(string[] args) { var mn = Console.ReadLine().Split(); var n = int.Parse(mn[0]); var m = int.Parse(mn[1]); var ans = 0; if (n == 1 && m == 1) ans = 1; else if (n == 1) ans = m - 2; else if (m == 1) ans = n - 2; else ans = (m - 2) * (n - 2); Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace abc090c { class Program { static void Main(string[] args) { var mn = Console.ReadLine().Split(); var n = long.Parse(mn[0]); var m = long.Parse(mn[1]); var ans = 0L; checked { if (n == 1 && m == 1) ans = 1; else if (n == 1) ans = m - 2; else if (m == 1) ans = n - 2; else ans = (m - 2) * (n - 2); } Console.WriteLine(ans); } } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 287, 0, 292], ["+", 0, 195, 8, 196, 0, 287, 0, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 287, 0, 196, 0, 46]]
8
152
9
using System; public class Hello { public static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var n = int.Parse(line[0]); var m = int.Parse(line[1]); long a; if (n == 1 && m == 1) a = 1; else if (n == 1 && m != 1) a = m - 2; else if (n != 1 && m == 1) a = n - 2; else a = (n - 2) * (m - 2); Console.WriteLine(a); } }
using System; public class Hello { public static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var n = long.Parse(line[0]); var m = long.Parse(line[1]); long a; if (n == 1 && m == 1) a = 1; else if (n == 1 && m != 1) a = m - 2; else if (n != 1 && m == 1) a = n - 2; else a = (n - 2) * (m - 2); Console.WriteLine(a); } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
8
137
4
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Program { public static void Main() { new Program().Solve(); } void Solve() { var tmp = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); int n = tmp[0]; int m = tmp[1]; long ans = 0; if (n == 1 && m == 1) { ans = 1; } else if (n == 1) { ans = m - 2; } else if (m == 1) { ans = n - 2; } else // m>=2,n>=2 { ans = (n - 2) * (m - 2); } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Program { public static void Main() { new Program().Solve(); } void Solve() { var tmp = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); long n = tmp[0]; long m = tmp[1]; long ans = 0; if (n == 1 && m == 1) { ans = 1; } else if (n == 1) { ans = m - 2; } else if (m == 1) { ans = n - 2; } else // m>=2,n>=2 { ans = (n - 2) * (m - 2); } Console.WriteLine(ans); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
167
4
using System; using System.IO; using System.Linq; using System.Collections.Generic; class Program { static int[] dx = new int[] { 0, 0, 1, -1 }; static int[] dy = new int[] { 1, -1, 0, 0 }; static void Solve() { var n = sc.Int(); var m = sc.Int(); if (n > 2 && m > 2) { pr.WriteLine((n - 2) * (m - 2)); } else if (n == 1 && m == 1) { pr.WriteLine(1); } else if (n == 2 || m == 2) { pr.WriteLine(0); } else { pr.WriteLine(Math.Max(n, m) - 2); } } static int[,] Mul(int[,] a, int[,] b) { var ret = new int[a.GetLength(0), b.GetLength(1)]; for (int i = 0; i < a.GetLength(0); i++) for (int j = 0; j < b.GetLength(1); j++) for (int k = 0; k < a.GetLength(1); k++) ret[i, j] += a[i, k] * b[k, j]; return ret; } static int[,] Pow(int[,] a, int n) { var b = new int[a.GetLength(1), a.GetLength(0)]; var f = n % 2 == 1; for (int i = 0; i < a.GetLength(0); i++) b[i, i] = 1; while (n > 0) { if (n % 2 == 1) b = Mul(a, b); n >>= 1; } return b; } class Coord { public int x; public int y; } static void Main(string[] args) { // pr.AutoFlush = true; Solve(); pr.Flush(); // Console.ReadKey(); } static Scanner sc = new Scanner(); static Printer pr = new Printer(); } #region IO class Scanner { private int _i = 0; private string[] line = new string[0]; private T[] Enumerate<T>(int n, Func<T> f) { T[] ret = new T[n]; for (int i = 0; i < n; i++) ret[i] = f(); return ret; } public string Str() { if (line.Length <= _i) { line = Console.ReadLine().Split(' '); _i = 0; } return line[_i++]; } public int Int() => int.Parse(Str()); public long Long() => long.Parse(Str()); public double Double() => double.Parse(Str()); public int[] Int(int n) => Enumerate(n, Int); public long[] Long(int n) => Enumerate(n, Long); public double[] Double(int n) => Enumerate(n, Double); public string[] Str(int n) => Enumerate(n, Str); } class Printer : StreamWriter { public Printer() : base(Console.OpenStandardOutput()) { AutoFlush = false; } } #endregion
using System; using System.IO; using System.Linq; using System.Collections.Generic; class Program { static int[] dx = new int[] { 0, 0, 1, -1 }; static int[] dy = new int[] { 1, -1, 0, 0 }; static void Solve() { var n = sc.Long(); var m = sc.Long(); if (n > 2 && m > 2) { pr.WriteLine((n - 2) * (m - 2)); } else if (n == 1 && m == 1) { pr.WriteLine(1); } else if (n == 2 || m == 2) { pr.WriteLine(0); } else { pr.WriteLine(Math.Max(n, m) - 2); } } static int[,] Mul(int[,] a, int[,] b) { var ret = new int[a.GetLength(0), b.GetLength(1)]; for (int i = 0; i < a.GetLength(0); i++) for (int j = 0; j < b.GetLength(1); j++) for (int k = 0; k < a.GetLength(1); k++) ret[i, j] += a[i, k] * b[k, j]; return ret; } static int[,] Pow(int[,] a, int n) { var b = new int[a.GetLength(1), a.GetLength(0)]; var f = n % 2 == 1; for (int i = 0; i < a.GetLength(0); i++) b[i, i] = 1; while (n > 0) { if (n % 2 == 1) b = Mul(a, b); n >>= 1; } return b; } class Coord { public int x; public int y; } static void Main(string[] args) { // pr.AutoFlush = true; Solve(); pr.Flush(); // Console.ReadKey(); } static Scanner sc = new Scanner(); static Printer pr = new Printer(); } #region IO class Scanner { private int _i = 0; private string[] line = new string[0]; private T[] Enumerate<T>(int n, Func<T> f) { T[] ret = new T[n]; for (int i = 0; i < n; i++) ret[i] = f(); return ret; } public string Str() { if (line.Length <= _i) { line = Console.ReadLine().Split(' '); _i = 0; } return line[_i++]; } public int Int() => int.Parse(Str()); public long Long() => long.Parse(Str()); public double Double() => double.Parse(Str()); public int[] Int(int n) => Enumerate(n, Int); public long[] Long(int n) => Enumerate(n, Long); public double[] Double(int n) => Enumerate(n, Double); public string[] Str(int n) => Enumerate(n, Str); } class Printer : StreamWriter { public Printer() : base(Console.OpenStandardOutput()) { AutoFlush = false; } } #endregion
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22]]
8
728
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC90_3 { class Program { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); int N = int.Parse(s[0]); int M = int.Parse(s[1]); if (N == 1 && M == 1) { Console.WriteLine(1); } else if (N == 1 && M > 2) { Console.WriteLine(M - 2); } else if (N > 2 && M == 1) { Console.WriteLine(N - 2); } else if (N == 2 || M == 2) { Console.WriteLine(0); } else { Console.WriteLine(N * M - 2 * (N + M - 2)); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC90_3 { class Program { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); long N = long.Parse(s[0]); long M = long.Parse(s[1]); if (N == 1 && M == 1) { Console.WriteLine(1); } else if (N == 1 && M > 2) { Console.WriteLine(M - 2); } else if (N > 2 && M == 1) { Console.WriteLine(N - 2); } else if (N == 2 || M == 2) { Console.WriteLine(0); } else { Console.WriteLine(N * M - 2 * (N + M - 2)); } } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
8
195
8
using System; using System.Linq; using System.Collections; class Program { public static void Main() { string[] imp = Console.ReadLine().Split(' '); int n, m; n = int.Parse(imp[0]); m = int.Parse(imp[1]); if (n == 1 && m == 1) Console.WriteLine(1); else if (n == 1) Console.WriteLine(m - 2); else if (m == 1) Console.WriteLine(n - 2); else Console.WriteLine((n - 2) * (m - 2)); } }
using System; using System.Linq; using System.Collections; class Program { public static void Main() { string[] imp = Console.ReadLine().Split(' '); int n, m; n = int.Parse(imp[0]); m = int.Parse(imp[1]); if (n == 1 && m == 1) Console.WriteLine(1); else if (n == 1) Console.WriteLine(m - 2); else if (m == 1) Console.WriteLine(n - 2); else Console.WriteLine((long)(n - 2) * (m - 2)); } }
[["+", 3, 4, 0, 28, 0, 16, 31, 74, 39, 199], ["+", 3, 4, 0, 28, 0, 16, 31, 74, 0, 25], ["+", 0, 28, 0, 16, 31, 74, 51, 23, 0, 24]]
8
139
3
using System; namespace abc089_c { class Program { static void Main(string[] args) { var n = int.Parse(System.Console.ReadLine()); var march = new int[5]; for (var i = 0; i < n; i++) { var s = System.Console.ReadLine(); if (s[0] == 'M') { march[0]++; } else if (s[0] == 'A') { march[1]++; } else if (s[0] == 'R') { march[2]++; } else if (s[0] == 'C') { march[3]++; } else if (s[0] == 'H') { march[4]++; } } long ans = 0; for (var i = 0; i < 3; i++) { for (var j = i + 1; j < 4; j++) { for (var h = j + 1; h < 5; h++) { ans += march[i] * march[j] * march[h]; } } } Console.WriteLine(ans); } } }
using System; namespace abc089_c { class Program { static void Main(string[] args) { var n = int.Parse(System.Console.ReadLine()); var march = new int[5]; for (var i = 0; i < n; i++) { var s = System.Console.ReadLine(); if (s[0] == 'M') { march[0]++; } else if (s[0] == 'A') { march[1]++; } else if (s[0] == 'R') { march[2]++; } else if (s[0] == 'C') { march[3]++; } else if (s[0] == 'H') { march[4]++; } } long ans = 0; for (var i = 0; i < 3; i++) { for (var j = i + 1; j < 4; j++) { for (var h = j + 1; h < 5; h++) { ans += (long)march[i] * march[j] * march[h]; } } } Console.WriteLine(ans); } } }
[["+", 0, 11, 12, 16, 31, 16, 31, 74, 0, 24], ["+", 0, 11, 12, 16, 31, 16, 31, 74, 39, 199], ["+", 0, 11, 12, 16, 31, 16, 31, 74, 0, 25]]
8
254
3
using System; using System.Text; using System.Collections.Generic; using System.Linq; using E = System.Linq.Enumerable; class Program { static int[] A; static void Main(string[] args) { //入力を受け取る var N = int.Parse(Console.ReadLine()); var march = new int[5]; for (int i = 0; i < N; i++) { var str = Console.ReadLine(); var sento = str[0]; if (sento == 'M') { march[0]++; } else if (sento == 'A') { march[1]++; } else if (sento == 'R') { march[2]++; } else if (sento == 'C') { march[3]++; } else if (sento == 'H') { march[4]++; } } var ans = 0; for (int i = 0; i < 3; i++) { for (int j = i + 1; j < 4; j++) { for (int k = j + 1; k < 5; k++) { // Console.WriteLine("i:"+i+"j:"+j+"k:"+k); ans += march[i] * march[j] * march[k]; } } } Console.WriteLine(ans); } }
using System; using System.Text; using System.Collections.Generic; using System.Linq; using E = System.Linq.Enumerable; class Program { static int[] A; static void Main(string[] args) { //入力を受け取る var N = long.Parse(Console.ReadLine()); var march = new long[5]; for (int i = 0; i < N; i++) { var str = Console.ReadLine(); var sento = str[0]; if (sento == 'M') { march[0]++; } else if (sento == 'A') { march[1]++; } else if (sento == 'R') { march[2]++; } else if (sento == 'C') { march[3]++; } else if (sento == 'H') { march[4]++; } } long ans = 0; for (int i = 0; i < 3; i++) { for (int j = i + 1; j < 4; j++) { for (int k = j + 1; k < 5; k++) { // Console.WriteLine("i:"+i+"j:"+j+"k:"+k); ans += march[i] * march[j] * march[k]; } } } Console.WriteLine(ans); } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
273
6
using System; using System.Linq; using System.Collections.Generic; using System.Text; using static System.Console; using static System.Math; class Program { static void Main(string[] args) { int N = int.Parse(ReadLine()); int[] names = new int[5]; char[] MARCH = new char[5] { 'M', 'A', 'R', 'C', 'H' }; for (int i = 0; i < N; i++) { string s = ReadLine(); for (int j = 0; j < 5; j++) { if (s[0] == MARCH[j]) names[j]++; } } long ans = 0; for (int i = 0; i < 3; i++) { for (int j = i + 1; j < 4; j++) { for (int k = j + 1; k < 5; k++) { ans += names[i] * names[j] * names[k]; } } } WriteLine(ans); } }
using System; using System.Linq; using System.Collections.Generic; using System.Text; using static System.Console; using static System.Math; class Program { static void Main(string[] args) { int N = int.Parse(ReadLine()); int[] names = new int[5]; char[] MARCH = new char[5] { 'M', 'A', 'R', 'C', 'H' }; for (int i = 0; i < N; i++) { string s = ReadLine(); for (int j = 0; j < 5; j++) { if (s[0] == MARCH[j]) names[j]++; } } long ans = 0; for (int i = 0; i < 3; i++) { for (int j = i + 1; j < 4; j++) { for (int k = j + 1; k < 5; k++) { ans += (long)names[i] * names[j] * names[k]; } } } WriteLine(ans); } }
[["+", 0, 11, 12, 16, 31, 16, 31, 74, 0, 24], ["+", 0, 11, 12, 16, 31, 16, 31, 74, 39, 199], ["+", 0, 11, 12, 16, 31, 16, 31, 74, 0, 25]]
8
238
3
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC089C { class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var count = new Dictionary<char, int>(); count.Add('M', 0); count.Add('A', 0); count.Add('R', 0); count.Add('C', 0); count.Add('H', 0); foreach (var i in Enumerable.Range(0, n)) { var currentName = Console.ReadLine(); var initialChar = currentName.First(); if (initialChar == 'M' || initialChar == 'A' || initialChar == 'R' || initialChar == 'C' || initialChar == 'H') { count[initialChar]++; } } var pattern = new List<string>(); pattern.Add("MAR"); pattern.Add("MAC"); pattern.Add("MAH"); pattern.Add("MRC"); pattern.Add("MRH"); pattern.Add("MCH"); pattern.Add("ARC"); pattern.Add("ARH"); pattern.Add("ACH"); pattern.Add("RCH"); var result = 0L; foreach (var currentPattern in pattern) { result += count[currentPattern[0]] * count[currentPattern[1]] * count[currentPattern[2]]; } Console.WriteLine(result); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC089C { class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var count = new Dictionary<char, long>(); count.Add('M', 0); count.Add('A', 0); count.Add('R', 0); count.Add('C', 0); count.Add('H', 0); foreach (var i in Enumerable.Range(0, n)) { var currentName = Console.ReadLine(); var initialChar = currentName.First(); if (initialChar == 'M' || initialChar == 'A' || initialChar == 'R' || initialChar == 'C' || initialChar == 'H') { count[initialChar]++; } } var pattern = new List<string>(); pattern.Add("MAR"); pattern.Add("MAC"); pattern.Add("MAH"); pattern.Add("MRC"); pattern.Add("MRH"); pattern.Add("MCH"); pattern.Add("ARC"); pattern.Add("ARH"); pattern.Add("ACH"); pattern.Add("RCH"); var result = 0L; foreach (var currentPattern in pattern) { result += count[currentPattern[0]] * count[currentPattern[1]] * count[currentPattern[2]]; } Console.WriteLine(result); } } }
[["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199]]
8
350
2
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; namespace ABC089C { class Program { static void Solve(Input input) { var keys = "MARCH"; var n = input.NextInt(); var map = keys.ToDictionary(x => x, _ => 0); for (int i = 0; i < n; i++) { var s = input.Next(); if (map.ContainsKey(s[0])) { map[s[0]]++; } } var p = (long)map.Count(x => x.Value > 0); // pC3 * map[i].Value(>0) long pat = 0; if (p >= 3) { for (int i = 0; i < 5; i++) { for (int j = i + 1; j < 5; j++) { for (int k = j + 1; k < 5; k++) { pat += map[keys[i]] * map[keys[j]] * map[keys[k]]; } } } } Console.WriteLine(pat); } #region Competitive Template static readonly int MOD = (int)1e9 + 7; public static void Main(string[] args) { // 出力が少ないときはこれをセットする方が時間かかるけれど // その場合は出力がボトルネックになっていないので、まあ良しとする var needsFlushOutput = true; if (needsFlushOutput) { // 細かく出力しないようにする var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } // 通常は引数無しで、ファイルから読み出したい場合はpath指定する var input = new Input(); // 仮想的に標準入力をセットする // input.SetText(""); Solve(input); Console.Out.Flush(); } class Input { // 変な改行コードがたまに混じっているので、一応セパレート指定する // スペース単独指定の方がもちろん早い static readonly char[] separator = { ' ', '\r', '\n' }; Queue<string> q { get; set; } StreamReader sr; /// <summary> /// 特定のファイルから読み出したい場合はpath指定する /// </summary> /// <param name="path"></param> public Input(string path = "") { q = new Queue<string>(); if (string.IsNullOrEmpty(path)) { sr = new StreamReader(Console.OpenStandardInput()); } else { sr = new StreamReader(path); } } /// <summary> /// 入力予約 /// </summary> /// <param name="items"></param> public void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } /// <summary> /// 入力予約 /// </summary> /// <param name="s"></param> /// <returns></returns> public bool SetText(string s) { if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } return true; } /// <summary> /// 内部queueに入力からの値をsplitして格納する /// </summary> /// <returns></returns> bool read() { var s = sr.ReadLine(); if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } if (!q.Any()) return read(); return true; } /// <summary> /// 次のstringを一つ読み込む /// </summary> /// <returns></returns> public string Next() { if (!q.Any()) { if (!read()) { return ""; } } return q.Dequeue(); } /// <summary> /// 指定個数queueにたまるまでenqueueし続ける /// </summary> /// <param name="n"></param> /// <returns></returns> bool accumulate(int n) { while (q.Count() < n) { if (!read()) return false; } return true; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); /// <summary> /// n個の要素をparseして、それぞれにoffsetをaddした配列を返す /// </summary> /// <typeparam name="T"></typeparam> /// <param name="n"></param> /// <param name="offset"></param> /// <param name="parse"></param> /// <param name="add"></param> /// <returns></returns> T[] NextT<T>(int n, T offset, Func<string, T> parse, Func<T, T, T> add) { if (!accumulate(n)) return null; var a = new T[n]; for (int i = 0; i < n; i++) a[i] = add(parse(q.Dequeue()), offset); return a; } public string[] Next(int n) => NextT(n, "", x => x, (x, y) => x); public int[] NextInt(int n, int offset = 0) => NextT(n, offset, int.Parse, (x, y) => x + y); public long[] NextLong(int n, long offset = 0) => NextT(n, offset, long.Parse, (x, y) => x + y); public double[] NextDouble(int n, double offset = 0.0) => NextT(n, offset, double.Parse, (x, y) => x + y); } static class Utils { public static void Print<T>(IEnumerable<T> ie, string sep = " ") => Console.WriteLine(string.Join(sep, ie)); public static void Print<T>(params T[] objs) => Print(objs); public static T Max<T>(params T[] objs) => objs.Max(); public static T Min<T>(params T[] objs) => objs.Min(); public static void Swap<T>(ref T x, ref T y) where T : struct { var t = x; x = y; y = t; } public static void Swap<T>(IList<T> list, int i, int j) where T : struct { var t = list[i]; list[i] = list[j]; list[j] = t; } /// <summary> /// vでfillされたT[d1][d2]配列を作成する /// </summary> /// <typeparam name="T"></typeparam> /// <param name="d1"></param> /// <param name="d2"></param> /// <param name="v"></param> /// <returns></returns> public static T[][] Create2DArray<T>(int d1, int d2, T v = default(T)) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(v, d2).ToArray()) .ToArray(); } /// <summary> /// vでfillされたT[d1][d2][d3]配列を作成する /// </summary> /// <typeparam name="T"></typeparam> /// <param name="d1"></param> /// <param name="d2"></param> /// <param name="d3"></param> /// <param name="v"></param> /// <returns></returns> public static T[][][] Create3DArray<T>(int d1, int d2, int d3, T v = default(T)) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(0, d2) .Select(__ => Enumerable.Repeat(v, d3).ToArray()) .ToArray()) .ToArray(); } } #endregion } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; namespace ABC089C { class Program { static void Solve(Input input) { var keys = "MARCH"; var n = input.NextInt(); var map = keys.ToDictionary(x => x, _ => 0L); for (int i = 0; i < n; i++) { var s = input.Next(); if (map.ContainsKey(s[0])) { map[s[0]]++; } } var p = (long)map.Count(x => x.Value > 0); // pC3 * map[i].Value(>0) long pat = 0; if (p >= 3) { for (int i = 0; i < 5; i++) { for (int j = i + 1; j < 5; j++) { for (int k = j + 1; k < 5; k++) { pat += map[keys[i]] * map[keys[j]] * map[keys[k]]; } } } } Console.WriteLine(pat); } #region Competitive Template static readonly int MOD = (int)1e9 + 7; public static void Main(string[] args) { // 出力が少ないときはこれをセットする方が時間かかるけれど // その場合は出力がボトルネックになっていないので、まあ良しとする var needsFlushOutput = true; if (needsFlushOutput) { // 細かく出力しないようにする var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } // 通常は引数無しで、ファイルから読み出したい場合はpath指定する var input = new Input(); // 仮想的に標準入力をセットする // input.SetText(""); Solve(input); Console.Out.Flush(); } class Input { // 変な改行コードがたまに混じっているので、一応セパレート指定する // スペース単独指定の方がもちろん早い static readonly char[] separator = { ' ', '\r', '\n' }; Queue<string> q { get; set; } StreamReader sr; /// <summary> /// 特定のファイルから読み出したい場合はpath指定する /// </summary> /// <param name="path"></param> public Input(string path = "") { q = new Queue<string>(); if (string.IsNullOrEmpty(path)) { sr = new StreamReader(Console.OpenStandardInput()); } else { sr = new StreamReader(path); } } /// <summary> /// 入力予約 /// </summary> /// <param name="items"></param> public void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } /// <summary> /// 入力予約 /// </summary> /// <param name="s"></param> /// <returns></returns> public bool SetText(string s) { if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } return true; } /// <summary> /// 内部queueに入力からの値をsplitして格納する /// </summary> /// <returns></returns> bool read() { var s = sr.ReadLine(); if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } if (!q.Any()) return read(); return true; } /// <summary> /// 次のstringを一つ読み込む /// </summary> /// <returns></returns> public string Next() { if (!q.Any()) { if (!read()) { return ""; } } return q.Dequeue(); } /// <summary> /// 指定個数queueにたまるまでenqueueし続ける /// </summary> /// <param name="n"></param> /// <returns></returns> bool accumulate(int n) { while (q.Count() < n) { if (!read()) return false; } return true; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); /// <summary> /// n個の要素をparseして、それぞれにoffsetをaddした配列を返す /// </summary> /// <typeparam name="T"></typeparam> /// <param name="n"></param> /// <param name="offset"></param> /// <param name="parse"></param> /// <param name="add"></param> /// <returns></returns> T[] NextT<T>(int n, T offset, Func<string, T> parse, Func<T, T, T> add) { if (!accumulate(n)) return null; var a = new T[n]; for (int i = 0; i < n; i++) a[i] = add(parse(q.Dequeue()), offset); return a; } public string[] Next(int n) => NextT(n, "", x => x, (x, y) => x); public int[] NextInt(int n, int offset = 0) => NextT(n, offset, int.Parse, (x, y) => x + y); public long[] NextLong(int n, long offset = 0) => NextT(n, offset, long.Parse, (x, y) => x + y); public double[] NextDouble(int n, double offset = 0.0) => NextT(n, offset, double.Parse, (x, y) => x + y); } static class Utils { public static void Print<T>(IEnumerable<T> ie, string sep = " ") => Console.WriteLine(string.Join(sep, ie)); public static void Print<T>(params T[] objs) => Print(objs); public static T Max<T>(params T[] objs) => objs.Max(); public static T Min<T>(params T[] objs) => objs.Min(); public static void Swap<T>(ref T x, ref T y) where T : struct { var t = x; x = y; y = t; } public static void Swap<T>(IList<T> list, int i, int j) where T : struct { var t = list[i]; list[i] = list[j]; list[j] = t; } /// <summary> /// vでfillされたT[d1][d2]配列を作成する /// </summary> /// <typeparam name="T"></typeparam> /// <param name="d1"></param> /// <param name="d2"></param> /// <param name="v"></param> /// <returns></returns> public static T[][] Create2DArray<T>(int d1, int d2, T v = default(T)) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(v, d2).ToArray()) .ToArray(); } /// <summary> /// vでfillされたT[d1][d2][d3]配列を作成する /// </summary> /// <typeparam name="T"></typeparam> /// <param name="d1"></param> /// <param name="d2"></param> /// <param name="d3"></param> /// <param name="v"></param> /// <returns></returns> public static T[][][] Create3DArray<T>(int d1, int d2, int d3, T v = default(T)) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(0, d2) .Select(__ => Enumerable.Repeat(v, d3).ToArray()) .ToArray()) .ToArray(); } } #endregion } }
[["-", 0, 213, 3, 4, 0, 28, 0, 218, 8, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 218, 8, 203]]
8
1,312
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; public static class Program { public static void Main(params string[] args) { var ary = "MARCH".ToArray(); var hash = new HashSet<Char>(ary); var n = int.Parse(Console.ReadLine()); var d = Enumerable.Range(0, n) .Select(x => Console.ReadLine()) .Where(x => hash.Contains(x[0])) .GroupBy(x => x[0]) .ToDictionary(x => x.Key, x => x.Count()); long r = 0; for (int i = 0; i < ary.Length; i++) { for (int j = i + 1; j < ary.Length; j++) { for (int k = j + 1; k < ary.Length; k++) { int v1, v2, v3; if (d.TryGetValue(ary[i], out v1) && d.TryGetValue(ary[j], out v2) && d.TryGetValue(ary[k], out v3)) { r += v1 * v2 * v3; } } } } Console.WriteLine(r); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; public static class Program { public static void Main(params string[] args) { var ary = "MARCH".ToArray(); var hash = new HashSet<Char>(ary); var n = int.Parse(Console.ReadLine()); var d = Enumerable.Range(0, n) .Select(x => Console.ReadLine()) .Where(x => hash.Contains(x[0])) .GroupBy(x => x[0]) .ToDictionary(x => x.Key, x => (long)x.Count()); long r = 0; for (int i = 0; i < ary.Length; i++) { for (int j = i + 1; j < ary.Length; j++) { for (int k = j + 1; k < ary.Length; k++) { long v1, v2, v3; if (d.TryGetValue(ary[i], out v1) && d.TryGetValue(ary[j], out v2) && d.TryGetValue(ary[k], out v3)) { r += v1 * v2 * v3; } } } } Console.WriteLine(r); } }
[["+", 3, 4, 0, 28, 0, 218, 8, 74, 0, 24], ["+", 3, 4, 0, 28, 0, 218, 8, 74, 39, 199], ["+", 3, 4, 0, 28, 0, 218, 8, 74, 0, 25], ["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199]]
8
276
5
using System; using System.Linq; namespace ABC089_C { class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var s = new string[n].Select(x => Console.ReadLine()).Distinct().ToArray(); var m = 0; var a = 0; var r = 0; var c = 0; var h = 0; foreach (var ch in s) { if (ch[0] == 'M') m++; else if (ch[0] == 'A') a++; else if (ch[0] == 'R') r++; else if (ch[0] == 'C') c++; else if (ch[0] == 'H') h++; } long ans = 0; var d = new int[10] { 0, 0, 0, 0, 0, 0, 1, 1, 1, 2 }; var e = new int[10] { 1, 1, 1, 2, 2, 3, 2, 2, 3, 3 }; var f = new int[10] { 2, 3, 4, 3, 4, 4, 3, 4, 4, 4 }; var num = new int[5] { m, a, r, c, h }; for (var i = 0; i < 10; i++) { ans += num[d[i]] * num[e[i]] * num[f[i]]; } Console.WriteLine(ans); } } }
using System; using System.Linq; namespace ABC089_C { class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var s = new string[n].Select(x => Console.ReadLine()).Distinct().ToArray(); var m = 0; var a = 0; var r = 0; var c = 0; var h = 0; foreach (var ch in s) { if (ch[0] == 'M') m++; else if (ch[0] == 'A') a++; else if (ch[0] == 'R') r++; else if (ch[0] == 'C') c++; else if (ch[0] == 'H') h++; } long ans = 0; var d = new int[10] { 0, 0, 0, 0, 0, 0, 1, 1, 1, 2 }; var e = new int[10] { 1, 1, 1, 2, 2, 3, 2, 2, 3, 3 }; var f = new int[10] { 2, 3, 4, 3, 4, 4, 3, 4, 4, 4 }; var num = new long[5] { m, a, r, c, h }; for (var i = 0; i < 10; i++) { ans += num[d[i]] * num[e[i]] * num[f[i]]; } Console.WriteLine(ans); } } }
[["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199]]
8
341
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace AtC { class Program { static void Main(string[] args) { var N = ReadInt(); uint[] namesCount = { 0, 0, 0, 0, 0 }; List<char> head = new List<char> { 'M', 'A', 'R', 'C', 'H' }; for (int i = 0; i < N; i++) { var str = ReadString(); var index = head.IndexOf(str[0]); if (index >= 0) namesCount[index]++; } ulong count = 0; for (int i = 0; i < 5; i++) for (int j = i + 1; j < 5; j++) for (int k = j + 1; k < 5; k++) count += namesCount[i] * namesCount[j] * namesCount[k]; Out(count); } //最小公倍数 static int LCM(int num1, int num2) { var gcd = GCD(num1, num2); return num1 * (num2 / gcd); } static long LCM(long num1, long num2) { var gcd = GCD(num1, num2); return num1 * (num2 / gcd); } //最大公約数 static int GCD(int num1, int num2) { int a = Math.Max(num1, num2); int b = Math.Min(num1, num2); int mod; while ((mod = a % b) != 0) { a = b; b = mod; } return b; } static long GCD(long num1, long num2) { long a = Math.Max(num1, num2); long b = Math.Min(num1, num2); long mod; while ((mod = a % b) != 0) { a = b; b = mod; } return b; } static int[] ReadIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } static int ReadInt() { return int.Parse(Console.ReadLine()); } static long[] ReadLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } static long ReadLong() { return long.Parse(Console.ReadLine()); } static string ReadString() { return Console.ReadLine(); } static void Out(object o) { Console.WriteLine(o); } } static class EnumerableExtension { public delegate void Function<in T>(T val); public static void ForEach<T>(this IEnumerable<T> enumerable, Function<T> function) { foreach (var x in enumerable) { function(x); } } } class PriorityQueue<T> {} }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace AtC { class Program { static void Main(string[] args) { var N = ReadInt(); ulong[] namesCount = { 0, 0, 0, 0, 0 }; List<char> head = new List<char> { 'M', 'A', 'R', 'C', 'H' }; for (int i = 0; i < N; i++) { var str = ReadString(); var index = head.IndexOf(str[0]); if (index >= 0) namesCount[index]++; } ulong count = 0; for (int i = 0; i < 5; i++) for (int j = i + 1; j < 5; j++) for (int k = j + 1; k < 5; k++) count += namesCount[i] * namesCount[j] * namesCount[k]; Out(count); } //最小公倍数 static int LCM(int num1, int num2) { var gcd = GCD(num1, num2); return num1 * (num2 / gcd); } static long LCM(long num1, long num2) { var gcd = GCD(num1, num2); return num1 * (num2 / gcd); } //最大公約数 static int GCD(int num1, int num2) { int a = Math.Max(num1, num2); int b = Math.Min(num1, num2); int mod; while ((mod = a % b) != 0) { a = b; b = mod; } return b; } static long GCD(long num1, long num2) { long a = Math.Max(num1, num2); long b = Math.Min(num1, num2); long mod; while ((mod = a % b) != 0) { a = b; b = mod; } return b; } static int[] ReadIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } static int ReadInt() { return int.Parse(Console.ReadLine()); } static long[] ReadLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } static long ReadLong() { return long.Parse(Console.ReadLine()); } static string ReadString() { return Console.ReadLine(); } static void Out(object o) { Console.WriteLine(o); } } static class EnumerableExtension { public delegate void Function<in T>(T val); public static void ForEach<T>(this IEnumerable<T> enumerable, Function<T> function) { foreach (var x in enumerable) { function(x); } } } class PriorityQueue<T> {} }
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199]]
8
607
2
using System; using System.Collections.Generic; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); var G = (from _ in Enumerable.Repeat(0, n) let s = Console.ReadLine() where s.StartsWith("M") || s.StartsWith("A") || s.StartsWith("R") || s.StartsWith("C") || s.StartsWith("H") group s by s[0] into g select g.Count()).ToArray(); long ans = 0; for (int i = 0; i < G.Length; i++) { for (int j = i + 1; j < G.Length; j++) { for (int k = j + 1; k < G.Length; k++) { ans += G[i] * G[j] * G[k]; } } } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); var G = (from _ in Enumerable.Repeat(0, n) let s = Console.ReadLine() where s.StartsWith("M") || s.StartsWith("A") || s.StartsWith("R") || s.StartsWith("C") || s.StartsWith("H") group s by s[0] into g select g.Count()).ToArray(); long ans = 0; for (int i = 0; i < G.Length; i++) { for (int j = i + 1; j < G.Length; j++) { for (int k = j + 1; k < G.Length; k++) { ans += (long)G[i] * G[j] * G[k]; } } } Console.WriteLine(ans); } } }
[["+", 0, 11, 12, 16, 31, 16, 31, 74, 0, 24], ["+", 0, 11, 12, 16, 31, 16, 31, 74, 39, 199], ["+", 0, 11, 12, 16, 31, 16, 31, 74, 0, 25]]
8
224
3
using System; using System.Collections.Generic; using System.Linq; using static System.Math; using static AtCoderTemplate.MyExtensions; using static AtCoderTemplate.MyInputOutputs; using static AtCoderTemplate.MyNumericFunctions; namespace AtCoderTemplate { public class Program { public static void Main(string[] args) { var N = ReadInt(); var S = new List<string>(); foreach (var i in Enumerable.Range(0, N)) { S.Add(Console.ReadLine()); } var M = S.Where(Si => Si[0] == 'M').Count(); var A = S.Where(Si => Si[0] == 'A').Count(); var R = S.Where(Si => Si[0] == 'R').Count(); var C = S.Where(Si => Si[0] == 'C').Count(); var H = S.Where(Si => Si[0] == 'H').Count(); var not0 = new List<int> { M, A, R, C, H }.Where(i => i != 0).ToList(); if (not0.Count < 3) { Print(0); } else { var lastIx = not0.Count - 1; var ans = Enumerable.Range(0, lastIx - 2 + 1) .SelectMany( a => Enumerable.Range(a + 1, lastIx - 1 - (a + 1) + 1) .SelectMany( b => Enumerable.Range(b + 1, lastIx - (b + 1) + 1) .Select(c => { // Print ($"{a}, {b}, {c}"); return not0[a] * not0[b] * not0[c]; }))) .Sum(); Print(ans); } } } static class MyInputOutputs { /* Input & Output*/ public static int ReadInt() { return int.Parse(Console.ReadLine()); } public static long ReadLong() { return long.Parse(Console.ReadLine()); } public static List<int> ReadInts() { return Console.ReadLine().Split(' ').Select(c => int.Parse(c)).ToList(); } public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(c => long.Parse(c)).ToList(); } public static List<List<int>> ReadIntColumns(int n) { /* 入力例 A1 B1 A2 B2 ... An Bn 出力例 [[A1,A2,...,An], [B1,B2,...,Bn]] */ var rows = Enumerable.Range(0, n).Select(i => ReadInts()).ToList(); var m = rows.FirstOrDefault()?.Count() ?? 0; return Enumerable.Range(0, m) .Select(i => rows.Select(items => items[i]).ToList()) .ToList(); } public static List<List<long>> ReadLongColumns(int n) { /* 入力例 A1 B1 A2 B2 ... An Bn 出力例 [[A1,A2,...,An], [B1,B2,...,Bn]] */ var rows = Enumerable.Range(0, n).Select(i => ReadLongs()).ToList(); var m = rows.FirstOrDefault()?.Count() ?? 0; return Enumerable.Range(0, m) .Select(i => rows.Select(items => items[i]).ToList()) .ToList(); } public static void Print<T>(T item) { Console.WriteLine(item); } public static void PrintIf<T1, T2>(bool condition, T1 trueResult, T2 falseResult) { if (condition) { Console.WriteLine(trueResult); } else { Console.WriteLine(falseResult); } } public static void PrintRow<T>(IEnumerable<T> list) { /* 横ベクトルで表示 A B C D ... */ if (!list.IsEmpty()) { Console.Write(list.First()); foreach (var item in list.Skip(1)) { Console.Write($" {item}"); } } Console.Write("\n"); } public static void PrintColomn<T>(IEnumerable<T> list) { /* 縦ベクトルで表示 A B C D ... */ foreach (var item in list) { Console.WriteLine(item); } } public static void Print2DArray<T>(IEnumerable<IEnumerable<T>> sources) { foreach (var row in sources) { PrintRow(row); } } } static class MyNumericFunctions { public static bool isEven(int a) { return a % 2 == 0; } public static bool isEven(long a) { return a % 2 == 0; } public static bool isOdd(int a) { return !isEven(a); } public static bool isOdd(long a) { return !isEven(a); } public static long nPk(int n, int k) { if (k > n) { return 0; } else { return Enumerable.Range(n - k + 1, k) .Aggregate((long)1, ((i, m) => i * m)); } } public static long Fact(int n) { return nPk(n, n); } public static long nCk(int n, int k) { if (k > n) { return 0; } else { return nPk(n, k) / Fact(k); } } // 最大公約数 public static long GCD(long m, long n) { if (m < n) { return GCD(n, m); } else if (n == 0) { return m; } else { return GCD(n, m % n); } } // 最小公倍数 public static long LCM(long m, long n) { if (m < n) { return LCM(n, m); } else { return (m * n) / GCD(m, n); } } } static class MyExtensions { // AppendとPrependが、.NET Standard 1.6からの追加で、Mono 4.6.2 // はそれに対応して仕様はあるが、実装がない public static IEnumerable<T> Append<T>(this IEnumerable<T> source, T element) { return source.Concat(Enumerable.Repeat(element, 1)); } public static IEnumerable<T> Prepend<T>(this IEnumerable<T> source, T element) { return Enumerable.Repeat(element, 1).Concat(source); } // TakeLastとSkipLastが、.Net Standard 2.1からの追加で、Mono 4.6.2 // はそれに対応していない public static IEnumerable<T> TakeLast<T>(this IEnumerable<T> source, int count) { return source.Skip(source.Count() - count); } public static IEnumerable<T> SkipLast<T>(this IEnumerable<T> source, int count) { return source.Take(source.Count() - count); } public static bool IsEmpty<T>(this IEnumerable<T> source) { return !source.Any(); } /// <summary> /// インデックスiの位置の要素からk個取り除く /// O(N) /// </summary> public static IEnumerable<T> TakeAwayRange<T>(this IEnumerable<T> source, int i, int count) { return source.Take(i).Concat(source.Skip(i + count)); } /// <summary> /// インデックスiの位置の要素を取り除く /// O(N) /// </summary> public static IEnumerable<T> TakeAwayAt<T>(this IEnumerable<T> source, int i) { return source.TakeAwayRange(i, 1); } /// <summary> /// インデックスiの位置にシーケンスを挿入する /// O(N + K) /// </summary> public static IEnumerable<T> InsertEnumAt<T>(this IEnumerable<T> source, int i, IEnumerable<T> inserted) { return source.Take(i).Concat(inserted).Concat(source.Skip(i)); } /// <summary> /// 順列を得る /// O(N!) /// </summary> public static IEnumerable<IEnumerable<T>> Perm<T>(this IEnumerable<T> source, int n) { if (n == 0 || source.IsEmpty() || source.Count() < n) { return Enumerable.Empty<IEnumerable<T>>(); } else if (n == 1) { return source.Select(i => new List<T> { i }); } else { var nexts = source.Select( (x, i) => new { next = source.Take(i).Concat(source.Skip(i + 1)), selected = source.Take(i + 1).Last() }); return nexts.SelectMany( next => Perm(next.next, n - 1) .Select(item => item.Prepend(next.selected))); } } /// <summary> /// シーケンスの隣り合う要素を2引数の関数に適用したシーケンスを得る /// </summary> /// <para>O(N)</para> /// <param name="source">元のシーケンス</param> /// <param name="func">2引数関数</param> /// <example>[1,2,3,4].MapAdjacent(f) => [f(1,2), f(2,3), f(3,4)]</example> public static IEnumerable<TR> MapAdjacent<T1, TR>(this IEnumerable<T1> source, Func<T1, T1, TR> func) { var list = source.ToList(); return Enumerable.Range(1, list.Count - 1) .Select(i => func(list[i], list[i - 1])); } /// <summary> /// 累積項を要素にもつシーケンスを得る(初項は、first) /// <para>O(N)</para> /// </summary> /// <param name="source">元のシーケンス</param> /// <param name="func">2引数関数f</param> /// <param name="first">func(first, source[0])のための初項</param> /// <example> [1,2,3].Scanl1(f,0) => [0, f(0,1), f(f(0,1),2), /// f(f(f(0,1),2),3)]</example> public static IEnumerable<TR> Scanl<T, TR>(this IEnumerable<T> source, TR first, Func<TR, T, TR> func) { var list = source.ToList(); var result = new List<TR> { first }; foreach (var i in Enumerable.Range(0, source.Count())) { result.Add(func(result[i], list[i])); } return result; } /// <summary> /// 累積項を要素にもつシーケンスを得る(初項は、source.First()) /// <para>O(N)</para> /// </summary> /// <param name="source">元のシーケンス</param> /// <param name="func">2引数関数f</param> /// <example> [1,2,3].Scanl1(f) => [1, f(1,2), f(f(1,2),3)]</example> public static IEnumerable<T> Scanl1<T>(this IEnumerable<T> source, Func<T, T, T> func) { var list = source.ToList(); var result = new List<T> { list[0] }; foreach (var i in Enumerable.Range(1, source.Count() - 1)) { result.Add(func(result[i - 1], list[i])); } return result; } /// <summary> /// 昇順にソートしたインデックスを得る /// </summary> /// <para>O(N * log N)</para> public static IEnumerable<int> SortIndex<T>(this IEnumerable<T> source) { return source.Select((item, i) => new { Item = item, Index = i }) .OrderBy(x => x.Item) .Select(x => x.Index); } } }
using System; using System.Collections.Generic; using System.Linq; using static System.Math; using static AtCoderTemplate.MyExtensions; using static AtCoderTemplate.MyInputOutputs; using static AtCoderTemplate.MyNumericFunctions; namespace AtCoderTemplate { public class Program { public static void Main(string[] args) { var N = ReadInt(); var S = new List<string>(); foreach (var i in Enumerable.Range(0, N)) { S.Add(Console.ReadLine()); } var M = S.Where(Si => Si[0] == 'M').Count(); var A = S.Where(Si => Si[0] == 'A').Count(); var R = S.Where(Si => Si[0] == 'R').Count(); var C = S.Where(Si => Si[0] == 'C').Count(); var H = S.Where(Si => Si[0] == 'H').Count(); var not0 = new List<long> { M, A, R, C, H }.Where(i => i != 0).ToList(); if (not0.Count < 3) { Print(0); } else { var lastIx = not0.Count - 1; var ans = Enumerable.Range(0, lastIx - 2 + 1) .SelectMany( a => Enumerable.Range(a + 1, lastIx - 1 - (a + 1) + 1) .SelectMany( b => Enumerable.Range(b + 1, lastIx - (b + 1) + 1) .Select(c => { // Print ($"{a}, {b}, {c}"); return not0[a] * not0[b] * not0[c]; }))) .Sum(); Print(ans); } } } static class MyInputOutputs { /* Input & Output*/ public static int ReadInt() { return int.Parse(Console.ReadLine()); } public static long ReadLong() { return long.Parse(Console.ReadLine()); } public static List<int> ReadInts() { return Console.ReadLine().Split(' ').Select(c => int.Parse(c)).ToList(); } public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(c => long.Parse(c)).ToList(); } public static List<List<int>> ReadIntColumns(int n) { /* 入力例 A1 B1 A2 B2 ... An Bn 出力例 [[A1,A2,...,An], [B1,B2,...,Bn]] */ var rows = Enumerable.Range(0, n).Select(i => ReadInts()).ToList(); var m = rows.FirstOrDefault()?.Count() ?? 0; return Enumerable.Range(0, m) .Select(i => rows.Select(items => items[i]).ToList()) .ToList(); } public static List<List<long>> ReadLongColumns(int n) { /* 入力例 A1 B1 A2 B2 ... An Bn 出力例 [[A1,A2,...,An], [B1,B2,...,Bn]] */ var rows = Enumerable.Range(0, n).Select(i => ReadLongs()).ToList(); var m = rows.FirstOrDefault()?.Count() ?? 0; return Enumerable.Range(0, m) .Select(i => rows.Select(items => items[i]).ToList()) .ToList(); } public static void Print<T>(T item) { Console.WriteLine(item); } public static void PrintIf<T1, T2>(bool condition, T1 trueResult, T2 falseResult) { if (condition) { Console.WriteLine(trueResult); } else { Console.WriteLine(falseResult); } } public static void PrintRow<T>(IEnumerable<T> list) { /* 横ベクトルで表示 A B C D ... */ if (!list.IsEmpty()) { Console.Write(list.First()); foreach (var item in list.Skip(1)) { Console.Write($" {item}"); } } Console.Write("\n"); } public static void PrintColomn<T>(IEnumerable<T> list) { /* 縦ベクトルで表示 A B C D ... */ foreach (var item in list) { Console.WriteLine(item); } } public static void Print2DArray<T>(IEnumerable<IEnumerable<T>> sources) { foreach (var row in sources) { PrintRow(row); } } } static class MyNumericFunctions { public static bool isEven(int a) { return a % 2 == 0; } public static bool isEven(long a) { return a % 2 == 0; } public static bool isOdd(int a) { return !isEven(a); } public static bool isOdd(long a) { return !isEven(a); } public static long nPk(int n, int k) { if (k > n) { return 0; } else { return Enumerable.Range(n - k + 1, k) .Aggregate((long)1, ((i, m) => i * m)); } } public static long Fact(int n) { return nPk(n, n); } public static long nCk(int n, int k) { if (k > n) { return 0; } else { return nPk(n, k) / Fact(k); } } // 最大公約数 public static long GCD(long m, long n) { if (m < n) { return GCD(n, m); } else if (n == 0) { return m; } else { return GCD(n, m % n); } } // 最小公倍数 public static long LCM(long m, long n) { if (m < n) { return LCM(n, m); } else { return (m * n) / GCD(m, n); } } } static class MyExtensions { // AppendとPrependが、.NET Standard 1.6からの追加で、Mono 4.6.2 // はそれに対応して仕様はあるが、実装がない public static IEnumerable<T> Append<T>(this IEnumerable<T> source, T element) { return source.Concat(Enumerable.Repeat(element, 1)); } public static IEnumerable<T> Prepend<T>(this IEnumerable<T> source, T element) { return Enumerable.Repeat(element, 1).Concat(source); } // TakeLastとSkipLastが、.Net Standard 2.1からの追加で、Mono 4.6.2 // はそれに対応していない public static IEnumerable<T> TakeLast<T>(this IEnumerable<T> source, int count) { return source.Skip(source.Count() - count); } public static IEnumerable<T> SkipLast<T>(this IEnumerable<T> source, int count) { return source.Take(source.Count() - count); } public static bool IsEmpty<T>(this IEnumerable<T> source) { return !source.Any(); } /// <summary> /// インデックスiの位置の要素からk個取り除く /// O(N) /// </summary> public static IEnumerable<T> TakeAwayRange<T>(this IEnumerable<T> source, int i, int count) { return source.Take(i).Concat(source.Skip(i + count)); } /// <summary> /// インデックスiの位置の要素を取り除く /// O(N) /// </summary> public static IEnumerable<T> TakeAwayAt<T>(this IEnumerable<T> source, int i) { return source.TakeAwayRange(i, 1); } /// <summary> /// インデックスiの位置にシーケンスを挿入する /// O(N + K) /// </summary> public static IEnumerable<T> InsertEnumAt<T>(this IEnumerable<T> source, int i, IEnumerable<T> inserted) { return source.Take(i).Concat(inserted).Concat(source.Skip(i)); } /// <summary> /// 順列を得る /// O(N!) /// </summary> public static IEnumerable<IEnumerable<T>> Perm<T>(this IEnumerable<T> source, int n) { if (n == 0 || source.IsEmpty() || source.Count() < n) { return Enumerable.Empty<IEnumerable<T>>(); } else if (n == 1) { return source.Select(i => new List<T> { i }); } else { var nexts = source.Select( (x, i) => new { next = source.Take(i).Concat(source.Skip(i + 1)), selected = source.Take(i + 1).Last() }); return nexts.SelectMany( next => Perm(next.next, n - 1) .Select(item => item.Prepend(next.selected))); } } /// <summary> /// シーケンスの隣り合う要素を2引数の関数に適用したシーケンスを得る /// </summary> /// <para>O(N)</para> /// <param name="source">元のシーケンス</param> /// <param name="func">2引数関数</param> /// <example>[1,2,3,4].MapAdjacent(f) => [f(1,2), f(2,3), f(3,4)]</example> public static IEnumerable<TR> MapAdjacent<T1, TR>(this IEnumerable<T1> source, Func<T1, T1, TR> func) { var list = source.ToList(); return Enumerable.Range(1, list.Count - 1) .Select(i => func(list[i], list[i - 1])); } /// <summary> /// 累積項を要素にもつシーケンスを得る(初項は、first) /// <para>O(N)</para> /// </summary> /// <param name="source">元のシーケンス</param> /// <param name="func">2引数関数f</param> /// <param name="first">func(first, source[0])のための初項</param> /// <example> [1,2,3].Scanl1(f,0) => [0, f(0,1), f(f(0,1),2), /// f(f(f(0,1),2),3)]</example> public static IEnumerable<TR> Scanl<T, TR>(this IEnumerable<T> source, TR first, Func<TR, T, TR> func) { var list = source.ToList(); var result = new List<TR> { first }; foreach (var i in Enumerable.Range(0, source.Count())) { result.Add(func(result[i], list[i])); } return result; } /// <summary> /// 累積項を要素にもつシーケンスを得る(初項は、source.First()) /// <para>O(N)</para> /// </summary> /// <param name="source">元のシーケンス</param> /// <param name="func">2引数関数f</param> /// <example> [1,2,3].Scanl1(f) => [1, f(1,2), f(f(1,2),3)]</example> public static IEnumerable<T> Scanl1<T>(this IEnumerable<T> source, Func<T, T, T> func) { var list = source.ToList(); var result = new List<T> { list[0] }; foreach (var i in Enumerable.Range(1, source.Count() - 1)) { result.Add(func(result[i - 1], list[i])); } return result; } /// <summary> /// 昇順にソートしたインデックスを得る /// </summary> /// <para>O(N * log N)</para> public static IEnumerable<int> SortIndex<T>(this IEnumerable<T> source) { return source.Select((item, i) => new { Item = item, Index = i }) .OrderBy(x => x.Item) .Select(x => x.Index); } } }
[["-", 63, 214, 205, 230, 39, 236, 237, 238, 0, 199], ["+", 63, 214, 205, 230, 39, 236, 237, 238, 0, 199]]
8
2,058
2
using System; using System.Linq; using System.Collections.Generic; public class c { public static void Main() { int n = int.Parse(Console.ReadLine()); int m = 0; int a = 0; int r = 0; int c = 0; int h = 0; for (int i = 0; i < n; i++) { string s = Console.ReadLine(); if (s[0] == 'M') m++; else if (s[0] == 'A') a++; else if (s[0] == 'R') r++; else if (s[0] == 'C') c++; else if (s[0] == 'H') h++; } long ans = m * a * r; ans += m * a * c; ans += m * a * h; ans += m * r * c; ans += m * r * h; ans += m * c * h; ans += a * r * c; ans += a * r * h; ans += a * c * h; ans += r * c * h; Console.WriteLine(ans); } }
using System; using System.Linq; using System.Collections.Generic; public class c { public static void Main() { int n = int.Parse(Console.ReadLine()); long m = 0; long a = 0; long r = 0; long c = 0; long h = 0; for (int i = 0; i < n; i++) { string s = Console.ReadLine(); if (s[0] == 'M') m++; else if (s[0] == 'A') a++; else if (s[0] == 'R') r++; else if (s[0] == 'C') c++; else if (s[0] == 'H') h++; } long ans = m * a * r; ans += m * a * c; ans += m * a * h; ans += m * r * c; ans += m * r * h; ans += m * c * h; ans += a * r * c; ans += a * r * h; ans += a * c * h; ans += r * c * h; Console.WriteLine(ans); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
254
10
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { Solve(); } static void Solve() { Scan sc = new Scan(); write wr = new write(); var k = sc.intarr; int n = k[0]; int m = 0, a = 0, r = 0, c = 0, h = 0; int[] k1 = { 0, 0, 0, 0, 0, 0, 1, 1, 1, 2 }; int[] k2 = { 1, 1, 1, 2, 2, 3, 2, 2, 3, 3 }; int[] k3 = { 2, 3, 4, 3, 4, 4, 3, 4, 4, 4 }; for (int i = 0; i < n; ++i) { string s = sc.str; if (s[0] == 'M') m++; if (s[0] == 'A') a++; if (s[0] == 'R') r++; if (s[0] == 'C') c++; if (s[0] == 'H') h++; } long ans = 0; int[] d = { m, a, r, c, h }; for (int i = 0; i < 10; ++i) { ans += d[k1[i]] * d[k2[i]] * d[k3[i]]; } wr.wri(ans); } } class Scan { public string str => Console.ReadLine(); public string[] strarr => str.Split(' '); public long[] longarr => strarr.Select(long.Parse).ToArray(); public int[] intarr => strarr.Select(int.Parse).ToArray(); public char[] chararr => strarr.Select(char.Parse).ToArray(); } class write { public void wri<Type>(Type x) { Console.WriteLine(x); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { Solve(); } static void Solve() { Scan sc = new Scan(); write wr = new write(); var k = sc.intarr; int n = k[0]; int m = 0, a = 0, r = 0, c = 0, h = 0; int[] k1 = { 0, 0, 0, 0, 0, 0, 1, 1, 1, 2 }; int[] k2 = { 1, 1, 1, 2, 2, 3, 2, 2, 3, 3 }; int[] k3 = { 2, 3, 4, 3, 4, 4, 3, 4, 4, 4 }; for (int i = 0; i < n; ++i) { string s = sc.str; if (s[0] == 'M') m++; if (s[0] == 'A') a++; if (s[0] == 'R') r++; if (s[0] == 'C') c++; if (s[0] == 'H') h++; } long ans = 0; long[] d = { m, a, r, c, h }; for (int i = 0; i < 10; ++i) { ans += d[k1[i]] * d[k2[i]] * d[k3[i]]; } wr.wri(ans); } } class Scan { public string str => Console.ReadLine(); public string[] strarr => str.Split(' '); public long[] longarr => strarr.Select(long.Parse).ToArray(); public int[] intarr => strarr.Select(int.Parse).ToArray(); public char[] chararr => strarr.Select(char.Parse).ToArray(); } class write { public void wri<Type>(Type x) { Console.WriteLine(x); } }
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199]]
8
459
2
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var dict = new Dictionary<char, int>(); for (int i = 0; i < n; i++) { var c = Console.ReadLine()[0]; switch (c) { case 'M': case 'A': case 'R': case 'C': case 'H': if (dict.ContainsKey(c)) { dict[c]++; } else { dict[c] = 1; } break; } } var d = dict.Values.ToArray(); var ans = dfs(0, 3, d); Console.WriteLine(ans); } static int dfs(int i, int n, int[] d) { if (n == 0) { return 1; } var ans = 0; for (; i <= d.Length - n; i++) { ans += d[i] * dfs(i + 1, n - 1, d); } return ans; } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var dict = new Dictionary<char, int>(); for (int i = 0; i < n; i++) { var c = Console.ReadLine()[0]; switch (c) { case 'M': case 'A': case 'R': case 'C': case 'H': if (dict.ContainsKey(c)) { dict[c]++; } else { dict[c] = 1; } break; } } var d = dict.Values.ToArray(); var ans = dfs(0, 3, d); Console.WriteLine(ans); } static long dfs(int i, int n, int[] d) { if (n == 0) { return 1; } var ans = 0L; for (; i <= d.Length - n; i++) { ans += d[i] * dfs(i + 1, n - 1, d); } return ans; } }
[["-", 0, 208, 0, 235, 8, 201, 0, 195, 39, 199], ["+", 0, 208, 0, 235, 8, 201, 0, 195, 39, 199], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
8
247
4
using System; using System.Diagnostics; using System.Collections.Generic; using System.Linq; class Program { static void Main() { int n = int.Parse(Console.ReadLine()); var dic = new Dictionary<char, int>(); for (int i = 0; i < n; i++) { string s = Console.ReadLine(); if (s[0] == 'M' || s[0] == 'A' || s[0] == 'R' || s[0] == 'C' || s[0] == 'H') { // 存在したら++、しなければ値1で追加 if (dic.ContainsKey(s[0])) dic[s[0]]++; else dic[s[0]] = 1; } } int ans = 0; for (int i = 0; i < 1 << dic.Count; i++) { // ビット演算で3つの掛け算を全部計算 var bits = new bool[dic.Count]; int m = 0; for (int j = 0; j < dic.Count; j++) { if ((i >> j & 1) == 1) { bits[j] = true; m++; } } if (m == 3) { int tmp = 1; for (int j = 0; j < dic.Count; j++) { if (bits[j]) tmp *= dic.ElementAt(j).Value; } ans += tmp; } } Console.WriteLine(ans); } }
using System; using System.Diagnostics; using System.Collections.Generic; using System.Linq; class Program { static void Main() { int n = int.Parse(Console.ReadLine()); var dic = new Dictionary<char, int>(); for (int i = 0; i < n; i++) { string s = Console.ReadLine(); if (s[0] == 'M' || s[0] == 'A' || s[0] == 'R' || s[0] == 'C' || s[0] == 'H') { // 存在したら++、しなければ値1で追加 if (dic.ContainsKey(s[0])) dic[s[0]]++; else dic[s[0]] = 1; } } long ans = 0; for (int i = 0; i < 1 << dic.Count; i++) { // ビット演算で3つの掛け算を全部計算 var bits = new bool[dic.Count]; int m = 0; for (int j = 0; j < dic.Count; j++) { if ((i >> j & 1) == 1) { bits[j] = true; m++; } } if (m == 3) { long tmp = 1; for (int j = 0; j < dic.Count; j++) { if (bits[j]) tmp *= dic.ElementAt(j).Value; } ans += tmp; } } Console.WriteLine(ans); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 57, 64, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 57, 64, 196, 0, 197, 0, 198, 39, 199]]
8
309
4
using System; using System.Collections.Generic; using System.Linq; namespace CSharpSample01 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); var diclist = new HashSet<string>[5]; var M = new HashSet<string>(); var A = new HashSet<string>(); var R = new HashSet<string>(); var C = new HashSet<string>(); var H = new HashSet<string>(); for (int i = 0; i < N; i++) { string str = Console.ReadLine(); if (str[0] == 'M') M.Add(str); else if (str[0] == 'A') A.Add(str); else if (str[0] == 'R') R.Add(str); else if (str[0] == 'C') C.Add(str); else if (str[0] == 'H') H.Add(str); } diclist[0] = M; diclist[1] = A; diclist[2] = R; diclist[3] = C; diclist[4] = H; long ans = 0; for (int i = 0; i <= 2; i++) { for (int j = i + 1; j <= 3; j++) { for (int k = j + 1; k <= 4; k++) { ans += diclist[i].Count * diclist[j].Count * diclist[k].Count; } } } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; namespace CSharpSample01 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); var diclist = new HashSet<string>[5]; var M = new HashSet<string>(); var A = new HashSet<string>(); var R = new HashSet<string>(); var C = new HashSet<string>(); var H = new HashSet<string>(); for (int i = 0; i < N; i++) { string str = Console.ReadLine(); if (str[0] == 'M') M.Add(str); else if (str[0] == 'A') A.Add(str); else if (str[0] == 'R') R.Add(str); else if (str[0] == 'C') C.Add(str); else if (str[0] == 'H') H.Add(str); } diclist[0] = M; diclist[1] = A; diclist[2] = R; diclist[3] = C; diclist[4] = H; long ans = 0; for (int i = 0; i <= 2; i++) { for (int j = i + 1; j <= 3; j++) { for (int k = j + 1; k <= 4; k++) { ans += (long)diclist[i].Count * diclist[j].Count * diclist[k].Count; } } } Console.WriteLine(ans); } } }
[["+", 0, 11, 12, 16, 31, 16, 31, 74, 0, 24], ["+", 0, 11, 12, 16, 31, 16, 31, 74, 39, 199], ["+", 0, 11, 12, 16, 31, 16, 31, 74, 0, 25]]
8
356
3
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Program { static void Main(string[] args) { // var line1 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); // var N = line1[0]; // var M = line1[1]; // var a = new long[M]; // var b = new long[M]; // int bridge = 0; // int[,] dag = new int[N,N]; // for (int i = 0; i < M; i++) //{ // var line2 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); // a[i] = line2[0]-1; // b[i] = line2[1]-1; // dag[a[i], b[i]] = 1; // dag[b[i], a[i]] = 1; //} // for (int i = 0; i < M; i++) //{ // bool[] visited = new bool[N]; // dag[a[i], b[i]] = 0; // dag[b[i], a[i]] = 0; // DFS(0,visited,dag); // if (visited.Where(n => n == true).Count() != N) // { // bridge++; // } // dag[a[i], b[i]] = 1; // dag[b[i], a[i]] = 1; //} // Console.WriteLine(bridge); // var line1 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); // var A = line1[0]; // var B = line1[1]; // var C = line1[2]; // var D = line1[3]; // var E = line1[4]; // var F = line1[5]; var N = int.Parse(Console.ReadLine()); char[] mozi = new char[N]; int[] MARCH = new int[5]; int cnt = 0; for (int i = 0; i < N; i++) { mozi[i] = Console.ReadLine().ToCharArray()[0]; } MARCH[0] = mozi.Where(n => n == 'M').Count(); MARCH[1] = mozi.Where(n => n == 'A').Count(); MARCH[2] = mozi.Where(n => n == 'R').Count(); MARCH[3] = mozi.Where(n => n == 'C').Count(); MARCH[4] = mozi.Where(n => n == 'H').Count(); for (int i = 0; i < 3; i++) { for (int j = i + 1; j < 4; j++) { for (int k = j + 1; k < 5; k++) { cnt += MARCH[i] * MARCH[j] * MARCH[k]; } } } Console.WriteLine(cnt); } public static void DFS(int v, bool[] visited, int[,] dag) { visited[v] = true; for (int i = 0; i < visited.Length; i++) { if (dag[v, i] == 0) continue; if (visited[i]) continue; DFS(i, visited, dag); } } public static long LowerBound<T>(T[] arr, long start, long end, T value, IComparer<T> comparer) { long low = start; long high = end; long mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) < 0) low = mid + 1; else high = mid; } return low; } //引数省略のオーバーロード public static long LowerBound<T>(T[] arr, T value) where T : IComparable { return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default); } public static long UpperBound<T>(T[] arr, long start, long end, T value, IComparer<T> comparer) { long low = start; long high = end; long mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) <= 0) low = mid + 1; else high = mid; } return low; } //引数省略のオーバーロード public static long UpperBound<T>(T[] arr, T value) { return UpperBound(arr, 0, arr.Length, value, Comparer<T>.Default); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Program { static void Main(string[] args) { // var line1 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); // var N = line1[0]; // var M = line1[1]; // var a = new long[M]; // var b = new long[M]; // int bridge = 0; // int[,] dag = new int[N,N]; // for (int i = 0; i < M; i++) //{ // var line2 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); // a[i] = line2[0]-1; // b[i] = line2[1]-1; // dag[a[i], b[i]] = 1; // dag[b[i], a[i]] = 1; //} // for (int i = 0; i < M; i++) //{ // bool[] visited = new bool[N]; // dag[a[i], b[i]] = 0; // dag[b[i], a[i]] = 0; // DFS(0,visited,dag); // if (visited.Where(n => n == true).Count() != N) // { // bridge++; // } // dag[a[i], b[i]] = 1; // dag[b[i], a[i]] = 1; //} // Console.WriteLine(bridge); // var line1 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); // var A = line1[0]; // var B = line1[1]; // var C = line1[2]; // var D = line1[3]; // var E = line1[4]; // var F = line1[5]; var N = int.Parse(Console.ReadLine()); char[] mozi = new char[N]; long[] MARCH = new long[5]; long cnt = 0; for (int i = 0; i < N; i++) { mozi[i] = Console.ReadLine().ToCharArray()[0]; } MARCH[0] = mozi.Where(n => n == 'M').Count(); MARCH[1] = mozi.Where(n => n == 'A').Count(); MARCH[2] = mozi.Where(n => n == 'R').Count(); MARCH[3] = mozi.Where(n => n == 'C').Count(); MARCH[4] = mozi.Where(n => n == 'H').Count(); for (int i = 0; i < 3; i++) { for (int j = i + 1; j < 4; j++) { for (int k = j + 1; k < 5; k++) { cnt += MARCH[i] * MARCH[j] * MARCH[k]; } } } Console.WriteLine(cnt); } public static void DFS(int v, bool[] visited, int[,] dag) { visited[v] = true; for (int i = 0; i < visited.Length; i++) { if (dag[v, i] == 0) continue; if (visited[i]) continue; DFS(i, visited, dag); } } public static long LowerBound<T>(T[] arr, long start, long end, T value, IComparer<T> comparer) { long low = start; long high = end; long mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) < 0) low = mid + 1; else high = mid; } return low; } //引数省略のオーバーロード public static long LowerBound<T>(T[] arr, T value) where T : IComparable { return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default); } public static long UpperBound<T>(T[] arr, long start, long end, T value, IComparer<T> comparer) { long low = start; long high = end; long mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) <= 0) low = mid + 1; else high = mid; } return low; } //引数省略のオーバーロード public static long UpperBound<T>(T[] arr, T value) { return UpperBound(arr, 0, arr.Length, value, Comparer<T>.Default); } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
694
6
using System; using System.Collections.Generic; using System.Linq; class Program { static long ans = 0; static int[] h = new int[5]; static void Main() { int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string s = Console.ReadLine(); if (s[0] == 'M') { h[0]++; } else if (s[0] == 'A') { h[1]++; } else if (s[0] == 'R') { h[2]++; } else if (s[0] == 'C') { h[3]++; } else if (s[0] == 'H') { h[4]++; } } fu(0, 0, 1); Console.WriteLine(ans); } static void fu(int n, int a, int b) { if (n == 3) { ans += b; } else { for (int i = a; i < 5; i++) { if (h[i] > 0) { fu(n + 1, i + 1, b * h[i]); } } } } }
using System; using System.Collections.Generic; using System.Linq; class Program { static long ans = 0; static long[] h = new long[5]; static void Main() { int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string s = Console.ReadLine(); if (s[0] == 'M') { h[0]++; } else if (s[0] == 'A') { h[1]++; } else if (s[0] == 'R') { h[2]++; } else if (s[0] == 'C') { h[3]++; } else if (s[0] == 'H') { h[4]++; } } fu(0, 0, 1); Console.WriteLine(ans); } static void fu(int n, int a, long b) { if (n == 3) { ans += b; } else { for (int i = a; i < 5; i++) { if (h[i] > 0) { fu(n + 1, i + 1, b * h[i]); } } } } }
[["-", 8, 201, 0, 124, 0, 198, 39, 224, 39, 199], ["+", 8, 201, 0, 124, 0, 198, 39, 224, 39, 199], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199]]
8
273
6
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Practice { class Program { private static int ReadAndParseInt() { return int.Parse(Console.ReadLine()); } private static int[] ReadAndParseIntArr() { return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } private static long ReadAndParseLong() { return long.Parse(Console.ReadLine()); } private static long[] ReadAndParseLongArr() { return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } static void Main(string[] args) { SolveA(args); // SolveB(args); // SolveC(args); // SolveD(args); } private const long MOD = 1000000007; static void SolveA(string[] args) { int n = ReadAndParseInt(); var charTotalArr = new Dictionary<char, int>(); for (int i = 0; i < n; ++i) { string sz = Console.ReadLine(); char c = sz[0]; if (charTotalArr.ContainsKey(c)) { charTotalArr[c]++; } else { charTotalArr[c] = 1; } } string[] compArr = { "MAR", "MAC", "MAH", "MRC", "MRH", "MCH", "ARC", "ARH", "RCH", "ACH" }; long total = 0; foreach (var seach in compArr) { if (!charTotalArr.ContainsKey(seach[0])) { continue; } if (!charTotalArr.ContainsKey(seach[1])) { continue; } if (!charTotalArr.ContainsKey(seach[2])) { continue; } total += charTotalArr[seach[0]] * charTotalArr[seach[1]] * charTotalArr[seach[2]]; } Console.WriteLine(total); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Practice { class Program { private static int ReadAndParseInt() { return int.Parse(Console.ReadLine()); } private static int[] ReadAndParseIntArr() { return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } private static long ReadAndParseLong() { return long.Parse(Console.ReadLine()); } private static long[] ReadAndParseLongArr() { return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } static void Main(string[] args) { SolveA(args); // SolveB(args); // SolveC(args); // SolveD(args); } private const long MOD = 1000000007; static void SolveA(string[] args) { int n = ReadAndParseInt(); var charTotalArr = new Dictionary<char, long>(); for (int i = 0; i < n; ++i) { string sz = Console.ReadLine(); char c = sz[0]; if (charTotalArr.ContainsKey(c)) { charTotalArr[c]++; } else { charTotalArr[c] = 1; } } string[] compArr = { "MAR", "MAC", "MAH", "MRC", "MRH", "MCH", "ARC", "ARH", "RCH", "ACH" }; long total = 0; foreach (var seach in compArr) { if (!charTotalArr.ContainsKey(seach[0])) { continue; } if (!charTotalArr.ContainsKey(seach[1])) { continue; } if (!charTotalArr.ContainsKey(seach[2])) { continue; } total += charTotalArr[seach[0]] * charTotalArr[seach[1]] * charTotalArr[seach[2]]; } Console.WriteLine(total); } } }
[["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199]]
8
396
2
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.IO; using System.Text; using System.Diagnostics; class Program { static void Main() { int n = int.Parse(Console.ReadLine()); long ans = 0; Dictionary<char, int> dict = new Dictionary<char, int>(); for (int i = 0; i < n; i++) { char c = Console.ReadLine()[0]; dict[c] = dict.ContainsKey(c) ? dict[c] + 1 : 1; } if (dict.Count >= 3) { int[] count = new int[5]; count[0] = dict.ContainsKey('M') ? dict['M'] : 0; count[1] = dict.ContainsKey('A') ? dict['A'] : 0; count[2] = dict.ContainsKey('R') ? dict['R'] : 0; count[3] = dict.ContainsKey('C') ? dict['C'] : 0; count[4] = dict.ContainsKey('H') ? dict['H'] : 0; for (int i = 0; i < 5; i++) { for (int j = i + 1; j < 5; j++) { for (int k = j + 1; k < 5; k++) { ans += count[i] * count[j] * count[k]; } } } } Console.WriteLine(ans); } }
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.IO; using System.Text; using System.Diagnostics; class Program { static void Main() { long n = int.Parse(Console.ReadLine()); long ans = 0; Dictionary<char, long> dict = new Dictionary<char, long>(); for (int i = 0; i < n; i++) { char c = Console.ReadLine()[0]; dict[c] = dict.ContainsKey(c) ? dict[c] + 1 : 1; } if (dict.Count >= 3) { long[] count = new long[5]; count[0] = dict.ContainsKey('M') ? dict['M'] : 0; count[1] = dict.ContainsKey('A') ? dict['A'] : 0; count[2] = dict.ContainsKey('R') ? dict['R'] : 0; count[3] = dict.ContainsKey('C') ? dict['C'] : 0; count[4] = dict.ContainsKey('H') ? dict['H'] : 0; for (int i = 0; i < 5; i++) { for (int j = i + 1; j < 5; j++) { for (int k = j + 1; k < 5; k++) { ans += count[i] * count[j] * count[k]; } } } } Console.WriteLine(ans); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 197, 0, 198, 39, 236, 237, 238, 0, 199], ["+", 0, 197, 0, 198, 39, 236, 237, 238, 0, 199], ["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["-", 64, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 64, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199]]
8
346
10