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.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { public class QuestionA { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // 文字列の入力 // string s = Console.ReadLine(); // 整数の入力 // long n = long.Parse(Console.ReadLine()); // 文字列配列の入力 // string[] inputStrArray = Console.ReadLine().Split(' '); // 整数配列の入力 var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray(); var A = inputLongArray[0]; var B = inputLongArray[1]; var H = inputLongArray[2]; var M = inputLongArray[3]; float H_deg = (H * (float)30) + ((M / (float)60) * (float)30); float M_deg = (float)360 * (M / (float)60); double HM_diff = (H_deg - M_deg) * (Math.PI / (float)180); double cosC = Math.Cos(HM_diff); double c = Math.Sqrt(Math.Pow(A, 2) + Math.Pow(B, 2) - 2 * A * B * cosC); Console.WriteLine(c); Console.Out.Flush(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { public class QuestionA { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // 文字列の入力 // string s = Console.ReadLine(); // 整数の入力 // long n = long.Parse(Console.ReadLine()); // 文字列配列の入力 // string[] inputStrArray = Console.ReadLine().Split(' '); // 整数配列の入力 var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray(); var A = inputLongArray[0]; var B = inputLongArray[1]; var H = inputLongArray[2]; var M = inputLongArray[3]; double H_deg = (H * (double)30) + ((M / (double)60) * (double)30); double M_deg = (double)360 * (M / (double)60); double HM_diff = (H_deg - M_deg) * (Math.PI / (float)180); double cosC = Math.Cos(HM_diff); double c = Math.Sqrt(Math.Pow(A, 2) + Math.Pow(B, 2) - 2 * A * B * cosC); Console.WriteLine(c); Console.Out.Flush(); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 16, 31, 23, 0, 16, 12, 74, 39, 199], ["+", 0, 16, 31, 23, 0, 16, 12, 74, 39, 199], ["-", 0, 16, 12, 23, 0, 16, 12, 74, 39, 199], ["+", 0, 16, 12, 23, 0, 16, 12, 74, 39, 199], ["-", 0, 200, 0, 212, 0, 16, 31, 74, 39, 199], ["+", 0, 200, 0, 212, 0, 16, 31, 74, 39, 199]]
8
274
14
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Globalization; using System.Diagnostics; class Solve { public Solve() {} public static int Main() { new Solve().calc(); return 0; } Scanner cin; void calc() { cin = new Scanner(); var A = cin.nextInt(); // 時針 var B = cin.nextInt(); // 分針 var H = cin.nextInt(); // 時 var M = cin.nextInt(); // 分 var radA = H / 12.0 + M / 5.0; var radB = M / 60.0; var theta = 2.0 * Math.PI * Math.Abs(radA - radB); // 余弦定理 // a^2 = b^2 + c^2 - 2 * b * c * cos(theta); var square = A * A + B * B - 2 * A * B * Math.Cos(theta); Console.WriteLine(Math.Sqrt(square)); } } class Modulo { private const int M = 1000000007; private readonly int[] m_facs; public int Mul(int a, int b) { return (int)(Math.BigMul(a, b) % M); } public Modulo(int n) { m_facs = new int[n + 1]; m_facs[0] = 1; for (int i = 1; i <= n; ++i) { m_facs[i] = Mul(m_facs[i - 1], i); } } public int Fac(int n) { return m_facs[n]; } public int Pow(int a, int m) { switch (m) { case 0: return 1; case 1: return a; default: int p1 = Pow(a, m / 2); int p2 = Mul(p1, p1); return ((m % 2) == 0) ? p2 : Mul(p2, a); } } public int Div(int a, int b) { return Mul(a, Pow(b, M - 2)); } 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 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; } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Globalization; using System.Diagnostics; class Solve { public Solve() {} public static int Main() { new Solve().calc(); return 0; } Scanner cin; void calc() { cin = new Scanner(); var A = cin.nextInt(); // 時針 var B = cin.nextInt(); // 分針 var H = cin.nextInt(); // 時 var M = cin.nextInt(); // 分 var radA = 30.0 * H / 360.0 + 6.0 * M / 360.0 / 12.0; var radB = 6.0 * M / 360.0; var theta = Math.Abs(2.0 * Math.PI * (radA - radB)); // 余弦定理 // a^2 = b^2 + c^2 - 2 * b * c * cos(theta); var square = A * A + B * B - 2.0 * A * B * Math.Cos(theta); var result = Math.Sqrt(square); Console.WriteLine(result); } } class Modulo { private const int M = 1000000007; private readonly int[] m_facs; public int Mul(int a, int b) { return (int)(Math.BigMul(a, b) % M); } public Modulo(int n) { m_facs = new int[n + 1]; m_facs[0] = 1; for (int i = 1; i <= n; ++i) { m_facs[i] = Mul(m_facs[i - 1], i); } } public int Fac(int n) { return m_facs[n]; } public int Pow(int a, int m) { switch (m) { case 0: return 1; case 1: return a; default: int p1 = Pow(a, m / 2); int p2 = Mul(p1, p1); return ((m % 2) == 0) ? p2 : Mul(p2, a); } } public int Div(int a, int b) { return Mul(a, Pow(b, M - 2)); } 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 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; } }
[["+", 0, 212, 0, 16, 31, 16, 31, 16, 31, 250], ["+", 0, 212, 0, 16, 31, 16, 31, 16, 17, 48], ["-", 0, 200, 0, 212, 0, 16, 31, 16, 12, 250], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 12, 250], ["+", 0, 16, 12, 16, 31, 16, 31, 16, 31, 250], ["+", 0, 16, 12, 16, 31, 16, 31, 16, 17, 48], ["-", 0, 200, 0, 212, 0, 16, 12, 16, 12, 250], ["+", 0, 212, 0, 16, 12, 16, 31, 16, 12, 250], ["+", 0, 200, 0, 212, 0, 16, 12, 16, 17, 85], ["+", 0, 200, 0, 212, 0, 16, 12, 16, 12, 250], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 31, 250], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 17, 48], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 250], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 250], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["-", 0, 212, 0, 16, 12, 213, 63, 214, 205, 22], ["-", 0, 212, 0, 16, 12, 213, 63, 214, 0, 131], ["-", 0, 212, 0, 16, 12, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25], ["-", 0, 16, 12, 16, 31, 16, 31, 16, 31, 203], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
842
37
using System; using System.Collections.Generic; using System.Linq; public class Hello { public static void Main() { var input = Console.ReadLine().Split().Select(x => Int32.Parse(x)).ToList(); var a = input[0]; var b = input[1]; var h = input[2]; var m = input[3]; var h_loc = Tuple.Create(a * Math.Cos(2 * Math.PI * (h / 12.0)), a * Math.Sin(2 * Math.PI * (h / 12.0))); var m_loc = Tuple.Create(b * Math.Cos(2 * Math.PI * (m / 60.0)), b * Math.Sin(2 * Math.PI * (m / 60.0))); // System.Console.WriteLine(h_loc); System.Console.WriteLine(m_loc); var ret = Math.Pow(Math.Pow(h_loc.Item1 - m_loc.Item1, 2) + Math.Pow(h_loc.Item2 - m_loc.Item2, 2), 0.5); System.Console.WriteLine(ret); } }
using System; using System.Collections.Generic; using System.Linq; public class Hello { public static void Main() { var input = Console.ReadLine().Split().Select(x => Int32.Parse(x)).ToList(); var a = input[0]; var b = input[1]; var h = input[2]; var m = input[3]; var h_loc = Tuple.Create( a * Math.Cos(2 * Math.PI * (h / 12.0 + m / (12.0 * 60.0))), a * Math.Sin(2 * Math.PI * (h / 12.0 + m / (12.0 * 60.0)))); var m_loc = Tuple.Create(b * Math.Cos(2 * Math.PI * (m / 60.0)), b * Math.Sin(2 * Math.PI * (m / 60.0))); var ret = Math.Pow(Math.Pow(h_loc.Item1 - m_loc.Item1, 2) + Math.Pow(h_loc.Item2 - m_loc.Item2, 2), 0.5); System.Console.WriteLine(ret); } }
[["+", 0, 28, 0, 16, 12, 23, 0, 16, 17, 72], ["+", 0, 16, 12, 23, 0, 16, 12, 16, 31, 22], ["+", 0, 16, 12, 23, 0, 16, 12, 16, 17, 85], ["+", 12, 23, 0, 16, 12, 16, 12, 23, 0, 24], ["+", 0, 16, 12, 16, 12, 23, 0, 16, 31, 250], ["+", 0, 16, 12, 16, 12, 23, 0, 16, 17, 48], ["+", 0, 16, 12, 16, 12, 23, 0, 16, 12, 250], ["+", 12, 23, 0, 16, 12, 16, 12, 23, 0, 25], ["-", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 1, 0, 213, 63, 214, 205, 214, 205, 22], ["-", 0, 1, 0, 213, 63, 214, 205, 214, 0, 131], ["-", 0, 1, 0, 213, 63, 214, 205, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
240
25
using System; class C { public static void Main() { int[] Ar = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); int A = Ar[0], B = Ar[1], H = Ar[2], M = Ar[3]; double shortr = 30 * H; shortr += M * 0.5; double longr = 6 * M; double abs = Math.Abs(longr - shortr); double min = Math.Min(abs, 360 - abs); if (min == 180 || min == 0) { Console.WriteLine(B - A); return; } double aji = (A * A) + (B * B); decimal minus = ((decimal)Math.Cos(min * (Math.PI / 180)) * 2 * B * A); double ans = Math.Sqrt(aji - (double)minus); Console.WriteLine(ans); } }
using System; class C { public static void Main() { int[] Ar = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); int A = Ar[0], B = Ar[1], H = Ar[2], M = Ar[3]; double shortr = 30 * H; shortr += M * 0.5; double longr = 6 * M; double abs = Math.Abs(longr - shortr); double min = Math.Min(abs, 360 - abs); double aji = (A * A) + (B * B); decimal minus = ((decimal)Math.Cos(min * (Math.PI / 180)) * 2 * B * A); double ans = Math.Sqrt(aji - (double)minus); Console.WriteLine(ans); } }
[["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
206
23
using System; using System.Collections.Generic; using System.Linq; namespace x { class Program { static void Main(string[] args) { var vals = IOUtils.ReadInts(); var hLen = vals[0]; var mLen = vals[1]; var hour = vals[2]; var min = vals[3]; var totalMin = hour * 60 + min; var hKakuPerMin = 0.5; var mKakuPerMin = 6; var hKaku = totalMin * hKakuPerMin; var mKaku = totalMin * mKakuPerMin % 360; if (hKaku == mKaku) { System.Console.WriteLine(Math.Abs(hLen - mLen)); return; } if (Math.Abs(hKaku - mKaku) == 180) { System.Console.WriteLine(hLen + mLen); return; } Point hPt = GetPoint(hLen, hKaku); Point mPt = GetPoint(mLen, mKaku); var res = Math.Sqrt(Math.Pow(hPt.x - mPt.x, 2) + Math.Pow(hPt.y - mPt.y, 2)); System.Console.WriteLine(res); } private static Point GetPoint(int len, double kaku) { if (kaku == 0) { return new Point(0, len); } if (kaku == 90) { return new Point(len, 0); } if (kaku == 180) { return new Point(0, len * -1); } if (kaku == 270) { return new Point(len * -1, 0); } if (0 < kaku && kaku < 90) { var tmpKaku = kaku * Math.PI / 180; var y = Math.Cos(kaku) * len; var x = Math.Sin(kaku) * len; return new Point(x, y); } else if (90 < kaku && kaku < 180) { var tmpKaku = (kaku - 90) * Math.PI / 180; var y = Math.Sin(tmpKaku) * len * -1; var x = Math.Cos(tmpKaku) * len; return new Point(x, y); } else if (180 < kaku && kaku < 270) { var tmpKaku = (kaku - 180) * Math.PI / 180; var y = Math.Cos(tmpKaku) * len * -1; var x = Math.Sin(tmpKaku) * len * -1; return new Point(x, y); } else { var tmpKaku = (kaku - 270) * Math.PI / 180; var y = Math.Sin(tmpKaku) * len; var x = Math.Cos(tmpKaku) * len * -1; return new Point(x, y); } } class Point { public readonly double x; public readonly double y; public Point(double x, double y) { this.x = x; this.y = y; } } } static class IOUtils { public static (int a, int b) Read2Ints() { var vals = ReadInts(); return (vals[0], vals[1]); } public static (int a, int b, int c) Read3Ints() { var vals = ReadInts(); return (vals[0], vals[1], vals[2]); } public static IEnumerable<int[]> ReadIntLines(int count) { for (int i = 0; i < count; i++) { yield return ReadInts(); } } public static IEnumerable<long[]> ReadLongLines(int count) { for (int i = 0; i < count; i++) { yield return ReadLongs(); } } public static int ReadInt() { return int.Parse(Console.ReadLine()); } public static long ReadLong() { return long.Parse(Console.ReadLine()); } public static ulong ReadUlong() { return ulong.Parse(Console.ReadLine()); } public static int[] ReadInts() { return Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray(); } public static long[] ReadLongs() { return Console.ReadLine().Split(' ').Select(v => long.Parse(v)).ToArray(); } public static void WriteNums(params int[] nums) { Console.WriteLine(string.Join(" ", nums)); } } }
using System; using System.Collections.Generic; using System.Linq; namespace x { class Program { static void Main(string[] args) { var vals = IOUtils.ReadInts(); var hLen = vals[0]; var mLen = vals[1]; var hour = vals[2]; var min = vals[3]; var totalMin = hour * 60 + min; var hKakuPerMin = 0.5; var mKakuPerMin = 6; var hKaku = totalMin * hKakuPerMin; var mKaku = totalMin * mKakuPerMin % 360; if (hKaku == mKaku) { System.Console.WriteLine(Math.Abs(hLen - mLen)); return; } if (Math.Abs(hKaku - mKaku) == 180) { System.Console.WriteLine(hLen + mLen); return; } Point hPt = GetPoint(hLen, hKaku); Point mPt = GetPoint(mLen, mKaku); var res = Math.Sqrt(Math.Pow(hPt.x - mPt.x, 2) + Math.Pow(hPt.y - mPt.y, 2)); System.Console.WriteLine(res); } private static Point GetPoint(int len, double kaku) { if (kaku == 0) { return new Point(0, len); } if (kaku == 90) { return new Point(len, 0); } if (kaku == 180) { return new Point(0, len * -1); } if (kaku == 270) { return new Point(len * -1, 0); } if (0 < kaku && kaku < 90) { // var tmpKaku = kaku * Math.PI / 180; // var y = Math.Cos(kaku) * len; // var x = Math.Sin(kaku) * len; var tmpKaku = (90 - kaku) * Math.PI / 180; var y = Math.Sin(tmpKaku) * len; var x = Math.Cos(tmpKaku) * len; return new Point(x, y); } else if (90 < kaku && kaku < 180) { var tmpKaku = (kaku - 90) * Math.PI / 180; var y = Math.Sin(tmpKaku) * len * -1; var x = Math.Cos(tmpKaku) * len; return new Point(x, y); } else if (180 < kaku && kaku < 270) { // var tmpKaku = (kaku - 180) * Math.PI / 180; // var y = Math.Cos(tmpKaku) * len * -1; // var x = Math.Sin(tmpKaku) * len * -1; var tmpKaku = (270 - kaku) * Math.PI / 180; var y = Math.Sin(tmpKaku) * len * -1; var x = Math.Cos(tmpKaku) * len * -1; return new Point(x, y); } else { // var tmpKaku = (kaku - 270) * Math.PI / 180; // var y = Math.Sin(tmpKaku) * len; // var x = Math.Cos(tmpKaku) * len * -1; var tmpKaku = (kaku - 270) * Math.PI / 180; var y = Math.Sin(tmpKaku) * len; var x = Math.Cos(tmpKaku) * len * -1; return new Point(x, y); } } class Point { public readonly double x; public readonly double y; public Point(double x, double y) { this.x = x; this.y = y; } } } static class IOUtils { public static (int a, int b) Read2Ints() { var vals = ReadInts(); return (vals[0], vals[1]); } public static (int a, int b, int c) Read3Ints() { var vals = ReadInts(); return (vals[0], vals[1], vals[2]); } public static IEnumerable<int[]> ReadIntLines(int count) { for (int i = 0; i < count; i++) { yield return ReadInts(); } } public static IEnumerable<long[]> ReadLongLines(int count) { for (int i = 0; i < count; i++) { yield return ReadLongs(); } } public static int ReadInt() { return int.Parse(Console.ReadLine()); } public static long ReadLong() { return long.Parse(Console.ReadLine()); } public static ulong ReadUlong() { return ulong.Parse(Console.ReadLine()); } public static int[] ReadInts() { return Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray(); } public static long[] ReadLongs() { return Console.ReadLine().Split(' ').Select(v => long.Parse(v)).ToArray(); } public static void WriteNums(params int[] nums) { Console.WriteLine(string.Join(" ", nums)); } } }
[["+", 0, 212, 0, 16, 31, 16, 31, 23, 0, 24], ["+", 0, 16, 31, 16, 31, 23, 0, 16, 31, 203], ["+", 0, 16, 31, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 212, 0, 16, 31, 16, 31, 23, 0, 25], ["-", 0, 212, 0, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 212, 0, 16, 31, 213, 63, 214, 141, 22], ["-", 0, 16, 31, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 16, 31, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 16, 31, 16, 31, 23, 0, 16, 31, 22], ["-", 0, 16, 31, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 16, 31, 16, 31, 23, 0, 16, 12, 22], ["-", 0, 16, 31, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 16, 31, 16, 31, 213, 63, 214, 141, 22]]
8
920
20
using System; class SS { static void Main() { var lines = Console.ReadLine().Split(" "); int S = int.Parse(lines[0]); int L = int.Parse(lines[1]); int H = int.Parse(lines[2]); int M = int.Parse(lines[3]); if (H > 12) H -= 12; double angleA = 360 * M / 60; double angleB = (H * 60 + M) * 360 / (60 * 12); double angle = angleA - angleB; if (angle < 0) angle = angle + 360; if (angle > 180) angle = 360 - angle; var degree = angle * Math.PI / 180; var leng = Math.Sqrt(S * S + L * L - 2 * S * L * Math.Cos(degree)); Console.WriteLine("{0}", leng); } }
using System; class SS { static void Main() { var lines = Console.ReadLine().Split(" "); double S = double.Parse(lines[0]); var L = double.Parse(lines[1]); var H = double.Parse(lines[2]); var M = double.Parse(lines[3]); if (H > 12) H -= 12; double angleA = 360 * M / 60.0; double angleB = (H * 60 + M) * 360 / (60 * 12.0); double angle = angleA - angleB; if (angle < 0) angle = angle + 360; if (angle > 180) angle = 360 - angle; var degree = angle * Math.PI / 180.0; var leng = Math.Sqrt(S * S + L * L - 2 * S * L * Math.Cos(degree)); Console.WriteLine("{0}", leng); } }
[["-", 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, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 250], ["-", 0, 212, 0, 16, 12, 23, 0, 16, 12, 203], ["+", 0, 212, 0, 16, 12, 23, 0, 16, 12, 250]]
8
202
22
using System; namespace ABC168C { class Program { static void Main(string[] args) { var wo = Console.ReadLine().Split(" "); double a = int.Parse(wo[0]); double b = int.Parse(wo[1]); double h = int.Parse(wo[2]); double m = int.Parse(wo[3]); double s, x; h = h / 12 * 360 + m / 60 * 30; m = m / 60 * 360; if (h > m) s = h - m; else s = m - h; if (s >= 180) s = 360 - s; s = s / 180 * Math.PI; x = Math.Sqrt(a * a + b * b + 2 * a * b * Math.Cos(s)); Console.WriteLine(x); } } }
using System; namespace ABC168C { class Program { static void Main(string[] args) { var wo = Console.ReadLine().Split(" "); double a = int.Parse(wo[0]); double b = int.Parse(wo[1]); double h = int.Parse(wo[2]); double m = int.Parse(wo[3]); double s, x; h = (h * 60 + m) * 0.5; m = m * 6; if (h > m) s = h - m; else s = m - h; if (s >= 180) s = 360 - s; s = s / 180 * Math.PI; x = Math.Sqrt(a * a + b * b - 2 * a * b * Math.Cos(s)); Console.WriteLine(x); } } }
[["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["-", 0, 11, 12, 16, 31, 16, 31, 16, 17, 85], ["-", 0, 11, 12, 16, 31, 16, 31, 16, 12, 203], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 12, 203], ["+", 12, 16, 31, 23, 0, 16, 31, 16, 12, 203], ["-", 0, 11, 12, 16, 12, 16, 31, 16, 17, 85], ["-", 0, 11, 12, 16, 12, 16, 31, 16, 12, 203], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25], ["-", 0, 1, 0, 11, 12, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 250], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 17, 85], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 33]]
8
193
16
using System; using System.Collections.Generic; using System.Linq; namespace Atcoder { class Program { static void Main(string[] args) { int A, B, H, M; double xH, yH, xM, yM; double dH, dM; string[] str = Console.ReadLine().Split(' '); A = int.Parse(str[0]); B = int.Parse(str[1]); H = int.Parse(str[2]); M = int.Parse(str[3]); dH = (H * 30 + M / 2) * (Math.PI / 180); dM = M * (Math.PI / 30); xH = A * Math.Cos(dH); yH = A * Math.Sin(dH); xM = B * Math.Cos(dM); yM = B * Math.Sin(dM); // Console.WriteLine(dH); double distance = Math.Sqrt((xM - xH) * (xM - xH) + (yM - yH) * (yM - yH)); Console.WriteLine(distance); } } }
using System; using System.Collections.Generic; using System.Linq; namespace Atcoder { class Program { static void Main(string[] args) { double A, B, H, M; double xH, yH, xM, yM; double dH, dM; string[] str = Console.ReadLine().Split(' '); A = double.Parse(str[0]); B = double.Parse(str[1]); H = double.Parse(str[2]); M = double.Parse(str[3]); dH = (double)((H * 30 + M / 2) * (Math.PI / 180)); dM = (double)(M * (Math.PI / 30)); xH = A * Math.Cos(dH); yH = A * Math.Sin(dH); xM = B * Math.Cos(dM); yM = B * Math.Sin(dM); // Console.WriteLine(dH); double distance = Math.Sqrt((xM - xH) * (xM - xH) + (yM - yH) * (yM - yH)); Console.WriteLine(distance); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["+", 8, 196, 0, 1, 0, 11, 12, 74, 0, 24], ["+", 8, 196, 0, 1, 0, 11, 12, 74, 39, 199], ["+", 8, 196, 0, 1, 0, 11, 12, 74, 0, 25], ["+", 0, 1, 0, 11, 12, 74, 51, 23, 0, 24], ["+", 0, 1, 0, 11, 12, 74, 51, 23, 0, 25], ["+", 12, 74, 51, 23, 0, 16, 12, 23, 0, 25]]
8
239
20
using System; namespace c { class Program { static void Main(string[] args) { var _ = Console.ReadLine().Split(); var a = int.Parse(_[0]); var b = int.Parse(_[1]); var h = int.Parse(_[2]); var m = int.Parse(_[3]); var k = ((360 / 12 * h) + (0.5 * m)) - (360 / 60 * m); k = Math.Min(k, 360 - k); Console.WriteLine(k); var x = (a * a) + (b * b) - ((2 * a * b) * Math.Cos(k * (Math.PI / 180))); Console.WriteLine(string.Format("{0:f20}", Math.Sqrt(x))); } } }
using System; namespace c { class Program { static void Main(string[] args) { var _ = Console.ReadLine().Split(); var a = int.Parse(_[0]); var b = int.Parse(_[1]); var h = int.Parse(_[2]); var m = int.Parse(_[3]); var k = ((360 / 12 * h) + (0.5 * m)) - (360 / 60 * m); k = Math.Min(k, 360 - k); var x = (a * a) + (b * b) - ((2 * a * b) * Math.Cos(k * (Math.PI / 180))); Console.WriteLine(string.Format("{0:f20}", Math.Sqrt(x))); } } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
195
7
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; namespace AtCoder.C { public class Program { public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); } private static object GetResult() { var (A, B, H, M) = Read4Longs(); var h = 2 * Math.PI * ((double)H / 12) + 2 * Math.PI * ((double)M / 720); var m = 2 * Math.PI * (double)M / 60; var abs = Math.Abs(m - h); var theta = abs < Math.PI ? abs : abs - Math.PI; var cosC = Math.Cos(theta); if (cosC == 1) return A + B; return Math.Sqrt(A * A + B * B - 2 * A * B * cosC); } #region Console.Read public static string ReadText() { return Console.ReadLine(); } public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); } public static long ReadLong() { return long.Parse(Console.ReadLine()); } public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); } public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); } public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); } public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); } public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); } #endregion } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; namespace AtCoder.C { public class Program { public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); } private static object GetResult() { var (A, B, H, M) = Read4Longs(); var h = 2 * Math.PI * ((double)H / 12) + 2 * Math.PI * ((double)M / 720); var m = 2 * Math.PI * (double)M / 60; // if (Math.Abs(h - m) == 2 * Math.PI) return Math.Abs(A - B); // if (h == m) return Math.Abs(A - B); var abs = Math.Abs(m - h); var theta = abs < Math.PI ? abs : (2 * Math.PI - abs); var cosC = Math.Cos(theta); if (cosC == 1) return Math.Abs(A - B); if (cosC == -1) return A + B; return Math.Sqrt(A * A + B * B - 2 * A * B * cosC); } #region Console.Read public static string ReadText() { return Console.ReadLine(); } public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); } public static long ReadLong() { return long.Parse(Console.ReadLine()); } public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); } public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); } public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); } public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); } public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); } #endregion } }
[["-", 0, 200, 0, 212, 0, 41, 75, 16, 31, 22], ["-", 0, 200, 0, 212, 0, 41, 75, 16, 17, 33], ["+", 0, 200, 0, 212, 0, 41, 75, 23, 0, 24], ["+", 0, 41, 75, 23, 0, 16, 31, 16, 31, 203], ["+", 0, 41, 75, 23, 0, 16, 31, 16, 17, 48], ["+", 0, 212, 0, 41, 75, 23, 0, 16, 17, 33], ["+", 0, 212, 0, 41, 75, 23, 0, 16, 12, 22], ["+", 0, 200, 0, 212, 0, 41, 75, 23, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 38], ["+", 0, 57, 64, 37, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 64, 37, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 64, 37, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 64, 37, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 0, 57, 64, 37, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 241, 0, 33]]
8
484
25
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace C { class Program { const double PI = Math.PI; static void Main(string[] args) { var input = Console.ReadLine().Split(' '); var A = int.Parse(input[0]); var B = int.Parse(input[1]); var H = int.Parse(input[2]); var M = int.Parse(input[3]); double ans; double argA = (30 * H + M / 2) * PI / 180; double argB = 6 * M * PI / 180; double cargA = (30 * H + M / 2); double ax = A * Math.Sin(argA); double ay = A * Math.Cos(argA); double bx = B * Math.Sin(argB); double by = B * Math.Cos(argB); ans = Math.Sqrt((bx - ax) * (bx - ax) + (by - ay) * (by - ay)); Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace C { class Program { const double PI = Math.PI; static void Main(string[] args) { var input = Console.ReadLine().Split(' '); var A = double.Parse(input[0]); var B = double.Parse(input[1]); var H = double.Parse(input[2]); var M = double.Parse(input[3]); double ans; double argA = (30 * H + M / 2) * PI / 180; double argB = 6 * M * PI / 180; double ax = A * Math.Sin(argA); double ay = A * Math.Cos(argA); double bx = B * Math.Sin(argB); double by = B * Math.Cos(argB); ans = Math.Sqrt((bx - ax) * (bx - ax) + (by - ay) * (by - ay)); Console.WriteLine(ans); } } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 23, 0, 24], ["-", 0, 212, 0, 23, 0, 16, 31, 16, 31, 203], ["-", 0, 212, 0, 23, 0, 16, 31, 16, 17, 48], ["-", 0, 212, 0, 23, 0, 16, 31, 16, 12, 22], ["-", 0, 200, 0, 212, 0, 23, 0, 16, 17, 72], ["-", 0, 212, 0, 23, 0, 16, 12, 16, 31, 22], ["-", 0, 212, 0, 23, 0, 16, 12, 16, 17, 85], ["-", 0, 212, 0, 23, 0, 16, 12, 16, 12, 203], ["-", 0, 198, 0, 200, 0, 212, 0, 23, 0, 25]]
8
252
21
using System; using System.Collections; using System.Collections.Generic; using System.Linq; class Colon { static void Main(string[] args) { var input = Console.ReadLine().Split(' '); int long_stick = int.Parse(input[0]); int short_stick = int.Parse(input[1]); var hour = int.Parse(input[2]); var minutes = int.Parse(input[3]); double ans_length = 0; var total_time = hour * 60 + minutes; var short_arg = (total_time * 0.5) % 360.0; Console.WriteLine(short_arg); var long_arg = minutes * 6.0; var total_arg = Math.Abs(short_arg - long_arg); if (total_arg >= 180.0) { total_arg = 360.0 - total_arg; } var ans_argR = total_arg * 3.14159265358979 / 180.0; ans_length = Math.Sqrt(long_stick * long_stick + short_stick * short_stick - 2.0 * long_stick * short_stick * Math.Cos(ans_argR)); Console.WriteLine("{0:F11}", ans_length); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; class Colon { static void Main(string[] args) { var input = Console.ReadLine().Split(' '); int long_stick = int.Parse(input[0]); int short_stick = int.Parse(input[1]); var hour = int.Parse(input[2]); var minutes = int.Parse(input[3]); double ans_length; var total_time = hour * 60.0 + minutes; var short_arg = (total_time * 0.5) % 360.0; var long_arg = minutes * 6.0; var total_arg = Math.Abs(short_arg - long_arg); if (total_arg >= 180.0) { total_arg = 360.0 - total_arg; } var ans_argR = total_arg * 3.14159265358979323846 / 180.0; ans_length = Math.Sqrt(long_stick * long_stick + short_stick * short_stick - 2.0 * long_stick * short_stick * Math.Cos(ans_argR)); Console.WriteLine("{0:F20}", ans_length); } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 200, 0, 212, 0, 16, 31, 16, 12, 203], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 12, 250], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 0, 200, 0, 212, 0, 16, 31, 16, 12, 250], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
216
15
using System; using System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.Contracts; using System.Linq; namespace at_coder { #if TEST [TestClass] #endif public class Test_168_d { #if TEST public static void Test_Main() #else public static void Main() #endif { int[] ar = ReadIntArray(); int A = ar[0]; // 時間 int B = ar[1]; // 分 int H = ar[2]; int M = ar[3]; // 中間の角度の差を求める (Radian) double d1 = H / 12.0 * 2 * Math.PI; double d2 = M / 60.0 * 2 * Math.PI; double dd = Math.Abs(d1 - d2); // 時 針 double x1 = A; double y1 = 0; // 分 double x2 = Math.Cos(dd) * B; double y2 = Math.Sin(dd) * B; // 距離を求める double l = Math.Sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); Write(l.ToString()); } private static void Write(string s) { Console.WriteLine(s); } private static int[] ReadIntArray() { string[] ss = Console.ReadLine().Split( new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); int[] ar = new int[ss.Length]; for (int i = 0; i < ss.Length; i++) { ar[i] = int.Parse(ss[i]); } return ar; } private static int ReadInt() { return int.Parse(Console.ReadLine()); } private static void ReadInt(out int a, out int b) { var ar = ReadIntArray(); a = ar[0]; b = ar[1]; } private static void ReadInt(out int a, out int b, out int c) { var ar = ReadIntArray(); a = ar[0]; b = ar[1]; c = ar[2]; } private static string ReadString() { return Console.ReadLine(); } private static string[] ReadStringArray() { string[] ss = Console.ReadLine().Split( new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); return ss; } #if !TEST } } #endif
using System; using System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.Contracts; using System.Linq; namespace at_coder { #if TEST [TestClass] #endif public class Test_168_d { #if TEST public static void Test_Main() #else public static void Main() #endif { int[] ar = ReadIntArray(); int A = ar[0]; // 時間 int B = ar[1]; // 分 int H = ar[2]; int M = ar[3]; // 中間の角度の差を求める (Radian) double H2 = H + M / 60.0; double d1 = H2 / 12.0 * 2 * Math.PI; double d2 = M / 60.0 * 2 * Math.PI; double dd = Math.Abs(d1 - d2); // 時 針 double x1 = A; double y1 = 0; // 分 double x2 = Math.Cos(dd) * B; double y2 = Math.Sin(dd) * B; // 距離を求める double l = Math.Sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); Write(l.ToString()); } private static void Write(string s) { Console.WriteLine(s); } private static int[] ReadIntArray() { string[] ss = Console.ReadLine().Split( new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); int[] ar = new int[ss.Length]; for (int i = 0; i < ss.Length; i++) { ar[i] = int.Parse(ss[i]); } return ar; } private static int ReadInt() { return int.Parse(Console.ReadLine()); } private static void ReadInt(out int a, out int b) { var ar = ReadIntArray(); a = ar[0]; b = ar[1]; } private static void ReadInt(out int a, out int b, out int c) { var ar = ReadIntArray(); a = ar[0]; b = ar[1]; c = ar[2]; } private static string ReadString() { return Console.ReadLine(); } private static string[] ReadStringArray() { string[] ss = Console.ReadLine().Split( new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); return ss; } #if !TEST } } #endif
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 200, 0, 212, 0, 16, 12, 16, 31, 22], ["+", 0, 200, 0, 212, 0, 16, 12, 16, 17, 85], ["+", 0, 200, 0, 212, 0, 16, 12, 16, 12, 250], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 212, 0, 16, 31, 16, 31, 16, 31, 22]]
8
495
11
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; class TEST { static void Main() { Sol mySol = new Sol(); mySol.Solve(); } } class Sol { public void Solve() { double xa = A * Math.Cos(Math.PI / 2.0 - H * (Math.PI * 2.0 / 12.0)); double ya = A * Math.Sin(Math.PI / 2.0 - H * (Math.PI * 2.0 / 12.0)); double xb = B * Math.Cos(Math.PI / 2.0 - M * (Math.PI * 2.0 / 60.0)); double yb = B * Math.Sin(Math.PI / 2.0 - M * (Math.PI * 2.0 / 60.0)); Console.WriteLine(Math.Sqrt((xa - xb) * (xa - xb) + (ya - yb) * (ya - yb))); } int A, B, H, M; public Sol() { var d = ria(); A = d[0]; B = d[1]; H = d[2]; M = d[3]; } static String rs() { return Console.ReadLine(); } static int ri() { return int.Parse(Console.ReadLine()); } static long rl() { return long.Parse(Console.ReadLine()); } static double rd() { return double.Parse(Console.ReadLine()); } static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); } static int[] ria(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); } static long[] rla(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); } static double[] rda(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; class TEST { static void Main() { Sol mySol = new Sol(); mySol.Solve(); } } class Sol { public void Solve() { double xa = A * Math.Cos(Math.PI / 2.0 - (H + M / 60.0) * (Math.PI * 2.0 / 12.0)); double ya = A * Math.Sin(Math.PI / 2.0 - (H + M / 60.0) * (Math.PI * 2.0 / 12.0)); double xb = B * Math.Cos(Math.PI / 2.0 - M * (Math.PI * 2.0 / 60.0)); double yb = B * Math.Sin(Math.PI / 2.0 - M * (Math.PI * 2.0 / 60.0)); Console.WriteLine(Math.Sqrt((xa - xb) * (xa - xb) + (ya - yb) * (ya - yb))); } int A, B, H, M; public Sol() { var d = ria(); A = d[0]; B = d[1]; H = d[2]; M = d[3]; } static String rs() { return Console.ReadLine(); } static int ri() { return int.Parse(Console.ReadLine()); } static long rl() { return long.Parse(Console.ReadLine()); } static double rd() { return double.Parse(Console.ReadLine()); } static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); } static int[] ria(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); } static long[] rla(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); } static double[] rda(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); } }
[["+", 0, 28, 0, 16, 12, 16, 31, 23, 0, 24], ["+", 0, 16, 12, 16, 31, 23, 0, 16, 17, 72], ["+", 12, 16, 31, 23, 0, 16, 12, 16, 31, 22], ["+", 12, 16, 31, 23, 0, 16, 12, 16, 17, 85], ["+", 12, 16, 31, 23, 0, 16, 12, 16, 12, 250], ["+", 0, 28, 0, 16, 12, 16, 31, 23, 0, 25]]
8
478
12
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace ForATCODER { public class Program { /// template /// /// String[] s = Console.ReadLine().Split(' '); /// long[] nk = s2larray(Console.ReadLine().Split(' ')); /// public static void Main(string[] args) { // String[] s = Console.ReadLine().Split(' '); long[] dat = s2larray(Console.ReadLine().Split(' ')); double deg_h; double deg_m; deg_h = dat[2] * (360.0d / 12.0d); deg_m = dat[3] * (360.0d / 60.0d); deg_h += dat[3] * 0.5; double degs = Math.Abs(deg_h - deg_m); if (degs > 180) degs -= 180d; // double result = (dat[0] / (double)dat[1]) * Math.Tan(degs * // Math.PI/180); double result = Math.Pow(dat[0], 2) + Math.Pow(dat[1], 2) - 2d * (dat[0] * dat[1] * 1.0d) * Math.Cos(degs * Math.PI / 180.0d); result = Math.Sqrt(result); RESULT(result); } static void addarray(long[] arr, int start, int end) { for (int i = start; i <= end; i++) { arr[i]++; } } public static decimal Sqrt(decimal x) { decimal sqrt_x = (decimal)Math.Sqrt((long)x); for (int i = 0; i < 10; ++i) sqrt_x = 0.5m * (sqrt_x + x / sqrt_x); return sqrt_x; } static long summ(long s) { if (s == 1) return 1; return s + summ(s - 1); } public static bool checka(int[] a, int m) { int back = 1; for (int i = 0; i < a.Length; i++) { if (a[i] >= 1 && a[i] <= m) { if (a[i] >= back) { back = a[i]; } else { return false; } } else { return false; } } return true; } public static ulong pow(int a, int b) { ulong res = 1; for (int i = 0; i < b; i++) { res *= (ulong)a; } return res; } static int s2i(String s) { return Convert.ToInt32(s); } static long s2l(String s) { return Convert.ToInt64(s); } static void RESULT(double res) { Console.WriteLine(res); } static void RESULT(long res) { Console.WriteLine(res); } static void RESULT(ulong res) { Console.WriteLine(res); } static void RESULT(int res) { Console.WriteLine(res); } static void RESULT(String res) { Console.WriteLine(res); } static String[] ReadLineAll(int count) { String[] res = new String[count]; for (int i = 0; i < count; i++) { res[i] = Console.ReadLine(); } return res; } static int[] s2iarray(String[] src) { int len = src.Length; int[] res = new int[len]; for (int i = 0; i < len; i++) { res[i] = Convert.ToInt32(src[i]); } return res; } static long[] s2larray(String[] src) { int len = src.Length; long[] res = new long[len]; for (int i = 0; i < len; i++) { res[i] = Convert.ToInt64(src[i]); } return res; } static ulong[] s2larray2(String[] src) { int len = src.Length; ulong[] res = new ulong[len]; for (int i = 0; i < len; i++) { res[i] = Convert.ToUInt64(src[i]); } return res; } static long C(int n, int r) { if (n <= 1) return 0; if (r > n - r) r = n - r; // because C(n, r) == C(n, n - r) long ans = 1; int i; for (i = 1; i <= r; i++) { ans *= n - r + i; ans /= i; } return ans; } static long C(long n, long r) { if (n <= 1) return 0; if (r > n - r) r = n - r; // because C(n, r) == C(n, n - r) long ans = 1; int i; for (i = 1; i <= r; i++) { ans *= n - r + i; ans /= i; } return ans; } static ulong C(ulong n, ulong r) { if (n <= 1) return 0; if (r > n - r) r = n - r; // because C(n, r) == C(n, n - r) ulong ans = 1; ulong i; for (i = 1; i <= r; i++) { ans *= n - r + i; ans /= i; } return ans; } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace ForATCODER { public class Program { /// template /// /// String[] s = Console.ReadLine().Split(' '); /// long[] nk = s2larray(Console.ReadLine().Split(' ')); /// public static void Main(string[] args) { // String[] s = Console.ReadLine().Split(' '); long[] dat = s2larray(Console.ReadLine().Split(' ')); double deg_h; double deg_m; deg_h = dat[2] * (360.0d / 12.0d); deg_m = dat[3] * (360.0d / 60.0d); deg_h += dat[3] * 0.5; double degs = Math.Abs(deg_h - deg_m); // if (degs > 180) degs -= 180d; // double result = (dat[0] / (double)dat[1]) * Math.Tan(degs * // Math.PI/180); double result = Math.Pow(dat[0], 2) + Math.Pow(dat[1], 2) - 2d * (dat[0] * dat[1] * 1.0d) * Math.Cos(degs * Math.PI / 180.0d); result = Math.Sqrt(result); RESULT(result); } static void addarray(long[] arr, int start, int end) { for (int i = start; i <= end; i++) { arr[i]++; } } public static decimal Sqrt(decimal x) { decimal sqrt_x = (decimal)Math.Sqrt((long)x); for (int i = 0; i < 10; ++i) sqrt_x = 0.5m * (sqrt_x + x / sqrt_x); return sqrt_x; } static long summ(long s) { if (s == 1) return 1; return s + summ(s - 1); } public static bool checka(int[] a, int m) { int back = 1; for (int i = 0; i < a.Length; i++) { if (a[i] >= 1 && a[i] <= m) { if (a[i] >= back) { back = a[i]; } else { return false; } } else { return false; } } return true; } public static ulong pow(int a, int b) { ulong res = 1; for (int i = 0; i < b; i++) { res *= (ulong)a; } return res; } static int s2i(String s) { return Convert.ToInt32(s); } static long s2l(String s) { return Convert.ToInt64(s); } static void RESULT(double res) { Console.WriteLine(res); } static void RESULT(long res) { Console.WriteLine(res); } static void RESULT(ulong res) { Console.WriteLine(res); } static void RESULT(int res) { Console.WriteLine(res); } static void RESULT(String res) { Console.WriteLine(res); } static String[] ReadLineAll(int count) { String[] res = new String[count]; for (int i = 0; i < count; i++) { res[i] = Console.ReadLine(); } return res; } static int[] s2iarray(String[] src) { int len = src.Length; int[] res = new int[len]; for (int i = 0; i < len; i++) { res[i] = Convert.ToInt32(src[i]); } return res; } static long[] s2larray(String[] src) { int len = src.Length; long[] res = new long[len]; for (int i = 0; i < len; i++) { res[i] = Convert.ToInt64(src[i]); } return res; } static ulong[] s2larray2(String[] src) { int len = src.Length; ulong[] res = new ulong[len]; for (int i = 0; i < len; i++) { res[i] = Convert.ToUInt64(src[i]); } return res; } static long C(int n, int r) { if (n <= 1) return 0; if (r > n - r) r = n - r; // because C(n, r) == C(n, n - r) long ans = 1; int i; for (i = 1; i <= r; i++) { ans *= n - r + i; ans /= i; } return ans; } static long C(long n, long r) { if (n <= 1) return 0; if (r > n - r) r = n - r; // because C(n, r) == C(n, n - r) long ans = 1; int i; for (i = 1; i <= r; i++) { ans *= n - r + i; ans /= i; } return ans; } static ulong C(ulong n, ulong r) { if (n <= 1) return 0; if (r > n - r) r = n - r; // because C(n, r) == C(n, n - r) ulong ans = 1; ulong i; for (i = 1; i <= r; i++) { ans *= n - r + i; ans /= i; } return ans; } } }
[["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["-", 0, 57, 64, 1, 0, 11, 0, 202, 0, 110], ["-", 8, 196, 0, 57, 64, 1, 0, 11, 12, 250], ["-", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35]]
8
1,041
10
using System; using System.Linq; using System.Collections; using System.Collections.Generic; namespace Main { class Program { static void Main(string[] args) { //ここから // int n=Readint(); // string[] str = Console.ReadLine().Split(' '); string[] str = Console.ReadLine().Split(' '); int a = int.Parse(str[0]); int b = int.Parse(str[1]); int h = int.Parse(str[2]); int m = int.Parse(str[3]); double cos = Math.Cos(Math.PI * ((double)h / 6 + (double)m / 360 - (double)m / 30)); Console.WriteLine(cos); double ans2 = (a * a + b * b - 2 * a * b * cos); Console.WriteLine((double)Math.Pow(ans2, 0.5)); //ここまで } static int Readint() { return int.Parse(Console.ReadLine()); } static long Readlong() { return long.Parse(Console.ReadLine()); } static int Min(int a, int b) { if (a < b) return a; return b; } static int Max(int a, int b) { if (a > b) return a; return b; } } }
using System; using System.Linq; using System.Collections; using System.Collections.Generic; namespace Main { class Program { static void Main(string[] args) { //ここから // int n=Readint(); // string[] str = Console.ReadLine().Split(' '); string[] str = Console.ReadLine().Split(' '); int a = int.Parse(str[0]); int b = int.Parse(str[1]); int h = int.Parse(str[2]); int m = int.Parse(str[3]); double cos = Math.Cos(Math.PI * ((double)h / 6 + (double)m / 360 - (double)m / 30)); // Console.WriteLine(cos); double ans2 = (a * a + b * b - 2 * a * b * cos); Console.WriteLine((double)Math.Pow(ans2, 0.5)); //ここまで } static int Readint() { return int.Parse(Console.ReadLine()); } static long Readlong() { return long.Parse(Console.ReadLine()); } static int Min(int a, int b) { if (a < b) return a; return b; } static int Max(int a, int b) { if (a > b) return a; return b; } } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
279
7
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int n = int.Parse(input[0]); int m = int.Parse(input[1]); int[,] path = new int[m, 2]; List<int>[] pa = new List<int>[n]; for (int i = 0; i < n; i++) { pa[i] = new List<int>(); } for (int i = 0; i < m; i++) { string[] input2 = Console.ReadLine().Split(' '); pa[path[i, 0] - 1].Add(path[i, 1]); pa[path[i, 1] - 1].Add(path[i, 0]); } int[] dist = new int[n]; int[] prev = new int[n]; var que = new Queue<int>(); que.Enqueue(1); while (que.Count > 0) { int current = que.Peek(); que.Dequeue(); foreach (int item in pa[current - 1]) { if (dist[item - 1] == 0) { que.Enqueue(item); dist[item - 1] = dist[current - 1] + 1; prev[item - 1] = current; } } } for (int i = 1; i < n; i++) { if (prev[i] == 0) { Console.WriteLine("No"); return; } } Console.WriteLine("Yes"); for (int i = 1; i < n; i++) { Console.WriteLine(prev[i]); } } }
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int n = int.Parse(input[0]); int m = int.Parse(input[1]); int[,] path = new int[m, 2]; List<int>[] pa = new List<int>[n]; for (int i = 0; i < n; i++) { pa[i] = new List<int>(); } for (int i = 0; i < m; i++) { string[] input2 = Console.ReadLine().Split(' '); path[i, 0] = int.Parse(input2[0]); path[i, 1] = int.Parse(input2[1]); pa[path[i, 0] - 1].Add(path[i, 1]); pa[path[i, 1] - 1].Add(path[i, 0]); } int[] dist = new int[n]; int[] prev = new int[n]; var que = new Queue<int>(); que.Enqueue(1); while (que.Count > 0) { int current = que.Peek(); que.Dequeue(); foreach (int item in pa[current - 1]) { if (dist[item - 1] == 0) { que.Enqueue(item); dist[item - 1] = dist[current - 1] + 1; prev[item - 1] = current; } } } for (int i = 1; i < n; i++) { if (prev[i] == 0) { Console.WriteLine("No"); return; } } Console.WriteLine("Yes"); for (int i = 1; i < n; i++) { Console.WriteLine(prev[i]); } } }
[["+", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 21], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 12, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
8
404
34
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp15 { class Class345 { static void Main() { var NM = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = NM[0], M = NM[1]; var edge = new List<int>[N]; for (int i = 0; i < N; i++) edge[i] = new List<int>(); for (int i = 0; i < M; i++) { var r = Console.ReadLine().Split().Select(x => int.Parse(x) - 1).ToArray(); edge[r[0]].Add(r[1]); edge[r[1]].Add(r[0]); } int[] nums = new int[N]; bool[] frags = new bool[N]; frags[0] = true; var que = new Queue<int>(); que.Enqueue(0); while (que.Count > 0) { var t = que.Dequeue(); foreach (int i in edge[t]) { if (frags[i]) continue; frags[i] = true; nums[i] = t; que.Enqueue(i); } } if (frags.Contains(false)) Console.WriteLine("No"); else { for (int i = 1; i < N; i++) Console.WriteLine(nums[i] + 1); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp15 { class Class345 { static void Main() { var NM = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = NM[0], M = NM[1]; var edge = new List<int>[N]; for (int i = 0; i < N; i++) edge[i] = new List<int>(); for (int i = 0; i < M; i++) { var r = Console.ReadLine().Split().Select(x => int.Parse(x) - 1).ToArray(); edge[r[0]].Add(r[1]); edge[r[1]].Add(r[0]); } int[] nums = new int[N]; bool[] frags = new bool[N]; frags[0] = true; var que = new Queue<int>(); que.Enqueue(0); while (que.Count > 0) { var t = que.Dequeue(); foreach (int i in edge[t]) { if (frags[i]) continue; frags[i] = true; nums[i] = t; que.Enqueue(i); } } if (frags.Contains(false)) Console.WriteLine("No"); else { Console.WriteLine("Yes"); for (int i = 1; i < N; i++) Console.WriteLine(nums[i] + 1); } } } }
[["+", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35]]
8
354
9
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main(string[] args) { int[] arr = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var n = arr[0]; var m = arr[1]; var nodeArr = new Node[n]; for (int i = 0; i < n; i++) { nodeArr[i] = new Node(i + 1); } for (int i = 0; i < m; i++) { int[] arrTwo = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); int a = arrTwo[0]; int b = arrTwo[1]; nodeArr[a - 1].Children.Add(nodeArr[b - 1]); nodeArr[b - 1].Children.Add(nodeArr[a - 1]); } Search(nodeArr[0]); for (int i = 1; i < n; i++) { nodeArr[i].writeAns(); } } public static void Search(Node root) { var queue = new Queue<Node>(); root.Visited = true; // Visit(root); queue.Enqueue(root); while (queue.Count != 0) { var current_node = queue.Dequeue(); if (current_node.Children != null) { foreach (var node in current_node.Children) { if (!node.Visited) { // Visit(node); node.AnsNode = current_node; node.Visited = true; queue.Enqueue(node); } } } } } } public class Node { public int node; public Node(int i) { this.node = i; } public bool Visited { get; set; } public List<Node> Children = new List<Node>(); public Node AnsNode { get; set; } public void writeAns() { Console.WriteLine(AnsNode.node); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main(string[] args) { int[] arr = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var n = arr[0]; var m = arr[1]; var nodeArr = new Node[n]; for (int i = 0; i < n; i++) { nodeArr[i] = new Node(i + 1); } for (int i = 0; i < m; i++) { int[] arrTwo = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); int a = arrTwo[0]; int b = arrTwo[1]; nodeArr[a - 1].Children.Add(nodeArr[b - 1]); nodeArr[b - 1].Children.Add(nodeArr[a - 1]); } Search(nodeArr[0]); Console.WriteLine("Yes"); for (int i = 1; i < n; i++) { nodeArr[i].writeAns(); } } public static void Search(Node root) { var queue = new Queue<Node>(); root.Visited = true; // Visit(root); queue.Enqueue(root); while (queue.Count != 0) { var current_node = queue.Dequeue(); if (current_node.Children != null) { foreach (var node in current_node.Children) { if (!node.Visited) { // Visit(node); node.AnsNode = current_node; node.Visited = true; queue.Enqueue(node); } } } } } } public class Node { public int node; public Node(int i) { this.node = i; } public bool Visited { get; set; } public List<Node> Children = new List<Node>(); public Node AnsNode { get; set; } public void writeAns() { Console.WriteLine(AnsNode.node); } }
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 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, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
436
9
using System; using System.Collections.Generic; using System.Text; using Graph = System.Collections.Generic.List<System.Collections.Generic.List<int>>; namespace AtCoder.Problems { public class ProblemD { public static void Main(string[] args) { var s = new SolveD(); s.Solve(); } public class Scanner { private string[] _s; private int _i; private readonly char[] _separators = 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(_separators, StringSplitOptions.RemoveEmptyEntries); if (_s.Length == 0) return Next(); _i = 0; return _s[_i++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public ulong NextULong() => ulong.Parse(Next()); public double NextDouble() => double.Parse(Next()); public int[] GetIntArray(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[] GetLongArray(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[] GetDoubleArray(int n, double add = 0) { double[] array = new double[n]; for (int i = 0; i < n; i++) { array[i] = NextDouble() + add; } return array; } public string[] GetStringArray(int n) { string[] array = new string[n]; for (int i = 0; i < n; i++) { array[i] = Next(); } return array; } } } public class SolveD { public void Solve() { var cin = new ProblemD.Scanner(); var n = cin.NextInt(); var m = cin.NextInt(); var g = new Graph(n + 1); for (int i = 0; i < n + 1; i++) { g.Add(new List<int>()); } for (int i = 0; i < m; i++) { var a = cin.NextInt(); var b = cin.NextInt(); g[a].Add(b); g[b].Add(a); } var result = GetAnswer(n, m, g); Console.WriteLine(result); } public string GetAnswer(int n, int m, Graph g) { var count = new int[n + 1]; var queue = new Queue<int>(); queue.Enqueue(1); while (queue.TryDequeue(out var room)) { foreach (var nextRoom in g[room]) { if (nextRoom == 1 || count[nextRoom] > 0) { continue; } queue.Enqueue(nextRoom); count[nextRoom] = count[room] + 1; } } var sb = new StringBuilder(); sb.AppendLine("Yes"); for (int i = 2; i < count.Length; i++) { if (count[i] == 0) { return "No"; } sb.AppendLine(count[i].ToString()); } return sb.ToString(); } } }
using System; using System.Collections.Generic; using System.Text; using Graph = System.Collections.Generic.List<System.Collections.Generic.List<int>>; namespace AtCoder.Problems { public class ProblemD { public static void Main(string[] args) { var s = new SolveD(); s.Solve(); } public class Scanner { private string[] _s; private int _i; private readonly char[] _separators = 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(_separators, StringSplitOptions.RemoveEmptyEntries); if (_s.Length == 0) return Next(); _i = 0; return _s[_i++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public ulong NextULong() => ulong.Parse(Next()); public double NextDouble() => double.Parse(Next()); public int[] GetIntArray(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[] GetLongArray(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[] GetDoubleArray(int n, double add = 0) { double[] array = new double[n]; for (int i = 0; i < n; i++) { array[i] = NextDouble() + add; } return array; } public string[] GetStringArray(int n) { string[] array = new string[n]; for (int i = 0; i < n; i++) { array[i] = Next(); } return array; } } } public class SolveD { public void Solve() { var cin = new ProblemD.Scanner(); var n = cin.NextInt(); var m = cin.NextInt(); var g = new Graph(n + 1); for (int i = 0; i < n + 1; i++) { g.Add(new List<int>()); } for (int i = 0; i < m; i++) { var a = cin.NextInt(); var b = cin.NextInt(); g[a].Add(b); g[b].Add(a); } var result = GetAnswer(n, m, g); Console.WriteLine(result); } public string GetAnswer(int n, int m, Graph g) { var kanban = new int[n + 1]; var queue = new Queue<int>(); queue.Enqueue(1); while (queue.TryDequeue(out var room)) { foreach (var nextRoom in g[room]) { if (nextRoom == 1 || kanban[nextRoom] > 0) { continue; } queue.Enqueue(nextRoom); kanban[nextRoom] = room; } } var sb = new StringBuilder(); sb.AppendLine("Yes"); for (int i = 2; i < kanban.Length; i++) { if (kanban[i] == 0) { return "No"; } sb.AppendLine(kanban[i].ToString()); } return sb.ToString(); } } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["-", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["-", 0, 1, 0, 11, 12, 16, 31, 204, 205, 22], ["-", 0, 11, 12, 16, 31, 204, 206, 207, 0, 70], ["-", 0, 11, 12, 16, 31, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 205, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 214, 205, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["-", 0, 28, 0, 213, 63, 214, 205, 204, 205, 22], ["+", 0, 28, 0, 213, 63, 214, 205, 204, 205, 22]]
8
821
17
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Threading; using System.Runtime.CompilerServices; using System.Text; using System.Diagnostics; using System.Numerics; using static System.Console; using static System.Convert; using static System.Math; using static Template; class Solver { public Scanner sc; public void Solve() { var N = sc.Int; var zero = 0; long c = 0, d = 0; var ct = new Dictionary<Frac, int>(); for (int i = 0; i < N; i++) { int a, b; sc.ArrInt.Out(out a, out b); if (a == 0 && b == 0) zero++; else if (a == 0) d++; else if (b == 0) c++; else { Frac f = (a, b); if (!ct.ContainsKey(f)) ct[f] = 0; ct[f]++; } } ModInt res = c + d + 1; var use = new HashSet<Frac>(); foreach (var f in ct.Keys) { var l = ModInt.Pow(2, ct[f]); Frac p = (-f.s, f.f); if (use.Contains(p)) continue; if (ct.ContainsKey(p)) { l += ModInt.Pow(2, ct[p]) - 1; } res *= l; use.Add(f); } Console.WriteLine(res - 1); } } class Frac { public long f, s; public void Normalize() { if (s < 0) { f = -f; s = -s; } var g = GCD(Abs(f), Abs(s)); if (g == 0) { f = 0; s = 1; } else { f /= g; s /= g; } } public Frac(long f = 0, long s = 1) { this.f = f; this.s = s; Normalize(); } public double ToDouble() => (double)f / s; public override string ToString() => f + "/" + s; public static bool operator ==(Frac a, Frac b) { return a.f * b.s == a.s * b.f; } public static bool operator !=(Frac a, Frac b) => !(a == b); public static Frac operator +(Frac a, Frac b) { Frac rt = new Frac(); rt.f = a.f * b.s + a.s * b.f; rt.s = a.s * b.s; rt.Normalize(); return rt; } public static Frac operator -(Frac a, Frac b) { Frac rt = new Frac(); rt.f = a.f * b.s - a.s * b.f; rt.s = a.s * b.s; rt.Normalize(); return rt; } public static Frac operator *(Frac a, Frac b) { Frac rt = new Frac(); rt.f = a.f * b.f; rt.s = a.s * b.s; rt.Normalize(); return rt; } public static Frac operator /(Frac a, Frac b) { Frac rt = new Frac(); rt.f = a.f * b.s; rt.s = a.s * b.f; rt.Normalize(); return rt; } public static implicit operator Frac(long a) => new Frac(a); public static implicit operator Frac((long f, long s)p) => new Frac(p.f, p.s); public override bool Equals(object b) { if (b == null) return false; var w = (Frac)b; return w.f == f && w.s == s; } public override int GetHashCode() { unchecked { return (f.GetHashCode() << 5 + f.GetHashCode()) ^ s.GetHashCode(); } } public long GCD(long num1, long num2) => num1<num2? GCD(num2, num1) : num2> 0 ? GCD(num2, num1 % num2) : num1; } public struct ModInt { public const long MOD = (int)1e9 + 7; // public const long MOD = 998244353; public long Value { get; set; } public ModInt(long n = 0) { Value = n; } private static ModInt[] fac, inv, facinv; public override string ToString() => Value.ToString(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator +(ModInt l, ModInt r) { l.Value += r.Value; if (l.Value >= MOD) l.Value -= MOD; return l; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator -(ModInt l, ModInt r) { l.Value -= r.Value; if (l.Value < 0) l.Value += MOD; return l; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator *(ModInt l, ModInt r) => new ModInt(l.Value * r.Value % MOD); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator /(ModInt l, ModInt r) => l * Pow(r, MOD - 2); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator long(ModInt l) => l.Value; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator ModInt(long n) { n %= MOD; if (n < 0) n += MOD; return new ModInt(n); } public static ModInt Pow(ModInt m, long n) { if (n == 0) return 1; if (n % 2 == 0) return Pow(m * m, n >> 1); else return Pow(m * m, n >> 1) * m; } public static void Build(int n) { fac = new ModInt[n + 1]; facinv = new ModInt[n + 1]; inv = new ModInt[n + 1]; inv[1] = fac[0] = fac[1] = facinv[0] = facinv[1] = 1; for (var i = 2; i <= n; i++) { fac[i] = fac[i - 1] * i; inv[i] = MOD - inv[MOD % i] * (MOD / i); facinv[i] = facinv[i - 1] * inv[i]; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt Fac(int n) => fac[n]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt Inv(int n) => inv[n]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt FacInv(int n) => facinv[n]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt Comb(int n, int r) { if (n < r) return 0; if (n == r) return 1; return fac[n] * facinv[r] * facinv[n - r]; } public static ModInt Perm(int n, int r) { if (n < r) return 0; return fac[n] * facinv[n - r]; } } #region Template public static class Template { static void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); var sol = new Solver() { sc = new Scanner() }; // var th = new Thread(sol.Solve, 1 << 26);th.Start();th.Join(); sol.Solve(); Console.Out.Flush(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) > 0) { a = b; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void swap<T>(ref T a, ref T b) { var t = b; b = a; a = t; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void swap<T>(this IList<T> A, int i, int j) { var t = A[i]; A[i] = A[j]; A[j] = t; } public static T[] Create<T>(int n, Func<T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; } public static T[] Create<T>(int n, Func<int, T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; } public static void Out<T>(this IList<T> A, out T a) => a = A[0]; public static void Out<T>(this IList<T> A, out T a, out T b) { a = A[0]; b = A[1]; } public static void Out<T>(this IList<T> A, out T a, out T b, out T c) { A.Out(out a, out b); c = A[2]; } public static void Out<T>(this IList<T> A, out T a, out T b, out T c, out T d) { A.Out(out a, out b, out c); d = A[3]; } public static string Concat<T>(this IEnumerable<T> A, string sp) => string.Join(sp, A); public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> A) => A.OrderBy(v => Guid.NewGuid()); public static int CompareTo<T>(this T[] A, T[] B, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; for (var i = 0; i < Min(A.Length, B.Length); i++) { int c = cmp(A[i], B[i]); if (c > 0) return 1; else if (c < 0) return -1; } if (A.Length == B.Length) return 0; if (A.Length > B.Length) return 1; else return -1; } public static int ArgMax<T>(this IList<T> A, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; T max = A[0]; int rt = 0; for (int i = 1; i < A.Count; i++) if (cmp(max, A[i]) < 0) { max = A[i]; rt = i; } return rt; } public static T PopBack<T>(this List<T> A) { var v = A[A.Count - 1]; A.RemoveAt(A.Count - 1); return v; } public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); } } public class Scanner { public string Str => Console.ReadLine().Trim(); public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray(); public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray(); public char[][] Grid(int n) => Create(n, () => Str.ToCharArray()); public int[] ArrInt1D(int n) => Create(n, () => Int); public long[] ArrLong1D(int n) => Create(n, () => Long); public int[][] ArrInt2D(int n) => Create(n, () => ArrInt); public long[][] ArrLong2D(int n) => Create(n, () => ArrLong); private Queue<string> q = new Queue<string>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); } public void Make<T1>(out T1 v1) => v1 = Next<T1>(); public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); } public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); } public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); } public void Make<T1, T2, T3, T4, T5, T6, T7>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6, out T7 v7) { Make(out v1, out v2, out v3, out v4, out v5, out v6); v7 = Next<T7>(); } public (T1, T2) Make<T1, T2>() { Make(out T1 v1, out T2 v2); return (v1, v2); } public (T1, T2, T3) Make<T1, T2, T3>() { Make(out T1 v1, out T2 v2, out T3 v3); return (v1, v2, v3); } public (T1, T2, T3, T4) Make<T1, T2, T3, T4>() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2, v3, v4); } } #endregion
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Threading; using System.Runtime.CompilerServices; using System.Text; using System.Diagnostics; using System.Numerics; using static System.Console; using static System.Convert; using static System.Math; using static Template; class Solver { public Scanner sc; public void Solve() { var N = sc.Int; var zero = 0; long c = 0, d = 0; var ct = new Dictionary<Frac, int>(); for (int i = 0; i < N; i++) { long a, b; sc.ArrLong.Out(out a, out b); if (a == 0 && b == 0) zero++; else if (a == 0) d++; else if (b == 0) c++; else { Frac f = (a, b); if (!ct.ContainsKey(f)) ct[f] = 0; ct[f]++; } } ModInt res = ModInt.Pow(2, c) + ModInt.Pow(2, d) - 1; var use = new HashSet<Frac>(); foreach (var f in ct.Keys) { var l = ModInt.Pow(2, ct[f]); Frac p = (-f.s, f.f); if (use.Contains(p)) continue; if (ct.ContainsKey(p)) { l += ModInt.Pow(2, ct[p]) - 1; } res *= l; use.Add(f); } Console.WriteLine(res - 1 + zero); } } class Frac { public long f, s; public void Normalize() { if (s < 0) { f = -f; s = -s; } var g = GCD(Abs(f), Abs(s)); if (g == 0) { f = 0; s = 1; } else { f /= g; s /= g; } } public Frac(long f = 0, long s = 1) { this.f = f; this.s = s; Normalize(); } public double ToDouble() => (double)f / s; public override string ToString() => f + "/" + s; public static bool operator ==(Frac a, Frac b) { return a.f * b.s == a.s * b.f; } public static bool operator !=(Frac a, Frac b) => !(a == b); public static Frac operator +(Frac a, Frac b) { Frac rt = new Frac(); rt.f = a.f * b.s + a.s * b.f; rt.s = a.s * b.s; rt.Normalize(); return rt; } public static Frac operator -(Frac a, Frac b) { Frac rt = new Frac(); rt.f = a.f * b.s - a.s * b.f; rt.s = a.s * b.s; rt.Normalize(); return rt; } public static Frac operator *(Frac a, Frac b) { Frac rt = new Frac(); rt.f = a.f * b.f; rt.s = a.s * b.s; rt.Normalize(); return rt; } public static Frac operator /(Frac a, Frac b) { Frac rt = new Frac(); rt.f = a.f * b.s; rt.s = a.s * b.f; rt.Normalize(); return rt; } public static implicit operator Frac(long a) => new Frac(a); public static implicit operator Frac((long f, long s)p) => new Frac(p.f, p.s); public override bool Equals(object b) { if (b == null) return false; var w = (Frac)b; return w.f == f && w.s == s; } public override int GetHashCode() { unchecked { return (f.GetHashCode() << 5 + f.GetHashCode()) ^ s.GetHashCode(); } } public long GCD(long num1, long num2) => num1<num2? GCD(num2, num1) : num2> 0 ? GCD(num2, num1 % num2) : num1; } public struct ModInt { public const long MOD = (int)1e9 + 7; // public const long MOD = 998244353; public long Value { get; set; } public ModInt(long n = 0) { Value = n; } private static ModInt[] fac, inv, facinv; public override string ToString() => Value.ToString(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator +(ModInt l, ModInt r) { l.Value += r.Value; if (l.Value >= MOD) l.Value -= MOD; return l; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator -(ModInt l, ModInt r) { l.Value -= r.Value; if (l.Value < 0) l.Value += MOD; return l; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator *(ModInt l, ModInt r) => new ModInt(l.Value * r.Value % MOD); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator /(ModInt l, ModInt r) => l * Pow(r, MOD - 2); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator long(ModInt l) => l.Value; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator ModInt(long n) { n %= MOD; if (n < 0) n += MOD; return new ModInt(n); } public static ModInt Pow(ModInt m, long n) { if (n == 0) return 1; if (n % 2 == 0) return Pow(m * m, n >> 1); else return Pow(m * m, n >> 1) * m; } public static void Build(int n) { fac = new ModInt[n + 1]; facinv = new ModInt[n + 1]; inv = new ModInt[n + 1]; inv[1] = fac[0] = fac[1] = facinv[0] = facinv[1] = 1; for (var i = 2; i <= n; i++) { fac[i] = fac[i - 1] * i; inv[i] = MOD - inv[MOD % i] * (MOD / i); facinv[i] = facinv[i - 1] * inv[i]; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt Fac(int n) => fac[n]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt Inv(int n) => inv[n]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt FacInv(int n) => facinv[n]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt Comb(int n, int r) { if (n < r) return 0; if (n == r) return 1; return fac[n] * facinv[r] * facinv[n - r]; } public static ModInt Perm(int n, int r) { if (n < r) return 0; return fac[n] * facinv[n - r]; } } #region Template public static class Template { static void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); var sol = new Solver() { sc = new Scanner() }; // var th = new Thread(sol.Solve, 1 << 26);th.Start();th.Join(); sol.Solve(); Console.Out.Flush(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) > 0) { a = b; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void swap<T>(ref T a, ref T b) { var t = b; b = a; a = t; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void swap<T>(this IList<T> A, int i, int j) { var t = A[i]; A[i] = A[j]; A[j] = t; } public static T[] Create<T>(int n, Func<T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; } public static T[] Create<T>(int n, Func<int, T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; } public static void Out<T>(this IList<T> A, out T a) => a = A[0]; public static void Out<T>(this IList<T> A, out T a, out T b) { a = A[0]; b = A[1]; } public static void Out<T>(this IList<T> A, out T a, out T b, out T c) { A.Out(out a, out b); c = A[2]; } public static void Out<T>(this IList<T> A, out T a, out T b, out T c, out T d) { A.Out(out a, out b, out c); d = A[3]; } public static string Concat<T>(this IEnumerable<T> A, string sp) => string.Join(sp, A); public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> A) => A.OrderBy(v => Guid.NewGuid()); public static int CompareTo<T>(this T[] A, T[] B, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; for (var i = 0; i < Min(A.Length, B.Length); i++) { int c = cmp(A[i], B[i]); if (c > 0) return 1; else if (c < 0) return -1; } if (A.Length == B.Length) return 0; if (A.Length > B.Length) return 1; else return -1; } public static int ArgMax<T>(this IList<T> A, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; T max = A[0]; int rt = 0; for (int i = 1; i < A.Count; i++) if (cmp(max, A[i]) < 0) { max = A[i]; rt = i; } return rt; } public static T PopBack<T>(this List<T> A) { var v = A[A.Count - 1]; A.RemoveAt(A.Count - 1); return v; } public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); } } public class Scanner { public string Str => Console.ReadLine().Trim(); public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray(); public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray(); public char[][] Grid(int n) => Create(n, () => Str.ToCharArray()); public int[] ArrInt1D(int n) => Create(n, () => Int); public long[] ArrLong1D(int n) => Create(n, () => Long); public int[][] ArrInt2D(int n) => Create(n, () => ArrInt); public long[][] ArrLong2D(int n) => Create(n, () => ArrLong); private Queue<string> q = new Queue<string>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); } public void Make<T1>(out T1 v1) => v1 = Next<T1>(); public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); } public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); } public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); } public void Make<T1, T2, T3, T4, T5, T6, T7>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6, out T7 v7) { Make(out v1, out v2, out v3, out v4, out v5, out v6); v7 = Next<T7>(); } public (T1, T2) Make<T1, T2>() { Make(out T1 v1, out T2 v2); return (v1, v2); } public (T1, T2, T3) Make<T1, T2, T3>() { Make(out T1 v1, out T2 v2, out T3 v3); return (v1, v2, v3); } public (T1, T2, T3, T4) Make<T1, T2, T3, T4>() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2, v3, v4); } } #endregion
[["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 1, 0, 213, 63, 214, 205, 214, 141, 22], ["+", 0, 1, 0, 213, 63, 214, 205, 214, 141, 22], ["+", 0, 16, 31, 16, 31, 213, 63, 214, 205, 22], ["+", 0, 16, 31, 16, 31, 213, 63, 214, 0, 131], ["+", 0, 16, 31, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 16, 31, 16, 31, 213, 3, 4, 0, 24], ["+", 31, 16, 31, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 16, 31, 16, 31, 213, 3, 4, 0, 21], ["+", 0, 16, 31, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 16, 31, 16, 12, 213, 63, 214, 205, 22], ["+", 0, 16, 31, 16, 12, 213, 63, 214, 0, 131], ["+", 0, 16, 31, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 16, 31, 16, 12, 213, 3, 4, 0, 24], ["+", 31, 16, 12, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 16, 31, 16, 12, 213, 3, 4, 0, 21], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 16, 31, 16, 12, 213, 3, 4, 0, 25], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
8
3,278
22
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Numerics; namespace AtCoder { public static class Ex { public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.OrdinalIgnoreCase); return s.ToList(); } public static void yesno(this bool b) { Console.WriteLine(b ? "yes" : "no"); } public static void YesNo(this bool b) { Console.WriteLine(b ? "Yes" : "No"); } public static void YESNO(this bool b) { Console.WriteLine(b ? "YES" : "NO"); } public static int BuildBitCount(this int bits) { bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555); bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333); bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f); bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff); return (bits & 0x0000ffff) + (bits >> 16 & 0x0000ffff); } } partial class AtCoder { public string GetStr() { return Console.ReadLine().Trim(); } public char GetChar() { return Console.ReadLine().Trim()[0]; } public int GetInt() { return int.Parse(Console.ReadLine().Trim()); } public long GetLong() { return long.Parse(Console.ReadLine().Trim()); } public double GetDouble() { return double.Parse(Console.ReadLine().Trim()); } public string[] GetStrArray() { return Console.ReadLine().Trim().Split(' '); } public int[] GetIntArray() { return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); } public long[] GetLongArray() { return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); } public char[] GetCharArray() { return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray(); } public double[] GetDoubleArray() { return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray(); } public T[][] CreateJaggedArray<T>(int H, int W, T value) { return Enumerable.Repeat(0, H) .Select(s => Enumerable.Repeat(value, W).ToArray()) .ToArray(); } public int[][] GetIntJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetIntArray().ToArray()) .ToArray(); } public long[][] GetLongJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetLongArray().ToArray()) .ToArray(); } public char[][] GetCharJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetStr().ToCharArray()) .ToArray(); } public double[][] GetDoubleJaggedArray(int N) { return Enumerable.Repeat(0, N).Select(s => GetDoubleArray()).ToArray(); } Dictionary<int, List<int>> GetUnweightedAdjacencyList(int N, int M, bool isDirected, bool isNode_0indexed) { var dic = new Dictionary<int, List<int>>(); foreach (var e in Enumerable.Range(0, N)) { dic.Add(e, new List<int>()); } for (int i = 0; i < M; i++) { var input = GetIntArray(); var a = isNode_0indexed ? input[0] : input[0] - 1; var b = isNode_0indexed ? input[1] : input[1] - 1; dic[a].Add(b); if (isDirected == false) dic[b].Add(a); } return dic; } Dictionary<int, List<Edge>> GetWeightedAdjacencyList(int N, int M, bool isDirected, bool isNode_0indexed) { var dic = new Dictionary<int, List<Edge>>(); foreach (var e in Enumerable.Range(0, N)) { dic.Add(e, new List<Edge>()); } for (int i = 0; i < M; i++) { var input = GetIntArray(); var a = isNode_0indexed ? input[0] : input[0] - 1; var b = isNode_0indexed ? input[1] : input[1] - 1; var c = input[2]; dic[a].Add(new Edge(b, c)); if (isDirected == false) dic[b].Add(new Edge(a, c)); } return dic; } bool eq<T, U>() => typeof(T).Equals(typeof(U)); T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); 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); void Multi<T>(out T a) => a = cv<T>(GetStr()); void Multi<T, U>(out T a, out U b) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); } 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]); } void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); } } class Edge { public Edge(int to, long length) { To = to; Length = length; } public int To { get; set; } public long Length { get; set; } } partial class Program { static void Main() { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new AtCoder().Solve(); Console.Out.Flush(); Console.Read(); } } public partial class AtCoder { public void Solve() { long mod = 1000000007; var N = GetInt(); long az = 0; long bz = 0; var iwashi = GetLongJaggedArray(N) .Select(s => { var a = s[0]; var b = s[1]; if (a == 0 && b == 0) return null; if (a == 0) { az++; return null; } if (b == 0) { bz++; return null; } var gcd = GCD(a, b); a /= gcd; b /= gcd; if (b < 0) { a *= -1; b *= -1; } return new Tuple<long, long>(a, b); }) .Where(i => i != null) .GroupBy(g => g) .ToDictionary(g => g.Key, g => (long)g.Count()); long zero = (ModPow(2, az, mod) + ModPow(2, bz, mod) - 1 + mod) % mod; long sum = zero; var hs = new HashSet<Tuple<long, long>>(); foreach (var i in iwashi.Keys) { if (hs.Contains(i)) continue; var a = i.Item1; var b = i.Item2; if (a < 0) { a *= -1; b *= -1; } var tmpkey = new Tuple<long, long>(-b, a); var tmpvalue = iwashi.ContainsKey(tmpkey) ? iwashi[tmpkey] : 0; var value = (ModPow(2, iwashi[i], mod) + ModPow(2, tmpvalue, mod) - 1 + mod) % mod; sum = sum * value % mod; hs.Add(i); hs.Add(tmpkey); } Console.WriteLine((sum - 1 + mod) % mod); } long GCD(long a, long b) { return b != 0 ? GCD(b, a % b) : a > 0 ? a : -a; } long ModPow(long a, long n, long mod) { long res = 1; while (n > 0) { if ((n & 1) == 1) { res = res * a % mod; } a = a * a % mod; ; n >>= 1; } return res; } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Numerics; namespace AtCoder { public static class Ex { public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.OrdinalIgnoreCase); return s.ToList(); } public static void yesno(this bool b) { Console.WriteLine(b ? "yes" : "no"); } public static void YesNo(this bool b) { Console.WriteLine(b ? "Yes" : "No"); } public static void YESNO(this bool b) { Console.WriteLine(b ? "YES" : "NO"); } public static int BuildBitCount(this int bits) { bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555); bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333); bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f); bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff); return (bits & 0x0000ffff) + (bits >> 16 & 0x0000ffff); } } partial class AtCoder { public string GetStr() { return Console.ReadLine().Trim(); } public char GetChar() { return Console.ReadLine().Trim()[0]; } public int GetInt() { return int.Parse(Console.ReadLine().Trim()); } public long GetLong() { return long.Parse(Console.ReadLine().Trim()); } public double GetDouble() { return double.Parse(Console.ReadLine().Trim()); } public string[] GetStrArray() { return Console.ReadLine().Trim().Split(' '); } public int[] GetIntArray() { return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); } public long[] GetLongArray() { return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); } public char[] GetCharArray() { return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray(); } public double[] GetDoubleArray() { return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray(); } public T[][] CreateJaggedArray<T>(int H, int W, T value) { return Enumerable.Repeat(0, H) .Select(s => Enumerable.Repeat(value, W).ToArray()) .ToArray(); } public int[][] GetIntJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetIntArray().ToArray()) .ToArray(); } public long[][] GetLongJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetLongArray().ToArray()) .ToArray(); } public char[][] GetCharJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetStr().ToCharArray()) .ToArray(); } public double[][] GetDoubleJaggedArray(int N) { return Enumerable.Repeat(0, N).Select(s => GetDoubleArray()).ToArray(); } Dictionary<int, List<int>> GetUnweightedAdjacencyList(int N, int M, bool isDirected, bool isNode_0indexed) { var dic = new Dictionary<int, List<int>>(); foreach (var e in Enumerable.Range(0, N)) { dic.Add(e, new List<int>()); } for (int i = 0; i < M; i++) { var input = GetIntArray(); var a = isNode_0indexed ? input[0] : input[0] - 1; var b = isNode_0indexed ? input[1] : input[1] - 1; dic[a].Add(b); if (isDirected == false) dic[b].Add(a); } return dic; } Dictionary<int, List<Edge>> GetWeightedAdjacencyList(int N, int M, bool isDirected, bool isNode_0indexed) { var dic = new Dictionary<int, List<Edge>>(); foreach (var e in Enumerable.Range(0, N)) { dic.Add(e, new List<Edge>()); } for (int i = 0; i < M; i++) { var input = GetIntArray(); var a = isNode_0indexed ? input[0] : input[0] - 1; var b = isNode_0indexed ? input[1] : input[1] - 1; var c = input[2]; dic[a].Add(new Edge(b, c)); if (isDirected == false) dic[b].Add(new Edge(a, c)); } return dic; } bool eq<T, U>() => typeof(T).Equals(typeof(U)); T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); 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); void Multi<T>(out T a) => a = cv<T>(GetStr()); void Multi<T, U>(out T a, out U b) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); } 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]); } void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); } } class Edge { public Edge(int to, long length) { To = to; Length = length; } public int To { get; set; } public long Length { get; set; } } partial class Program { static void Main() { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new AtCoder().Solve(); Console.Out.Flush(); Console.Read(); } } public partial class AtCoder { public void Solve() { long mod = 1000000007; var N = GetInt(); long zz = 0; long az = 0; long bz = 0; var iwashi = GetLongJaggedArray(N) .Select(s => { var a = s[0]; var b = s[1]; if (a == 0 && b == 0) { zz++; return null; } if (a == 0) { az++; return null; } if (b == 0) { bz++; return null; } var gcd = GCD(a, b); a /= gcd; b /= gcd; if (b < 0) { a *= -1; b *= -1; } return new Tuple<long, long>(a, b); }) .Where(i => i != null) .GroupBy(g => g) .ToDictionary(g => g.Key, g => (long)g.Count()); long zero = (ModPow(2, az, mod) + ModPow(2, bz, mod) - 1 + mod) % mod; long sum = zero; var hs = new HashSet<Tuple<long, long>>(); foreach (var i in iwashi.Keys) { if (hs.Contains(i)) continue; var a = i.Item1; var b = i.Item2; if (a < 0) { a *= -1; b *= -1; } var tmpkey = new Tuple<long, long>(-b, a); var tmpvalue = iwashi.ContainsKey(tmpkey) ? iwashi[tmpkey] : 0; var value = (ModPow(2, iwashi[i], mod) + ModPow(2, tmpvalue, mod) - 1 + mod) % mod; sum = sum * value % mod; hs.Add(i); hs.Add(tmpkey); } Console.WriteLine((sum - 1 + mod + zz) % mod); } long GCD(long a, long b) { return b != 0 ? GCD(b, a % b) : a > 0 ? a : -a; } long ModPow(long a, long n, long mod) { long res = 1; while (n > 0) { if ((n & 1) == 1) { res = res * a % mod; } a = a * a % mod; ; n >>= 1; } return res; } } }
[["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 218, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 218, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 12, 22]]
8
2,300
12
using System; using System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; namespace AtCoder { public class Program { static void Main() { var cin = new Scanner(); int n = cin.Int(); var ab = new (long a, long b)[n]; for (int i = 0; i < n; i++) { ab[i] = (cin.Long(), cin.Long()); } var bunsus = new Bunsu[n]; for (int i = 0; i < n; i++) { var gcd = Math.Abs(GCD(ab[i].a, ab[i].b)); if (gcd == 0) { gcd = 1; } long bunshi = Math.Abs(ab[i].a / gcd); if ((ab[i].a < 0 && ab[i].b > 0) || (ab[i].a > 0 && ab[i].b < 0)) { bunshi *= -1; } long bunbo = Math.Abs(ab[i].b / gcd); bunsus[i] = new Bunsu { Bunshi = bunshi, Bunbo = bunbo }; } var map = new HashMap<Bunsu, int>(x => 0); var bunshiZero = 0; var bunboZero = 0; int zerozero = 0; for (int i = 0; i < n; i++) { if (bunsus[i].Bunbo == 0 && bunsus[i].Bunshi == 0) { ++zerozero; continue; } else if (bunsus[i].Bunbo == 0) { bunboZero++; } else if (bunsus[i].Bunshi == 0) { bunshiZero++; } else { map[bunsus[i]]++; } } var pows = new ModInt[n + 1]; for (int i = 0; i < n + 1; i++) { pows[i] = ModInt.Pow(2, i); } var done = new HashSet<Bunsu>(); ModInt ans = 1; foreach (var key in map.Keys) { if (done.Contains(key)) { continue; } var pair = key.Bunshi > 0 ? new Bunsu { Bunshi = -1 * key.Bunbo, Bunbo = key.Bunshi } : new Bunsu { Bunshi = key.Bunbo, Bunbo = -1 * key.Bunshi }; if (map.ContainsKey(pair)) { ans *= (pows[map[pair]] + pows[map[key]] - 1); } else { ans *= 2; } done.Add(key); done.Add(pair); } ans *= (pows[bunshiZero] + pows[bunboZero] - 1); ans -= 1; ans += zerozero; Console.WriteLine(ans.Value); } public static long GCD(long a, long b) { if (b == 0) { return a; } return GCD(b, a % b); } } [DebuggerDisplay("{Bunshi} {Bunbo}")] public struct Bunsu : IEquatable<Bunsu> { public long Bunshi { get; set; } public long Bunbo { get; set; } public bool Equals([AllowNull] Bunsu other) { return Bunshi == other.Bunshi && Bunbo == other.Bunbo; } public override int GetHashCode() { return HashCode.Combine(Bunshi, Bunbo); } } public struct ModInt { public static long P { get; set; } = (long)1e9 + 7; public static ModInt Pow(ModInt value, long k) { return Pow(value.Value, k); } public static ModInt Pow(long value, long k) { long ret = 1; for (k %= P - 1; k > 0; k >>= 1, value = value * value % P) { if ((k & 1) == 1) { ret = ret * value % P; } } return new ModInt(ret); } public static ModInt Inverse(ModInt value) { return Pow(value, P - 2); } public long Value; public ModInt(long value) { value %= P; if (value < 0) { value += P; } Value = value; } public static ModInt operator +(ModInt lhs, ModInt rhs) { lhs.Value += rhs.Value; if (lhs.Value >= P) { lhs.Value -= P; } return lhs; } public static ModInt operator -(ModInt lhs, ModInt rhs) { lhs.Value -= rhs.Value; if (lhs.Value < 0) { lhs.Value += P; } return lhs; } public static ModInt operator *(ModInt lhs, ModInt rhs) { return new ModInt(lhs.Value * rhs.Value % P); } public static ModInt operator /(ModInt lhs, ModInt rhs) { long exp = P - 2; while (exp > 0) { if (exp % 2 > 0) { lhs *= rhs; } rhs *= rhs; exp /= 2; } return lhs; } public static implicit operator ModInt(long n) { n %= P; if (n < 0) { n += P; } return new ModInt(n); } public override string ToString() { return Value.ToString(); } } public class HashMap<TKey, TValue> : Dictionary<TKey, TValue> { private readonly Func<TKey, TValue> initialzier_; public HashMap(Func<TKey, TValue> initialzier) : base() { initialzier_ = initialzier; } public HashMap(Func<TKey, TValue> initialzier, int capacity) : base(capacity) { initialzier_ = initialzier; } new public TValue this[TKey key] { get { if (ContainsKey(key) == false) { base[key] = initialzier_(key); } return base[key]; } set { base[key] = value; } } } public static class Helper { public static void UpdateMin<T>(ref T target, T value) where T : IComparable<T> => target = target.CompareTo(value) > 0 ? value : target; public static void UpdateMin<T>(ref T target, T value, Action<T> onUpdated) where T : IComparable<T> { if (target.CompareTo(value) > 0) { target = value; onUpdated(value); } } public static void UpdateMax<T>(ref T target, T value) where T : IComparable<T> => target = target.CompareTo(value) < 0 ? value : target; public static void UpdateMax<T>(ref T target, T value, Action<T> onUpdated) where T : IComparable<T> { if (target.CompareTo(value) < 0) { target = value; onUpdated(value); } } public static T[] Array<T>(int n, Func<int, T> init) => Enumerable.Range(0, n).Select(x => init(x)).ToArray(); public static List<T> List<T>(int n, Func<int, T> init) => Enumerable.Range(0, n).Select(x => init(x)).ToList(); public static T[,] Array2<T>(int n, int m, T init) { var array = new T[n, m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { array[i, j] = init; } } return array; } public static T[,] Array2<T>(int n, int m, Func<int, int, T> initializer) { var array = new T[n, m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { array[i, j] = initializer(i, j); } } return array; } public static T[,,] Array3<T>(int n1, int n2, int n3, T init) { var array = new T[n1, n2, n3]; for (int i1 = 0; i1 < n1; i1++) { for (int i2 = 0; i2 < n2; i2++) { for (int i3 = 0; i3 < n3; i3++) { array[i1, i2, i3] = init; } } } return array; } private static readonly int[] delta4_ = { 1, 0, -1, 0, 1 }; public static void DoAt4(int i, int j, int imax, int jmax, Action<int, int> action) { for (int n = 0; n < 4; n++) { int ii = i + delta4_[n]; int jj = j + delta4_[n + 1]; if ((uint)ii < (uint)imax && (uint)jj < (uint)jmax) { action(ii, jj); } } } } public class Scanner { private readonly char[] delimiter_ = new char[] { ' ' }; private readonly string filePath_; private readonly Func<string> reader_; private string[] buf_; private int index_; public Scanner(string file = "") { if (string.IsNullOrWhiteSpace(file)) { reader_ = Console.ReadLine; } else { filePath_ = file; var fs = new StreamReader(file); reader_ = fs.ReadLine; } buf_ = new string[0]; index_ = 0; } public string Next() { if (index_ < buf_.Length) { return buf_[index_++]; } string st = reader_(); while (st == "") { st = reader_(); } buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries); if (buf_.Length == 0) { return Next(); } index_ = 0; return buf_[index_++]; } public int Int() => int.Parse(Next()); public long Long() => long.Parse(Next()); public double Double() => double.Parse(Next()); public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = Int() + add; } return Array; } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = Long() + add; } return Array; } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = Double() + add; } return Array; } public void Save(string text) { if (string.IsNullOrWhiteSpace(filePath_)) { return; } File.WriteAllText(filePath_ + "_output.txt", text); } } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; namespace AtCoder { public class Program { static void Main() { var cin = new Scanner(); int n = cin.Int(); var ab = new (long a, long b)[n]; for (int i = 0; i < n; i++) { ab[i] = (cin.Long(), cin.Long()); } var bunsus = new Bunsu[n]; for (int i = 0; i < n; i++) { var gcd = Math.Abs(GCD(ab[i].a, ab[i].b)); if (gcd == 0) { gcd = 1; } long bunshi = Math.Abs(ab[i].a / gcd); if ((ab[i].a < 0 && ab[i].b > 0) || (ab[i].a > 0 && ab[i].b < 0)) { bunshi *= -1; } long bunbo = Math.Abs(ab[i].b / gcd); bunsus[i] = new Bunsu { Bunshi = bunshi, Bunbo = bunbo }; } var map = new HashMap<Bunsu, int>(x => 0); var bunshiZero = 0; var bunboZero = 0; int zerozero = 0; for (int i = 0; i < n; i++) { if (bunsus[i].Bunbo == 0 && bunsus[i].Bunshi == 0) { ++zerozero; continue; } else if (bunsus[i].Bunbo == 0) { bunboZero++; } else if (bunsus[i].Bunshi == 0) { bunshiZero++; } else { map[bunsus[i]]++; } } var pows = new ModInt[n + 1]; for (int i = 0; i < n + 1; i++) { pows[i] = ModInt.Pow(2, i); } var done = new HashSet<Bunsu>(); ModInt ans = 1; foreach (var key in map.Keys) { if (done.Contains(key)) { continue; } var pair = key.Bunshi > 0 ? new Bunsu { Bunshi = -1 * key.Bunbo, Bunbo = key.Bunshi } : new Bunsu { Bunshi = key.Bunbo, Bunbo = -1 * key.Bunshi }; if (map.ContainsKey(pair)) { ans *= (pows[map[pair]] + pows[map[key]] - 1); } else { ans *= pows[map[key]]; } done.Add(key); done.Add(pair); } ans *= (pows[bunshiZero] + pows[bunboZero] - 1); ans -= 1; ans += zerozero; Console.WriteLine(ans.Value); } public static long GCD(long a, long b) { if (b == 0) { return a; } return GCD(b, a % b); } } [DebuggerDisplay("{Bunshi} {Bunbo}")] public struct Bunsu : IEquatable<Bunsu> { public long Bunshi { get; set; } public long Bunbo { get; set; } public bool Equals([AllowNull] Bunsu other) { return Bunshi == other.Bunshi && Bunbo == other.Bunbo; } public override int GetHashCode() { return HashCode.Combine(Bunshi, Bunbo); } } public struct ModInt { public static long P { get; set; } = (long)1e9 + 7; public static ModInt Pow(ModInt value, long k) { return Pow(value.Value, k); } public static ModInt Pow(long value, long k) { long ret = 1; for (k %= P - 1; k > 0; k >>= 1, value = value * value % P) { if ((k & 1) == 1) { ret = ret * value % P; } } return new ModInt(ret); } public static ModInt Inverse(ModInt value) { return Pow(value, P - 2); } public long Value; public ModInt(long value) { value %= P; if (value < 0) { value += P; } Value = value; } public static ModInt operator +(ModInt lhs, ModInt rhs) { lhs.Value += rhs.Value; if (lhs.Value >= P) { lhs.Value -= P; } return lhs; } public static ModInt operator -(ModInt lhs, ModInt rhs) { lhs.Value -= rhs.Value; if (lhs.Value < 0) { lhs.Value += P; } return lhs; } public static ModInt operator *(ModInt lhs, ModInt rhs) { return new ModInt(lhs.Value * rhs.Value % P); } public static ModInt operator /(ModInt lhs, ModInt rhs) { long exp = P - 2; while (exp > 0) { if (exp % 2 > 0) { lhs *= rhs; } rhs *= rhs; exp /= 2; } return lhs; } public static implicit operator ModInt(long n) { n %= P; if (n < 0) { n += P; } return new ModInt(n); } public override string ToString() { return Value.ToString(); } } public class HashMap<TKey, TValue> : Dictionary<TKey, TValue> { private readonly Func<TKey, TValue> initialzier_; public HashMap(Func<TKey, TValue> initialzier) : base() { initialzier_ = initialzier; } public HashMap(Func<TKey, TValue> initialzier, int capacity) : base(capacity) { initialzier_ = initialzier; } new public TValue this[TKey key] { get { if (ContainsKey(key) == false) { base[key] = initialzier_(key); } return base[key]; } set { base[key] = value; } } } public static class Helper { public static void UpdateMin<T>(ref T target, T value) where T : IComparable<T> => target = target.CompareTo(value) > 0 ? value : target; public static void UpdateMin<T>(ref T target, T value, Action<T> onUpdated) where T : IComparable<T> { if (target.CompareTo(value) > 0) { target = value; onUpdated(value); } } public static void UpdateMax<T>(ref T target, T value) where T : IComparable<T> => target = target.CompareTo(value) < 0 ? value : target; public static void UpdateMax<T>(ref T target, T value, Action<T> onUpdated) where T : IComparable<T> { if (target.CompareTo(value) < 0) { target = value; onUpdated(value); } } public static T[] Array<T>(int n, Func<int, T> init) => Enumerable.Range(0, n).Select(x => init(x)).ToArray(); public static List<T> List<T>(int n, Func<int, T> init) => Enumerable.Range(0, n).Select(x => init(x)).ToList(); public static T[,] Array2<T>(int n, int m, T init) { var array = new T[n, m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { array[i, j] = init; } } return array; } public static T[,] Array2<T>(int n, int m, Func<int, int, T> initializer) { var array = new T[n, m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { array[i, j] = initializer(i, j); } } return array; } public static T[,,] Array3<T>(int n1, int n2, int n3, T init) { var array = new T[n1, n2, n3]; for (int i1 = 0; i1 < n1; i1++) { for (int i2 = 0; i2 < n2; i2++) { for (int i3 = 0; i3 < n3; i3++) { array[i1, i2, i3] = init; } } } return array; } private static readonly int[] delta4_ = { 1, 0, -1, 0, 1 }; public static void DoAt4(int i, int j, int imax, int jmax, Action<int, int> action) { for (int n = 0; n < 4; n++) { int ii = i + delta4_[n]; int jj = j + delta4_[n + 1]; if ((uint)ii < (uint)imax && (uint)jj < (uint)jmax) { action(ii, jj); } } } } public class Scanner { private readonly char[] delimiter_ = new char[] { ' ' }; private readonly string filePath_; private readonly Func<string> reader_; private string[] buf_; private int index_; public Scanner(string file = "") { if (string.IsNullOrWhiteSpace(file)) { reader_ = Console.ReadLine; } else { filePath_ = file; var fs = new StreamReader(file); reader_ = fs.ReadLine; } buf_ = new string[0]; index_ = 0; } public string Next() { if (index_ < buf_.Length) { return buf_[index_++]; } string st = reader_(); while (st == "") { st = reader_(); } buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries); if (buf_.Length == 0) { return Next(); } index_ = 0; return buf_[index_++]; } public int Int() => int.Parse(Next()); public long Long() => long.Parse(Next()); public double Double() => double.Parse(Next()); public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = Int() + add; } return Array; } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = Long() + add; } return Array; } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = Double() + add; } return Array; } public void Save(string text) { if (string.IsNullOrWhiteSpace(filePath_)) { return; } File.WriteAllText(filePath_ + "_output.txt", text); } } }
[["-", 0, 57, 75, 196, 0, 1, 0, 11, 12, 203], ["+", 75, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 12, 204, 206, 207, 0, 28, 0, 204, 205, 22], ["+", 206, 207, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 206, 207, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73]]
8
2,349
8
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Threading; using System.Text; using System.Text.RegularExpressions; using System.Diagnostics; using static util; using P = pair<int, int>; class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; var solver = new Solver(sw); // var t = new Thread(solver.solve, 1 << 26); // 64 MB // t.Start(); // t.Join(); solver.solve(); sw.Flush(); } } class Solver { StreamWriter sw; Scan sc; void Prt(string a) => sw.WriteLine(a); void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a)); void Prt(params object[] a) => Prt(string.Join(" ", a)); public Solver(StreamWriter sw) { this.sw = sw; this.sc = new Scan(); } public void solve() { int n = sc.Int; var dic = new SortedDictionary<pair<long, long>, int>(); int c = n; for (int i = 0; i < n; i++) { long a, b; sc.Multi(out a, out b); if (a == 0 && b == 0) { --c; continue; } long g = MyMath.gcd(Math.Abs(a), Math.Abs(b)); a /= g; b /= g; if (a < 0 || a == 0 && b < 0) { a = -a; b = -b; } var p = new pair<long, long>(a, b); if (!dic.ContainsKey(p)) { dic.Add(p, 0); } ++dic[p]; } long ans = MyMath.pow(2, c); foreach (var item in dic) { var p = new pair<long, long>(item.Key.v2, -item.Key.v1); if (p.v1 < 0 || p.v1 == 0 && p.v2 < 0) { p.v1 = -p.v1; p.v2 = -p.v2; } if (item.Key.CompareTo(p) < 0 && dic.ContainsKey(p)) { ans = ans * MyMath.inv(MyMath.pow(2, item.Value + dic[p])) % M * ((MyMath.pow(2, item.Value) + MyMath.pow(2, dic[p]) + M - 1) % M) % M; } } Prt((ans + M - 1) % M); } } class pair<T, U> : IComparable<pair<T, U>> { public T v1; public U v2; public pair() : this(default(T), default(U)) {} public pair(T v1, U v2) { this.v1 = v1; this.v2 = v2; } public int CompareTo(pair<T, U> a) { int c = Comparer<T>.Default.Compare(v1, a.v1); return c != 0 ? c : Comparer<U>.Default.Compare(v2, a.v2); } public override string ToString() => v1 + " " + v2; public void Deconstruct(out T a, out U b) { a = v1; b = v2; } } static class util { public static readonly int M = 1000000007; // public static readonly int M = 998244353; public static readonly long LM = 1L << 60; public static readonly double eps = 1e-11; public static void DBG(string a) => Console.Error.WriteLine(a); public static void DBG<T>(IEnumerable<T> a) => DBG(string.Join(" ", a)); public static void DBG(params object[] a) => DBG(string.Join(" ", a)); public static void Assert(params bool[] conds) { if (conds.Any(x => !x)) throw new Exception(); } public static pair<T, U> make_pair<T, U>(T v1, U v2) => new pair<T, U>(v1, v2); public static int CompareList<T>(IList<T> a, IList<T> b) where T : IComparable<T> { for (int i = 0; i < a.Count && i < b.Count; i++) if (a[i].CompareTo(b[i]) != 0) return a[i].CompareTo(b[i]); return a.Count.CompareTo(b.Count); } public static bool inside(int i, int j, int h, int w) => i >= 0 && i < h && j >= 0 && j < w; static readonly int[] dd = { 0, 1, 0, -1 }; // static readonly string dstring = "RDLU"; public static P[] adjacents(int i, int j) => Enumerable.Range(0, dd.Length) .Select(k => new P(i + dd[k], j + dd[k ^ 1])) .ToArray(); public static P[] adjacents(int i, int j, int h, int w) => Enumerable.Range(0, dd.Length) .Select(k => new P(i + dd[k], j + dd[k ^ 1])) .Where(p => inside(p.v1, p.v2, h, w)) .ToArray(); public static P[] adjacents(this P p) => adjacents(p.v1, p.v2); public static P[] adjacents(this P p, int h, int w) => adjacents(p.v1, p.v2, h, w); public static Dictionary<T, int> compress<T>(this IEnumerable<T> a) => a.Distinct() .OrderBy(v => v) .Select((v, i) => new { v, i }) .ToDictionary(p => p.v, p => p.i); public static Dictionary<T, int> compress<T>(params IEnumerable<T>[] a) => compress(a.Aggregate(Enumerable.Union)); public static T[] inv<T>(this Dictionary<T, int> dic) { var res = new T[dic.Count]; foreach (var item in dic) res[item.Value] = item.Key; return res; } public static void swap<T>(ref T a, ref T b) where T : struct { var t = a; a = b; b = t; } public static void swap<T>(this IList<T> a, int i, int j) where T : struct { var t = a[i]; a[i] = a[j]; a[j] = t; } public static T[] copy<T>(this IList<T> a) { var ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } public static void Deconstruct<T>(this IList<T> v, out T a) { a = v[0]; } public static void Deconstruct<T>(this IList<T> v, out T a, out T b) { a = v[0]; b = v[1]; } public static void Deconstruct<T>(this IList<T> v, out T a, out T b, out T c) { a = v[0]; b = v[1]; c = v[2]; } public static void Deconstruct<T>(this IList<T> v, out T a, out T b, out T c, out T d) { a = v[0]; b = v[1]; c = v[2]; d = v[3]; } public static void Deconstruct<T>(this IList<T> v, out T a, out T b, out T c, out T d, out T e) { a = v[0]; b = v[1]; c = v[2]; d = v[3]; e = v[4]; } } class Scan { StreamReader sr; public Scan() { sr = new StreamReader(Console.OpenStandardInput()); } public Scan(string path) { sr = new StreamReader(path); } public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public string Str => sr.ReadLine().Trim(); public pair<T, U> Pair<T, U>() { T a; U b; Multi(out a, out b); return new pair<T, U>(a, b); } public P P => Pair<int, int>(); public int[] IntArr => StrArr.Select(int.Parse).ToArray(); public long[] LongArr => StrArr.Select(long.Parse).ToArray(); public double[] DoubleArr => StrArr.Select(double.Parse).ToArray(); public string[] StrArr => Str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); bool eq<T, U>() => typeof(T).Equals(typeof(U)); T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); 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); public void Multi<T>(out T a) => a = cv<T>(Str); public void Multi<T, U>(out T a, out U b) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); } public void Multi<T, U, V>(out T a, out U b, out V c) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } } static class MyMath { public static long Mod = util.M; // public static long Mod = 1000000007; public static bool isprime(long a) { if (a < 2) return false; for (long i = 2; i * i <= a; i++) if (a % i == 0) return false; return true; } public static bool[] sieve(int n) { var p = new bool[n + 1]; for (int i = 2; i <= n; i++) p[i] = true; for (int i = 2; i * i <= n; i++) if (p[i]) for (int j = i * i; j <= n; j += i) p[j] = false; return p; } public static int[] sieve2(int n) { var p = new int[n + 1]; for (int i = 2; i <= n; i++) p[i] = i; for (int i = 2; i * i <= n; i++) { if (p[i] == i) for (int j = i * i; j <= n; j += i) p[j] = Math.Min(p[j], i); } return p; } public static bool[] segmentSieve(long l, long r) { int sqn = (int)Math.Sqrt(r + 9); var ps = getprimes(sqn); return segmentSieve(l, r, ps); } public static bool[] segmentSieve(long l, long r, List<int> ps) { var sieve = new bool[r - l + 1]; for (long i = l; i <= r; i++) sieve[i - l] = true; foreach (long p in ps) { if (p * p > r) break; for (long i = p >= l ? p * p : (l + p - 1) / p * p; i <= r; i += p) sieve[i - l] = false; } return sieve; } public static List<int> getprimes(int n) { var prs = new List<int>(); var p = sieve(n); for (int i = 2; i <= n; i++) if (p[i]) prs.Add(i); return prs; } public static long pow(long a, long b, long mod) { a %= mod; if (b < 0) Console.Error.WriteLine($"power number is negative ({a}^{b})."); if (b <= 0) return 1; var t = pow(a, b / 2, mod); if ((b & 1) == 0) return t * t % mod; return t * t % mod * a % mod; } public static long pow(long a, long b) => pow(a, b, Mod); public static long inv(long a) => pow(a, Mod - 2); public static long gcd(long a, long b) { while (b > 0) { var t = a % b; a = b; b = t; } return a; } // a x + b y = gcd(a, b) public static long extgcd(long a, long b, out long x, out long y) { long g = a; x = 1; y = 0; if (b > 0) { g = extgcd(b, a % b, out y, out x); y -= a / b * x; } return g; } // return (r, m): x = r (mod. m) // return (0, -1) if no answer public static pair<long, long> chineserem(IList<long> b, IList<long> m) { long r = 0, M = 1; for (int i = 0; i < b.Count; ++i) { long p, q; long d = extgcd(M, m[i], out p, out q); // p is inv of M/d (mod. m[i]/d) if ((b[i] - r) % d != 0) return new pair<long, long>(0, -1); long tmp = (b[i] - r) / d * p % (m[i] / d); r += M * tmp; M *= m[i] / d; } return new pair<long, long>((r % M + M) % M, M); } // return k: x^k = y (mod. mod) O(sqrt(mod)) public static long modlog(long x, long y, long mod) { if (y == 1) return 0; long H = (long)Math.Sqrt(mod) + 1; var baby = new Dictionary<long, long>(); for (long b = 0, xby = y; b < H; b++, xby = (xby * x) % mod) { if (!baby.ContainsKey(xby)) baby.Add(xby, b); else baby[xby] = b; } long xH = 1; for (int i = 0; i < H; ++i) xH = xH * x % mod; for (long a = 1, xaH = xH; a <= H; a++, xaH = (xaH * xH) % mod) if (baby.ContainsKey(xaH)) return a * H - baby[xaH]; return -1; } public static long lcm(long a, long b) => a / gcd(a, b) * b; static long[] facts, invs; public static void setfacts(int n) { facts = new long[n + 1]; facts[0] = 1; for (int i = 1; i <= n; i++) facts[i] = facts[i - 1] * i % Mod; invs = new long[n + 1]; invs[n] = inv(facts[n]); for (int i = n; i > 0; i--) invs[i - 1] = invs[i] * i % Mod; } public static long fact(long n) { if (n < 0) return 0; if (facts != null && facts.Length > n) return facts[n]; long numer = 1; for (long i = 1; i <= n; i++) numer = numer * (i % Mod) % Mod; return numer; } public static long perm(long n, long r) { if (n < 0 || r < 0 || r > n) return 0; if (facts != null && facts.Length > n) return facts[n] * invs[n - r] % Mod; long numer = 1; for (long i = 0; i < r; i++) numer = numer * ((n - i) % Mod) % Mod; return numer; } public static long comb(long n, long r) { if (n < 0 || r < 0 || r > n) return 0; if (facts != null && facts.Length > n) return facts[n] * invs[r] % Mod * invs[n - r] % Mod; if (n - r < r) r = n - r; long numer = 1, denom = 1; for (long i = 0; i < r; i++) { numer = numer * ((n - i) % Mod) % Mod; denom = denom * ((i + 1) % Mod) % Mod; } return numer * inv(denom) % Mod; } public static long multi_choose(long n, long r) => comb(n + r - 1, r); public static long[][] getcombs(int n) { var ret = new long [n + 1][]; for (int i = 0; i <= n; i++) { ret[i] = new long[i + 1]; ret[i][0] = ret[i][i] = 1; for (int j = 1; j < i; j++) ret[i][j] = (ret[i - 1][j - 1] + ret[i - 1][j]) % Mod; } return ret; } // nC0, nC2, ..., nCn public static long[] getcomb(int n) { var ret = new long[n + 1]; ret[0] = 1; for (int i = 0; i < n; i++) ret[i + 1] = ret[i] * (n - i) % Mod * inv(i + 1) % Mod; return ret; } public static class ModMatrix { public static long[][] E(int n) { var ret = new long [n][]; for (int i = 0; i < n; i++) { ret[i] = new long[n]; ret[i][i] = 1; } return ret; } public static long[][] pow(long[][] A, long n) { if (n == 0) return E(A.Length); var t = pow(A, n / 2); if ((n & 1) == 0) return mul(t, t); return mul(mul(t, t), A); } public static long dot(long[] x, long[] y) { int n = x.Length; long ret = 0; for (int i = 0; i < n; i++) ret = (ret + x[i] * y[i]) % Mod; return ret; } public static long[][] trans(long[][] A) { int n = A[0].Length, m = A.Length; var ret = new long [n][]; for (int i = 0; i < n; i++) { ret[i] = new long[m]; for (int j = 0; j < m; j++) ret[i][j] = A[j][i]; } return ret; } public static long[] mul(long a, long[] x) { int n = x.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = a * x[i] % Mod; return ret; } public static long[] mul(long[][] A, long[] x) { int n = A.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static long[][] mul(long a, long[][] A) { int n = A.Length; var ret = new long [n][]; for (int i = 0; i < n; i++) ret[i] = mul(a, A[i]); return ret; } public static long[][] mul(long[][] A, long[][] B) { int n = A.Length; var Bt = trans(B); var ret = new long [n][]; for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]); return ret; } } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Threading; using System.Text; using System.Text.RegularExpressions; using System.Diagnostics; using static util; using P = pair<int, int>; class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; var solver = new Solver(sw); // var t = new Thread(solver.solve, 1 << 26); // 64 MB // t.Start(); // t.Join(); solver.solve(); sw.Flush(); } } class Solver { StreamWriter sw; Scan sc; void Prt(string a) => sw.WriteLine(a); void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a)); void Prt(params object[] a) => Prt(string.Join(" ", a)); public Solver(StreamWriter sw) { this.sw = sw; this.sc = new Scan(); } public void solve() { int n = sc.Int; var dic = new SortedDictionary<pair<long, long>, int>(); int c = n; int cc = 0; for (int i = 0; i < n; i++) { long a, b; sc.Multi(out a, out b); if (a == 0 && b == 0) { --c; ++cc; continue; } long g = MyMath.gcd(Math.Abs(a), Math.Abs(b)); a /= g; b /= g; if (a < 0 || a == 0 && b < 0) { a = -a; b = -b; } var p = new pair<long, long>(a, b); if (!dic.ContainsKey(p)) { dic.Add(p, 0); } ++dic[p]; } long ans = MyMath.pow(2, c); foreach (var item in dic) { var p = new pair<long, long>(item.Key.v2, -item.Key.v1); if (p.v1 < 0 || p.v1 == 0 && p.v2 < 0) { p.v1 = -p.v1; p.v2 = -p.v2; } if (item.Key.CompareTo(p) < 0 && dic.ContainsKey(p)) { ans = ans * MyMath.inv(MyMath.pow(2, item.Value + dic[p])) % M * ((MyMath.pow(2, item.Value) + MyMath.pow(2, dic[p]) + M - 1) % M) % M; } } Prt((ans + M - 1 + cc) % M); } } class pair<T, U> : IComparable<pair<T, U>> { public T v1; public U v2; public pair() : this(default(T), default(U)) {} public pair(T v1, U v2) { this.v1 = v1; this.v2 = v2; } public int CompareTo(pair<T, U> a) { int c = Comparer<T>.Default.Compare(v1, a.v1); return c != 0 ? c : Comparer<U>.Default.Compare(v2, a.v2); } public override string ToString() => v1 + " " + v2; public void Deconstruct(out T a, out U b) { a = v1; b = v2; } } static class util { public static readonly int M = 1000000007; // public static readonly int M = 998244353; public static readonly long LM = 1L << 60; public static readonly double eps = 1e-11; public static void DBG(string a) => Console.Error.WriteLine(a); public static void DBG<T>(IEnumerable<T> a) => DBG(string.Join(" ", a)); public static void DBG(params object[] a) => DBG(string.Join(" ", a)); public static void Assert(params bool[] conds) { if (conds.Any(x => !x)) throw new Exception(); } public static pair<T, U> make_pair<T, U>(T v1, U v2) => new pair<T, U>(v1, v2); public static int CompareList<T>(IList<T> a, IList<T> b) where T : IComparable<T> { for (int i = 0; i < a.Count && i < b.Count; i++) if (a[i].CompareTo(b[i]) != 0) return a[i].CompareTo(b[i]); return a.Count.CompareTo(b.Count); } public static bool inside(int i, int j, int h, int w) => i >= 0 && i < h && j >= 0 && j < w; static readonly int[] dd = { 0, 1, 0, -1 }; // static readonly string dstring = "RDLU"; public static P[] adjacents(int i, int j) => Enumerable.Range(0, dd.Length) .Select(k => new P(i + dd[k], j + dd[k ^ 1])) .ToArray(); public static P[] adjacents(int i, int j, int h, int w) => Enumerable.Range(0, dd.Length) .Select(k => new P(i + dd[k], j + dd[k ^ 1])) .Where(p => inside(p.v1, p.v2, h, w)) .ToArray(); public static P[] adjacents(this P p) => adjacents(p.v1, p.v2); public static P[] adjacents(this P p, int h, int w) => adjacents(p.v1, p.v2, h, w); public static Dictionary<T, int> compress<T>(this IEnumerable<T> a) => a.Distinct() .OrderBy(v => v) .Select((v, i) => new { v, i }) .ToDictionary(p => p.v, p => p.i); public static Dictionary<T, int> compress<T>(params IEnumerable<T>[] a) => compress(a.Aggregate(Enumerable.Union)); public static T[] inv<T>(this Dictionary<T, int> dic) { var res = new T[dic.Count]; foreach (var item in dic) res[item.Value] = item.Key; return res; } public static void swap<T>(ref T a, ref T b) where T : struct { var t = a; a = b; b = t; } public static void swap<T>(this IList<T> a, int i, int j) where T : struct { var t = a[i]; a[i] = a[j]; a[j] = t; } public static T[] copy<T>(this IList<T> a) { var ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } public static void Deconstruct<T>(this IList<T> v, out T a) { a = v[0]; } public static void Deconstruct<T>(this IList<T> v, out T a, out T b) { a = v[0]; b = v[1]; } public static void Deconstruct<T>(this IList<T> v, out T a, out T b, out T c) { a = v[0]; b = v[1]; c = v[2]; } public static void Deconstruct<T>(this IList<T> v, out T a, out T b, out T c, out T d) { a = v[0]; b = v[1]; c = v[2]; d = v[3]; } public static void Deconstruct<T>(this IList<T> v, out T a, out T b, out T c, out T d, out T e) { a = v[0]; b = v[1]; c = v[2]; d = v[3]; e = v[4]; } } class Scan { StreamReader sr; public Scan() { sr = new StreamReader(Console.OpenStandardInput()); } public Scan(string path) { sr = new StreamReader(path); } public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public string Str => sr.ReadLine().Trim(); public pair<T, U> Pair<T, U>() { T a; U b; Multi(out a, out b); return new pair<T, U>(a, b); } public P P => Pair<int, int>(); public int[] IntArr => StrArr.Select(int.Parse).ToArray(); public long[] LongArr => StrArr.Select(long.Parse).ToArray(); public double[] DoubleArr => StrArr.Select(double.Parse).ToArray(); public string[] StrArr => Str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); bool eq<T, U>() => typeof(T).Equals(typeof(U)); T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); 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); public void Multi<T>(out T a) => a = cv<T>(Str); public void Multi<T, U>(out T a, out U b) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); } public void Multi<T, U, V>(out T a, out U b, out V c) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } } static class MyMath { public static long Mod = util.M; // public static long Mod = 1000000007; public static bool isprime(long a) { if (a < 2) return false; for (long i = 2; i * i <= a; i++) if (a % i == 0) return false; return true; } public static bool[] sieve(int n) { var p = new bool[n + 1]; for (int i = 2; i <= n; i++) p[i] = true; for (int i = 2; i * i <= n; i++) if (p[i]) for (int j = i * i; j <= n; j += i) p[j] = false; return p; } public static int[] sieve2(int n) { var p = new int[n + 1]; for (int i = 2; i <= n; i++) p[i] = i; for (int i = 2; i * i <= n; i++) { if (p[i] == i) for (int j = i * i; j <= n; j += i) p[j] = Math.Min(p[j], i); } return p; } public static bool[] segmentSieve(long l, long r) { int sqn = (int)Math.Sqrt(r + 9); var ps = getprimes(sqn); return segmentSieve(l, r, ps); } public static bool[] segmentSieve(long l, long r, List<int> ps) { var sieve = new bool[r - l + 1]; for (long i = l; i <= r; i++) sieve[i - l] = true; foreach (long p in ps) { if (p * p > r) break; for (long i = p >= l ? p * p : (l + p - 1) / p * p; i <= r; i += p) sieve[i - l] = false; } return sieve; } public static List<int> getprimes(int n) { var prs = new List<int>(); var p = sieve(n); for (int i = 2; i <= n; i++) if (p[i]) prs.Add(i); return prs; } public static long pow(long a, long b, long mod) { a %= mod; if (b < 0) Console.Error.WriteLine($"power number is negative ({a}^{b})."); if (b <= 0) return 1; var t = pow(a, b / 2, mod); if ((b & 1) == 0) return t * t % mod; return t * t % mod * a % mod; } public static long pow(long a, long b) => pow(a, b, Mod); public static long inv(long a) => pow(a, Mod - 2); public static long gcd(long a, long b) { while (b > 0) { var t = a % b; a = b; b = t; } return a; } // a x + b y = gcd(a, b) public static long extgcd(long a, long b, out long x, out long y) { long g = a; x = 1; y = 0; if (b > 0) { g = extgcd(b, a % b, out y, out x); y -= a / b * x; } return g; } // return (r, m): x = r (mod. m) // return (0, -1) if no answer public static pair<long, long> chineserem(IList<long> b, IList<long> m) { long r = 0, M = 1; for (int i = 0; i < b.Count; ++i) { long p, q; long d = extgcd(M, m[i], out p, out q); // p is inv of M/d (mod. m[i]/d) if ((b[i] - r) % d != 0) return new pair<long, long>(0, -1); long tmp = (b[i] - r) / d * p % (m[i] / d); r += M * tmp; M *= m[i] / d; } return new pair<long, long>((r % M + M) % M, M); } // return k: x^k = y (mod. mod) O(sqrt(mod)) public static long modlog(long x, long y, long mod) { if (y == 1) return 0; long H = (long)Math.Sqrt(mod) + 1; var baby = new Dictionary<long, long>(); for (long b = 0, xby = y; b < H; b++, xby = (xby * x) % mod) { if (!baby.ContainsKey(xby)) baby.Add(xby, b); else baby[xby] = b; } long xH = 1; for (int i = 0; i < H; ++i) xH = xH * x % mod; for (long a = 1, xaH = xH; a <= H; a++, xaH = (xaH * xH) % mod) if (baby.ContainsKey(xaH)) return a * H - baby[xaH]; return -1; } public static long lcm(long a, long b) => a / gcd(a, b) * b; static long[] facts, invs; public static void setfacts(int n) { facts = new long[n + 1]; facts[0] = 1; for (int i = 1; i <= n; i++) facts[i] = facts[i - 1] * i % Mod; invs = new long[n + 1]; invs[n] = inv(facts[n]); for (int i = n; i > 0; i--) invs[i - 1] = invs[i] * i % Mod; } public static long fact(long n) { if (n < 0) return 0; if (facts != null && facts.Length > n) return facts[n]; long numer = 1; for (long i = 1; i <= n; i++) numer = numer * (i % Mod) % Mod; return numer; } public static long perm(long n, long r) { if (n < 0 || r < 0 || r > n) return 0; if (facts != null && facts.Length > n) return facts[n] * invs[n - r] % Mod; long numer = 1; for (long i = 0; i < r; i++) numer = numer * ((n - i) % Mod) % Mod; return numer; } public static long comb(long n, long r) { if (n < 0 || r < 0 || r > n) return 0; if (facts != null && facts.Length > n) return facts[n] * invs[r] % Mod * invs[n - r] % Mod; if (n - r < r) r = n - r; long numer = 1, denom = 1; for (long i = 0; i < r; i++) { numer = numer * ((n - i) % Mod) % Mod; denom = denom * ((i + 1) % Mod) % Mod; } return numer * inv(denom) % Mod; } public static long multi_choose(long n, long r) => comb(n + r - 1, r); public static long[][] getcombs(int n) { var ret = new long [n + 1][]; for (int i = 0; i <= n; i++) { ret[i] = new long[i + 1]; ret[i][0] = ret[i][i] = 1; for (int j = 1; j < i; j++) ret[i][j] = (ret[i - 1][j - 1] + ret[i - 1][j]) % Mod; } return ret; } // nC0, nC2, ..., nCn public static long[] getcomb(int n) { var ret = new long[n + 1]; ret[0] = 1; for (int i = 0; i < n; i++) ret[i + 1] = ret[i] * (n - i) % Mod * inv(i + 1) % Mod; return ret; } public static class ModMatrix { public static long[][] E(int n) { var ret = new long [n][]; for (int i = 0; i < n; i++) { ret[i] = new long[n]; ret[i][i] = 1; } return ret; } public static long[][] pow(long[][] A, long n) { if (n == 0) return E(A.Length); var t = pow(A, n / 2); if ((n & 1) == 0) return mul(t, t); return mul(mul(t, t), A); } public static long dot(long[] x, long[] y) { int n = x.Length; long ret = 0; for (int i = 0; i < n; i++) ret = (ret + x[i] * y[i]) % Mod; return ret; } public static long[][] trans(long[][] A) { int n = A[0].Length, m = A.Length; var ret = new long [n][]; for (int i = 0; i < n; i++) { ret[i] = new long[m]; for (int j = 0; j < m; j++) ret[i][j] = A[j][i]; } return ret; } public static long[] mul(long a, long[] x) { int n = x.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = a * x[i] % Mod; return ret; } public static long[] mul(long[][] A, long[] x) { int n = A.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static long[][] mul(long a, long[][] A) { int n = A.Length; var ret = new long [n][]; for (int i = 0; i < n; i++) ret[i] = mul(a, A[i]); return ret; } public static long[][] mul(long[][] A, long[][] B) { int n = A.Length; var Bt = trans(B); var ret = new long [n][]; for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]); return ret; } } }
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 1, 0, 241, 0, 29], ["+", 0, 57, 64, 196, 0, 1, 0, 241, 0, 22], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 12, 22]]
8
4,910
10
using System; using System.Linq; using System.Collections.Generic; namespace AtCoder.Contests.ABC168 { /// <summary> /// /// </summary> static class E { static void Main(string[] args) { var n = NextInt(); var counts = new CountDic<Tuple<int, long, long>>(); var zeros = 0; for (int i = 0; i < n; i++) { var a = NextLong(); var b = NextLong(); if (a == 0 && b == 0) { zeros++; continue; } if (a == 0 || b == 0) { var aoverb = new Tuple<int, long, long>(0, a == 0 ? 0 : 1, b == 0 ? 0 : 1); continue; } var asign = a >= 0 ? 1 : -1; var bsign = b >= 0 ? 1 : -1; a *= asign; b *= bsign; var gcd = GCD.Solve(a, b); a = a / gcd; b = b / gcd; var aoberb = new Tuple<int, long, long>(asign * bsign, a, b); counts.CountUp(aoberb); } mint result = 1; var hash = new HashSet<Tuple<int, long, long>>(); foreach (var kv in counts) { var key = kv.Key; var v = kv.Value; var bovera = new Tuple<int, long, long>(-key.Item1, key.Item3, key.Item2); if (key.Item2 == 0 || key.Item3 == 0) { bovera = new Tuple<int, long, long>(0, key.Item2 == 0 ? 1 : 0, key.Item3 == 0 ? 1 : 0); } if (hash.Contains(bovera)) { continue; } if (hash.Contains(key)) { continue; } var opponents = counts[bovera]; result *= 1 + (mint.Pow(2, v) - 1) + (mint.Pow(2, opponents) - 1); hash.Add(key); hash.Add(bovera); } result += zeros; Console.WriteLine(result - 1); } struct mint : IEquatable<mint> { // static uint mod = 998244353; public static uint mod = 1000000007; uint _v; public mint(long v) : this((uint)(v % mod + mod)) {} private mint(uint v) { _v = v < mod ? v : (v - mod); } public static void SetMod(uint p) { mod = p; } public static mint operator +(mint lhs, mint rhs) { return new mint(lhs._v + rhs._v); } public static mint operator -(mint lhs, mint rhs) { return new mint(lhs._v + mod - rhs._v); } public static mint operator *(mint lhs, mint rhs) { return new mint((uint)((ulong)lhs._v * rhs._v % mod)); } public static mint operator /(mint lhs, mint rhs) { return lhs * rhs.Inv(); } public static mint operator ^(mint x, int n) { return Pow(x, n); } public static bool operator ==(mint l, mint r) { return l._v == r._v; } public static bool operator !=(mint l, mint r) { return !(l == r); } public static bool operator<(mint l, mint r) { return l._v < r._v; } public static bool operator>(mint l, mint r) { return l._v > r._v; } public static mint Pow(mint x, int n) { var r = new mint(1); while (n > 0) { if ((n & 1) > 0) r *= x; x *= x; n >>= 1; } return r; } public mint Pow(int n) { return Pow(this, n); } public mint Inv() { return Pow((int)mod - 2); } public bool Equals(mint o) { return this == o; } public override bool Equals(object obj) { if (obj is mint) return this == (mint)obj; else return false; } public override int GetHashCode() { return _v.GetHashCode(); } public override string ToString() { return _v.ToString(); } public static implicit operator mint(int i) { return new mint(i); } public static implicit operator mint(long i) { return new mint(i); } private static mint[] _fact; public static void SetFact(int n) { _fact = new mint[n + 1]; _fact[0] = 1; for (int i = 1; i < n + 1; i++) { _fact[i] = _fact[i - 1] * i; } } public static mint Fact(int n) { if (_fact == null || _fact.Length <= n) { SetFact(n * 2); } return _fact[n]; } public static mint Combination(int n, int r) { return Fact(n) / (Fact(n - r) * Fact(r)); } } #region Console static int _index = 0; static string[] _buffer; static string Next() { if (_buffer == null || _index >= _buffer.Length) { _buffer = Console.ReadLine().Split(); _index = 0; } return _buffer[_index++]; } static int NextInt() { return int.Parse(Next()); } static long NextLong() { return long.Parse(Next()); } static int ReadInt() { return int.Parse(Console.ReadLine()); } static long ReadLong() { return long.Parse(Console.ReadLine()); } static int[] ReadIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } static int[] ReadIntArray(int n) { var a = new int[n]; for (int i = 0; i < n; i++) { a[i] = ReadInt(); } return a; } static long[] ReadLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } static long[] ReadLongArray(int n) { var a = new long[n]; for (int i = 0; i < n; i++) { a[i] = ReadLong(); } return a; } static List<T> ReadObjects<T>(int n, Func<int[], T> creator) { var l = new List<T>(n); for (int i = 0; i < n; i++) { var a = ReadIntArray(); l.Add(creator(a)); } return l; } static int[,] ReadMatrix(int n, int m) { var r = new int[n, m]; for (int i = 0; i < n; i++) { var a = ReadIntArray(); for (int j = 0; j < m; j++) { r[i, j] = a[j]; } } return r; } #endregion } class CountDic<T> : IDictionary<T, int> { private Dictionary<T, int> _dic = new Dictionary<T, int>(); public int this[T key] { get { return Get(key); } set { _dic[key] = value; } } public ICollection<T> Keys { get { return _dic.Keys; } } public ICollection<int> Values { get { return _dic.Values; } } public int Count { get { return _dic.Count; } } public bool IsReadOnly { get { return false; } } public void Add(T key, int value) { _dic.Add(key, value); } public void Add(KeyValuePair<T, int> item) { throw new NotImplementedException(); } public void Clear() { _dic = new Dictionary<T, int>(); } public bool Contains(KeyValuePair<T, int> item) { return _dic.Contains(item); } public bool ContainsKey(T key) { return _dic.ContainsKey(key); } public void CopyTo(KeyValuePair<T, int>[] array, int arrayIndex) { throw new NotImplementedException(); } public IEnumerator<KeyValuePair<T, int>> GetEnumerator() { return _dic.GetEnumerator(); } public bool Remove(T key) { return _dic.Remove(key); } public bool Remove(KeyValuePair<T, int> item) { return _dic.Remove(item.Key); } public bool TryGetValue(T key, out int value) { value = Get(key); return true; } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return _dic.GetEnumerator(); } private int Get(T key) { int c; if (_dic.TryGetValue(key, out c)) { return c; } else { return 0; } } public int CountUp(T key) { var c = Get(key) + 1; _dic[key] = c; return c; } } class GCD { public static int Solve(int x, int y) { var a = Math.Max(x, y); var b = x + y - a; while (b != 0) { var c = b; b = a % b; a = c; } return a; } public static long Solve(long x, long y) { var a = Math.Max(x, y); var b = x + y - a; while (b != 0) { var c = b; b = a % b; a = c; } return a; } } }
using System; using System.Linq; using System.Collections.Generic; namespace AtCoder.Contests.ABC168 { /// <summary> /// /// </summary> static class E { static void Main(string[] args) { var n = NextInt(); var counts = new CountDic<Tuple<int, long, long>>(); var zeros = 0; for (int i = 0; i < n; i++) { var a = NextLong(); var b = NextLong(); if (a == 0 && b == 0) { zeros++; continue; } if (a == 0 || b == 0) { var aoverb = new Tuple<int, long, long>(0, a == 0 ? 0 : 1, b == 0 ? 0 : 1); counts.CountUp(aoverb); continue; } var asign = a >= 0 ? 1 : -1; var bsign = b >= 0 ? 1 : -1; a *= asign; b *= bsign; var gcd = GCD.Solve(a, b); a = a / gcd; b = b / gcd; var aoberb = new Tuple<int, long, long>(asign * bsign, a, b); counts.CountUp(aoberb); } mint result = 1; var hash = new HashSet<Tuple<int, long, long>>(); foreach (var kv in counts) { var key = kv.Key; var v = kv.Value; var bovera = new Tuple<int, long, long>(-key.Item1, key.Item3, key.Item2); if (key.Item2 == 0 || key.Item3 == 0) { bovera = new Tuple<int, long, long>(0, key.Item2 == 0 ? 1 : 0, key.Item3 == 0 ? 1 : 0); } if (hash.Contains(bovera)) { continue; } if (hash.Contains(key)) { continue; } var opponents = counts[bovera]; result *= 1 + (mint.Pow(2, v) - 1) + (mint.Pow(2, opponents) - 1); hash.Add(key); hash.Add(bovera); } result += zeros; Console.WriteLine(result - 1); } struct mint : IEquatable<mint> { // static uint mod = 998244353; public static uint mod = 1000000007; uint _v; public mint(long v) : this((uint)(v % mod + mod)) {} private mint(uint v) { _v = v < mod ? v : (v - mod); } public static void SetMod(uint p) { mod = p; } public static mint operator +(mint lhs, mint rhs) { return new mint(lhs._v + rhs._v); } public static mint operator -(mint lhs, mint rhs) { return new mint(lhs._v + mod - rhs._v); } public static mint operator *(mint lhs, mint rhs) { return new mint((uint)((ulong)lhs._v * rhs._v % mod)); } public static mint operator /(mint lhs, mint rhs) { return lhs * rhs.Inv(); } public static mint operator ^(mint x, int n) { return Pow(x, n); } public static bool operator ==(mint l, mint r) { return l._v == r._v; } public static bool operator !=(mint l, mint r) { return !(l == r); } public static bool operator<(mint l, mint r) { return l._v < r._v; } public static bool operator>(mint l, mint r) { return l._v > r._v; } public static mint Pow(mint x, int n) { var r = new mint(1); while (n > 0) { if ((n & 1) > 0) r *= x; x *= x; n >>= 1; } return r; } public mint Pow(int n) { return Pow(this, n); } public mint Inv() { return Pow((int)mod - 2); } public bool Equals(mint o) { return this == o; } public override bool Equals(object obj) { if (obj is mint) return this == (mint)obj; else return false; } public override int GetHashCode() { return _v.GetHashCode(); } public override string ToString() { return _v.ToString(); } public static implicit operator mint(int i) { return new mint(i); } public static implicit operator mint(long i) { return new mint(i); } private static mint[] _fact; public static void SetFact(int n) { _fact = new mint[n + 1]; _fact[0] = 1; for (int i = 1; i < n + 1; i++) { _fact[i] = _fact[i - 1] * i; } } public static mint Fact(int n) { if (_fact == null || _fact.Length <= n) { SetFact(n * 2); } return _fact[n]; } public static mint Combination(int n, int r) { return Fact(n) / (Fact(n - r) * Fact(r)); } } #region Console static int _index = 0; static string[] _buffer; static string Next() { if (_buffer == null || _index >= _buffer.Length) { _buffer = Console.ReadLine().Split(); _index = 0; } return _buffer[_index++]; } static int NextInt() { return int.Parse(Next()); } static long NextLong() { return long.Parse(Next()); } static int ReadInt() { return int.Parse(Console.ReadLine()); } static long ReadLong() { return long.Parse(Console.ReadLine()); } static int[] ReadIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } static int[] ReadIntArray(int n) { var a = new int[n]; for (int i = 0; i < n; i++) { a[i] = ReadInt(); } return a; } static long[] ReadLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } static long[] ReadLongArray(int n) { var a = new long[n]; for (int i = 0; i < n; i++) { a[i] = ReadLong(); } return a; } static List<T> ReadObjects<T>(int n, Func<int[], T> creator) { var l = new List<T>(n); for (int i = 0; i < n; i++) { var a = ReadIntArray(); l.Add(creator(a)); } return l; } static int[,] ReadMatrix(int n, int m) { var r = new int[n, m]; for (int i = 0; i < n; i++) { var a = ReadIntArray(); for (int j = 0; j < m; j++) { r[i, j] = a[j]; } } return r; } #endregion } class CountDic<T> : IDictionary<T, int> { private Dictionary<T, int> _dic = new Dictionary<T, int>(); public int this[T key] { get { return Get(key); } set { _dic[key] = value; } } public ICollection<T> Keys { get { return _dic.Keys; } } public ICollection<int> Values { get { return _dic.Values; } } public int Count { get { return _dic.Count; } } public bool IsReadOnly { get { return false; } } public void Add(T key, int value) { _dic.Add(key, value); } public void Add(KeyValuePair<T, int> item) { throw new NotImplementedException(); } public void Clear() { _dic = new Dictionary<T, int>(); } public bool Contains(KeyValuePair<T, int> item) { return _dic.Contains(item); } public bool ContainsKey(T key) { return _dic.ContainsKey(key); } public void CopyTo(KeyValuePair<T, int>[] array, int arrayIndex) { throw new NotImplementedException(); } public IEnumerator<KeyValuePair<T, int>> GetEnumerator() { return _dic.GetEnumerator(); } public bool Remove(T key) { return _dic.Remove(key); } public bool Remove(KeyValuePair<T, int> item) { return _dic.Remove(item.Key); } public bool TryGetValue(T key, out int value) { value = Get(key); return true; } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return _dic.GetEnumerator(); } private int Get(T key) { int c; if (_dic.TryGetValue(key, out c)) { return c; } else { return 0; } } public int CountUp(T key) { var c = Get(key) + 1; _dic[key] = c; return c; } } class GCD { public static int Solve(int x, int y) { var a = Math.Max(x, y); var b = x + y - a; while (b != 0) { var c = b; b = a % b; a = c; } return a; } public static long Solve(long x, long y) { var a = Math.Max(x, y); var b = x + y - a; while (b != 0) { var c = b; b = a % b; a = c; } return a; } } }
[["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
8
2,094
7
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; using static System.Math; namespace AtTest.ABC_168 { class E { static void Main(string[] args) { var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false }; SetOut(sw); Method(args); Out.Flush(); } static void Method(string[] args) { int n = ReadInt(); var pairs = new Dictionary<long, Dictionary<long, int>>(); for (int i = 0; i < n; i++) { long[] ab = ReadLongs(); long a = ab[0]; long b = ab[1]; if (Abs(a) > 0 && Abs(b) > 0) { long gcd = GCD(Abs(a), Abs(b)); a /= gcd; b /= gcd; } else { if (a == 0) { b = 1; } if (b == 0) { a = 1; } } if (a < 0) { a *= -1; b *= -1; } if (!pairs.ContainsKey(a)) { pairs.Add(a, new Dictionary<long, int>()); } if (!pairs[a].ContainsKey(b)) { pairs[a].Add(b, 0); } pairs[a][b]++; } long mask = 1000000000 + 7; long[] pow2s = new long[n + 5]; pow2s[0] = 1; for (int i = 1; i < n + 5; i++) { pow2s[i] = pow2s[i - 1] * 2; pow2s[i] %= mask; } long res = 0; if (pairs.ContainsKey(0) && pairs[0].ContainsKey(0)) { res += pairs[0][0]; } long others = 1; var used = new Dictionary<long, HashSet<long>>(); foreach (long a in pairs.Keys) { foreach (long b in pairs[a].Keys) { if (used.ContainsKey(a) && used[a].Contains(b)) { continue; } if (pairs.ContainsKey(-b) && pairs[-b].ContainsKey(a)) { others *= (pow2s[pairs[a][b]] + pow2s[pairs[-b][a]] - 1 + mask) % mask; if (!used.ContainsKey(a)) { used.Add(a, new HashSet<long>()); } used[a].Add(b); if (!used.ContainsKey(-b)) { used.Add(-b, new HashSet<long>()); } used[-b].Add(a); } else if (pairs.ContainsKey(b) && pairs[b].ContainsKey(-a)) { others *= (pow2s[pairs[a][b]] + pow2s[pairs[b][-a]] - 1 + mask) % mask; if (!used.ContainsKey(a)) { used.Add(a, new HashSet<long>()); } used[a].Add(b); if (!used.ContainsKey(b)) { used.Add(b, new HashSet<long>()); } used[b].Add(-a); } else { others *= pow2s[pairs[a][b]]; } others %= mask; } } others = (others - 1 + mask) % mask; res += others; res %= mask; WriteLine(res); } static long GCD(long a, long b) { if (b > a) { long temp = b; b = a; a = temp; } long c = b; do { c = a % b; a = b; b = c; } while (c > 0); return a; } static long LCM(long a, long b) { long c = GCD(a, b); return a * b / c; } private static string Read() { return ReadLine(); } private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); } 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); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; using static System.Math; namespace AtTest.ABC_168 { class E { static void Main(string[] args) { var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false }; SetOut(sw); Method(args); Out.Flush(); } static void Method(string[] args) { int n = ReadInt(); var pairs = new Dictionary<long, Dictionary<long, int>>(); for (int i = 0; i < n; i++) { long[] ab = ReadLongs(); long a = ab[0]; long b = ab[1]; if (Abs(a) > 0 && Abs(b) > 0) { long gcd = GCD(Abs(a), Abs(b)); a /= gcd; b /= gcd; } else { if (a == 0 && Abs(b) > 0) { b = 1; } if (b == 0 && Abs(a) > 0) { a = 1; } } if (a < 0) { a *= -1; b *= -1; } if (!pairs.ContainsKey(a)) { pairs.Add(a, new Dictionary<long, int>()); } if (!pairs[a].ContainsKey(b)) { pairs[a].Add(b, 0); } pairs[a][b]++; } long mask = 1000000000 + 7; long[] pow2s = new long[n + 5]; pow2s[0] = 1; for (int i = 1; i < n + 5; i++) { pow2s[i] = pow2s[i - 1] * 2; pow2s[i] %= mask; } long res = 0; if (pairs.ContainsKey(0) && pairs[0].ContainsKey(0)) { res += pairs[0][0]; } long others = 1; var used = new Dictionary<long, HashSet<long>>(); used.Add(0, new HashSet<long>()); used[0].Add(0); foreach (long a in pairs.Keys) { foreach (long b in pairs[a].Keys) { if (used.ContainsKey(a) && used[a].Contains(b)) { continue; } if (pairs.ContainsKey(-b) && pairs[-b].ContainsKey(a)) { others *= (pow2s[pairs[a][b]] + pow2s[pairs[-b][a]] - 1 + mask) % mask; if (!used.ContainsKey(a)) { used.Add(a, new HashSet<long>()); } used[a].Add(b); if (!used.ContainsKey(-b)) { used.Add(-b, new HashSet<long>()); } used[-b].Add(a); } else if (pairs.ContainsKey(b) && pairs[b].ContainsKey(-a)) { others *= (pow2s[pairs[a][b]] + pow2s[pairs[b][-a]] - 1 + mask) % mask; if (!used.ContainsKey(a)) { used.Add(a, new HashSet<long>()); } used[a].Add(b); if (!used.ContainsKey(b)) { used.Add(b, new HashSet<long>()); } used[b].Add(-a); } else { others *= pow2s[pairs[a][b]]; } others %= mask; } } others = (others - 1 + mask) % mask; res += others; res %= mask; WriteLine(res); } static long GCD(long a, long b) { if (b > a) { long temp = b; b = a; a = temp; } long c = b; do { c = a % b; a = b; b = c; } while (c > 0); return a; } static long LCM(long a, long b) { long c = GCD(a, b); return a * b / c; } private static string Read() { return ReadLine(); } private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); } 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); } } }
[["+", 0, 57, 75, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 31, 213, 63, 22], ["+", 15, 16, 12, 16, 31, 213, 3, 4, 0, 24], ["+", 12, 16, 31, 213, 3, 4, 0, 28, 0, 22], ["+", 75, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["+", 75, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 25], ["+", 15, 16, 12, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 200, 0, 212, 0, 230, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["+", 0, 213, 3, 4, 0, 28, 0, 230, 0, 228], ["+", 3, 4, 0, 28, 0, 230, 39, 236, 141, 22], ["+", 0, 28, 0, 230, 39, 236, 237, 238, 0, 18], ["+", 0, 28, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 28, 0, 230, 39, 236, 237, 238, 0, 47], ["+", 3, 4, 0, 28, 0, 230, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 230, 3, 4, 0, 25], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 0, 1, 0, 213, 63, 214, 205, 204, 205, 22], ["+", 0, 213, 63, 214, 205, 204, 206, 207, 0, 70], ["+", 63, 214, 205, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 213, 63, 214, 205, 204, 206, 207, 0, 73]]
8
1,074
39
using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace V { partial class Solver { public void Solve() { Write(SolveLong()); // YesNo(SolveBool()); } public long SolveLong() { var n = Read; var pairs = sc.Pairs(n); // n = 200000; // pairs = Enumerable.Range(0, 200000).Select(x => new Pair((1L << 60) * (x // % 3 - 1), (1L << 60) * (x % 3 - 2))).ToArray(); var fish = pairs .Select(x => { if (x.X == 0 && x.Y == 0) return new Fish(); var a = x.X; var b = x.Y; var gn = a > 0 && b >= 0 ? 1 : a <= 0 && b > 0 ? 2 : a < 0 && b <= 0 ? 3 : 4; long ga = 0L; long gb = 0L; switch (gn) { case 1: ga = a; gb = b; break; case 2: ga = b; gb = -a; break; case 3: ga = -a; gb = -b; break; case 4: ga = -b; gb = a; break; } var gcd = ga == 0 || gb == 0 ? 1 : C.Gcd(ga, gb); return new Fish() { a = a, b = b, ga = ga / gcd, gb = gb / gcd, gn = gn, }; }) .GroupBy(x => new { x.ga, x.gb }); var res = new Mint(1); var resZero = new Mint(); foreach (var g in fish) { if (g.Key.ga == 0 && g.Key.gb == 0) { resZero += g.Count(); continue; } var fg = g.GroupBy(x => x.gn % 2).Select(x => Mint.Pow(2, x.Count()) - 1); var c = new Mint(1); foreach (var fgc in fg) c += fgc; res *= c; } res -= 1; res += resZero; return res.Value; } public class Fish { public long a; public long b; public long ga; public long gb; public long gn; } public bool SolveBool() { var n = Read; return false; } } } namespace V { class StartingPoint { static void Main(string[] args) { try { var streamReader = args.Any() ? new StreamReader(args[0]) : new StreamReader(Console.OpenStandardInput()); var streamWriter = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; var scanner = new Scanner(streamReader); var printer = new Printer(streamWriter); var solver = new Solver(scanner, printer); solver.Solve(); streamWriter.Flush(); } catch (Exception e) { Console.WriteLine(e); if (args.Any() == false) throw e; } if (args.Any()) Console.ReadKey(); } } } namespace V { partial class Solver { public Solver(Scanner sc, Printer pr) { this.sc = sc; this.pr = pr; } private readonly Scanner sc; private readonly Printer pr; private IEnumerable<int> Loop(int n) => C.Loop(n); private IEnumerable<long> Loop(long n) => C.Loop(n); private int RdInt => sc.Int; private int ReadInt => sc.Int; private long Rd => sc.Long; private long Read => sc.Long; private long ReadLong => sc.Long; private double RdDouble => sc.Double; private double ReadDouble => sc.Double; private string Str => sc.Str; private string RdStr => sc.Str; private string ReadStr => sc.Str; private int[] ArrInt(int n) => sc.Ints(n); private int[] ArrInt(long n) => sc.Ints(n); private long[] Arr(int n) => sc.Longs(n); private long[] Arr(long n) => sc.Longs(n); private long[] ArrLong(int n) => sc.Longs(n); private long[] ArrLong(long n) => sc.Longs(n); private double[] ArrDouble(int n) => sc.Doubles(n); private double[] ArrDouble(long n) => sc.Doubles(n); private string[] ArrStr(int n) => sc.Strs(n); private string[] ArrStr(long n) => sc.Strs(n); private void Wr(string s) => pr.Write(s); private void Wr(object obj) => pr.Write(obj); private void Wr<T>(IEnumerable<T> ts) => pr.Write(ts); private void Wr(params object[] objs) => pr.Write(objs); private void Write(string s) => pr.Write(s); private void Write(object obj) => pr.Write(obj); private void Write<T>(IEnumerable<T> ts) => pr.Write(ts); private void Write(params object[] objs) => pr.Write(objs); private void YesNo(bool b) => Write(b ? "Yes" : "No"); private void YESNO(bool b) => Write(b ? "YES" : "NO"); } class Scanner { private readonly TextReader reader; public Scanner(TextReader reader) { this.reader = reader; } private Queue<string> strQueue = new Queue<string>(); public string Str { get { if (strQueue.Count > 0) return strQueue.Dequeue(); string[] strs = null; do { strs = reader.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); } while (strs.Any() == false); foreach (var s in strs.Skip(1)) strQueue.Enqueue(s); return strs[0]; } } public int Int => int.Parse(this.Str); public long Long => long.Parse(this.Str); public double Double => double.Parse(this.Str); public static bool TypeEquals<T1, T2>() => typeof(T1).Equals(typeof(T2)); public static T1 ChangeTypes<T1, T2>(T2 t2) => (T1)System.Convert.ChangeType(t2, typeof(T1)); public static T1 Convert<T1>(string s) => TypeEquals<T1, int>() ? ChangeTypes<T1, int>(int.Parse(s)) : TypeEquals<T1, long>() ? ChangeTypes<T1, long>(long.Parse(s)) : TypeEquals<T1, double>() ? ChangeTypes<T1, double>(int.Parse(s)) : TypeEquals<T1, char>() ? ChangeTypes<T1, char>(s[0]) : ChangeTypes<T1, string>(s); public Pair<TX, TY> P2<TX, TY>() => new Pair<TX, TY>(Convert<TX>(this.Str), Convert<TY>(this.Str)); public Pair3<TX, TY, TZ> P3<TX, TY, TZ>() => new Pair3<TX, TY, TZ>( Convert<TX>(this.Str), Convert<TY>(this.Str), Convert<TZ>(this.Str)); public Pair4<TX, TY, TZ, TW> P4<TX, TY, TZ, TW>() => new Pair4<TX, TY, TZ, TW>(Convert<TX>(this.Str), Convert<TY>(this.Str), Convert<TZ>(this.Str), Convert<TW>(this.Str)); } static class ScannerExtension { public static int[] Ints(this Scanner scanner, int n) => scanner.Ints((long)n); public static int[] Ints(this Scanner scanner, long n) => scanner.ScanStrs<int>(n).ToArray(); public static long[] Longs(this Scanner scanner, int n) => scanner.Longs((long)n); public static long[] Longs(this Scanner scanner, long n) => scanner.ScanStrs<long>(n).ToArray(); public static double[] Doubles(this Scanner scanner, int n) => scanner.Doubles((long)n); public static double[] Doubles(this Scanner scanner, long n) => scanner.ScanStrs<double>(n).ToArray(); public static string[] Strs(this Scanner scanner, int n) => scanner.Strs((long)n); public static string[] Strs(this Scanner scanner, long n) => scanner.ScanStrs<string>(n).ToArray(); private static IEnumerable<T> ScanStrs<T>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return Scanner.Convert<T>(scanner.Str); } public static Pair<TX, TY>[] Pairs<TX, TY>(this Scanner scanner, int n) => scanner.Pairs<TX, TY>((long)n); public static Pair<TX, TY>[] Pairs<TX, TY>(this Scanner scanner, long n) => scanner.ScanPairs<TX, TY>(n).ToArray(); public static Pair<long, long>[] Pairs(this Scanner scanner, int n) => scanner.Pairs((long)n); public static Pair<long, long>[] Pairs(this Scanner scanner, long n) => scanner.ScanPairs<long, long>(n).ToArray(); public static Pair<int, int>[] PairsInt(this Scanner scanner, int n) => scanner.PairsInt((long)n); public static Pair<int, int>[] PairsInt(this Scanner scanner, long n) => scanner.ScanPairs<int, int>(n).ToArray(); private static IEnumerable<Pair<TX, TY>> ScanPairs<TX, TY>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P2<TX, TY>(); } public static Pair3<TX, TY, TZ>[] Pairs3<TX, TY, TZ>( this Scanner scanner, int n) => scanner.Pairs3<TX, TY, TZ>((long)n); public static Pair3<TX, TY, TZ>[] Pairs3<TX, TY, TZ>(this Scanner scanner, long n) => scanner.ScanPairs3<TX, TY, TZ>(n).ToArray(); public static Pair3<long, long, long>[] Pairs3(this Scanner scanner, int n) => scanner.Pairs3((long)n); public static Pair3<long, long, long>[] Pairs3(this Scanner scanner, long n) => scanner.ScanPairs3<long, long, long>(n).ToArray(); public static Pair3<int, int, int>[] Pairs3Int(this Scanner scanner, int n) => scanner.Pairs3Int((long)n); public static Pair3<int, int, int>[] Pairs3Int(this Scanner scanner, long n) => scanner.ScanPairs3<int, int, int>(n).ToArray(); private static IEnumerable<Pair3<TX, TY, TZ>> ScanPairs3<TX, TY, TZ>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P3<TX, TY, TZ>(); } public static Pair4<TX, TY, TZ, TW>[] Pairs4<TX, TY, TZ, TW>( this Scanner scanner, int n) => scanner.Pairs4<TX, TY, TZ, TW>((long)n); public static Pair4<TX, TY, TZ, TW>[] Pairs4<TX, TY, TZ, TW>( this Scanner scanner, long n) => scanner.ScanPairs4<TX, TY, TZ, TW>(n).ToArray(); public static Pair4<long, long, long, long>[] Pairs4( this Scanner scanner, int n) => scanner.Pairs4((long)n); public static Pair4<long, long, long, long>[] Pairs4(this Scanner scanner, long n) => scanner.ScanPairs4<long, long, long, long>(n).ToArray(); public static Pair4<int, int, int, int>[] Pairs4Int( this Scanner scanner, int n) => scanner.Pairs4Int((long)n); public static Pair4<int, int, int, int>[] Pairs4Int(this Scanner scanner, long n) => scanner.ScanPairs4<int, int, int, int>(n).ToArray(); private static IEnumerable<Pair4<TX, TY, TZ, TW>> ScanPairs4<TX, TY, TZ, TW>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P4<TX, TY, TZ, TW>(); } } class Pair<TX, TY> { public TX X { get; } public TY Y { get; } public Pair(TX x, TY y) { this.X = x; this.Y = y; } } class Pair : Pair<long, long> { public Pair(long x, long y) : base(x, y) {} } class PairInt : Pair<int, int> { public PairInt(int x, int y) : base(x, y) {} } class Pair3<TX, TY, TZ> { public TX X { get; } public TY Y { get; } public TZ Z { get; } public Pair3(TX x, TY y, TZ z) { this.X = x; this.Y = y; this.Z = z; } } class Pair3 : Pair3<long, long, long> { public Pair3(long x, long y, long z) : base(x, y, z) {} } class Pair3Int : Pair3<int, int, int> { public Pair3Int(int x, int y, int z) : base(x, y, z) {} } class Pair4<TX, TY, TZ, TW> { public TX X { get; } public TY Y { get; } public TZ Z { get; } public TW W { get; } public Pair4(TX x, TY y, TZ z, TW w) { this.X = x; this.Y = y; this.Z = z; this.W = w; } } class Pair4 : Pair4<long, long, long, long> { public Pair4(long x, long y, long z, long w) : base(x, y, z, w) {} } class Pair4Int : Pair4<int, int, int, int> { public Pair4Int(int x, int y, int z, int w) : base(x, y, z, w) {} } class Printer { private readonly TextWriter writer; public Printer(TextWriter writer) { this.writer = writer; } public void Write(string obj) { writer.WriteLine(obj); } public void Write(object obj) { writer.WriteLine(obj); } public void Write<T>(IEnumerable<T> ts) { writer.WriteLine(string.Join(" ", ts)); } public void Write(params object[] objs) { writer.WriteLine(string.Join(" ", objs)); } } static class Extension { public static bool TryRemove<T>(this HashSet<T> ts, T t) { if (ts.Contains(t)) { ts.Remove(t); return true; } else { return false; } } public static void SafeSet<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] = value; else ts.Add(t, value); } public static void SafeAdd<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] += value; else ts.Add(t, value); } public static void SafeSub<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] -= value; else ts.Add(t, value); } public static void SafeMult<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] *= value; else ts.Add(t, value); } public static void SafeDiv<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] /= value; else ts.Add(t, value); } public static HashSet<T> ToHashSet<T>(this IEnumerable<T> ts) => new HashSet<T>(ts.Distinct()); public static long ToDigit(this char c) => (long)(c - '0'); public static long ToSmallAbcIndex(this char c) => (long)(c - 'a'); public static long ToLargeAbcIndex(this char c) => (long)(c - 'A'); public static long Count<T1, T2>(this IGrouping<T1, T2> gs) => gs.LongCount(); public static string ToStr(this IEnumerable<char> cs) => new string(cs.ToArray()); public static long ToLong(this IEnumerable<char> s) { var basis = 1L; var res = 0L; foreach (var c in s) { var d = c.ToSmallAbcIndex() + 1; res += d * basis; basis *= 27; } return res; } } class C { public class IterTools { /// <summary> /// 組み合わせ(重複なし) /// n = 4, k = 3 => (0,1,2) (0,1,3) (0,2,3) (1,2,3) /// </summary> public static IEnumerable<IReadOnlyList<long>> Combinations(long n, long k) { if (k <= 0) yield break; long[] indices = new long[k]; long pointer = 0; while (pointer >= 0) { if (indices[pointer] < n) { if (pointer >= k - 1) { yield return indices; indices[pointer]++; } else { indices[pointer + 1] = indices[pointer] + 1; pointer++; } } else { pointer--; if (pointer >= 0) indices[pointer]++; } } } /// <summary> /// 組み合わせ(重複なし) /// n = 4, k = 3 => (0,1,2) (0,1,3) (0,2,3) (1,2,3) /// </summary> public static IEnumerable<IReadOnlyList<T>> Combinations<T>(T[] ts, long k) { if (k <= 0) yield break; long[] indices = new long[k]; T[] container = new T[k]; long pointer = 0; long n = ts.LongLength; while (pointer >= 0) { if (indices[pointer] < n) { container[pointer] = ts[indices[pointer]]; if (pointer >= k - 1) { yield return container; indices[pointer]++; } else { indices[pointer + 1] = indices[pointer] + 1; pointer++; } } else { pointer--; if (pointer >= 0) indices[pointer]++; } } } /// <summary> /// 組み合わせ(重複あり) /// n = 3, k = 2 => (0,0) (0,1) (0,2) (1,0) (1,1) (1,2) (2,0) (2,1) (2,2) /// </summary> public static IEnumerable<IReadOnlyList<long>> CombinationsWithReplacement(long n, long k) { if (k <= 0) yield break; long[] container = new long[k]; long pointer = 0; while (pointer >= 0) { if (container[pointer] < n) { if (pointer >= k - 1) { yield return container; container[pointer]++; } else { container[pointer + 1] = 0; pointer++; } } else { pointer--; if (pointer >= 0) container[pointer]++; } } } /// <summary> /// 組み合わせ(重複あり) /// n = 3, k = 2 => (0,0) (0,1) (0,2) (1,0) (1,1) (1,2) (2,0) (2,1) (2,2) /// </summary> public static IEnumerable<IReadOnlyList<T>> CombinationsWithReplacement<T>(T[] ts, long k) { if (k <= 0) yield break; long[] indices = new long[k]; T[] container = new T[k]; long pointer = 0; long n = ts.LongLength; while (pointer >= 0) { if (indices[pointer] < n) { container[pointer] = ts[indices[pointer]]; if (pointer >= k - 1) { yield return container; indices[pointer]++; } else { indices[pointer + 1] = 0; pointer++; } } else { pointer--; if (pointer >= 0) indices[pointer]++; } } } /// <summary> /// 順列 /// n = 3, k = 2 => (0,1) (0,2) (1,0) (1,2) (2,0) (2,1) /// </summary> public static IEnumerable<IReadOnlyList<long>> Permutations(long n, long k) { if (k <= 0) yield break; HashSet<long> enumed = new HashSet<long>(); long[] container = new long[k]; long pointer = 0; while (pointer >= 0) { if (container[pointer] < n) { if (enumed.Contains(container[pointer])) { container[pointer]++; } else if (pointer >= k - 1) { yield return container; container[pointer]++; } else { enumed.Add(container[pointer]); container[pointer + 1] = 0; pointer++; } } else { pointer--; if (pointer >= 0) { enumed.Remove(container[pointer]); container[pointer]++; } } } } /// <summary> /// 順列 /// n = 3, k = 2 => (0,1) (0,2) (1,0) (1,2) (2,0) (2,1) /// </summary> public static IEnumerable<IReadOnlyList<T>> Permutations<T>(T[] ts, long k) { if (k <= 0) yield break; HashSet<long> enumed = new HashSet<long>(); long[] indices = new long[k]; T[] container = new T[k]; long pointer = 0; long n = ts.LongLength; while (pointer >= 0) { if (indices[pointer] < n) { if (enumed.Contains(indices[pointer])) { indices[pointer]++; } else if (pointer >= k - 1) { container[pointer] = ts[indices[pointer]]; yield return container; indices[pointer]++; } else { container[pointer] = ts[indices[pointer]]; enumed.Add(indices[pointer]); indices[pointer + 1] = 0; pointer++; } } else { pointer--; if (pointer >= 0) { enumed.Remove(indices[pointer]); indices[pointer]++; } } } } } public class Tree { public Tree() { toNodes = new Dictionary<long, long[]>(); } public Tree(Scanner sc, long n, bool base1 = true, bool singleDirection = false) { Adjust(sc.Pairs(n), base1, singleDirection); } public Tree(Pair<long, long>[] edges, bool base1 = true, bool singleDirection = false) { Adjust(edges, base1, singleDirection); } public Tree(IEnumerable<long> ps, IEnumerable<long> qs, bool base1 = true, bool singleDirection = false) { Adjust(ps.Zip(qs, (p, q) => new Pair<long, long>(p, q)).ToArray(), base1, singleDirection); } private void Adjust(Pair<long, long>[] edges, bool base1, bool singleDirection) { var arrows = base1 ? edges.Select(x => new { from = x.X - 1, to = x.Y - 1 }) : edges.Select(x => new { from = x.X, to = x.Y }); if (singleDirection == false) arrows = arrows.Concat(arrows.Select(x => new { from = x.to, to = x.from })); toNodes = arrows.GroupBy(x => x.from) .ToDictionary(x => x.Key, x => x.Select(xs => xs.to).ToArray()); } private long[] empty = new long[0]; private Dictionary<long, long[]> toNodes; public long[] To(long from) { long[] res = null; if (toNodes.TryGetValue(from, out res)) return res; else return empty; } public IEnumerable<Pair<long, long>> GetRouteEdges(long from, long to) { return GetRouteEdgesImpl(from, to).Skip(1); } private IEnumerable<Pair<long, long>> GetRouteEdgesImpl(long from, long to) { var routeNodes = GetRouteNodes(from, to); var current = -1L; foreach (var next in routeNodes) { yield return new Pair<long, long>(current, next); current = next; } } public IEnumerable<long> GetRouteNodes(long from, long to) { Stack<long> routeNodes = new Stack<long>(); HashSet<long> checkedNodes = new HashSet<long>(); GetRouteNodes(from, to, routeNodes, checkedNodes); return routeNodes.Reverse(); } private bool GetRouteNodes(long current, long dest, Stack<long> routeNodes, HashSet<long> checkedNodes) { routeNodes.Push(current); checkedNodes.Add(current); if (current == dest) return true; foreach (var next in toNodes[current]) { if (checkedNodes.Contains(next)) continue; if (GetRouteNodes(next, dest, routeNodes, checkedNodes)) return true; } routeNodes.Pop(); return false; } } public class PriorityQueue<TKey, TState> where TKey : IComparable<TKey> { public int Count { get; private set; } private readonly Func<TState, TKey> keySelector; private readonly bool desc; private TState[] states = new TState[65536]; private TKey[] keys = new TKey[65536]; //[MethodImpl(MethodImplOptions.AggressiveInlining)] public PriorityQueue(Func<TState, TKey> keySelector, bool desc = false) { this.keySelector = keySelector; this.desc = desc; } public TState Top { //[MethodImpl(MethodImplOptions.AggressiveInlining)] get { ValidateNonEmpty(); return states[1]; } } //[MethodImpl(MethodImplOptions.AggressiveInlining)] public TState Dequeue() { var top = Top; var item = states[Count]; var key = keys[Count]; Count--; int index = 1; while (true) { if ((index << 1) >= Count) { if (index << 1 > Count) break; if (key.CompareTo(keys[index << 1]) <= 0 ^ desc) break; states[index] = states[index << 1]; keys[index] = keys[index << 1]; index <<= 1; } else { var nextIndex = keys[index << 1].CompareTo(keys[(index << 1) + 1]) <= 0 ^ desc ? (index << 1) : (index << 1) + 1; if (key.CompareTo(keys[nextIndex]) <= 0 ^ desc) break; states[index] = states[nextIndex]; keys[index] = keys[nextIndex]; index = nextIndex; } } states[index] = item; keys[index] = key; return top; } //[MethodImpl(MethodImplOptions.AggressiveInlining)] public void Enqueue(TState state) { var key = keySelector.Invoke(state); Count++; int index = Count; if (states.Length == Count) Extend(states.Length * 2); while ((index >> 1) != 0) { if (keys[index >> 1].CompareTo(key) <= 0 ^ desc) break; states[index] = states[index >> 1]; keys[index] = keys[index >> 1]; index >>= 1; } states[index] = state; keys[index] = key; } //[MethodImpl(MethodImplOptions.AggressiveInlining)] private void Extend(int newSize) { TState[] newStates = new TState[newSize]; TKey[] newKeys = new TKey[newSize]; states.CopyTo(newStates, 0); keys.CopyTo(newKeys, 0); states = newStates; keys = newKeys; } private void ValidateNonEmpty() { if (Count == 0) throw new IndexOutOfRangeException(); } } public class BinaryIndexTree { long length; long[] binaryIndexedTree; public BinaryIndexTree(long length) { this.length = length; binaryIndexedTree = new long[length + 1]; } public void Add(long indexZeroBase, long additional) { // i += i & -i // 1が立っている最下位ビットを足す、の意味 for (long i = indexZeroBase + 1; i <= length; i += i & -i) { binaryIndexedTree[i] += additional; } } public long Sum(long indexZeroBase) { long result = 0; // i += i & -i // 1が立っている最下位ビットを引く、の意味 for (long i = indexZeroBase + 1; i > 0; i -= i & -i) { result += binaryIndexedTree[i]; } return result; } } public static class BinarySearch { public static long GetFirstIndexGreater<T>(T x, IList<T> listOrdered) where T : IComparable { return GetFirstIndexGreater(x, listOrdered, 0, listOrdered.Count - 1); } public static long GetFirstIndexGreater<T>(T x, IList<T> listOrdered, int low, int high) where T : IComparable { var count = listOrdered.Count; if (count == 0) return low; if (listOrdered[high].CompareTo(x) <= 0) return high + 1; while (low < high) { var mid = (low + high) / 2; if (listOrdered[mid].CompareTo(x) > 0) high = mid; else low = mid + 1; } return low; } public static long GetLastIndexLess<T>(T x, IList<T> listOrdered) where T : IComparable { return GetLastIndexLess(x, listOrdered, 0, listOrdered.Count - 1); } public static long GetLastIndexLess<T>(T x, IList<T> listOrdered, int low, int high) where T : IComparable { var count = listOrdered.Count; if (count == 0) return low - 1; if (listOrdered[0].CompareTo(x) >= 0) return low - 1; while (low < high) { var mid = (low + high + 1) / 2; if (listOrdered[mid].CompareTo(x) < 0) low = mid; else high = mid - 1; } return low; } } public static class BellmanFord { public class Vertex { public long Distance { get; set; } public Vertex() { Distance = long.MaxValue; } } public class Edge { public int From { get; private set; } public int To { get; private set; } public long Weight { get; private set; } public Edge(int from, int to, long weight) { From = from; To = to; Weight = weight; } } private static void GetReachable(int origin, ref HashSet<int> reached, ref Dictionary<int, int[]> paths) { if (reached.Contains(origin)) return; reached.Add(origin); if (paths.ContainsKey(origin) == false) return; foreach (var p in paths[origin]) GetReachable(p, ref reached, ref paths); } /// <summary> /// null: 負の無限大 /// long.MaxValue: たどり着けない /// その他: 距離 /// </summary> public static long? RunBellmanFord(int vertexCount, List<Edge> rawEdges, int source, int dest) { var forwards = rawEdges.GroupBy(x => x.From) .ToDictionary(x => x.Key, x => x.Select(xs => xs.To).ToArray()); var reverses = rawEdges.GroupBy(x => x.To).ToDictionary( x => x.Key, x => x.Select(xs => xs.From).ToArray()); var fromSource = new HashSet<int>(); var toDest = new HashSet<int>(); GetReachable(source, ref fromSource, ref forwards); GetReachable(dest, ref toDest, ref reverses); var edges = rawEdges.Where(e => fromSource.Contains(e.From)) .Where(e => fromSource.Contains(e.To)) .Where(e => toDest.Contains(e.From)) .Where(e => toDest.Contains(e.To)) .ToArray(); // initialize distances var vertices = new List<Vertex>(); for (int i = 0; i < vertexCount; i++) vertices.Add(new Vertex()); vertices[source].Distance = 0L; // update distances for (int i = 0; i < vertices.Count; i++) { foreach (var e in edges) { var from = vertices[e.From]; var to = vertices[e.To]; if (from.Distance == long.MaxValue) continue; var newDistance = from.Distance + e.Weight; if (to.Distance > newDistance) { to.Distance = newDistance; } } } // check negative cycle foreach (var e in edges) { var from = vertices[e.From]; var to = vertices[e.To]; if (from.Distance + e.Weight < to.Distance) return null; } return vertices[dest].Distance; } } public static long Gcd(int a, int b) => Gcd((long)a, (long)b); public static long Gcd(long a, long b) { if (a < b) return GcdImpl(b, a); else return GcdImpl(a, b); } private static long GcdImpl(long a, long b) { var remainder = a % b; if (remainder == 0) return b; else return GcdImpl(b, remainder); } public static long Lcm(int a, int b) => Lcm((long)a, (long)b); public static long Lcm(long a, long b) { return a / Gcd(a, b) * b; } public static long Pow(int n, int p) => Pow((long)n, (long)p); public static long Pow(long n, long p) { var res = 1L; for (long i = 0; i < p; i++) res *= n; return res; } public static Dictionary<long, long> Factorize(int n) => Factorize((long)n); public static Dictionary<long, long> Factorize(long n) { var res = new Dictionary<long, long>(); var r = n; for (long i = 2; i * i <= r; i++) { var c = 0L; while (r % i == 0) { c++; r /= i; } if (c > 0) res.Add(i, c); } if (r > 1) res.Add(r, 1); return res; } public static IEnumerable<long> Divisors(int n) => Divisors((long)n); public static IEnumerable<long> Divisors(long n) { var cache = new Stack<long>(); for (long i = 1; i * i <= n; i++) { if (n % i == 0) { yield return i; cache.Push(i); } } var r = cache.Peek(); if (r * r == n) cache.Pop(); while (cache.Count > 0) { var i = cache.Pop(); yield return n / i; } } public static IEnumerable<int> Loop(int n) { for (int i = 0; i < n; i++) yield return i; } public static IEnumerable<long> Loop(long n) { for (long i = 0L; i < n; i++) yield return i; } } struct Mint { public static long Divider { set { divider = value; } } private static long divider = 1000000007L; public static void Set998244353() { divider = 998244353L; } public static void Set1000000009() { divider = 1000000009L; } public long Value { get; } public override string ToString() => this.Value.ToString(); public Mint(long value) { this.Value = value; } // public static implicit operator Mint(long a) => new Mint(a % divider); // public static implicit operator Mint(int a) => new Mint(a % divider); // public static explicit operator long(Mint a) => a.Value; // public static explicit operator int(Mint a) => (int)a.Value; public static Mint operator +(Mint a, Mint b) => new Mint((a.Value + b.Value) % divider); public static Mint operator +(Mint a, long b) => a + new Mint(b); public static Mint operator +(Mint a, int b) => a + new Mint(b); public static Mint operator -(Mint a, Mint b) { var t = (a.Value - b.Value) % divider; if (t < 0L) t += divider; return new Mint(t); } public static Mint operator -(Mint a, long b) => a - new Mint(b); public static Mint operator -(Mint a, int b) => a - new Mint(b); public static Mint operator *(Mint a, Mint b) => new Mint((a.Value * b.Value) % divider); public static Mint operator *(Mint a, long b) => a * new Mint(b); public static Mint operator *(Mint a, int b) => a * new Mint(b); public static Mint operator /(Mint a, Mint b) => new Mint((a.Value * InvImpl(b.Value)) % divider); public static Mint operator /(Mint a, long b) => a / new Mint(b); public static Mint operator /(Mint a, int b) => a / new Mint(b); public Mint Pow(long p) => new Mint(PowImpl(Value, p)); public static Mint Pow(long a, long p) => new Mint(PowImpl(a, p)); private static long PowImpl(long a, long p) { if (p == 0L) return 1L; if (p == 1L) return a; var halfP = p / 2L; var halfPowered = PowImpl(a, halfP); var powered = halfPowered * halfPowered % divider; return p % 2L == 0L ? powered : powered * a % divider; } public static Mint Inv(long a) => new Mint(InvImpl(a)); private static readonly Dictionary<long, long> invCache = new Dictionary<long, long>(); private static long InvImpl(long a) { long cache; if (invCache.TryGetValue(a, out cache)) return cache; var result = PowImpl(a, divider - 2L); invCache.Add(a, result); return result; } public static Mint Fac(long a) => new Mint(FacImpl(a)); private static long[] facCache = new long[262144]; private static long cachedFac = 0L; private static long FacImpl(long a) { if (a >= divider) return 0L; facCache[0] = 1L; if (facCache.LongLength <= a) { long newSize = facCache.LongLength; while (newSize <= a) { newSize *= 2; } ExtendFacCache(newSize); } if (cachedFac < a) { var val = facCache[cachedFac]; var start = cachedFac + 1L; for (long i = start; i <= a; i++) { val = (val * i) % divider; facCache[i] = val; } cachedFac = a; } return facCache[a]; } private static void ExtendFacCache(long newSize) { long[] newFacCache = new long[newSize]; facCache.CopyTo(newFacCache, 0); facCache = newFacCache; } public static Mint Perm(long n, long r) => new Mint(PermImpl(n, r)); private static long PermImpl(long n, long r) { if (n < r) return 0L; if (r <= 0L) return 1L; var nn = FacImpl(n); var nr = FacImpl(n - r); return (nn * InvImpl(nr)) % divider; } public static Mint Comb(long n, long r) => new Mint(CombImpl(n, r)); private static long CombImpl(long n, long r) { if (n < r) return 0L; if (n == r) return 1L; if (n - r < r) return CombImpl(n, n - r); var nn = FacImpl(n); var nr = FacImpl(n - r); var rr = FacImpl(r); var nrrr = (nr * rr) % divider; return (nn * InvImpl(nrrr)) % divider; } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace V { partial class Solver { public void Solve() { Write(SolveLong()); // YesNo(SolveBool()); } public long SolveLong() { var n = Read; var pairs = sc.Pairs(n); // n = 200000; // pairs = Enumerable.Range(0, 200000).Select(x => new Pair((1L << 60) * (x // % 3 - 1), (1L << 60) * (x % 3 - 2))).ToArray(); var fish = pairs .Select(x => { if (x.X == 0 && x.Y == 0) return new Fish(); var a = x.X; var b = x.Y; var gn = a > 0 && b >= 0 ? 1 : a <= 0 && b > 0 ? 2 : a < 0 && b <= 0 ? 3 : 4; long ga = 0L; long gb = 0L; switch (gn) { case 1: ga = a; gb = b; break; case 2: ga = b; gb = -a; break; case 3: ga = -a; gb = -b; break; case 4: ga = -b; gb = a; break; } if (ga == 0 || gb == 0) { ga = 1; gb = 0; } else { var gcd = C.Gcd(ga, gb); ga /= gcd; gb /= gcd; } return new Fish() { a = a, b = b, ga = ga, gb = gb, gn = gn, }; }) .GroupBy(x => new { x.ga, x.gb }); var res = new Mint(1); var resZero = new Mint(); foreach (var g in fish) { if (g.Key.ga == 0 && g.Key.gb == 0) { resZero += g.Count(); continue; } var fg = g.GroupBy(x => x.gn % 2).Select(x => Mint.Pow(2, x.Count()) - 1); var c = new Mint(1); foreach (var fgc in fg) c += fgc; res *= c; } res -= 1; res += resZero; return res.Value; } public class Fish { public long a; public long b; public long ga; public long gb; public long gn; } public bool SolveBool() { var n = Read; return false; } } } namespace V { class StartingPoint { static void Main(string[] args) { try { var streamReader = args.Any() ? new StreamReader(args[0]) : new StreamReader(Console.OpenStandardInput()); var streamWriter = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; var scanner = new Scanner(streamReader); var printer = new Printer(streamWriter); var solver = new Solver(scanner, printer); solver.Solve(); streamWriter.Flush(); } catch (Exception e) { Console.WriteLine(e); if (args.Any() == false) throw e; } if (args.Any()) Console.ReadKey(); } } } namespace V { partial class Solver { public Solver(Scanner sc, Printer pr) { this.sc = sc; this.pr = pr; } private readonly Scanner sc; private readonly Printer pr; private IEnumerable<int> Loop(int n) => C.Loop(n); private IEnumerable<long> Loop(long n) => C.Loop(n); private int RdInt => sc.Int; private int ReadInt => sc.Int; private long Rd => sc.Long; private long Read => sc.Long; private long ReadLong => sc.Long; private double RdDouble => sc.Double; private double ReadDouble => sc.Double; private string Str => sc.Str; private string RdStr => sc.Str; private string ReadStr => sc.Str; private int[] ArrInt(int n) => sc.Ints(n); private int[] ArrInt(long n) => sc.Ints(n); private long[] Arr(int n) => sc.Longs(n); private long[] Arr(long n) => sc.Longs(n); private long[] ArrLong(int n) => sc.Longs(n); private long[] ArrLong(long n) => sc.Longs(n); private double[] ArrDouble(int n) => sc.Doubles(n); private double[] ArrDouble(long n) => sc.Doubles(n); private string[] ArrStr(int n) => sc.Strs(n); private string[] ArrStr(long n) => sc.Strs(n); private void Wr(string s) => pr.Write(s); private void Wr(object obj) => pr.Write(obj); private void Wr<T>(IEnumerable<T> ts) => pr.Write(ts); private void Wr(params object[] objs) => pr.Write(objs); private void Write(string s) => pr.Write(s); private void Write(object obj) => pr.Write(obj); private void Write<T>(IEnumerable<T> ts) => pr.Write(ts); private void Write(params object[] objs) => pr.Write(objs); private void YesNo(bool b) => Write(b ? "Yes" : "No"); private void YESNO(bool b) => Write(b ? "YES" : "NO"); } class Scanner { private readonly TextReader reader; public Scanner(TextReader reader) { this.reader = reader; } private Queue<string> strQueue = new Queue<string>(); public string Str { get { if (strQueue.Count > 0) return strQueue.Dequeue(); string[] strs = null; do { strs = reader.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); } while (strs.Any() == false); foreach (var s in strs.Skip(1)) strQueue.Enqueue(s); return strs[0]; } } public int Int => int.Parse(this.Str); public long Long => long.Parse(this.Str); public double Double => double.Parse(this.Str); public static bool TypeEquals<T1, T2>() => typeof(T1).Equals(typeof(T2)); public static T1 ChangeTypes<T1, T2>(T2 t2) => (T1)System.Convert.ChangeType(t2, typeof(T1)); public static T1 Convert<T1>(string s) => TypeEquals<T1, int>() ? ChangeTypes<T1, int>(int.Parse(s)) : TypeEquals<T1, long>() ? ChangeTypes<T1, long>(long.Parse(s)) : TypeEquals<T1, double>() ? ChangeTypes<T1, double>(int.Parse(s)) : TypeEquals<T1, char>() ? ChangeTypes<T1, char>(s[0]) : ChangeTypes<T1, string>(s); public Pair<TX, TY> P2<TX, TY>() => new Pair<TX, TY>(Convert<TX>(this.Str), Convert<TY>(this.Str)); public Pair3<TX, TY, TZ> P3<TX, TY, TZ>() => new Pair3<TX, TY, TZ>( Convert<TX>(this.Str), Convert<TY>(this.Str), Convert<TZ>(this.Str)); public Pair4<TX, TY, TZ, TW> P4<TX, TY, TZ, TW>() => new Pair4<TX, TY, TZ, TW>(Convert<TX>(this.Str), Convert<TY>(this.Str), Convert<TZ>(this.Str), Convert<TW>(this.Str)); } static class ScannerExtension { public static int[] Ints(this Scanner scanner, int n) => scanner.Ints((long)n); public static int[] Ints(this Scanner scanner, long n) => scanner.ScanStrs<int>(n).ToArray(); public static long[] Longs(this Scanner scanner, int n) => scanner.Longs((long)n); public static long[] Longs(this Scanner scanner, long n) => scanner.ScanStrs<long>(n).ToArray(); public static double[] Doubles(this Scanner scanner, int n) => scanner.Doubles((long)n); public static double[] Doubles(this Scanner scanner, long n) => scanner.ScanStrs<double>(n).ToArray(); public static string[] Strs(this Scanner scanner, int n) => scanner.Strs((long)n); public static string[] Strs(this Scanner scanner, long n) => scanner.ScanStrs<string>(n).ToArray(); private static IEnumerable<T> ScanStrs<T>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return Scanner.Convert<T>(scanner.Str); } public static Pair<TX, TY>[] Pairs<TX, TY>(this Scanner scanner, int n) => scanner.Pairs<TX, TY>((long)n); public static Pair<TX, TY>[] Pairs<TX, TY>(this Scanner scanner, long n) => scanner.ScanPairs<TX, TY>(n).ToArray(); public static Pair<long, long>[] Pairs(this Scanner scanner, int n) => scanner.Pairs((long)n); public static Pair<long, long>[] Pairs(this Scanner scanner, long n) => scanner.ScanPairs<long, long>(n).ToArray(); public static Pair<int, int>[] PairsInt(this Scanner scanner, int n) => scanner.PairsInt((long)n); public static Pair<int, int>[] PairsInt(this Scanner scanner, long n) => scanner.ScanPairs<int, int>(n).ToArray(); private static IEnumerable<Pair<TX, TY>> ScanPairs<TX, TY>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P2<TX, TY>(); } public static Pair3<TX, TY, TZ>[] Pairs3<TX, TY, TZ>( this Scanner scanner, int n) => scanner.Pairs3<TX, TY, TZ>((long)n); public static Pair3<TX, TY, TZ>[] Pairs3<TX, TY, TZ>(this Scanner scanner, long n) => scanner.ScanPairs3<TX, TY, TZ>(n).ToArray(); public static Pair3<long, long, long>[] Pairs3(this Scanner scanner, int n) => scanner.Pairs3((long)n); public static Pair3<long, long, long>[] Pairs3(this Scanner scanner, long n) => scanner.ScanPairs3<long, long, long>(n).ToArray(); public static Pair3<int, int, int>[] Pairs3Int(this Scanner scanner, int n) => scanner.Pairs3Int((long)n); public static Pair3<int, int, int>[] Pairs3Int(this Scanner scanner, long n) => scanner.ScanPairs3<int, int, int>(n).ToArray(); private static IEnumerable<Pair3<TX, TY, TZ>> ScanPairs3<TX, TY, TZ>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P3<TX, TY, TZ>(); } public static Pair4<TX, TY, TZ, TW>[] Pairs4<TX, TY, TZ, TW>( this Scanner scanner, int n) => scanner.Pairs4<TX, TY, TZ, TW>((long)n); public static Pair4<TX, TY, TZ, TW>[] Pairs4<TX, TY, TZ, TW>( this Scanner scanner, long n) => scanner.ScanPairs4<TX, TY, TZ, TW>(n).ToArray(); public static Pair4<long, long, long, long>[] Pairs4( this Scanner scanner, int n) => scanner.Pairs4((long)n); public static Pair4<long, long, long, long>[] Pairs4(this Scanner scanner, long n) => scanner.ScanPairs4<long, long, long, long>(n).ToArray(); public static Pair4<int, int, int, int>[] Pairs4Int( this Scanner scanner, int n) => scanner.Pairs4Int((long)n); public static Pair4<int, int, int, int>[] Pairs4Int(this Scanner scanner, long n) => scanner.ScanPairs4<int, int, int, int>(n).ToArray(); private static IEnumerable<Pair4<TX, TY, TZ, TW>> ScanPairs4<TX, TY, TZ, TW>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P4<TX, TY, TZ, TW>(); } } class Pair<TX, TY> { public TX X { get; } public TY Y { get; } public Pair(TX x, TY y) { this.X = x; this.Y = y; } } class Pair : Pair<long, long> { public Pair(long x, long y) : base(x, y) {} } class PairInt : Pair<int, int> { public PairInt(int x, int y) : base(x, y) {} } class Pair3<TX, TY, TZ> { public TX X { get; } public TY Y { get; } public TZ Z { get; } public Pair3(TX x, TY y, TZ z) { this.X = x; this.Y = y; this.Z = z; } } class Pair3 : Pair3<long, long, long> { public Pair3(long x, long y, long z) : base(x, y, z) {} } class Pair3Int : Pair3<int, int, int> { public Pair3Int(int x, int y, int z) : base(x, y, z) {} } class Pair4<TX, TY, TZ, TW> { public TX X { get; } public TY Y { get; } public TZ Z { get; } public TW W { get; } public Pair4(TX x, TY y, TZ z, TW w) { this.X = x; this.Y = y; this.Z = z; this.W = w; } } class Pair4 : Pair4<long, long, long, long> { public Pair4(long x, long y, long z, long w) : base(x, y, z, w) {} } class Pair4Int : Pair4<int, int, int, int> { public Pair4Int(int x, int y, int z, int w) : base(x, y, z, w) {} } class Printer { private readonly TextWriter writer; public Printer(TextWriter writer) { this.writer = writer; } public void Write(string obj) { writer.WriteLine(obj); } public void Write(object obj) { writer.WriteLine(obj); } public void Write<T>(IEnumerable<T> ts) { writer.WriteLine(string.Join(" ", ts)); } public void Write(params object[] objs) { writer.WriteLine(string.Join(" ", objs)); } } static class Extension { public static bool TryRemove<T>(this HashSet<T> ts, T t) { if (ts.Contains(t)) { ts.Remove(t); return true; } else { return false; } } public static void SafeSet<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] = value; else ts.Add(t, value); } public static void SafeAdd<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] += value; else ts.Add(t, value); } public static void SafeSub<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] -= value; else ts.Add(t, value); } public static void SafeMult<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] *= value; else ts.Add(t, value); } public static void SafeDiv<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] /= value; else ts.Add(t, value); } public static HashSet<T> ToHashSet<T>(this IEnumerable<T> ts) => new HashSet<T>(ts.Distinct()); public static long ToDigit(this char c) => (long)(c - '0'); public static long ToSmallAbcIndex(this char c) => (long)(c - 'a'); public static long ToLargeAbcIndex(this char c) => (long)(c - 'A'); public static long Count<T1, T2>(this IGrouping<T1, T2> gs) => gs.LongCount(); public static string ToStr(this IEnumerable<char> cs) => new string(cs.ToArray()); public static long ToLong(this IEnumerable<char> s) { var basis = 1L; var res = 0L; foreach (var c in s) { var d = c.ToSmallAbcIndex() + 1; res += d * basis; basis *= 27; } return res; } } class C { public class IterTools { /// <summary> /// 組み合わせ(重複なし) /// n = 4, k = 3 => (0,1,2) (0,1,3) (0,2,3) (1,2,3) /// </summary> public static IEnumerable<IReadOnlyList<long>> Combinations(long n, long k) { if (k <= 0) yield break; long[] indices = new long[k]; long pointer = 0; while (pointer >= 0) { if (indices[pointer] < n) { if (pointer >= k - 1) { yield return indices; indices[pointer]++; } else { indices[pointer + 1] = indices[pointer] + 1; pointer++; } } else { pointer--; if (pointer >= 0) indices[pointer]++; } } } /// <summary> /// 組み合わせ(重複なし) /// n = 4, k = 3 => (0,1,2) (0,1,3) (0,2,3) (1,2,3) /// </summary> public static IEnumerable<IReadOnlyList<T>> Combinations<T>(T[] ts, long k) { if (k <= 0) yield break; long[] indices = new long[k]; T[] container = new T[k]; long pointer = 0; long n = ts.LongLength; while (pointer >= 0) { if (indices[pointer] < n) { container[pointer] = ts[indices[pointer]]; if (pointer >= k - 1) { yield return container; indices[pointer]++; } else { indices[pointer + 1] = indices[pointer] + 1; pointer++; } } else { pointer--; if (pointer >= 0) indices[pointer]++; } } } /// <summary> /// 組み合わせ(重複あり) /// n = 3, k = 2 => (0,0) (0,1) (0,2) (1,0) (1,1) (1,2) (2,0) (2,1) (2,2) /// </summary> public static IEnumerable<IReadOnlyList<long>> CombinationsWithReplacement(long n, long k) { if (k <= 0) yield break; long[] container = new long[k]; long pointer = 0; while (pointer >= 0) { if (container[pointer] < n) { if (pointer >= k - 1) { yield return container; container[pointer]++; } else { container[pointer + 1] = 0; pointer++; } } else { pointer--; if (pointer >= 0) container[pointer]++; } } } /// <summary> /// 組み合わせ(重複あり) /// n = 3, k = 2 => (0,0) (0,1) (0,2) (1,0) (1,1) (1,2) (2,0) (2,1) (2,2) /// </summary> public static IEnumerable<IReadOnlyList<T>> CombinationsWithReplacement<T>(T[] ts, long k) { if (k <= 0) yield break; long[] indices = new long[k]; T[] container = new T[k]; long pointer = 0; long n = ts.LongLength; while (pointer >= 0) { if (indices[pointer] < n) { container[pointer] = ts[indices[pointer]]; if (pointer >= k - 1) { yield return container; indices[pointer]++; } else { indices[pointer + 1] = 0; pointer++; } } else { pointer--; if (pointer >= 0) indices[pointer]++; } } } /// <summary> /// 順列 /// n = 3, k = 2 => (0,1) (0,2) (1,0) (1,2) (2,0) (2,1) /// </summary> public static IEnumerable<IReadOnlyList<long>> Permutations(long n, long k) { if (k <= 0) yield break; HashSet<long> enumed = new HashSet<long>(); long[] container = new long[k]; long pointer = 0; while (pointer >= 0) { if (container[pointer] < n) { if (enumed.Contains(container[pointer])) { container[pointer]++; } else if (pointer >= k - 1) { yield return container; container[pointer]++; } else { enumed.Add(container[pointer]); container[pointer + 1] = 0; pointer++; } } else { pointer--; if (pointer >= 0) { enumed.Remove(container[pointer]); container[pointer]++; } } } } /// <summary> /// 順列 /// n = 3, k = 2 => (0,1) (0,2) (1,0) (1,2) (2,0) (2,1) /// </summary> public static IEnumerable<IReadOnlyList<T>> Permutations<T>(T[] ts, long k) { if (k <= 0) yield break; HashSet<long> enumed = new HashSet<long>(); long[] indices = new long[k]; T[] container = new T[k]; long pointer = 0; long n = ts.LongLength; while (pointer >= 0) { if (indices[pointer] < n) { if (enumed.Contains(indices[pointer])) { indices[pointer]++; } else if (pointer >= k - 1) { container[pointer] = ts[indices[pointer]]; yield return container; indices[pointer]++; } else { container[pointer] = ts[indices[pointer]]; enumed.Add(indices[pointer]); indices[pointer + 1] = 0; pointer++; } } else { pointer--; if (pointer >= 0) { enumed.Remove(indices[pointer]); indices[pointer]++; } } } } } public class Tree { public Tree() { toNodes = new Dictionary<long, long[]>(); } public Tree(Scanner sc, long n, bool base1 = true, bool singleDirection = false) { Adjust(sc.Pairs(n), base1, singleDirection); } public Tree(Pair<long, long>[] edges, bool base1 = true, bool singleDirection = false) { Adjust(edges, base1, singleDirection); } public Tree(IEnumerable<long> ps, IEnumerable<long> qs, bool base1 = true, bool singleDirection = false) { Adjust(ps.Zip(qs, (p, q) => new Pair<long, long>(p, q)).ToArray(), base1, singleDirection); } private void Adjust(Pair<long, long>[] edges, bool base1, bool singleDirection) { var arrows = base1 ? edges.Select(x => new { from = x.X - 1, to = x.Y - 1 }) : edges.Select(x => new { from = x.X, to = x.Y }); if (singleDirection == false) arrows = arrows.Concat(arrows.Select(x => new { from = x.to, to = x.from })); toNodes = arrows.GroupBy(x => x.from) .ToDictionary(x => x.Key, x => x.Select(xs => xs.to).ToArray()); } private long[] empty = new long[0]; private Dictionary<long, long[]> toNodes; public long[] To(long from) { long[] res = null; if (toNodes.TryGetValue(from, out res)) return res; else return empty; } public IEnumerable<Pair<long, long>> GetRouteEdges(long from, long to) { return GetRouteEdgesImpl(from, to).Skip(1); } private IEnumerable<Pair<long, long>> GetRouteEdgesImpl(long from, long to) { var routeNodes = GetRouteNodes(from, to); var current = -1L; foreach (var next in routeNodes) { yield return new Pair<long, long>(current, next); current = next; } } public IEnumerable<long> GetRouteNodes(long from, long to) { Stack<long> routeNodes = new Stack<long>(); HashSet<long> checkedNodes = new HashSet<long>(); GetRouteNodes(from, to, routeNodes, checkedNodes); return routeNodes.Reverse(); } private bool GetRouteNodes(long current, long dest, Stack<long> routeNodes, HashSet<long> checkedNodes) { routeNodes.Push(current); checkedNodes.Add(current); if (current == dest) return true; foreach (var next in toNodes[current]) { if (checkedNodes.Contains(next)) continue; if (GetRouteNodes(next, dest, routeNodes, checkedNodes)) return true; } routeNodes.Pop(); return false; } } public class PriorityQueue<TKey, TState> where TKey : IComparable<TKey> { public int Count { get; private set; } private readonly Func<TState, TKey> keySelector; private readonly bool desc; private TState[] states = new TState[65536]; private TKey[] keys = new TKey[65536]; //[MethodImpl(MethodImplOptions.AggressiveInlining)] public PriorityQueue(Func<TState, TKey> keySelector, bool desc = false) { this.keySelector = keySelector; this.desc = desc; } public TState Top { //[MethodImpl(MethodImplOptions.AggressiveInlining)] get { ValidateNonEmpty(); return states[1]; } } //[MethodImpl(MethodImplOptions.AggressiveInlining)] public TState Dequeue() { var top = Top; var item = states[Count]; var key = keys[Count]; Count--; int index = 1; while (true) { if ((index << 1) >= Count) { if (index << 1 > Count) break; if (key.CompareTo(keys[index << 1]) <= 0 ^ desc) break; states[index] = states[index << 1]; keys[index] = keys[index << 1]; index <<= 1; } else { var nextIndex = keys[index << 1].CompareTo(keys[(index << 1) + 1]) <= 0 ^ desc ? (index << 1) : (index << 1) + 1; if (key.CompareTo(keys[nextIndex]) <= 0 ^ desc) break; states[index] = states[nextIndex]; keys[index] = keys[nextIndex]; index = nextIndex; } } states[index] = item; keys[index] = key; return top; } //[MethodImpl(MethodImplOptions.AggressiveInlining)] public void Enqueue(TState state) { var key = keySelector.Invoke(state); Count++; int index = Count; if (states.Length == Count) Extend(states.Length * 2); while ((index >> 1) != 0) { if (keys[index >> 1].CompareTo(key) <= 0 ^ desc) break; states[index] = states[index >> 1]; keys[index] = keys[index >> 1]; index >>= 1; } states[index] = state; keys[index] = key; } //[MethodImpl(MethodImplOptions.AggressiveInlining)] private void Extend(int newSize) { TState[] newStates = new TState[newSize]; TKey[] newKeys = new TKey[newSize]; states.CopyTo(newStates, 0); keys.CopyTo(newKeys, 0); states = newStates; keys = newKeys; } private void ValidateNonEmpty() { if (Count == 0) throw new IndexOutOfRangeException(); } } public class BinaryIndexTree { long length; long[] binaryIndexedTree; public BinaryIndexTree(long length) { this.length = length; binaryIndexedTree = new long[length + 1]; } public void Add(long indexZeroBase, long additional) { // i += i & -i // 1が立っている最下位ビットを足す、の意味 for (long i = indexZeroBase + 1; i <= length; i += i & -i) { binaryIndexedTree[i] += additional; } } public long Sum(long indexZeroBase) { long result = 0; // i += i & -i // 1が立っている最下位ビットを引く、の意味 for (long i = indexZeroBase + 1; i > 0; i -= i & -i) { result += binaryIndexedTree[i]; } return result; } } public static class BinarySearch { public static long GetFirstIndexGreater<T>(T x, IList<T> listOrdered) where T : IComparable { return GetFirstIndexGreater(x, listOrdered, 0, listOrdered.Count - 1); } public static long GetFirstIndexGreater<T>(T x, IList<T> listOrdered, int low, int high) where T : IComparable { var count = listOrdered.Count; if (count == 0) return low; if (listOrdered[high].CompareTo(x) <= 0) return high + 1; while (low < high) { var mid = (low + high) / 2; if (listOrdered[mid].CompareTo(x) > 0) high = mid; else low = mid + 1; } return low; } public static long GetLastIndexLess<T>(T x, IList<T> listOrdered) where T : IComparable { return GetLastIndexLess(x, listOrdered, 0, listOrdered.Count - 1); } public static long GetLastIndexLess<T>(T x, IList<T> listOrdered, int low, int high) where T : IComparable { var count = listOrdered.Count; if (count == 0) return low - 1; if (listOrdered[0].CompareTo(x) >= 0) return low - 1; while (low < high) { var mid = (low + high + 1) / 2; if (listOrdered[mid].CompareTo(x) < 0) low = mid; else high = mid - 1; } return low; } } public static class BellmanFord { public class Vertex { public long Distance { get; set; } public Vertex() { Distance = long.MaxValue; } } public class Edge { public int From { get; private set; } public int To { get; private set; } public long Weight { get; private set; } public Edge(int from, int to, long weight) { From = from; To = to; Weight = weight; } } private static void GetReachable(int origin, ref HashSet<int> reached, ref Dictionary<int, int[]> paths) { if (reached.Contains(origin)) return; reached.Add(origin); if (paths.ContainsKey(origin) == false) return; foreach (var p in paths[origin]) GetReachable(p, ref reached, ref paths); } /// <summary> /// null: 負の無限大 /// long.MaxValue: たどり着けない /// その他: 距離 /// </summary> public static long? RunBellmanFord(int vertexCount, List<Edge> rawEdges, int source, int dest) { var forwards = rawEdges.GroupBy(x => x.From) .ToDictionary(x => x.Key, x => x.Select(xs => xs.To).ToArray()); var reverses = rawEdges.GroupBy(x => x.To).ToDictionary( x => x.Key, x => x.Select(xs => xs.From).ToArray()); var fromSource = new HashSet<int>(); var toDest = new HashSet<int>(); GetReachable(source, ref fromSource, ref forwards); GetReachable(dest, ref toDest, ref reverses); var edges = rawEdges.Where(e => fromSource.Contains(e.From)) .Where(e => fromSource.Contains(e.To)) .Where(e => toDest.Contains(e.From)) .Where(e => toDest.Contains(e.To)) .ToArray(); // initialize distances var vertices = new List<Vertex>(); for (int i = 0; i < vertexCount; i++) vertices.Add(new Vertex()); vertices[source].Distance = 0L; // update distances for (int i = 0; i < vertices.Count; i++) { foreach (var e in edges) { var from = vertices[e.From]; var to = vertices[e.To]; if (from.Distance == long.MaxValue) continue; var newDistance = from.Distance + e.Weight; if (to.Distance > newDistance) { to.Distance = newDistance; } } } // check negative cycle foreach (var e in edges) { var from = vertices[e.From]; var to = vertices[e.To]; if (from.Distance + e.Weight < to.Distance) return null; } return vertices[dest].Distance; } } public static long Gcd(int a, int b) => Gcd((long)a, (long)b); public static long Gcd(long a, long b) { if (a < b) return GcdImpl(b, a); else return GcdImpl(a, b); } private static long GcdImpl(long a, long b) { var remainder = a % b; if (remainder == 0) return b; else return GcdImpl(b, remainder); } public static long Lcm(int a, int b) => Lcm((long)a, (long)b); public static long Lcm(long a, long b) { return a / Gcd(a, b) * b; } public static long Pow(int n, int p) => Pow((long)n, (long)p); public static long Pow(long n, long p) { var res = 1L; for (long i = 0; i < p; i++) res *= n; return res; } public static Dictionary<long, long> Factorize(int n) => Factorize((long)n); public static Dictionary<long, long> Factorize(long n) { var res = new Dictionary<long, long>(); var r = n; for (long i = 2; i * i <= r; i++) { var c = 0L; while (r % i == 0) { c++; r /= i; } if (c > 0) res.Add(i, c); } if (r > 1) res.Add(r, 1); return res; } public static IEnumerable<long> Divisors(int n) => Divisors((long)n); public static IEnumerable<long> Divisors(long n) { var cache = new Stack<long>(); for (long i = 1; i * i <= n; i++) { if (n % i == 0) { yield return i; cache.Push(i); } } var r = cache.Peek(); if (r * r == n) cache.Pop(); while (cache.Count > 0) { var i = cache.Pop(); yield return n / i; } } public static IEnumerable<int> Loop(int n) { for (int i = 0; i < n; i++) yield return i; } public static IEnumerable<long> Loop(long n) { for (long i = 0L; i < n; i++) yield return i; } } struct Mint { public static long Divider { set { divider = value; } } private static long divider = 1000000007L; public static void Set998244353() { divider = 998244353L; } public static void Set1000000009() { divider = 1000000009L; } public long Value { get; } public override string ToString() => this.Value.ToString(); public Mint(long value) { this.Value = value; } // public static implicit operator Mint(long a) => new Mint(a % divider); // public static implicit operator Mint(int a) => new Mint(a % divider); // public static explicit operator long(Mint a) => a.Value; // public static explicit operator int(Mint a) => (int)a.Value; public static Mint operator +(Mint a, Mint b) => new Mint((a.Value + b.Value) % divider); public static Mint operator +(Mint a, long b) => a + new Mint(b); public static Mint operator +(Mint a, int b) => a + new Mint(b); public static Mint operator -(Mint a, Mint b) { var t = (a.Value - b.Value) % divider; if (t < 0L) t += divider; return new Mint(t); } public static Mint operator -(Mint a, long b) => a - new Mint(b); public static Mint operator -(Mint a, int b) => a - new Mint(b); public static Mint operator *(Mint a, Mint b) => new Mint((a.Value * b.Value) % divider); public static Mint operator *(Mint a, long b) => a * new Mint(b); public static Mint operator *(Mint a, int b) => a * new Mint(b); public static Mint operator /(Mint a, Mint b) => new Mint((a.Value * InvImpl(b.Value)) % divider); public static Mint operator /(Mint a, long b) => a / new Mint(b); public static Mint operator /(Mint a, int b) => a / new Mint(b); public Mint Pow(long p) => new Mint(PowImpl(Value, p)); public static Mint Pow(long a, long p) => new Mint(PowImpl(a, p)); private static long PowImpl(long a, long p) { if (p == 0L) return 1L; if (p == 1L) return a; var halfP = p / 2L; var halfPowered = PowImpl(a, halfP); var powered = halfPowered * halfPowered % divider; return p % 2L == 0L ? powered : powered * a % divider; } public static Mint Inv(long a) => new Mint(InvImpl(a)); private static readonly Dictionary<long, long> invCache = new Dictionary<long, long>(); private static long InvImpl(long a) { long cache; if (invCache.TryGetValue(a, out cache)) return cache; var result = PowImpl(a, divider - 2L); invCache.Add(a, result); return result; } public static Mint Fac(long a) => new Mint(FacImpl(a)); private static long[] facCache = new long[262144]; private static long cachedFac = 0L; private static long FacImpl(long a) { if (a >= divider) return 0L; facCache[0] = 1L; if (facCache.LongLength <= a) { long newSize = facCache.LongLength; while (newSize <= a) { newSize *= 2; } ExtendFacCache(newSize); } if (cachedFac < a) { var val = facCache[cachedFac]; var start = cachedFac + 1L; for (long i = start; i <= a; i++) { val = (val * i) % divider; facCache[i] = val; } cachedFac = a; } return facCache[a]; } private static void ExtendFacCache(long newSize) { long[] newFacCache = new long[newSize]; facCache.CopyTo(newFacCache, 0); facCache = newFacCache; } public static Mint Perm(long n, long r) => new Mint(PermImpl(n, r)); private static long PermImpl(long n, long r) { if (n < r) return 0L; if (r <= 0L) return 1L; var nn = FacImpl(n); var nr = FacImpl(n - r); return (nn * InvImpl(nr)) % divider; } public static Mint Comb(long n, long r) => new Mint(CombImpl(n, r)); private static long CombImpl(long n, long r) { if (n < r) return 0L; if (n == r) return 1L; if (n - r < r) return CombImpl(n, n - r); var nn = FacImpl(n); var nr = FacImpl(n - r); var rr = FacImpl(r); var nrrr = (nr * rr) % divider; return (nn * InvImpl(nrrr)) % divider; } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 28, 0, 218, 8, 196, 0, 57, 0, 121], ["+", 0, 28, 0, 218, 8, 196, 0, 57, 0, 24], ["-", 0, 198, 0, 200, 0, 212, 0, 41, 0, 101], ["+", 0, 28, 0, 218, 8, 196, 0, 57, 0, 25], ["+", 0, 218, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 41, 0, 102], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 0, 218, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 28, 0, 218, 8, 196, 0, 57, 0, 95], ["+", 0, 218, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 75, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 8, 196, 0, 57, 75, 196, 0, 197, 0, 35], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 90], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 0, 218, 8, 196, 0, 57, 75, 196, 0, 46], ["-", 0, 230, 10, 229, 0, 11, 12, 16, 17, 85], ["-", 0, 230, 10, 229, 0, 11, 12, 16, 12, 22]]
8
8,507
35
using System; using System.Linq; using System.Collections.Generic; namespace Contest { class Program { static void Main(string[] args) { ABC168.E(); } class ABC168 { public static void A() { var N = Read.Int(); switch (N % 10) { case 0: case 1: case 6: case 8: Console.WriteLine("pon"); return; case 3: Console.WriteLine("bon"); return; case 2: case 4: case 5: case 7: case 9: Console.WriteLine("hon"); return; } } public static void B() { var K = Read.Int(); var S = Read.Str(); Console.WriteLine(S.Length <= K ? S : S.Substring(0, K) + "..."); } public static void C() { var A = Read.Int(); var B = Read.Int(); var H = Read.Int(); var M = Read.Int(); var r1 = Math.PI * (H * 60 + M) / 360; var r2 = Math.PI * M / 30; var x1 = Math.Cos(r1) * A; var y1 = Math.Sin(r1) * A; var x2 = Math.Cos(r2) * B; var y2 = Math.Sin(r2) * B; Console.WriteLine(Math.Sqrt( Math.Max(0, (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)))); } public static void D() { var N = Read.Int(); var M = Read.Int(); var Adj = Read.AdjacencyList(N, M); var ans = Enumerable.Range(0, N + 1).Select(i => -1).ToArray(); var queue = new Queue<int>(); queue.Enqueue(1); while (queue.Count > 0) { var v = queue.Dequeue(); foreach (var w in Adj[v]) { if (ans[w] >= 0) { continue; } ans[w] = v; queue.Enqueue(w); } } if (ans.Skip(2).Count(x => x < 0) > 0) { Console.WriteLine("No"); return; } Console.WriteLine("Yes"); Console.WriteLine(String.Join(Environment.NewLine, ans.Skip(2))); } public static void E() { var N = Read.Int(); var AB = Read.TupleLong(N); var Zero = new List<Tuple<long, long>>(); var D1 = new List<Tuple<long, long>>(); var D2 = new List<Tuple<long, long>>(); var count1 = new Dictionary<long, Dictionary<long, long>>(); var count2 = new Dictionary<long, Dictionary<long, long>>(); foreach (var t in AB) { var X = t.Item1; var Y = t.Item2; if (X == 0 && Y == 0) { Zero.Add(new Tuple<long, long>(0, 0)); continue; } if (Y < 0) { X *= -1; Y *= -1; } var gcd = Util.GCD(Math.Abs(X), Y); X /= gcd; Y /= gcd; if (X >= 0) { if (!count1.ContainsKey(X)) { count1.Add(X, new Dictionary<long, long>()); } if (!count1[X].ContainsKey(Y)) { count1[X].Add(Y, 0); } count1[X][Y]++; } else { if (!count2.ContainsKey(X)) { count2.Add(X, new Dictionary<long, long>()); } if (!count2[X].ContainsKey(Y)) { count2[X].Add(Y, 0); } count2[X][Y]++; } } MOD two = 2; MOD ans = 1; foreach (var kvp1 in count1) { foreach (var kvp2 in kvp1.Value) { var X = kvp1.Key; var Y = kvp2.Key; var C = kvp2.Value; if (count2.ContainsKey(-Y) && count2[-Y].ContainsKey(X)) { var C2 = count2[-Y][X]; count2[-Y][X] = 0; ans = ans * (two.Power(C) + two.Power(C2) - 1); } else { ans = ans * (two.Power(C) - 0); } } } foreach (var kvp1 in count2) { foreach (var kvp2 in kvp1.Value) { ans = ans * two.Power(kvp2.Value); } } Console.WriteLine((ans + Zero.Count - 1).V); } public static void F() {} } class Util { public static long[] ASum(long[] array) { var res = new long[array.Length + 1]; for (int i = 0; i < array.Length; ++i) { res[i + 1] = res[i] + array[i]; } return res; } public static Dictionary<T, long> Frequency<T>(T[] array) { var dict = new Dictionary<T, long>(); foreach (var a in array) { if (!dict.ContainsKey(a)) { dict.Add(a, 0); } dict[a]++; } return dict; } public static long GCD(long a, long b) { while (b > 0) { var c = a % b; a = b; b = c; } return a; } } struct MOD { public static long P = 1000000007; public readonly long V; public MOD(long a) { this.V = a % P; } public static implicit operator MOD(long a) { return new MOD(a); } public static MOD operator +(MOD a, MOD b) { return new MOD((a.V + b.V) % P); } public static MOD operator -(MOD a, MOD b) { return new MOD((a.V - b.V + P) % P); } public static MOD operator *(MOD a, MOD b) { return new MOD((a.V * b.V) % P); } public static MOD operator /(MOD a, MOD b) { return new MOD((a.V * b.Inverse().V) % P); } public MOD Inverse() { long a = V, p = P; long b = p, c = 1, d = 0, e = 0, f = 0; while (b != 0) { e = a / b; f = b; b = a - e * b; a = f; f = d; d = c - e * d; c = f; } c %= p; return c + (c < 0 ? p : 0); } public MOD Power(long n) { long a = V, p = P; long res = 1; long mult = a; for (int i = 0; i < 63; ++i) { if ((n & ((long)1 << i)) > 0) { res = (res * mult) % p; } mult = (mult * mult) % p; } return res; } public override string ToString() { return V.ToString(); } } static class Read { static Queue<string> queue = new Queue<string>(); static void Enqueue() { var ss = Console.ReadLine().Split(' '); foreach (var s in ss) { queue.Enqueue(s); } } public static int Int() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt32(queue.Dequeue()); } public static long Long() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt64(queue.Dequeue()); } public static string Str() { if (queue.Count == 0) { Enqueue(); } return queue.Dequeue(); } public static int[] IntN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt32(s)) .ToArray(); } public static long[] LongN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt64(s)) .ToArray(); } public static ulong[] ULongN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToUInt64(s)) .ToArray(); } public static string[] StrN() { return Console.ReadLine().Split(' '); } public static Tuple<int, int>[] TupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = Read.IntN(); list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<long, long>[] TupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<string, string>[] TupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = Read.StrN(); list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<double, double>[] TupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); } public static long[,] LongMatrix(int r, int c) { var mat = new long[r, c]; for (int i = 0; i < r; ++i) { var x = Read.LongN(); for (int j = 0; j < c; ++j) { mat[i, j] = x[j]; } } return mat; } public static Dictionary<int, HashSet<int>> AdjacencyList(int N, int M, bool isDirectional = false) { Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new HashSet<int>()); } for (int i = 0; i < M; ++i) { var ab = Read.IntN(); if (!dict[ab[0]].Contains(ab[1])) { dict[ab[0]].Add(ab[1]); } if (!isDirectional && !dict[ab[1]].Contains(ab[0])) { dict[ab[1]].Add(ab[0]); } } return dict; } public static Dictionary<int, Dictionary<int, long>> AdjacencyListWithWeight(int N, int M) { Dictionary<int, Dictionary<int, long>> dict = new Dictionary<int, Dictionary<int, long>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new Dictionary<int, long>()); } for (int i = 0; i < M; ++i) { var ab = Read.IntN(); dict[ab[0]].Add(ab[1], ab[2]); dict[ab[1]].Add(ab[0], ab[2]); } return dict; } } } }
using System; using System.Linq; using System.Collections.Generic; namespace Contest { class Program { static void Main(string[] args) { ABC168.E(); } class ABC168 { public static void A() { var N = Read.Int(); switch (N % 10) { case 0: case 1: case 6: case 8: Console.WriteLine("pon"); return; case 3: Console.WriteLine("bon"); return; case 2: case 4: case 5: case 7: case 9: Console.WriteLine("hon"); return; } } public static void B() { var K = Read.Int(); var S = Read.Str(); Console.WriteLine(S.Length <= K ? S : S.Substring(0, K) + "..."); } public static void C() { var A = Read.Int(); var B = Read.Int(); var H = Read.Int(); var M = Read.Int(); var r1 = Math.PI * (H * 60 + M) / 360; var r2 = Math.PI * M / 30; var x1 = Math.Cos(r1) * A; var y1 = Math.Sin(r1) * A; var x2 = Math.Cos(r2) * B; var y2 = Math.Sin(r2) * B; Console.WriteLine(Math.Sqrt( Math.Max(0, (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)))); } public static void D() { var N = Read.Int(); var M = Read.Int(); var Adj = Read.AdjacencyList(N, M); var ans = Enumerable.Range(0, N + 1).Select(i => -1).ToArray(); var queue = new Queue<int>(); queue.Enqueue(1); while (queue.Count > 0) { var v = queue.Dequeue(); foreach (var w in Adj[v]) { if (ans[w] >= 0) { continue; } ans[w] = v; queue.Enqueue(w); } } if (ans.Skip(2).Count(x => x < 0) > 0) { Console.WriteLine("No"); return; } Console.WriteLine("Yes"); Console.WriteLine(String.Join(Environment.NewLine, ans.Skip(2))); } public static void E() { var N = Read.Int(); var AB = Read.TupleLong(N); var Zero = new List<Tuple<long, long>>(); var D1 = new List<Tuple<long, long>>(); var D2 = new List<Tuple<long, long>>(); var count1 = new Dictionary<long, Dictionary<long, long>>(); var count2 = new Dictionary<long, Dictionary<long, long>>(); foreach (var t in AB) { var X = t.Item1; var Y = t.Item2; if (X == 0 && Y == 0) { Zero.Add(new Tuple<long, long>(0, 0)); continue; } if (Y < 0) { X *= -1; Y *= -1; } var gcd = Util.GCD(Math.Abs(X), Y); X /= gcd; Y /= gcd; if (Y == 0) { X = 1; } if (X == 0) { Y = 1; } if (X > 0) { if (!count1.ContainsKey(X)) { count1.Add(X, new Dictionary<long, long>()); } if (!count1[X].ContainsKey(Y)) { count1[X].Add(Y, 0); } count1[X][Y]++; } else { if (!count2.ContainsKey(X)) { count2.Add(X, new Dictionary<long, long>()); } if (!count2[X].ContainsKey(Y)) { count2[X].Add(Y, 0); } count2[X][Y]++; } } MOD two = 2; MOD ans = 1; foreach (var kvp1 in count1) { foreach (var kvp2 in kvp1.Value) { var X = kvp1.Key; var Y = kvp2.Key; var C = kvp2.Value; if (count2.ContainsKey(-Y) && count2[-Y].ContainsKey(X)) { var C2 = count2[-Y][X]; count2[-Y][X] = 0; ans = ans * (two.Power(C) + two.Power(C2) - 1); } else { ans = ans * (two.Power(C) - 0); } } } foreach (var kvp1 in count2) { foreach (var kvp2 in kvp1.Value) { ans = ans * two.Power(kvp2.Value); } } Console.WriteLine((ans + Zero.Count - 1).V); } public static void F() {} } class Util { public static long[] ASum(long[] array) { var res = new long[array.Length + 1]; for (int i = 0; i < array.Length; ++i) { res[i + 1] = res[i] + array[i]; } return res; } public static Dictionary<T, long> Frequency<T>(T[] array) { var dict = new Dictionary<T, long>(); foreach (var a in array) { if (!dict.ContainsKey(a)) { dict.Add(a, 0); } dict[a]++; } return dict; } public static long GCD(long a, long b) { while (b > 0) { var c = a % b; a = b; b = c; } return a; } } struct MOD { public static long P = 1000000007; public readonly long V; public MOD(long a) { this.V = a % P; } public static implicit operator MOD(long a) { return new MOD(a); } public static MOD operator +(MOD a, MOD b) { return new MOD((a.V + b.V) % P); } public static MOD operator -(MOD a, MOD b) { return new MOD((a.V - b.V + P) % P); } public static MOD operator *(MOD a, MOD b) { return new MOD((a.V * b.V) % P); } public static MOD operator /(MOD a, MOD b) { return new MOD((a.V * b.Inverse().V) % P); } public MOD Inverse() { long a = V, p = P; long b = p, c = 1, d = 0, e = 0, f = 0; while (b != 0) { e = a / b; f = b; b = a - e * b; a = f; f = d; d = c - e * d; c = f; } c %= p; return c + (c < 0 ? p : 0); } public MOD Power(long n) { long a = V, p = P; long res = 1; long mult = a; for (int i = 0; i < 63; ++i) { if ((n & ((long)1 << i)) > 0) { res = (res * mult) % p; } mult = (mult * mult) % p; } return res; } public override string ToString() { return V.ToString(); } } static class Read { static Queue<string> queue = new Queue<string>(); static void Enqueue() { var ss = Console.ReadLine().Split(' '); foreach (var s in ss) { queue.Enqueue(s); } } public static int Int() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt32(queue.Dequeue()); } public static long Long() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt64(queue.Dequeue()); } public static string Str() { if (queue.Count == 0) { Enqueue(); } return queue.Dequeue(); } public static int[] IntN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt32(s)) .ToArray(); } public static long[] LongN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt64(s)) .ToArray(); } public static ulong[] ULongN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToUInt64(s)) .ToArray(); } public static string[] StrN() { return Console.ReadLine().Split(' '); } public static Tuple<int, int>[] TupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = Read.IntN(); list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<long, long>[] TupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<string, string>[] TupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = Read.StrN(); list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<double, double>[] TupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); } public static long[,] LongMatrix(int r, int c) { var mat = new long[r, c]; for (int i = 0; i < r; ++i) { var x = Read.LongN(); for (int j = 0; j < c; ++j) { mat[i, j] = x[j]; } } return mat; } public static Dictionary<int, HashSet<int>> AdjacencyList(int N, int M, bool isDirectional = false) { Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new HashSet<int>()); } for (int i = 0; i < M; ++i) { var ab = Read.IntN(); if (!dict[ab[0]].Contains(ab[1])) { dict[ab[0]].Add(ab[1]); } if (!isDirectional && !dict[ab[1]].Contains(ab[0])) { dict[ab[1]].Add(ab[0]); } } return dict; } public static Dictionary<int, Dictionary<int, long>> AdjacencyListWithWeight(int N, int M) { Dictionary<int, Dictionary<int, long>> dict = new Dictionary<int, Dictionary<int, long>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new Dictionary<int, long>()); } for (int i = 0; i < M; ++i) { var ab = Read.IntN(); dict[ab[0]].Add(ab[1], ab[2]); dict[ab[1]].Add(ab[0], ab[2]); } return dict; } } } }
[["+", 0, 210, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 25], ["+", 0, 210, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 210, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 210, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 24], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 17, 47]]
8
2,765
26
using System; using System.Collections.Generic; using System.Linq; namespace ABC168F { class Program { static void Main(string[] args) { var NM = ReadInt(); int N = NM[0]; int M = NM[1]; var A = new List<int>(); // x var B = new List<int>(); // x var C = new List<int>(); // y var D = new List<int>(); // x var E = new List<int>(); // y var F = new List<int>(); // y for (int i = 0; i < N; i++) { var input = ReadInt(); A.Add(input[0]); B.Add(input[1]); C.Add(input[2]); } for (int i = 0; i < M; i++) { var input = ReadInt(); D.Add(input[0]); E.Add(input[1]); F.Add(input[2]); } //座標圧縮 List<int> xList = new List<int>(); List<int> yList = new List<int>(); xList.AddRange(A); xList.AddRange(B); xList.AddRange(D); xList.Add(0); yList.AddRange(C); yList.AddRange(E); yList.AddRange(F); yList.Add(0); //牛原点 var toValueX = xList.Distinct().OrderBy(x => x).ToArray(); var toValueY = yList.Distinct().OrderBy(x => x).ToArray(); var indexFromValueTableX = toValueX.Select((value, index) => new { value, index }) .ToDictionary(p => p.value, p => p.index); var indexFromValueTableY = toValueY.Select((value, index) => new { value, index }) .ToDictionary(p => p.value, p => p.index); int countX = indexFromValueTableX.Count; int countY = indexFromValueTableY.Count; A = A.Select(v => indexFromValueTableX[v]).ToList(); B = B.Select(v => indexFromValueTableX[v]).ToList(); D = D.Select(v => indexFromValueTableX[v]).ToList(); C = C.Select(v => indexFromValueTableY[v]).ToList(); E = E.Select(v => indexFromValueTableY[v]).ToList(); F = F.Select(v => indexFromValueTableY[v]).ToList(); // int[,] map = new int[2 * countX, 2 * countY]; for (int i = 0; i < N; i++) { for (int x = 2 * A[i]; x <= 2 * B[i]; x++) { map[x, 2 * C[i]] = 1; } } for (int i = 0; i < M; i++) { for (int y = 2 * E[i]; y <= 2 * F[i]; y++) { map[2 * D[i], y] = 1; } } map[2 * indexFromValueTableX[0], 2 * indexFromValueTableY[0]] = 2; // DrawMapforDebug(map); // dfs long ans = 0; int[] dx = new int[] { -1, 0, 1, 0 }; int[] dy = new int[] { 0, 1, 0, -1 }; //接続部をすべて塗る Queue<int> queX = new Queue<int>(); Queue<int> queY = new Queue<int>(); queX.Enqueue(2 * indexFromValueTableX[0]); queY.Enqueue(2 * indexFromValueTableY[0]); while (queX.Count > 0) { // DrawMapforDebug(map); int px = queX.Dequeue(); int py = queY.Dequeue(); for (int k = 0; k < 4; k++) { int tx = px + dx[k]; int ty = py + dy[k]; if (tx < 0 || 2 * countX - 1 <= tx || ty < 0 || 2 * countY - 1 <= ty) { ans = -1; break; } if (map[tx, ty] > 0) continue; long cand = 0; if (tx % 2 == 1 && ty % 2 == 1) cand = (long)(toValueX[tx / 2 + 1] - toValueX[tx / 2]) * (toValueY[ty / 2 + 1] - toValueY[ty / 2]); ans += cand; queX.Enqueue(tx); queY.Enqueue(ty); map[tx, ty] = 2; } } if (ans != -1) Console.WriteLine(ans); else Console.WriteLine("INF"); Console.ReadKey(); } /// <summary> /// 二次元配列の可視化メソッド /// </summary> /// <param name="map"></param> static void DrawMapforDebug(int[,] map) { int W = map.GetLength(0); int H = map.GetLength(1); int[,] map2 = new int[W + 1, H + 1]; for (int i = 0; i < W + 1; i++) { for (int j = 0; j < H + 1; j++) { if (i == 0 && j == 0) map[i, j] = 0; else if (i == 0) map2[i, j] = j - 1; else if (j == 0) map2[i, j] = i - 1; else map2[i, j] = map[i - 1, j - 1]; } } for (int i = 0; i < W + 1; i++) { for (int j = 0; j < H + 1; j++) { Console.Write(map2[i, j] % 10); } Console.WriteLine(); } Console.WriteLine(); } static int[] ReadInt() { int[] ret = Console.ReadLine().Split().Select(int.Parse).ToArray(); return ret; } static long[] ReadLong() { long[] ret = Console.ReadLine().Split().Select(long.Parse).ToArray(); return ret; } } }
using System; using System.Collections.Generic; using System.Linq; namespace ABC168F { class Program { static void Main(string[] args) { var NM = ReadInt(); int N = NM[0]; int M = NM[1]; var A = new List<int>(); // x var B = new List<int>(); // x var C = new List<int>(); // y var D = new List<int>(); // x var E = new List<int>(); // y var F = new List<int>(); // y for (int i = 0; i < N; i++) { var input = ReadInt(); A.Add(input[0]); B.Add(input[1]); C.Add(input[2]); } for (int i = 0; i < M; i++) { var input = ReadInt(); D.Add(input[0]); E.Add(input[1]); F.Add(input[2]); } //座標圧縮 List<int> xList = new List<int>(); List<int> yList = new List<int>(); xList.AddRange(A); xList.AddRange(B); xList.AddRange(D); xList.Add(0); yList.AddRange(C); yList.AddRange(E); yList.AddRange(F); yList.Add(0); //牛原点 var toValueX = xList.Distinct().OrderBy(x => x).ToArray(); var toValueY = yList.Distinct().OrderBy(x => x).ToArray(); var indexFromValueTableX = toValueX.Select((value, index) => new { value, index }) .ToDictionary(p => p.value, p => p.index); var indexFromValueTableY = toValueY.Select((value, index) => new { value, index }) .ToDictionary(p => p.value, p => p.index); int countX = indexFromValueTableX.Count; int countY = indexFromValueTableY.Count; A = A.Select(v => indexFromValueTableX[v]).ToList(); B = B.Select(v => indexFromValueTableX[v]).ToList(); D = D.Select(v => indexFromValueTableX[v]).ToList(); C = C.Select(v => indexFromValueTableY[v]).ToList(); E = E.Select(v => indexFromValueTableY[v]).ToList(); F = F.Select(v => indexFromValueTableY[v]).ToList(); // int[,] map = new int[2 * countX, 2 * countY]; for (int i = 0; i < N; i++) { for (int x = 2 * A[i]; x <= 2 * B[i]; x++) { map[x, 2 * C[i]] = 1; } } for (int i = 0; i < M; i++) { for (int y = 2 * E[i]; y <= 2 * F[i]; y++) { map[2 * D[i], y] = 1; } } map[2 * indexFromValueTableX[0], 2 * indexFromValueTableY[0]] = 2; // DrawMapforDebug(map); // dfs long ans = 0; int[] dx = new int[] { -1, 0, 1, 0 }; int[] dy = new int[] { 0, 1, 0, -1 }; //接続部をすべて塗る Queue<int> queX = new Queue<int>(); Queue<int> queY = new Queue<int>(); queX.Enqueue(2 * indexFromValueTableX[0]); queY.Enqueue(2 * indexFromValueTableY[0]); while (queX.Count > 0) { // DrawMapforDebug(map); int px = queX.Dequeue(); int py = queY.Dequeue(); for (int k = 0; k < 4; k++) { int tx = px + dx[k]; int ty = py + dy[k]; if (map[tx, ty] > 0) continue; if (tx <= 0 || 2 * countX - 1 <= tx || ty <= 0 || 2 * countY - 1 <= ty) { ans = -1; queX.Clear(); // whileからも抜ける break; } long cand = 0; if (tx % 2 == 1 && ty % 2 == 1) cand = (long)(toValueX[tx / 2 + 1] - toValueX[tx / 2]) * (toValueY[ty / 2 + 1] - toValueY[ty / 2]); ans += cand; queX.Enqueue(tx); queY.Enqueue(ty); map[tx, ty] = 2; } } if (ans != -1) Console.WriteLine(ans); else Console.WriteLine("INF"); Console.ReadKey(); } /// <summary> /// 二次元配列の可視化メソッド /// </summary> /// <param name="map"></param> static void DrawMapforDebug(int[,] map) { int W = map.GetLength(0); int H = map.GetLength(1); int[,] map2 = new int[W + 1, H + 1]; for (int i = 0; i < W + 1; i++) { for (int j = 0; j < H + 1; j++) { if (i == 0 && j == 0) map2[i, j] = 0; else if (i == 0) map2[i, j] = j - 1; else if (j == 0) map2[i, j] = i - 1; else map2[i, j] = map[i - 1, j - 1]; } } for (int i = 0; i < W + 1; i++) { for (int j = 0; j < H + 1; j++) { Console.Write(map2[i, j] % 10); } Console.WriteLine(); } Console.WriteLine(); } static int[] ReadInt() { int[] ret = Console.ReadLine().Split().Select(int.Parse).ToArray(); return ret; } static long[] ReadLong() { long[] ret = Console.ReadLine().Split().Select(long.Parse).ToArray(); return ret; } } }
[["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["-", 15, 16, 31, 16, 31, 16, 31, 16, 17, 18], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 21], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 116, 0, 117], ["+", 0, 7, 8, 196, 0, 57, 64, 116, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 15, 16, 31, 16, 31, 16, 31, 16, 31, 22], ["+", 15, 16, 31, 16, 31, 16, 31, 16, 17, 19], ["+", 15, 16, 31, 16, 31, 16, 31, 16, 12, 203], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 17, 18], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 19], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["-", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["-", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 57, 15, 16, 31, 204, 206, 207, 0, 21], ["-", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 0, 7, 8, 196, 0, 57, 64, 116, 0, 117], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 57, 64, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 57, 64, 1, 0, 11, 31, 204, 205, 22]]
8
1,337
38
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { class A_167_Registration { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // 文字列の入力 string s = Console.ReadLine(); string t = Console.ReadLine(); string result; s = s + t.Substring(t.Length - 1, 1); if (s == t) { result = "Yes"; Console.WriteLine(result); } else { result = "No"; Console.WriteLine(result); } Console.Out.Flush(); Console.WriteLine(result); Console.Out.Flush(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { class A_167_Registration { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // 文字列の入力 string s = Console.ReadLine(); string t = Console.ReadLine(); string result; s = s + t.Substring(t.Length - 1, 1); if (s == t) { result = "Yes"; Console.WriteLine(result); } else { result = "No"; Console.WriteLine(result); } Console.Out.Flush(); } } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 0, 1, 0, 213, 63, 214, 205, 214, 205, 22], ["-", 0, 1, 0, 213, 63, 214, 205, 214, 0, 131], ["-", 0, 1, 0, 213, 63, 214, 205, 214, 141, 22]]
8
177
15
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { class A_Registration_167 { // https://atcoder.jp/contests/abc167/tasks/abc167_a public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // 文字列配列の入力 string[] inputStrArray = Console.ReadLine().Split(' '); string s = inputStrArray[0]; string t = inputStrArray[1]; string result; s = s + t.Substring(t.Length - 1, 1); if (s == t) { result = "Yes"; Console.WriteLine(result); } else { result = "No"; Console.WriteLine(result); } Console.Out.Flush(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { class A_Registration_167 { // https://atcoder.jp/contests/abc167/tasks/abc167_a public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); string s = Console.ReadLine(); string t = Console.ReadLine(); string result; s = s + t.Substring(t.Length - 1, 1); if (s == t) { result = "Yes"; Console.WriteLine(result); } else { result = "No"; Console.WriteLine(result); } Console.Out.Flush(); } } }
[["-", 0, 197, 0, 198, 39, 224, 225, 226, 0, 70], ["-", 0, 197, 0, 198, 39, 224, 225, 226, 0, 73], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 252, 0, 104], ["-", 0, 213, 3, 4, 0, 28, 0, 252, 0, 253], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["-", 0, 200, 0, 212, 0, 204, 206, 207, 0, 70], ["-", 0, 212, 0, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 200, 0, 212, 0, 204, 206, 207, 0, 73], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25]]
8
179
28
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { class A_167_Registration { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // 文字列配列の入力 string[] inputStrArray = Console.ReadLine().Split(' '); string result; if (inputStrArray[0] == inputStrArray[1].Substring(0, inputStrArray[0].Length)) { result = "Yes"; } else { result = "No"; } Console.WriteLine(result); Console.Out.Flush(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { class A_167_Registration { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // 文字列の入力 string S = Console.ReadLine(); string T = Console.ReadLine(); string result; if (S == T.Substring(0, S.Length)) { result = "Yes"; } else { result = "No"; } Console.WriteLine(result); Console.Out.Flush(); } } }
[["-", 0, 197, 0, 198, 39, 224, 225, 226, 0, 70], ["-", 0, 197, 0, 198, 39, 224, 225, 226, 0, 73], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 252, 0, 104], ["-", 0, 213, 3, 4, 0, 28, 0, 252, 0, 253], ["-", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["-", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["-", 15, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 15, 16, 12, 213, 63, 214, 205, 204, 205, 22], ["-", 12, 213, 63, 214, 205, 204, 206, 207, 0, 70], ["-", 63, 214, 205, 204, 206, 207, 0, 28, 0, 203], ["-", 12, 213, 63, 214, 205, 204, 206, 207, 0, 73], ["+", 0, 57, 15, 16, 12, 213, 63, 214, 205, 22], ["-", 3, 4, 0, 28, 0, 214, 205, 204, 205, 22], ["-", 0, 28, 0, 214, 205, 204, 206, 207, 0, 70], ["-", 0, 214, 205, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 28, 0, 214, 205, 204, 206, 207, 0, 73], ["+", 12, 213, 3, 4, 0, 28, 0, 214, 205, 22]]
8
156
29
using System; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { string S = Console.ReadLine(); string T = Console.ReadLine(); if (T.Contains(S)) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
using System; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { string S = Console.ReadLine(); string T = Console.ReadLine(); if (S == T.Substring(0, S.Length)) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 8, 196, 0, 57, 15, 213, 63, 214, 141, 22], ["+", 0, 57, 15, 16, 12, 213, 63, 214, 141, 22], ["+", 15, 16, 12, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 57, 15, 16, 12, 213, 3, 4, 0, 21], ["+", 12, 213, 3, 4, 0, 28, 0, 214, 0, 131], ["+", 12, 213, 3, 4, 0, 28, 0, 214, 141, 22]]
8
77
8
using System; public class Hello { public static void Main() { var s = Console.ReadLine(); var t = Console.ReadLine(); if (t.StartsWith(s)) { if (s.Length + 1 == t.Length) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
using System; public class Hello { public static void Main() { var s = Console.ReadLine(); var t = Console.ReadLine(); if (t.StartsWith(s)) { if (s.Length + 1 == t.Length) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } else { Console.WriteLine("No"); } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
80
12
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { public class QuestionA { /// <summary> /// A - Registration /// https://atcoder.jp/contests/abc167/tasks/abc167_a /// </summary> /// <param name="args"></param> public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // 文字列の入力 string str_S = Console.ReadLine(); string str_T = Console.ReadLine(); int num_Length = str_S.Length; if (str_T.Substring(0, num_Length) == str_S) Console.WriteLine("Yes"); else Console.WriteLine("No"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { public class QuestionA { /// <summary> /// A - Registration /// https://atcoder.jp/contests/abc167/tasks/abc167_a /// </summary> /// <param name="args"></param> public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // 文字列の入力 string str_S = Console.ReadLine(); string str_T = Console.ReadLine(); int num_Length = str_S.Length; string kkk = str_T.Substring(0, num_Length); if (str_T.Substring(0, num_Length) == str_S) Console.WriteLine("Yes"); else Console.WriteLine("No"); Console.Out.Flush(); } } }
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 57, 75, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 75, 1, 0, 35], ["+", 0, 1, 0, 213, 63, 214, 205, 214, 205, 22], ["+", 0, 1, 0, 213, 63, 214, 205, 214, 0, 131], ["+", 0, 1, 0, 213, 63, 214, 205, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24]]
8
142
20
using System; namespace ConsoleApp3 { class Program { static void Main(string[] args) { string S = Console.ReadLine().Trim(); string T = Console.ReadLine().Trim(); var correct = S == T.Substring(0, T.Length - 1); Console.WriteLine(correct); } } }
using System; namespace ConsoleApp3 { class Program { static void Main(string[] args) { string S = Console.ReadLine().Trim(); string T = Console.ReadLine().Trim(); var correct = S == T.Substring(0, T.Length - 1); Console.WriteLine(correct ? "Yes" : "No"); } } }
[["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 62], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 62], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222]]
8
73
8
using System; using System.Collections.Generic; using System.ComponentModel.Design; using System.Globalization; using System.IO.Compression; using System.IO.Pipes; using System.Linq; using System.Numerics; using System.Text; using static System.Console; using static System.Math; namespace AtCoder { class Program { static void Main(string[] args) { var S = Read(); var T = Read(); var a = T.Replace(S, ""); if (a.Count() == 1) WriteLine("Yes"); else WriteLine("No"); } 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); } } }
using System; using System.Collections.Generic; using System.ComponentModel.Design; using System.Globalization; using System.IO.Compression; using System.IO.Pipes; using System.Linq; using System.Numerics; using System.Text; using static System.Console; using static System.Math; namespace AtCoder { class Program { static void Main(string[] args) { var S = Read(); var T = Read(); var lastchar = T[T.Length - 1]; if (S + lastchar == T) { WriteLine("Yes"); } else { WriteLine("No"); } } 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); } } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 70], ["+", 206, 207, 0, 28, 0, 16, 31, 214, 205, 22], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["-", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 206, 207, 0, 28, 0, 16, 31, 214, 141, 22], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 73], ["-", 0, 57, 15, 16, 31, 213, 63, 214, 205, 22], ["-", 0, 57, 15, 16, 31, 213, 63, 214, 0, 131], ["-", 0, 57, 15, 16, 31, 213, 63, 214, 141, 22], ["-", 0, 57, 15, 16, 31, 213, 3, 4, 0, 24], ["-", 0, 57, 15, 16, 31, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 72], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
306
29
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; using System.Text.RegularExpressions; namespace Yuzuki { class Yukari { public static void Main(string[] args) { string s, t; s = Console.ReadLine(); t = Console.ReadLine(); Console.WriteLine(s.Length + 1 == t.Length && t.Contains(s) ? "Yes" : "No"); } } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; using System.Text.RegularExpressions; namespace Yuzuki { class Yukari { public static void Main(string[] args) { string s, t; s = Console.ReadLine(); t = Console.ReadLine(); Console.WriteLine( s.Length + 1 == t.Length && t.Substring(0, t.Length - 1) == s ? "Yes" : "No"); } } }
[["-", 0, 41, 15, 16, 12, 213, 63, 214, 141, 22], ["+", 15, 16, 12, 16, 31, 213, 63, 214, 141, 22], ["-", 15, 16, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 12, 16, 31, 213, 3, 4, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 31, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 16, 31, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 16, 31, 214, 141, 22], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 28, 0, 41, 15, 16, 12, 16, 17, 60], ["+", 0, 28, 0, 41, 15, 16, 12, 16, 12, 22]]
8
115
12
using System; using System.IO; using System.Linq; using System.Collections.Generic; using System.Text; using System.Numerics; namespace abc167 { class Program { static void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); if (File.Exists("input.txt")) { Console.SetIn(new StreamReader("input.txt")); } solve_abc167A(); Console.Out.Flush(); } public static void solve_abc167B() {} public static void solve_abc167A() { string a = Console.ReadLine(); string b = Console.ReadLine(); Console.WriteLine(b.Contains(a) ? "Yes" : "No"); } } }
using System; using System.IO; using System.Linq; using System.Collections.Generic; using System.Text; using System.Numerics; namespace abc167 { class Program { static void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); if (File.Exists("input.txt")) { Console.SetIn(new StreamReader("input.txt")); } solve_abc167A(); Console.Out.Flush(); } public static void solve_abc167B() {} public static void solve_abc167A() { string a = Console.ReadLine(); string b = Console.ReadLine(); Console.WriteLine(a.Equals(b.Substring(0, b.Length - 1)) ? "Yes" : "No"); } } }
[["+", 0, 28, 0, 41, 15, 213, 63, 214, 205, 22], ["+", 0, 28, 0, 41, 15, 213, 63, 214, 0, 131], ["+", 0, 28, 0, 41, 15, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 41, 15, 213, 3, 4, 0, 24], ["-", 0, 28, 0, 41, 15, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 0, 41, 15, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 16, 31, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 16, 31, 214, 141, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
161
15
using System; namespace AtCoder { internal static class Program { private static void Main() { string s = Console.ReadLine(); string t = Console.ReadLine(); bool res = true; if (s.Length == t.Length - 1) { for (int i = 0; i < s.Length; i++) { if (s[i] != t[i]) res = false; } } else res = false; Console.WriteLine(res); } } }
using System; namespace AtCoder { internal static class Program { private static void Main() { string s = Console.ReadLine(); string t = Console.ReadLine(); bool res = true; if (s.Length == t.Length - 1) { for (int i = 0; i < s.Length; i++) { if (s[i] != t[i]) res = false; } } else res = false; if (res == true) Console.WriteLine("Yes"); else Console.WriteLine("No"); } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 211, 0, 146], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 57, 75, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 75, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 75, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 75, 1, 0, 213, 3, 4, 0, 24]]
8
104
20
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Text; using System.Linq; using E = System.Linq.Enumerable; internal partial class Solver { public void Run() { var s = ns(); var t = ns(); cout.WriteLine(t.StartsWith(t) && s.Length + 1 == t.Length ? "Yes" : "No"); } } // PREWRITEN CODE BEGINS FROM HERE internal partial class Solver : Scanner { public static void Main() { #if LOCAL byte[] inputBuffer = new byte[1000000]; var inputStream = Console.OpenStandardInput(inputBuffer.Length); using (var reader = new StreamReader(inputStream, Console.InputEncoding, false, inputBuffer.Length)) { Console.SetIn(reader); new Solver(Console.In, Console.Out).Run(); } #else Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new Solver(Console.In, Console.Out).Run(); Console.Out.Flush(); #endif } #pragma warning disable IDE0052 private readonly TextReader cin; private readonly TextWriter cout; #pragma warning restore IDE0052 public Solver(TextReader reader, TextWriter writer) : base(reader) { cin = reader; cout = writer; } public Solver(string input, TextWriter writer) : this(new StringReader(input), writer) {} #pragma warning disable IDE1006 #pragma warning disable IDE0051 private int ni() { return NextInt(); } private int[] ni(int n) { return NextIntArray(n); } private long nl() { return NextLong(); } private long[] nl(int n) { return NextLongArray(n); } private double nd() { return NextDouble(); } private double[] nd(int n) { return NextDoubleArray(n); } private string ns() { return Next(); } private string[] ns(int n) { return NextArray(n); } #pragma warning restore IDE1006 #pragma warning restore IDE0051 } internal static class LinqPadExtension { [Conditional("DEBUG")] public static void Dump<T>(this T obj) { #if DEBUG LINQPad.Extensions.Dump(obj); #endif } } public class Scanner { private readonly TextReader Reader; private readonly CultureInfo ci = CultureInfo.InvariantCulture; private readonly char[] buffer = new char[2 * 1024]; private int cursor = 0, length = 0; private string Token; private readonly StringBuilder sb = new StringBuilder(1024); public Scanner() : this(Console.In) {} public Scanner(TextReader reader) { Reader = reader; } public int NextInt() { return checked((int)NextLong()); } public long NextLong() { var s = Next(); long r = 0; int i = 0; bool negative = false; if (s[i] == '-') { negative = true; i++; } for (; i < s.Length; i++) { r = r * 10 + (s[i] - '0'); #if DEBUG if (!char.IsDigit(s[i])) throw new FormatException(); #endif } return negative ? -r : r; } public double NextDouble() { return double.Parse(Next(), ci); } public string[] NextArray(int size) { string[] array = new string[size]; for (int i = 0; i < size; i++) { array[i] = Next(); } return array; } public int[] NextIntArray(int size) { int[] array = new int[size]; for (int i = 0; i < size; i++) { array[i] = NextInt(); } return array; } public long[] NextLongArray(int size) { long[] array = new long[size]; for (int i = 0; i < size; i++) { array[i] = NextLong(); } return array; } public double[] NextDoubleArray(int size) { double[] array = new double[size]; for (int i = 0; i < size; i++) { array[i] = NextDouble(); } return array; } public string Next() { if (Token == null) { if (!StockToken()) { throw new Exception(); } } var token = Token; Token = null; return token; } public bool HasNext() { if (Token != null) { return true; } return StockToken(); } private bool StockToken() { while (true) { sb.Clear(); while (true) { if (cursor >= length) { cursor = 0; if ((length = Reader.Read(buffer, 0, buffer.Length)) <= 0) { break; } } var c = buffer[cursor++]; if (33 <= c && c <= 126) { sb.Append(c); } else { if (sb.Length > 0) break; } } if (sb.Length > 0) { Token = sb.ToString(); return true; } return false; } } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Text; using System.Linq; using E = System.Linq.Enumerable; internal partial class Solver { public void Run() { var s = ns(); var t = ns(); cout.WriteLine(t.Remove(t.Length - 1, 1) == s ? "Yes" : "No"); } } // PREWRITEN CODE BEGINS FROM HERE internal partial class Solver : Scanner { public static void Main() { #if LOCAL byte[] inputBuffer = new byte[1000000]; var inputStream = Console.OpenStandardInput(inputBuffer.Length); using (var reader = new StreamReader(inputStream, Console.InputEncoding, false, inputBuffer.Length)) { Console.SetIn(reader); new Solver(Console.In, Console.Out).Run(); } #else Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new Solver(Console.In, Console.Out).Run(); Console.Out.Flush(); #endif } #pragma warning disable IDE0052 private readonly TextReader cin; private readonly TextWriter cout; #pragma warning restore IDE0052 public Solver(TextReader reader, TextWriter writer) : base(reader) { cin = reader; cout = writer; } public Solver(string input, TextWriter writer) : this(new StringReader(input), writer) {} #pragma warning disable IDE1006 #pragma warning disable IDE0051 private int ni() { return NextInt(); } private int[] ni(int n) { return NextIntArray(n); } private long nl() { return NextLong(); } private long[] nl(int n) { return NextLongArray(n); } private double nd() { return NextDouble(); } private double[] nd(int n) { return NextDoubleArray(n); } private string ns() { return Next(); } private string[] ns(int n) { return NextArray(n); } #pragma warning restore IDE1006 #pragma warning restore IDE0051 } internal static class LinqPadExtension { [Conditional("DEBUG")] public static void Dump<T>(this T obj) { #if DEBUG LINQPad.Extensions.Dump(obj); #endif } } public class Scanner { private readonly TextReader Reader; private readonly CultureInfo ci = CultureInfo.InvariantCulture; private readonly char[] buffer = new char[2 * 1024]; private int cursor = 0, length = 0; private string Token; private readonly StringBuilder sb = new StringBuilder(1024); public Scanner() : this(Console.In) {} public Scanner(TextReader reader) { Reader = reader; } public int NextInt() { return checked((int)NextLong()); } public long NextLong() { var s = Next(); long r = 0; int i = 0; bool negative = false; if (s[i] == '-') { negative = true; i++; } for (; i < s.Length; i++) { r = r * 10 + (s[i] - '0'); #if DEBUG if (!char.IsDigit(s[i])) throw new FormatException(); #endif } return negative ? -r : r; } public double NextDouble() { return double.Parse(Next(), ci); } public string[] NextArray(int size) { string[] array = new string[size]; for (int i = 0; i < size; i++) { array[i] = Next(); } return array; } public int[] NextIntArray(int size) { int[] array = new int[size]; for (int i = 0; i < size; i++) { array[i] = NextInt(); } return array; } public long[] NextLongArray(int size) { long[] array = new long[size]; for (int i = 0; i < size; i++) { array[i] = NextLong(); } return array; } public double[] NextDoubleArray(int size) { double[] array = new double[size]; for (int i = 0; i < size; i++) { array[i] = NextDouble(); } return array; } public string Next() { if (Token == null) { if (!StockToken()) { throw new Exception(); } } var token = Token; Token = null; return token; } public bool HasNext() { if (Token != null) { return true; } return StockToken(); } private bool StockToken() { while (true) { sb.Clear(); while (true) { if (cursor >= length) { cursor = 0; if ((length = Reader.Read(buffer, 0, buffer.Length)) <= 0) { break; } } var c = buffer[cursor++]; if (33 <= c && c <= 126) { sb.Append(c); } else { if (sb.Length > 0) break; } } if (sb.Length > 0) { Token = sb.ToString(); return true; } return false; } } }
[["-", 0, 41, 15, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 41, 15, 16, 31, 213, 63, 214, 141, 22], ["-", 0, 41, 15, 16, 31, 213, 3, 4, 0, 25], ["-", 3, 4, 0, 28, 0, 41, 15, 16, 17, 98], ["-", 15, 16, 12, 16, 31, 16, 31, 214, 205, 22], ["-", 0, 41, 15, 16, 12, 16, 31, 16, 17, 72], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 41, 15, 16, 31, 213, 3, 4, 0, 21], ["+", 0, 41, 15, 16, 31, 213, 3, 4, 0, 25], ["-", 0, 41, 15, 16, 12, 16, 12, 214, 205, 22], ["-", 0, 41, 15, 16, 12, 16, 12, 214, 0, 131], ["-", 0, 41, 15, 16, 12, 16, 12, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 22]]
8
1,112
14
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Text.RegularExpressions; namespace A { class Program { static void Main(string[] args) { string s = Console.ReadLine(); string t = Console.ReadLine(); bool s_is_alphabet = Regex.IsMatch(s, @"^[a-z]+$"); bool t_is_alphabet = Regex.IsMatch(t, @"^[a-z]+$"); if (s_is_alphabet && t_is_alphabet) { if (1 <= s.Length && s.Length <= 10 && t.Length == s.Length + 1) { if (s == t.Substring(0, t.Length - 1)) { Console.WriteLine("Yes"); } } } Console.WriteLine("No"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Text.RegularExpressions; namespace A { class Program { static void Main(string[] args) { string s = Console.ReadLine(); string t = Console.ReadLine(); bool s_is_alphabet = Regex.IsMatch(s, @"^[a-z]+$"); bool t_is_alphabet = Regex.IsMatch(t, @"^[a-z]+$"); bool ans = false; if (s_is_alphabet && t_is_alphabet) { if (1 <= s.Length && s.Length <= 10 && t.Length == s.Length + 1) { if (s == t.Substring(0, t.Length - 1)) { ans = true; } } } Console.WriteLine(ans ? "Yes" : "No"); } } }
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 211, 0, 147], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 211, 0, 146], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 15, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 62], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102]]
8
166
22
using System; using System.Text.RegularExpressions; class Program { static void Main(string[] args) { // S string strS = Console.ReadLine(); // T string strT = Console.ReadLine(); var reg = new Regex("[a-z]"); string resultS = reg.Replace(strS, ""); string resultT = reg.Replace(strT, ""); if ((strS.Length >= 1 && strS.Length <= 10) && (string.IsNullOrWhiteSpace(resultS) && string.IsNullOrWhiteSpace(resultT))) { if (strS.Length + 1 == strT.Length) { Console.WriteLine("Yes"); return; } } Console.WriteLine("No"); return; } }
using System; using System.Text.RegularExpressions; class Program { static void Main(string[] args) { // S string strS = Console.ReadLine(); // T string strT = Console.ReadLine(); var reg = new Regex("[a-z]"); string resultS = reg.Replace(strS, ""); string resultT = reg.Replace(strT, ""); if ((strS.Length >= 1 && strS.Length <= 10) && (string.IsNullOrWhiteSpace(resultS) && string.IsNullOrWhiteSpace(resultT)) && (strS == strT.Substring(0, strS.Length) && strS.Length + 1 == strT.Length)) { Console.WriteLine("Yes"); return; } Console.WriteLine("No"); return; } }
[["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 15, 16, 12, 23, 0, 16, 31, 16, 17, 60], ["+", 0, 16, 31, 16, 12, 213, 63, 214, 205, 22], ["+", 0, 16, 31, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 16, 31, 16, 12, 213, 3, 4, 0, 24], ["+", 31, 16, 12, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 16, 31, 16, 12, 213, 3, 4, 0, 21], ["+", 12, 213, 3, 4, 0, 28, 0, 214, 205, 22], ["+", 12, 213, 3, 4, 0, 28, 0, 214, 0, 131], ["+", 0, 16, 31, 16, 12, 213, 3, 4, 0, 25], ["+", 0, 57, 15, 16, 12, 23, 0, 16, 17, 98], ["+", 0, 16, 12, 16, 31, 16, 31, 214, 205, 22], ["+", 0, 16, 12, 16, 31, 16, 31, 214, 0, 131], ["+", 0, 16, 12, 16, 31, 16, 31, 214, 141, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 25], ["-", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46]]
8
152
19
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { string a = Console.ReadLine(); string b = Console.ReadLine(); int nagasa = a.Length; b = b.Remove(nagasa, 1); Console.WriteLine(b); if (a == b) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { string a = Console.ReadLine(); string b = Console.ReadLine(); int nagasa = a.Length; b = b.Remove(nagasa, 1); if (a == b) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
114
7
using System; using System.Linq; using System.Collections.Generic; using System.Text; public class Program { public static void Main(string[] args) { new A().test(); } } public class A { public void test() { // 普通の文字列 var before = CommonRead.ReadStr(); var after = CommonRead.ReadStr(); if (after.Length == before.Length + 1 && after.Contains(before)) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } static class CommonRead { public static string ReadStr() { return Console.ReadLine(); } public static string[] ReadStrA() { return ReadStr().Split(' '); } public static List<string> ReadStrL() { return ReadStrA().ToList(); } public static int ReadInt() { return Convert.ToInt32(ReadStr()); } public static int[] ReadIntA() { return ReadStrA().Select(s => Convert.ToInt32(s)).ToArray(); } public static List<int> ReadIntL() { return ReadStrA().Select(s => Convert.ToInt32(s)).ToList(); } public static long ReadLong() { return Convert.ToInt64(ReadStr()); } public static long[] ReadLongA() { return ReadStrA().Select(s => Convert.ToInt64(s)).ToArray(); } public static List<long> ReadLongL() { return ReadStrA().Select(s => Convert.ToInt64(s)).ToList(); } public static decimal ReadDecimal() { return Convert.ToDecimal(ReadStr()); } public static decimal[] ReadDecimalA() { return ReadStrA().Select(s => Convert.ToDecimal(s)).ToArray(); } public static List<decimal> ReadDecimalL() { return ReadStrA().Select(s => Convert.ToDecimal(s)).ToList(); } public static double ReadDouble() { return Convert.ToDouble(ReadStr()); } public static double[] ReadDoubleA() { return ReadStrA().Select(s => Convert.ToDouble(s)).ToArray(); } public static List<double> ReadDoubleL() { return ReadStrA().Select(s => Convert.ToDouble(s)).ToList(); } }
using System; using System.Linq; using System.Collections.Generic; using System.Text; public class Program { public static void Main(string[] args) { new A().test(); } } public class A { public void test() { // 普通の文字列 var before = CommonRead.ReadStr(); var after = CommonRead.ReadStr(); if (after.Length == before.Length + 1 && before.Equals(after.Substring(0, after.Length - 1))) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } static class CommonRead { public static string ReadStr() { return Console.ReadLine(); } public static string[] ReadStrA() { return ReadStr().Split(' '); } public static List<string> ReadStrL() { return ReadStrA().ToList(); } public static int ReadInt() { return Convert.ToInt32(ReadStr()); } public static int[] ReadIntA() { return ReadStrA().Select(s => Convert.ToInt32(s)).ToArray(); } public static List<int> ReadIntL() { return ReadStrA().Select(s => Convert.ToInt32(s)).ToList(); } public static long ReadLong() { return Convert.ToInt64(ReadStr()); } public static long[] ReadLongA() { return ReadStrA().Select(s => Convert.ToInt64(s)).ToArray(); } public static List<long> ReadLongL() { return ReadStrA().Select(s => Convert.ToInt64(s)).ToList(); } public static decimal ReadDecimal() { return Convert.ToDecimal(ReadStr()); } public static decimal[] ReadDecimalA() { return ReadStrA().Select(s => Convert.ToDecimal(s)).ToArray(); } public static List<decimal> ReadDecimalL() { return ReadStrA().Select(s => Convert.ToDecimal(s)).ToList(); } public static double ReadDouble() { return Convert.ToDouble(ReadStr()); } public static double[] ReadDoubleA() { return ReadStrA().Select(s => Convert.ToDouble(s)).ToArray(); } public static List<double> ReadDoubleL() { return ReadStrA().Select(s => Convert.ToDouble(s)).ToList(); } }
[["+", 0, 57, 15, 16, 12, 213, 63, 214, 205, 22], ["+", 0, 57, 15, 16, 12, 213, 63, 214, 0, 131], ["+", 0, 57, 15, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 57, 15, 16, 12, 213, 3, 4, 0, 24], ["-", 0, 57, 15, 16, 12, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 15, 16, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 16, 31, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 16, 31, 214, 141, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
505
15
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; namespace B { 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 abck = Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); if (abck[3] <= abck[0]) { Console.WriteLine(abck[0]); return; } if (abck[3] <= abck[0] + abck[1]) { Console.WriteLine(abck[0]); return; } Console.WriteLine(abck[0] - Math.Min(abck[2], (abck[3] - (abck[0] + abck[1])))); } } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; namespace B { 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 abck = Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); if (abck[3] <= abck[0]) { Console.WriteLine(abck[3]); return; } if (abck[3] <= abck[0] + abck[1]) { Console.WriteLine(abck[0]); return; } Console.WriteLine( abck[0] - Math.Min(abck[2], (Math.Max(0, abck[3] - (abck[0] + abck[1]))))); } } }
[["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 23, 0, 213, 63, 214, 205, 22], ["+", 0, 28, 0, 23, 0, 213, 63, 214, 0, 131], ["+", 0, 28, 0, 23, 0, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 23, 0, 213, 3, 4, 0, 24], ["+", 0, 23, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 28, 0, 23, 0, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25]]
8
217
9
using System; using System.Collections.Generic; namespace Atc_0020 { class Program { static void Main(string[] args) { var s = Console.ReadLine(); long A = long.Parse(s.Split(' ')[0]); long B = long.Parse(s.Split(' ')[1]); long C = long.Parse(s.Split(' ')[2]); long K = long.Parse(s.Split(' ')[3]); long ans = 0; ans += A; if (0 < (K - A - B)) { ans -= ((K - A - B)); } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; namespace Atc_0020 { class Program { static void Main(string[] args) { var s = Console.ReadLine(); long A = long.Parse(s.Split(' ')[0]); long B = long.Parse(s.Split(' ')[1]); long C = long.Parse(s.Split(' ')[2]); long K = long.Parse(s.Split(' ')[3]); if (K <= A) { Console.WriteLine(K); return; } long ans = A; if (0 < (K - A - B)) { ans -= ((K - A - B)); } Console.WriteLine(ans); } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107]]
8
160
21
using System; using System.Linq; namespace _167_b { internal class EasyLinearProgramming { private static void Main(string[] args) { var abck = Console.ReadLine()?.Split(" ").Select(long.Parse).ToList(); if (abck == null) return; var a = abck[0]; var b = abck[1]; var c = abck[2]; var k = abck[3]; var remain = k; long sum = 0; if (remain > a) { remain -= a; sum += a * 1; } else { sum += a * 1; Console.WriteLine(sum); return; } if (remain > b) { remain -= b; sum += b * 0; } else { Console.WriteLine(sum); return; } sum += remain * -1; Console.WriteLine(sum); } } }
using System; using System.Linq; namespace _167_b { internal class EasyLinearProgramming { private static void Main(string[] args) { var abck = Console.ReadLine()?.Split(" ").Select(long.Parse).ToArray(); if (abck == null) return; var a = abck[0]; var b = abck[1]; var c = abck[2]; var k = abck[3]; var remain = k; long sum = 0; // 1のカード if (remain > a) { remain -= a; sum += a; } else { sum += remain; Console.WriteLine(sum); return; } // 0のカード if (remain > b) { remain -= b; } else { Console.WriteLine(sum); return; } // -1のカード sum -= remain; Console.WriteLine(sum); } } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["-", 75, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["-", 75, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["-", 75, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 12, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["-", 0, 1, 0, 11, 12, 16, 12, 241, 0, 33], ["-", 0, 1, 0, 11, 12, 16, 12, 241, 0, 203]]
8
187
19
using System; using System.Linq; class program { static void Main() { var abck = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); var a = abck[0]; var b = abck[1]; var k = abck[3]; if (a + b > k) { Console.Write(a); return; } else { Console.Write(2 * a + b - k); } } }
using System; using System.Linq; class program { static void Main() { var abck = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); var a = abck[0]; var b = abck[1]; var k = abck[3]; if (a > k) { Console.Write(k); } else if (a + b > k) { Console.Write(a); } else { Console.Write(2 * a + b - k); } } }
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 31, 22], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38]]
8
107
18
using System; using System.CodeDom.Compiler; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; class Program { static void Main(string[] args) { int[] ABCK = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray(); int A = ABCK[0]; int B = ABCK[1]; int C = ABCK[2]; int K = ABCK[3]; if (K <= A || K <= A + B) Console.WriteLine(K); else Console.WriteLine(A - (K - A - B)); } /// <summary> /// アナグラム /// </summary> /// <param name="word1"></param> /// <param name="word2"></param> /// <returns></returns> static bool IsAnagramOf(string word1, string word2) { return word1.OrderBy(x => x).SequenceEqual(word2.OrderBy(x => x)); } /// <summary> /// 最小公倍数 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static long Lcm(long a, long b) { return a * b / Gcd(a, b); } /// <summary> /// 最大公約数 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static long Gcd(long a, long b) { if (a < b) // 引数を入替えて自分を呼び出す return Gcd(b, a); while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } } // string s = Console.ReadLine(); // int[] intArray = Console.ReadLine().Split(' ').Select(i => // int.Parse(i)).ToArray(); int H = intArray[0]; int W = intArray[1]; int N = // int.Parse(Console.ReadLine()); List<int> A = new // List<int>(Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray()); // Boolean ok = false; // Console.WriteLine(ans); // Console.WriteLine("Yes"); // Console.WriteLine("No"); // Console.ReadKey(); // Console.WriteLine(cnt); // string[] strArray = Console.ReadLine().Split(' ').ToArray(); // string S = strArray[0]; // string T = strArray[1];
using System; using System.CodeDom.Compiler; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; class Program { static void Main(string[] args) { int[] ABCK = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray(); int A = ABCK[0]; int B = ABCK[1]; int C = ABCK[2]; int K = ABCK[3]; if (K <= A) Console.WriteLine(K); else if (K <= A + B) Console.WriteLine(A); else Console.WriteLine(A - (K - A - B)); } /// <summary> /// アナグラム /// </summary> /// <param name="word1"></param> /// <param name="word2"></param> /// <returns></returns> static bool IsAnagramOf(string word1, string word2) { return word1.OrderBy(x => x).SequenceEqual(word2.OrderBy(x => x)); } /// <summary> /// 最小公倍数 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static long Lcm(long a, long b) { return a * b / Gcd(a, b); } /// <summary> /// 最大公約数 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static long Gcd(long a, long b) { if (a < b) // 引数を入替えて自分を呼び出す return Gcd(b, a); while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } } // string s = Console.ReadLine(); // int[] intArray = Console.ReadLine().Split(' ').Select(i => // int.Parse(i)).ToArray(); int H = intArray[0]; int W = intArray[1]; int N = // int.Parse(Console.ReadLine()); List<int> A = new // List<int>(Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray()); // Boolean ok = false; // Console.WriteLine(ans); // Console.WriteLine("Yes"); // Console.WriteLine("No"); // Console.ReadKey(); // Console.WriteLine(cnt); // string[] strArray = Console.ReadLine().Split(' ').ToArray(); // string S = strArray[0]; // string T = strArray[1];
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 64, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["-", 64, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
290
14
using System; using System.Collections.Generic; namespace AtCoder.Problems { public class ProblemD { public static void Main(string[] args) { var s = new SolveD(); s.Solve(); } public class Scanner { private string[] _s; private int _i; private readonly char[] _separators = 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(_separators, StringSplitOptions.RemoveEmptyEntries); if (_s.Length == 0) return Next(); _i = 0; return _s[_i++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public ulong NextULong() => ulong.Parse(Next()); public double NextDouble() => double.Parse(Next()); public int[] GetIntArray(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[] GetLongArray(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[] GetDoubleArray(int n, double add = 0) { double[] array = new double[n]; for (int i = 0; i < n; i++) { array[i] = NextDouble() + add; } return array; } public string[] GetStringArray(int n) { string[] array = new string[n]; for (int i = 0; i < n; i++) { array[i] = Next(); } return array; } } } public class SolveD { public void Solve() { var cin = new ProblemD.Scanner(); var n = cin.NextInt(); var k = cin.NextLong(); var a = cin.GetIntArray(n); var result = GetAnswer(n, k, a); Console.WriteLine(result); } public int GetAnswer(int n, long k, int[] a) { var ans = 1; var list = new List<int>(n); while (k > 0) { // リストにある場合は循環回数の剰余を出す if (list.Contains(ans)) { var index = list.IndexOf(ans); var count = list.Count - index; k %= count; return list[index + (int)k]; } // リストにないので単純に1つ進んでリストに追加 list.Add(ans); ans = a[ans - 1]; --k; } return -1; } } }
using System; using System.Collections.Generic; namespace AtCoder.Problems { public class ProblemD { public static void Main(string[] args) { var s = new SolveD(); s.Solve(); } public class Scanner { private string[] _s; private int _i; private readonly char[] _separators = 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(_separators, StringSplitOptions.RemoveEmptyEntries); if (_s.Length == 0) return Next(); _i = 0; return _s[_i++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public ulong NextULong() => ulong.Parse(Next()); public double NextDouble() => double.Parse(Next()); public int[] GetIntArray(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[] GetLongArray(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[] GetDoubleArray(int n, double add = 0) { double[] array = new double[n]; for (int i = 0; i < n; i++) { array[i] = NextDouble() + add; } return array; } public string[] GetStringArray(int n) { string[] array = new string[n]; for (int i = 0; i < n; i++) { array[i] = Next(); } return array; } } } public class SolveD { public void Solve() { var cin = new ProblemD.Scanner(); var n = cin.NextInt(); var k = cin.NextLong(); var a = cin.GetIntArray(n); var result = GetAnswer(n, k, a); Console.WriteLine(result); } public int GetAnswer(int n, long k, int[] a) { var ans = 1; var list = new List<int>(n + 1); var dp = new bool[n + 1]; while (k > 0) { // リストにある場合は循環回数の剰余を出す if (dp[ans]) { var index = list.IndexOf(ans); var count = list.Count - index; k %= count; return list[index + (int)k]; } // リストにないので単純に1つ進んでリストに追加 dp[ans] = true; list.Add(ans); ans = a[ans - 1]; --k; } return ans; } } }
[["+", 0, 230, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 230, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 227, 0, 228], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 70], ["+", 0, 227, 39, 224, 225, 226, 0, 16, 31, 22], ["+", 0, 227, 39, 224, 225, 226, 0, 16, 17, 72], ["+", 0, 227, 39, 224, 225, 226, 0, 16, 12, 203], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 73], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 57, 15, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 57, 15, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 57, 15, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 57, 15, 213, 3, 4, 0, 24], ["+", 0, 52, 8, 196, 0, 57, 15, 204, 205, 22], ["+", 8, 196, 0, 57, 15, 204, 206, 207, 0, 70], ["-", 8, 196, 0, 57, 15, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 15, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 211, 0, 146], ["+", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["-", 0, 195, 8, 196, 0, 37, 0, 241, 0, 33], ["-", 0, 195, 8, 196, 0, 37, 0, 241, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 37, 0, 22]]
8
642
31
using System.Collections; using System.Text; using System.Threading.Tasks; using static System.Math; using static System.Console; using System.Collections.Generic; using System.Linq; using System; using System.Numerics; class Program { #region Reader // static Vector2Int ReadVec2Int //{ // get // { // string[] s = Console.ReadLine().Split(' '); // return new Vector2Int(int.Parse(s[0]), int.Parse(s[1])); // } //} // static Vector2Int[] ReadVec2Ints(int n) //{ // List<Vector2Int> list = new List<Vector2Int>(); // for (int i = 0; i < n; ++i) // { // var ab = ReadInts; // list.Add(new Vector2Int(ab[0], ab[1])); // } // return list.ToArray(); //} // static HashSet<Vector2Int> ReadVec2IntHash(int n) //{ // HashSet<Vector2Int> hash = new HashSet<Vector2Int>(); // for (int i = 0; i < n; ++i) // { // var ab = ReadInts; // hash.Add(new Vector2Int(ab[0], ab[1])); // } // return hash; //} static string ReadStr => Console.ReadLine(); static string[] ReadStrs => Console.ReadLine().Split(' '); static int ReadInt => Convert.ToInt32(Console.ReadLine()); static int[] ReadInts => Console.ReadLine().Split(' ').Select(s => Convert.ToInt32(s)).ToArray(); static long ReadLong => Convert.ToInt64(Console.ReadLine()); static long[] ReadLongs => Console.ReadLine().Split(' ').Select(s => Convert.ToInt64(s)).ToArray(); static long[,] ReLongMatrix(int r, int c) { var mat = new long[r, c]; for (int i = 0; i < r; ++i) { var x = ReadLongs; for (int j = 0; j < c; ++j) { mat[i, j] = x[j]; } } return mat; } static Tuple<string, string>[] ReTupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = ReadStrs; list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<long, long>[] ReTupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = ReadLongs; list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<int, int>[] ReadTupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = ReadInts; list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<double, double>[] ReTupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = ReadLongs; list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); } static Dictionary<int, HashSet<int>> ReAdjacencyList(int N, int M) { Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new HashSet<int>()); } for (int i = 0; i < M; ++i) { var ab = ReadInts; dict[ab[0]].Add(ab[1]); dict[ab[1]].Add(ab[0]); } return dict; } #endregion static void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } static int mod = (int)Pow(10, 9) + 7; public static long GetInv(long a, long mod = 1000000007) { return PowerMod(a, mod - 2, mod); } public static long Combination(long a, long b, long mod = 1000000007) { if (b < 0 || b > a) return 0; if (b > a / 2) b = a - b; long numerator = Factorial(a, mod); long denominator = (Factorial(b, mod) * Factorial(a - b, mod)) % mod; return (numerator * GetInv(denominator, mod)) % mod; } public static long Factorial(long n, long mod = 1000000007) { if (n == 0) return 1; if (n == 1) return 1; long ans = n; for (int i = 2; i < n; i++) { ans = (ans * i) % mod; } return ans; } private static long PowerMod(long a, long n, long mod = 1000000007) { if (n == 0) return 1; if (n == 1) return a; long p = PowerMod(a, n / 2, mod); if (n % 2 == 1) return ((p * p) % mod * a) % mod; else return (p * p) % mod; } /// <summary> /// 最小公倍数 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static long Lcm(long a, long b) { return a * b / Gcd(a, b); // return ( ((a * b)%mod) * GetInv( Gcd(a, b) ,mod ) )%mod; } /// <summary> /// 最大公約数 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static long Gcd(long a, long b) { if (a < b) // 引数を入替えて自分を呼び出す return Gcd(b, a); while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } static void Main() { long[] NK = ReadLongs; int[] As = ReadInts; for (int i = 0; i < As.Length; i++) { As[i]--; } List<int> move = new List<int>() { 0 }; bool[] done = new bool[As.Length]; done[0] = true; int index = 0; int last = -1; while (true) { if (done[As[move[index]]]) { last = As[move[index]]; last = move[last]; break; } move.Add(As[move[index]]); done[As[move[index]]] = true; index++; } int before = 0; int after = 0; for (int i = 0; i < move.Count; i++) { if (move[i] == last) break; before++; } after = move.Count - before; int ans = 0; if (NK[1] - before < 0) { ans = move[(int)NK[1]]; } else { ans = move[(int)((NK[1] - before) % after)]; } WriteLine(ans + 1); } }
using System.Collections; using System.Text; using System.Threading.Tasks; using static System.Math; using static System.Console; using System.Collections.Generic; using System.Linq; using System; using System.Numerics; class Program { #region Reader // static Vector2Int ReadVec2Int //{ // get // { // string[] s = Console.ReadLine().Split(' '); // return new Vector2Int(int.Parse(s[0]), int.Parse(s[1])); // } //} // static Vector2Int[] ReadVec2Ints(int n) //{ // List<Vector2Int> list = new List<Vector2Int>(); // for (int i = 0; i < n; ++i) // { // var ab = ReadInts; // list.Add(new Vector2Int(ab[0], ab[1])); // } // return list.ToArray(); //} // static HashSet<Vector2Int> ReadVec2IntHash(int n) //{ // HashSet<Vector2Int> hash = new HashSet<Vector2Int>(); // for (int i = 0; i < n; ++i) // { // var ab = ReadInts; // hash.Add(new Vector2Int(ab[0], ab[1])); // } // return hash; //} static string ReadStr => Console.ReadLine(); static string[] ReadStrs => Console.ReadLine().Split(' '); static int ReadInt => Convert.ToInt32(Console.ReadLine()); static int[] ReadInts => Console.ReadLine().Split(' ').Select(s => Convert.ToInt32(s)).ToArray(); static long ReadLong => Convert.ToInt64(Console.ReadLine()); static long[] ReadLongs => Console.ReadLine().Split(' ').Select(s => Convert.ToInt64(s)).ToArray(); static long[,] ReLongMatrix(int r, int c) { var mat = new long[r, c]; for (int i = 0; i < r; ++i) { var x = ReadLongs; for (int j = 0; j < c; ++j) { mat[i, j] = x[j]; } } return mat; } static Tuple<string, string>[] ReTupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = ReadStrs; list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<long, long>[] ReTupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = ReadLongs; list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<int, int>[] ReadTupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = ReadInts; list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<double, double>[] ReTupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = ReadLongs; list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); } static Dictionary<int, HashSet<int>> ReAdjacencyList(int N, int M) { Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new HashSet<int>()); } for (int i = 0; i < M; ++i) { var ab = ReadInts; dict[ab[0]].Add(ab[1]); dict[ab[1]].Add(ab[0]); } return dict; } #endregion static void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } static int mod = (int)Pow(10, 9) + 7; public static long GetInv(long a, long mod = 1000000007) { return PowerMod(a, mod - 2, mod); } public static long Combination(long a, long b, long mod = 1000000007) { if (b < 0 || b > a) return 0; if (b > a / 2) b = a - b; long numerator = Factorial(a, mod); long denominator = (Factorial(b, mod) * Factorial(a - b, mod)) % mod; return (numerator * GetInv(denominator, mod)) % mod; } public static long Factorial(long n, long mod = 1000000007) { if (n == 0) return 1; if (n == 1) return 1; long ans = n; for (int i = 2; i < n; i++) { ans = (ans * i) % mod; } return ans; } private static long PowerMod(long a, long n, long mod = 1000000007) { if (n == 0) return 1; if (n == 1) return a; long p = PowerMod(a, n / 2, mod); if (n % 2 == 1) return ((p * p) % mod * a) % mod; else return (p * p) % mod; } /// <summary> /// 最小公倍数 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static long Lcm(long a, long b) { return a * b / Gcd(a, b); // return ( ((a * b)%mod) * GetInv( Gcd(a, b) ,mod ) )%mod; } /// <summary> /// 最大公約数 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static long Gcd(long a, long b) { if (a < b) // 引数を入替えて自分を呼び出す return Gcd(b, a); while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } static void Main() { long[] NK = ReadLongs; int[] As = ReadInts; for (int i = 0; i < As.Length; i++) { As[i]--; } List<int> move = new List<int>() { 0 }; bool[] done = new bool[As.Length]; done[0] = true; int current = 0; int last = -1; while (true) { if (done[As[current]]) { last = As[current]; break; } move.Add(As[current]); done[As[current]] = true; current = As[current]; } int before = 0; int after = 0; for (int i = 0; i < move.Count; i++) { if (move[i] == last) break; before++; } after = move.Count - before; int ans = 0; if (NK[1] - before < 0) { ans = move[(int)NK[1]]; } else { ans = move[before + (int)((NK[1] - before) % after)]; } WriteLine(ans + 1); } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 206, 207, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 0, 204, 206, 207, 0, 28, 0, 204, 205, 22], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["-", 206, 207, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["-", 12, 204, 206, 207, 0, 28, 0, 204, 205, 22], ["-", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 64, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["-", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 52, 8, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 52, 8, 196, 0, 1, 0, 223, 0, 29], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 72]]
8
1,473
39
using System; using System.Text; using System.Collections.Generic; using System.Collections; using System.Linq; using E = System.Linq.Enumerable; class Program { static void Main(string[] args) { // var NX = Console.ReadLine().Split(' ').Select(x => // long.Parse(x)).ToArray(); var NMK = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); var N = NMK[0]; var M = NMK[1]; var K = NMK[2]; Modular ans = new Modular(0); for (int i = 0; i <= K; i++) { ans += M * Modular.Pow(M - 1, (int)N - 1 - i) * Modular.Pow(M, i); } Console.WriteLine(ans.value); } } class Modular { private const int M = 998244353; public long value; public Modular(long value) { 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) { return (a.value + b.value) % M; } public static Modular operator -(Modular a, Modular b) { return a.value - b.value; } public static Modular operator *(Modular a, Modular b) { return 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 }; private 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 Ncr(int n, int r) { return (n < r) ? 0 : (n == r) ? 1 : Fac(n) / (Fac(r) * Fac(n - r)); } public static explicit operator int(Modular a) { return (int)a.value; } public static Modular Lcm(Modular a, Modular b) { var tmp = Gcdl(a.value, b.value); return ((a * b) / new Modular(tmp)); } static Modular Gcd(Modular m, Modular n) { if (n.value > m.value) return Gcd(n, m); if (n.value == 0) return m; var r = new Modular(m.value % n.value); return Gcd(n, r); } static long Gcdl(long m, long n) { if (n > m) return Gcdl(n, m); if (n == 0) return m; return Gcdl(n, m % n); } }
using System; using System.Text; using System.Collections.Generic; using System.Collections; using System.Linq; using E = System.Linq.Enumerable; class Program { static void Main(string[] args) { // var NX = Console.ReadLine().Split(' ').Select(x => // long.Parse(x)).ToArray(); var NMK = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); var N = NMK[0]; var M = NMK[1]; var K = NMK[2]; Modular ans = new Modular(0); for (int i = 0; i <= K; i++) { ans += M * Modular.Pow(M - 1, (int)N - 1 - i) * Modular.Ncr((int)N - 1, i); } Console.WriteLine(ans.value); } } class Modular { private const int M = 998244353; public long value; public Modular(long value) { 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) { return (a.value + b.value) % M; } public static Modular operator -(Modular a, Modular b) { return a.value - b.value; } public static Modular operator *(Modular a, Modular b) { return 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 }; private 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 Ncr(int n, int r) { return (n < r) ? 0 : (n == r) ? 1 : Fac(n) / (Fac(r) * Fac(n - r)); } public static explicit operator int(Modular a) { return (int)a.value; } public static Modular Lcm(Modular a, Modular b) { var tmp = Gcdl(a.value, b.value); return ((a * b) / new Modular(tmp)); } static Modular Gcd(Modular m, Modular n) { if (n.value > m.value) return Gcd(n, m); if (n.value == 0) return m; var r = new Modular(m.value % n.value); return Gcd(n, r); } static long Gcdl(long m, long n) { if (n > m) return Gcdl(n, m); if (n == 0) return m; return Gcdl(n, m % n); } }
[["-", 0, 11, 12, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 11, 12, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 11, 12, 16, 12, 213, 3, 4, 0, 24], ["-", 12, 16, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 74, 39, 199], ["+", 3, 4, 0, 28, 0, 16, 31, 74, 0, 25], ["+", 3, 4, 0, 28, 0, 16, 31, 74, 51, 22], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
690
9
using System; using System.Collections.Generic; using static Assistant.Input; using static Assistant.Debug; using System.Linq; using Assistant; namespace ABC167E_3 { class Program { static void Main(string[] args) { var N = RInt; var M = RInt; var K = RInt; long mod = 998244353; long a = 1; long b = ModPow(M - 1, N - 1, mod); long memo = ModPow(M - 1, mod - 2, mod); long ans = 0; for (int i = 0; i <= K; i++) { ans += a * b % mod; ans %= mod; a = a * (N - i - 1) % mod * ModPow(i + 1, mod - 2, mod) % mod; b = b * memo % mod; } ans = ans * M % mod; Console.WriteLine(ans); } /// <summary> /// a^n (mod p) /// nが非常に大きい時に有効 /// </summary> /// <param name="a"></param> /// <param name="n"></param> /// <param name="mod"></param> /// <returns></returns> public static long ModPow(long a, long n, long p) { if (n == 0) return 1; if (n == 1) return a % p; if (n % 2 == 1) return (a * ModPow(a, n - 1, p)) % p; long t = ModPow(a, n / 2, p); return (t * t) % p; } } } namespace Assistant { static class Input { static List<string> line = new List<string>(); static int index = 0; static String RNext() { if (line.Count <= index) line.AddRange(Console.ReadLine().Split()); return line[index++]; } public static int RInt => int.Parse(RNext()); public static long RLong => long.Parse(RNext()); public static int[] RInts => Console.ReadLine().Split().Select(int.Parse).ToArray(); public static long[] RLongs => Console.ReadLine().Split().Select(long.Parse).ToArray(); public static string RString => RNext(); //以下未テスト public static int[] RIntsC(int c) => Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray(); public static long[] RLongsC(int c) => Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray(); public static char[][] RMap(int h) => Enumerable.Repeat(0, h) .Select(x => Console.ReadLine().ToCharArray()) .ToArray(); } static class Debug { static public void Draw2D(int[,] map, int mode = 1) { #if DEBUG int W = map.GetLength(0); int H = map.GetLength(1); int[,] map2 = new int[W + 1, H + 1]; for (int i = 0; i < W + 1; i++) { for (int j = 0; j < H + 1; j++) { if (i == 0 && j == 0) map2[i, j] = 0; else if (i == 0) map2[i, j] = j - 1; else if (j == 0) map2[i, j] = i - 1; else map2[i, j] = map[i - 1, j - 1]; } } for (int i = 0; i < W + 1; i++) { for (int j = 0; j < H + 1; j++) { if (mode == 0) Console.Write(map2[i, j] % 10); if (mode == 1) Console.Write(map2[i, j] + " "); } Console.WriteLine(); } Console.WriteLine(); #endif } public static void Draw1D(int[] array, int mode = 0) { #if DEBUG Console.WriteLine(string.Join(" ", array)); #endif } } }
using System; using System.Collections.Generic; using static Assistant.Input; using static Assistant.Debug; using System.Linq; using Assistant; namespace ABC167E_3 { class Program { static void Main(string[] args) { var N = RInt; var M = RInt; var K = RInt; long mod = 998244353; long a = 1; long b = M > 1 ? ModPow(M - 1, N - 1, mod) : 1; long memo = ModPow(M - 1, mod - 2, mod); long ans = 0; for (int i = 0; i <= K; i++) { ans += a * b % mod; ans %= mod; a = a * (N - i - 1) % mod * ModPow(i + 1, mod - 2, mod) % mod; b = b * memo % mod; } ans = ans * M % mod; if (M == 1) { if (N > K + 1) ans = 0; else ans = 1; } Console.WriteLine(ans); } /// <summary> /// a^n (mod p) /// nが非常に大きい時に有効 /// </summary> /// <param name="a"></param> /// <param name="n"></param> /// <param name="mod"></param> /// <returns></returns> public static long ModPow(long a, long n, long p) { if (n == 0) return 1; if (n == 1) return a % p; if (n % 2 == 1) return (a * ModPow(a, n - 1, p)) % p; long t = ModPow(a, n / 2, p); return (t * t) % p; } } } namespace Assistant { static class Input { static List<string> line = new List<string>(); static int index = 0; static String RNext() { if (line.Count <= index) line.AddRange(Console.ReadLine().Split()); return line[index++]; } public static int RInt => int.Parse(RNext()); public static long RLong => long.Parse(RNext()); public static int[] RInts => Console.ReadLine().Split().Select(int.Parse).ToArray(); public static long[] RLongs => Console.ReadLine().Split().Select(long.Parse).ToArray(); public static string RString => RNext(); //以下未テスト public static int[] RIntsC(int c) => Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray(); public static long[] RLongsC(int c) => Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray(); public static char[][] RMap(int h) => Enumerable.Repeat(0, h) .Select(x => Console.ReadLine().ToCharArray()) .ToArray(); } static class Debug { static public void Draw2D(int[,] map, int mode = 1) { #if DEBUG int W = map.GetLength(0); int H = map.GetLength(1); int[,] map2 = new int[W + 1, H + 1]; for (int i = 0; i < W + 1; i++) { for (int j = 0; j < H + 1; j++) { if (i == 0 && j == 0) map2[i, j] = 0; else if (i == 0) map2[i, j] = j - 1; else if (j == 0) map2[i, j] = i - 1; else map2[i, j] = map[i - 1, j - 1]; } } for (int i = 0; i < W + 1; i++) { for (int j = 0; j < H + 1; j++) { if (mode == 0) Console.Write(map2[i, j] % 10); if (mode == 1) Console.Write(map2[i, j] + " "); } Console.WriteLine(); } Console.WriteLine(); #endif } public static void Draw1D(int[] array, int mode = 0) { #if DEBUG Console.WriteLine(string.Join(" ", array)); #endif } } }
[["+", 0, 200, 0, 212, 0, 41, 15, 16, 31, 22], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 17, 47], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 101], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 102], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 75, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 47], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 17, 72], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 64, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 57, 64, 1, 0, 11, 12, 203], ["+", 0, 57, 64, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 95], ["+", 64, 196, 0, 57, 75, 1, 0, 11, 31, 22], ["+", 0, 57, 75, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 57, 75, 1, 0, 11, 12, 203], ["+", 0, 57, 64, 196, 0, 57, 75, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
866
31
using System; using System.Numerics; using System.Linq; using System.Collections.Generic; using System.Text; namespace debug { class ProgramD { static void Main(string[] args) { //入力 string[] s = Console.ReadLine().Split(' '); long n = long.Parse(s[0]); long m = long.Parse(s[1]); long k = long.Parse(s[2]); long MOD = 998244353; //下準備 nCk com = new nCk(); com.fac = new long[n + 1]; com.inv = new long[n + 1]; com.finv = new long[n + 1]; com.mod = MOD; com.max = n + 1; //メモ作成 com.com_init(); long ans = 0; for (int i = 0; i <= k; i++) { if (i == 0) { ans += m * modpow(m - 1, n - 1, MOD); ans %= MOD; continue; } ans += (m * com.com(n - 1, k) % MOD * modpow(m - 1, n - k - 1, MOD)) % MOD; ans %= MOD; } Console.WriteLine(ans); } //繰り返し二乗法で求める static long modpow(long a, long n, long MOD) { if (n == 0) return 1; if (n % 2 == 0) { long temp = modpow(a, n / 2, MOD); return temp * temp % MOD; } return a * modpow(a, n - 1, MOD) % MOD; } } class nCk { public long mod; public long max; public long[] fac; public long[] inv; public long[] finv; //メモ作成(前準備) public void com_init() { fac[0] = 1; fac[1] = 1; finv[0] = 1; finv[1] = 1; inv[1] = 1; for (long i = 2; i < max; i++) { fac[i] = i * fac[i - 1] % mod; inv[i] = mod - inv[mod % i] * (mod / i) % mod; finv[i] = finv[i - 1] * inv[i] % mod; } } //二項計算 public long com(long n, long k) { if (n < 0 || k < 0) return 0; if (n < k) return 0; return fac[n] * (finv[n - k] * finv[k] % mod) % mod; } } }
using System; using System.Numerics; using System.Linq; using System.Collections.Generic; using System.Text; namespace debug { class ProgramD { static void Main(string[] args) { //入力 string[] s = Console.ReadLine().Split(' '); long n = long.Parse(s[0]); long m = long.Parse(s[1]); long k = long.Parse(s[2]); long MOD = 998244353; //下準備 nCk com = new nCk(); com.fac = new long[n + 1]; com.inv = new long[n + 1]; com.finv = new long[n + 1]; com.mod = MOD; com.max = n + 1; //メモ作成 com.com_init(); long ans = 0; for (long i = 0; i <= k; i++) { if (i == 0) { ans += modpow(m - 1, n - 1, MOD); ans %= MOD; continue; } ans += (com.com(n - 1, i) * modpow(m - 1, n - i - 1, MOD)) % MOD; ans %= MOD; } ans *= m; ans %= MOD; Console.WriteLine(ans); } //繰り返し二乗法で求める static long modpow(long a, long n, long MOD) { if (n == 0) return 1; if (n % 2 == 0) { long temp = modpow(a, n / 2, MOD); return temp * temp % MOD; } return a * modpow(a, n - 1, MOD) % MOD; } } class nCk { public long mod; public long max; public long[] fac; public long[] inv; public long[] finv; //メモ作成(前準備) public void com_init() { fac[0] = 1; fac[1] = 1; finv[0] = 1; finv[1] = 1; inv[1] = 1; for (long i = 2; i < max; i++) { fac[i] = i * fac[i - 1] % mod; inv[i] = mod - inv[mod % i] * (mod / i) % mod; finv[i] = finv[i - 1] * inv[i] % mod; } } //二項計算 public long com(long n, long k) { if (n < 0 || k < 0) return 0; if (n < k) return 0; return fac[n] * (finv[n - k] * finv[k] % mod) % mod; } } }
[["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["-", 31, 23, 0, 16, 31, 16, 31, 16, 31, 22], ["-", 31, 23, 0, 16, 31, 16, 31, 16, 17, 48], ["-", 31, 16, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 16, 31, 213, 3, 4, 0, 28, 0, 22], ["-", 12, 16, 31, 23, 0, 16, 31, 16, 17, 109], ["-", 12, 16, 31, 23, 0, 16, 31, 16, 12, 22], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 108], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 132]]
8
549
20
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; namespace AtCoder { public class Program { static void Main() { var cin = new Scanner(); int n = cin.Int(); int m = cin.Int(); int k = cin.Int(); ModInt.P = 998244353; ModCounting.InitializeFactorial(Math.Max(n, m), 998244353); var rui = new ModInt[n + 1]; rui[1] = m - 1; for (int i = 2; i <= n; i++) { rui[i] = rui[i - 1] * (m - 1); } ModInt ans = 0; for (int i = 0; i <= k; i++) { ModInt temp = m; temp *= ModCounting.Combination(n - 1, i) * rui[n - 1 - i]; ans += temp; } Console.WriteLine(ans.Value); } } public struct ModInt { public static long P { get; set; } = (long)1e9 + 7; public static ModInt Pow(ModInt value, long k) { return Pow(value.Value, k); } public static ModInt Pow(long value, long k) { long ret = 1; for (k %= P - 1; k > 0; k >>= 1, value = value * value % P) { if ((k & 1) == 1) { ret = ret * value % P; } } return new ModInt(ret); } public static ModInt Inverse(ModInt value) { return Pow(value, P - 2); } public long Value; public ModInt(long value) { value %= P; if (value < 0) { value += P; } Value = value; } public static ModInt operator +(ModInt lhs, ModInt rhs) { lhs.Value += rhs.Value; if (lhs.Value >= P) { lhs.Value -= P; } return lhs; } public static ModInt operator -(ModInt lhs, ModInt rhs) { lhs.Value -= rhs.Value; if (lhs.Value < 0) { lhs.Value += P; } return lhs; } public static ModInt operator *(ModInt lhs, ModInt rhs) { return new ModInt(lhs.Value * rhs.Value % P); } public static ModInt operator /(ModInt lhs, ModInt rhs) { long exp = P - 2; while (exp > 0) { if (exp % 2 > 0) { lhs *= rhs; } rhs *= rhs; exp /= 2; } return lhs; } public static implicit operator ModInt(long n) { n %= P; if (n < 0) { n += P; } return new ModInt(n); } public override string ToString() { return Value.ToString(); } } public static class ModCounting { private static long p_; private static long[] factorial_; private static long[] inverseFactorial_; private static long[] inverse_; public static void InitializeFactorial(long max, long p = 1000000007) { p_ = p; factorial_ = new long[max + 1]; inverseFactorial_ = new long[max + 1]; inverse_ = new long[max + 1]; factorial_[0] = factorial_[1] = 1; inverseFactorial_[0] = inverseFactorial_[1] = 1; inverse_[1] = 1; for (int i = 2; i <= max; i++) { factorial_[i] = factorial_[i - 1] * i % p; inverse_[i] = p - inverse_[p % i] * (p / i) % p; inverseFactorial_[i] = inverseFactorial_[i - 1] * inverse_[i] % p; } } public static long Factorial(long n) { if (n < 0) { return 0; } return factorial_[n]; } public static long InverseFactorial(long n) { if (n < 0) { return 0; } return inverseFactorial_[n]; } public static long Inverse(long n) { if (n < 0) { return 0; } return inverse_[n]; } public static long Permutation(long n, long k) { if (n < k || (n < 0 || k < 0)) { return 0; } return factorial_[n] * inverseFactorial_[n - k] % p_; } public static long RepeatedPermutation(long n, long k) { long ret = 1; for (k %= p_ - 1; k > 0; k >>= 1, n = n * n % p_) { if ((k & 1) == 1) { ret = ret * n % p_; } } return ret; } public static long Combination(long n, long k) { if (n < k || (n < 0 || k < 0)) { return 0; } return factorial_[n] * (inverseFactorial_[k] * inverseFactorial_[n - k] % p_) % p_; } public static long CombinationK(long n, long k) { long ret = 1; for (int i = 0; i < k; i++) { ret = (ret * (n - i)) % p_; ret = (ret * inverse_[i + 1]) % p_; } return ret; } public static long HomogeneousProduct(long n, long k) { if (n < 0 || k < 0) { return 0; } return Combination(n + k - 1, k); } } public class HashMap<TKey, TValue> : Dictionary<TKey, TValue> { private readonly Func<TKey, TValue> initialzier_; public HashMap(Func<TKey, TValue> initialzier) : base() { initialzier_ = initialzier; } public HashMap(Func<TKey, TValue> initialzier, int capacity) : base(capacity) { initialzier_ = initialzier; } new public TValue this[TKey key] { get { if (ContainsKey(key) == false) { base[key] = initialzier_(key); } return base[key]; } set { base[key] = value; } } } public static class Helper { public static void UpdateMin<T>(ref T target, T value) where T : IComparable<T> => target = target.CompareTo(value) > 0 ? value : target; public static void UpdateMin<T>(ref T target, T value, Action<T> onUpdated) where T : IComparable<T> { if (target.CompareTo(value) > 0) { target = value; onUpdated(value); } } public static void UpdateMax<T>(ref T target, T value) where T : IComparable<T> => target = target.CompareTo(value) < 0 ? value : target; public static void UpdateMax<T>(ref T target, T value, Action<T> onUpdated) where T : IComparable<T> { if (target.CompareTo(value) < 0) { target = value; onUpdated(value); } } public static T[] Array<T>(int n, Func<int, T> init) => Enumerable.Range(0, n).Select(x => init(x)).ToArray(); public static List<T> List<T>(int n, Func<int, T> init) => Enumerable.Range(0, n).Select(x => init(x)).ToList(); public static T[,] Array2<T>(int n, int m, T init) { var array = new T[n, m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { array[i, j] = init; } } return array; } public static T[,] Array2<T>(int n, int m, Func<int, int, T> initializer) { var array = new T[n, m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { array[i, j] = initializer(i, j); } } return array; } public static T[,,] Array3<T>(int n1, int n2, int n3, T init) { var array = new T[n1, n2, n3]; for (int i1 = 0; i1 < n1; i1++) { for (int i2 = 0; i2 < n2; i2++) { for (int i3 = 0; i3 < n3; i3++) { array[i1, i2, i3] = init; } } } return array; } private static readonly int[] delta4_ = { 1, 0, -1, 0, 1 }; public static void DoAt4(int i, int j, int imax, int jmax, Action<int, int> action) { for (int n = 0; n < 4; n++) { int ii = i + delta4_[n]; int jj = j + delta4_[n + 1]; if ((uint)ii < (uint)imax && (uint)jj < (uint)jmax) { action(ii, jj); } } } } public class Scanner { private readonly char[] delimiter_ = new char[] { ' ' }; private readonly string filePath_; private readonly Func<string> reader_; private string[] buf_; private int index_; public Scanner(string file = "") { if (string.IsNullOrWhiteSpace(file)) { reader_ = Console.ReadLine; } else { filePath_ = file; var fs = new StreamReader(file); reader_ = fs.ReadLine; } buf_ = new string[0]; index_ = 0; } public string Next() { if (index_ < buf_.Length) { return buf_[index_++]; } string st = reader_(); while (st == "") { st = reader_(); } buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries); if (buf_.Length == 0) { return Next(); } index_ = 0; return buf_[index_++]; } public int Int() => int.Parse(Next()); public long Long() => long.Parse(Next()); public double Double() => double.Parse(Next()); public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = Int() + add; } return Array; } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = Long() + add; } return Array; } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = Double() + add; } return Array; } public void Save(string text) { if (string.IsNullOrWhiteSpace(filePath_)) { return; } File.WriteAllText(filePath_ + "_output.txt", text); } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; namespace AtCoder { public class Program { static void Main() { var cin = new Scanner(); int n = cin.Int(); int m = cin.Int(); int k = cin.Int(); ModInt.P = 998244353; ModCounting.InitializeFactorial(Math.Max(n, m), 998244353); var rui = new ModInt[n + 1]; rui[0] = 1; rui[1] = m - 1; for (int i = 2; i <= n; i++) { rui[i] = rui[i - 1] * (m - 1); } ModInt ans = 0; for (int i = 0; i <= k; i++) { ModInt temp = m; temp *= ModCounting.Combination(n - 1, i) * rui[n - 1 - i]; ans += temp; } Console.WriteLine(ans.Value); } } public struct ModInt { public static long P { get; set; } = (long)1e9 + 7; public static ModInt Pow(ModInt value, long k) { return Pow(value.Value, k); } public static ModInt Pow(long value, long k) { long ret = 1; for (k %= P - 1; k > 0; k >>= 1, value = value * value % P) { if ((k & 1) == 1) { ret = ret * value % P; } } return new ModInt(ret); } public static ModInt Inverse(ModInt value) { return Pow(value, P - 2); } public long Value; public ModInt(long value) { value %= P; if (value < 0) { value += P; } Value = value; } public static ModInt operator +(ModInt lhs, ModInt rhs) { lhs.Value += rhs.Value; if (lhs.Value >= P) { lhs.Value -= P; } return lhs; } public static ModInt operator -(ModInt lhs, ModInt rhs) { lhs.Value -= rhs.Value; if (lhs.Value < 0) { lhs.Value += P; } return lhs; } public static ModInt operator *(ModInt lhs, ModInt rhs) { return new ModInt(lhs.Value * rhs.Value % P); } public static ModInt operator /(ModInt lhs, ModInt rhs) { long exp = P - 2; while (exp > 0) { if (exp % 2 > 0) { lhs *= rhs; } rhs *= rhs; exp /= 2; } return lhs; } public static implicit operator ModInt(long n) { n %= P; if (n < 0) { n += P; } return new ModInt(n); } public override string ToString() { return Value.ToString(); } } public static class ModCounting { private static long p_; private static long[] factorial_; private static long[] inverseFactorial_; private static long[] inverse_; public static void InitializeFactorial(long max, long p = 1000000007) { p_ = p; factorial_ = new long[max + 1]; inverseFactorial_ = new long[max + 1]; inverse_ = new long[max + 1]; factorial_[0] = factorial_[1] = 1; inverseFactorial_[0] = inverseFactorial_[1] = 1; inverse_[1] = 1; for (int i = 2; i <= max; i++) { factorial_[i] = factorial_[i - 1] * i % p; inverse_[i] = p - inverse_[p % i] * (p / i) % p; inverseFactorial_[i] = inverseFactorial_[i - 1] * inverse_[i] % p; } } public static long Factorial(long n) { if (n < 0) { return 0; } return factorial_[n]; } public static long InverseFactorial(long n) { if (n < 0) { return 0; } return inverseFactorial_[n]; } public static long Inverse(long n) { if (n < 0) { return 0; } return inverse_[n]; } public static long Permutation(long n, long k) { if (n < k || (n < 0 || k < 0)) { return 0; } return factorial_[n] * inverseFactorial_[n - k] % p_; } public static long RepeatedPermutation(long n, long k) { long ret = 1; for (k %= p_ - 1; k > 0; k >>= 1, n = n * n % p_) { if ((k & 1) == 1) { ret = ret * n % p_; } } return ret; } public static long Combination(long n, long k) { if (n < k || (n < 0 || k < 0)) { return 0; } return factorial_[n] * (inverseFactorial_[k] * inverseFactorial_[n - k] % p_) % p_; } public static long CombinationK(long n, long k) { long ret = 1; for (int i = 0; i < k; i++) { ret = (ret * (n - i)) % p_; ret = (ret * inverse_[i + 1]) % p_; } return ret; } public static long HomogeneousProduct(long n, long k) { if (n < 0 || k < 0) { return 0; } return Combination(n + k - 1, k); } } public class HashMap<TKey, TValue> : Dictionary<TKey, TValue> { private readonly Func<TKey, TValue> initialzier_; public HashMap(Func<TKey, TValue> initialzier) : base() { initialzier_ = initialzier; } public HashMap(Func<TKey, TValue> initialzier, int capacity) : base(capacity) { initialzier_ = initialzier; } new public TValue this[TKey key] { get { if (ContainsKey(key) == false) { base[key] = initialzier_(key); } return base[key]; } set { base[key] = value; } } } public static class Helper { public static void UpdateMin<T>(ref T target, T value) where T : IComparable<T> => target = target.CompareTo(value) > 0 ? value : target; public static void UpdateMin<T>(ref T target, T value, Action<T> onUpdated) where T : IComparable<T> { if (target.CompareTo(value) > 0) { target = value; onUpdated(value); } } public static void UpdateMax<T>(ref T target, T value) where T : IComparable<T> => target = target.CompareTo(value) < 0 ? value : target; public static void UpdateMax<T>(ref T target, T value, Action<T> onUpdated) where T : IComparable<T> { if (target.CompareTo(value) < 0) { target = value; onUpdated(value); } } public static T[] Array<T>(int n, Func<int, T> init) => Enumerable.Range(0, n).Select(x => init(x)).ToArray(); public static List<T> List<T>(int n, Func<int, T> init) => Enumerable.Range(0, n).Select(x => init(x)).ToList(); public static T[,] Array2<T>(int n, int m, T init) { var array = new T[n, m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { array[i, j] = init; } } return array; } public static T[,] Array2<T>(int n, int m, Func<int, int, T> initializer) { var array = new T[n, m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { array[i, j] = initializer(i, j); } } return array; } public static T[,,] Array3<T>(int n1, int n2, int n3, T init) { var array = new T[n1, n2, n3]; for (int i1 = 0; i1 < n1; i1++) { for (int i2 = 0; i2 < n2; i2++) { for (int i3 = 0; i3 < n3; i3++) { array[i1, i2, i3] = init; } } } return array; } private static readonly int[] delta4_ = { 1, 0, -1, 0, 1 }; public static void DoAt4(int i, int j, int imax, int jmax, Action<int, int> action) { for (int n = 0; n < 4; n++) { int ii = i + delta4_[n]; int jj = j + delta4_[n + 1]; if ((uint)ii < (uint)imax && (uint)jj < (uint)jmax) { action(ii, jj); } } } } public class Scanner { private readonly char[] delimiter_ = new char[] { ' ' }; private readonly string filePath_; private readonly Func<string> reader_; private string[] buf_; private int index_; public Scanner(string file = "") { if (string.IsNullOrWhiteSpace(file)) { reader_ = Console.ReadLine; } else { filePath_ = file; var fs = new StreamReader(file); reader_ = fs.ReadLine; } buf_ = new string[0]; index_ = 0; } public string Next() { if (index_ < buf_.Length) { return buf_[index_++]; } string st = reader_(); while (st == "") { st = reader_(); } buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries); if (buf_.Length == 0) { return Next(); } index_ = 0; return buf_[index_++]; } public int Int() => int.Parse(Next()); public long Long() => long.Parse(Next()); public double Double() => double.Parse(Next()); public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = Int() + add; } return Array; } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = Long() + add; } return Array; } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = Double() + add; } return Array; } public void Save(string text) { if (string.IsNullOrWhiteSpace(filePath_)) { return; } File.WriteAllText(filePath_ + "_output.txt", text); } } }
[["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70]]
8
2,376
7
using System; using System.Collections.Generic; using System.Linq; using System.Text; // using System.Numerics; using System.Runtime.CompilerServices; using System.Diagnostics; using ll=System.Int64; using static Contest_F.Lib_IO; using static Contest_F.Lib_Minifunc; public static class Contest_F { public static void Main() { checked{ long n; Lib_IO.rm(out n); string[]s; rl(n,out s); List<P<ll,ll,ll>> g = new List<P<ll, ll, ll>>(); List<P<ll,ll,ll>> h = new List<P<ll, ll, ll>>(); ll ac = 0; for (int i = 0; i < n; i++) { int c = 0; int mn = 0; int mx = 0; for (int j = 0; j < s[i].Length; j++) { if(s[i][j]=='('){ c++; }else{ c--; } chmin(ref mn,c); chmax(ref mx,c); } if(0<c){ g.Add(new P<ll, ll, ll>(mn,mx,c)); }else{ h.Add(new P<ll, ll, ll>(mn,mx,c)); } ac += c; } g.Sort((x,y)=>y.A.CompareTo(x.A)); h.Sort((x,y)=>(-x.A+x.C).CompareTo(-y.A+y.C)); string ans = "Yes"; if(ac!=0) ans = "No"; ll cc = 0; foreach (var e in g) { if(cc+e.A<0){ ans = "No"; break; } cc += e.C; } foreach (var e in h) { if(cc+e.A<0){ ans = "No"; break; } cc += e.C; } Lib_IO.wm(ans); } } #region BaseModule public static class Lib_Minifunc{ [MethodImpl(256)] public static void swap1<T>(ref T a, ref T b) { T t = a; a = b; b = t; } [MethodImpl(256)] public static void swap2<T>(ref T a, ref T b) where T : IComparable { if (a.CompareTo(b)==1) swap1(ref a, ref b); } // b の方が小さければ交換 [MethodImpl(256)] public static bool chmin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b)== 1) { a = b; return true; } return false; } // b の方が小さければ a を更新 [MethodImpl(256)] public static bool chmax<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b)==-1) { a = b; return true; } return false; } // b の方が大きければ a を更新 [MethodImpl(256)] public static bool inside(long i, long n) => (0<=i&&i<n); [MethodImpl(256)] public static bool inside(long x, long y, long w, long h) => (inside(x,w)&&inside(y,h)); [MethodImpl(256)] public static T min<T>(params T[] a) where T : IComparable => a.Min(); [MethodImpl(256)] public static T max<T>(params T[] a) where T : IComparable => a.Max(); [MethodImpl(256)] public static long mod(long a, long m=MOD1) { var v = a%m; return (v<0?v+m:v); } [MethodImpl(256)] public static long ceiling(long a, long b) => (a%b==0?a/b:a/b+1); // 整数商の切り上げ [MethodImpl(256)] public static P<T,U> initp<T,U>(T a,U b) => new P<T,U>(a,b); [MethodImpl(256)] public static P<T,U,V> initp<T,U,V>(T a,U b,V c) => new P<T,U,V>(a,b,c); [MethodImpl(256)] public static P<T,U,V,W> initp<T,U,V,W>(T a,U b,V c,W d) => new P<T,U,V,W>(a,b,c,d); [MethodImpl(256)] public static bool initd<T,U>(Dictionary<T,U> d, T k) { if(d.ContainsKey(k)) { return false; } else { d[k] = default(U); return true; } } public static T[] inita<T>(long len1) where T : new() { var m = new T[len1]; for (int i=0;i<m.Length;i++) m[i] = new T(); return m; } public static T[][] initm<T>(long len1,long len2,T val) where T : struct { var m = new T[len1][]; for (int i=0;i<m.Length;i++) m[i] = Enumerable.Repeat(val,(int)len2).ToArray(); return m; } public static T[][][] initm<T>(long len1,long len2,long len3,T val) where T : struct { var m = new T[len1][][]; for (int i=0;i<m.Length;i++) m[i] = initm(len2,len3,val); return m; } public const long MOD1 = 1000000007; // 10^9+7 public const double EPS1 = 1e-8; public const long INF1 = 1000000000000000; // 10^15 } public struct P<T,U> { public T A; public U B; public P(T a,U b) { A = a; B = b; } public static implicit operator KeyValuePair<T,U>(P<T,U> a) => new KeyValuePair<T,U>(a.A,a.B); public static implicit operator P<T,U>(KeyValuePair<T,U> a) => new P<T,U>(a.Key,a.Value); } public struct P<T,U,V> { public T A; public U B; public V C; public P(T a,U b,V c) { A = a; B = b; C = c; } } public struct P<T,U,V,W> { public T A; public U B; public V C; public W D; public P(T a,U b,V c,W d) { A = a; B = b; C = c; D = d; } } public static class Lib_IO { class Prt : System.IO.StreamWriter { public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } } public Prt(System.IO.Stream s) : base(s,new UTF8Encoding(false,true)) {} public Prt(System.IO.Stream s,Encoding e) : base(s,e) {} } static Prt sw = new Prt(Console.OpenStandardOutput()); static char[] sp = new char[] {' '}; [MethodImpl(256)] static bool eq<T,U>() => typeof(T).Equals(typeof(U)); [MethodImpl(256)] static T ct<T,U>(U a) => (T)Convert.ChangeType(a,typeof(T)); [MethodImpl(256)] 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,System.Globalization.CultureInfo.InvariantCulture)) : eq<T,char>() ? ct<T,char>(s[0]) : ct<T,string>(s); public static string[] rm<T>(out T a) { var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries); a = cv<T>(z[0]); return z; } public static string[] rm<T,U>(out T a,out U b) { var z = rm<T>(out a); b = cv<U>(z[1]); return z; } public static string[] rm<T,U,V>(out T a,out U b,out V c) { var z = rm<T,U>(out a,out b); c = cv<V>(z[2]); return z; } public static string[] rm<T,U,V,W>(out T a,out U b,out V c,out W d) { var z = rm<T,U,V>(out a,out b,out c); d = cv<W>(z[3]); return z; } public static string[] rm<T,U,V,W,X>(out T a,out U b,out V c,out W d,out X e) { var z = rm<T,U,V,W>(out a,out b,out c,out d); e = cv<X>(z[4]); return z; } public static string[] rm<T,U,V,W,X,Y>(out T a,out U b,out V c,out W d,out X e,out Y f) { var z = rm<T,U,V,W,X>(out a,out b,out c,out d,out e); f = cv<Y>(z[5]); return z; } public static string[] ra<T>(out T[] a) { var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries); a = z.Select(cv<T>).ToArray(); return z; } public static string[][] rl<T>(long n,out T[] a) { a = new T[n]; var y = new string[n][]; for(int i=0;i<n;i++) y[i] = rm(out a[i]); return y; } public static string[][] rl<T,U>(long n,out P<T,U>[] a) { a = new P<T,U>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; y[i] = rm(out o,out p); a[i] = new P<T,U>(o,p); } return y; } public static string[][] rl<T,U,V>(long n,out P<T,U,V>[] a) { a = new P<T,U,V>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; V q; y[i] = rm(out o,out p,out q); a[i] = new P<T,U,V>(o,p,q); } return y; } public static string[][] rl<T,U,V,W>(long n,out P<T,U,V,W>[] a) { a = new P<T,U,V,W>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; V q; W r; y[i] = rm(out o,out p,out q,out r); a[i] = new P<T,U,V,W>(o,p,q,r); } return y; } public static string[][] rx<T>(long n,out T[][] a) { a = new T[n][]; var y = new string[n][]; for(int i=0;i<n;i++) y[i] = ra(out a[i]); return y; } static void wwp(Action act){ sw.AutoFlush = false; Console.SetOut(sw); act(); Console.Out.Flush(); sw.AutoFlush = true; Console.SetOut(sw); } [MethodImpl(256)] static string wfm(Type t) =>t.Equals(typeof(double)) ? "{0:F10}" : "{0}"; public static void wm(params object[] a) { wwp(()=>{ for(int i=0;i<a.Length-1;i++) Console.Write(wfm(a[i].GetType())+" ",a[i]); Console.WriteLine(wfm(a[a.Length-1].GetType()),a[a.Length-1]); }); } public static void wa<T>(IList<T> a) { wxa(new IList<T>[]{a}, " "); } public static void wl<T>(IList<T> a) { wwp(()=>{ var f = wfm(typeof(T)); foreach(T x in a) Console.WriteLine(f,x); }); } static void wxa<T>(IList<IList<T>> a, string s) { wwp(()=>{ var f = wfm(typeof(T)); var g = f + s; foreach(var b in a) { for(int i=0;i<b.Count-1;i++) Console.Write(g,b[i]); Console.WriteLine(f,b[b.Count-1]); } }); } public static void wx<T>(IList<IList<T>> a) { wxa(a, " "); } public static void wg<T>(IList<IList<T>> a) { wxa(a, ""); } } #endregion }
using System; using System.Collections.Generic; using System.Linq; using System.Text; // using System.Numerics; using System.Runtime.CompilerServices; using System.Diagnostics; using ll=System.Int64; using static Contest_F.Lib_IO; using static Contest_F.Lib_Minifunc; public static class Contest_F { public static void Main() { checked{ long n; Lib_IO.rm(out n); string[]s; rl(n,out s); List<P<ll,ll,ll>> g = new List<P<ll, ll, ll>>(); List<P<ll,ll,ll>> h = new List<P<ll, ll, ll>>(); ll ac = 0; for (int i = 0; i < n; i++) { int c = 0; int mn = 0; int mx = 0; for (int j = 0; j < s[i].Length; j++) { if(s[i][j]=='('){ c++; }else{ c--; } chmin(ref mn,c); chmax(ref mx,c); } if(0<c){ g.Add(new P<ll, ll, ll>(mn,mx,c)); }else{ h.Add(new P<ll, ll, ll>(mn,mx,c)); } ac += c; } g.Sort((x,y)=>y.A.CompareTo(x.A)); h.Sort((x,y)=>(-y.A+y.C).CompareTo(-x.A+x.C)); //h.Sort((x,y)=>(x.A).CompareTo(y.A)); string ans = "Yes"; if(ac!=0) ans = "No"; ll cc = 0; foreach (var e in g) { if(cc+e.A<0){ ans = "No"; break; } cc += e.C; } foreach (var e in h) { if(cc+e.A<0){ ans = "No"; break; } cc += e.C; } Lib_IO.wm(ans); } } #region BaseModule public static class Lib_Minifunc{ [MethodImpl(256)] public static void swap1<T>(ref T a, ref T b) { T t = a; a = b; b = t; } [MethodImpl(256)] public static void swap2<T>(ref T a, ref T b) where T : IComparable { if (a.CompareTo(b)==1) swap1(ref a, ref b); } // b の方が小さければ交換 [MethodImpl(256)] public static bool chmin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b)== 1) { a = b; return true; } return false; } // b の方が小さければ a を更新 [MethodImpl(256)] public static bool chmax<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b)==-1) { a = b; return true; } return false; } // b の方が大きければ a を更新 [MethodImpl(256)] public static bool inside(long i, long n) => (0<=i&&i<n); [MethodImpl(256)] public static bool inside(long x, long y, long w, long h) => (inside(x,w)&&inside(y,h)); [MethodImpl(256)] public static T min<T>(params T[] a) where T : IComparable => a.Min(); [MethodImpl(256)] public static T max<T>(params T[] a) where T : IComparable => a.Max(); [MethodImpl(256)] public static long mod(long a, long m=MOD1) { var v = a%m; return (v<0?v+m:v); } [MethodImpl(256)] public static long ceiling(long a, long b) => (a%b==0?a/b:a/b+1); // 整数商の切り上げ [MethodImpl(256)] public static P<T,U> initp<T,U>(T a,U b) => new P<T,U>(a,b); [MethodImpl(256)] public static P<T,U,V> initp<T,U,V>(T a,U b,V c) => new P<T,U,V>(a,b,c); [MethodImpl(256)] public static P<T,U,V,W> initp<T,U,V,W>(T a,U b,V c,W d) => new P<T,U,V,W>(a,b,c,d); [MethodImpl(256)] public static bool initd<T,U>(Dictionary<T,U> d, T k) { if(d.ContainsKey(k)) { return false; } else { d[k] = default(U); return true; } } public static T[] inita<T>(long len1) where T : new() { var m = new T[len1]; for (int i=0;i<m.Length;i++) m[i] = new T(); return m; } public static T[][] initm<T>(long len1,long len2,T val) where T : struct { var m = new T[len1][]; for (int i=0;i<m.Length;i++) m[i] = Enumerable.Repeat(val,(int)len2).ToArray(); return m; } public static T[][][] initm<T>(long len1,long len2,long len3,T val) where T : struct { var m = new T[len1][][]; for (int i=0;i<m.Length;i++) m[i] = initm(len2,len3,val); return m; } public const long MOD1 = 1000000007; // 10^9+7 public const double EPS1 = 1e-8; public const long INF1 = 1000000000000000; // 10^15 } public struct P<T,U> { public T A; public U B; public P(T a,U b) { A = a; B = b; } public static implicit operator KeyValuePair<T,U>(P<T,U> a) => new KeyValuePair<T,U>(a.A,a.B); public static implicit operator P<T,U>(KeyValuePair<T,U> a) => new P<T,U>(a.Key,a.Value); } public struct P<T,U,V> { public T A; public U B; public V C; public P(T a,U b,V c) { A = a; B = b; C = c; } } public struct P<T,U,V,W> { public T A; public U B; public V C; public W D; public P(T a,U b,V c,W d) { A = a; B = b; C = c; D = d; } } public static class Lib_IO { class Prt : System.IO.StreamWriter { public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } } public Prt(System.IO.Stream s) : base(s,new UTF8Encoding(false,true)) {} public Prt(System.IO.Stream s,Encoding e) : base(s,e) {} } static Prt sw = new Prt(Console.OpenStandardOutput()); static char[] sp = new char[] {' '}; [MethodImpl(256)] static bool eq<T,U>() => typeof(T).Equals(typeof(U)); [MethodImpl(256)] static T ct<T,U>(U a) => (T)Convert.ChangeType(a,typeof(T)); [MethodImpl(256)] 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,System.Globalization.CultureInfo.InvariantCulture)) : eq<T,char>() ? ct<T,char>(s[0]) : ct<T,string>(s); public static string[] rm<T>(out T a) { var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries); a = cv<T>(z[0]); return z; } public static string[] rm<T,U>(out T a,out U b) { var z = rm<T>(out a); b = cv<U>(z[1]); return z; } public static string[] rm<T,U,V>(out T a,out U b,out V c) { var z = rm<T,U>(out a,out b); c = cv<V>(z[2]); return z; } public static string[] rm<T,U,V,W>(out T a,out U b,out V c,out W d) { var z = rm<T,U,V>(out a,out b,out c); d = cv<W>(z[3]); return z; } public static string[] rm<T,U,V,W,X>(out T a,out U b,out V c,out W d,out X e) { var z = rm<T,U,V,W>(out a,out b,out c,out d); e = cv<X>(z[4]); return z; } public static string[] rm<T,U,V,W,X,Y>(out T a,out U b,out V c,out W d,out X e,out Y f) { var z = rm<T,U,V,W,X>(out a,out b,out c,out d,out e); f = cv<Y>(z[5]); return z; } public static string[] ra<T>(out T[] a) { var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries); a = z.Select(cv<T>).ToArray(); return z; } public static string[][] rl<T>(long n,out T[] a) { a = new T[n]; var y = new string[n][]; for(int i=0;i<n;i++) y[i] = rm(out a[i]); return y; } public static string[][] rl<T,U>(long n,out P<T,U>[] a) { a = new P<T,U>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; y[i] = rm(out o,out p); a[i] = new P<T,U>(o,p); } return y; } public static string[][] rl<T,U,V>(long n,out P<T,U,V>[] a) { a = new P<T,U,V>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; V q; y[i] = rm(out o,out p,out q); a[i] = new P<T,U,V>(o,p,q); } return y; } public static string[][] rl<T,U,V,W>(long n,out P<T,U,V,W>[] a) { a = new P<T,U,V,W>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; V q; W r; y[i] = rm(out o,out p,out q,out r); a[i] = new P<T,U,V,W>(o,p,q,r); } return y; } public static string[][] rx<T>(long n,out T[][] a) { a = new T[n][]; var y = new string[n][]; for(int i=0;i<n;i++) y[i] = ra(out a[i]); return y; } static void wwp(Action act){ sw.AutoFlush = false; Console.SetOut(sw); act(); Console.Out.Flush(); sw.AutoFlush = true; Console.SetOut(sw); } [MethodImpl(256)] static string wfm(Type t) =>t.Equals(typeof(double)) ? "{0:F10}" : "{0}"; public static void wm(params object[] a) { wwp(()=>{ for(int i=0;i<a.Length-1;i++) Console.Write(wfm(a[i].GetType())+" ",a[i]); Console.WriteLine(wfm(a[a.Length-1].GetType()),a[a.Length-1]); }); } public static void wa<T>(IList<T> a) { wxa(new IList<T>[]{a}, " "); } public static void wl<T>(IList<T> a) { wwp(()=>{ var f = wfm(typeof(T)); foreach(T x in a) Console.WriteLine(f,x); }); } static void wxa<T>(IList<IList<T>> a, string s) { wwp(()=>{ var f = wfm(typeof(T)); var g = f + s; foreach(var b in a) { for(int i=0;i<b.Count-1;i++) Console.Write(g,b[i]); Console.WriteLine(f,b[b.Count-1]); } }); } public static void wx<T>(IList<IList<T>> a) { wxa(a, " "); } public static void wg<T>(IList<IList<T>> a) { wxa(a, ""); } } #endregion }
[["-", 205, 23, 0, 16, 31, 241, 0, 214, 205, 22], ["+", 205, 23, 0, 16, 31, 241, 0, 214, 205, 22], ["-", 63, 214, 205, 23, 0, 16, 12, 214, 205, 22], ["+", 63, 214, 205, 23, 0, 16, 12, 214, 205, 22], ["-", 0, 28, 0, 16, 31, 241, 0, 214, 205, 22], ["+", 0, 28, 0, 16, 31, 241, 0, 214, 205, 22], ["-", 3, 4, 0, 28, 0, 16, 12, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 16, 12, 214, 205, 22]]
8
3,267
8
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Abc167F { struct Bracket { public long BraN; public long KetN; } public static void Main() { var n = int.Parse(Console.ReadLine()); long braN = 0; long ketN = 0; long m = 0; var bra = new List<Bracket>(); var ket = new List<Bracket>(); for (int i = 0; i < n; i++) { var s = Console.ReadLine(); m += s.Length; var x = new Bracket { BraN = 0, KetN = 0 }; for (int j = 0; j < s.Length; j++) { x.BraN += s[j] == '(' ? 1 : -1; if (x.KetN > x.BraN) x.KetN = x.BraN; } x.KetN = -x.KetN; x.BraN += x.KetN; if (x.BraN == 0) ketN += x.KetN; else if (x.KetN == 0) braN += x.BraN; else if (x.BraN >= x.KetN) bra.Add(x); else ket.Add(x); } foreach (var item in bra.OrderBy(x => x.KetN)) { braN -= item.KetN; if (braN < 0) { Console.WriteLine("No"); return; } braN += item.BraN; } foreach (var item in ket.OrderByDescending(x => x.BraN)) braN += item.BraN - item.KetN; Console.WriteLine(braN == ketN ? "Yes" : "No"); } } }
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Abc167F { struct Bracket { public long BraN; public long KetN; } public static void Main() { var n = int.Parse(Console.ReadLine()); long braN = 0; long ketN = 0; long m = 0; var bra = new List<Bracket>(); var ket = new List<Bracket>(); for (int i = 0; i < n; i++) { var s = Console.ReadLine(); m += s.Length; var x = new Bracket { BraN = 0, KetN = 0 }; for (int j = 0; j < s.Length; j++) { x.BraN += s[j] == '(' ? 1 : -1; if (x.KetN > x.BraN) x.KetN = x.BraN; } x.KetN = -x.KetN; x.BraN += x.KetN; if (x.BraN == 0) ketN += x.KetN; else if (x.KetN == 0) braN += x.BraN; else if (x.BraN >= x.KetN) bra.Add(x); else ket.Add(x); } foreach (var item in bra.OrderBy(x => x.KetN)) { braN -= item.KetN; if (braN < 0) { Console.WriteLine("No"); return; } braN += item.BraN; } foreach (var item in ket.OrderBy(x => x.BraN)) { ketN -= item.BraN; if (ketN < 0) { Console.WriteLine("No"); return; } ketN += item.KetN; } Console.WriteLine(braN == ketN ? "Yes" : "No"); } } }
[["-", 8, 196, 0, 210, 12, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 210, 12, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 210, 8, 1, 0, 11, 31, 22], ["-", 0, 210, 8, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 195, 8, 196, 0, 210, 8, 196, 0, 45], ["+", 0, 210, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["-", 0, 210, 8, 1, 0, 11, 12, 16, 17, 33], ["+", 8, 196, 0, 210, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 24], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 25], ["+", 0, 210, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 210, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 195, 8, 196, 0, 210, 8, 196, 0, 46]]
8
358
31
using System; using System.Collections.Generic; using System.Collections; using System.Collections.Specialized; using System.Linq; using System.Text; using System.IO; using System.Reflection; using static System.Math; using System.Numerics; static class Program { const int mod = (int)1e9 + 7; const double eps = 1e-11; static void Main() { Sc sc = new Sc(); var n = sc.I; var h = new int [n][]; var b = new bool[n]; for (int i = 0; i < n; i++) { var t = sc.S; h[i] = new int[2]; int g = 0; for (int j = 0; j < t.Length; j++) { if (t[j] == ')') { g--; } else { g++; } if (g < 0) { h[i][0]++; g = 0; } } if (g > 0) { h[i][1] = g; } } h = h.OrderBy(x => x[0]).ThenByDescending(x => x[1]).ToArray(); int p = 0; for (int i = 0; i < n; i++) { if (h[i][0] == 0) { p += h[i][1]; b[i] = true; } } for (int i = 0; i < n; i++) { if (b[i]) { continue; } if (h[i][0] <= h[i][1]) { p -= h[i][0]; if (p < 0) { Console.WriteLine("No"); return; } p += h[i][1]; b[i] = true; } } h = h.OrderByDescending(x => x[0]).ThenByDescending(x => x[1]).ToArray(); for (int i = 0; i < n; i++) { if (h[i][0] == 0 || h[i][0] <= h[i][1]) { continue; } p -= h[i][0]; if (p < 0) { Console.WriteLine("No"); return; } p += h[i][1]; } Console.WriteLine("{0}", p == 0 ? "Yes" : "No"); } } public class Sc { public int I { get { return int.Parse(Console.ReadLine()); } } public long L { get { return long.Parse(Console.ReadLine()); } } public double D { get { return double.Parse(Console.ReadLine()); } } public string S { get { return Console.ReadLine(); } } public int[] Ia { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } } public long[] La { get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); } } public double[] Da { get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); } } public string[] Sa { get { return Console.ReadLine().Split(); } } public object[] Oa { get { return Console.ReadLine().Split(); } } public int[] Ia2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), int.Parse); } } public int[] Ia3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), int.Parse); } public int[] Ia3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), int.Parse); } public long[] La2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), long.Parse); } } public long[] La3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), long.Parse); } public long[] La3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), long.Parse); } public double[] Da2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), double.Parse); } } public double[] Da3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), double.Parse); } public double[] Da3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), double.Parse); } public T[] Arr<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(); } return a; } public T[] Arr<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(i); } return a; } public T[] Arr<T>(int n, Func<string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(Console.ReadLine().Split()); } return a; } public T[] Arr<T>(int n, Func<int, string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(i, Console.ReadLine().Split()); } return a; } }
using System; using System.Collections.Generic; using System.Collections; using System.Collections.Specialized; using System.Linq; using System.Text; using System.IO; using System.Reflection; using static System.Math; using System.Numerics; using nint = System.Int64; static class Program { const int mod = (int)1e9 + 7; const double eps = 1e-11; static void Main() { Sc sc = new Sc(); var n = sc.I; var h = new int [n][]; var b = new bool[n]; for (int i = 0; i < n; i++) { var t = sc.S; h[i] = new int[2]; int g = 0; for (int j = 0; j < t.Length; j++) { if (t[j] == ')') { g--; } else { g++; } if (g < 0) { h[i][0]++; g = 0; } } if (g > 0) { h[i][1] = g; } } h = h.OrderBy(x => x[0]).ThenByDescending(x => x[1]).ToArray(); int p = 0; for (int i = 0; i < n; i++) { if (h[i][0] == 0) { p += h[i][1]; b[i] = true; } } for (int i = 0; i < n; i++) { if (b[i]) { continue; } if (h[i][0] <= h[i][1]) { p -= h[i][0]; if (p < 0) { Console.WriteLine("No"); return; } p += h[i][1]; b[i] = true; } } h = h.OrderByDescending(x => x[1]).ToArray(); for (int i = 0; i < n; i++) { if (h[i][0] == 0 || h[i][0] <= h[i][1]) { continue; } p -= h[i][0]; if (p < 0) { Console.WriteLine("No"); return; } p += h[i][1]; } Console.WriteLine("{0}", p == 0 ? "Yes" : "No"); } } public class Sc { public int I { get { return int.Parse(Console.ReadLine()); } } public long L { get { return long.Parse(Console.ReadLine()); } } public double D { get { return double.Parse(Console.ReadLine()); } } public string S { get { return Console.ReadLine(); } } public int[] Ia { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } } public long[] La { get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); } } public double[] Da { get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); } } public string[] Sa { get { return Console.ReadLine().Split(); } } public object[] Oa { get { return Console.ReadLine().Split(); } } public int[] Ia2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), int.Parse); } } public int[] Ia3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), int.Parse); } public int[] Ia3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), int.Parse); } public long[] La2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), long.Parse); } } public long[] La3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), long.Parse); } public long[] La3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), long.Parse); } public double[] Da2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), double.Parse); } } public double[] Da3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), double.Parse); } public double[] Da3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), double.Parse); } public T[] Arr<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(); } return a; } public T[] Arr<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(i); } return a; } public T[] Arr<T>(int n, Func<string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(Console.ReadLine().Split()); } return a; } public T[] Arr<T>(int n, Func<int, string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(i, Console.ReadLine().Split()); } return a; } }
[["+", 36, 36, 0, 208, 0, 299, 0, 197, 0, 233], ["+", 0, 208, 0, 299, 0, 197, 0, 198, 39, 199], ["+", 0, 299, 0, 197, 0, 198, 39, 199, 0, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 205, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 0, 131], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["+", 36, 36, 0, 208, 0, 299, 0, 197, 0, 35], ["-", 205, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["-", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["-", 205, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["-", 3, 4, 0, 28, 0, 218, 8, 204, 205, 22], ["-", 0, 28, 0, 218, 8, 204, 206, 207, 0, 70], ["-", 0, 218, 8, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 28, 0, 218, 8, 204, 206, 207, 0, 73], ["-", 205, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["-", 12, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["-", 12, 213, 63, 214, 205, 213, 63, 214, 141, 22]]
8
1,494
18
using System; using System.IO; using System.Linq; namespace AtCoder.R167.F { public static class Solver { public static void Main() { using (var sw = new StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }) { Solve(Console.In, sw); } } public static void Solve(TextReader tr, TextWriter tw) { WriteAnswer(tw, Parse(tr)); } private static void WriteAnswer(TextWriter tw, string answer) { tw.WriteLine(answer); } private static string Parse(TextReader tr) { var n = int.Parse(tr.ReadLine()); var s = new string[n]; for (int i = 0; i < n; ++i) { s[i] = tr.ReadLine(); } return Calc(s); } public static string Calc(string[] s) { var t = new(int, int)[s.Length]; for (int i = 0; i < s.Length; ++i) { foreach (var c in s[i]) { if (c == '(') { ++t[i].Item2; } else if (c == ')') { t[i].Item1 = Math.Min(t[i].Item1, --t[i].Item2); } } } if (t.Sum(x => x.Item2) != 0) return "No"; var upper = t.Where(x => x.Item2 >= 0).OrderByDescending(x => x.Item1).ToArray(); var lower = t.Where(x => x.Item2 < 0).ToArray(); var currentLevel = 0; foreach (var u in upper) { if (u.Item1 + currentLevel < 0) { return "No"; } currentLevel += u.Item2; } foreach (var u in lower) { if (u.Item1 + currentLevel < 0) { return "No"; } currentLevel += u.Item2; } return "Yes"; } } }
using System; using System.IO; using System.Linq; namespace AtCoder.R167.F { public static class Solver { public static void Main() { using (var sw = new StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }) { Solve(Console.In, sw); } } public static void Solve(TextReader tr, TextWriter tw) { WriteAnswer(tw, Parse(tr)); } private static void WriteAnswer(TextWriter tw, string answer) { tw.WriteLine(answer); } private static string Parse(TextReader tr) { var n = int.Parse(tr.ReadLine()); var s = new string[n]; for (int i = 0; i < n; ++i) { s[i] = tr.ReadLine(); } return Calc(s); } public static string Calc(string[] s) { var t = new(int, int)[s.Length]; for (int i = 0; i < s.Length; ++i) { foreach (var c in s[i]) { if (c == '(') { ++t[i].Item2; } else if (c == ')') { t[i].Item1 = Math.Min(t[i].Item1, --t[i].Item2); } } } if (t.Sum(x => x.Item2) != 0) return "No"; var upper = t.Where(x => x.Item2 >= 0).OrderByDescending(x => x.Item1).ToArray(); var lower = t.Where(x => x.Item2 < 0).OrderBy(x => x.Item1 - x.Item2).ToArray(); var currentLevel = 0; foreach (var u in upper) { if (u.Item1 + currentLevel < 0) { return "No"; } currentLevel += u.Item2; } foreach (var u in lower) { if (u.Item1 + currentLevel < 0) { return "No"; } currentLevel += u.Item2; } return "Yes"; } } }
[["+", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 205, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 0, 28, 0, 218, 8, 16, 31, 214, 205, 22], ["+", 0, 28, 0, 218, 8, 16, 31, 214, 0, 131], ["+", 0, 28, 0, 218, 8, 16, 31, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 17, 33], ["+", 0, 28, 0, 218, 8, 16, 12, 214, 205, 22], ["+", 0, 28, 0, 218, 8, 16, 12, 214, 0, 131], ["+", 0, 28, 0, 218, 8, 16, 12, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131]]
8
431
13
using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace V { partial class Solver { public void Solve() { // Write(SolveLong()); YesNo(SolveBool()); } public long SolveLong() { long n = Read; return 0; } public bool SolveBool() { long n = Read; var s = ArrStr(n); var p = s.Select(x => Convert(x)).ToArray(); if (p.Select(x => x.final).Sum() != 0) return false; var current = p.Where(x => x.min >= 0).Sum(x => x.final); var pp = p.Where(x => x.min < 0) .OrderBy(x => x.min - x.final) .ThenByDescending(x => x.min); var cur = current; var res = true; foreach (var ppp in pp) { if (cur + ppp.min < 0) { res = false; break; } cur += ppp.final; } if (res) return true; pp = p.Where(x => x.min < 0).OrderByDescending(x => x.min); cur = current; res = true; foreach (var ppp in pp) { if (cur + ppp.min < 0) { res = false; break; } cur += ppp.final; } if (res) return true; return false; } (int min, int final) Convert(string s) { var min = 0; var final = 0; foreach (var c in s) { if (c == '(') final++; else final--; min = Math.Min(min, final); } return (min, final); } } } namespace V { class StartingPoint { static void Main(string[] args) { try { var streamReader = args.Any() ? new StreamReader(args[0]) : new StreamReader(Console.OpenStandardInput()); var streamWriter = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; var scanner = new Scanner(streamReader); var printer = new Printer(streamWriter); var solver = new Solver(scanner, printer); solver.Solve(); streamWriter.Flush(); } catch (Exception e) { Console.WriteLine(e); if (args.Any() == false) throw e; } if (args.Any()) Console.ReadKey(); } } } namespace V { partial class Solver { public Solver(Scanner sc, Printer pr) { this.sc = sc; this.pr = pr; } private readonly Scanner sc; private readonly Printer pr; private IEnumerable<int> Loop(int n) => C.Loop(n); private IEnumerable<long> Loop(long n) => C.Loop(n); private int RdInt => sc.Int; private int ReadInt => sc.Int; private long Rd => sc.Long; private long Read => sc.Long; private long ReadLong => sc.Long; private double RdDouble => sc.Double; private double ReadDouble => sc.Double; private string Str => sc.Str; private string RdStr => sc.Str; private string ReadStr => sc.Str; private int[] ArrInt(int n) => sc.Ints(n); private int[] ArrInt(long n) => sc.Ints(n); private long[] Arr(int n) => sc.Longs(n); private long[] Arr(long n) => sc.Longs(n); private long[] ArrLong(int n) => sc.Longs(n); private long[] ArrLong(long n) => sc.Longs(n); private double[] ArrDouble(int n) => sc.Doubles(n); private double[] ArrDouble(long n) => sc.Doubles(n); private string[] ArrStr(int n) => sc.Strs(n); private string[] ArrStr(long n) => sc.Strs(n); private void Wr(string s) => pr.Write(s); private void Wr(object obj) => pr.Write(obj); private void Wr<T>(IEnumerable<T> ts) => pr.Write(ts); private void Wr(params object[] objs) => pr.Write(objs); private void Write(string s) => pr.Write(s); private void Write(object obj) => pr.Write(obj); private void Write<T>(IEnumerable<T> ts) => pr.Write(ts); private void Write(params object[] objs) => pr.Write(objs); private void YesNo(bool b) => Write(b ? "Yes" : "No"); private void YESNO(bool b) => Write(b ? "YES" : "NO"); } class Scanner { private readonly TextReader reader; public Scanner(TextReader reader) { this.reader = reader; } private Queue<string> strQueue = new Queue<string>(); public string Str { get { if (strQueue.Count > 0) return strQueue.Dequeue(); string[] strs = null; do { strs = reader.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); } while (strs.Any() == false); foreach (var s in strs.Skip(1)) strQueue.Enqueue(s); return strs[0]; } } public int Int => int.Parse(this.Str); public long Long => long.Parse(this.Str); public double Double => double.Parse(this.Str); public static bool TypeEquals<T1, T2>() => typeof(T1).Equals(typeof(T2)); public static T1 ChangeTypes<T1, T2>(T2 t2) => (T1)System.Convert.ChangeType(t2, typeof(T1)); public static T1 Convert<T1>(string s) => TypeEquals<T1, int>() ? ChangeTypes<T1, int>(int.Parse(s)) : TypeEquals<T1, long>() ? ChangeTypes<T1, long>(long.Parse(s)) : TypeEquals<T1, double>() ? ChangeTypes<T1, double>(int.Parse(s)) : TypeEquals<T1, char>() ? ChangeTypes<T1, char>(s[0]) : ChangeTypes<T1, string>(s); public Pair<TX, TY> P2<TX, TY>() => new Pair<TX, TY>(Convert<TX>(this.Str), Convert<TY>(this.Str)); public Pair3<TX, TY, TZ> P3<TX, TY, TZ>() => new Pair3<TX, TY, TZ>( Convert<TX>(this.Str), Convert<TY>(this.Str), Convert<TZ>(this.Str)); public Pair4<TX, TY, TZ, TW> P4<TX, TY, TZ, TW>() => new Pair4<TX, TY, TZ, TW>(Convert<TX>(this.Str), Convert<TY>(this.Str), Convert<TZ>(this.Str), Convert<TW>(this.Str)); } static class ScannerExtension { public static int[] Ints(this Scanner scanner, int n) => scanner.Ints((long)n); public static int[] Ints(this Scanner scanner, long n) => scanner.ScanStrs<int>(n).ToArray(); public static long[] Longs(this Scanner scanner, int n) => scanner.Longs((long)n); public static long[] Longs(this Scanner scanner, long n) => scanner.ScanStrs<long>(n).ToArray(); public static double[] Doubles(this Scanner scanner, int n) => scanner.Doubles((long)n); public static double[] Doubles(this Scanner scanner, long n) => scanner.ScanStrs<double>(n).ToArray(); public static string[] Strs(this Scanner scanner, int n) => scanner.Strs((long)n); public static string[] Strs(this Scanner scanner, long n) => scanner.ScanStrs<string>(n).ToArray(); private static IEnumerable<T> ScanStrs<T>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return Scanner.Convert<T>(scanner.Str); } public static Pair<TX, TY>[] Pairs<TX, TY>(this Scanner scanner, int n) => scanner.Pairs<TX, TY>((long)n); public static Pair<TX, TY>[] Pairs<TX, TY>(this Scanner scanner, long n) => scanner.ScanPairs<TX, TY>(n).ToArray(); public static Pair<long, long>[] Pairs(this Scanner scanner, int n) => scanner.Pairs((long)n); public static Pair<long, long>[] Pairs(this Scanner scanner, long n) => scanner.ScanPairs<long, long>(n).ToArray(); public static Pair<int, int>[] PairsInt(this Scanner scanner, int n) => scanner.PairsInt((long)n); public static Pair<int, int>[] PairsInt(this Scanner scanner, long n) => scanner.ScanPairs<int, int>(n).ToArray(); private static IEnumerable<Pair<TX, TY>> ScanPairs<TX, TY>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P2<TX, TY>(); } public static Pair3<TX, TY, TZ>[] Pairs3<TX, TY, TZ>( this Scanner scanner, int n) => scanner.Pairs3<TX, TY, TZ>((long)n); public static Pair3<TX, TY, TZ>[] Pairs3<TX, TY, TZ>(this Scanner scanner, long n) => scanner.ScanPairs3<TX, TY, TZ>(n).ToArray(); public static Pair3<long, long, long>[] Pairs3(this Scanner scanner, int n) => scanner.Pairs3((long)n); public static Pair3<long, long, long>[] Pairs3(this Scanner scanner, long n) => scanner.ScanPairs3<long, long, long>(n).ToArray(); public static Pair3<int, int, int>[] Pairs3Int(this Scanner scanner, int n) => scanner.Pairs3Int((long)n); public static Pair3<int, int, int>[] Pairs3Int(this Scanner scanner, long n) => scanner.ScanPairs3<int, int, int>(n).ToArray(); private static IEnumerable<Pair3<TX, TY, TZ>> ScanPairs3<TX, TY, TZ>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P3<TX, TY, TZ>(); } public static Pair4<TX, TY, TZ, TW>[] Pairs4<TX, TY, TZ, TW>( this Scanner scanner, int n) => scanner.Pairs4<TX, TY, TZ, TW>((long)n); public static Pair4<TX, TY, TZ, TW>[] Pairs4<TX, TY, TZ, TW>( this Scanner scanner, long n) => scanner.ScanPairs4<TX, TY, TZ, TW>(n).ToArray(); public static Pair4<long, long, long, long>[] Pairs4( this Scanner scanner, int n) => scanner.Pairs4((long)n); public static Pair4<long, long, long, long>[] Pairs4(this Scanner scanner, long n) => scanner.ScanPairs4<long, long, long, long>(n).ToArray(); public static Pair4<int, int, int, int>[] Pairs4Int( this Scanner scanner, int n) => scanner.Pairs4Int((long)n); public static Pair4<int, int, int, int>[] Pairs4Int(this Scanner scanner, long n) => scanner.ScanPairs4<int, int, int, int>(n).ToArray(); private static IEnumerable<Pair4<TX, TY, TZ, TW>> ScanPairs4<TX, TY, TZ, TW>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P4<TX, TY, TZ, TW>(); } } class Pair<TX, TY> { public TX X { get; } public TY Y { get; } public Pair(TX x, TY y) { this.X = x; this.Y = y; } } class Pair : Pair<long, long> { public Pair(long x, long y) : base(x, y) {} } class PairInt : Pair<int, int> { public PairInt(int x, int y) : base(x, y) {} } class Pair3<TX, TY, TZ> { public TX X { get; } public TY Y { get; } public TZ Z { get; } public Pair3(TX x, TY y, TZ z) { this.X = x; this.Y = y; this.Z = z; } } class Pair3 : Pair3<long, long, long> { public Pair3(long x, long y, long z) : base(x, y, z) {} } class Pair3Int : Pair3<int, int, int> { public Pair3Int(int x, int y, int z) : base(x, y, z) {} } class Pair4<TX, TY, TZ, TW> { public TX X { get; } public TY Y { get; } public TZ Z { get; } public TW W { get; } public Pair4(TX x, TY y, TZ z, TW w) { this.X = x; this.Y = y; this.Z = z; this.W = w; } } class Pair4 : Pair4<long, long, long, long> { public Pair4(long x, long y, long z, long w) : base(x, y, z, w) {} } class Pair4Int : Pair4<int, int, int, int> { public Pair4Int(int x, int y, int z, int w) : base(x, y, z, w) {} } class Printer { private readonly TextWriter writer; public Printer(TextWriter writer) { this.writer = writer; } public void Write(string obj) { writer.WriteLine(obj); } public void Write(object obj) { writer.WriteLine(obj); } public void Write<T>(IEnumerable<T> ts) { writer.WriteLine(string.Join(" ", ts)); } public void Write(params object[] objs) { writer.WriteLine(string.Join(" ", objs)); } } static class Extension { public static bool TryRemove<T>(this HashSet<T> ts, T t) { if (ts.Contains(t)) { ts.Remove(t); return true; } else { return false; } } public static void SafeSet<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] = value; else ts.Add(t, value); } public static void SafeAdd<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] += value; else ts.Add(t, value); } public static void SafeSub<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] -= value; else ts.Add(t, value); } public static void SafeMult<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] *= value; else ts.Add(t, value); } public static void SafeDiv<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] /= value; else ts.Add(t, value); } public static HashSet<T> ToHashSet<T>(this IEnumerable<T> ts) => new HashSet<T>(ts.Distinct()); public static long ToDigit(this char c) => (long)(c - '0'); public static long ToSmallAbcIndex(this char c) => (long)(c - 'a'); public static long ToLargeAbcIndex(this char c) => (long)(c - 'A'); public static long Count<T1, T2>(this IGrouping<T1, T2> gs) => gs.LongCount(); } class C { public class IterTools { /// <summary> /// 組み合わせ(重複なし) /// n = 4, k = 3 => (0,1,2) (0,1,3) (0,2,3) (1,2,3) /// </summary> public static IEnumerable<IReadOnlyList<long>> Combinations(long n, long k) { if (k <= 0) yield break; long[] indices = new long[k]; long pointer = 0; while (pointer >= 0) { if (indices[pointer] < n) { if (pointer >= k - 1) { yield return indices; indices[pointer]++; } else { indices[pointer + 1] = indices[pointer] + 1; pointer++; } } else { pointer--; if (pointer >= 0) indices[pointer]++; } } } /// <summary> /// 組み合わせ(重複なし) /// n = 4, k = 3 => (0,1,2) (0,1,3) (0,2,3) (1,2,3) /// </summary> public static IEnumerable<IReadOnlyList<T>> Combinations<T>(T[] ts, long k) { if (k <= 0) yield break; long[] indices = new long[k]; T[] container = new T[k]; long pointer = 0; long n = ts.LongLength; while (pointer >= 0) { if (indices[pointer] < n) { container[pointer] = ts[indices[pointer]]; if (pointer >= k - 1) { yield return container; indices[pointer]++; } else { indices[pointer + 1] = indices[pointer] + 1; pointer++; } } else { pointer--; if (pointer >= 0) indices[pointer]++; } } } /// <summary> /// 組み合わせ(重複あり) /// n = 3, k = 2 => (0,0) (0,1) (0,2) (1,0) (1,1) (1,2) (2,0) (2,1) (2,2) /// </summary> public static IEnumerable<IReadOnlyList<long>> CombinationsWithReplacement(long n, long k) { if (k <= 0) yield break; long[] container = new long[k]; long pointer = 0; while (pointer >= 0) { if (container[pointer] < n) { if (pointer >= k - 1) { yield return container; container[pointer]++; } else { container[pointer + 1] = 0; pointer++; } } else { pointer--; if (pointer >= 0) container[pointer]++; } } } /// <summary> /// 組み合わせ(重複あり) /// n = 3, k = 2 => (0,0) (0,1) (0,2) (1,0) (1,1) (1,2) (2,0) (2,1) (2,2) /// </summary> public static IEnumerable<IReadOnlyList<T>> CombinationsWithReplacement<T>(T[] ts, long k) { if (k <= 0) yield break; long[] indices = new long[k]; T[] container = new T[k]; long pointer = 0; long n = ts.LongLength; while (pointer >= 0) { if (indices[pointer] < n) { container[pointer] = ts[indices[pointer]]; if (pointer >= k - 1) { yield return container; indices[pointer]++; } else { indices[pointer + 1] = 0; pointer++; } } else { pointer--; if (pointer >= 0) indices[pointer]++; } } } /// <summary> /// 順列 /// n = 3, k = 2 => (0,1) (0,2) (1,0) (1,2) (2,0) (2,1) /// </summary> public static IEnumerable<IReadOnlyList<long>> Permutations(long n, long k) { if (k <= 0) yield break; HashSet<long> enumed = new HashSet<long>(); long[] container = new long[k]; long pointer = 0; while (pointer >= 0) { if (container[pointer] < n) { if (enumed.Contains(container[pointer])) { container[pointer]++; } else if (pointer >= k - 1) { yield return container; container[pointer]++; } else { enumed.Add(container[pointer]); container[pointer + 1] = 0; pointer++; } } else { pointer--; if (pointer >= 0) { enumed.Remove(container[pointer]); container[pointer]++; } } } } /// <summary> /// 順列 /// n = 3, k = 2 => (0,1) (0,2) (1,0) (1,2) (2,0) (2,1) /// </summary> public static IEnumerable<IReadOnlyList<T>> Permutations<T>(T[] ts, long k) { if (k <= 0) yield break; HashSet<long> enumed = new HashSet<long>(); long[] indices = new long[k]; T[] container = new T[k]; long pointer = 0; long n = ts.LongLength; while (pointer >= 0) { if (indices[pointer] < n) { if (enumed.Contains(indices[pointer])) { indices[pointer]++; } else if (pointer >= k - 1) { container[pointer] = ts[indices[pointer]]; yield return container; indices[pointer]++; } else { container[pointer] = ts[indices[pointer]]; enumed.Add(indices[pointer]); indices[pointer + 1] = 0; pointer++; } } else { pointer--; if (pointer >= 0) { enumed.Remove(indices[pointer]); indices[pointer]++; } } } } } public class Tree { public Tree() { toNodes = new Dictionary<long, long[]>(); } public Tree(Scanner sc, long n, bool base1 = true, bool singleDirection = false) { Adjust(sc.Pairs(n), base1, singleDirection); } public Tree(Pair<long, long>[] edges, bool base1 = true, bool singleDirection = false) { Adjust(edges, base1, singleDirection); } public Tree(IEnumerable<long> ps, IEnumerable<long> qs, bool base1 = true, bool singleDirection = false) { Adjust(ps.Zip(qs, (p, q) => new Pair<long, long>(p, q)).ToArray(), base1, singleDirection); } private void Adjust(Pair<long, long>[] edges, bool base1, bool singleDirection) { var arrows = base1 ? edges.Select(x => new { from = x.X - 1, to = x.Y - 1 }) : edges.Select(x => new { from = x.X, to = x.Y }); if (singleDirection == false) arrows = arrows.Concat(arrows.Select(x => new { from = x.to, to = x.from })); toNodes = arrows.GroupBy(x => x.from) .ToDictionary(x => x.Key, x => x.Select(xs => xs.to).ToArray()); } private long[] empty = new long[0]; private Dictionary<long, long[]> toNodes; public long[] To(long from) { long[] res = null; if (toNodes.TryGetValue(from, out res)) return res; else return empty; } public IEnumerable<Pair<long, long>> GetRouteEdges(long from, long to) { return GetRouteEdgesImpl(from, to).Skip(1); } private IEnumerable<Pair<long, long>> GetRouteEdgesImpl(long from, long to) { var routeNodes = GetRouteNodes(from, to); var current = -1L; foreach (var next in routeNodes) { yield return new Pair<long, long>(current, next); current = next; } } public IEnumerable<long> GetRouteNodes(long from, long to) { Stack<long> routeNodes = new Stack<long>(); HashSet<long> checkedNodes = new HashSet<long>(); GetRouteNodes(from, to, routeNodes, checkedNodes); return routeNodes.Reverse(); } private bool GetRouteNodes(long current, long dest, Stack<long> routeNodes, HashSet<long> checkedNodes) { routeNodes.Push(current); checkedNodes.Add(current); if (current == dest) return true; foreach (var next in toNodes[current]) { if (checkedNodes.Contains(next)) continue; if (GetRouteNodes(next, dest, routeNodes, checkedNodes)) return true; } routeNodes.Pop(); return false; } } public class PriorityQueue<TKey, TState> where TKey : IComparable<TKey> { public int Count { get; private set; } private readonly Func<TState, TKey> keySelector; private readonly bool desc; private TState[] states = new TState[65536]; private TKey[] keys = new TKey[65536]; //[MethodImpl(MethodImplOptions.AggressiveInlining)] public PriorityQueue(Func<TState, TKey> keySelector, bool desc = false) { this.keySelector = keySelector; this.desc = desc; } public TState Top { //[MethodImpl(MethodImplOptions.AggressiveInlining)] get { ValidateNonEmpty(); return states[1]; } } //[MethodImpl(MethodImplOptions.AggressiveInlining)] public TState Dequeue() { var top = Top; var item = states[Count]; var key = keys[Count]; Count--; int index = 1; while (true) { if ((index << 1) >= Count) { if (index << 1 > Count) break; if (key.CompareTo(keys[index << 1]) <= 0 ^ desc) break; states[index] = states[index << 1]; keys[index] = keys[index << 1]; index <<= 1; } else { var nextIndex = keys[index << 1].CompareTo(keys[(index << 1) + 1]) <= 0 ^ desc ? (index << 1) : (index << 1) + 1; if (key.CompareTo(keys[nextIndex]) <= 0 ^ desc) break; states[index] = states[nextIndex]; keys[index] = keys[nextIndex]; index = nextIndex; } } states[index] = item; keys[index] = key; return top; } //[MethodImpl(MethodImplOptions.AggressiveInlining)] public void Enqueue(TState state) { var key = keySelector.Invoke(state); Count++; int index = Count; if (states.Length == Count) Extend(states.Length * 2); while ((index >> 1) != 0) { if (keys[index >> 1].CompareTo(key) <= 0 ^ desc) break; states[index] = states[index >> 1]; keys[index] = keys[index >> 1]; index >>= 1; } states[index] = state; keys[index] = key; } //[MethodImpl(MethodImplOptions.AggressiveInlining)] private void Extend(int newSize) { TState[] newStates = new TState[newSize]; TKey[] newKeys = new TKey[newSize]; states.CopyTo(newStates, 0); keys.CopyTo(newKeys, 0); states = newStates; keys = newKeys; } private void ValidateNonEmpty() { if (Count == 0) throw new IndexOutOfRangeException(); } } public class BinaryIndexTree { long length; long[] binaryIndexedTree; public BinaryIndexTree(long length) { this.length = length; binaryIndexedTree = new long[length + 1]; } public void Add(long indexZeroBase, long additional) { // i += i & -i // 1が立っている最下位ビットを足す、の意味 for (long i = indexZeroBase + 1; i <= length; i += i & -i) { binaryIndexedTree[i] += additional; } } public long Sum(long indexZeroBase) { long result = 0; // i += i & -i // 1が立っている最下位ビットを引く、の意味 for (long i = indexZeroBase + 1; i > 0; i -= i & -i) { result += binaryIndexedTree[i]; } return result; } } public static class BinarySearch { public static long GetFirstIndexGreater(long x, IReadOnlyList<long> listOrdered) { var count = listOrdered.Count; if (count == 0) return 0; if (listOrdered[count - 1] <= x) return count; int low = 0; int high = listOrdered.Count - 1; while (low < high) { var mid = (low + high) / 2; if (listOrdered[mid] > x) high = mid; else low = mid + 1; } return low; } public static long GetFirstIndexGreater(int x, IReadOnlyList<int> listOrdered) { var count = listOrdered.Count; if (count == 0) return 0; if (listOrdered[count - 1] <= x) return count; int low = 0; int high = listOrdered.Count - 1; while (low < high) { var mid = (low + high) / 2; if (listOrdered[mid] > x) high = mid; else low = mid + 1; } return low; } public static long GetLastIndexLess(long x, IReadOnlyList<long> listOrdered) { var count = listOrdered.Count; if (count == 0) return -1; if (listOrdered[0] >= x) return -1; int low = 0; int high = listOrdered.Count - 1; while (low < high) { var mid = (low + high + 1) / 2; if (listOrdered[mid] < x) low = mid; else high = mid - 1; } return low; } public static long GetLastIndexLess(int x, IReadOnlyList<int> listOrdered) { var count = listOrdered.Count; if (count == 0) return -1; if (listOrdered[0] >= x) return -1; int low = 0; int high = listOrdered.Count - 1; while (low < high) { var mid = (low + high + 1) / 2; if (listOrdered[mid] < x) low = mid; else high = mid - 1; } return low; } } public static class BellmanFord { public class Vertex { public long Distance { get; set; } public Vertex() { Distance = long.MaxValue; } } public class Edge { public int From { get; private set; } public int To { get; private set; } public long Weight { get; private set; } public Edge(int from, int to, long weight) { From = from; To = to; Weight = weight; } } private static void GetReachable(int origin, ref HashSet<int> reached, ref Dictionary<int, int[]> paths) { if (reached.Contains(origin)) return; reached.Add(origin); if (paths.ContainsKey(origin) == false) return; foreach (var p in paths[origin]) GetReachable(p, ref reached, ref paths); } /// <summary> /// null: 負の無限大 /// long.MaxValue: たどり着けない /// その他: 距離 /// </summary> public static long? RunBellmanFord(int vertexCount, List<Edge> rawEdges, int source, int dest) { var forwards = rawEdges.GroupBy(x => x.From) .ToDictionary(x => x.Key, x => x.Select(xs => xs.To).ToArray()); var reverses = rawEdges.GroupBy(x => x.To).ToDictionary( x => x.Key, x => x.Select(xs => xs.From).ToArray()); var fromSource = new HashSet<int>(); var toDest = new HashSet<int>(); GetReachable(source, ref fromSource, ref forwards); GetReachable(dest, ref toDest, ref reverses); var edges = rawEdges.Where(e => fromSource.Contains(e.From)) .Where(e => fromSource.Contains(e.To)) .Where(e => toDest.Contains(e.From)) .Where(e => toDest.Contains(e.To)) .ToArray(); // initialize distances var vertices = new List<Vertex>(); for (int i = 0; i < vertexCount; i++) vertices.Add(new Vertex()); vertices[source].Distance = 0L; // update distances for (int i = 0; i < vertices.Count; i++) { foreach (var e in edges) { var from = vertices[e.From]; var to = vertices[e.To]; if (from.Distance == long.MaxValue) continue; var newDistance = from.Distance + e.Weight; if (to.Distance > newDistance) { to.Distance = newDistance; } } } // check negative cycle foreach (var e in edges) { var from = vertices[e.From]; var to = vertices[e.To]; if (from.Distance + e.Weight < to.Distance) return null; } return vertices[dest].Distance; } } public static long Gcd(int a, int b) => Gcd((long)a, (long)b); public static long Gcd(long a, long b) { if (a < b) return GcdImpl(b, a); else return GcdImpl(a, b); } private static long GcdImpl(long a, long b) { var remainder = a % b; if (remainder == 0) return b; else return GcdImpl(b, remainder); } public static long Lcm(int a, int b) => Lcm((long)a, (long)b); public static long Lcm(long a, long b) { return a / Gcd(a, b) * b; } public static long Pow(int n, int p) => Pow((long)n, (long)p); public static long Pow(long n, long p) { var res = 1L; for (long i = 0; i < p; i++) res *= n; return res; } public static Dictionary<long, long> Factorize(int n) => Factorize((long)n); public static Dictionary<long, long> Factorize(long n) { var res = new Dictionary<long, long>(); var r = n; for (long i = 2; i * i <= r; i++) { var c = 0L; while (r % i == 0) { c++; r /= i; } if (c > 0) res.Add(i, c); } if (r > 1) res.Add(r, 1); return res; } public static IEnumerable<long> Divisors(int n) => Divisors((long)n); public static IEnumerable<long> Divisors(long n) { var cache = new Stack<long>(); for (long i = 1; i * i <= n; i++) { if (n % i == 0) { yield return i; cache.Push(i); } } var r = cache.Peek(); if (r * r == n) cache.Pop(); while (cache.Count > 0) { var i = cache.Pop(); yield return n / i; } } public static IEnumerable<int> Loop(int n) { for (int i = 0; i < n; i++) yield return i; } public static IEnumerable<long> Loop(long n) { for (long i = 0L; i < n; i++) yield return i; } } struct Mint { public static long Divider { set { divider = value; } } private static long divider = 1000000007L; public static void Set998244353() { divider = 998244353L; } public static void Set1000000009() { divider = 1000000009L; } public long Value { get; } public override string ToString() => this.Value.ToString(); public Mint(long value) { this.Value = value; } // public static implicit operator Mint(long a) => new Mint(a % divider); // public static implicit operator Mint(int a) => new Mint(a % divider); // public static explicit operator long(Mint a) => a.Value; // public static explicit operator int(Mint a) => (int)a.Value; public static Mint operator +(Mint a, Mint b) => new Mint((a.Value + b.Value) % divider); public static Mint operator +(Mint a, long b) => a + new Mint(b); public static Mint operator +(Mint a, int b) => a + new Mint(b); public static Mint operator -(Mint a, Mint b) { var t = (a.Value - b.Value) % divider; if (t < 0L) t += divider; return new Mint(t); } public static Mint operator -(Mint a, long b) => a - new Mint(b); public static Mint operator -(Mint a, int b) => a - new Mint(b); public static Mint operator *(Mint a, Mint b) => new Mint((a.Value * b.Value) % divider); public static Mint operator *(Mint a, long b) => a * new Mint(b); public static Mint operator *(Mint a, int b) => a * new Mint(b); public static Mint operator /(Mint a, Mint b) => new Mint((a.Value * InvImpl(b.Value)) % divider); public static Mint operator /(Mint a, long b) => a / new Mint(b); public static Mint operator /(Mint a, int b) => a / new Mint(b); public Mint Pow(long p) => new Mint(PowImpl(Value, p)); public static Mint Pow(long a, long p) => new Mint(PowImpl(a, p)); private static long PowImpl(long a, long p) { if (p == 0L) return 1L; if (p == 1L) return a; var halfP = p / 2L; var halfPowered = PowImpl(a, halfP); var powered = halfPowered * halfPowered % divider; return p % 2L == 0L ? powered : powered * a % divider; } public static Mint Inv(long a) => new Mint(InvImpl(a)); private static readonly Dictionary<long, long> invCache = new Dictionary<long, long>(); private static long InvImpl(long a) { long cache; if (invCache.TryGetValue(a, out cache)) return cache; var result = PowImpl(a, divider - 2L); invCache.Add(a, result); return result; } public static Mint Fac(long a) => new Mint(FacImpl(a)); private static long[] facCache = new long[262144]; private static long cachedFac = 0L; private static long FacImpl(long a) { if (a >= divider) return 0L; facCache[0] = 1L; if (facCache.LongLength <= a) { long newSize = facCache.LongLength; while (newSize <= a) { newSize *= 2; } ExtendFacCache(newSize); } if (cachedFac < a) { var val = facCache[cachedFac]; var start = cachedFac + 1L; for (long i = start; i <= a; i++) { val = (val * i) % divider; facCache[i] = val; } cachedFac = a; } return facCache[a]; } private static void ExtendFacCache(long newSize) { long[] newFacCache = new long[newSize]; facCache.CopyTo(newFacCache, 0); facCache = newFacCache; } public static Mint Perm(long n, long r) => new Mint(PermImpl(n, r)); private static long PermImpl(long n, long r) { if (n < r) return 0L; if (r <= 0L) return 1L; var nn = FacImpl(n); var nr = FacImpl(n - r); return (nn * InvImpl(nr)) % divider; } public static Mint Comb(long n, long r) => new Mint(CombImpl(n, r)); private static long CombImpl(long n, long r) { if (n < r) return 0L; if (n == r) return 1L; if (n - r < r) return CombImpl(n, n - r); var nn = FacImpl(n); var nr = FacImpl(n - r); var rr = FacImpl(r); var nrrr = (nr * rr) % divider; return (nn * InvImpl(nrrr)) % divider; } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace V { partial class Solver { public void Solve() { // Write(SolveLong()); YesNo(SolveBool()); } public long SolveLong() { long n = Read; return 0; } public bool SolveBool() { long n = Read; var s = ArrStr(n); var p = s.Select(x => Convert(x)).ToArray(); if (p.Select(x => x.final).Sum() != 0) return false; var current = p.Where(x => x.min >= 0).Sum(x => x.final); var pp = p.Where(x => x.min < 0) .OrderBy(x => x.min - x.final) .ThenByDescending(x => x.min); var cur = current; var res = true; foreach (var ppp in pp) { if (cur + ppp.min < 0) { res = false; break; } cur += ppp.final; } if (res) return true; pp = p.Where(x => x.min < 0) .OrderBy(x => x.min == x.final) .ThenByDescending(x => x.min); cur = current; res = true; foreach (var ppp in pp) { if (cur + ppp.min < 0) { res = false; break; } cur += ppp.final; } if (res) return true; return false; } (int min, int final) Convert(string s) { var min = 0; var final = 0; foreach (var c in s) { if (c == '(') final++; else final--; min = Math.Min(min, final); } return (min, final); } } } namespace V { class StartingPoint { static void Main(string[] args) { try { var streamReader = args.Any() ? new StreamReader(args[0]) : new StreamReader(Console.OpenStandardInput()); var streamWriter = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; var scanner = new Scanner(streamReader); var printer = new Printer(streamWriter); var solver = new Solver(scanner, printer); solver.Solve(); streamWriter.Flush(); } catch (Exception e) { Console.WriteLine(e); if (args.Any() == false) throw e; } if (args.Any()) Console.ReadKey(); } } } namespace V { partial class Solver { public Solver(Scanner sc, Printer pr) { this.sc = sc; this.pr = pr; } private readonly Scanner sc; private readonly Printer pr; private IEnumerable<int> Loop(int n) => C.Loop(n); private IEnumerable<long> Loop(long n) => C.Loop(n); private int RdInt => sc.Int; private int ReadInt => sc.Int; private long Rd => sc.Long; private long Read => sc.Long; private long ReadLong => sc.Long; private double RdDouble => sc.Double; private double ReadDouble => sc.Double; private string Str => sc.Str; private string RdStr => sc.Str; private string ReadStr => sc.Str; private int[] ArrInt(int n) => sc.Ints(n); private int[] ArrInt(long n) => sc.Ints(n); private long[] Arr(int n) => sc.Longs(n); private long[] Arr(long n) => sc.Longs(n); private long[] ArrLong(int n) => sc.Longs(n); private long[] ArrLong(long n) => sc.Longs(n); private double[] ArrDouble(int n) => sc.Doubles(n); private double[] ArrDouble(long n) => sc.Doubles(n); private string[] ArrStr(int n) => sc.Strs(n); private string[] ArrStr(long n) => sc.Strs(n); private void Wr(string s) => pr.Write(s); private void Wr(object obj) => pr.Write(obj); private void Wr<T>(IEnumerable<T> ts) => pr.Write(ts); private void Wr(params object[] objs) => pr.Write(objs); private void Write(string s) => pr.Write(s); private void Write(object obj) => pr.Write(obj); private void Write<T>(IEnumerable<T> ts) => pr.Write(ts); private void Write(params object[] objs) => pr.Write(objs); private void YesNo(bool b) => Write(b ? "Yes" : "No"); private void YESNO(bool b) => Write(b ? "YES" : "NO"); } class Scanner { private readonly TextReader reader; public Scanner(TextReader reader) { this.reader = reader; } private Queue<string> strQueue = new Queue<string>(); public string Str { get { if (strQueue.Count > 0) return strQueue.Dequeue(); string[] strs = null; do { strs = reader.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); } while (strs.Any() == false); foreach (var s in strs.Skip(1)) strQueue.Enqueue(s); return strs[0]; } } public int Int => int.Parse(this.Str); public long Long => long.Parse(this.Str); public double Double => double.Parse(this.Str); public static bool TypeEquals<T1, T2>() => typeof(T1).Equals(typeof(T2)); public static T1 ChangeTypes<T1, T2>(T2 t2) => (T1)System.Convert.ChangeType(t2, typeof(T1)); public static T1 Convert<T1>(string s) => TypeEquals<T1, int>() ? ChangeTypes<T1, int>(int.Parse(s)) : TypeEquals<T1, long>() ? ChangeTypes<T1, long>(long.Parse(s)) : TypeEquals<T1, double>() ? ChangeTypes<T1, double>(int.Parse(s)) : TypeEquals<T1, char>() ? ChangeTypes<T1, char>(s[0]) : ChangeTypes<T1, string>(s); public Pair<TX, TY> P2<TX, TY>() => new Pair<TX, TY>(Convert<TX>(this.Str), Convert<TY>(this.Str)); public Pair3<TX, TY, TZ> P3<TX, TY, TZ>() => new Pair3<TX, TY, TZ>( Convert<TX>(this.Str), Convert<TY>(this.Str), Convert<TZ>(this.Str)); public Pair4<TX, TY, TZ, TW> P4<TX, TY, TZ, TW>() => new Pair4<TX, TY, TZ, TW>(Convert<TX>(this.Str), Convert<TY>(this.Str), Convert<TZ>(this.Str), Convert<TW>(this.Str)); } static class ScannerExtension { public static int[] Ints(this Scanner scanner, int n) => scanner.Ints((long)n); public static int[] Ints(this Scanner scanner, long n) => scanner.ScanStrs<int>(n).ToArray(); public static long[] Longs(this Scanner scanner, int n) => scanner.Longs((long)n); public static long[] Longs(this Scanner scanner, long n) => scanner.ScanStrs<long>(n).ToArray(); public static double[] Doubles(this Scanner scanner, int n) => scanner.Doubles((long)n); public static double[] Doubles(this Scanner scanner, long n) => scanner.ScanStrs<double>(n).ToArray(); public static string[] Strs(this Scanner scanner, int n) => scanner.Strs((long)n); public static string[] Strs(this Scanner scanner, long n) => scanner.ScanStrs<string>(n).ToArray(); private static IEnumerable<T> ScanStrs<T>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return Scanner.Convert<T>(scanner.Str); } public static Pair<TX, TY>[] Pairs<TX, TY>(this Scanner scanner, int n) => scanner.Pairs<TX, TY>((long)n); public static Pair<TX, TY>[] Pairs<TX, TY>(this Scanner scanner, long n) => scanner.ScanPairs<TX, TY>(n).ToArray(); public static Pair<long, long>[] Pairs(this Scanner scanner, int n) => scanner.Pairs((long)n); public static Pair<long, long>[] Pairs(this Scanner scanner, long n) => scanner.ScanPairs<long, long>(n).ToArray(); public static Pair<int, int>[] PairsInt(this Scanner scanner, int n) => scanner.PairsInt((long)n); public static Pair<int, int>[] PairsInt(this Scanner scanner, long n) => scanner.ScanPairs<int, int>(n).ToArray(); private static IEnumerable<Pair<TX, TY>> ScanPairs<TX, TY>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P2<TX, TY>(); } public static Pair3<TX, TY, TZ>[] Pairs3<TX, TY, TZ>( this Scanner scanner, int n) => scanner.Pairs3<TX, TY, TZ>((long)n); public static Pair3<TX, TY, TZ>[] Pairs3<TX, TY, TZ>(this Scanner scanner, long n) => scanner.ScanPairs3<TX, TY, TZ>(n).ToArray(); public static Pair3<long, long, long>[] Pairs3(this Scanner scanner, int n) => scanner.Pairs3((long)n); public static Pair3<long, long, long>[] Pairs3(this Scanner scanner, long n) => scanner.ScanPairs3<long, long, long>(n).ToArray(); public static Pair3<int, int, int>[] Pairs3Int(this Scanner scanner, int n) => scanner.Pairs3Int((long)n); public static Pair3<int, int, int>[] Pairs3Int(this Scanner scanner, long n) => scanner.ScanPairs3<int, int, int>(n).ToArray(); private static IEnumerable<Pair3<TX, TY, TZ>> ScanPairs3<TX, TY, TZ>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P3<TX, TY, TZ>(); } public static Pair4<TX, TY, TZ, TW>[] Pairs4<TX, TY, TZ, TW>( this Scanner scanner, int n) => scanner.Pairs4<TX, TY, TZ, TW>((long)n); public static Pair4<TX, TY, TZ, TW>[] Pairs4<TX, TY, TZ, TW>( this Scanner scanner, long n) => scanner.ScanPairs4<TX, TY, TZ, TW>(n).ToArray(); public static Pair4<long, long, long, long>[] Pairs4( this Scanner scanner, int n) => scanner.Pairs4((long)n); public static Pair4<long, long, long, long>[] Pairs4(this Scanner scanner, long n) => scanner.ScanPairs4<long, long, long, long>(n).ToArray(); public static Pair4<int, int, int, int>[] Pairs4Int( this Scanner scanner, int n) => scanner.Pairs4Int((long)n); public static Pair4<int, int, int, int>[] Pairs4Int(this Scanner scanner, long n) => scanner.ScanPairs4<int, int, int, int>(n).ToArray(); private static IEnumerable<Pair4<TX, TY, TZ, TW>> ScanPairs4<TX, TY, TZ, TW>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P4<TX, TY, TZ, TW>(); } } class Pair<TX, TY> { public TX X { get; } public TY Y { get; } public Pair(TX x, TY y) { this.X = x; this.Y = y; } } class Pair : Pair<long, long> { public Pair(long x, long y) : base(x, y) {} } class PairInt : Pair<int, int> { public PairInt(int x, int y) : base(x, y) {} } class Pair3<TX, TY, TZ> { public TX X { get; } public TY Y { get; } public TZ Z { get; } public Pair3(TX x, TY y, TZ z) { this.X = x; this.Y = y; this.Z = z; } } class Pair3 : Pair3<long, long, long> { public Pair3(long x, long y, long z) : base(x, y, z) {} } class Pair3Int : Pair3<int, int, int> { public Pair3Int(int x, int y, int z) : base(x, y, z) {} } class Pair4<TX, TY, TZ, TW> { public TX X { get; } public TY Y { get; } public TZ Z { get; } public TW W { get; } public Pair4(TX x, TY y, TZ z, TW w) { this.X = x; this.Y = y; this.Z = z; this.W = w; } } class Pair4 : Pair4<long, long, long, long> { public Pair4(long x, long y, long z, long w) : base(x, y, z, w) {} } class Pair4Int : Pair4<int, int, int, int> { public Pair4Int(int x, int y, int z, int w) : base(x, y, z, w) {} } class Printer { private readonly TextWriter writer; public Printer(TextWriter writer) { this.writer = writer; } public void Write(string obj) { writer.WriteLine(obj); } public void Write(object obj) { writer.WriteLine(obj); } public void Write<T>(IEnumerable<T> ts) { writer.WriteLine(string.Join(" ", ts)); } public void Write(params object[] objs) { writer.WriteLine(string.Join(" ", objs)); } } static class Extension { public static bool TryRemove<T>(this HashSet<T> ts, T t) { if (ts.Contains(t)) { ts.Remove(t); return true; } else { return false; } } public static void SafeSet<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] = value; else ts.Add(t, value); } public static void SafeAdd<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] += value; else ts.Add(t, value); } public static void SafeSub<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] -= value; else ts.Add(t, value); } public static void SafeMult<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] *= value; else ts.Add(t, value); } public static void SafeDiv<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] /= value; else ts.Add(t, value); } public static HashSet<T> ToHashSet<T>(this IEnumerable<T> ts) => new HashSet<T>(ts.Distinct()); public static long ToDigit(this char c) => (long)(c - '0'); public static long ToSmallAbcIndex(this char c) => (long)(c - 'a'); public static long ToLargeAbcIndex(this char c) => (long)(c - 'A'); public static long Count<T1, T2>(this IGrouping<T1, T2> gs) => gs.LongCount(); } class C { public class IterTools { /// <summary> /// 組み合わせ(重複なし) /// n = 4, k = 3 => (0,1,2) (0,1,3) (0,2,3) (1,2,3) /// </summary> public static IEnumerable<IReadOnlyList<long>> Combinations(long n, long k) { if (k <= 0) yield break; long[] indices = new long[k]; long pointer = 0; while (pointer >= 0) { if (indices[pointer] < n) { if (pointer >= k - 1) { yield return indices; indices[pointer]++; } else { indices[pointer + 1] = indices[pointer] + 1; pointer++; } } else { pointer--; if (pointer >= 0) indices[pointer]++; } } } /// <summary> /// 組み合わせ(重複なし) /// n = 4, k = 3 => (0,1,2) (0,1,3) (0,2,3) (1,2,3) /// </summary> public static IEnumerable<IReadOnlyList<T>> Combinations<T>(T[] ts, long k) { if (k <= 0) yield break; long[] indices = new long[k]; T[] container = new T[k]; long pointer = 0; long n = ts.LongLength; while (pointer >= 0) { if (indices[pointer] < n) { container[pointer] = ts[indices[pointer]]; if (pointer >= k - 1) { yield return container; indices[pointer]++; } else { indices[pointer + 1] = indices[pointer] + 1; pointer++; } } else { pointer--; if (pointer >= 0) indices[pointer]++; } } } /// <summary> /// 組み合わせ(重複あり) /// n = 3, k = 2 => (0,0) (0,1) (0,2) (1,0) (1,1) (1,2) (2,0) (2,1) (2,2) /// </summary> public static IEnumerable<IReadOnlyList<long>> CombinationsWithReplacement(long n, long k) { if (k <= 0) yield break; long[] container = new long[k]; long pointer = 0; while (pointer >= 0) { if (container[pointer] < n) { if (pointer >= k - 1) { yield return container; container[pointer]++; } else { container[pointer + 1] = 0; pointer++; } } else { pointer--; if (pointer >= 0) container[pointer]++; } } } /// <summary> /// 組み合わせ(重複あり) /// n = 3, k = 2 => (0,0) (0,1) (0,2) (1,0) (1,1) (1,2) (2,0) (2,1) (2,2) /// </summary> public static IEnumerable<IReadOnlyList<T>> CombinationsWithReplacement<T>(T[] ts, long k) { if (k <= 0) yield break; long[] indices = new long[k]; T[] container = new T[k]; long pointer = 0; long n = ts.LongLength; while (pointer >= 0) { if (indices[pointer] < n) { container[pointer] = ts[indices[pointer]]; if (pointer >= k - 1) { yield return container; indices[pointer]++; } else { indices[pointer + 1] = 0; pointer++; } } else { pointer--; if (pointer >= 0) indices[pointer]++; } } } /// <summary> /// 順列 /// n = 3, k = 2 => (0,1) (0,2) (1,0) (1,2) (2,0) (2,1) /// </summary> public static IEnumerable<IReadOnlyList<long>> Permutations(long n, long k) { if (k <= 0) yield break; HashSet<long> enumed = new HashSet<long>(); long[] container = new long[k]; long pointer = 0; while (pointer >= 0) { if (container[pointer] < n) { if (enumed.Contains(container[pointer])) { container[pointer]++; } else if (pointer >= k - 1) { yield return container; container[pointer]++; } else { enumed.Add(container[pointer]); container[pointer + 1] = 0; pointer++; } } else { pointer--; if (pointer >= 0) { enumed.Remove(container[pointer]); container[pointer]++; } } } } /// <summary> /// 順列 /// n = 3, k = 2 => (0,1) (0,2) (1,0) (1,2) (2,0) (2,1) /// </summary> public static IEnumerable<IReadOnlyList<T>> Permutations<T>(T[] ts, long k) { if (k <= 0) yield break; HashSet<long> enumed = new HashSet<long>(); long[] indices = new long[k]; T[] container = new T[k]; long pointer = 0; long n = ts.LongLength; while (pointer >= 0) { if (indices[pointer] < n) { if (enumed.Contains(indices[pointer])) { indices[pointer]++; } else if (pointer >= k - 1) { container[pointer] = ts[indices[pointer]]; yield return container; indices[pointer]++; } else { container[pointer] = ts[indices[pointer]]; enumed.Add(indices[pointer]); indices[pointer + 1] = 0; pointer++; } } else { pointer--; if (pointer >= 0) { enumed.Remove(indices[pointer]); indices[pointer]++; } } } } } public class Tree { public Tree() { toNodes = new Dictionary<long, long[]>(); } public Tree(Scanner sc, long n, bool base1 = true, bool singleDirection = false) { Adjust(sc.Pairs(n), base1, singleDirection); } public Tree(Pair<long, long>[] edges, bool base1 = true, bool singleDirection = false) { Adjust(edges, base1, singleDirection); } public Tree(IEnumerable<long> ps, IEnumerable<long> qs, bool base1 = true, bool singleDirection = false) { Adjust(ps.Zip(qs, (p, q) => new Pair<long, long>(p, q)).ToArray(), base1, singleDirection); } private void Adjust(Pair<long, long>[] edges, bool base1, bool singleDirection) { var arrows = base1 ? edges.Select(x => new { from = x.X - 1, to = x.Y - 1 }) : edges.Select(x => new { from = x.X, to = x.Y }); if (singleDirection == false) arrows = arrows.Concat(arrows.Select(x => new { from = x.to, to = x.from })); toNodes = arrows.GroupBy(x => x.from) .ToDictionary(x => x.Key, x => x.Select(xs => xs.to).ToArray()); } private long[] empty = new long[0]; private Dictionary<long, long[]> toNodes; public long[] To(long from) { long[] res = null; if (toNodes.TryGetValue(from, out res)) return res; else return empty; } public IEnumerable<Pair<long, long>> GetRouteEdges(long from, long to) { return GetRouteEdgesImpl(from, to).Skip(1); } private IEnumerable<Pair<long, long>> GetRouteEdgesImpl(long from, long to) { var routeNodes = GetRouteNodes(from, to); var current = -1L; foreach (var next in routeNodes) { yield return new Pair<long, long>(current, next); current = next; } } public IEnumerable<long> GetRouteNodes(long from, long to) { Stack<long> routeNodes = new Stack<long>(); HashSet<long> checkedNodes = new HashSet<long>(); GetRouteNodes(from, to, routeNodes, checkedNodes); return routeNodes.Reverse(); } private bool GetRouteNodes(long current, long dest, Stack<long> routeNodes, HashSet<long> checkedNodes) { routeNodes.Push(current); checkedNodes.Add(current); if (current == dest) return true; foreach (var next in toNodes[current]) { if (checkedNodes.Contains(next)) continue; if (GetRouteNodes(next, dest, routeNodes, checkedNodes)) return true; } routeNodes.Pop(); return false; } } public class PriorityQueue<TKey, TState> where TKey : IComparable<TKey> { public int Count { get; private set; } private readonly Func<TState, TKey> keySelector; private readonly bool desc; private TState[] states = new TState[65536]; private TKey[] keys = new TKey[65536]; //[MethodImpl(MethodImplOptions.AggressiveInlining)] public PriorityQueue(Func<TState, TKey> keySelector, bool desc = false) { this.keySelector = keySelector; this.desc = desc; } public TState Top { //[MethodImpl(MethodImplOptions.AggressiveInlining)] get { ValidateNonEmpty(); return states[1]; } } //[MethodImpl(MethodImplOptions.AggressiveInlining)] public TState Dequeue() { var top = Top; var item = states[Count]; var key = keys[Count]; Count--; int index = 1; while (true) { if ((index << 1) >= Count) { if (index << 1 > Count) break; if (key.CompareTo(keys[index << 1]) <= 0 ^ desc) break; states[index] = states[index << 1]; keys[index] = keys[index << 1]; index <<= 1; } else { var nextIndex = keys[index << 1].CompareTo(keys[(index << 1) + 1]) <= 0 ^ desc ? (index << 1) : (index << 1) + 1; if (key.CompareTo(keys[nextIndex]) <= 0 ^ desc) break; states[index] = states[nextIndex]; keys[index] = keys[nextIndex]; index = nextIndex; } } states[index] = item; keys[index] = key; return top; } //[MethodImpl(MethodImplOptions.AggressiveInlining)] public void Enqueue(TState state) { var key = keySelector.Invoke(state); Count++; int index = Count; if (states.Length == Count) Extend(states.Length * 2); while ((index >> 1) != 0) { if (keys[index >> 1].CompareTo(key) <= 0 ^ desc) break; states[index] = states[index >> 1]; keys[index] = keys[index >> 1]; index >>= 1; } states[index] = state; keys[index] = key; } //[MethodImpl(MethodImplOptions.AggressiveInlining)] private void Extend(int newSize) { TState[] newStates = new TState[newSize]; TKey[] newKeys = new TKey[newSize]; states.CopyTo(newStates, 0); keys.CopyTo(newKeys, 0); states = newStates; keys = newKeys; } private void ValidateNonEmpty() { if (Count == 0) throw new IndexOutOfRangeException(); } } public class BinaryIndexTree { long length; long[] binaryIndexedTree; public BinaryIndexTree(long length) { this.length = length; binaryIndexedTree = new long[length + 1]; } public void Add(long indexZeroBase, long additional) { // i += i & -i // 1が立っている最下位ビットを足す、の意味 for (long i = indexZeroBase + 1; i <= length; i += i & -i) { binaryIndexedTree[i] += additional; } } public long Sum(long indexZeroBase) { long result = 0; // i += i & -i // 1が立っている最下位ビットを引く、の意味 for (long i = indexZeroBase + 1; i > 0; i -= i & -i) { result += binaryIndexedTree[i]; } return result; } } public static class BinarySearch { public static long GetFirstIndexGreater(long x, IReadOnlyList<long> listOrdered) { var count = listOrdered.Count; if (count == 0) return 0; if (listOrdered[count - 1] <= x) return count; int low = 0; int high = listOrdered.Count - 1; while (low < high) { var mid = (low + high) / 2; if (listOrdered[mid] > x) high = mid; else low = mid + 1; } return low; } public static long GetFirstIndexGreater(int x, IReadOnlyList<int> listOrdered) { var count = listOrdered.Count; if (count == 0) return 0; if (listOrdered[count - 1] <= x) return count; int low = 0; int high = listOrdered.Count - 1; while (low < high) { var mid = (low + high) / 2; if (listOrdered[mid] > x) high = mid; else low = mid + 1; } return low; } public static long GetLastIndexLess(long x, IReadOnlyList<long> listOrdered) { var count = listOrdered.Count; if (count == 0) return -1; if (listOrdered[0] >= x) return -1; int low = 0; int high = listOrdered.Count - 1; while (low < high) { var mid = (low + high + 1) / 2; if (listOrdered[mid] < x) low = mid; else high = mid - 1; } return low; } public static long GetLastIndexLess(int x, IReadOnlyList<int> listOrdered) { var count = listOrdered.Count; if (count == 0) return -1; if (listOrdered[0] >= x) return -1; int low = 0; int high = listOrdered.Count - 1; while (low < high) { var mid = (low + high + 1) / 2; if (listOrdered[mid] < x) low = mid; else high = mid - 1; } return low; } } public static class BellmanFord { public class Vertex { public long Distance { get; set; } public Vertex() { Distance = long.MaxValue; } } public class Edge { public int From { get; private set; } public int To { get; private set; } public long Weight { get; private set; } public Edge(int from, int to, long weight) { From = from; To = to; Weight = weight; } } private static void GetReachable(int origin, ref HashSet<int> reached, ref Dictionary<int, int[]> paths) { if (reached.Contains(origin)) return; reached.Add(origin); if (paths.ContainsKey(origin) == false) return; foreach (var p in paths[origin]) GetReachable(p, ref reached, ref paths); } /// <summary> /// null: 負の無限大 /// long.MaxValue: たどり着けない /// その他: 距離 /// </summary> public static long? RunBellmanFord(int vertexCount, List<Edge> rawEdges, int source, int dest) { var forwards = rawEdges.GroupBy(x => x.From) .ToDictionary(x => x.Key, x => x.Select(xs => xs.To).ToArray()); var reverses = rawEdges.GroupBy(x => x.To).ToDictionary( x => x.Key, x => x.Select(xs => xs.From).ToArray()); var fromSource = new HashSet<int>(); var toDest = new HashSet<int>(); GetReachable(source, ref fromSource, ref forwards); GetReachable(dest, ref toDest, ref reverses); var edges = rawEdges.Where(e => fromSource.Contains(e.From)) .Where(e => fromSource.Contains(e.To)) .Where(e => toDest.Contains(e.From)) .Where(e => toDest.Contains(e.To)) .ToArray(); // initialize distances var vertices = new List<Vertex>(); for (int i = 0; i < vertexCount; i++) vertices.Add(new Vertex()); vertices[source].Distance = 0L; // update distances for (int i = 0; i < vertices.Count; i++) { foreach (var e in edges) { var from = vertices[e.From]; var to = vertices[e.To]; if (from.Distance == long.MaxValue) continue; var newDistance = from.Distance + e.Weight; if (to.Distance > newDistance) { to.Distance = newDistance; } } } // check negative cycle foreach (var e in edges) { var from = vertices[e.From]; var to = vertices[e.To]; if (from.Distance + e.Weight < to.Distance) return null; } return vertices[dest].Distance; } } public static long Gcd(int a, int b) => Gcd((long)a, (long)b); public static long Gcd(long a, long b) { if (a < b) return GcdImpl(b, a); else return GcdImpl(a, b); } private static long GcdImpl(long a, long b) { var remainder = a % b; if (remainder == 0) return b; else return GcdImpl(b, remainder); } public static long Lcm(int a, int b) => Lcm((long)a, (long)b); public static long Lcm(long a, long b) { return a / Gcd(a, b) * b; } public static long Pow(int n, int p) => Pow((long)n, (long)p); public static long Pow(long n, long p) { var res = 1L; for (long i = 0; i < p; i++) res *= n; return res; } public static Dictionary<long, long> Factorize(int n) => Factorize((long)n); public static Dictionary<long, long> Factorize(long n) { var res = new Dictionary<long, long>(); var r = n; for (long i = 2; i * i <= r; i++) { var c = 0L; while (r % i == 0) { c++; r /= i; } if (c > 0) res.Add(i, c); } if (r > 1) res.Add(r, 1); return res; } public static IEnumerable<long> Divisors(int n) => Divisors((long)n); public static IEnumerable<long> Divisors(long n) { var cache = new Stack<long>(); for (long i = 1; i * i <= n; i++) { if (n % i == 0) { yield return i; cache.Push(i); } } var r = cache.Peek(); if (r * r == n) cache.Pop(); while (cache.Count > 0) { var i = cache.Pop(); yield return n / i; } } public static IEnumerable<int> Loop(int n) { for (int i = 0; i < n; i++) yield return i; } public static IEnumerable<long> Loop(long n) { for (long i = 0L; i < n; i++) yield return i; } } struct Mint { public static long Divider { set { divider = value; } } private static long divider = 1000000007L; public static void Set998244353() { divider = 998244353L; } public static void Set1000000009() { divider = 1000000009L; } public long Value { get; } public override string ToString() => this.Value.ToString(); public Mint(long value) { this.Value = value; } // public static implicit operator Mint(long a) => new Mint(a % divider); // public static implicit operator Mint(int a) => new Mint(a % divider); // public static explicit operator long(Mint a) => a.Value; // public static explicit operator int(Mint a) => (int)a.Value; public static Mint operator +(Mint a, Mint b) => new Mint((a.Value + b.Value) % divider); public static Mint operator +(Mint a, long b) => a + new Mint(b); public static Mint operator +(Mint a, int b) => a + new Mint(b); public static Mint operator -(Mint a, Mint b) { var t = (a.Value - b.Value) % divider; if (t < 0L) t += divider; return new Mint(t); } public static Mint operator -(Mint a, long b) => a - new Mint(b); public static Mint operator -(Mint a, int b) => a - new Mint(b); public static Mint operator *(Mint a, Mint b) => new Mint((a.Value * b.Value) % divider); public static Mint operator *(Mint a, long b) => a * new Mint(b); public static Mint operator *(Mint a, int b) => a * new Mint(b); public static Mint operator /(Mint a, Mint b) => new Mint((a.Value * InvImpl(b.Value)) % divider); public static Mint operator /(Mint a, long b) => a / new Mint(b); public static Mint operator /(Mint a, int b) => a / new Mint(b); public Mint Pow(long p) => new Mint(PowImpl(Value, p)); public static Mint Pow(long a, long p) => new Mint(PowImpl(a, p)); private static long PowImpl(long a, long p) { if (p == 0L) return 1L; if (p == 1L) return a; var halfP = p / 2L; var halfPowered = PowImpl(a, halfP); var powered = halfPowered * halfPowered % divider; return p % 2L == 0L ? powered : powered * a % divider; } public static Mint Inv(long a) => new Mint(InvImpl(a)); private static readonly Dictionary<long, long> invCache = new Dictionary<long, long>(); private static long InvImpl(long a) { long cache; if (invCache.TryGetValue(a, out cache)) return cache; var result = PowImpl(a, divider - 2L); invCache.Add(a, result); return result; } public static Mint Fac(long a) => new Mint(FacImpl(a)); private static long[] facCache = new long[262144]; private static long cachedFac = 0L; private static long FacImpl(long a) { if (a >= divider) return 0L; facCache[0] = 1L; if (facCache.LongLength <= a) { long newSize = facCache.LongLength; while (newSize <= a) { newSize *= 2; } ExtendFacCache(newSize); } if (cachedFac < a) { var val = facCache[cachedFac]; var start = cachedFac + 1L; for (long i = start; i <= a; i++) { val = (val * i) % divider; facCache[i] = val; } cachedFac = a; } return facCache[a]; } private static void ExtendFacCache(long newSize) { long[] newFacCache = new long[newSize]; facCache.CopyTo(newFacCache, 0); facCache = newFacCache; } public static Mint Perm(long n, long r) => new Mint(PermImpl(n, r)); private static long PermImpl(long n, long r) { if (n < r) return 0L; if (r <= 0L) return 1L; var nn = FacImpl(n); var nr = FacImpl(n - r); return (nn * InvImpl(nr)) % divider; } public static Mint Comb(long n, long r) => new Mint(CombImpl(n, r)); private static long CombImpl(long n, long r) { if (n < r) return 0L; if (n == r) return 1L; if (n - r < r) return CombImpl(n, n - r); var nn = FacImpl(n); var nr = FacImpl(n - r); var rr = FacImpl(r); var nrrr = (nr * rr) % divider; return (nn * InvImpl(nrrr)) % divider; } } }
[["-", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 12, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 12, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 205, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 0, 28, 0, 218, 8, 16, 31, 214, 205, 22], ["+", 0, 28, 0, 218, 8, 16, 31, 214, 0, 131], ["+", 0, 28, 0, 218, 8, 16, 31, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 17, 60], ["+", 0, 28, 0, 218, 8, 16, 12, 214, 205, 22], ["+", 0, 28, 0, 218, 8, 16, 12, 214, 0, 131], ["+", 0, 28, 0, 218, 8, 16, 12, 214, 141, 22], ["+", 12, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22]]
8
8,447
15
using System; using System.Linq; using System.Collections.Generic; namespace Contest { class Program { static void Main(string[] args) { ABC167.F(); } class ABC167 { public static void A() { var S = Read.Str(); var T = Read.Str(); Console.WriteLine(S == T.Substring(0, S.Length) ? "Yes" : "No"); } public static void B() { var A = Read.Long(); var B = Read.Long(); var C = Read.Long(); var K = Read.Long(); if (K <= A) { Console.WriteLine(K); return; } if (K <= A + B) { Console.WriteLine(A); return; } Console.WriteLine(A - (K - A - B)); } public static void C() { var N = Read.Int(); var M = Read.Int(); var X = Read.Int(); var CA = Enumerable.Range(0, N).Select(i => Read.IntN()).ToArray(); int min = (int)1e8; for (int i = 0; i < (1 << N); ++i) { var sum = new int[M]; var cost = 0; for (int j = 0; j < N; ++j) { if ((i & (1 << j)) > 0) { cost += CA[j][0]; for (int k = 0; k < M; ++k) { sum[k] += CA[j][k + 1]; } } } if (sum.Count(x => x >= X) == M) { min = Math.Min(min, cost); } } Console.WriteLine(min == (int)1e8 ? -1 : min); } public static void D() { var N = Read.Int(); var K = Read.Long(); var A = Read.IntN(); List<int> list = new List<int>(); var hash = new HashSet<int>(); int current = 1; list.Add(current); hash.Add(current); while (true) { var to = A[current - 1]; list.Add(to); if (hash.Contains(to)) { break; } hash.Add(to); current = to; } var last = list.Last(); var idx = list.IndexOf(last); if (K < list.Count) { Console.WriteLine(list[(int)K]); return; } var K2 = (K - idx) % (list.Count - idx - 1); Console.WriteLine(list[idx + (int)K2]); } public static void E() { var N = Read.Int(); var M = Read.Int(); var K = Read.Int(); var comb = Util.Combin(N + M + 10, Util.P); MOD ans = 0; for (int i = 0; i <= K; ++i) { var a = ((MOD)M) * ((MOD)(M - 1)).Power(N - i - 1); var b = comb(N - 1, i); ans += a * b; } Console.WriteLine(ans.V); } public static void F() { var N = Read.Int(); var S = Enumerable.Range(0, N).Select(i => Read.Str()).ToArray(); var X = new List<Tuple<int, int, int>>(); foreach (var s in S) { var c1 = s.Count(x => x == '('); var c2 = s.Count(x => x == ')'); int min = 0; int cur = 0; for (int i = 0; i < s.Length; ++i) { if (s[i] == '(') { cur--; } else { cur++; } min = Math.Max(min, cur); } X.Add(new Tuple<int, int, int>(c1, c2, min)); } var sum1 = X.Select(x => x.Item1).Sum(); var sum2 = X.Select(x => x.Item2).Sum(); if (sum1 != sum2) { Console.WriteLine("No"); return; } var X0 = new List<Tuple<int, int, int>>(); var X1 = new List<Tuple<int, int, int>>(); var X2 = new List<Tuple<int, int, int>>(); foreach (var x in X) { if (x.Item1 > x.Item2) { X0.Add(x); } else if (x.Item1 == x.Item2) { X1.Add(x); } else { X2.Add(x); } } X0 = X0.OrderBy(x => x.Item3).ToList(); int current = 0; for (int i = 0; i < X0.Count; ++i) { var x = X0[i]; if (current < x.Item3) { Console.WriteLine("No"); return; } current += x.Item1 - x.Item2; } for (int i = 0; i < X1.Count; ++i) { var x = X1[i]; if (current < x.Item3) { Console.WriteLine("No"); return; } } X2 = X2.OrderBy(x => -((long)x.Item3) * 2000000 - (x.Item1 - x.Item2)) .ToList(); // X2 = X2.OrderBy(x => -((long)x.Item3) * 2000000).ToList(); for (int i = 0; i < X2.Count; ++i) { var x = X2[i]; if (current < x.Item3) { Console.WriteLine("No"); return; } current += x.Item1 - x.Item2; } Console.WriteLine("Yes"); } } class Util { public static readonly long P = 998244353; public static long[] ASum(long[] array) { var res = new long[array.Length + 1]; for (int i = 0; i < array.Length; ++i) { res[i + 1] = res[i] + array[i]; } return res; } public static Dictionary<T, long> Frequency<T>(T[] array) { var dict = new Dictionary<T, long>(); foreach (var a in array) { if (!dict.ContainsKey(a)) { dict.Add(a, 0); } dict[a]++; } return dict; } public static long Power(long a, long n, long p) { long res = 1; long mult = a; for (int i = 0; i < 63; ++i) { if ((n & ((long)1 << i)) > 0) { res = (res * mult) % p; } mult = (mult * mult) % p; } return res; } public static long Inverse(long a, long p) { long b = p, c = 1, d = 0, e = 0, f = 0; while (b != 0) { e = a / b; f = b; b = a - e * b; a = f; f = d; d = c - e * d; c = f; } c %= p; return c + (c < 0 ? p : 0); } public static long[] Facts(int n, long p) { var facts = new long[n + 1]; facts[0] = 1; for (int i = 1; i <= n; ++i) { facts[i] = (i * facts[i - 1]) % p; } return facts; } public static Func<int, int, long> Combin(int n, long P) { var fact = Facts(n, P); var inv = fact.Select(x => Inverse(x, P)).ToArray(); return (N, M) => { if (N < 0 || N < M || M < 0) { return 0; } return (((fact[N] * inv[M]) % P) * inv[N - M]) % P; }; } } struct MOD { public static long P = 998244353; public readonly long V; public MOD(long a) { this.V = a % P; } public static implicit operator MOD(long a) { return new MOD(a); } public static MOD operator +(MOD a, MOD b) { return new MOD((a.V + b.V) % P); } public static MOD operator -(MOD a, MOD b) { return new MOD((a.V - b.V + P) % P); } public static MOD operator *(MOD a, MOD b) { return new MOD((a.V * b.V) % P); } public static MOD operator /(MOD a, MOD b) { return new MOD((a.V * b.Inverse().V) % P); } public MOD Inverse() { long a = V, p = P; long b = p, c = 1, d = 0, e = 0, f = 0; while (b != 0) { e = a / b; f = b; b = a - e * b; a = f; f = d; d = c - e * d; c = f; } c %= p; return c + (c < 0 ? p : 0); } public MOD Power(long n) { long a = V, p = P; long res = 1; long mult = a; for (int i = 0; i < 63; ++i) { if ((n & ((long)1 << i)) > 0) { res = (res * mult) % p; } mult = (mult * mult) % p; } return res; } public override string ToString() { return V.ToString(); } } static class Read { static Queue<string> queue = new Queue<string>(); static void Enqueue() { var ss = Console.ReadLine().Split(' '); foreach (var s in ss) { queue.Enqueue(s); } } public static int Int() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt32(queue.Dequeue()); } public static long Long() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt64(queue.Dequeue()); } public static string Str() { if (queue.Count == 0) { Enqueue(); } return queue.Dequeue(); } public static int[] IntN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt32(s)) .ToArray(); } public static long[] LongN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt64(s)) .ToArray(); } public static ulong[] ULongN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToUInt64(s)) .ToArray(); } public static string[] StrN() { return Console.ReadLine().Split(' '); } public static Tuple<int, int>[] TupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = Read.IntN(); list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<long, long>[] TupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<string, string>[] TupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = Read.StrN(); list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<double, double>[] TupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); } public static long[,] LongMatrix(int r, int c) { var mat = new long[r, c]; for (int i = 0; i < r; ++i) { var x = Read.LongN(); for (int j = 0; j < c; ++j) { mat[i, j] = x[j]; } } return mat; } public static Dictionary<int, HashSet<int>> AdjacencyList(int N, int M, bool isDirectional = false) { Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new HashSet<int>()); } for (int i = 0; i < M; ++i) { var ab = Read.IntN(); if (!dict[ab[0]].Contains(ab[1])) { dict[ab[0]].Add(ab[1]); } if (!isDirectional && !dict[ab[1]].Contains(ab[0])) { dict[ab[1]].Add(ab[0]); } } return dict; } public static Dictionary<int, Dictionary<int, long>> AdjacencyListWithWeight(int N, int M) { Dictionary<int, Dictionary<int, long>> dict = new Dictionary<int, Dictionary<int, long>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new Dictionary<int, long>()); } for (int i = 0; i < M; ++i) { var ab = Read.IntN(); dict[ab[0]].Add(ab[1], ab[2]); dict[ab[1]].Add(ab[0], ab[2]); } return dict; } } } }
using System; using System.Linq; using System.Collections.Generic; namespace Contest { class Program { static void Main(string[] args) { ABC167.F(); } class ABC167 { public static void A() { var S = Read.Str(); var T = Read.Str(); Console.WriteLine(S == T.Substring(0, S.Length) ? "Yes" : "No"); } public static void B() { var A = Read.Long(); var B = Read.Long(); var C = Read.Long(); var K = Read.Long(); if (K <= A) { Console.WriteLine(K); return; } if (K <= A + B) { Console.WriteLine(A); return; } Console.WriteLine(A - (K - A - B)); } public static void C() { var N = Read.Int(); var M = Read.Int(); var X = Read.Int(); var CA = Enumerable.Range(0, N).Select(i => Read.IntN()).ToArray(); int min = (int)1e8; for (int i = 0; i < (1 << N); ++i) { var sum = new int[M]; var cost = 0; for (int j = 0; j < N; ++j) { if ((i & (1 << j)) > 0) { cost += CA[j][0]; for (int k = 0; k < M; ++k) { sum[k] += CA[j][k + 1]; } } } if (sum.Count(x => x >= X) == M) { min = Math.Min(min, cost); } } Console.WriteLine(min == (int)1e8 ? -1 : min); } public static void D() { var N = Read.Int(); var K = Read.Long(); var A = Read.IntN(); List<int> list = new List<int>(); var hash = new HashSet<int>(); int current = 1; list.Add(current); hash.Add(current); while (true) { var to = A[current - 1]; list.Add(to); if (hash.Contains(to)) { break; } hash.Add(to); current = to; } var last = list.Last(); var idx = list.IndexOf(last); if (K < list.Count) { Console.WriteLine(list[(int)K]); return; } var K2 = (K - idx) % (list.Count - idx - 1); Console.WriteLine(list[idx + (int)K2]); } public static void E() { var N = Read.Int(); var M = Read.Int(); var K = Read.Int(); var comb = Util.Combin(N + M + 10, Util.P); MOD ans = 0; for (int i = 0; i <= K; ++i) { var a = ((MOD)M) * ((MOD)(M - 1)).Power(N - i - 1); var b = comb(N - 1, i); ans += a * b; } Console.WriteLine(ans.V); } public static void F() { var N = Read.Int(); var S = Enumerable.Range(0, N).Select(i => Read.Str()).ToArray(); var X = new List<Tuple<int, int, int>>(); foreach (var s in S) { var c1 = s.Count(x => x == '('); var c2 = s.Count(x => x == ')'); int min = 0; int cur = 0; for (int i = 0; i < s.Length; ++i) { if (s[i] == '(') { cur--; } else { cur++; } min = Math.Max(min, cur); } X.Add(new Tuple<int, int, int>(c1, c2, min)); } var sum1 = X.Select(x => x.Item1).Sum(); var sum2 = X.Select(x => x.Item2).Sum(); if (sum1 != sum2) { Console.WriteLine("No"); return; } var X0 = new List<Tuple<int, int, int>>(); var X1 = new List<Tuple<int, int, int>>(); var X2 = new List<Tuple<int, int, int>>(); foreach (var x in X) { if (x.Item1 > x.Item2) { X0.Add(x); } else if (x.Item1 == x.Item2) { X1.Add(x); } else { X2.Add(x); } } X0 = X0.OrderBy(x => x.Item3).ToList(); int current = 0; for (int i = 0; i < X0.Count; ++i) { var x = X0[i]; if (current < x.Item3) { Console.WriteLine("No"); return; } current += x.Item1 - x.Item2; } for (int i = 0; i < X1.Count; ++i) { var x = X1[i]; if (current < x.Item3) { Console.WriteLine("No"); return; } } X2 = X2.OrderBy(x => -x.Item3 - (x.Item1 - x.Item2)).ToList(); // X2 = X2.OrderBy(x => -((long)x.Item3) * 2000000 - (x.Item1 - // x.Item2)).ToList(); X2 = X2.OrderBy(x => -((long)x.Item3) * // 2000000).ToList(); for (int i = 0; i < X2.Count; ++i) { var x = X2[i]; if (current < x.Item3) { Console.WriteLine("No"); return; } current += x.Item1 - x.Item2; } Console.WriteLine("Yes"); } } class Util { public static readonly long P = 998244353; public static long[] ASum(long[] array) { var res = new long[array.Length + 1]; for (int i = 0; i < array.Length; ++i) { res[i + 1] = res[i] + array[i]; } return res; } public static Dictionary<T, long> Frequency<T>(T[] array) { var dict = new Dictionary<T, long>(); foreach (var a in array) { if (!dict.ContainsKey(a)) { dict.Add(a, 0); } dict[a]++; } return dict; } public static long Power(long a, long n, long p) { long res = 1; long mult = a; for (int i = 0; i < 63; ++i) { if ((n & ((long)1 << i)) > 0) { res = (res * mult) % p; } mult = (mult * mult) % p; } return res; } public static long Inverse(long a, long p) { long b = p, c = 1, d = 0, e = 0, f = 0; while (b != 0) { e = a / b; f = b; b = a - e * b; a = f; f = d; d = c - e * d; c = f; } c %= p; return c + (c < 0 ? p : 0); } public static long[] Facts(int n, long p) { var facts = new long[n + 1]; facts[0] = 1; for (int i = 1; i <= n; ++i) { facts[i] = (i * facts[i - 1]) % p; } return facts; } public static Func<int, int, long> Combin(int n, long P) { var fact = Facts(n, P); var inv = fact.Select(x => Inverse(x, P)).ToArray(); return (N, M) => { if (N < 0 || N < M || M < 0) { return 0; } return (((fact[N] * inv[M]) % P) * inv[N - M]) % P; }; } } struct MOD { public static long P = 998244353; public readonly long V; public MOD(long a) { this.V = a % P; } public static implicit operator MOD(long a) { return new MOD(a); } public static MOD operator +(MOD a, MOD b) { return new MOD((a.V + b.V) % P); } public static MOD operator -(MOD a, MOD b) { return new MOD((a.V - b.V + P) % P); } public static MOD operator *(MOD a, MOD b) { return new MOD((a.V * b.V) % P); } public static MOD operator /(MOD a, MOD b) { return new MOD((a.V * b.Inverse().V) % P); } public MOD Inverse() { long a = V, p = P; long b = p, c = 1, d = 0, e = 0, f = 0; while (b != 0) { e = a / b; f = b; b = a - e * b; a = f; f = d; d = c - e * d; c = f; } c %= p; return c + (c < 0 ? p : 0); } public MOD Power(long n) { long a = V, p = P; long res = 1; long mult = a; for (int i = 0; i < 63; ++i) { if ((n & ((long)1 << i)) > 0) { res = (res * mult) % p; } mult = (mult * mult) % p; } return res; } public override string ToString() { return V.ToString(); } } static class Read { static Queue<string> queue = new Queue<string>(); static void Enqueue() { var ss = Console.ReadLine().Split(' '); foreach (var s in ss) { queue.Enqueue(s); } } public static int Int() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt32(queue.Dequeue()); } public static long Long() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt64(queue.Dequeue()); } public static string Str() { if (queue.Count == 0) { Enqueue(); } return queue.Dequeue(); } public static int[] IntN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt32(s)) .ToArray(); } public static long[] LongN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt64(s)) .ToArray(); } public static ulong[] ULongN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToUInt64(s)) .ToArray(); } public static string[] StrN() { return Console.ReadLine().Split(' '); } public static Tuple<int, int>[] TupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = Read.IntN(); list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<long, long>[] TupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<string, string>[] TupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = Read.StrN(); list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<double, double>[] TupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); } public static long[,] LongMatrix(int r, int c) { var mat = new long[r, c]; for (int i = 0; i < r; ++i) { var x = Read.LongN(); for (int j = 0; j < c; ++j) { mat[i, j] = x[j]; } } return mat; } public static Dictionary<int, HashSet<int>> AdjacencyList(int N, int M, bool isDirectional = false) { Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new HashSet<int>()); } for (int i = 0; i < M; ++i) { var ab = Read.IntN(); if (!dict[ab[0]].Contains(ab[1])) { dict[ab[0]].Add(ab[1]); } if (!isDirectional && !dict[ab[1]].Contains(ab[0])) { dict[ab[1]].Add(ab[0]); } } return dict; } public static Dictionary<int, Dictionary<int, long>> AdjacencyListWithWeight(int N, int M) { Dictionary<int, Dictionary<int, long>> dict = new Dictionary<int, Dictionary<int, long>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new Dictionary<int, long>()); } for (int i = 0; i < M; ++i) { var ab = Read.IntN(); dict[ab[0]].Add(ab[1], ab[2]); dict[ab[1]].Add(ab[0], ab[2]); } return dict; } } } }
[["-", 8, 16, 31, 16, 31, 241, 0, 23, 0, 24], ["-", 31, 16, 31, 241, 0, 23, 0, 74, 0, 24], ["-", 31, 16, 31, 241, 0, 23, 0, 74, 39, 199], ["-", 31, 16, 31, 241, 0, 23, 0, 74, 0, 25], ["-", 8, 16, 31, 16, 31, 241, 0, 23, 0, 25], ["-", 0, 28, 0, 218, 8, 16, 31, 16, 17, 48], ["-", 0, 28, 0, 218, 8, 16, 31, 16, 12, 203]]
8
3,329
7
using System; using System.Collections.Generic; using System.Linq; using CompLib.Collections; using CompLib.Util; public class Program { int N; string[] S; public void Solve() { var sc = new Scanner(); N = sc.NextInt(); S = new string[N]; for (int i = 0; i < N; i++) { S[i] = sc.Next(); } int[] cnt = new int[N]; int[] min = new int[N]; for (int i = 0; i < N; i++) { int c = 0; int m = 0; foreach (var ch in S[i]) { if (ch == '(') c++; else c--; m = Math.Min(m, c); } cnt[i] = c; min[i] = m; } // minが0のやつ // var l1 = new List<int>(); // cntが0以上のやつ var l2 = new List<int>(); // cntが負、 var l3 = new List<int>(); for (int i = 0; i < N; i++) { // if (min[i] == 0) l1.Add(i); if (cnt[i] >= 0) l2.Add(i); else l2.Add(i); } int counter = 0; // foreach (var i in l1) // { // counter += cnt[i]; // } l2.Sort((l, r) => min[r].CompareTo(min[l])); foreach (var i in l2) { if (counter + min[i] < 0) { Console.WriteLine("No"); return; } counter += cnt[i]; } l3.Sort((l, r) => (cnt[r] - min[r]).CompareTo(cnt[l] - min[l])); foreach (var i in l3) { if (counter + min[i] < 0) { Console.WriteLine("No"); return; } counter += cnt[i]; } Console.WriteLine(counter == 0 ? "Yes" : "No"); } public static void Main(string[] args) => new Program().Solve(); } // https://bitbucket.org/camypaper/complib namespace CompLib.Collections { using System; using System.Collections.Generic; #region PriorityQueue /// <summary> /// 指定した型のインスタンスを最も価値が低い順に取り出すことが可能な可変サイズのコレクションを表します. /// </summary> /// <typeparam name="T">優先度付きキュー内の要素の型を指定します.</typeparam> /// <remarks>内部的にはバイナリヒープによって実装されています.</remarks> public class PriorityQueue<T> { readonly List<T> heap = new List<T>(); readonly Comparison<T> cmp; /// <summary> /// デフォルトの比較子を使用してインスタンスを初期化します. /// </summary> /// <remarks>この操作は O(1) で実行されます.</remarks> public PriorityQueue() { cmp = Comparer<T>.Default.Compare; } /// <summary> /// デリゲートで表されるような比較関数を使用してインスタンスを初期化します. /// </summary> /// <param name="comparison"></param> /// <remarks>この操作は O(1) で実行されます.</remarks> public PriorityQueue(Comparison<T> comparison) { cmp = comparison; } /// <summary> /// 指定された比較子を使用してインスタンスを初期化します. /// </summary> /// <param name="comparer"></param> /// <remarks>この操作は O(1) で実行されます.</remarks> public PriorityQueue(IComparer<T> comparer) { cmp = comparer.Compare; } /// <summary> /// 優先度付きキューに要素を追加します. /// </summary> /// <param name="item">優先度付きキューに追加される要素</param> /// <remarks>最悪計算量 O(log N) で実行されます.</remarks> public void Enqueue(T item) { var pos = heap.Count; heap.Add(item); while (pos > 0) { var par = (pos - 1) / 2; if (cmp(heap[par], item) <= 0) break; heap[pos] = heap[par]; pos = par; } heap[pos] = item; } /// <summary> /// 優先度付きキューから最も価値が低い要素を削除し,返します. /// </summary> /// <returns>優先度付きキューから削除された要素.</returns> /// <remarks>最悪計算量 O(log N) で実行されます.</remarks> public T Dequeue() { var ret = heap[0]; var pos = 0; var x = heap[heap.Count - 1]; while (pos * 2 + 1 < heap.Count - 1) { var lch = pos * 2 + 1; var rch = pos * 2 + 2; if (rch < heap.Count - 1 && cmp(heap[rch], heap[lch]) < 0) lch = rch; if (cmp(heap[lch], x) >= 0) break; heap[pos] = heap[lch]; pos = lch; } heap[pos] = x; heap.RemoveAt(heap.Count - 1); return ret; } /// <summary> /// 優先度付きキューに含まれる最も価値が低い要素を削除せずに返します. /// </summary> /// <returns>優先度付きキューに含まれる最も価値が低い要素.</returns> /// <remarks>この操作は O(1) で実行されます.</remarks> public T Peek() { return heap[0]; } /// <summary> /// 優先度付きキュー内の要素の数を取得します. /// </summary> /// <returns>優先度付キュー内にある要素の数</returns> /// <remarks>最悪計算量 O(1) で実行されます.</remarks> public int Count { get { return heap.Count; } } /// <summary> /// 優先度付きキュー内に要素が存在するかどうかを O(1) で判定します. /// </summary> /// <returns>優先度付キュー内にある要素が存在するならば /// true,そうでなければ false.</returns> <remarks>この操作は O(1) /// で実行されます.</remarks> public bool Any() { return heap.Count > 0; } /// <summary> /// 優先度付きキューに含まれる要素を昇順に並べて返します. /// </summary> /// <remarks>この操作は計算量 O(N log N)で実行されます.</remarks> public T[] Items { get { var ret = heap.ToArray(); Array.Sort(ret, cmp); return ret; } } } #endregion } 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 System.Linq; using CompLib.Collections; using CompLib.Util; public class Program { int N; string[] S; public void Solve() { var sc = new Scanner(); N = sc.NextInt(); S = new string[N]; for (int i = 0; i < N; i++) { S[i] = sc.Next(); } int[] cnt = new int[N]; int[] min = new int[N]; for (int i = 0; i < N; i++) { int c = 0; int m = 0; foreach (var ch in S[i]) { if (ch == '(') c++; else c--; m = Math.Min(m, c); } cnt[i] = c; min[i] = m; } // minが0のやつ // var l1 = new List<int>(); // cntが0以上のやつ var l2 = new List<int>(); // cntが負、 var l3 = new List<int>(); // min == cnt var l4 = new List<int>(); for (int i = 0; i < N; i++) { // if (min[i] == 0) l1.Add(i); if (cnt[i] >= 0) l2.Add(i); else l3.Add(i); } int counter = 0; // foreach (var i in l1) // { // counter += cnt[i]; // } l2.Sort((l, r) => min[r].CompareTo(min[l])); foreach (var i in l2) { if (counter + min[i] < 0) { Console.WriteLine("No"); return; } counter += cnt[i]; } l3.Sort((l, r) => (cnt[r] - min[r]).CompareTo(cnt[l] - min[l])); foreach (var i in l3) { if (counter + min[i] < 0) { Console.WriteLine("No"); return; } counter += cnt[i]; } Console.WriteLine(counter == 0 ? "Yes" : "No"); } public static void Main(string[] args) => new Program().Solve(); } // https://bitbucket.org/camypaper/complib namespace CompLib.Collections { using System; using System.Collections.Generic; #region PriorityQueue /// <summary> /// 指定した型のインスタンスを最も価値が低い順に取り出すことが可能な可変サイズのコレクションを表します. /// </summary> /// <typeparam name="T">優先度付きキュー内の要素の型を指定します.</typeparam> /// <remarks>内部的にはバイナリヒープによって実装されています.</remarks> public class PriorityQueue<T> { readonly List<T> heap = new List<T>(); readonly Comparison<T> cmp; /// <summary> /// デフォルトの比較子を使用してインスタンスを初期化します. /// </summary> /// <remarks>この操作は O(1) で実行されます.</remarks> public PriorityQueue() { cmp = Comparer<T>.Default.Compare; } /// <summary> /// デリゲートで表されるような比較関数を使用してインスタンスを初期化します. /// </summary> /// <param name="comparison"></param> /// <remarks>この操作は O(1) で実行されます.</remarks> public PriorityQueue(Comparison<T> comparison) { cmp = comparison; } /// <summary> /// 指定された比較子を使用してインスタンスを初期化します. /// </summary> /// <param name="comparer"></param> /// <remarks>この操作は O(1) で実行されます.</remarks> public PriorityQueue(IComparer<T> comparer) { cmp = comparer.Compare; } /// <summary> /// 優先度付きキューに要素を追加します. /// </summary> /// <param name="item">優先度付きキューに追加される要素</param> /// <remarks>最悪計算量 O(log N) で実行されます.</remarks> public void Enqueue(T item) { var pos = heap.Count; heap.Add(item); while (pos > 0) { var par = (pos - 1) / 2; if (cmp(heap[par], item) <= 0) break; heap[pos] = heap[par]; pos = par; } heap[pos] = item; } /// <summary> /// 優先度付きキューから最も価値が低い要素を削除し,返します. /// </summary> /// <returns>優先度付きキューから削除された要素.</returns> /// <remarks>最悪計算量 O(log N) で実行されます.</remarks> public T Dequeue() { var ret = heap[0]; var pos = 0; var x = heap[heap.Count - 1]; while (pos * 2 + 1 < heap.Count - 1) { var lch = pos * 2 + 1; var rch = pos * 2 + 2; if (rch < heap.Count - 1 && cmp(heap[rch], heap[lch]) < 0) lch = rch; if (cmp(heap[lch], x) >= 0) break; heap[pos] = heap[lch]; pos = lch; } heap[pos] = x; heap.RemoveAt(heap.Count - 1); return ret; } /// <summary> /// 優先度付きキューに含まれる最も価値が低い要素を削除せずに返します. /// </summary> /// <returns>優先度付きキューに含まれる最も価値が低い要素.</returns> /// <remarks>この操作は O(1) で実行されます.</remarks> public T Peek() { return heap[0]; } /// <summary> /// 優先度付きキュー内の要素の数を取得します. /// </summary> /// <returns>優先度付キュー内にある要素の数</returns> /// <remarks>最悪計算量 O(1) で実行されます.</remarks> public int Count { get { return heap.Count; } } /// <summary> /// 優先度付きキュー内に要素が存在するかどうかを O(1) で判定します. /// </summary> /// <returns>優先度付キュー内にある要素が存在するならば /// true,そうでなければ false.</returns> <remarks>この操作は O(1) /// で実行されます.</remarks> public bool Any() { return heap.Count > 0; } /// <summary> /// 優先度付きキューに含まれる要素を昇順に並べて返します. /// </summary> /// <remarks>この操作は計算量 O(N log N)で実行されます.</remarks> public T[] Items { get { var ret = heap.ToArray(); Array.Sort(ret, cmp); return ret; } } } #endregion } 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, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 230, 0, 228], ["+", 0, 200, 0, 212, 0, 230, 39, 236, 141, 22], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 18], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 47], ["+", 0, 200, 0, 212, 0, 230, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 230, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 57, 75, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 75, 1, 0, 213, 63, 214, 205, 22]]
8
1,203
13
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC116A2 { class Program { static void Main(string[] args) { string a; a = Console.ReadLine(); if (a == "ABC") a = "ARC"; if (a == "ARC") a = "ABC"; Console.WriteLine(a); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC116A2 { class Program { static void Main(string[] args) { string a; a = Console.ReadLine(); if (a == "ABC") a = "ARC"; else a = "ABC"; Console.WriteLine(a); Console.ReadKey(); } } }
[["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 8, 196, 0, 57, 15, 16, 12, 5, 0, 62], ["-", 8, 196, 0, 57, 15, 16, 12, 5, 0, 222], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24]]
8
92
15
using System; namespace ChokudaiScanner { class MainClass { static void Main() { Scanner cin = new Scanner(); string N = cin.Next(); if (N == "ABC") { Console.WriteLine("ARC"); } else { Console.WriteLine(N); } } } 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 string[] ArrayNext(int N) { string[] Array = new string[N]; for (int i = 0; i < N; i++) { Array[i] = Next(); } return Array; } 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; } } }
using System; namespace ChokudaiScanner { class MainClass { static void Main() { Scanner cin = new Scanner(); string N = cin.Next(); if (N == "ABC") { Console.WriteLine("ARC"); } else if (N == "ARC") { Console.WriteLine("ABC"); } } } 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 string[] ArrayNext(int N) { string[] Array = new string[N]; for (int i = 0; i < N; i++) { Array[i] = Next(); } return Array; } 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; } } }
[["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 31, 22], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 60], ["+", 0, 57, 75, 57, 15, 16, 12, 5, 0, 62], ["+", 0, 57, 75, 57, 15, 16, 12, 5, 0, 222], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 25], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
464
12
using System; using System.Collections.Generic; namespace First { class Program { static void Main(string[] args) { List<string> a = new List<string>(); List<int> a2 = new List<int>(); string data = Console.ReadLine(); String[] data2 = data.Split(' '); int n = Int32.Parse(data2[0]); int k = Int32.Parse(data2[1]); bool[] nSwitch = new bool[n]; for (int i = 0; i < k; i++) { int d = Int32.Parse(Console.ReadLine()); data = Console.ReadLine(); a.AddRange(data.Split(' ')); a2 = a.ConvertAll(Int32.Parse); for (int h = 0; h < a2.Count; h++) { nSwitch[a2.IndexOf(h)] = true; } } int cnt = 0; for (int i = 0; i < nSwitch.Length; i++) { if (!nSwitch[i]) cnt++; } Console.WriteLine(cnt); } } }
using System; using System.Collections.Generic; namespace First { class Program { static void Main(string[] args) { List<string> a = new List<string>(); List<int> a2 = new List<int>(); string data = Console.ReadLine(); String[] data2 = data.Split(' '); int n = Int32.Parse(data2[0]); int k = Int32.Parse(data2[1]); bool[] nSwitch = new bool[n]; for (int i = 0; i < k; i++) { int d = Int32.Parse(Console.ReadLine()); data = Console.ReadLine(); a.AddRange(data.Split(' ')); a2 = a.ConvertAll(Int32.Parse); foreach (int num in a2) { nSwitch[num - 1] = true; } a2.Clear(); } int cnt = 0; for (int i = 0; i < nSwitch.Length; i++) { if (!nSwitch[i]) cnt++; } Console.WriteLine(cnt); } } }
[["-", 8, 196, 0, 7, 8, 196, 0, 7, 0, 88], ["+", 8, 196, 0, 7, 8, 196, 0, 210, 0, 266], ["-", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 7, 0, 35], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 8, 196, 0, 7, 8, 196, 0, 210, 31, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 210, 0, 267], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 0, 131], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 141, 22], ["-", 0, 7, 8, 196, 0, 7, 26, 223, 0, 22], ["-", 0, 7, 8, 196, 0, 7, 26, 223, 0, 29], ["-", 206, 207, 0, 28, 0, 213, 63, 214, 205, 22], ["-", 206, 207, 0, 28, 0, 213, 63, 214, 0, 131], ["-", 206, 207, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 206, 207, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 206, 207, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
8
251
30
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) { string[] input = Console.ReadLine().Split(); string[] count = new string[0]; int k = int.Parse(input[1].ToString()); int sunuke = 0; for (int i = 0; i < k; i++) { int d = int.Parse(Console.ReadLine()); string[] a = Console.ReadLine().Split(); for (int j = 0; j < d; j++) { Array.Resize(ref count, count.Length + 1); count[count.Length - 1] = a[j]; } } for (int i = 1; i <= k; i++) { string g = i.ToString(); if (count.Contains(g)) { sunuke++; } } Console.WriteLine(); Console.WriteLine(k - sunuke); Console.Read(); } } }
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) { string[] input = Console.ReadLine().Split(); string[] count = new string[0]; int k = int.Parse(input[1].ToString()); int n = int.Parse(input[0].ToString()); int sunuke = 0; for (int i = 0; i < k; i++) { int d = int.Parse(Console.ReadLine()); string[] a = Console.ReadLine().Split(); for (int j = 0; j < d; j++) { Array.Resize(ref count, count.Length + 1); count[count.Length - 1] = a[j]; } } for (int i = 1; i <= n; i++) { string g = i.ToString(); if (count.Contains(g)) { sunuke++; } } Console.WriteLine(); Console.WriteLine(n - sunuke); Console.Read(); } } }
[["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 213, 63, 214, 205, 204, 205, 22], ["+", 0, 213, 63, 214, 205, 204, 206, 207, 0, 70], ["+", 63, 214, 205, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 213, 63, 214, 205, 204, 206, 207, 0, 73], ["+", 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], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22]]
8
243
21
using System; using System.Collections.Generic; using System.Linq; namespace Atcoder { class Program { static void Main(string[] args) { var nk = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray(); var n = nk[0]; var k = nk[1]; List<int> d = new List<int>(); List<int[]> a = new List<int[]>(); for (int i = 0; i < k; i++) { d.Add(int.Parse(Console.ReadLine())); var aa = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray(); a.Add(aa); } int ans = n - a.Distinct().Count(); Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; namespace Atcoder { class Program { static void Main(string[] args) { var nk = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray(); var n = nk[0]; var k = nk[1]; List<int> d = new List<int>(); List<int[]> a = new List<int[]>(); for (int i = 0; i < k; i++) { d.Add(int.Parse(Console.ReadLine())); var aa = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray(); a.Add(aa); } var b = a.SelectMany(s => s).Distinct().Count(); int ans = n - b; Console.WriteLine(ans); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 205, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 205, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 205, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 205, 213, 3, 4, 0, 28, 0, 218, 8, 22], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22]]
8
201
20
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; namespace Tasks { public class B { 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 N = Scanner.Scan<int>(); var A = Scanner.ScanEnumerable<ulong>().ToArray(); if (A.Contains(0UL)) { Console.WriteLine(0); return; } var answer = 1UL; var ok = true; for (var i = 0; i < N && ok; i++) { answer *= A[i]; if (answer > (ulong)1e18) ok = false; } Console.WriteLine(ok ? answer.ToString() : "-1"); } public static class Scanner { private static Queue<string> queue = new Queue<string>(); public static T Next<T>() { if (!queue.Any()) foreach (var item in Console.ReadLine().Trim().Split(" ")) queue.Enqueue(item); return (T)Convert.ChangeType(queue.Dequeue(), typeof(T)); } public static T Scan<T>() => Next<T>(); public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>()); public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(), Next<T3>()); public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>()); public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>()); public static IEnumerable<T> ScanEnumerable<T>() => Console.ReadLine().Trim().Split(" ").Select( x => (T)Convert.ChangeType(x, typeof(T))); } } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; namespace Tasks { public class B { 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 N = Scanner.Scan<int>(); var A = Scanner.ScanEnumerable<ulong>().ToArray(); const ulong limit = (ulong)1e18; if (A.Contains(0UL)) { Console.WriteLine(0); return; } var answer = 1UL; var ok = true; for (var i = 0; i < N && ok; i++) { try { checked { answer *= A[i]; } } catch { ok = false; } if (answer > limit) ok = false; } Console.WriteLine(ok ? answer.ToString() : "-1"); } public static class Scanner { private static Queue<string> queue = new Queue<string>(); public static T Next<T>() { if (!queue.Any()) foreach (var item in Console.ReadLine().Trim().Split(" ")) queue.Enqueue(item); return (T)Convert.ChangeType(queue.Dequeue(), typeof(T)); } public static T Scan<T>() => Next<T>(); public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>()); public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(), Next<T3>()); public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>()); public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>()); public static IEnumerable<T> ScanEnumerable<T>() => Console.ReadLine().Trim().Split(" ").Select( x => (T)Convert.ChangeType(x, typeof(T))); } } }
[["+", 0, 195, 8, 196, 0, 197, 0, 251, 0, 154], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 24], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 25], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 51, 250], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 45], ["+", 8, 196, 0, 7, 8, 196, 0, 246, 0, 247], ["+", 0, 7, 8, 196, 0, 246, 8, 196, 0, 45], ["+", 8, 196, 0, 246, 8, 196, 0, 287, 0, 292], ["+", 0, 246, 8, 196, 0, 287, 0, 196, 0, 46], ["+", 0, 7, 8, 196, 0, 246, 8, 196, 0, 46], ["+", 0, 7, 8, 196, 0, 246, 0, 248, 0, 249], ["+", 8, 196, 0, 246, 0, 248, 8, 196, 0, 45], ["+", 0, 248, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 211, 0, 147], ["+", 0, 246, 0, 248, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 246, 0, 248, 8, 196, 0, 46], ["-", 8, 196, 0, 57, 15, 16, 12, 74, 0, 24], ["-", 8, 196, 0, 57, 15, 16, 12, 74, 39, 199], ["-", 8, 196, 0, 57, 15, 16, 12, 74, 0, 25], ["-", 8, 196, 0, 57, 15, 16, 12, 74, 51, 250], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22]]
8
555
27
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; namespace B { 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 n = int.Parse(Console.ReadLine()); var ai = Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); if (ai.Contains(0)) { Console.WriteLine(0); return; } var limit = (long)1e18; var answer = 1L; for (var i = 0; i < ai.Length; i++) { try { answer *= ai[i]; } catch (OverflowException) { Console.WriteLine(-1); return; } if (answer > limit) { Console.WriteLine(-1); return; } } Console.WriteLine(answer); } } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; namespace B { 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 n = int.Parse(Console.ReadLine()); var ai = Console.ReadLine().Trim().Split(' ').Select(decimal.Parse).ToArray(); if (ai.Contains(0)) { Console.WriteLine(0); return; } var limit = (decimal)1e18; decimal answer = 1; for (var i = 0; i < ai.Length; i++) { try { answer *= ai[i]; } catch { Console.WriteLine(-1); return; } if (answer > limit) { Console.WriteLine(-1); return; } } Console.WriteLine(answer); } } }
[["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 196, 0, 246, 0, 248, 0, 300, 0, 24], ["-", 8, 196, 0, 246, 0, 248, 0, 300, 39, 22], ["-", 8, 196, 0, 246, 0, 248, 0, 300, 0, 25]]
8
237
11
using System; using System.Linq; using System.Collections.Generic; namespace ABC177 { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var A = Console.ReadLine().Split(' '); if (A.Contains("0")) { System.Console.WriteLine(0); return; } ulong limit = (ulong)Math.Pow(10, 18); ulong answer = 1; for (int i = 0; i < N; i++) { answer *= ulong.Parse(A[i]); if (answer > limit) { System.Console.WriteLine(-1); return; } } System.Console.WriteLine(answer); } } }
using System; using System.Linq; using System.Collections.Generic; namespace ABC177 { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var A = Console.ReadLine().Split(' '); if (A.Contains("0")) { System.Console.WriteLine(0); return; } ulong limit = (ulong)Math.Pow(10, 18); ulong answer = 1; for (int i = 0; i < N; i++) { if (answer <= limit / ulong.Parse(A[i])) { answer *= ulong.Parse(A[i]); } else { System.Console.WriteLine(-1); return; } } System.Console.WriteLine(answer); } } }
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 108], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 85], ["+", 15, 16, 12, 16, 12, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 108], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 12, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95]]
8
165
25
using System; using System.Linq; class IDONTKNOWCSHARP { public static void Main() { int num = int.Parse(Console.ReadLine()); long[] values = Convert(GetLines()); long ans = 1; bool first = true; if (values.Contains(0)) { Console.WriteLine("0"); return; } foreach (long value in values) { if (first) { ans = value; first = false; continue; } // try // { ans *= value; // } // catch // { // Console.WriteLine("-1"); // return; //// } } if (ans > 1000000000000000000) { Console.WriteLine("-1"); return; } // Console.WriteLine("{0:D}", (long)Math.Pow(10, 18)); Console.WriteLine("{0:d}", ans); // Console.ReadKey(); } static string[] GetLines() { return Console.ReadLine().Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); } static long[] Convert(string[] v) { var temp = new long[v.Length]; for (int i = 0; i < temp.Length; i++) { temp[i] = long.Parse(v[i]); } return temp; } }
using System; using System.Linq; class IDONTKNOWCSHARP { public static void Main() { Console.WriteLine(); int num = int.Parse(Console.ReadLine()); ulong[] values = Convert(GetLines()); ulong ans = 1; bool first = true; if (values.Any(x => x == 0)) { Console.WriteLine("0"); return; } foreach (ulong value in values) { if (first) { ans = value; first = false; continue; } try { checked { ans *= value; } } catch { Console.WriteLine("-1"); return; } } if (ans > 1000000000000000000) { Console.WriteLine("-1"); return; } // Console.WriteLine("{0:D}", (long)Math.Pow(10, 18)); Console.WriteLine("{0:d}", ans); // Console.ReadKey(); } static string[] GetLines() { return Console.ReadLine().Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); } static ulong[] Convert(string[] v) { var temp = new ulong[v.Length]; for (int i = 0; i < temp.Length; i++) { temp[i] = ulong.Parse(v[i]); } return temp; } }
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 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, 196, 0, 57, 15, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 57, 15, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 15, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 17, 60], ["-", 8, 201, 0, 195, 8, 196, 0, 210, 39, 199], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 39, 199], ["+", 8, 196, 0, 210, 8, 196, 0, 246, 0, 247], ["+", 0, 210, 8, 196, 0, 246, 8, 196, 0, 45], ["+", 8, 196, 0, 246, 8, 196, 0, 287, 0, 292], ["+", 0, 246, 8, 196, 0, 287, 0, 196, 0, 45], ["+", 8, 196, 0, 287, 0, 196, 0, 1, 0, 35], ["+", 0, 246, 8, 196, 0, 287, 0, 196, 0, 46], ["+", 0, 210, 8, 196, 0, 246, 8, 196, 0, 46], ["+", 0, 210, 8, 196, 0, 246, 0, 248, 0, 249], ["+", 8, 196, 0, 246, 0, 248, 8, 196, 0, 45], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 246, 0, 248, 8, 196, 0, 37, 0, 38], ["+", 0, 246, 0, 248, 8, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 210, 8, 196, 0, 46], ["-", 0, 235, 8, 201, 0, 195, 39, 224, 39, 199], ["+", 0, 235, 8, 201, 0, 195, 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, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199]]
8
240
44
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var A = new List<long>(); var line = Console.ReadLine().Split(" "); for (int i = 0; i < N; i++) { A.Add(long.Parse(line[i])); } long result = 1; try { foreach (var item in A) { checked { result *= item; } } } catch (OverflowException ex) { result = -1; } if (result > 1000000000000000000) { result = -1; } Console.WriteLine(result); } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var A = new List<long>(); var line = Console.ReadLine().Split(" "); for (int i = 0; i < N; i++) { A.Add(long.Parse(line[i])); } long result = 1; if (A.Contains(0)) { result = 0; } else { try { foreach (var item in A) { checked { result *= item; } } } catch (OverflowException ex) { result = -1; } if (result > 1000000000000000000) { result = -1; } } Console.WriteLine(result); } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 57, 15, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 57, 15, 213, 3, 4, 0, 24], ["+", 0, 57, 15, 213, 3, 4, 0, 28, 0, 203], ["+", 8, 196, 0, 57, 15, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 57, 64, 196, 0, 46]]
8
158
18
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { long max = 1000000000000000000; var N = cin.ReadInt; var num = new long[N]; long ans = 1; for (int i = 0; i < N; i++) { num[i] = cin.ReadLong; } if (num.Contains(0)) { ans = 0; } else { foreach (var n in num) { ans *= n; if (ans > max) { ans = -1; break; } } } WriteLine(ans); } public void Display(int[] array) { var txt = ""; foreach (var item in array) { txt += " " + item.ToString(); } WriteLine("{0}", txt); } public void Display(int index, int[] array) { var txt = ""; foreach (var item in array) { txt += " " + item.ToString(); } WriteLine("{0} : {1}", index, txt); } public void Display(List<int>[] list) { for (int i = 0; i < list.Length; i++) { Display(i, list[i].ToArray()); } } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; i++) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { long max = 1000000000000000000; var N = cin.ReadInt; var num = new long[N]; long ans = 1; for (int i = 0; i < N; i++) { num[i] = cin.ReadLong; } if (num.Contains(0)) { ans = 0; } else { foreach (var n in num) { if (ans > max / n) { ans = -1; break; } ans *= n; } } WriteLine(ans); } public void Display(int[] array) { var txt = ""; foreach (var item in array) { txt += " " + item.ToString(); } WriteLine("{0}", txt); } public void Display(int index, int[] array) { var txt = ""; foreach (var item in array) { txt += " " + item.ToString(); } WriteLine("{0} : {1}", index, txt); } public void Display(List<int>[] list) { for (int i = 0; i < list.Length; i++) { Display(i, list[i].ToArray()); } } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; i++) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
[["-", 0, 210, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 108], ["-", 0, 210, 8, 196, 0, 1, 0, 11, 12, 22], ["-", 75, 196, 0, 210, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 85], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["+", 0, 210, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 108], ["+", 0, 210, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 75, 196, 0, 210, 8, 196, 0, 1, 0, 35]]
8
671
10
using System; using System.Collections.Generic; namespace test { class MainClass { public static void Main(string[] args) { //問題169 int N = int.Parse(Console.ReadLine()); string[] line = Console.ReadLine().Split(' '); long[] A = new long[N]; for (int i = 0; i < N; i++) { // Console.WriteLine(i); A[i] = long.Parse(line[i]); // Console.WriteLine(A[i]); if (A[i] == 0) { Console.WriteLine(0); return; } } long ans = 1; for (int i = 0; i < N; i++) { ans *= A[i]; if (ans > 1000000000000000000) { Console.WriteLine(-1); return; } } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; namespace test { class MainClass { public static void Main(string[] args) { //問題169 int N = int.Parse(Console.ReadLine()); string[] line = Console.ReadLine().Split(' '); long[] A = new long[N]; for (int i = 0; i < N; i++) { // Console.WriteLine(i); A[i] = long.Parse(line[i]); // Console.WriteLine(A[i]); if (A[i] == 0) { Console.WriteLine(0); return; } } long ans = 1; for (int i = 0; i < N; i++) { if (ans > 1000000000000000000 / A[i]) { Console.WriteLine(-1); return; } ans *= A[i]; } Console.WriteLine(ans); } } }
[["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 108], ["-", 8, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["-", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["-", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 85], ["+", 0, 57, 15, 16, 12, 16, 12, 204, 205, 22], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 108], ["+", 8, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
8
180
19
using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; using System.Text; namespace AtCoder { class Program { private static void Main(string[] args) { var n = Scanner.Integer(); var a = Scanner.ArrayLong(n); if (a.Contains(0)) { Console.WriteLine(0); return; } try { var val = a.Aggregate((long)1, (c, b) => c * b); if ((val / (long)(Math.Pow(10, 18) + 1)) >= 1) { Console.WriteLine("-1"); } else { Console.WriteLine(val); } } catch (Exception e) { Console.WriteLine("-1"); } } #region Utility static readonly StreamScanner Scanner = new StreamScanner(Console.OpenStandardInput()); /// <summary> 一括出力 </summary> private static void OutAllLine(IEnumerable<dynamic> items) { var sb = new StringBuilder(); foreach (var result in items) { sb.Append(result + "\n"); } sb = sb.Remove(sb.Length - 1, 1); Console.WriteLine(sb); } #endregion } #region Utility Class public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } private readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) throw new EndOfStreamException(); if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public long Long() { long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != '-' && (b < '0' || '9' < b)); if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } public int Integer() { return (int)Long(); } public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); } /// <summary> 数値読み込み </summary> public List<long> ArrayLong(int count = 0) { var scan = new List<long>(); for (int i = 0; i < count; i++) { scan.Add(Long()); } return scan; } /// <summary> 数値読み込み </summary> public List<int> ArrayInt(int count = 0) { var scan = new List<int>(); for (int i = 0; i < count; i++) { scan.Add(Integer()); } return scan; } } public class Primer { /// <summary> 素数判定 </summary> public static bool IsPrime(int num) { if (num < 2) { return false; } if (num == 2) { return true; } if (num % 2 == 0) { return false; } double sqrtNum = Math.Sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) { return false; } } return true; } public static IEnumerable<int> GetPrimeFactors(int n) { int i = 2; int tmp = n; while (i * i <= n) //※1 { if (tmp % i == 0) { tmp /= i; yield return i; } else { i++; } } if (tmp != 1) yield return tmp; } } public class Mod109 { public const int _7 = 1000000007; public const int _9 = 1000000009; public const int _3 = 998244353; private readonly int ModValue; public Mod109(int modValue = Mod109._7) { ModValue = modValue; } /// <summary> 和 </summary> public long Addition(IEnumerable<long> nums) { return nums.Aggregate<long, long>( 0, (current, num) => ModifyPositive((current + num) % ModValue)); } /// <summary> 差 </summary> public long Subtraction(IEnumerable<long> nums) { return nums.Aggregate<long, long>( 0, (current, num) => ModifyPositive((current - num) % ModValue)); } /// <summary> 積 </summary> public long Multiplication(IEnumerable<long> nums) { return nums.Aggregate<long, long>( 1, (current, num) => ModifyPositive((current * num) % ModValue)); } private long ModifyPositive(long value) { return value < 0 ? (value + ModValue) : value; } } public class BitArrayMaker { public List<int> Integer(int bitValue, int length) { var list = new List<int>(); for (int i = 0; i < length; i++) { if (bitValue % 2 == 1) { list.Add(i); } bitValue /= 2; } return list; } public bool[] Boolean(int bitValue, int length) { var list = new bool[length]; for (int i = 0; i < length; i++) { list[i] = bitValue % 2 == 1; bitValue /= 2; } return list; } } #endregion }
using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; using System.Text; namespace AtCoder { class Program { private static void Main(string[] args) { var n = Scanner.Integer(); var a = Scanner.ArrayLong(n).Select(x => (decimal)x).ToArray(); if (a.Contains(0)) { Console.WriteLine(0); return; } try { var val = a.Aggregate((decimal)1, (c, b) => c * b); var j = val - (decimal)(Math.Pow(10, 18) + 1); if (j >= 1) { Console.WriteLine("-1"); } else { Console.WriteLine(val); } } catch (Exception) { Console.WriteLine("-1"); } } #region Utility static readonly StreamScanner Scanner = new StreamScanner(Console.OpenStandardInput()); /// <summary> 一括出力 </summary> private static void OutAllLine(IEnumerable<dynamic> items) { var sb = new StringBuilder(); foreach (var result in items) { sb.Append(result + "\n"); } sb = sb.Remove(sb.Length - 1, 1); Console.WriteLine(sb); } #endregion } #region Utility Class public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } private readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) throw new EndOfStreamException(); if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public long Long() { long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != '-' && (b < '0' || '9' < b)); if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } public int Integer() { return (int)Long(); } public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); } /// <summary> 数値読み込み </summary> public List<long> ArrayLong(int count = 0) { var scan = new List<long>(); for (int i = 0; i < count; i++) { scan.Add(Long()); } return scan; } /// <summary> 数値読み込み </summary> public List<int> ArrayInt(int count = 0) { var scan = new List<int>(); for (int i = 0; i < count; i++) { scan.Add(Integer()); } return scan; } } public class Primer { /// <summary> 素数判定 </summary> public static bool IsPrime(int num) { if (num < 2) { return false; } if (num == 2) { return true; } if (num % 2 == 0) { return false; } double sqrtNum = Math.Sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) { return false; } } return true; } public static IEnumerable<int> GetPrimeFactors(int n) { int i = 2; int tmp = n; while (i * i <= n) //※1 { if (tmp % i == 0) { tmp /= i; yield return i; } else { i++; } } if (tmp != 1) yield return tmp; } } public class Mod109 { public const int _7 = 1000000007; public const int _9 = 1000000009; public const int _3 = 998244353; private readonly int ModValue; public Mod109(int modValue = Mod109._7) { ModValue = modValue; } /// <summary> 和 </summary> public long Addition(IEnumerable<long> nums) { return nums.Aggregate<long, long>( 0, (current, num) => ModifyPositive((current + num) % ModValue)); } /// <summary> 差 </summary> public long Subtraction(IEnumerable<long> nums) { return nums.Aggregate<long, long>( 0, (current, num) => ModifyPositive((current - num) % ModValue)); } /// <summary> 積 </summary> public long Multiplication(IEnumerable<long> nums) { return nums.Aggregate<long, long>( 1, (current, num) => ModifyPositive((current * num) % ModValue)); } private long ModifyPositive(long value) { return value < 0 ? (value + ModValue) : value; } } public class BitArrayMaker { public List<int> Integer(int bitValue, int length) { var list = new List<int>(); for (int i = 0; i < length; i++) { if (bitValue % 2 == 1) { list.Add(i); } bitValue /= 2; } return list; } public bool[] Boolean(int bitValue, int length) { var list = new bool[length]; for (int i = 0; i < length; i++) { list[i] = bitValue % 2 == 1; bitValue /= 2; } return list; } } #endregion }
[["+", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 205, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 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], ["+", 3, 4, 0, 28, 0, 218, 8, 74, 51, 22], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 0, 213, 3, 4, 0, 28, 0, 74, 39, 199], ["+", 0, 213, 3, 4, 0, 28, 0, 74, 39, 199], ["-", 8, 196, 0, 246, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 246, 8, 196, 0, 57, 0, 24], ["-", 8, 196, 0, 57, 15, 16, 31, 23, 0, 24], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 57, 15, 16, 31, 23, 0, 16, 17, 85], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["-", 15, 16, 31, 23, 0, 16, 12, 74, 39, 199], ["+", 0, 200, 0, 212, 0, 16, 12, 74, 39, 199], ["-", 8, 196, 0, 57, 15, 16, 31, 23, 0, 25], ["+", 8, 196, 0, 246, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 246, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 246, 8, 196, 0, 57, 0, 24], ["+", 0, 246, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 8, 196, 0, 246, 0, 248, 0, 300, 141, 22]]
8
1,230
32
using System; using System.Linq; using static System.Console; namespace B { internal class Program { private static readonly long MaxValue = 1000000000000000000; public static void Main(string[] args) { var n = ReadLine(); var input = ReadLine().Split(' ').Select(long.Parse); if (input.Contains(0)) { WriteLine(0); return; } var result = input.Aggregate( (r, c) => (c < MaxValue / r || r * c < MaxValue) ? r * c : -1); WriteLine(result > 0 ? result : -1); } } }
using System; using System.Linq; using static System.Console; namespace B { internal class Program { private static readonly long MaxValue = 1000000000000000000; public static void Main(string[] args) { var n = ReadLine(); var input = ReadLine().Split(' ').Select(long.Parse); if (input.Contains(0)) { WriteLine(0); return; } var result = input.Aggregate((r, c) => c <= MaxValue / r ? r * c : -1); WriteLine(result > 0 ? result : -1); } } }
[["-", 0, 28, 0, 218, 8, 41, 15, 23, 0, 24], ["-", 8, 41, 15, 23, 0, 16, 31, 16, 17, 18], ["+", 0, 28, 0, 218, 8, 41, 15, 16, 17, 19], ["-", 15, 23, 0, 16, 31, 16, 12, 16, 12, 22], ["-", 0, 218, 8, 41, 15, 23, 0, 16, 17, 106], ["-", 15, 23, 0, 16, 12, 16, 31, 16, 17, 48], ["-", 15, 23, 0, 16, 12, 16, 31, 16, 12, 22], ["-", 8, 41, 15, 23, 0, 16, 12, 16, 17, 18], ["-", 8, 41, 15, 23, 0, 16, 12, 16, 12, 22], ["-", 0, 28, 0, 218, 8, 41, 15, 23, 0, 25]]
8
136
10
using System; namespace ConsoleApp1 { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); var input = Console.ReadLine().Split(' '); long[] numbers = new long[n]; long res = 1; bool haszero = false; for (int i = 0; i < n; i++) { numbers[i] = long.Parse(input[i]); if (numbers[i] == 0) haszero = true; } if (haszero) { Console.WriteLine(0); } else { for (int i = 0; i < n; i++) { res *= numbers[i]; if (res > 1000000000000000000) { res = -1; break; } } Console.WriteLine(res); } } } }
using System; namespace ConsoleApp1 { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); var input = Console.ReadLine().Split(' '); long[] numbers = new long[n]; long res = 1; bool haszero = false; double logres = 0; for (int i = 0; i < n; i++) { numbers[i] = long.Parse(input[i]); if (numbers[i] == 0) haszero = true; } if (haszero) { Console.WriteLine(0); } else { for (int i = 0; i < n; i++) { res *= numbers[i]; logres += Math.Log10(numbers[i]); if (res > 1000000000000000000 || logres > 18) { res = -1; break; } } Console.WriteLine(res); } } } }
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 12, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 75, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
8
178
21
using System; using System.Collections.Generic; using System.Linq; public class AtCoder { public static void Main() { //入力を保持する var N = int.Parse(Console.ReadLine()); var As = Console.ReadLine().Split().Select(e => long.Parse(e)).ToArray(); // Array.Sort(As); foreach (var a in As) { if (a == 0) { Console.WriteLine(0); return; } } long ans = 1; for (int i = 0; i < N; i++) { long work = ans * As[i]; if ((work > 1000000000000000000) || (work < 0)) { ans = -1; break; } ans = ans * As[i]; } Console.WriteLine(ans); } }
using System; using System.Collections.Generic; using System.Linq; public class AtCoder { public static void Main() { //入力を保持する var N = int.Parse(Console.ReadLine()); var As = Console.ReadLine().Split().Select(e => long.Parse(e)).ToArray(); // Array.Sort(As); foreach (var a in As) { if (a == 0) { Console.WriteLine(0); return; } } long ans = 1; for (int i = 0; i < N; i++) { if (1000000000000000000 / As[i] < ans) { ans = -1; break; } ans = ans * As[i]; } Console.WriteLine(ans); } }
[["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 48], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 85], ["-", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 8, 196, 0, 57, 15, 16, 31, 23, 0, 24], ["-", 0, 57, 15, 16, 31, 23, 0, 16, 31, 22], ["-", 0, 57, 15, 16, 31, 23, 0, 16, 17, 47], ["-", 0, 57, 15, 16, 31, 23, 0, 16, 12, 203], ["-", 8, 196, 0, 57, 15, 16, 31, 23, 0, 25], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 106], ["-", 8, 196, 0, 57, 15, 16, 12, 23, 0, 24], ["-", 0, 57, 15, 16, 12, 23, 0, 16, 31, 22], ["-", 0, 57, 15, 16, 12, 23, 0, 16, 12, 203], ["-", 8, 196, 0, 57, 15, 16, 12, 23, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22]]
8
169
23
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { // 整数の入力 int n = int.Parse(Console.ReadLine()); long[] a = new long[n]; // スペース区切りの整数の入力 string[] input = Console.ReadLine().Split(' '); for (int i = 0; i < n; i++) { a[i] = long.Parse(input[i]); } long result = 1; long limit = (long)Math.Pow(10, 18); for (int i = 0; i < n; i++) { if (a[i] == 0) { result = 0; break; } else if (result <= limit / a[i]) { result = result * a[i]; } else { result = -1; break; } } //出力 Console.WriteLine(result.ToString("0")); } }
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { // 整数の入力 int n = int.Parse(Console.ReadLine()); long[] a = new long[n]; // スペース区切りの整数の入力 string[] input = Console.ReadLine().Split(' '); for (int i = 0; i < n; i++) { a[i] = long.Parse(input[i]); if (a[i] == 0) { Console.WriteLine(a[i]); return; } } long result = 1; long limit = (long)Math.Pow(10, 18); for (int i = 0; i < n; i++) { if (a[i] == 0) { result = 0; break; } else if (result <= limit / a[i]) { result = result * a[i]; } else { result = -1; break; } } //出力 Console.WriteLine(result.ToString("0")); } }
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
202
23
using System; using System.Collections; using System.Collections.Generic; class Program { static void Main() { long n = long.Parse(Console.ReadLine()); long ans = 1; String[] inline = Console.ReadLine().Split(' '); int flag = 1; for (int i = 0; i < n; i++) { ans *= long.Parse(inline[i]); if (ans == 0) { flag = 0; break; } if (ans > (long)Math.Pow(10, 18)) { flag = -1; } } switch (flag) { case 1: Console.WriteLine(ans); break; case 0: Console.WriteLine(0); break; case -1: Console.WriteLine(-1); break; } } }
using System; using System.Collections; using System.Collections.Generic; class Program { static void Main() { long n = long.Parse(Console.ReadLine()); long ans = 1; String[] inline = Console.ReadLine().Split(' '); int flag = 1; for (int i = 0; i < n; i++) { try { checked { ans *= long.Parse(inline[i]); } } catch (OverflowException) { flag = -1; } if (ans == 0) { flag = 0; break; } if (ans > (long)Math.Pow(10, 18)) { flag = -1; } } switch (flag) { case 1: Console.WriteLine(ans); break; case 0: Console.WriteLine(0); break; case -1: Console.WriteLine(-1); break; } } }
[["+", 8, 196, 0, 7, 8, 196, 0, 246, 0, 247], ["+", 0, 7, 8, 196, 0, 246, 8, 196, 0, 45], ["+", 8, 196, 0, 246, 8, 196, 0, 287, 0, 292], ["+", 0, 246, 8, 196, 0, 287, 0, 196, 0, 45], ["+", 0, 246, 8, 196, 0, 287, 0, 196, 0, 46], ["+", 0, 7, 8, 196, 0, 246, 8, 196, 0, 46], ["+", 0, 7, 8, 196, 0, 246, 0, 248, 0, 249], ["+", 8, 196, 0, 246, 0, 248, 0, 300, 0, 24], ["+", 8, 196, 0, 246, 0, 248, 0, 300, 39, 22], ["+", 8, 196, 0, 246, 0, 248, 0, 300, 0, 25], ["+", 8, 196, 0, 246, 0, 248, 8, 196, 0, 45], ["+", 0, 248, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 241, 0, 33], ["+", 8, 196, 0, 1, 0, 11, 12, 241, 0, 203], ["+", 0, 246, 0, 248, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 246, 0, 248, 8, 196, 0, 46]]
8
177
17
using System; using System.Linq; namespace AtCoder.Question { public class QuestionB { public static void Main(string[] args) { var n = ReadValue<long>(); var array = ReadValues<long>(); long result = 1; long max = 1000000000000000000; if (array.Any(x => x == 0)) { Console.WriteLine(0); return; } for (int i = 0; i < array.Length; i++) { if (max / result > array[i]) { Console.WriteLine(-1); return; } result *= array[i]; } Console.WriteLine(result); } static T ReadValue<T>() { return (T)Convert.ChangeType(Console.ReadLine(), typeof(T)); } static (T1, T2) ReadValue<T1, T2>() { var input = Console.ReadLine().Split(' '); return ((T1)Convert.ChangeType(input[0], typeof(T1)), (T2)Convert.ChangeType(input[1], typeof(T2))); } static (T1, T2, T3) ReadValue<T1, T2, T3>() { var input = Console.ReadLine().Split(' '); return ((T1)Convert.ChangeType(input[0], typeof(T1)), (T2)Convert.ChangeType(input[1], typeof(T2)), (T3)Convert.ChangeType(input[2], typeof(T3))); } static (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>() { var input = Console.ReadLine().Split(' '); return ((T1)Convert.ChangeType(input[0], typeof(T1)), (T2)Convert.ChangeType(input[1], typeof(T2)), (T3)Convert.ChangeType(input[2], typeof(T3)), (T4)Convert.ChangeType(input[3], typeof(T4))); } static T[] ReadValues<T>() { var input = Console.ReadLine().Split(' '); return input.Select(x => (T)Convert.ChangeType(x, typeof(T))).ToArray(); } } }
using System; using System.Linq; namespace AtCoder.Question { public class QuestionB { public static void Main(string[] args) { var n = ReadValue<long>(); var array = ReadValues<long>(); long result = 1; long max = (long)Math.Pow(10, 18); if (array.Any(x => x == 0)) { Console.WriteLine(0); return; } for (int i = 0; i < array.Length; i++) { if (max / result < array[i]) { Console.WriteLine(-1); return; } result *= array[i]; } Console.WriteLine(result); } static T ReadValue<T>() { return (T)Convert.ChangeType(Console.ReadLine(), typeof(T)); } static (T1, T2) ReadValue<T1, T2>() { var input = Console.ReadLine().Split(' '); return ((T1)Convert.ChangeType(input[0], typeof(T1)), (T2)Convert.ChangeType(input[1], typeof(T2))); } static (T1, T2, T3) ReadValue<T1, T2, T3>() { var input = Console.ReadLine().Split(' '); return ((T1)Convert.ChangeType(input[0], typeof(T1)), (T2)Convert.ChangeType(input[1], typeof(T2)), (T3)Convert.ChangeType(input[2], typeof(T3))); } static (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>() { var input = Console.ReadLine().Split(' '); return ((T1)Convert.ChangeType(input[0], typeof(T1)), (T2)Convert.ChangeType(input[1], typeof(T2)), (T3)Convert.ChangeType(input[2], typeof(T3)), (T4)Convert.ChangeType(input[3], typeof(T4))); } static T[] ReadValues<T>() { var input = Console.ReadLine().Split(' '); return input.Select(x => (T)Convert.ChangeType(x, typeof(T))).ToArray(); } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 24], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 25], ["+", 0, 212, 0, 74, 51, 213, 63, 214, 205, 22], ["+", 0, 212, 0, 74, 51, 213, 63, 214, 0, 131], ["+", 0, 212, 0, 74, 51, 213, 63, 214, 141, 22], ["+", 0, 212, 0, 74, 51, 213, 3, 4, 0, 24], ["+", 0, 74, 51, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 212, 0, 74, 51, 213, 3, 4, 0, 21], ["+", 0, 212, 0, 74, 51, 213, 3, 4, 0, 25], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18]]
8
504
14
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC_169b { class Program { static void Main(string[] args) { int input = int.Parse(Console.ReadLine()); long[] num = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); long res = 1; if (num.Contains(0)) { Console.WriteLine("0"); Console.Read(); return; } foreach (long item in num) { res *= item; if (res > (long)Math.Pow(10, 18)) { res = long.Parse("-1"); } } Console.WriteLine(res); Console.Read(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC_169b { class Program { static void Main(string[] args) { int input = int.Parse(Console.ReadLine()); long[] num = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); long res = 1; if (num.Contains(0)) { Console.WriteLine("0"); Console.Read(); return; } try { checked { foreach (long item in num) { res *= item; if (res > (long)Math.Pow(10, 18)) { res = long.Parse("-1"); } } } } catch { res = long.Parse("-1"); } Console.WriteLine(res); Console.Read(); } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 246, 0, 247], ["+", 0, 195, 8, 196, 0, 246, 8, 196, 0, 45], ["+", 8, 196, 0, 246, 8, 196, 0, 287, 0, 292], ["+", 0, 246, 8, 196, 0, 287, 0, 196, 0, 45], ["+", 0, 210, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 287, 0, 196, 0, 210, 8, 196, 0, 46], ["+", 0, 246, 8, 196, 0, 287, 0, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 246, 0, 248, 0, 249], ["+", 8, 196, 0, 246, 0, 248, 8, 196, 0, 45], ["+", 0, 248, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 12, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 12, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 0, 246, 0, 248, 8, 196, 0, 1, 0, 35]]
8
175
20
using System; class Multiplication2 { static void Main() { var n = int.Parse(Console.ReadLine()); String[] a = Console.ReadLine().Split(); ulong sum = 1; int frag = 0; for (int i = 0; i < n; i++) { if (ulong.Parse(a[i]) == 0) { frag = 1; break; } } if (frag == 1) Console.WriteLine(0); else { try { for (int i = 0; i < n; i++) { checked { sum *= ulong.Parse(a[i]); } } } catch (OverflowException) { Console.WriteLine(-1); } if (sum > 1000000000000000000) Console.WriteLine(-1); else Console.WriteLine(sum); } } }
using System; class Multiplication2 { static void Main() { var n = int.Parse(Console.ReadLine()); String[] a = Console.ReadLine().Split(); ulong sum = 1; for (int i = 0; i < n; i++) { if (ulong.Parse(a[i]) == 0) { Console.WriteLine(0); return; } } try { for (int i = 0; i < n; i++) { checked { sum *= ulong.Parse(a[i]); } } } catch (OverflowException) { Console.WriteLine(-1); return; } if (sum > 1000000000000000000) Console.WriteLine(-1); else Console.WriteLine(sum); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["-", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["+", 0, 246, 0, 248, 8, 196, 0, 1, 0, 35], ["+", 0, 246, 0, 248, 8, 196, 0, 37, 0, 38], ["-", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
177
28
using System; class Multiplication2 { static void Main() { var n = int.Parse(Console.ReadLine()); String[] a = Console.ReadLine().Split(); ulong sum = 1; // var array = new long[n]; int frag = 0; for (int i = 0; i < n; i++) { if (ulong.Parse(a[i]) == 0) { frag = 1; break; } } if (frag == 1) Console.WriteLine("0"); else { try { for (int i = 0; i < n; i++) { checked { sum *= ulong.Parse(a[i]); } } } catch (OverflowException) { Console.WriteLine("-1"); } if (sum > 1000000000000000000) Console.WriteLine("-1"); else Console.WriteLine(sum); } } }
using System; class Multiplication2 { static void Main() { var n = int.Parse(Console.ReadLine()); String[] a = Console.ReadLine().Split(); ulong sum = 1; int frag = 0; for (int i = 0; i < n; i++) { if (ulong.Parse(a[i]) == 0) { frag = 1; break; } } if (frag == 1) Console.WriteLine(0); else { try { for (int i = 0; i < n; i++) { checked { sum *= ulong.Parse(a[i]); } } } catch (OverflowException) { Console.WriteLine(-1); return; } if (sum > 1000000000000000000) Console.WriteLine(-1); else Console.WriteLine(sum); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["+", 0, 246, 0, 248, 8, 196, 0, 1, 0, 35], ["+", 0, 246, 0, 248, 8, 196, 0, 37, 0, 38]]
8
182
14
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace B { class Program { static void Main(string[] args) { string line = Console.ReadLine(); int N = int.Parse(line); long[] A = new long[N]; line = Console.ReadLine(); string[] strs = line.Split(' '); for (int i = 0; i < N; i++) { A[i] = long.Parse(strs[i]); } long sum = A[0]; long MAX = 1; for (int i = 0; i < 18; i++) MAX *= 10; for (int i = 1; i < N; i++) { if (A[i] > MAX / sum) { Console.WriteLine(-1); return; } sum *= A[i]; } Console.WriteLine(sum); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace B { class Program { static void Main(string[] args) { string line = Console.ReadLine(); int N = int.Parse(line); long[] A = new long[N]; line = Console.ReadLine(); string[] strs = line.Split(' '); for (int i = 0; i < N; i++) { A[i] = long.Parse(strs[i]); if (A[i] == 0) { Console.WriteLine(0); return; } } long sum = A[0]; long MAX = 1; for (int i = 0; i < 18; i++) MAX *= 10; for (int i = 1; i < N; i++) { if (A[i] > MAX / sum) { Console.WriteLine(-1); return; } sum *= A[i]; } Console.WriteLine(sum); } } }
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46]]
8
213
20
using System; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] ArrayS = Console.ReadLine().Split(' '); try { ulong sum = 1; ulong A = 1000000000000000000; ulong[] Array1 = new ulong[N]; for (int i = 0; i < N; i++) { if (ArrayS[i] == "0") { Console.WriteLine(0); return; } Array1[i] = ulong.Parse(ArrayS[i]); } Array.Sort(Array1); for (int i = 0; i < N; i++) { sum = (sum * Array1[i]); if (sum > A) { Console.WriteLine("-1"); return; } } Console.WriteLine(sum); } catch { Console.WriteLine("-1"); return; } } } } // long n = long.Parse(Console.ReadLine()); // long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => // long.Parse(i)).ToArray(); // Console.WriteLine(cnt); // Console.ReadKey();
using System; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] ArrayS = Console.ReadLine().Split(' '); try { ulong sum = 1; ulong A = 1000000000000000000; ulong[] Array1 = new ulong[N]; for (int i = 0; i < N; i++) { if (ArrayS[i] == "0") { Console.WriteLine(0); return; } Array1[i] = ulong.Parse(ArrayS[i]); } Array.Sort(Array1); for (int i = 0; i < N; i++) { if (A / sum < Array1[i]) { Console.WriteLine("-1"); return; } sum = (sum * Array1[i]); if (sum > A) { Console.WriteLine("-1"); return; } } Console.WriteLine(sum); } catch { Console.WriteLine("-1"); return; } } } } // long n = long.Parse(Console.ReadLine()); // long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => // long.Parse(i)).ToArray(); // Console.WriteLine(cnt); // Console.ReadKey();
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 85], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 12, 204, 205, 22], ["+", 0, 57, 15, 16, 12, 204, 206, 207, 0, 70], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 57, 15, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
215
24
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { class QuestionB { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // 整数の入力 long n = long.Parse(Console.ReadLine()); // 整数配列の入力 var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray(); long ret = 1; if (inputLongArray.Where(r => r == 0).Any()) { ret = 0; } else { for (int i = 0; i < n; i++) { long b = inputLongArray[i]; if (IsOverFlow(ret, b) || (ret * b).ToString().Length > 18) { ret = -1; break; } else { ret *= b; } } } string result = ret.ToString(); Console.WriteLine(result); Console.Out.Flush(); } /// <summary> /// a * b > LONGMAX /// a > LONGMAX / b ならNG /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <param name="target"></param> /// <returns></returns> public static bool IsOverFlow(long a, long b) { return a > long.MaxValue / b; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { class QuestionB { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // 整数の入力 long n = long.Parse(Console.ReadLine()); // 整数配列の入力 var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray(); long ret = 1; if (inputLongArray.Where(r => r == 0).Any()) { ret = 0; } else { for (int i = 0; i < n; i++) { long b = inputLongArray[i]; if (IsOverFlow(ret, b) || (ret * b) > 1000000000000000000) { ret = -1; break; } else { ret *= b; } } } string result = ret.ToString(); Console.WriteLine(result); Console.Out.Flush(); } /// <summary> /// a * b > LONGMAX /// a > LONGMAX / b ならNG /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <param name="target"></param> /// <returns></returns> public static bool IsOverFlow(long a, long b) { return a > long.MaxValue / b; } } }
[["-", 12, 16, 31, 214, 205, 213, 63, 214, 0, 131], ["-", 12, 16, 31, 214, 205, 213, 63, 214, 141, 22], ["-", 12, 16, 31, 214, 205, 213, 3, 4, 0, 24], ["-", 12, 16, 31, 214, 205, 213, 3, 4, 0, 25], ["-", 0, 57, 15, 16, 12, 16, 31, 214, 0, 131], ["-", 0, 57, 15, 16, 12, 16, 31, 214, 141, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
8
274
8
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleAppTest { class Multiplication2 { static void Main(string[] args) { var i = 0; var num = Console.ReadLine(); if (num == null) { Console.WriteLine(0); return; } int eleNum = int.Parse(num); var ele = new long[eleNum]; long sum = 1; long max = (long)Math.Pow(10, 18); // 2つ以上のスペース区切り入力の取得 string[] str = Console.ReadLine().Split(' '); //数値で受け取りたい場合は変換する for (i = 0; i < eleNum; i++) { ele[i] = long.Parse(str[i]); if (ele[i] == 0) { Console.WriteLine(0); return; } } for (i = 0; i < eleNum; i++) { sum *= ele[i]; if (sum > max) { sum = -1; break; } } Console.WriteLine($"{sum}"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleAppTest { class Multiplication2 { static void Main(string[] args) { var i = 0; var num = Console.ReadLine(); if (num == null) { Console.WriteLine(0); return; } int eleNum = int.Parse(num); var ele = new long[eleNum]; long sum = 1; long max = (long)Math.Pow(10, 18); // 2つ以上のスペース区切り入力の取得 string[] str = Console.ReadLine().Split(' '); //数値で受け取りたい場合は変換する for (i = 0; i < eleNum; i++) { ele[i] = long.Parse(str[i]); if (ele[i] == 0) { Console.WriteLine(0); return; } } for (i = 0; i < eleNum; i++) { if (max / sum < ele[i]) { sum = -1; break; } sum *= ele[i]; if (sum > max) { sum = -1; break; } } Console.WriteLine($"{sum}"); } } }
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 85], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 12, 204, 205, 22], ["+", 0, 57, 15, 16, 12, 204, 206, 207, 0, 70], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 57, 15, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 241, 0, 33], ["+", 64, 196, 0, 1, 0, 11, 12, 241, 0, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22]]
8
234
20
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC169B { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] input = Console.ReadLine().Split(' '); ulong M = 1; int over = 0; for (int i = 0; i < N; i++) { ulong A1 = ulong.Parse(input[i]); M *= A1; if (M > 1000000000000000000) { over = -1; break; } } for (int j = 0; j < N; j++) { long Ai = long.Parse(input[j]); if (Ai == 0) { M = 0; } } if (over == -1) { Console.WriteLine("-1"); } else { Console.WriteLine(M); } // Console.WriteLine(input[0].Length); // Console.WriteLine(input[1].Length); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC169B { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] input = Console.ReadLine().Split(' '); ulong M = 1; int over = 0; for (int i = 0; i < N; i++) { ulong A1 = ulong.Parse(input[i]); if (A1 <= 1000000000000000000 / M & A1 != 0) { M *= A1; } else { over = -1; } } for (int j = 0; j < N; j++) { long Ai = long.Parse(input[j]); if (Ai == 0) { M = 0; over = 0; } } if (over == -1) { Console.WriteLine("-1"); } else { Console.WriteLine(M); } // Console.WriteLine(input[0].Length); // Console.WriteLine(input[1].Length); } } }
[["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 108], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 12, 22], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 19], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 85], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 67], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 79], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 108], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 45], ["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 35], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203]]
8
207
27
using System; namespace ChokudaiScanner { class MainClass { static void Main() { Scanner cin = new Scanner(); int N = cin.NextInt(); ulong[] A = cin.ArrayLong(N); ulong B = 1; Array.Sort(A); if (A[0] == 0) { Console.WriteLine("0"); } else { for (int i = 0; i < N; i++) { B *= A[i]; if (B > 100000000000000000) { Console.WriteLine("-1"); break; } if (i == N - 1) { Console.WriteLine(B); } } } } } 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 string[] ArrayNext(int N) { string[] Array = new string[N]; for (int i = 0; i < N; i++) { Array[i] = Next(); } return Array; } 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 ulong NextLong() { return ulong.Parse(Next()); } public ulong[] ArrayLong(int N, ulong add = 0) { ulong[] Array = new ulong[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; } } }
using System; namespace ChokudaiScanner { class MainClass { static void Main() { Scanner cin = new Scanner(); int N = cin.NextInt(); long[] A = cin.ArrayLong(N); long B = 1; Array.Sort(A); if (A[0] == 0) { Console.WriteLine("0"); } else { for (int i = 0; i < N; i++) { if (A[i] <= 1000000000000000000 / B) { B *= A[i]; } else { Console.WriteLine("-1"); return; } } Console.WriteLine(B); } } } 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 string[] ArrayNext(int N) { string[] Array = new string[N]; for (int i = 0; i < N; i++) { Array[i] = Next(); } return Array; } 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; } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 75, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 75, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 85], ["+", 75, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 75, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 75, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 75, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 75, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 8, 196, 0, 57, 75, 196, 0, 37, 0, 38], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 7, 8, 196, 0, 46], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 57, 75, 196, 0, 7, 8, 196, 0, 46], ["-", 8, 201, 0, 235, 8, 201, 0, 195, 39, 199], ["+", 8, 201, 0, 235, 8, 201, 0, 195, 39, 199], ["-", 8, 196, 0, 37, 0, 213, 63, 214, 205, 199], ["+", 8, 196, 0, 37, 0, 213, 63, 214, 205, 199], ["-", 0, 235, 8, 201, 0, 195, 39, 224, 39, 199], ["+", 0, 235, 8, 201, 0, 195, 39, 224, 39, 199], ["-", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199]]
8
541
50
using System; using System.Collections.Generic; using System.Linq; using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { class QuestionB { // https://atcoder.jp/contests/abc169/tasks/abc169_b public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // 整数の入力 long n = long.Parse(Console.ReadLine()); // 整数配列の入力 var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray(); long result = 1; var limit = (long)Math.Pow(10, 18); foreach (long c in inputLongArray) { result = result * c; } if (result > limit) { result = -1; } Console.WriteLine(result); Console.Out.Flush(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { class QuestionB { // https://atcoder.jp/contests/abc169/tasks/abc169_b public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // 整数の入力 long n = long.Parse(Console.ReadLine()); // 整数配列の入力 var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray(); long result = 1; var limit = (long)Math.Pow(10, 18); foreach (long c in inputLongArray) { if (c == 0) { result = 0; break; } if (c <= limit / result) { result *= c; } else { result = -1; } } Console.WriteLine(result); Console.Out.Flush(); } } }
[["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 24], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 25], ["+", 0, 210, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 85], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 108], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 0, 210, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 95], ["+", 0, 210, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 210, 8, 196, 0, 57, 75, 196, 0, 46]]
8
199
27
using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Linq; using System.Reflection; using System.Runtime.InteropServices; using System.Runtime.Serialization; using System.Security.Cryptography.X509Certificates; using System.Xml; namespace hello_world { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); string[] s = Console.ReadLine().Split(" "); long[] aa = new long[n]; long sum = 1; if (s.Contains("0")) Console.WriteLine("0"); else { for (int i = 0; i < n; i++) { aa[i] = long.Parse(s[i]); sum *= aa[i]; if (sum > 1000000000000000000) { sum = -1; i = n - 1; } } Console.WriteLine(sum); } } } }
using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Linq; using System.Reflection; using System.Runtime.InteropServices; using System.Runtime.Serialization; using System.Security.Cryptography.X509Certificates; using System.Xml; namespace hello_world { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); string[] s = Console.ReadLine().Split(" "); long[] aa = new long[n]; long sum = 1; if (s.Contains("0")) Console.WriteLine("0"); else { try { checked { for (int i = 0; i < n; i++) { aa[i] = long.Parse(s[i]); sum *= aa[i]; if (sum > 1000000000000000000) { sum = -1; i = n - 1; } } Console.WriteLine(sum); } } catch { Console.WriteLine(-1); } } } } }
[["+", 8, 196, 0, 57, 75, 196, 0, 246, 0, 247], ["+", 0, 57, 75, 196, 0, 246, 8, 196, 0, 45], ["+", 75, 196, 0, 246, 8, 196, 0, 287, 0, 292], ["+", 0, 246, 8, 196, 0, 287, 0, 196, 0, 45], ["+", 0, 246, 8, 196, 0, 287, 0, 196, 0, 46], ["+", 0, 57, 75, 196, 0, 246, 8, 196, 0, 46], ["+", 0, 57, 75, 196, 0, 246, 0, 248, 0, 249], ["+", 75, 196, 0, 246, 0, 248, 8, 196, 0, 45], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 246, 0, 248, 8, 196, 0, 1, 0, 35], ["+", 75, 196, 0, 246, 0, 248, 8, 196, 0, 46]]
8
214
17
using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Linq; using System.Reflection; using System.Runtime.InteropServices; using System.Runtime.Serialization; using System.Security.Cryptography.X509Certificates; using System.Xml; namespace hello_world { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); string[] aa = Console.ReadLine().Split(" "); int[] a = new int[n]; long sum = 1; for (int i = 0; i < n; i++) Input1(aa[i], out a[i]); if (aa.Contains("0")) Console.WriteLine("0"); else { try { checked { for (int i = 0; i < n; i++) { sum *= a[i]; } if (sum > 1000000000000000000) Console.WriteLine("-1"); else Console.WriteLine(sum); } } catch (OverflowException ex) { Console.WriteLine("-1"); } } } private static int Input1(string s, out int n) { if (int.TryParse(s, out n)) n = int.Parse(s); else n = 0; return n; } } }
using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Linq; using System.Reflection; using System.Runtime.InteropServices; using System.Runtime.Serialization; using System.Security.Cryptography.X509Certificates; using System.Xml; namespace hello_world { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); string[] aa = Console.ReadLine().Split(" "); ulong[] a = new ulong[n]; ulong sum = 1; for (int i = 0; i < n; i++) Input1(aa[i], out a[i]); if (aa.Contains("0")) Console.WriteLine("0"); else { try { checked { for (int i = 0; i < n; i++) { sum *= a[i]; } if (sum > 1000000000000000000) Console.WriteLine("-1"); else Console.WriteLine(sum); } } catch (OverflowException ex) { Console.WriteLine("-1"); } } } private static ulong Input1(string s, out ulong n) { if (ulong.TryParse(s, out n)) n = ulong.Parse(s); else n = 0; return n; } } }
[["-", 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, 201, 0, 235, 8, 201, 0, 195, 39, 199], ["+", 8, 201, 0, 235, 8, 201, 0, 195, 39, 199], ["-", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["-", 8, 196, 0, 57, 15, 213, 63, 214, 205, 199], ["+", 8, 196, 0, 57, 15, 213, 63, 214, 205, 199], ["-", 64, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["+", 64, 1, 0, 11, 12, 213, 63, 214, 205, 199]]
8
289
14
using System; class Program { static void Main() { int n = int.Parse(Console.ReadLine()); string[] In = Console.ReadLine().Split(' '); ulong sum = 1, temp = 0; bool flag = true; bool HasZero = false; for (int i = 0; i < n; i++) { if (long.Parse(In[i]) == 0) HasZero = true; } if (!HasZero) { for (int i = 0; i < n; i++) { temp = ulong.Parse(In[i]); sum *= temp; if (temp == (ulong)Math.Pow(10, 18) || sum > (ulong)Math.Pow(10, 18)) { flag = false; break; } } if (flag) Console.WriteLine(sum); else Console.WriteLine(-1); } else { Console.WriteLine(0); } } }
using System; class Program { static void Main() { int n = int.Parse(Console.ReadLine()); string[] In = Console.ReadLine().Split(' '); ulong sum = 1, temp = 0; bool flag = true; bool HasZero = false; for (int i = 0; i < n; i++) { if (long.Parse(In[i]) == 0) HasZero = true; } if (!HasZero) { try { checked { for (int i = 0; i < n; i++) { temp = ulong.Parse(In[i]); sum *= temp; if (temp == (ulong)Math.Pow(10, 18) || sum > (ulong)Math.Pow(10, 18)) { flag = false; break; } } if (flag) Console.WriteLine(sum); else Console.WriteLine(-1); } } catch { Console.WriteLine(-1); } } else { Console.WriteLine(0); } } }
[["+", 8, 196, 0, 57, 64, 196, 0, 246, 0, 247], ["+", 0, 57, 64, 196, 0, 246, 8, 196, 0, 45], ["+", 64, 196, 0, 246, 8, 196, 0, 287, 0, 292], ["+", 0, 246, 8, 196, 0, 287, 0, 196, 0, 45], ["+", 0, 246, 8, 196, 0, 287, 0, 196, 0, 46], ["+", 0, 57, 64, 196, 0, 246, 8, 196, 0, 46], ["+", 0, 57, 64, 196, 0, 246, 0, 248, 0, 249], ["+", 64, 196, 0, 246, 0, 248, 8, 196, 0, 45], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 246, 0, 248, 8, 196, 0, 1, 0, 35], ["+", 64, 196, 0, 246, 0, 248, 8, 196, 0, 46]]
8
206
17
using Microsoft.VisualBasic; using System; namespace AtCoder.Abc { class QuestionB { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var n = int.Parse(Console.ReadLine()); var sp = Console.ReadLine().Split(' '); var a = new long[n]; for (int i = 0; i < n; i++) { a[i] = long.Parse(sp[i]); if (a[i] == 0) { Console.WriteLine(0); Console.Out.Flush(); return; } } const long m = 1000000000000000000; long ans = a[0]; for (int i = 1; i < n; i++) { if ((m) / ans > a[i]) { Console.WriteLine(-1); Console.Out.Flush(); return; } ans *= a[i]; } Console.WriteLine(ans); Console.Out.Flush(); } } }
using Microsoft.VisualBasic; using System; namespace AtCoder.Abc { class QuestionB { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var n = int.Parse(Console.ReadLine()); var sp = Console.ReadLine().Split(' '); var a = new long[n]; for (int i = 0; i < n; i++) { a[i] = long.Parse(sp[i]); if (a[i] == 0) { Console.WriteLine(0); Console.Out.Flush(); return; } } const long m = 1000000000000000000; long ans = 1; for (int i = 0; i < n; i++) { if ((m) / ans < a[i] || ans * a[i] > m) { Console.WriteLine(-1); Console.Out.Flush(); return; } ans *= a[i]; } Console.WriteLine(ans); Console.Out.Flush(); } } }
[["-", 0, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["-", 0, 200, 0, 212, 0, 204, 206, 207, 0, 70], ["-", 0, 212, 0, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 200, 0, 212, 0, 204, 206, 207, 0, 73], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 18], ["+", 0, 57, 15, 16, 31, 16, 12, 204, 205, 22], ["+", 15, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["+", 31, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 17, 48], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22]]
8
242
18
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(); long[] a = sc.LongArray(); if (a.Contains(0)) { Console.WriteLine(0); return; } long answer = 1; for (int i = 0; i < n; i++) { answer *= a[i]; if (answer < 0 || answer > 1000000000000000000) { answer = -1; break; } } 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(); long[] a = sc.LongArray(); if (a.Contains(0)) { Console.WriteLine(0); return; } long answer = 1; for (int i = 0; i < n; i++) { try { checked { answer *= a[i]; if (answer > 1000000000000000000) { Console.Write(-1); return; } } } catch (OverflowException) { Console.Write(-1); return; } } 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(); } }
[["+", 8, 196, 0, 7, 8, 196, 0, 246, 0, 247], ["+", 0, 7, 8, 196, 0, 246, 8, 196, 0, 45], ["+", 8, 196, 0, 246, 8, 196, 0, 287, 0, 292], ["+", 0, 246, 8, 196, 0, 287, 0, 196, 0, 45], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 18], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 106], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 0, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 0, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 287, 0, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 246, 8, 196, 0, 287, 0, 196, 0, 46], ["+", 0, 7, 8, 196, 0, 246, 8, 196, 0, 46], ["+", 0, 7, 8, 196, 0, 246, 0, 248, 0, 249], ["+", 8, 196, 0, 246, 0, 248, 0, 300, 0, 24], ["+", 8, 196, 0, 246, 0, 248, 0, 300, 39, 22], ["+", 8, 196, 0, 246, 0, 248, 0, 300, 0, 25], ["+", 8, 196, 0, 246, 0, 248, 8, 196, 0, 45], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 246, 0, 248, 8, 196, 0, 1, 0, 35], ["+", 0, 246, 0, 248, 8, 196, 0, 37, 0, 38]]
8
428
35
// // ABC169B // URL : https://atcoder.jp/contests/abc169/tasks/abc169_b // using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Security.Cryptography.X509Certificates; namespace AtCoder { class ABC169B { public static readonly long MOD_CONST = 1000000007; //(long)Math.Pow(10, 9) + 7; static void Main(string[] args) { //出力高速化 var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } public static void Solve() { ulong C = (ulong)Math.Pow(10, 18); long n = long.Parse(Console.ReadLine()); ulong[] inputLongArray = Console.ReadLine() .Split(' ') .Select(_inputStr => ulong.Parse(_inputStr)) .ToArray(); foreach (var x in inputLongArray) { if (x == 0) { Console.WriteLine("0"); return; } } ulong ans = 1; foreach (var x in inputLongArray) { bool over = false; if (x > C || ans > C) { over = true; } else if ((ans * x) > C || ans * x < 0) { over = true; } if (over == true) { Console.WriteLine("-1"); return; } ans *= x; } Console.WriteLine(ans); } //--------------------------------------------------------------------------------- #region MyLib /// <summary> /// グラフ系 /// </summary> public class Node { public Node(long val) { this.Value = val; this.Children = new List<Node>(); } public Node(long val, List<Node> children) { this.Value = val; this.Children = children; } public long Value { get; set; } public List<Node> Children { get; set; } } /// <summary> /// Clamping /// </summary> /// <typeparam name="T">比較型</typeparam> /// <param name="x">clampしたい値</param> /// <param name="min">最小値</param> /// <param name="max">最大値</param> /// <returns>clamp済みの値</returns> public static T Clamp<T>(T x, T min, T max) where T : IComparable<T> { if (x.CompareTo(min) < 0) { return min; } else if (x.CompareTo(max) > 0) { return max; } else return x; // return Math.Max(Math.Min(x, max), min); } /// <summary> /// 指定された底log_baseでの, 対数を計算 /// </summary> /// <param name="x"></param> /// <param name="log_base">指定の底</param> /// <returns></returns> public static double LogBase(double x, double log_base) { // log_b(N) = log_a(N) / log_a(B)より return Math.Log(x) / Math.Log(log_base); } /// <summary> /// 初項a, 公差d, 項数nの数列の和 /// </summary> /// <param name="n">求めたいところ</param> /// <returns>初項からxまで足した値</returns> static long SumSeries(long a, long d, long n) { return (2 * a + (n - 1) * d) * n / 2; } /// <summary> /// 累積和の配列を計算する /// Sum[ a[0], a[i] )がs[i+1]に入っている /// s[0] : 0 //一切和を取らない場合 /// s[1] : ls[0] //a[0] + s[0] = a[0] /// s[2] : ls[1] + s[1] //a[1] + a[0] /// ... /// s[N] : ls[N-1] + s[N-1] //a[N-1] + ... + a[0] /// s[N+1]: ls[N] + s[N] //a[N] + ... + a[0] /// /// 例: [1, 7)の和(a[1] + ... + a[6]) /// s[1] = a[0] //[0, 1) /// s[7] = a[0] + a[1] + ... + a[6] //[0, 7) /// よってs[7] - s[1]); /// </summary> /// <param name="ls">計算したい配列</param> /// <returns>累積和配列</returns> static List<long> AggregateSumList(List<long> a) { var s = new List<long>(a.Count + 1); if (a.Count == 0) { return s; } s.Add(0); // s[0] = 0 for (int i = 0; i < a.Count; ++i) { s.Add(a[i] + s[i]); } return s; } /// <summary> /// 与えられた数が素数かどうかを計算する /// </summary> /// <param name="num">対象数</param> /// <returns>true:素数, false:素数ではない(合成数)</returns> 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 = Math.Sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) { return false; } } return true; } /// <summary> /// 順列mPnを計算する /// </summary> /// <param name="m"></param> /// <param name="n"></param> /// <returns></returns> public static long Permutation(long m, long n) { long ret = 1; for (var i = 0; i < n; ++i) { ret *= m - i; } return ret; } /// <summary> /// 組み合わせmCnを計算する /// </summary> /// <param name="m"></param> /// <param name="n"></param> /// <returns></returns> public static long Combination(long m, long n) { if (m == n || n == 0) { return 1; } long ans = 1; for (var i = 1; i <= n; ++i) { ans = ans * (m - i + 1) / i; } return ans; } static long Gcd(long m, long n) { if (n == 0) return m; return Gcd(n, m % n); } static long Lcm(long m, long n) { var gcd = Gcd(m, n); // return (m * n) / gcd; return m / gcd * n; //桁あふれ対策 } #endregion MyLib } }
// // ABC169B // URL : https://atcoder.jp/contests/abc169/tasks/abc169_b // using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Security.Cryptography.X509Certificates; namespace AtCoder { class ABC169B { public static readonly long MOD_CONST = 1000000007; //(long)Math.Pow(10, 9) + 7; static void Main(string[] args) { //出力高速化 var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } public static void Solve() { ulong C = (ulong)Math.Pow(10, 18); long n = long.Parse(Console.ReadLine()); ulong[] inputLongArray = Console.ReadLine() .Split(' ') .Select(_inputStr => ulong.Parse(_inputStr)) .ToArray(); // var inputLongArray = new ulong[100000]; // for(int i = 0; i < inputLongArray.Length; ++i) //{ // inputLongArray[i] = C; //} foreach (var x in inputLongArray) { if (x == 0) { Console.WriteLine("0"); return; } } ulong ans = 1; foreach (var x in inputLongArray) { bool over = false; #if false //掛ける前に、そもそも入力がCを超えてたら、絶対にoverflowするので if (x > C || ans > C) { over = true; } //計算結果が、Cを超えてたら or 計算した結果がoverflowしたらansを下回るはず else if (ans * x > C || ans * x < ans ){ over = true; } #else // ans * x > Cと同じ。ただし左辺でoverflowが出ない if (x > C / ans) { over = true; } #endif if (over == true) { Console.WriteLine("-1"); return; } ans *= x; } Console.WriteLine(ans); } //--------------------------------------------------------------------------------- #region MyLib /// <summary> /// グラフ系 /// </summary> public class Node { public Node(long val) { this.Value = val; this.Children = new List<Node>(); } public Node(long val, List<Node> children) { this.Value = val; this.Children = children; } public long Value { get; set; } public List<Node> Children { get; set; } } /// <summary> /// Clamping /// </summary> /// <typeparam name="T">比較型</typeparam> /// <param name="x">clampしたい値</param> /// <param name="min">最小値</param> /// <param name="max">最大値</param> /// <returns>clamp済みの値</returns> public static T Clamp<T>(T x, T min, T max) where T : IComparable<T> { if (x.CompareTo(min) < 0) { return min; } else if (x.CompareTo(max) > 0) { return max; } else return x; // return Math.Max(Math.Min(x, max), min); } /// <summary> /// 指定された底log_baseでの, 対数を計算 /// </summary> /// <param name="x"></param> /// <param name="log_base">指定の底</param> /// <returns></returns> public static double LogBase(double x, double log_base) { // log_b(N) = log_a(N) / log_a(B)より return Math.Log(x) / Math.Log(log_base); } /// <summary> /// 初項a, 公差d, 項数nの数列の和 /// </summary> /// <param name="n">求めたいところ</param> /// <returns>初項からxまで足した値</returns> static long SumSeries(long a, long d, long n) { return (2 * a + (n - 1) * d) * n / 2; } /// <summary> /// 累積和の配列を計算する /// Sum[ a[0], a[i] )がs[i+1]に入っている /// s[0] : 0 //一切和を取らない場合 /// s[1] : ls[0] //a[0] + s[0] = a[0] /// s[2] : ls[1] + s[1] //a[1] + a[0] /// ... /// s[N] : ls[N-1] + s[N-1] //a[N-1] + ... + a[0] /// s[N+1]: ls[N] + s[N] //a[N] + ... + a[0] /// /// 例: [1, 7)の和(a[1] + ... + a[6]) /// s[1] = a[0] //[0, 1) /// s[7] = a[0] + a[1] + ... + a[6] //[0, 7) /// よってs[7] - s[1]); /// </summary> /// <param name="ls">計算したい配列</param> /// <returns>累積和配列</returns> static List<long> AggregateSumList(List<long> a) { var s = new List<long>(a.Count + 1); if (a.Count == 0) { return s; } s.Add(0); // s[0] = 0 for (int i = 0; i < a.Count; ++i) { s.Add(a[i] + s[i]); } return s; } /// <summary> /// 与えられた数が素数かどうかを計算する /// </summary> /// <param name="num">対象数</param> /// <returns>true:素数, false:素数ではない(合成数)</returns> 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 = Math.Sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) { return false; } } return true; } /// <summary> /// 順列mPnを計算する /// </summary> /// <param name="m"></param> /// <param name="n"></param> /// <returns></returns> public static long Permutation(long m, long n) { long ret = 1; for (var i = 0; i < n; ++i) { ret *= m - i; } return ret; } /// <summary> /// 組み合わせmCnを計算する /// </summary> /// <param name="m"></param> /// <param name="n"></param> /// <returns></returns> public static long Combination(long m, long n) { if (m == n || n == 0) { return 1; } long ans = 1; for (var i = 1; i <= n; ++i) { ans = ans * (m - i + 1) / i; } return ans; } static long Gcd(long m, long n) { if (n == 0) return m; return Gcd(n, m % n); } static long Lcm(long m, long n) { var gcd = Gcd(m, n); // return (m * n) / gcd; return m / gcd * n; //桁あふれ対策 } #endregion MyLib } }
[["+", 8, 201, 0, 195, 8, 196, 0, 210, 8, 196], ["+", 0, 195, 8, 196, 0, 210, 8, 196, 0, 197], ["+", 8, 196, 0, 210, 8, 196, 0, 197, 0, 198], ["+", 0, 210, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 199, 0, 200], ["+", 0, 197, 0, 198, 39, 199, 0, 200, 0, 301], ["+", 0, 198, 39, 199, 0, 200, 0, 301, 0, 211], ["+", 39, 199, 0, 200, 0, 301, 0, 211, 0, 169], ["+", 0, 200, 0, 301, 0, 211, 0, 169, 0, 57], ["+", 0, 301, 0, 211, 0, 169, 0, 57, 15, 16], ["+", 0, 211, 0, 169, 0, 57, 15, 16, 31, 16], ["+", 0, 169, 0, 57, 15, 16, 31, 16, 12, 16], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 64, 196], ["+", 15, 16, 31, 16, 12, 16, 64, 196, 0, 1], ["+", 31, 16, 12, 16, 64, 196, 0, 1, 0, 169], ["+", 12, 16, 64, 196, 0, 1, 0, 169, 75, 57], ["+", 64, 196, 0, 1, 0, 169, 75, 57, 15, 16], ["+", 0, 1, 0, 169, 75, 57, 15, 16, 64, 196], ["+", 0, 169, 75, 57, 15, 16, 64, 196, 0, 302], ["+", 75, 57, 15, 16, 64, 196, 0, 302, 0, 169], ["+", 15, 16, 64, 196, 0, 302, 0, 169, 0, 57], ["+", 64, 196, 0, 302, 0, 169, 0, 57, 15, 16], ["+", 0, 302, 0, 169, 0, 57, 15, 16, 31, 22], ["+", 0, 169, 0, 57, 15, 16, 31, 22, 12, 16], ["+", 0, 57, 15, 16, 31, 22, 12, 16, 64, 196], ["+", 15, 16, 31, 22, 12, 16, 64, 196, 0, 1], ["+", 31, 22, 12, 16, 64, 196, 0, 1, 0, 303], ["+", 12, 16, 64, 196, 0, 1, 0, 303, 0, 57], ["+", 64, 196, 0, 1, 0, 303, 0, 57, 15, 16], ["+", 0, 1, 0, 303, 0, 57, 15, 16, 31, 22], ["+", 0, 303, 0, 57, 15, 16, 31, 22, 12, 211], ["+", 0, 57, 15, 16, 31, 22, 12, 211, 64, 196], ["+", 15, 16, 31, 22, 12, 211, 64, 196, 0, 1], ["+", 31, 22, 12, 211, 64, 196, 0, 1, 0, 37], ["+", 12, 211, 64, 196, 0, 1, 0, 37, 0, 1], ["+", 64, 196, 0, 1, 0, 37, 0, 1, 0, 11], ["+", 0, 1, 0, 37, 0, 1, 0, 11, 31, 22], ["+", 0, 37, 0, 1, 0, 11, 31, 22, 0, 202], ["+", 0, 1, 0, 11, 31, 22, 0, 202, 12, 22], ["+", 8, 196, 0, 210, 8, 196, 0, 301, 0, 121], ["+", 0, 210, 8, 196, 0, 301, 0, 211, 0, 147], ["-", 0, 210, 8, 196, 0, 57, 75, 57, 0, 24], ["-", 75, 57, 15, 16, 31, 16, 31, 23, 0, 25], ["-", 0, 57, 75, 57, 15, 16, 12, 16, 12, 203], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 12, 22], ["+", 8, 196, 0, 210, 8, 196, 0, 302, 0, 95], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 24], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 85], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 25], ["+", 0, 210, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 211, 0, 146], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 210, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 210, 8, 196, 0, 303]]
8
902
25
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using static Input; using static Util; class Program { static int N; static long[] A; static void INPUT() { N = NextInt(); A = LineLong(); } static void OUT() { var ans = 1L; var max = (long)Math.Pow(10, 18); foreach (var a in A.OrderBy(__ => __).ToArray()) { if (a > max / ans) { ans = -1; break; } ans *= a; } Console.WriteLine(ans); } static void Main(string[] args) { #if DEBUG // TESTINPUT(); INPUT(); #else INPUT(); #endif OUT(); } static void TESTINPUT() {} } public class Input { public const long MOD = 1000000007; public const int INF = 1000000007; private static Queue<string> q = new Queue<string>(); private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); } public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); } public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); } public static string NextString() { Confirm(); return q.Dequeue(); } public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); } public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); } public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } } class Util {}
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using static Input; using static Util; class Program { static int N; static long[] A; static void INPUT() { N = NextInt(); A = LineLong(); } static void OUT() { var ans = 1L; var max = (long)Math.Pow(10, 18); foreach (var a in A.OrderBy(__ => __).ToArray()) { if (a == 0) { ans = 0; break; } if (a > max / ans) { ans = -1; break; } ans *= a; } Console.WriteLine(ans); } static void Main(string[] args) { #if DEBUG // TESTINPUT(); INPUT(); #else INPUT(); #endif OUT(); } static void TESTINPUT() {} } public class Input { public const long MOD = 1000000007; public const int INF = 1000000007; private static Queue<string> q = new Queue<string>(); private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); } public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); } public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); } public static string NextString() { Confirm(); return q.Dequeue(); } public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); } public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); } public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } } class Util {}
[["+", 0, 210, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 25], ["+", 0, 210, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 35], ["+", 0, 210, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 24], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 31, 22]]
8
490
14
using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); long[] a = Console.ReadLine() .Split(" ") .Select(x => long.Parse(x)) .OrderByDescending(x => x) .ToArray(); long res = 1; try { checked { for (int i = 0; i < a.Length; i++) { res *= a[i]; if (res > 1000000000000000000) { Console.WriteLine("-1"); Environment.Exit(0); } } } } catch (OverflowException ex) { Console.WriteLine("-1"); Environment.Exit(0); } Console.WriteLine(res); } } }
using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); long[] a = Console.ReadLine() .Split(" ") .Select(x => long.Parse(x)) .OrderByDescending(x => x) .ToArray(); long res = 1; if (a.Contains(0)) { Console.WriteLine("0"); Environment.Exit(0); } try { checked { for (int i = 0; i < a.Length; i++) { res *= a[i]; if (res > 1000000000000000000) { Console.WriteLine("-1"); Environment.Exit(0); } } } } catch (OverflowException ex) { Console.WriteLine("-1"); Environment.Exit(0); } Console.WriteLine(res); } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 57, 15, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 57, 15, 213, 3, 4, 0, 24], ["+", 0, 57, 15, 213, 3, 4, 0, 28, 0, 203], ["+", 8, 196, 0, 57, 15, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
184
27