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; class Progaram { static void Main(string[] args) { var l = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); l[0] = l[0] % l[1]; Console.WriteLine(l.Min()); } }
using System; using System.Collections.Generic; using System.Linq; class Progaram { static void Main(string[] args) { var l = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); l[0] = l[0] % l[1]; l[1] = l[1] - l[0]; Console.WriteLine(l.Min()); } }
[["+", 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, 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, 16, 31, 204, 205, 22], ["+", 0, 11, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 11, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 0, 1, 0, 11, 12, 16, 12, 204, 205, 22], ["+", 0, 11, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 11, 12, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
88
15
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace lean { class Program { static void Main() { // long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray(); string S = Console.ReadLine(); int N = S.Length; if (S.Substring(0, (N - 1) / 2) == S.Substring((N + 3) / 2, N)) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace lean { class Program { static void Main() { // long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray(); string S = Console.ReadLine(); int N = S.Length; if (S.Substring(0, (N - 1) / 2) == S.Substring((N + 3) / 2 - 1, (N - 1) / 2)) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
[["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 24], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 25], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 85]]
8
114
8
using System; using System.Linq; class Program { static void Main(string[] args) { var inputs = Console.ReadLine(); var length = inputs.Length; var front = inputs.Take((length - 1) / 2).ToArray(); var back = inputs.Skip(length + 1 / 2).Take((length - 1) / 2); bool isKaibun1 = front.SequenceEqual(front.Reverse()); bool isKaibun2 = back.SequenceEqual(back.Reverse()); if (isKaibun1 && isKaibun2) Console.WriteLine("Yes"); else Console.WriteLine("No"); } }
using System; using System.Linq; class Program { static void Main(string[] args) { var inputs = Console.ReadLine(); var length = inputs.Length; var front = inputs.Take((length - 1) / 2); var back = inputs.Reverse().Take((length - 1) / 2); bool isKaibun = inputs.SequenceEqual(inputs.Reverse()); bool isKaibun1 = front.SequenceEqual(front.Reverse()); bool isKaibun2 = back.SequenceEqual(back.Reverse()); if (isKaibun && isKaibun1 && isKaibun2) Console.WriteLine("Yes"); else Console.WriteLine("No"); } }
[["-", 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, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["-", 205, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 205, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 3, 4, 0, 28, 0, 16, 12, 16, 31, 203], ["-", 3, 4, 0, 28, 0, 16, 12, 16, 17, 85], ["-", 3, 4, 0, 28, 0, 16, 12, 16, 12, 203], ["+", 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], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 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], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 98]]
8
137
27
using System; using System.Linq; using System.Text.RegularExpressions; using System.Collections.Generic; using static System.Console; using static Program.Input; using static Program.MyMath; using static Program.Const; namespace Program { static class Const { public static string alp = "abcdefghijklmnopqrstuvwxyz"; public static string Alp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; public const long MOD = 1000000007; public static int INF = int.MaxValue; public static long INFL = long.MaxValue; } public static class Program { public static void Main() { var s = ReadLine(); var n = s.Length; WriteLine(s.isKAIBUN() && s.Substring(0, (n - 1) / 2).isKAIBUN() && s.Substring((n + 3) / 2 - 1).isKAIBUN() ? "Yes" : "No"); // ReadKey(); } public static bool isKAIBUN(this string s) { if (s.Length == 1) return true; return s.Substring(0, (s.Length - 1) / 2) == new string(s.Substring((s.Length / 2) + 1).Reverse().ToArray()); } } static class Input { public static void InputLine(out int a, out int b) { var input = ScanIntArray(); a = input[0]; b = input[1]; } public static void InputLine(out int a, out int b, out int c) { var input = ScanIntArray(); a = input[0]; b = input[1]; c = input[2]; } public static void InputLine(out int a, out int b, out int c, out int d) { var input = ScanIntArray(); a = input[0]; b = input[1]; c = input[2]; d = input[3]; } public static void InputLine(out long a, out long b) { var input = ScanLongArray(); a = input[0]; b = input[1]; } public static void InputLine(out long a, out long b, out long c) { var input = ScanLongArray(); a = input[0]; b = input[1]; c = input[2]; } public static void InputLine(out long a, out long b, out long c, out long d) { var input = ScanLongArray(); a = input[0]; b = input[1]; c = input[2]; d = input[3]; } public static void InputLine(out string a, out string b) { var input = ScanStrArray(); a = input[0]; b = input[1]; } public static int ScanInt() { return int.Parse(ReadLine()); } static public uint ScanUint() { return uint.Parse(ReadLine()); } static public double ScanDouble() { return double.Parse(ReadLine()); } static public long ScanLong() { return long.Parse(ReadLine()); } static public ulong ScanUlong() { return ulong.Parse(ReadLine()); } static public int[] ScanIntArray() { return ReadLine().Split().Select(x => int.Parse(x)).ToArray(); } static public uint[] ScanUintArray() { return ReadLine().Split().Select(x => uint.Parse(x)).ToArray(); } static public double[] ScanDoubleArray() { return ReadLine().Split().Select(x => double.Parse(x)).ToArray(); } static public long[] ScanLongArray() { return ReadLine().Split().Select(x => long.Parse(x)).ToArray(); } static public ulong[] ScanUlongArray() { return ReadLine().Split().Select(x => ulong.Parse(x)).ToArray(); } static public string ScanStr() { return ReadLine(); } static public string[] ScanStrArray() { return ScanStr().Split(); } static public string RegaxReplace(this string arg1, string pattern, string replacement) { return Regex.Replace(arg1, pattern, replacement); } } static class MyMath { static public int CountBit(this long a) { if (a == 0) return 0; int c = 1; for (; a > 1; a /= 2) if (a % 2 == 1) c++; return c; } static public int Floor2(this int a) { int N = 1; while (N < a) N *= 2; return N / 2; } static public long Floor2(this long a) { long N = 1; while (N < a) N *= 2; return N / 2; } static public int Ceiling2(this int a) { int N = 1; while (N < a) N *= 2; return N; } static public long Ceiling2(this long a) { long N = 1; while (N < a) N *= 2; return N; } static public long[] CumSum(this long[] a) { var res = new long[a.Length]; long s = 0; for (int i = 0; i < a.Length; i++) res[i] = (s += a[i]); return res; } static public IEnumerable<int> PrimeFactors(this int n) { int tmp = n; for (int i = 2; i * i <= n; i++) while (tmp % i == 0) { tmp /= i; yield return i; } if (tmp != 1) yield return tmp; } static public IEnumerable<long> PrimeFactors(this long n) { var tmp = n; for (long i = 2; i * i <= n; i++) while (tmp % i == 0) { tmp /= i; yield return i; } if (tmp != 1) yield return tmp; } static public int Digit(this int n, int d) { if (d < 0) return 0; return (n % (int)Math.Pow(10, d + 1)) / (int)Math.Pow(10, d); } static public int Length(this int n) { if (n < 0) return 0; return (int)Math.Log10(n) + 1; } static public int Top(this int n) { return n.Digit(n.Length() - 1); } public static bool isPrime(this int p) { if (p <= 1) return false; for (int i = 2; i * i <= p; i++) if (p % i == 0) return false; return true; } public static bool isPrime(this long p) { if (p <= 1) return false; for (long i = 2; i * i <= p; i++) if (p % i == 0) return false; return true; } public static int GCD(int a, int b) { Func<int, int, int> gcd = null; gcd = (x, y) => y == 0 ? x : gcd(y, x % y); return a > b ? gcd(a, b) : gcd(b, a); } public static long GCD(long a, long b) { Func<long, long, long> gcd = null; gcd = (x, y) => y == 0 ? x : gcd(y, x % y); return a > b ? gcd(a, b) : gcd(b, a); } public static ulong extGCD(ulong a, ulong b, ref ulong x, ref ulong y) { if (b == 0) { x = 1; y = 0; return a; } var d = extGCD(b, a % b, ref y, ref x); y -= a / b * x; return d; } public static int LCM(int a, int b) { return a * b / GCD(a, b); } public static long LCM(long a, long b) { return a * b / GCD(a, b); } public static long Inv(this long a, long m = MOD) { long b = m, u = 1, v = 0; while (b != 0) { long t = a / b; a -= t * b; swap(ref a, ref b); u -= t * v; swap(ref u, ref v); } u %= m; if (u < 0) u += m; return u; } private static void swap(ref long a, ref long b) { var t = a; a = b; b = t; } public static long ModPow(long a, long n, long m = MOD) { long res = 1; while (n > 0) { if (n % 2 == 1) res = (res * a) % m; a = (a * a) % m; n >>= 1; } return res; } } static class MyLinq { public static void Sort(this string[] array) { Array.Sort(array, StringComparer.OrdinalIgnoreCase); } public static void StringSort(this List<string> list) { list.Sort(StringComparer.OrdinalIgnoreCase); } public static string Join<T>(this IEnumerable<T> source, string separator) { return string.Join(separator, source); } public static IEnumerable<TItem> Distinct<TItem, TKey>(this IEnumerable<TItem> source, Func<TItem, TKey> keySelector) { if (source == null) throw new ArgumentNullException(nameof(source)); if (keySelector == null) throw new ArgumentNullException(nameof(keySelector)); var set = new HashSet<TKey>(); foreach (var item in source) if (set.Add(keySelector(item))) yield return item; } } }
using System; using System.Linq; using System.Text.RegularExpressions; using System.Collections.Generic; using static System.Console; using static Program.Input; using static Program.MyMath; using static Program.Const; namespace Program { static class Const { public static string alp = "abcdefghijklmnopqrstuvwxyz"; public static string Alp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; public const long MOD = 1000000007; public static int INF = int.MaxValue; public static long INFL = long.MaxValue; } public static class Program { public static void Main() { var s = ReadLine(); var n = s.Length; WriteLine(s.isKAIBUN() && s.Substring(0, (n - 1) / 2).isKAIBUN() && s.Substring((n + 3) / 2 - 1).isKAIBUN() ? "Yes" : "No"); // ReadKey(); } public static bool isKAIBUN(this string s) { if (s.Length == 1) return true; if (s.Length == 2) return s[0] == s[1]; return s.Substring(0, (s.Length - 1) / 2) == new string(s.Substring((s.Length / 2) + 1).Reverse().ToArray()); } } static class Input { public static void InputLine(out int a, out int b) { var input = ScanIntArray(); a = input[0]; b = input[1]; } public static void InputLine(out int a, out int b, out int c) { var input = ScanIntArray(); a = input[0]; b = input[1]; c = input[2]; } public static void InputLine(out int a, out int b, out int c, out int d) { var input = ScanIntArray(); a = input[0]; b = input[1]; c = input[2]; d = input[3]; } public static void InputLine(out long a, out long b) { var input = ScanLongArray(); a = input[0]; b = input[1]; } public static void InputLine(out long a, out long b, out long c) { var input = ScanLongArray(); a = input[0]; b = input[1]; c = input[2]; } public static void InputLine(out long a, out long b, out long c, out long d) { var input = ScanLongArray(); a = input[0]; b = input[1]; c = input[2]; d = input[3]; } public static void InputLine(out string a, out string b) { var input = ScanStrArray(); a = input[0]; b = input[1]; } public static int ScanInt() { return int.Parse(ReadLine()); } static public uint ScanUint() { return uint.Parse(ReadLine()); } static public double ScanDouble() { return double.Parse(ReadLine()); } static public long ScanLong() { return long.Parse(ReadLine()); } static public ulong ScanUlong() { return ulong.Parse(ReadLine()); } static public int[] ScanIntArray() { return ReadLine().Split().Select(x => int.Parse(x)).ToArray(); } static public uint[] ScanUintArray() { return ReadLine().Split().Select(x => uint.Parse(x)).ToArray(); } static public double[] ScanDoubleArray() { return ReadLine().Split().Select(x => double.Parse(x)).ToArray(); } static public long[] ScanLongArray() { return ReadLine().Split().Select(x => long.Parse(x)).ToArray(); } static public ulong[] ScanUlongArray() { return ReadLine().Split().Select(x => ulong.Parse(x)).ToArray(); } static public string ScanStr() { return ReadLine(); } static public string[] ScanStrArray() { return ScanStr().Split(); } static public string RegaxReplace(this string arg1, string pattern, string replacement) { return Regex.Replace(arg1, pattern, replacement); } } static class MyMath { static public int CountBit(this long a) { if (a == 0) return 0; int c = 1; for (; a > 1; a /= 2) if (a % 2 == 1) c++; return c; } static public int Floor2(this int a) { int N = 1; while (N < a) N *= 2; return N / 2; } static public long Floor2(this long a) { long N = 1; while (N < a) N *= 2; return N / 2; } static public int Ceiling2(this int a) { int N = 1; while (N < a) N *= 2; return N; } static public long Ceiling2(this long a) { long N = 1; while (N < a) N *= 2; return N; } static public long[] CumSum(this long[] a) { var res = new long[a.Length]; long s = 0; for (int i = 0; i < a.Length; i++) res[i] = (s += a[i]); return res; } static public IEnumerable<int> PrimeFactors(this int n) { int tmp = n; for (int i = 2; i * i <= n; i++) while (tmp % i == 0) { tmp /= i; yield return i; } if (tmp != 1) yield return tmp; } static public IEnumerable<long> PrimeFactors(this long n) { var tmp = n; for (long i = 2; i * i <= n; i++) while (tmp % i == 0) { tmp /= i; yield return i; } if (tmp != 1) yield return tmp; } static public int Digit(this int n, int d) { if (d < 0) return 0; return (n % (int)Math.Pow(10, d + 1)) / (int)Math.Pow(10, d); } static public int Length(this int n) { if (n < 0) return 0; return (int)Math.Log10(n) + 1; } static public int Top(this int n) { return n.Digit(n.Length() - 1); } public static bool isPrime(this int p) { if (p <= 1) return false; for (int i = 2; i * i <= p; i++) if (p % i == 0) return false; return true; } public static bool isPrime(this long p) { if (p <= 1) return false; for (long i = 2; i * i <= p; i++) if (p % i == 0) return false; return true; } public static int GCD(int a, int b) { Func<int, int, int> gcd = null; gcd = (x, y) => y == 0 ? x : gcd(y, x % y); return a > b ? gcd(a, b) : gcd(b, a); } public static long GCD(long a, long b) { Func<long, long, long> gcd = null; gcd = (x, y) => y == 0 ? x : gcd(y, x % y); return a > b ? gcd(a, b) : gcd(b, a); } public static ulong extGCD(ulong a, ulong b, ref ulong x, ref ulong y) { if (b == 0) { x = 1; y = 0; return a; } var d = extGCD(b, a % b, ref y, ref x); y -= a / b * x; return d; } public static int LCM(int a, int b) { return a * b / GCD(a, b); } public static long LCM(long a, long b) { return a * b / GCD(a, b); } public static long Inv(this long a, long m = MOD) { long b = m, u = 1, v = 0; while (b != 0) { long t = a / b; a -= t * b; swap(ref a, ref b); u -= t * v; swap(ref u, ref v); } u %= m; if (u < 0) u += m; return u; } private static void swap(ref long a, ref long b) { var t = a; a = b; b = t; } public static long ModPow(long a, long n, long m = MOD) { long res = 1; while (n > 0) { if (n % 2 == 1) res = (res * a) % m; a = (a * a) % m; n >>= 1; } return res; } } static class MyLinq { public static void Sort(this string[] array) { Array.Sort(array, StringComparer.OrdinalIgnoreCase); } public static void StringSort(this List<string> list) { list.Sort(StringComparer.OrdinalIgnoreCase); } public static string Join<T>(this IEnumerable<T> source, string separator) { return string.Join(separator, source); } public static IEnumerable<TItem> Distinct<TItem, TKey>(this IEnumerable<TItem> source, Func<TItem, TKey> keySelector) { if (source == null) throw new ArgumentNullException(nameof(source)); if (keySelector == null) throw new ArgumentNullException(nameof(keySelector)); var set = new HashSet<TKey>(); foreach (var item in source) if (set.Add(keySelector(item))) yield return item; } } }
[["+", 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, 214, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 141, 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, 57, 64, 37, 0, 16, 31, 204, 205, 22], ["+", 64, 37, 0, 16, 31, 204, 206, 207, 0, 70], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 64, 37, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 64, 37, 0, 16, 17, 60], ["+", 0, 57, 64, 37, 0, 16, 12, 204, 205, 22], ["+", 64, 37, 0, 16, 12, 204, 206, 207, 0, 70], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 64, 37, 0, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 37, 0, 38]]
8
2,091
19
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.AtCoder_Begginer_Contest_159 { class B { static void Main(string[] args) { string s = Console.ReadLine(); int halfLen = (s.Length - 2) / 2; string s1 = s.Substring(0, halfLen + 1); // Console.WriteLine(s1); // Console.WriteLine(new string(s1.Reverse().ToArray())); if (!s1.Equals(new string(s1.Reverse().ToArray()))) { Console.WriteLine("No"); // Console.ReadKey(); return; } string s2 = s.Substring(s.Length - halfLen - 1, halfLen + 1); // Console.WriteLine(s2); // Console.WriteLine(new string(s2.Reverse().ToArray())); if (!s2.Equals(new string(s2.Reverse().ToArray()))) { Console.WriteLine("No"); // Console.ReadKey(); return; } Console.WriteLine("Yes"); // Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.AtCoder_Begginer_Contest_159 { class B { static void Main(string[] args) { string s = Console.ReadLine(); if (!s.Equals(new string(s.Reverse().ToArray()))) { Console.WriteLine("No"); return; } int halfLen = (s.Length - 2) / 2; string s1 = s.Substring(0, halfLen + 1); // Console.WriteLine(s1); // Console.WriteLine(new string(s1.Reverse().ToArray())); if (!s1.Equals(new string(s1.Reverse().ToArray()))) { Console.WriteLine("No"); // Console.ReadKey(); return; } string s2 = s.Substring(s.Length - halfLen - 1, halfLen + 1); // Console.WriteLine(s2); // Console.WriteLine(new string(s2.Reverse().ToArray())); if (!s2.Equals(new string(s2.Reverse().ToArray()))) { Console.WriteLine("No"); // Console.ReadKey(); return; } Console.WriteLine("Yes"); // 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, 241, 0, 111], ["+", 0, 57, 15, 241, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 15, 241, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 15, 241, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 15, 241, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 230, 0, 228], ["+", 0, 213, 3, 4, 0, 28, 0, 230, 39, 199], ["+", 3, 4, 0, 28, 0, 230, 3, 4, 0, 24], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["+", 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, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 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], ["+", 3, 4, 0, 28, 0, 230, 3, 4, 0, 25], ["+", 0, 57, 15, 241, 0, 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], ["+", 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
190
35
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp15 { class Class162 { static void Main() { string S = Console.ReadLine(); int N = S.Length; string s1 = S.Substring(0, (N - 1) / 2); string s2 = S.Substring((N + 1) / 2); // Console.WriteLine($"{s1} {s2}"); if (s1 == s2) { string a1 = "", a2 = "", b1 = "", b2 = ""; if (s1.Length % 2 == 1) { a1 = s1.Substring(0, (s1.Length - 1) / 2); a2 = s1.Substring((s1.Length + 1) / 2); b1 = s2.Substring(0, (s2.Length - 1) / 2); b2 = s2.Substring((s2.Length + 1) / 2); } else { a1 = s1.Substring(0, (s1.Length) / 2); a2 = new string(s1.Substring((s1.Length + 1) / 2).Reverse().ToArray()); b1 = s2.Substring(0, (s2.Length) / 2); b2 = new string(s2.Substring((s2.Length + 1) / 2).Reverse().ToArray()); } // Console.WriteLine($"{a1} {a2} {b1} {b2}"); if (a1 == a2 && b1 == b2) { Console.WriteLine("Yes"); return; } } Console.WriteLine("No"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp15 { class Class162 { static void Main() { string S = Console.ReadLine(); int N = S.Length; string s1 = S.Substring(0, (N - 1) / 2); string s2 = S.Substring((N + 1) / 2); // Console.WriteLine($"{s1} {s2}"); if (s1 == s2) { string a1 = "", a2 = "", b1 = "", b2 = ""; if (s1.Length % 2 == 1) { a1 = s1.Substring(0, (s1.Length - 1) / 2); a2 = new string(s1.Substring((s1.Length + 1) / 2).Reverse().ToArray()); b1 = s2.Substring(0, (s2.Length - 1) / 2); b2 = new string(s2.Substring((s2.Length + 1) / 2).Reverse().ToArray()); } else { a1 = s1.Substring(0, (s1.Length) / 2); a2 = new string(s1.Substring((s1.Length + 1) / 2).Reverse().ToArray()); b1 = s2.Substring(0, (s2.Length) / 2); b2 = new string(s2.Substring((s2.Length + 1) / 2).Reverse().ToArray()); } // Console.WriteLine($"{a1} {a2} {b1} {b2}"); if (a1 == a2 && b1 == b2) { Console.WriteLine("Yes"); return; } } Console.WriteLine("No"); } } }
[["+", 64, 196, 0, 1, 0, 11, 12, 230, 0, 228], ["+", 64, 196, 0, 1, 0, 11, 12, 230, 39, 199], ["+", 0, 1, 0, 11, 12, 230, 3, 4, 0, 24], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 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, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
334
24
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { class _159b { static void Main() { string s = Console.ReadLine(); string rev = s.Reverse() + ""; string pre = s.Substring(0, (s.Length - 1) / 2); string prerev = pre.Reverse() + ""; string post = s.Substring((s.Length + 3) / 2 - 1, (s.Length - 1) / 2); string postrev = post.Reverse() + ""; if (s.CompareTo(rev) == 0 && pre.CompareTo(prerev) == 0 && post.CompareTo(postrev) == 0) { 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 { class _159b { static void Main() { string s = Console.ReadLine(); string rev = string.Join("", s.Reverse()); string pre = s.Substring(0, (s.Length - 1) / 2); string prerev = string.Join("", pre.Reverse()); string post = s.Substring((s.Length + 3) / 2 - 1, (s.Length - 1) / 2); string postrev = string.Join("", post.Reverse()); if (s.CompareTo(rev) == 0 && pre.CompareTo(prerev) == 0 && post.CompareTo(postrev) == 0) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
[["+", 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, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["-", 0, 200, 0, 212, 0, 16, 12, 5, 0, 62], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25]]
8
189
33
using System; using System.Linq; namespace oasobi { static class MainClass { public static void Main() { string S = Console.ReadLine(); int N = S.Length; string mae = S.Substring(0, (N - 1) / 2); string usiro = S.Substring((N + 1) / 2); var reva = new string(mae.Reverse().ToArray()); var revb = new string(usiro.Reverse().ToArray()); if (reva.Equals(mae) && revb.Equals(usiro)) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
using System; using System.Linq; namespace oasobi { static class MainClass { public static void Main() { string S = Console.ReadLine(); int N = S.Length; string mae = S.Substring(0, (N - 1) / 2); string usiro = S.Substring((N + 1) / 2); var reva = new string(mae.Reverse().ToArray()); var revb = new string(usiro.Reverse().ToArray()); if (reva.Equals(mae) && revb.Equals(usiro) && revb.Equals(mae)) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 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], ["+", 15, 16, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25]]
8
148
7
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { class Program { static void Main(string[] args) { var s = Console.ReadLine(); if (!IsPalindrome(s)) { Console.WriteLine("No"); return; } if (!IsPalindrome(s.Substring(0, (s.Length - 1) / 2))) { Console.WriteLine("No"); return; } if (!IsPalindrome(s.Substring((s.Length + 1) / 2, (s.Length - 1) / 2))) { Console.WriteLine("No"); return; } Console.WriteLine("Yes"); } private static bool IsPalindrome(string s) { for (int i = 0; i < (s.Length - 1) / 2; i++) { if (s[i] != s[s.Length - i - 1]) { return false; } } return true; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { class Program { static void Main(string[] args) { var s = Console.ReadLine(); if (!IsPalindrome(s)) { Console.WriteLine("No"); return; } if (!IsPalindrome(s.Substring(0, (s.Length - 1) / 2))) { Console.WriteLine("No"); return; } if (!IsPalindrome( s.Substring((s.Length + 3) / 2 - 1, (s.Length - 1) / 2))) { Console.WriteLine("No"); return; } Console.WriteLine("Yes"); } private static bool IsPalindrome(string s) { for (int i = 0; i < s.Length / 2; i++) { if (s[i] != s[s.Length - i - 1]) { return false; } } return true; } } }
[["-", 0, 28, 0, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 16, 31, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["-", 0, 7, 15, 16, 12, 16, 31, 23, 0, 24], ["-", 15, 16, 12, 16, 31, 23, 0, 16, 17, 33], ["-", 15, 16, 12, 16, 31, 23, 0, 16, 12, 203], ["-", 0, 7, 15, 16, 12, 16, 31, 23, 0, 25]]
8
225
8
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Numerics; namespace ABC159.B { using static Util; public class Solver : SolverBase { public void Run() { var S = ReadString(); var len = S.Length / 2; // 0 to (N-1)/2-1 Dump(S.Substring(0, len)); if (!IsLooped(S.Substring(0, len))) { WriteLine("No"); return; } // (N+1)/2 to N-1 Dump(S.Substring(S.Length / 2 + 1)); if (!IsLooped(S.Substring(S.Length / 2 + 1))) { WriteLine("No"); return; } WriteLine("Yes"); } static public bool IsLooped(string s) { var len = s.Length / 2; for (int i = 0; i < len; i++) { if (s[i] != s[s.Length - 1 - i]) return false; } return true; } #if !MYHOME static void Main(string[] args) { new Solver().Run(); } #endif } public static class Util { public static int Gcd(int a, int b) { if (a < b) // 引数を入替えて自分を呼び出す return Gcd(b, a); while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } public readonly static long MOD = 1000000007; public static string DumpToString<T>(IEnumerable<T> array) where T : IFormattable { var sb = new StringBuilder(); foreach (var item in array) { sb.Append(item); sb.Append(", "); } return sb.ToString(); } public static void InitArray<T>(T[] ary, T value) { for (int i = 0; i < ary.Length; i++) { ary[i] = value; } } public static void InitDP2<T>(T[,] dp, T value) { for (int i = 0; i < dp.GetLength(0); i++) { for (int j = 0; j < dp.GetLength(1); j++) { dp[i, j] = value; } } } public static void InitDP3<T>(T[,,] dp, T value) { for (int i = 0; i < dp.GetLength(0); i++) { for (int j = 0; j < dp.GetLength(1); j++) { for (int k = 0; k < dp.GetLength(2); k++) { dp[i, j, k] = value; } } } } /// <summary>charでも対応可能なMax</summary> public static T Max<T>(T a, T b) where T : IComparable { return 0 <= a.CompareTo(b) ? a : b; } /// <summary>3要素以上に対応するMax</summary> public static T Max<T>(params T[] nums) where T : IComparable { if (nums.Length == 0) return default(T); T max = nums[0]; for (int i = 1; i < nums.Length; i++) { max = max.CompareTo(nums[i]) > 0 ? max : nums[i]; } return max; } /// <summary>charでも対応可能なMin</summary> public static T Min<T>(T a, T b) where T : IComparable { return 0 < a.CompareTo(b) ? b : a; } /// <summary>3要素以上に対応するMin</summary> public static T Min<T>(params T[] nums) where T : IComparable { if (nums.Length == 0) return default(T); T min = nums[0]; for (int i = 1; i < nums.Length; i++) { min = min.CompareTo(nums[i]) < 0 ? min : nums[i]; } return min; } /// <summary> /// ソート済み配列 ary に同じ値の要素が含まれている? /// ※ソート順は昇順/降順どちらでもよい /// </summary> public static bool HasDuplicateInSortedArray<T>(T[] ary) where T : IComparable, IComparable<T> { if (ary.Length <= 1) return false; var lastNum = ary[ary.Length - 1]; foreach (var n in ary) { if (lastNum.CompareTo(n) == 0) { return true; } else { lastNum = n; } } return false; } public static bool ReplaceIfBigger<T>(ref T r, T v) where T : IComparable { if (r.CompareTo(v) < 0) { r = v; return true; } else { return false; } } public static bool ReplaceIfSmaller<T>(ref T r, T v) where T : IComparable { if (0 < r.CompareTo(v)) { r = v; return true; } else { return false; } } /// <summary> /// dic[key]にadderを加算する。keyが存在しなかった場合はdic[key]=adder /// をセットする。 /// </summary> public static void AddTo<TKey>(this Dictionary<TKey, int> dic, TKey key, int adder) { if (dic.ContainsKey(key)) { dic[key] += adder; } else { dic[key] = adder; } } /// <summary> /// 文字列 s が chars に含まれる文字を含んでいるか? /// </summary> public static bool ContainsAny(this string s, char[] chars) { for (int j = 0; j < s.Length; j++) { if (chars.Contains(s[j])) return true; } return false; } /// <summary> /// 二分探索 /// ※条件を満たす最小のidxを返す /// ※満たすものがない場合は ary.Length を返す /// ※『aryの先頭側が条件を満たさない、末尾側が条件を満たす』という前提 /// ただし、IsOK(...)の戻り値を逆転させれば、逆でも同じことが可能。 /// </summary> /// <param name="ary">探索対象配列 ★ソート済みであること</param> /// <param name="key">探索値 /// ※これ以上の値を持つ(IsOKがtrueを返す)最小のindexを返す</param> public static int BinarySearch<T>(T[] ary, T key) where T : IComparable, IComparable<T> { int left = -1; int right = ary.Length; while (1 < right - left) { var mid = left + (right - left) / 2; if (IsOK(ary, mid, key)) { right = mid; } else { left = mid; } } // left は条件を満たさない最大の値、right // は条件を満たす最小の値になっている return right; } public static bool IsOK<T>(T[] ary, int idx, T key) where T : IComparable, IComparable<T> { // key <= ary[idx] と同じ意味 return key.CompareTo(ary[idx]) <= 0; } } public class SolverBase { virtual protected string ReadLine() => Console.ReadLine(); virtual protected string ReadString() => ReadLine(); virtual protected int ReadInt() => int.Parse(ReadLine()); virtual protected long ReadLong() => long.Parse(ReadLine()); virtual protected string[] ReadStringArray() => ReadLine().Split(' '); virtual protected char[] ReadCharArray() => ReadLine() .Split(' ') .Select<string, char>( s => s[0]) .ToArray(); virtual protected int[] ReadIntArray() => ReadLine() .Split(' ') .Select<string, int>( s => int.Parse(s)) .ToArray(); virtual protected void ReadInt2(out int a, out int b) { var ary = ReadIntArray(); a = ary[0]; b = ary[1]; } virtual protected void ReadInt3(out int a, out int b, out int c) { var ary = ReadIntArray(); a = ary[0]; b = ary[1]; c = ary[2]; } virtual protected void ReadInt4(out int a, out int b, out int c, out int d) { var ary = ReadIntArray(); a = ary[0]; b = ary[1]; c = ary[2]; d = ary[3]; } virtual protected long[] ReadLongArray() => ReadLine() .Split(' ') .Select<string, long>( s => long.Parse(s)) .ToArray(); virtual protected void ReadLong2(out long a, out long b) { var ary = ReadLongArray(); a = ary[0]; b = ary[1]; } virtual protected void ReadLong3(out long a, out long b, out long c) { var ary = ReadLongArray(); a = ary[0]; b = ary[1]; c = ary[2]; } virtual protected void ReadLong4(out long a, out long b, out long c, out long d) { var ary = ReadLongArray(); a = ary[0]; b = ary[1]; c = ary[2]; d = ary[3]; } virtual protected double[] ReadDoubleArray() => ReadLine() .Split(' ') .Select<string, double>( s => double.Parse(s)) .ToArray(); virtual protected void WriteLine(string line) => Console.WriteLine(line); virtual protected void WriteLine(double d) => Console.WriteLine($"{d:F9}"); virtual protected void WriteLine<T>(T value) where T : IFormattable => Console.WriteLine(value); virtual protected void WriteGrid(IEnumerable<IEnumerable<char>> arrayOfArray) { var sb = new StringBuilder(); foreach (var a in arrayOfArray) { foreach (var c in a) { sb.Append(c); } sb.AppendLine(); } WriteLine(sb.ToString()); } [Conditional("DEBUG")] protected void Dump(string s) => Console.WriteLine(s); [Conditional("DEBUG")] protected void Dump(char c) => Console.WriteLine(c); [Conditional("DEBUG")] protected void Dump(int x) => Console.WriteLine(x); [Conditional("DEBUG")] protected void Dump(double d) => Console.WriteLine($"{d:F9}"); [Conditional("DEBUG")] protected void Dump<T>(IEnumerable<T> array) where T : IFormattable { string s = Util.DumpToString(array); // Consoleに出力すると、UnitTestの邪魔をしないというメリットあり。 Console.WriteLine(s); //_writer.WriteLine(s); } [Conditional("DEBUG")] protected void DumpGrid(IEnumerable<IEnumerable<char>> arrayOfArray) { var sb = new StringBuilder(); foreach (var a in arrayOfArray) { foreach (var c in a) { sb.Append(c); } sb.AppendLine(); } // Consoleに出力すると、UnitTestの邪魔をしないというメリットあり。 Console.WriteLine(sb.ToString()); //_writer.WriteLine(sb.ToString()); } [Conditional("DEBUG")] protected void DumpGrid<T>(IEnumerable<IEnumerable<T>> arrayOfArray) where T : IFormattable { var sb = new StringBuilder(); foreach (var a in arrayOfArray) { sb.AppendLine(Util.DumpToString(a)); } // Consoleに出力すると、UnitTestの邪魔をしないというメリットあり。 Console.WriteLine(sb.ToString()); //_writer.WriteLine(sb.ToString()); } [Conditional("DEBUG")] protected void DumpGrid(bool[,] grid) { var sb = new StringBuilder(); for (int i = 0; i < grid.GetLength(0); i++) { for (int j = 0; j < grid.GetLength(1); j++) { sb.Append(grid[i, j] ? "x " : ". "); } sb.AppendLine(); } Console.WriteLine(sb.ToString()); } [Conditional("DEBUG")] protected void DumpGrid(char[,] grid) { var sb = new StringBuilder(); for (int i = 0; i < grid.GetLength(0); i++) { for (int j = 0; j < grid.GetLength(1); j++) { sb.Append(grid[i, j]); sb.Append(" "); } sb.AppendLine(); } Console.WriteLine(sb.ToString()); } [Conditional("DEBUG")] protected void DumpDP<T>(T[,] dp) where T : IFormattable { var sb = new StringBuilder(); for (int i = 0; i < dp.GetLength(0); i++) { for (int j = 0; j < dp.GetLength(1); j++) { sb.Append(dp[i, j]); sb.Append(", "); } sb.AppendLine(); } Console.WriteLine(sb.ToString()); } } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Numerics; namespace ABC159.B { using static Util; public class Solver : SolverBase { public void Run() { var S = ReadString(); var len = S.Length / 2; if (!IsLooped(S)) { WriteLine("No"); return; } // 0 to (N-1)/2-1 Dump(S.Substring(0, len)); if (!IsLooped(S.Substring(0, len))) { WriteLine("No"); return; } // (N+1)/2 to N-1 Dump(S.Substring(S.Length / 2 + 1)); if (!IsLooped(S.Substring(S.Length / 2 + 1))) { WriteLine("No"); return; } WriteLine("Yes"); } static public bool IsLooped(string s) { var len = s.Length / 2; for (int i = 0; i < len; i++) { if (s[i] != s[s.Length - 1 - i]) return false; } return true; } #if !MYHOME static void Main(string[] args) { new Solver().Run(); } #endif } public static class Util { public static int Gcd(int a, int b) { if (a < b) // 引数を入替えて自分を呼び出す return Gcd(b, a); while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } public readonly static long MOD = 1000000007; public static string DumpToString<T>(IEnumerable<T> array) where T : IFormattable { var sb = new StringBuilder(); foreach (var item in array) { sb.Append(item); sb.Append(", "); } return sb.ToString(); } public static void InitArray<T>(T[] ary, T value) { for (int i = 0; i < ary.Length; i++) { ary[i] = value; } } public static void InitDP2<T>(T[,] dp, T value) { for (int i = 0; i < dp.GetLength(0); i++) { for (int j = 0; j < dp.GetLength(1); j++) { dp[i, j] = value; } } } public static void InitDP3<T>(T[,,] dp, T value) { for (int i = 0; i < dp.GetLength(0); i++) { for (int j = 0; j < dp.GetLength(1); j++) { for (int k = 0; k < dp.GetLength(2); k++) { dp[i, j, k] = value; } } } } /// <summary>charでも対応可能なMax</summary> public static T Max<T>(T a, T b) where T : IComparable { return 0 <= a.CompareTo(b) ? a : b; } /// <summary>3要素以上に対応するMax</summary> public static T Max<T>(params T[] nums) where T : IComparable { if (nums.Length == 0) return default(T); T max = nums[0]; for (int i = 1; i < nums.Length; i++) { max = max.CompareTo(nums[i]) > 0 ? max : nums[i]; } return max; } /// <summary>charでも対応可能なMin</summary> public static T Min<T>(T a, T b) where T : IComparable { return 0 < a.CompareTo(b) ? b : a; } /// <summary>3要素以上に対応するMin</summary> public static T Min<T>(params T[] nums) where T : IComparable { if (nums.Length == 0) return default(T); T min = nums[0]; for (int i = 1; i < nums.Length; i++) { min = min.CompareTo(nums[i]) < 0 ? min : nums[i]; } return min; } /// <summary> /// ソート済み配列 ary に同じ値の要素が含まれている? /// ※ソート順は昇順/降順どちらでもよい /// </summary> public static bool HasDuplicateInSortedArray<T>(T[] ary) where T : IComparable, IComparable<T> { if (ary.Length <= 1) return false; var lastNum = ary[ary.Length - 1]; foreach (var n in ary) { if (lastNum.CompareTo(n) == 0) { return true; } else { lastNum = n; } } return false; } public static bool ReplaceIfBigger<T>(ref T r, T v) where T : IComparable { if (r.CompareTo(v) < 0) { r = v; return true; } else { return false; } } public static bool ReplaceIfSmaller<T>(ref T r, T v) where T : IComparable { if (0 < r.CompareTo(v)) { r = v; return true; } else { return false; } } /// <summary> /// dic[key]にadderを加算する。keyが存在しなかった場合はdic[key]=adder /// をセットする。 /// </summary> public static void AddTo<TKey>(this Dictionary<TKey, int> dic, TKey key, int adder) { if (dic.ContainsKey(key)) { dic[key] += adder; } else { dic[key] = adder; } } /// <summary> /// 文字列 s が chars に含まれる文字を含んでいるか? /// </summary> public static bool ContainsAny(this string s, char[] chars) { for (int j = 0; j < s.Length; j++) { if (chars.Contains(s[j])) return true; } return false; } /// <summary> /// 二分探索 /// ※条件を満たす最小のidxを返す /// ※満たすものがない場合は ary.Length を返す /// ※『aryの先頭側が条件を満たさない、末尾側が条件を満たす』という前提 /// ただし、IsOK(...)の戻り値を逆転させれば、逆でも同じことが可能。 /// </summary> /// <param name="ary">探索対象配列 ★ソート済みであること</param> /// <param name="key">探索値 /// ※これ以上の値を持つ(IsOKがtrueを返す)最小のindexを返す</param> public static int BinarySearch<T>(T[] ary, T key) where T : IComparable, IComparable<T> { int left = -1; int right = ary.Length; while (1 < right - left) { var mid = left + (right - left) / 2; if (IsOK(ary, mid, key)) { right = mid; } else { left = mid; } } // left は条件を満たさない最大の値、right // は条件を満たす最小の値になっている return right; } public static bool IsOK<T>(T[] ary, int idx, T key) where T : IComparable, IComparable<T> { // key <= ary[idx] と同じ意味 return key.CompareTo(ary[idx]) <= 0; } } public class SolverBase { virtual protected string ReadLine() => Console.ReadLine(); virtual protected string ReadString() => ReadLine(); virtual protected int ReadInt() => int.Parse(ReadLine()); virtual protected long ReadLong() => long.Parse(ReadLine()); virtual protected string[] ReadStringArray() => ReadLine().Split(' '); virtual protected char[] ReadCharArray() => ReadLine() .Split(' ') .Select<string, char>( s => s[0]) .ToArray(); virtual protected int[] ReadIntArray() => ReadLine() .Split(' ') .Select<string, int>( s => int.Parse(s)) .ToArray(); virtual protected void ReadInt2(out int a, out int b) { var ary = ReadIntArray(); a = ary[0]; b = ary[1]; } virtual protected void ReadInt3(out int a, out int b, out int c) { var ary = ReadIntArray(); a = ary[0]; b = ary[1]; c = ary[2]; } virtual protected void ReadInt4(out int a, out int b, out int c, out int d) { var ary = ReadIntArray(); a = ary[0]; b = ary[1]; c = ary[2]; d = ary[3]; } virtual protected long[] ReadLongArray() => ReadLine() .Split(' ') .Select<string, long>( s => long.Parse(s)) .ToArray(); virtual protected void ReadLong2(out long a, out long b) { var ary = ReadLongArray(); a = ary[0]; b = ary[1]; } virtual protected void ReadLong3(out long a, out long b, out long c) { var ary = ReadLongArray(); a = ary[0]; b = ary[1]; c = ary[2]; } virtual protected void ReadLong4(out long a, out long b, out long c, out long d) { var ary = ReadLongArray(); a = ary[0]; b = ary[1]; c = ary[2]; d = ary[3]; } virtual protected double[] ReadDoubleArray() => ReadLine() .Split(' ') .Select<string, double>( s => double.Parse(s)) .ToArray(); virtual protected void WriteLine(string line) => Console.WriteLine(line); virtual protected void WriteLine(double d) => Console.WriteLine($"{d:F9}"); virtual protected void WriteLine<T>(T value) where T : IFormattable => Console.WriteLine(value); virtual protected void WriteGrid(IEnumerable<IEnumerable<char>> arrayOfArray) { var sb = new StringBuilder(); foreach (var a in arrayOfArray) { foreach (var c in a) { sb.Append(c); } sb.AppendLine(); } WriteLine(sb.ToString()); } [Conditional("DEBUG")] protected void Dump(string s) => Console.WriteLine(s); [Conditional("DEBUG")] protected void Dump(char c) => Console.WriteLine(c); [Conditional("DEBUG")] protected void Dump(int x) => Console.WriteLine(x); [Conditional("DEBUG")] protected void Dump(double d) => Console.WriteLine($"{d:F9}"); [Conditional("DEBUG")] protected void Dump<T>(IEnumerable<T> array) where T : IFormattable { string s = Util.DumpToString(array); // Consoleに出力すると、UnitTestの邪魔をしないというメリットあり。 Console.WriteLine(s); //_writer.WriteLine(s); } [Conditional("DEBUG")] protected void DumpGrid(IEnumerable<IEnumerable<char>> arrayOfArray) { var sb = new StringBuilder(); foreach (var a in arrayOfArray) { foreach (var c in a) { sb.Append(c); } sb.AppendLine(); } // Consoleに出力すると、UnitTestの邪魔をしないというメリットあり。 Console.WriteLine(sb.ToString()); //_writer.WriteLine(sb.ToString()); } [Conditional("DEBUG")] protected void DumpGrid<T>(IEnumerable<IEnumerable<T>> arrayOfArray) where T : IFormattable { var sb = new StringBuilder(); foreach (var a in arrayOfArray) { sb.AppendLine(Util.DumpToString(a)); } // Consoleに出力すると、UnitTestの邪魔をしないというメリットあり。 Console.WriteLine(sb.ToString()); //_writer.WriteLine(sb.ToString()); } [Conditional("DEBUG")] protected void DumpGrid(bool[,] grid) { var sb = new StringBuilder(); for (int i = 0; i < grid.GetLength(0); i++) { for (int j = 0; j < grid.GetLength(1); j++) { sb.Append(grid[i, j] ? "x " : ". "); } sb.AppendLine(); } Console.WriteLine(sb.ToString()); } [Conditional("DEBUG")] protected void DumpGrid(char[,] grid) { var sb = new StringBuilder(); for (int i = 0; i < grid.GetLength(0); i++) { for (int j = 0; j < grid.GetLength(1); j++) { sb.Append(grid[i, j]); sb.Append(" "); } sb.AppendLine(); } Console.WriteLine(sb.ToString()); } [Conditional("DEBUG")] protected void DumpDP<T>(T[,] dp) where T : IFormattable { var sb = new StringBuilder(); for (int i = 0; i < dp.GetLength(0); i++) { for (int j = 0; j < dp.GetLength(1); j++) { sb.Append(dp[i, j]); sb.Append(", "); } sb.AppendLine(); } Console.WriteLine(sb.ToString()); } } }
[["+", 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, 241, 0, 111], ["+", 8, 196, 0, 57, 15, 241, 0, 213, 63, 22], ["+", 0, 57, 15, 241, 0, 213, 3, 4, 0, 24], ["+", 15, 241, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 57, 15, 241, 0, 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, 213, 63, 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, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
2,532
19
using System; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Collections.Generic; class Program { static void Main(string[] args) { string line = Console.ReadLine(); int num = line.Length; string str = line.Substring(0, num / 2); int num2 = line.IndexOf(str, num / 2 + 1); if (num2 == -1) { Console.WriteLine("No"); } else { Console.WriteLine(num2); Console.WriteLine("Yes"); } } }
using System; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Collections.Generic; class Program { static void Main(string[] args) { string line = Console.ReadLine(); int num = line.Length; string str = line.Substring(0, num / 2); int num2 = line.IndexOf(str, num / 2 + 1); if (num2 == -1) { Console.WriteLine("No"); } else { Console.WriteLine("Yes"); } } }
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 75, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["-", 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]]
8
125
7
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using Library; using static Library.Input; namespace AtCoderTemplate { class ProgramB { static void Main() { var line = Line; int len = line.Length; if (len % 2 == 1 && string.Join("", line.Substring(0, (len - 1) / 2).Reverse()) == line.Substring(0, (len - 1) / 2) && string.Join("", line.Substring((len + 1) / 2, (len - 1) / 2).Reverse()) == line.Substring((len + 1) / 2, (len - 1) / 2)) { System.Console.WriteLine("Yes"); } else { System.Console.WriteLine("No"); } } } } namespace Library { class Input { static IEnumerator<string> enumerator = new string[] {}.AsEnumerable().GetEnumerator(); public static string Line => Console.ReadLine(); public static string[] StrArr => Line.Split(' '); public static int NextInt => int.Parse(NextWord()); public static long NextLong => long.Parse(NextWord()); public static List<int> IntList => StrArr.Select(int.Parse).ToList(); public static List<long> LongList => StrArr.Select(long.Parse).ToList(); public static IEnumerable<long[]> TakeLine(int N) { return Enumerable.Repeat(0, N).Select( _ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray()); } public static string NextWord() { while (!enumerator.MoveNext()) { enumerator = StrArr.AsEnumerable().GetEnumerator(); } return enumerator.Current; } } } namespace Library { class Modular { public const int mod = 1000000007; public readonly long value; public Modular(long value) { this.value = value; } public static implicit operator Modular(long a) { var m = a % mod; return new Modular((m < 0) ? m + mod : 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 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, mod - 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) % mod)); } 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; } } } namespace Library { class MyMath { public static long Gcd(long a, long b) { return b == 0 ? a : Gcd(b, a % b); } public static long Sqrt(long n) { if (n < 0) return 0; long a = 0, tmp = 0, b = 0; for (int i = 62; i >= 0; i -= 2) { tmp = (b << 1) + 1 <= (n >> i) ? 1 : 0; a = a << 1 | tmp; n -= (((b << 1) + 1) * tmp) << i; b = (b << 1) + tmp + tmp; } return a; } public static long Nck(int n, int k) { if (k == 0) return 1; if (n == 0) return 0; return n * Nck(n - 1, k - 1) / k; } } } namespace Library { public class PriorityQueue<T> { readonly List<T> _heap = new List<T>(); readonly Comparison<T> _comparison; public PriorityQueue(Comparison<T> comparison) { _comparison = comparison; } public PriorityQueue() : this(Comparer<T>.Default.Compare) {} public PriorityQueue(IComparer<T> comparer) : this(comparer.Compare) {} public void Enqueue(T item) { _heap.Add(item); int childID = _heap.Count - 1; int parentID = (childID - 1) / 2; while (childID > 0 && _comparison(_heap[parentID], _heap[childID]) > 0) { Swap(parentID, childID); childID = parentID; parentID = (parentID - 1) / 2; } } public T Dequeue() { var first = _heap.First(); _heap[0] = _heap.Last(); _heap.RemoveAt(_heap.Count - 1); int parentID = 0; int childID = parentID * 2 + 2; if (childID >= _heap.Count || _comparison(_heap[childID], _heap[childID - 1]) > 0) childID--; while (childID < _heap.Count && _comparison(_heap[parentID], _heap[childID]) > 0) { Swap(parentID, childID); parentID = childID; childID = parentID * 2 + 2; if (childID >= _heap.Count || _comparison(_heap[childID], _heap[childID - 1]) > 0) childID--; } return first; } void Swap(int parent, int child) { var tmp = _heap[parent]; _heap[parent] = _heap[child]; _heap[child] = tmp; } public T Peek() { return _heap[0]; } public int Count => _heap.Count; public bool Any() { return _heap.Any(); } public List<T> Data => _heap; } } namespace Library { public class UnionFind { public int[] Parents { get; set; } public UnionFind(int size) { Parents = Enumerable.Repeat(-1, size).ToArray(); } public int Find(int num) { if (Parents[num] < 0) return num; Parents[num] = Find(Parents[num]); return Parents[num]; } public int Size(int num) { return -Parents[Find(num)]; } public bool Same(int a, int b) { return Find(a) == Find(b); } public void Unite(int a, int b) { int x = Find(a), y = Find(b); if (Size(x) > Size(y)) { Parents[x] += Parents[y]; Parents[y] = x; } else { Parents[y] += Parents[x]; Parents[x] = y; } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using Library; using static Library.Input; namespace AtCoderTemplate { class ProgramB { static void Main() { var line = Line; int len = line.Length; if (len % 2 == 1 && string.Join("", line.Reverse()) == line && string.Join("", line.Substring(0, (len - 1) / 2).Reverse()) == line.Substring(0, (len - 1) / 2) && string.Join("", line.Substring((len + 1) / 2, (len - 1) / 2).Reverse()) == line.Substring((len + 1) / 2, (len - 1) / 2)) { System.Console.WriteLine("Yes"); } else { System.Console.WriteLine("No"); } } } } namespace Library { class Input { static IEnumerator<string> enumerator = new string[] {}.AsEnumerable().GetEnumerator(); public static string Line => Console.ReadLine(); public static string[] StrArr => Line.Split(' '); public static int NextInt => int.Parse(NextWord()); public static long NextLong => long.Parse(NextWord()); public static List<int> IntList => StrArr.Select(int.Parse).ToList(); public static List<long> LongList => StrArr.Select(long.Parse).ToList(); public static IEnumerable<long[]> TakeLine(int N) { return Enumerable.Repeat(0, N).Select( _ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray()); } public static string NextWord() { while (!enumerator.MoveNext()) { enumerator = StrArr.AsEnumerable().GetEnumerator(); } return enumerator.Current; } } } namespace Library { class Modular { public const int mod = 1000000007; public readonly long value; public Modular(long value) { this.value = value; } public static implicit operator Modular(long a) { var m = a % mod; return new Modular((m < 0) ? m + mod : 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 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, mod - 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) % mod)); } 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; } } } namespace Library { class MyMath { public static long Gcd(long a, long b) { return b == 0 ? a : Gcd(b, a % b); } public static long Sqrt(long n) { if (n < 0) return 0; long a = 0, tmp = 0, b = 0; for (int i = 62; i >= 0; i -= 2) { tmp = (b << 1) + 1 <= (n >> i) ? 1 : 0; a = a << 1 | tmp; n -= (((b << 1) + 1) * tmp) << i; b = (b << 1) + tmp + tmp; } return a; } public static long Nck(int n, int k) { if (k == 0) return 1; if (n == 0) return 0; return n * Nck(n - 1, k - 1) / k; } } } namespace Library { public class PriorityQueue<T> { readonly List<T> _heap = new List<T>(); readonly Comparison<T> _comparison; public PriorityQueue(Comparison<T> comparison) { _comparison = comparison; } public PriorityQueue() : this(Comparer<T>.Default.Compare) {} public PriorityQueue(IComparer<T> comparer) : this(comparer.Compare) {} public void Enqueue(T item) { _heap.Add(item); int childID = _heap.Count - 1; int parentID = (childID - 1) / 2; while (childID > 0 && _comparison(_heap[parentID], _heap[childID]) > 0) { Swap(parentID, childID); childID = parentID; parentID = (parentID - 1) / 2; } } public T Dequeue() { var first = _heap.First(); _heap[0] = _heap.Last(); _heap.RemoveAt(_heap.Count - 1); int parentID = 0; int childID = parentID * 2 + 2; if (childID >= _heap.Count || _comparison(_heap[childID], _heap[childID - 1]) > 0) childID--; while (childID < _heap.Count && _comparison(_heap[parentID], _heap[childID]) > 0) { Swap(parentID, childID); parentID = childID; childID = parentID * 2 + 2; if (childID >= _heap.Count || _comparison(_heap[childID], _heap[childID - 1]) > 0) childID--; } return first; } void Swap(int parent, int child) { var tmp = _heap[parent]; _heap[parent] = _heap[child]; _heap[child] = tmp; } public T Peek() { return _heap[0]; } public int Count => _heap.Count; public bool Any() { return _heap.Any(); } public List<T> Data => _heap; } } namespace Library { public class UnionFind { public int[] Parents { get; set; } public UnionFind(int size) { Parents = Enumerable.Repeat(-1, size).ToArray(); } public int Find(int num) { if (Parents[num] < 0) return num; Parents[num] = Find(Parents[num]); return Parents[num]; } public int Size(int num) { return -Parents[Find(num)]; } public bool Same(int a, int b) { return Find(a) == Find(b); } public void Unite(int a, int b) { int x = Find(a), y = Find(b); if (Size(x) > Size(y)) { Parents[x] += Parents[y]; Parents[y] = x; } else { Parents[y] += Parents[x]; Parents[x] = y; } } } }
[["+", 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], ["+", 31, 16, 12, 16, 31, 213, 3, 4, 0, 25], ["+", 15, 16, 31, 16, 31, 16, 12, 16, 17, 60], ["+", 15, 16, 31, 16, 31, 16, 12, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 98], ["+", 31, 16, 12, 16, 31, 213, 63, 214, 205, 199], ["+", 31, 16, 12, 16, 31, 213, 63, 214, 0, 131], ["+", 31, 16, 12, 16, 31, 213, 63, 214, 141, 22], ["+", 31, 16, 12, 16, 31, 213, 3, 4, 0, 24], ["+", 31, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 31, 16, 12, 16, 31, 213, 3, 4, 0, 21], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131]]
8
1,572
16
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main() { var l = int.Parse(Console.ReadLine()); decimal l3 = l / 3; decimal ans = l3 * l3 * l3; Console.WriteLine(ans.ToString()); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main() { var l = int.Parse(Console.ReadLine()); decimal l3 = l / 3m; decimal ans = l3 * l3 * l3; Console.WriteLine(ans.ToString()); Console.ReadLine(); } }
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 250], ["+", 3, 4, 0, 28, 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
72
8
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static void Main(string[] args) { var vs = Int32.Parse(Console.ReadLine()); var result = max(vs); Console.WriteLine(result); Console.ReadKey(); } public static double max(double vs) { double vs2 = vs / 3; return vs2; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static void Main(string[] args) { var vs = Int32.Parse(Console.ReadLine()); var result = max(vs); Console.WriteLine(result); Console.ReadKey(); } public static double max(double vs) { double vs2 = vs / 3; double vs3 = vs2 * vs2 * vs2; return vs3; } } }
[["-", 8, 201, 0, 195, 8, 196, 0, 37, 0, 38], ["+", 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, 16, 31, 16, 17, 48], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 12, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 48], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 37, 0, 38], ["+", 8, 201, 0, 195, 8, 196, 0, 37, 0, 22]]
8
101
11
using System; using System.Linq; using System.Collections.Generic; using System.Text; public class Program { public static void Main(string[] args) { new C().test(); } } public class C { public void test() { // 整数の入力 int input = CommonRead.ReadInt(); //出力 Console.WriteLine((Math.Pow((input / 3), 3))); } } 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 C().test(); } } public class C { public void test() { // 整数の入力 decimal input = CommonRead.ReadDecimal(); var divinput = decimal.Divide(input, 3.000000m); //出力 Console.WriteLine( Decimal.Multiply(Decimal.Multiply(divinput, divinput), divinput)); } } 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, 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, 141, 22], ["+", 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, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 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, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 250], ["-", 0, 213, 3, 4, 0, 28, 0, 23, 0, 24], ["-", 0, 28, 0, 23, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["-", 0, 28, 0, 23, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["-", 3, 4, 0, 28, 0, 23, 0, 16, 31, 22], ["-", 3, 4, 0, 28, 0, 23, 0, 16, 17, 85], ["-", 3, 4, 0, 28, 0, 23, 0, 16, 12, 203], ["-", 0, 213, 3, 4, 0, 28, 0, 23, 0, 25], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 23, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21]]
8
475
33
using System; using System.Collections.Generic; using System.Linq; class Ho { static void Main() { var N = int.Parse(Console.ReadLine()); var aho = Console.ReadLine().Split(); var A = new long[N + 1]; var b = new long[N + 1]; for (int i = 0; i < N; i++) { A[i] = long.Parse(aho[i]); } var count = new long[N + 1]; foreach (var a in A) { count[a]++; } // iが書かれたボールから2個を取り出す方法の数 var c = new long[N + 1]; for (int i = 0; i < N + 1; i++) { c[i] = count[i] * (count[i] - 1) / 2; } // ボールを除かないときの方法の数 var sum = c.Sum(); // aを除くときの方法の数を求める foreach (var a in A) { if (count[a] == 0) continue; var newCount = count[a] - 1; var ans = sum - c[a] + (newCount * (newCount - 1) / 2); Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; class Ho { static void Main() { var N = int.Parse(Console.ReadLine()); var aho = Console.ReadLine().Split(); var A = new long[N]; var b = new long[N + 1]; for (int i = 0; i < N; i++) { A[i] = long.Parse(aho[i]); } var count = new long[N + 1]; foreach (var a in A) { count[a]++; } // iが書かれたボールから2個を取り出す方法の数 var c = new long[N + 1]; for (int i = 0; i < N + 1; i++) { c[i] = count[i] * (count[i] - 1) / 2; } // ボールを除かないときの方法の数 var sum = c.Sum(); // aを除くときの方法の数を求める foreach (var a in A) { // if (count[a] == 0) continue; var newCount = count[a] - 1; var ans = sum - c[a] + (newCount * (newCount - 1) / 2); Console.WriteLine(ans); } } }
[["-", 0, 227, 39, 224, 225, 226, 0, 16, 17, 72], ["-", 0, 227, 39, 224, 225, 226, 0, 16, 12, 203], ["-", 8, 196, 0, 210, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 210, 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, 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, 116, 0, 117], ["-", 0, 210, 8, 196, 0, 57, 64, 116, 0, 35]]
8
253
13
using System; using System.Collections.Generic; using System.Numerics; using System.Linq; using static System.Math; class MainClass { public static void Main(string[] args) { var N = LnInt(); var As = LnLngs(); var nums = new long[N + 1]; for (int i = 0; i < N; i++) { nums[As[i]]++; } var combo = new long[N]; // 0~iまでの同じ数字の組み合わせの総数 combo[0] = nums[0] * (nums[0] - 1) / 2; for (int i = 0; i < N - 1; i++) { combo[i + 1] = combo[i] + nums[i + 1] * (nums[i + 1] - 1) / 2; } for (int k = 0; k < N; k++) { var remove = As[k]; print(combo[N - 1] - nums[remove] * (nums[remove] - 1) / 2 + (nums[remove] - 1) * (nums[remove] - 2) / 2); } } public static void print(object obj) { Console.WriteLine(obj); } public static long Gcd(long a, long b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } } public static int Gcd(int a, int b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } } public static int[] LnInts() { var vs = Console.ReadLine().Trim().Split( new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new int[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = int.Parse(vs[i]); return ins; } public static int LnInt() { var vs = Console.ReadLine().Trim(); return int.Parse(vs); } public static long[] LnLngs() { var vs = Console.ReadLine().Trim().Split( new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new long[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = long.Parse(vs[i]); return ins; } public static long LnLng() { var vs = Console.ReadLine().Trim(); return long.Parse(vs); } public static string[] LnStrs() { var vs = Console.ReadLine().Trim().Split( new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); return vs; } public static string LnStr() { var vs = Console.ReadLine().Trim(); return vs; } }
using System; using System.Collections.Generic; using System.Numerics; using System.Linq; using static System.Math; class MainClass { public static void Main(string[] args) { var N = LnInt(); var As = LnLngs(); var nums = new long[N + 1]; for (int i = 0; i < N; i++) { nums[As[i]]++; } var combo = new long[N + 1]; // 0~iまでの同じ数字の組み合わせの総数 combo[0] = nums[0] * (nums[0] - 1L) / 2L; for (int i = 0; i < N; i++) { combo[i + 1] = combo[i] + nums[i + 1] * (nums[i + 1] - 1L) / 2L; } for (int k = 0; k < N; k++) { var remove = As[k]; print(combo[N] - nums[remove] * (nums[remove] - 1L) / 2L + (nums[remove] - 1L) * (nums[remove] - 2L) / 2L); } } public static void print(object obj) { Console.WriteLine(obj); } public static long Gcd(long a, long b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } } public static int Gcd(int a, int b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } } public static int[] LnInts() { var vs = Console.ReadLine().Trim().Split( new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new int[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = int.Parse(vs[i]); return ins; } public static int LnInt() { var vs = Console.ReadLine().Trim(); return int.Parse(vs); } public static long[] LnLngs() { var vs = Console.ReadLine().Trim().Split( new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new long[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = long.Parse(vs[i]); return ins; } public static long LnLng() { var vs = Console.ReadLine().Trim(); return long.Parse(vs); } public static string[] LnStrs() { var vs = Console.ReadLine().Trim().Split( new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); return vs; } public static string LnStr() { var vs = Console.ReadLine().Trim(); return vs; } }
[["+", 0, 227, 39, 224, 225, 226, 0, 16, 17, 72], ["+", 0, 227, 39, 224, 225, 226, 0, 16, 12, 203], ["-", 12, 16, 31, 16, 12, 23, 0, 16, 12, 203], ["+", 12, 16, 31, 16, 12, 23, 0, 16, 12, 203], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["-", 0, 1, 0, 11, 12, 16, 12, 16, 12, 203], ["+", 0, 1, 0, 11, 12, 16, 12, 16, 12, 203], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 0, 28, 0, 16, 31, 16, 12, 16, 12, 203], ["+", 0, 28, 0, 16, 31, 16, 12, 16, 12, 203], ["-", 12, 16, 31, 16, 31, 23, 0, 16, 12, 203], ["+", 12, 16, 31, 16, 31, 23, 0, 16, 12, 203], ["-", 3, 4, 0, 28, 0, 16, 12, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 16, 12, 16, 12, 203]]
8
700
24
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Text; class Program { static void Main(string[] args) { // 入力 long n = long.Parse(Console.ReadLine()); long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray(); var dic = new Dictionary<long, long>() {}; for (long i = 0; i < n; i++) { if (!dic.ContainsKey(a[i])) { dic.Add(a[i], 1); } else { dic[a[i]]++; } } for (long i = 0; i < n; i++) { if (dic[a[i]] < 2) { dic[a[i]] = 0; } } var tmp1 = new Dictionary<long, long>() {}; foreach (var item in dic) { if (item.Value > 1) { tmp1.Add(item.Key, (item.Value * (item.Value - 1)) / 2); } } var tmp2 = new Dictionary<long, long>() {}; foreach (var item in dic) { if (item.Value > 2) { tmp2.Add(item.Key, (item.Value * (item.Value - 1)) / 2); } else if (item.Value == 2) { tmp2.Add(item.Key, 0); } } long[] ans = new long[n]; var sum = tmp1.Values.Sum(); for (long i = 0; i < n; i++) { if (dic[a[i]] == 0) { ans[i] = sum; } else { ans[i] = sum - tmp1[a[i]] + tmp2[a[i]]; } } for (long i = 0; i < n; i++) { Console.WriteLine(ans[i]); } } }
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Text; class Program { static void Main(string[] args) { // 入力 long n = long.Parse(Console.ReadLine()); long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray(); var dic = new Dictionary<long, long>() {}; for (long i = 0; i < n; i++) { if (!dic.ContainsKey(a[i])) { dic.Add(a[i], 1); } else { dic[a[i]]++; } } for (long i = 0; i < n; i++) { if (dic[a[i]] < 2) { dic[a[i]] = 0; } } var tmp1 = new Dictionary<long, long>() {}; foreach (var item in dic) { if (item.Value > 1) { tmp1.Add(item.Key, (item.Value * (item.Value - 1)) / 2); } } var tmp2 = new Dictionary<long, long>() {}; foreach (var item in dic) { if (item.Value > 2) { tmp2.Add(item.Key, ((item.Value - 1) * (item.Value - 2)) / 2); } else if (item.Value == 2) { tmp2.Add(item.Key, 0); } } long[] ans = new long[n]; var sum = tmp1.Values.Sum(); for (long i = 0; i < n; i++) { if (dic[a[i]] == 0) { ans[i] = sum; } else { ans[i] = sum - tmp1[a[i]] + tmp2[a[i]]; } } for (long i = 0; i < n; i++) { Console.WriteLine(ans[i]); } } }
[["+", 0, 16, 31, 23, 0, 16, 31, 23, 0, 24], ["+", 31, 23, 0, 16, 31, 23, 0, 16, 17, 33], ["+", 31, 23, 0, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 16, 31, 23, 0, 16, 31, 23, 0, 25], ["-", 31, 23, 0, 16, 12, 23, 0, 16, 12, 203], ["+", 31, 23, 0, 16, 12, 23, 0, 16, 12, 203]]
8
442
6
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; namespace AtCoder { public class ABC { // private const int mod = 1000000007; // 10^9+7 static void Main(string[] args) { // System.Diagnostics.Stopwatch stopwatch = new // System.Diagnostics.Stopwatch(); stopwatch.Start(); Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); // string s = Console.ReadLine(); int n = int.Parse(Console.ReadLine()); // long x = long.Parse(Console.ReadLine()); int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray(); // long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray(); Dictionary<int, long[]> count = new Dictionary<int, long[]>(); for (int i = 0; i < n; i++) { if (!count.ContainsKey(a[i])) { count.Add(a[i], new long[3]); } count[a[i]][0]++; } long sum = 0; foreach (var item in count) { item.Value[1] = Combination((int)item.Value[0], 2); item.Value[2] = Combination((int)item.Value[0] - 1, 2); sum += item.Value[1]; } for (int i = 0; i < n; i++) { long ans = sum - count[a[i]][1] + count[a[i]][2]; Console.WriteLine(ans); } Console.Out.Flush(); // System.Diagnostics.Debug.WriteLine(stopwatch.Elapsed); } #region 場合の数(rが一桁程度) static long Combination(int n, int r) { r = Math.Min(r, n - r); if (n < r) { return 0; } long ans = 1; for (int i = n; i > n - r; i--) { ans *= i; } for (int i = 1; i <= r; i++) { ans /= i; } return ans; } #endregion } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; namespace AtCoder { public class ABC { // private const int mod = 1000000007; // 10^9+7 static void Main(string[] args) { // System.Diagnostics.Stopwatch stopwatch = new // System.Diagnostics.Stopwatch(); stopwatch.Start(); Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); // string s = Console.ReadLine(); int n = int.Parse(Console.ReadLine()); // long x = long.Parse(Console.ReadLine()); int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray(); // long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray(); Dictionary<int, long[]> count = new Dictionary<int, long[]>(); for (int i = 0; i < n; i++) { if (!count.ContainsKey(a[i])) { count.Add(a[i], new long[3]); } count[a[i]][0]++; } long sum = 0; foreach (var item in count) { item.Value[1] = Combination((int)item.Value[0], 2); item.Value[2] = Combination((int)item.Value[0] - 1, 2); sum += item.Value[1]; } for (int i = 0; i < n; i++) { long ans = sum - count[a[i]][1] + count[a[i]][2]; Console.WriteLine(ans); } Console.Out.Flush(); // System.Diagnostics.Debug.WriteLine(stopwatch.Elapsed); } #region 場合の数(rが一桁程度) static long Combination(int n, int r) { if (n < r) { return 0; } r = Math.Min(r, n - r); long ans = 1; for (int i = n; i > n - r; i--) { ans *= i; } for (int i = 2; i <= r; i++) { ans /= i; } return ans; } #endregion } }
[["+", 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, 18], ["+", 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], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 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, 18], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 203], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
8
423
24
using System; using System.Collections.Generic; using System.IO; using System.Linq; class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var N = sc.ReadInt(); var A = sc.ReadLongArray(N); // iが書かれたボールの数 var count = new long[N + 1]; foreach (var a in A) { count[a]++; } // iが書かれたボールから2個を取り出す方法の数 var c = new long[N + 1]; for (int i = 0; i < N + 1; i++) { c[i] = count[i] * (count[i] - 1) / 2; } // ボールを除かないときの方法の数 var sum = count.Sum(); // aを除くときの方法の数を求める foreach (var a in A) { var newCount = count[a] - 1; var ans = sum - c[a] + (newCount * (newCount - 1) / 2); Console.WriteLine(ans); } Console.Out.Flush(); } static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public Tuple<int, int> ReadTup(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add); } public Tuple<long, long> ReadTupLong(int add = 0) { return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add); } public Tuple<int, int, int> ReadTup3(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public Tuple<int, int, int, int> ReadTup4(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) { var array = new Tuple<long, long>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTupLong(add); } return array; } public Tuple<int, int>[] ReadTupArray(int n, int add = 0) { var array = new Tuple<int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup(add); } return array; } public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) { var array = new Tuple<int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup3(add); } return array; } public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) { var array = new Tuple<int, int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup4(add); } return array; } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var N = sc.ReadInt(); var A = sc.ReadLongArray(N); // iが書かれたボールの数 var count = new long[N + 1]; foreach (var a in A) { count[a]++; } // iが書かれたボールから2個を取り出す方法の数 var c = new long[N + 1]; for (int i = 0; i < N + 1; i++) { c[i] = count[i] * (count[i] - 1) / 2; } // ボールを除かないときの方法の数 var sum = c.Sum(); // aを除くときの方法の数を求める foreach (var a in A) { if (count[a] == 0) continue; var newCount = count[a] - 1; var ans = sum - c[a] + (newCount * (newCount - 1) / 2); Console.WriteLine(ans); } Console.Out.Flush(); } static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public Tuple<int, int> ReadTup(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add); } public Tuple<long, long> ReadTupLong(int add = 0) { return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add); } public Tuple<int, int, int> ReadTup3(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public Tuple<int, int, int, int> ReadTup4(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) { var array = new Tuple<long, long>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTupLong(add); } return array; } public Tuple<int, int>[] ReadTupArray(int n, int add = 0) { var array = new Tuple<int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup(add); } return array; } public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) { var array = new Tuple<int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup3(add); } return array; } public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) { var array = new Tuple<int, int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup4(add); } return array; } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 210, 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, 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, 116, 0, 117], ["+", 0, 210, 8, 196, 0, 57, 64, 116, 0, 35]]
8
1,195
13
using System; using System.Linq; using System.Collections.Generic; using System.Collections; class Program { static void Main(string[] args) { var sol = new Solve(); sol.Exec(); } } class Solve { public void Exec() { var N = int.Parse(Console.ReadLine()); var A = Console.ReadLine().Split().Select(int.Parse).ToArray(); var dict = new Dictionary<int, int>(); var nCr = new long[200001]; for (var i = 1; i <= 200000; i++) { nCr[i] = CombCount(i, 2); } for (var i = 0; i < N; i++) { if (dict.ContainsKey(A[i])) dict[A[i]]++; else dict[A[i]] = 1; } var total = 0L; foreach (var d in dict) { if (d.Value >= 2) total += nCr[d.Value]; } for (var i = 0; i < N; i++) { if (dict[A[i]] >= 2) Console.WriteLine(total - (nCr[dict[A[i]]] - nCr[dict[A[i]] - 1])); else Console.WriteLine(0); } } public static long CombCount(int n, int m) { if (m == 0) return 1; if (n == 0) return 0; return (n * CombCount(n - 1, m - 1) / m); } }
using System; using System.Linq; using System.Collections.Generic; using System.Collections; class Program { static void Main(string[] args) { var sol = new Solve(); sol.Exec(); } } class Solve { public void Exec() { var N = int.Parse(Console.ReadLine()); var A = Console.ReadLine().Split().Select(int.Parse).ToArray(); var dict = new Dictionary<int, int>(); var nCr = new long[200001]; for (var i = 1; i <= 200000; i++) { nCr[i] = CombCount(i, 2); } for (var i = 0; i < N; i++) { if (dict.ContainsKey(A[i])) dict[A[i]]++; else dict[A[i]] = 1; } var total = 0L; foreach (var d in dict) { if (d.Value >= 2) total += nCr[d.Value]; } for (var i = 0; i < N; i++) { // if (dict[A[i]] - 1 >= 2) Console.WriteLine(total - (nCr[dict[A[i]]] - nCr[dict[A[i]] - 1])); // else // Console.WriteLine(0); } } public static long CombCount(int n, int m) { if (m == 0) return 1; if (n == 0) return 0; return (n * CombCount(n - 1, m - 1) / m); } }
[["-", 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], ["-", 31, 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, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25], ["-", 0, 7, 8, 196, 0, 57, 64, 1, 0, 35], ["-", 8, 196, 0, 7, 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], ["-", 75, 1, 0, 213, 3, 4, 0, 28, 0, 203]]
8
345
20
using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; using System.Numerics; namespace AtCoderWorkspace { public class Solver { public void Solve() { var cin = new Scanner(); var a = cin.nextInt(); var b = cin.nextInt(); for (int i = 25; i < 100000; i++) { var aa = (int)(i * 0.08); var bb = (int)(i * 0.10); if (aa == a && bb == b) { Console.WriteLine(i); return; } } Console.WriteLine(-1); } } 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 int[] DPArrayInt(int N, int ex) { int[] Array = new int[N + ex]; for (int i = 0; i < N; i++) { Array[i] = nextInt(); } 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 long[] DPArrayLong(int N, int ex) { long[] Array = new long[N + ex]; for (int i = 0; i < N; i++) { Array[i] = nextLong(); } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } class Program { static void Main(string[] s) => new Solver().Solve(); } }
using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; using System.Numerics; namespace AtCoderWorkspace { public class Solver { public void Solve() { var cin = new Scanner(); var a = cin.nextInt(); var b = cin.nextInt(); for (int i = 0; i < 100000; i++) { var y = 100 * i; var aa = (i * 8) / 100; var bb = (i * 10) / 100; if (aa == a && bb == b) { Console.WriteLine(i); return; } } Console.WriteLine(-1); } } 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 int[] DPArrayInt(int N, int ex) { int[] Array = new int[N + ex]; for (int i = 0; i < N; i++) { Array[i] = nextInt(); } 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 long[] DPArrayLong(int N, int ex) { long[] Array = new long[N + ex]; for (int i = 0; i < N; i++) { Array[i] = nextLong(); } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } class Program { static void Main(string[] s) => new Solver().Solve(); } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 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, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 48], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 74, 0, 25], ["-", 0, 200, 0, 212, 0, 74, 51, 23, 0, 24], ["-", 0, 212, 0, 74, 51, 23, 0, 16, 12, 250], ["+", 0, 212, 0, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 85], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
626
23
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ABC157 { public class C { static void Main(string[] args) { var inputs = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var answer = Enumerable.Range(0, 10000) .Where(x => Math.Truncate(x * 0.08) == inputs[0] && Math.Truncate(x * 0.1) == inputs[1]) .Min(); Console.WriteLine(answer); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ABC157 { public class C { static void Main(string[] args) { var inputs = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var answer = Enumerable.Range(0, 10000).Where( x => Math.Truncate(x * 0.08) == inputs[0] && Math.Truncate(x * 0.1) == inputs[1]); Console.WriteLine(answer.Any() ? answer.Min() : -1); } } }
[["-", 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, 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, 3, 4, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 0, 28, 0, 41, 64, 213, 63, 214, 205, 22], ["+", 0, 28, 0, 41, 64, 213, 63, 214, 0, 131], ["+", 0, 28, 0, 41, 64, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 41, 64, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 41, 64, 213, 3, 4, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 3, 4, 0, 28, 0, 41, 75, 241, 0, 33], ["+", 3, 4, 0, 28, 0, 41, 75, 241, 0, 203]]
8
123
17
namespace AtCoder { using System; using System.Linq; using System.Collections.Generic; using System.IO; using System.Text; using System.Text.RegularExpressions; class Program { static void Main() { var s = System.Console.ReadLine(); var q = System.Console.ReadLine().ToInt32(); var ans = new List<char>() { s[0] }; var sb1 = new StringBuilder(); var sb2 = new StringBuilder(); var revflg = false; for (int i = 0; i < q; i++) { var a = System.Console.ReadLine().Split(' ').ToArray(); // T1 if (a[0] == "1") { revflg = !revflg; continue; } // T2 F1 if (a[1] == "1" && !revflg || a[1] == "2" && revflg) { ans.Insert(0, a[2][0]); } // T2 F2 else { ans.Add(a[2][0]); } } // revcntが奇数ならリバース if (revflg) { ans.Reverse(); } Output(String.Concat(ans)); } private static void Output(string str) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Console.WriteLine(str); Console.Out.Flush(); } } static class Extentions { #region 拡張メソッド(string) public static string LeftB(this string stTarget, int iByteSize) { return MidB(stTarget, 1, iByteSize); } public static string MidB(this string stTarget, int iStart) { System.Text.Encoding hEncoding = System.Text.Encoding.GetEncoding("utf-8"); byte[] bBytes = hEncoding.GetBytes(stTarget); return hEncoding.GetString(bBytes, iStart - 1, bBytes.Length - iStart + 1); } public static string MidB(this string stTarget, int iStart, int iByteSize) { System.Text.Encoding hEncoding = System.Text.Encoding.GetEncoding("utf-8"); byte[] bBytes = hEncoding.GetBytes(stTarget); return hEncoding.GetString(bBytes, iStart - 1, iByteSize); } public static string RightB(this string stTarget, int iByteSize) { System.Text.Encoding hEncoding = System.Text.Encoding.GetEncoding("utf-8"); byte[] bBytes = hEncoding.GetBytes(stTarget); return hEncoding.GetString(bBytes, bBytes.Length - iByteSize, iByteSize); } public static bool IsNullOrEmpty(this string str) { return string.IsNullOrEmpty(str); } /// <summary> /// カルチャに依存した比較、または大文字と小文字を区別しない比較などの序数による比較を指定できる /// Contains。 /// </summary> /// <param name="value">対象文字列</param> /// <param name="partialValue">部分文字列</param> /// <param /// name="comparison">カルチャ、大文字と小文字の区別、および並べ替え規則を指定する /// StringComparison</param> <returns>一致する場合に true /// を返します。</returns> public static bool Contains(this string value, string partialValue, StringComparison comparison = 0) { return value.IndexOf(partialValue, comparison) >= 0; } public static bool IsNumeric(this string value) { return decimal.TryParse(value, out decimal d); } public static int ToInt32(this String number, int retValue = 0) { if (!number.IsNumeric()) return retValue; return int.Parse(number); } #endregion } } #region Template /* using System; using System.Collections.Generic; using System.Linq; // 整数の入力======================================== string[] input = Console.ReadLine().Split(' '); int a = int.Parse(input[0]); int b = int.Parse(input[1]); int c = int.Parse(Console.ReadLine()); //配列操作======================================== var a = System.Console.ReadLine().Split(' ').Select((x) => long.Parse(x)).ToArray(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = int.Parse(input2[i]); } Array.Sort(a); Array.Reverse(a); // 最小公倍数======================================== public static decimal Lcm(decimal a, decimal b) { return a * b / Gcd(a, b); } // ユークリッドの互除法 ======================================== public static decimal Gcd(decimal a, decimal b) { if (a < b) { // 引数を入替えて自分を呼び出す return Gcd(b, a); } while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } // 全bit探索======================================== // input桁のbit列で全探索を行う for (int x = 0; x < Math.Pow(2, input.Length); x++) { var array = new bool[input.Length]; // 右からk桁目を取り出す for (int k = 0; k < input.Length; k++) { var y = (x >> k) & 1; array[k] = y==1; } } // DFS(深さ探索)======================================== static void Main() { var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var h = input[0]; var w = input[1]; var meiro = new char[w, h]; var reached = new bool[w, h]; var sh = 0; var sw = 0; var gh = 0; var gw = 0; for (int i = 0; i < h; i++) { var x = Console.ReadLine(); for (int j = 0; j < w; j++) { meiro[j, i] = x[j]; // スタートとゴール地点を退避 if (x[j] == 's') { sh = i; sw = j; } if (x[j] == 'g') { gh = i; gw = j; } } } Search(sw, sh, meiro, reached); var ans = "No"; if (reached[gw, gh] == true) { ans = "Yes"; } Output(ans); } private static void Search(int x, int y, char[,] meiro, bool[,] reached) { // 壁や迷路の外なら脱出 if (x < 0 || y < 0 || x > meiro.GetLength(0) - 1 || y > meiro.GetLength(1) - 1 || meiro[x, y] == '#') return; // 到達済みの場合も脱出 if (reached[x, y] == true) return; // 到達記録 reached[x, y] = true; Search(x + 1, y, meiro, reached); Search(x, y + 1, meiro, reached); Search(x - 1, y, meiro, reached); Search(x, y - 1, meiro, reached); } // DFS(深さ探索)======================================== static void Main() { var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var r = input[0]; var c = input[1]; var meiro = new char[r, c]; var passed = new bool[r, c]; var start = Console.ReadLine().Split(' ').Select(x => int.Parse(x) -1).ToList(); var goal = Console.ReadLine().Split(' ').Select(x => int.Parse(x) -1).ToArray(); for (int i = 0; i < r; i++) { var x = Console.ReadLine(); for (int j = 0; j < c; j++) { meiro[i, j] = x[j]; } } var numMoves = new int[r, c]; var que = new Queue<int[]>(); start.Add(0); // 深さ que.Enqueue(start.ToArray()); BFS(que, passed, numMoves, meiro); Output(numMoves[goal[0], goal[1]].ToString()); } private static void BFS(Queue<int[]> que, bool[,] passed, int[,] numMoves, char[,] meiro) { while (que.Count() > 0) { var p = que.Dequeue(); var x = p[0]; var y = p[1]; // 壁や迷路の外なら脱出 if (x < 0 || y < 0 || x > meiro.GetLength(0) - 1 || y > meiro.GetLength(1) - 1 || meiro[x, y] == '#') continue; // 到達済みの場合も脱出 if (passed[x, y] == true) continue; // 到達記録 passed[x, y] = true; numMoves[x, y] = p[2]; que.Enqueue(new int[3] { x - 1, y , p[2] + 1 }); que.Enqueue(new int[3] { x + 1, y , p[2] + 1 }); que.Enqueue(new int[3] { x, y - 1, p[2] + 1 }); que.Enqueue(new int[3] { x, y + 1, p[2] + 1 }); } } //二分探索============================================== static void Main() { var n = Console.ReadLine().ToInt32(); var a = System.Console.ReadLine().Split(' ').Select((x) => long.Parse(x)).ToArray(); var b = System.Console.ReadLine().Split(' ').Select((x) => long.Parse(x)).ToArray(); var c = System.Console.ReadLine().Split(' ').Select((x) => long.Parse(x)).ToArray(); long ans = 0; for (int i = 0; i < a.Count(); i++) { var aIdx = LowerBound(a, b[i]) - 1; if (aIdx < 0) continue; var cIdx = UpperBound(c, b[i]); if (cIdx > n - 1) continue; //組み合わせ long combi = (long)(aIdx + 1) * (long)(n - cIdx); ans += combi; } Output(ans.ToString()); } private static int LowerBound(long[] arr, long target) { var min = 0; var max = arr.Length - 1; while (max >= min) { int mid = min + (max - min) / 2; if (arr[mid] < target) { min = mid + 1; } else { max = mid - 1; } } //target以上となる最初のインデックスを出力 return min; } private static int UpperBound(long[] arr, long target) { var min = 0; var max = arr.Length - 1; while (max >= min) { var mid = (min + max) / 2; if (arr[mid] <= target) { min = mid + 1; } else { max = mid - 1; } } //target以上となる最初のインデックスを出力 return min; } //出力======================================== Console.WriteLine(""); var sb = new StringBuilder(); for (int j = 0; j<n; j++) { sb.AppendLine(a[j].ToString()); } var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Console.WriteLine(sb.ToString()); Console.Out.Flush(); */ #endregion
namespace AtCoder { using System; using System.Linq; using System.Collections.Generic; using System.IO; using System.Text; using System.Text.RegularExpressions; class Program { static void Main() { var s = System.Console.ReadLine(); var q = System.Console.ReadLine().ToInt32(); var ans = new List<char>(s.ToArray()); var revflg = false; for (int i = 0; i < q; i++) { var a = System.Console.ReadLine().Split(' ').ToArray(); // T1 if (a[0] == "1") { revflg = !revflg; continue; } // T2 F1 if (a[1] == "1" && !revflg || a[1] == "2" && revflg) { ans.Insert(0, a[2][0]); } // T2 F2 else { ans.Add(a[2][0]); } } // revcntが奇数ならリバース if (revflg) { ans.Reverse(); } Output(String.Concat(ans)); } private static void Output(string str) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Console.WriteLine(str); Console.Out.Flush(); } } static class Extentions { #region 拡張メソッド(string) public static string LeftB(this string stTarget, int iByteSize) { return MidB(stTarget, 1, iByteSize); } public static string MidB(this string stTarget, int iStart) { System.Text.Encoding hEncoding = System.Text.Encoding.GetEncoding("utf-8"); byte[] bBytes = hEncoding.GetBytes(stTarget); return hEncoding.GetString(bBytes, iStart - 1, bBytes.Length - iStart + 1); } public static string MidB(this string stTarget, int iStart, int iByteSize) { System.Text.Encoding hEncoding = System.Text.Encoding.GetEncoding("utf-8"); byte[] bBytes = hEncoding.GetBytes(stTarget); return hEncoding.GetString(bBytes, iStart - 1, iByteSize); } public static string RightB(this string stTarget, int iByteSize) { System.Text.Encoding hEncoding = System.Text.Encoding.GetEncoding("utf-8"); byte[] bBytes = hEncoding.GetBytes(stTarget); return hEncoding.GetString(bBytes, bBytes.Length - iByteSize, iByteSize); } public static bool IsNullOrEmpty(this string str) { return string.IsNullOrEmpty(str); } /// <summary> /// カルチャに依存した比較、または大文字と小文字を区別しない比較などの序数による比較を指定できる /// Contains。 /// </summary> /// <param name="value">対象文字列</param> /// <param name="partialValue">部分文字列</param> /// <param /// name="comparison">カルチャ、大文字と小文字の区別、および並べ替え規則を指定する /// StringComparison</param> <returns>一致する場合に true /// を返します。</returns> public static bool Contains(this string value, string partialValue, StringComparison comparison = 0) { return value.IndexOf(partialValue, comparison) >= 0; } public static bool IsNumeric(this string value) { return decimal.TryParse(value, out decimal d); } public static int ToInt32(this String number, int retValue = 0) { if (!number.IsNumeric()) return retValue; return int.Parse(number); } #endregion } } #region Template /* using System; using System.Collections.Generic; using System.Linq; // 整数の入力======================================== string[] input = Console.ReadLine().Split(' '); int a = int.Parse(input[0]); int b = int.Parse(input[1]); int c = int.Parse(Console.ReadLine()); //配列操作======================================== var a = System.Console.ReadLine().Split(' ').Select((x) => long.Parse(x)).ToArray(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = int.Parse(input2[i]); } Array.Sort(a); Array.Reverse(a); // 最小公倍数======================================== public static decimal Lcm(decimal a, decimal b) { return a * b / Gcd(a, b); } // ユークリッドの互除法 ======================================== public static decimal Gcd(decimal a, decimal b) { if (a < b) { // 引数を入替えて自分を呼び出す return Gcd(b, a); } while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } // 全bit探索======================================== // input桁のbit列で全探索を行う for (int x = 0; x < Math.Pow(2, input.Length); x++) { var array = new bool[input.Length]; // 右からk桁目を取り出す for (int k = 0; k < input.Length; k++) { var y = (x >> k) & 1; array[k] = y==1; } } // DFS(深さ探索)======================================== static void Main() { var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var h = input[0]; var w = input[1]; var meiro = new char[w, h]; var reached = new bool[w, h]; var sh = 0; var sw = 0; var gh = 0; var gw = 0; for (int i = 0; i < h; i++) { var x = Console.ReadLine(); for (int j = 0; j < w; j++) { meiro[j, i] = x[j]; // スタートとゴール地点を退避 if (x[j] == 's') { sh = i; sw = j; } if (x[j] == 'g') { gh = i; gw = j; } } } Search(sw, sh, meiro, reached); var ans = "No"; if (reached[gw, gh] == true) { ans = "Yes"; } Output(ans); } private static void Search(int x, int y, char[,] meiro, bool[,] reached) { // 壁や迷路の外なら脱出 if (x < 0 || y < 0 || x > meiro.GetLength(0) - 1 || y > meiro.GetLength(1) - 1 || meiro[x, y] == '#') return; // 到達済みの場合も脱出 if (reached[x, y] == true) return; // 到達記録 reached[x, y] = true; Search(x + 1, y, meiro, reached); Search(x, y + 1, meiro, reached); Search(x - 1, y, meiro, reached); Search(x, y - 1, meiro, reached); } // DFS(深さ探索)======================================== static void Main() { var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var r = input[0]; var c = input[1]; var meiro = new char[r, c]; var passed = new bool[r, c]; var start = Console.ReadLine().Split(' ').Select(x => int.Parse(x) -1).ToList(); var goal = Console.ReadLine().Split(' ').Select(x => int.Parse(x) -1).ToArray(); for (int i = 0; i < r; i++) { var x = Console.ReadLine(); for (int j = 0; j < c; j++) { meiro[i, j] = x[j]; } } var numMoves = new int[r, c]; var que = new Queue<int[]>(); start.Add(0); // 深さ que.Enqueue(start.ToArray()); BFS(que, passed, numMoves, meiro); Output(numMoves[goal[0], goal[1]].ToString()); } private static void BFS(Queue<int[]> que, bool[,] passed, int[,] numMoves, char[,] meiro) { while (que.Count() > 0) { var p = que.Dequeue(); var x = p[0]; var y = p[1]; // 壁や迷路の外なら脱出 if (x < 0 || y < 0 || x > meiro.GetLength(0) - 1 || y > meiro.GetLength(1) - 1 || meiro[x, y] == '#') continue; // 到達済みの場合も脱出 if (passed[x, y] == true) continue; // 到達記録 passed[x, y] = true; numMoves[x, y] = p[2]; que.Enqueue(new int[3] { x - 1, y , p[2] + 1 }); que.Enqueue(new int[3] { x + 1, y , p[2] + 1 }); que.Enqueue(new int[3] { x, y - 1, p[2] + 1 }); que.Enqueue(new int[3] { x, y + 1, p[2] + 1 }); } } //二分探索============================================== static void Main() { var n = Console.ReadLine().ToInt32(); var a = System.Console.ReadLine().Split(' ').Select((x) => long.Parse(x)).ToArray(); var b = System.Console.ReadLine().Split(' ').Select((x) => long.Parse(x)).ToArray(); var c = System.Console.ReadLine().Split(' ').Select((x) => long.Parse(x)).ToArray(); long ans = 0; for (int i = 0; i < a.Count(); i++) { var aIdx = LowerBound(a, b[i]) - 1; if (aIdx < 0) continue; var cIdx = UpperBound(c, b[i]); if (cIdx > n - 1) continue; //組み合わせ long combi = (long)(aIdx + 1) * (long)(n - cIdx); ans += combi; } Output(ans.ToString()); } private static int LowerBound(long[] arr, long target) { var min = 0; var max = arr.Length - 1; while (max >= min) { int mid = min + (max - min) / 2; if (arr[mid] < target) { min = mid + 1; } else { max = mid - 1; } } //target以上となる最初のインデックスを出力 return min; } private static int UpperBound(long[] arr, long target) { var min = 0; var max = arr.Length - 1; while (max >= min) { var mid = (min + max) / 2; if (arr[mid] <= target) { min = mid + 1; } else { max = mid - 1; } } //target以上となる最初のインデックスを出力 return min; } //出力======================================== Console.WriteLine(""); var sb = new StringBuilder(); for (int j = 0; j<n; j++) { sb.AppendLine(a[j].ToString()); } var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Console.WriteLine(sb.ToString()); Console.Out.Flush(); */ #endregion
[["-", 0, 200, 0, 212, 0, 230, 3, 4, 0, 25], ["-", 0, 200, 0, 212, 0, 230, 10, 229, 0, 45], ["-", 0, 230, 10, 229, 0, 204, 206, 207, 0, 70], ["-", 10, 229, 0, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 230, 10, 229, 0, 204, 206, 207, 0, 73], ["-", 0, 200, 0, 212, 0, 230, 10, 229, 0, 46], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 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, 198, 0, 200, 0, 212, 0, 230, 39, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 0, 200, 0, 212, 0, 230, 3, 4, 0, 24]]
8
653
21
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { public static void Main() { string S = Console.ReadLine(); int Q = int.Parse(Console.ReadLine()); bool isReversed = false; var ans = new List<string>(S.Select(c => c.ToString())); for (int i = 0; i < Q; i++) { var query = Console.ReadLine(); if (query[0] == '1') { isReversed = !isReversed; continue; } if (query[0] == '2') { var row = query.Split(); int F = int.Parse(row[1]); string C = row[2]; if (F == 1 & !isReversed || (F == 2 & isReversed)) { ans.Insert(0, C); } else { ans.Add(C); } } } if (isReversed) { Console.WriteLine(String.Concat(ans.OrderBy(x => x))); } else { Console.WriteLine(String.Concat(ans)); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { public static void Main() { string S = Console.ReadLine(); int Q = int.Parse(Console.ReadLine()); bool isReversed = false; var ans = new List<char>(S.ToArray()); for (int i = 0; i < Q; i++) { var query = Console.ReadLine(); if (query[0] == '1') { isReversed = !isReversed; continue; } if (query[0] == '2') { var row = query.Split().ToArray(); int F = int.Parse(row[1]); char C = row[2][0]; if (F == 1 & !isReversed || (F == 2 & isReversed)) { ans.Insert(0, C); } else { ans.Add(C); } } } if (isReversed) { ans.Reverse(); } Console.WriteLine(String.Concat(ans)); } }
[["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["-", 0, 28, 0, 218, 8, 213, 63, 214, 205, 22], ["-", 0, 28, 0, 218, 8, 213, 63, 214, 0, 131], ["-", 0, 28, 0, 218, 8, 213, 63, 214, 141, 22], ["-", 0, 28, 0, 218, 8, 213, 3, 4, 0, 24], ["-", 0, 200, 0, 212, 0, 230, 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, 57, 64, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 57, 64, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 212, 0, 204, 205, 204, 206, 207, 0, 73], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 70], ["+", 0, 212, 0, 204, 206, 207, 0, 28, 0, 203], ["-", 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], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 218, 8, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["-", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["-", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
249
38
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Numerics; using System.Threading; using static System.Math; using static System.Array; using static AtCoder.IO_ShortCut; using static AtCoder.Tool; using static AtCoder.ModInt; namespace AtCoder { class AC { const int MOD = 1000000007; // const int MOD = 998244353; const int INF = int.MaxValue / 2; const long SINF = long.MaxValue / 2; const double EPS = 1e-8; static readonly int[] dI = { 0, 1, 0, -1, 1, -1, -1, 1 }; static readonly int[] dJ = { 1, 0, -1, 0, 1, 1, -1, -1 }; static List<List<int>> G = new List<List<int>>(); // static List<List<Edge>> G = new List<List<Edge>>(); // static List<Edge> E = new List<Edge>(); static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); /*var th = new Thread(Run, 1 << 26); th.Start(); th.Join();*/ Run(); Console.Out.Flush(); } static void Run() { int Testcase = 1; for (var _ = 0; _ < Testcase; _++) Solve(); } static void Solve() { var S = Str; int Q = Int; var fr = new StringBuilder(); var bk = new StringBuilder(); int k = 0; for (var i = 0; i < Q; i++) { var input = _ReadSplit; if (input.Length == 1) { k++; } else { int F = int.Parse(input[1]); var C = input[2]; if ((F + k) % 2 == 1) fr.Append(C); else bk.Append(C); } } if (k % 2 == 1) { var B = string.Join("", bk.ToString().Reverse()); OutL(B + S + fr.ToString()); } else { var F = string.Join("", fr.ToString().Reverse()); var ss = string.Join("", S.Reverse()); OutL(F + ss + bk.ToString()); } } public struct Edge { public int from; public int to; public long dist; public Edge(int t, long c) { from = -1; to = t; dist = c; } public Edge(int f, int t, long c) { from = f; to = t; dist = c; } } } struct ModInt { public long value; private const int MOD = 1000000007; // private const int MOD = 998244353; public ModInt(long value) { this.value = value; } public static implicit operator ModInt(long a) { var ret = a % MOD; return new ModInt(ret < 0 ? (ret + MOD) : ret); } public static ModInt operator +(ModInt a, ModInt b) => (a.value + b.value); public static ModInt operator -(ModInt a, ModInt b) => (a.value - b.value); public static ModInt operator *(ModInt a, ModInt b) => (a.value * b.value); public static ModInt operator /(ModInt a, ModInt b) => a * Modpow(b, MOD - 2); public static ModInt operator <<(ModInt a, int n) => (a.value << n); public static ModInt operator>>(ModInt a, int n) => (a.value >> n); public static ModInt operator ++(ModInt a) => a.value + 1; public static ModInt operator --(ModInt a) => a.value - 1; public static ModInt Modpow(ModInt a, long n) { var k = a; ModInt ret = 1; while (n > 0) { if ((n & 1) != 0) ret *= k; k *= k; n >>= 1; } return ret; } private static readonly List<long> Factorials = new List<long>() { 1 }; public static ModInt Fac(long n) { for (var i = Factorials.Count(); i <= n; i++) { Factorials.Add((Factorials[i - 1] * i) % MOD); } return Factorials[(int)n]; } public static ModInt nCr(long n, long r) { return n < r ? 0 : Fac(n) / (Fac(r) * Fac(n - r)); } public static explicit operator int(ModInt a) => (int)a.value; } static class IO_ShortCut { public static string[] _ReadSplit => Console.ReadLine().Split(); public static int[] _ReadSplitInt => ConvertAll(Console.ReadLine().Split(), int.Parse); public static long[] _ReadSplitLong => ConvertAll(Console.ReadLine().Split(), long.Parse); public static double[] _ReadSplit_Double => ConvertAll(Console.ReadLine().Split(), double.Parse); public static string Str => Console.ReadLine(); public static int Int => int.Parse(Console.ReadLine()); public static long Long => long.Parse(Console.ReadLine()); public static double Double => double.Parse(Console.ReadLine()); public static T Conv<T>(string input) { if (typeof(T).Equals(typeof(ModInt))) { return (T)(dynamic)(long.Parse(input)); } return (T)Convert.ChangeType(input, typeof(T)); } public static void Input<T>(out T a) => a = Conv<T>(Console.ReadLine()); public static void Input<T, U>(out T a, out U b) { var q = _ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); } public static void Input<T, U, V>(out T a, out U b, out V c) { var q = _ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); } public static void Input<T, U, V, W>(out T a, out U b, out V c, out W d) { var q = _ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); d = Conv<W>(q[3]); } public static void Input<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var q = _ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); d = Conv<W>(q[3]); e = Conv<X>(q[4]); } public static void OutL(object s) => Console.WriteLine(s); public static void Out_Sep<T>(IEnumerable<T> s) => Console.WriteLine(string.Join(" ", s)); public static void Out_Sep<T>(IEnumerable<T> s, string sep) => Console.WriteLine(string.Join($"{sep}", s)); public static void Out_Sep(params object[] s) => Console.WriteLine(string.Join(" ", s)); public static void Out_One(object s) => Console.Write($"{s} "); public static void Out_One(object s, string sep) => Console.Write($"{s}{sep}"); public static void Endl() => Console.WriteLine(); } public static class Tool { static public void Initialize<T>(ref T[] array, T initialvalue) { array = ConvertAll(array, x => initialvalue); } static public void Swap<T>(ref T a, ref T b) { T keep = a; a = b; b = keep; } static public void Display<T>(T[,] array2d, int n, int m) { for (var i = 0; i < n; i++) { for (var j = 0; j < m; j++) { Console.Write($"{array2d[i, j]} "); } Console.WriteLine(); } } static public long Gcd(long a, long b) { if (a == 0 || b == 0) return Max(a, b); return a % b == 0 ? b : Gcd(b, a % b); } static public long LPow(int a, int b) => (long)Pow(a, b); static public bool Bit(long x, int dig) => ((1L << dig) & x) != 0; static public int Sig(long a) => a == 0 ? 0 : (int)(a / Abs(a)); } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Numerics; using System.Threading; using static System.Math; using static System.Array; using static AtCoder.IO_ShortCut; using static AtCoder.Tool; using static AtCoder.ModInt; namespace AtCoder { class AC { const int MOD = 1000000007; // const int MOD = 998244353; const int INF = int.MaxValue / 2; const long SINF = long.MaxValue / 2; const double EPS = 1e-8; static readonly int[] dI = { 0, 1, 0, -1, 1, -1, -1, 1 }; static readonly int[] dJ = { 1, 0, -1, 0, 1, 1, -1, -1 }; static List<List<int>> G = new List<List<int>>(); // static List<List<Edge>> G = new List<List<Edge>>(); // static List<Edge> E = new List<Edge>(); static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); /*var th = new Thread(Run, 1 << 26); th.Start(); th.Join();*/ Run(); Console.Out.Flush(); } static void Run() { int Testcase = 1; for (var _ = 0; _ < Testcase; _++) Solve(); } static void Solve() { var S = Str; int Q = Int; var fr = new StringBuilder(); var bk = new StringBuilder(); int k = 0; for (var i = 0; i < Q; i++) { var input = _ReadSplit; if (input.Length == 1) { k++; } else { int F = int.Parse(input[1]); var C = input[2]; if ((F + k) % 2 == 1) fr.Append(C); else bk.Append(C); } } if (k % 2 == 1) { var B = string.Join("", bk.ToString().Reverse()); var ss = string.Join("", S.Reverse()); OutL(B + ss + fr.ToString()); } else { var F = string.Join("", fr.ToString().Reverse()); OutL(F + S + bk.ToString()); } } public struct Edge { public int from; public int to; public long dist; public Edge(int t, long c) { from = -1; to = t; dist = c; } public Edge(int f, int t, long c) { from = f; to = t; dist = c; } } } struct ModInt { public long value; private const int MOD = 1000000007; // private const int MOD = 998244353; public ModInt(long value) { this.value = value; } public static implicit operator ModInt(long a) { var ret = a % MOD; return new ModInt(ret < 0 ? (ret + MOD) : ret); } public static ModInt operator +(ModInt a, ModInt b) => (a.value + b.value); public static ModInt operator -(ModInt a, ModInt b) => (a.value - b.value); public static ModInt operator *(ModInt a, ModInt b) => (a.value * b.value); public static ModInt operator /(ModInt a, ModInt b) => a * Modpow(b, MOD - 2); public static ModInt operator <<(ModInt a, int n) => (a.value << n); public static ModInt operator>>(ModInt a, int n) => (a.value >> n); public static ModInt operator ++(ModInt a) => a.value + 1; public static ModInt operator --(ModInt a) => a.value - 1; public static ModInt Modpow(ModInt a, long n) { var k = a; ModInt ret = 1; while (n > 0) { if ((n & 1) != 0) ret *= k; k *= k; n >>= 1; } return ret; } private static readonly List<long> Factorials = new List<long>() { 1 }; public static ModInt Fac(long n) { for (var i = Factorials.Count(); i <= n; i++) { Factorials.Add((Factorials[i - 1] * i) % MOD); } return Factorials[(int)n]; } public static ModInt nCr(long n, long r) { return n < r ? 0 : Fac(n) / (Fac(r) * Fac(n - r)); } public static explicit operator int(ModInt a) => (int)a.value; } static class IO_ShortCut { public static string[] _ReadSplit => Console.ReadLine().Split(); public static int[] _ReadSplitInt => ConvertAll(Console.ReadLine().Split(), int.Parse); public static long[] _ReadSplitLong => ConvertAll(Console.ReadLine().Split(), long.Parse); public static double[] _ReadSplit_Double => ConvertAll(Console.ReadLine().Split(), double.Parse); public static string Str => Console.ReadLine(); public static int Int => int.Parse(Console.ReadLine()); public static long Long => long.Parse(Console.ReadLine()); public static double Double => double.Parse(Console.ReadLine()); public static T Conv<T>(string input) { if (typeof(T).Equals(typeof(ModInt))) { return (T)(dynamic)(long.Parse(input)); } return (T)Convert.ChangeType(input, typeof(T)); } public static void Input<T>(out T a) => a = Conv<T>(Console.ReadLine()); public static void Input<T, U>(out T a, out U b) { var q = _ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); } public static void Input<T, U, V>(out T a, out U b, out V c) { var q = _ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); } public static void Input<T, U, V, W>(out T a, out U b, out V c, out W d) { var q = _ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); d = Conv<W>(q[3]); } public static void Input<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var q = _ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); d = Conv<W>(q[3]); e = Conv<X>(q[4]); } public static void OutL(object s) => Console.WriteLine(s); public static void Out_Sep<T>(IEnumerable<T> s) => Console.WriteLine(string.Join(" ", s)); public static void Out_Sep<T>(IEnumerable<T> s, string sep) => Console.WriteLine(string.Join($"{sep}", s)); public static void Out_Sep(params object[] s) => Console.WriteLine(string.Join(" ", s)); public static void Out_One(object s) => Console.Write($"{s} "); public static void Out_One(object s, string sep) => Console.Write($"{s}{sep}"); public static void Endl() => Console.WriteLine(); } public static class Tool { static public void Initialize<T>(ref T[] array, T initialvalue) { array = ConvertAll(array, x => initialvalue); } static public void Swap<T>(ref T a, ref T b) { T keep = a; a = b; b = keep; } static public void Display<T>(T[,] array2d, int n, int m) { for (var i = 0; i < n; i++) { for (var j = 0; j < m; j++) { Console.Write($"{array2d[i, j]} "); } Console.WriteLine(); } } static public long Gcd(long a, long b) { if (a == 0 || b == 0) return Max(a, b); return a % b == 0 ? b : Gcd(b, a % b); } static public long LPow(int a, int b) => (long)Pow(a, b); static public bool Bit(long x, int dig) => ((1L << dig) & x) != 0; static public int Sig(long a) => a == 0 ? 0 : (int)(a / Abs(a)); } }
[["+", 64, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 64, 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, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 197, 0, 35], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 75, 196, 0, 197, 0, 35], ["-", 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], ["-", 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, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22]]
8
1,970
38
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Numerics; using System.Text; using System.Threading; using System.Threading.Tasks; using static System.Console; namespace ConsoleApp2 { class Program { static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); } static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); } static void Main(string[] args) { var S = new LinkedList<char>(Console.ReadLine()); var Q = int.Parse(Console.ReadLine()); var strs = new char[500000]; var ltor = true; for (var i = 0; i < Q; i++) { var ac = ReadLine().Split().ToArray(); if (ac[0] == "1") { ltor = !ltor; } else { if (ltor) { if (ac[1] == "1") { S.AddFirst(ac[2][0]); } else { S.AddLast(ac[2][0]); } } else { if (ac[1] != "1") { S.AddFirst(ac[2][0]); } else { S.AddLast(ac[2][0]); } } } } var ans = ""; if (!ltor) { ans = string.Join("", S.Reverse()); } Console.WriteLine(ans); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Numerics; using System.Text; using System.Threading; using System.Threading.Tasks; using static System.Console; namespace ConsoleApp2 { class Program { static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); } static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); } static void Main(string[] args) { var S = new LinkedList<char>(Console.ReadLine()); var Q = int.Parse(Console.ReadLine()); var strs = new char[500000]; var ltor = true; for (var i = 0; i < Q; i++) { var ac = ReadLine().Split().ToArray(); if (ac[0] == "1") { ltor = !ltor; } else { if (ltor) { if (ac[1] == "1") { S.AddFirst(ac[2][0]); } else { S.AddLast(ac[2][0]); } } else { if (ac[1] != "1") { S.AddFirst(ac[2][0]); } else { S.AddLast(ac[2][0]); } } } } var ans = ""; if (!ltor) { ans = string.Join("", S.Reverse()); } else { ans = string.Join("", S); } Console.WriteLine(ans); } } }
[["+", 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, 1, 0, 11, 31, 22], ["+", 75, 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], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 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
353
15
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { string s = Console.ReadLine(); long n = long.Parse(Console.ReadLine()); LinkedList<char> lst = new LinkedList<char>(s); Boolean inv = false; int cnt = 0; for (int i = 0; i < n; i++) { string inp = Console.ReadLine(); Boolean adds = false; if (inp.Length == 5) { if (inp[2] == '1') { adds = false; } else { adds = true; } if (inv) adds = !adds; if (adds) { lst.AddLast(inp[4]); } else { lst.AddFirst(inp[4]); } } else { inv = !inv; cnt++; } } if (cnt % 2 == 1) lst.Reverse(); Console.WriteLine(string.Concat(lst.ToArray())); } }
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { string s = Console.ReadLine(); long n = long.Parse(Console.ReadLine()); LinkedList<char> lst = new LinkedList<char>(s); Boolean inv = false; int cnt = 0; for (int i = 0; i < n; i++) { string inp = Console.ReadLine(); Boolean adds = false; if (inp.Length == 5) { if (inp[2] == '1') { adds = false; } else { adds = true; } if (inv) adds = !adds; if (adds) { lst.AddLast(inp[4]); } else { lst.AddFirst(inp[4]); } } else { inv = !inv; cnt++; } } char[] ans = lst.ToArray(); if (cnt % 2 == 1) ans = ans.Reverse().ToArray(); Console.WriteLine(string.Concat(ans)); } }
[["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 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], ["+", 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, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 57, 64, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 12, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["+", 12, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 12, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 64, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 64, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22]]
8
221
25
using System; using System.Collections.Generic; using System.IO; using System.Linq; class D { static StreamWriter Out = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; static void Main(string[] args) { string S; Input(out S); int Q; Input(out Q); bool isReversed = false; LinkedList<char> list = new LinkedList<char>(S.ToCharArray()); for (int i = 0; i < Q; i++) { string query = Console.ReadLine(); if (query.StartsWith("1")) { isReversed = !isReversed; } else { int f = int.Parse(query[2].ToString()); char c = query[4]; if (f == 1) { if (isReversed) { list.AddLast(c); } else { list.AddFirst(c); } } else { if (isReversed) { list.AddFirst(c); } else { list.AddLast(c); } } } } if (isReversed) { list.Reverse(); } Console.WriteLine(string.Join("", list)); } static T ChangeT<T>(string s) => (T)Convert.ChangeType(s, typeof(T)); static void Input<A>(out A a) { var words = Console.ReadLine().Split( new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries); a = ChangeT<A>(words[0]); } static void Input<A, B>(out A a, out B b) { var words = Console.ReadLine().Split( new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries); a = ChangeT<A>(words[0]); b = ChangeT<B>(words[1]); } static void Input<A, B, C>(out A a, out B b, out C c) { var words = Console.ReadLine().Split( new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries); a = ChangeT<A>(words[0]); b = ChangeT<B>(words[1]); c = ChangeT<C>(words[2]); } static void Input<A, B, C, D>(out A a, out B b, out C c, out D d) { var words = Console.ReadLine().Split( new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries); a = ChangeT<A>(words[0]); b = ChangeT<B>(words[1]); c = ChangeT<C>(words[2]); d = ChangeT<D>(words[3]); } static void Input<A, B, C, D, E>(out A a, out B b, out C c, out D d, out E e) { var words = Console.ReadLine().Split( new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries); a = ChangeT<A>(words[0]); b = ChangeT<B>(words[1]); c = ChangeT<C>(words[2]); d = ChangeT<D>(words[3]); e = ChangeT<E>(words[4]); } static void Input<A, B, C, D, E, F>(out A a, out B b, out C c, out D d, out E e, out F f) { var words = Console.ReadLine().Split( new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries); a = ChangeT<A>(words[0]); b = ChangeT<B>(words[1]); c = ChangeT<C>(words[2]); d = ChangeT<D>(words[3]); e = ChangeT<E>(words[4]); f = ChangeT<F>(words[5]); } static void InputArray<T>(out T[] array) { array = Console.ReadLine() .Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries) .Select(s => ChangeT<T>(s)) .ToArray(); } static void Print<T>(T s) => Out.WriteLine(s); static void Print<T>(params T[] s) => Out.WriteLine(string.Join(" ", s)); static void Print<T>(IEnumerable<T> e) => Out.WriteLine(string.Join(" ", e)); }
using System; using System.Collections.Generic; using System.IO; using System.Linq; class D { static StreamWriter Out = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; static void Main(string[] args) { string S; Input(out S); int Q; Input(out Q); bool isReversed = false; LinkedList<char> list = new LinkedList<char>(S.ToCharArray()); for (int i = 0; i < Q; i++) { string query = Console.ReadLine(); if (query.StartsWith("1")) { isReversed = !isReversed; } else { int f = int.Parse(query[2].ToString()); char c = query[4]; if (f == 1) { if (isReversed) { list.AddLast(c); } else { list.AddFirst(c); } } else { if (isReversed) { list.AddFirst(c); } else { list.AddLast(c); } } } } if (isReversed) { Console.WriteLine(string.Join("", list.Reverse())); } else { Console.WriteLine(string.Join("", list)); } } static T ChangeT<T>(string s) => (T)Convert.ChangeType(s, typeof(T)); static void Input<A>(out A a) { var words = Console.ReadLine().Split( new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries); a = ChangeT<A>(words[0]); } static void Input<A, B>(out A a, out B b) { var words = Console.ReadLine().Split( new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries); a = ChangeT<A>(words[0]); b = ChangeT<B>(words[1]); } static void Input<A, B, C>(out A a, out B b, out C c) { var words = Console.ReadLine().Split( new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries); a = ChangeT<A>(words[0]); b = ChangeT<B>(words[1]); c = ChangeT<C>(words[2]); } static void Input<A, B, C, D>(out A a, out B b, out C c, out D d) { var words = Console.ReadLine().Split( new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries); a = ChangeT<A>(words[0]); b = ChangeT<B>(words[1]); c = ChangeT<C>(words[2]); d = ChangeT<D>(words[3]); } static void Input<A, B, C, D, E>(out A a, out B b, out C c, out D d, out E e) { var words = Console.ReadLine().Split( new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries); a = ChangeT<A>(words[0]); b = ChangeT<B>(words[1]); c = ChangeT<C>(words[2]); d = ChangeT<D>(words[3]); e = ChangeT<E>(words[4]); } static void Input<A, B, C, D, E, F>(out A a, out B b, out C c, out D d, out E e, out F f) { var words = Console.ReadLine().Split( new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries); a = ChangeT<A>(words[0]); b = ChangeT<B>(words[1]); c = ChangeT<C>(words[2]); d = ChangeT<D>(words[3]); e = ChangeT<E>(words[4]); f = ChangeT<F>(words[5]); } static void InputArray<T>(out T[] array) { array = Console.ReadLine() .Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries) .Select(s => ChangeT<T>(s)) .ToArray(); } static void Print<T>(T s) => Out.WriteLine(s); static void Print<T>(params T[] s) => Out.WriteLine(string.Join(" ", s)); static void Print<T>(IEnumerable<T> e) => Out.WriteLine(string.Join(" ", e)); }
[["+", 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], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 199], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
1,016
16
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; using System.Numerics; using System.Runtime.CompilerServices; using System.Text; using static System.Math; using static Solve.Methods; using static Solve.Input; using static Solve.Output; using pii = Solve.Pair<int, int>; using pll = Solve.Pair<long, long>; using pli = Solve.Pair<long, int>; using pil = Solve.Pair<int, long>; using pss = Solve.Pair<string, string>; using psi = Solve.Pair<string, int>; using lint = System.Collections.Generic.List<int>; using llong = System.Collections.Generic.List<long>; using lstr = System.Collections.Generic.List<string>; using llint = System.Collections.Generic.List<System.Collections.Generic.List<int>>; using llstr = System.Collections.Generic.List<System.Collections.Generic.List<long>>; using lllong = System.Collections.Generic.List<System.Collections.Generic.List<string>>; using lii = System.Collections.Generic.List<Solve.Pair<int, int>>; using lll = System.Collections.Generic.List<Solve.Pair<long, long>>; using lli = System.Collections.Generic.List<Solve.Pair<long, int>>; using lil = System.Collections.Generic.List<Solve.Pair<int, long>>; using ll = System.Int64; namespace Solve { public class Solver { public void Main() { string S = ReadStr; int Q = ReadInt; var deque = new Deque<char>(); foreach(char c in S) deque.PushBack(c); bool isReversed = false; for (int i = 0; i < Q; i++) { int T = ReadInt; if (T == 1) { isReversed = !isReversed; } else { int F = ReadInt; char C = ReadStr[0]; if ((F == 1) ^ isReversed) deque.PushBack(C); else deque.PushFront(C); } } if (isReversed) { while (deque.Count > 0) { Console.Write(deque.PopFront()); } } else { while (deque.Count > 0) { Console.Write(deque.PopBack()); } } } // ReSharper disable UnusedMember.Local private const int MOD = (int) 1e9 + 7, INF = 1000000010; private const long LINF = 1000000000000000100; } // ライブラリ置き場ここから public class Deque<T> { T[] buf; int offset, capacity; public int Count { get; private set; } public Deque(int cap) { buf = new T[capacity = cap]; } public Deque() { buf = new T[capacity = 16]; } public T this[int index] { get { return buf[getIndex(index)]; } set { buf[getIndex(index)] = value; } } private int getIndex(int index) { if (index >= capacity) throw new IndexOutOfRangeException("out of range"); var ret = index + offset; if (ret >= capacity) ret -= capacity; return ret; } public void PushFront(T item) { if (Count == capacity) Extend(); if (--offset < 0) offset += buf.Length; buf[offset] = item; ++Count; } public T PopFront() { if (Count == 0) throw new InvalidOperationException("collection is empty"); --Count; var ret = buf[offset++]; if (offset >= capacity) offset -= capacity; return ret; } public void PushBack(T item) { if (Count == capacity) Extend(); var id = Count++ + offset; if (id >= capacity) id -= capacity; buf[id] = item; } public T PopBack() { if (Count == 0) throw new InvalidOperationException("collection is empty"); return buf[getIndex(--Count)]; } public void Insert(int index, T item) { if (index > Count) throw new IndexOutOfRangeException(); PushFront(item); for (int i = 0; i < index; i++) this[i] = this[i + 1]; this[index] = item; } public T RemoveAt(int index) { if (index < 0 || index >= Count) throw new IndexOutOfRangeException(); var ret = this[index]; for (int i = index; i > 0; i--) this[i] = this[i - 1]; PopFront(); return ret; } private void Extend() { T[] newBuffer = new T[capacity << 1]; if (offset > capacity - Count) { var len = buf.Length - offset; Array.Copy(buf, offset, newBuffer, 0, len); Array.Copy(buf, 0, newBuffer, len, Count - len); } else Array.Copy(buf, offset, newBuffer, 0, Count); buf = newBuffer; offset = 0; capacity <<= 1; } public T[] Items { get { var a = new T[Count]; for (int i = 0; i < Count; i++) a[i] = this[i]; return a; } } } // ライブラリ置き場ここまで #region Templete #if !LOCAL namespace Library { } #endif public static class Methods { public static readonly int[] dx = {-1, 0, 0, 1}; public static readonly int[] dy = {0, 1, -1, 0}; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Assert(bool b, string message = null) { if (!b) throw new Exception(message ?? "Assert failed."); } /* public static Comparison<T> greater<T>() where T : IComparable<T> => (a, b) => b.CompareTo(a); */ public static string JoinSpace<T>(this IEnumerable<T> source) => source.Join(" "); public static string JoinEndline<T>(this IEnumerable<T> source) => source.Join("\n"); public static string Join<T>(this IEnumerable<T> source, string s) => string.Join(s, source); public static string Join<T>(this IEnumerable<T> source, char c) => string.Join(c.ToString(), source); /// <summary> /// <see cref="Pair{T1, T2}"/> クラスのインスタンスを作成します。 /// </summary> /// <typeparam name="T1">firstの型</typeparam> /// <typeparam name="T2">secondの型</typeparam> /// <param name="first">firstの値</param> /// <param name="second">secondの値</param> /// <returns>作成した<see cref="Pair{T1, T2}"/> クラスのインスタンス</returns> public static Pair<T1, T2> make_pair<T1, T2>(T1 first, T2 second) where T1 : IComparable<T1> where T2 : IComparable<T2> => new Pair<T1, T2>(first, second); /// <summary>aとbをスワップします。</summary> public static void Swap<T>(ref T a, ref T b) where T : struct { var tmp = b; b = a; a = tmp; } /// <summary>aとbの最大公約数を求めます。</summary> /// <returns>aとbの最大公約数</returns> public static long Gcd(long a, long b) { while (true) { if (a < b) Swap(ref a, ref b); if (a % b == 0) return b; var x = a; a = b; b = x % b; } } /// <summary>aとbの最小公倍数を求めます。</summary> /// <returns>aとbの最小公倍数</returns> public static long Lcm(long a, long b) => a / Gcd(a, b) * b; /// <summary> /// 指定した数値が素数であるかを判定します。 /// </summary> /// <remarks>計算量 (sqrt(value)) </remarks> /// <param name="value">判定する数値</param> /// <returns>value が素数であるか</returns> public static bool IsPrime(long value) { if (value <= 1) return false; for (long i = 2; i * i <= value; i++) if (value % i == 0) return false; return true; } /// <summary> /// <see cref="a"/> ^ <see cref="b"/> (mod <see cref="p"/>) を求める /// </summary> /// <returns><see cref="a"/> ^ <see cref="b"/> (mod <see cref="p"/>) の値</returns> public static long PowMod(long a, long b, long p) { long res = 1; while (b > 0) { if (b % 2 != 0) res = res * a % p; a = a * a % p; b >>= 1; } return res; } /// <summary> /// mod pにおけるaの逆元を求めます。 /// </summary> /// <param name="a"></param> /// <param name="p">法</param> /// <returns></returns> public static long ModInv(long a, long p) => PowMod(a, p - 2, p); public static int DivCeil(int left, int right) => left / right + (left % right == 0 ? 0 : 1); public static long DivCeil(long left, long right) => left / right + (left % right == 0L ? 0L : 1L); /// <summary> /// src の順列を求めます。 /// </summary> /// <typeparam name="T">型</typeparam> /// <param name="src">順列を求める配列</param> /// <returns>src の順列</returns> public static IEnumerable<T[]> Permutations<T>(IEnumerable<T> src) { var ret = new List<T[]>(); Search(ret, new Stack<T>(), src.ToArray()); return ret; } private static void Search<T>(ICollection<T[]> perms, Stack<T> stack, T[] a) { int N = a.Length; if (N == 0) perms.Add(stack.Reverse().ToArray()); else { var b = new T[N - 1]; Array.Copy(a, 1, b, 0, N - 1); for (int i = 0; i < a.Length; ++i) { stack.Push(a[i]); Search(perms, stack, b); if (i < b.Length) b[i] = a[i]; stack.Pop(); } } } /// <summary> /// 指定した条件を満たす最小の数値を返します。 /// </summary> /// <param name="low">検索する数値の最小値</param> /// <param name="high">検索する数値の最大値</param> /// <param name="expression">条件</param> /// <returns>条件を満たす最小の数値</returns> public static long BinarySearch(long low, long high, Func<long, bool> expression) { while (low < high) { long middle = (high - low) / 2 + low; if (!expression(middle)) high = middle; else low = middle + 1; } return high; } /// <summary> /// 指定した値以上の先頭のインデクスを返します。 /// </summary> /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="start">開始インデクス [inclusive]</param> /// <param name="end">終了インデクス [exclusive]</param> /// <param name="value">検索する値</param> /// <param name="comparer">比較関数(インターフェイス)</param> /// <returns>指定した値以上の先頭のインデクス</returns> public static int LowerBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; while (low < high) { var mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) < 0) low = mid + 1; else high = mid; } return low; } /// <summary> /// 指定した値以上の先頭のインデクスを返します。 /// </summary> /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="value">検索する値</param> /// <returns>指定した値以上の先頭のインデクス</returns> public static int LowerBound<T>(T[] arr, T value) where T : IComparable { return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default); } /// <summary> /// 指定した値より大きい先頭のインデクスを返します。 /// </summary> /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="start">開始インデクス [inclusive]</param> /// <param name="end">終了インデクス [exclusive]</param> /// <param name="value">検索する値</param> /// <param name="comparer">比較関数(インターフェイス)</param> /// <returns>指定した値より大きい先頭のインデクス</returns> public static int UpperBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; while (low < high) { var mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) <= 0) low = mid + 1; else high = mid; } return low; } /// <summary> /// 指定した値より大きい先頭のインデクスを返します。 /// </summary>Z /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="value">検索する値</param> /// <returns>指定した値より大きい先頭のインデクス</returns> public static int UpperBound<T>(T[] arr, T value) { return UpperBound(arr, 0, arr.Length, value, Comparer<T>.Default); } public static IEnumerable<TResult> SelectNotNull<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TResult> func) => source.Where(val => val != null).Select(func); public static IEnumerable<TSource> WhereNotNull<TSource>(this IEnumerable<TSource> source) => source.Where(val => val != null); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] ArrayOf<T>(params T[] arr) => arr; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<T> ListOf<T>(params T[] arr) => new List<T>(arr); public static IEnumerable<TResult> Repeat<TResult>(TResult value) { while (true) yield return value; // ReSharper disable once IteratorNeverReturns } public static IEnumerable<TResult> Repeat<TResult>(TResult value, int count) => Enumerable.Repeat(value, count); [SuppressMessage("ReSharper", "PossibleMultipleEnumeration")] public static IEnumerable<TResult> Repeat<TResult>(this IEnumerable<TResult> source, int count) { if (source == null) throw new ArgumentNullException(nameof(source)); if (count < 0) throw new ArgumentOutOfRangeException(nameof(count)); for (int i = 0; i < count; i++) foreach (var v in source) yield return v; } [SuppressMessage("ReSharper", "PossibleMultipleEnumeration")] public static IEnumerable<TResult> Repeat<TResult>(this IEnumerable<TResult> source) { if (source == null) throw new ArgumentNullException(nameof(source)); while (true) foreach (var v in source) yield return v; } /// <summary> /// 文字の配列を文字列に変換します。 /// </summary> /// <param name="source">文字の配列</param> /// <returns>変換した文字列</returns> public static string AsString(this IEnumerable<char> source) => new string(source.ToArray()); /// <summary> /// <see cref="source"/> の累積和を返します。 /// </summary> /// <returns><see cref="source"/> の累積和</returns> public static IEnumerable<long> CumSum(this IEnumerable<long> source) { long sum = 0; foreach (var item in source) yield return sum += item; } /// <summary> /// <see cref="source"/> の累積和を返します。 /// </summary> /// <returns><see cref="source"/> の累積和</returns> public static IEnumerable<int> CumSum(this IEnumerable<int> source) { int sum = 0; foreach (var item in source) yield return sum += item; } /// <summary> /// <see cref="value"/>が l以上 r未満の範囲に含まれているかを返します。 /// </summary> /// <typeparam name="T">要素の型</typeparam> /// <param name="value">判定する値</param> /// <param name="l">下限の値 (含まれる)</param> /// <param name="r">上限の値 (含まれない)</param> /// <returns><see cref="value"/> が指定した範囲に含まれているか</returns> public static bool IsIn<T>(this T value, T l, T r) where T : IComparable<T> { if (l.CompareTo(r) > 0) throw new ArgumentException(); return l.CompareTo(value) <= 0 && value.CompareTo(r) < 0; } /// <summary> /// <see cref="start"/> 以上 <see cref="end"/> 未満の値を <see cref="step"/> ずつ増やした結果を列挙します。 /// </summary> /// <param name="start">値の下限 (含まれる)</param> /// <param name="end">値の上限 (含まれない)</param> /// <param name="step">1要素ごとに増やす値</param> /// <returns>範囲の結果</returns> public static IEnumerable<int> Range(int start, int end, int step = 1) { for (var i = start; i < end; i += step) yield return i; } /// <summary> /// 0 以上 <see cref="end"/> 未満の値を 1 ずつ増やした結果を列挙します。 /// </summary> /// <param name="end">値の上限 (含まれない)</param> /// <returns>範囲の結果</returns> public static IEnumerable<int> Range(int end) => Range(0, end); /// <summary> /// <see cref="start"/> 以上 <see cref="end"/> 未満の値を <see cref="step"/> ずつ増やした結果を逆順に列挙します。 /// </summary> /// <param name="start">値の下限 (含まれる)</param> /// <param name="end">値の上限 (含まれない)</param> /// <param name="step">1要素ごとに増やす値</param> /// <returns>範囲の結果</returns> public static IEnumerable<int> RangeReverse(int start, int end, int step = 1) { for (var i = end - 1; i >= start; i -= step) yield return i; } /// <summary> /// 0 以上 <see cref="end"/> 未満の値を 1 ずつ増やした結果を逆順に列挙します。 /// </summary> /// <param name="end">値の上限 (含まれない)</param> /// <returns>範囲の結果</returns> public static IEnumerable<int> RangeReverse(int end) => RangeReverse(0, end); /// <summary> /// 指定した配列をコピーして昇順ソートします。(非破壊的) /// </summary> /// <typeparam name="T">ソートする配列の型</typeparam> /// <param name="arr">ソートする配列</param> /// <returns>ソートされた配列</returns> public static T[] Sort<T>(this T[] arr) { var array = new T[arr.Length]; arr.CopyTo(array, 0); Array.Sort(array); return array; } /// <summary> /// 指定した配列をコピーして降順ソートします。(非破壊的) /// </summary> /// <typeparam name="T">ソートする配列の型</typeparam> /// <param name="arr">ソートする配列</param> /// <returns>ソートされた配列</returns> public static T[] SortDescending<T>(this T[] arr) { var array = new T[arr.Length]; arr.CopyTo(array, 0); Array.Sort(array); Array.Reverse(array); return array; } public static double Log2(double x) => Log(x, 2); 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; } 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; } public static T Min<T>(params T[] col) => col.Min(); public static T Max<T>(params T[] col) => col.Max(); /// <summary> /// 要素数 (a, b) の、defaultValue で満たされたジャグ配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <param name="defaultValue">デフォルト値</param> /// <returns>指定した条件で初期化された配列</returns> public static T[][] JaggedArray2D<T>(int a, int b, T defaultValue = default(T)) { var ret = new T[a][]; for (int i = 0; i < a; i++) { ret[i] = Enumerable.Repeat(defaultValue, b).ToArray(); } return ret; } /// <summary> /// 要素数 (a, b) の,defaultValue で満たされた二次元配列を作成します。 /// </summary> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <param name="defaultValue">デフォルト値</param> /// <typeparam name="T">配列の型</typeparam> public static T[,] Array2D<T>(int a, int b, T defaultValue = default(T)) { var ret = new T[a, b]; for (int i = 0; i < a; i++) for (int j = 0; j < b; j++) ret[i, j] = defaultValue; return ret; } /// <summary> /// ジャグ配列を2次元配列に変換します。配列の各要素の長さがすべて同じである必要があります。 /// </summary> /// <param name="array">ジャグ配列</param> /// <typeparam name="T">二次元配列</typeparam> public static T[,] To2DArray<T>(this T[][] array) { if (!array.Any()) return new T[0, 0]; int len = array[0].Length; if (array.Any(x => x.Length != len)) throw new ArgumentException("array の各要素の長さが異なります。", nameof(array)); var ret = new T[array.Length, len]; for (int i = 0; i < array.Length; i++) { for (int j = 0; j < len; j++) { ret[i, j] = array[i][j]; } } return ret; } // public static vector<T> ToVector<T>(this IEnumerable<T> source) => new vector<T>(source); } public static class Input { private const char _separator = ' '; private static readonly Queue<string> _input = new Queue<string>(); private static readonly StreamReader sr = #if FILE new StreamReader("in.txt"); #else new StreamReader(Console.OpenStandardInput()); #endif public static string ReadLine => sr.ReadLine(); public static string ReadStr => Read; public static string Read { get { if (_input.Count != 0) return _input.Dequeue(); // ReSharper disable once PossibleNullReferenceException var tmp = sr.ReadLine().Split(_separator); foreach (var val in tmp) { _input.Enqueue(val); } return _input.Dequeue(); } } public static int ReadInt => int.Parse(Read); public static long ReadLong => long.Parse(Read); public static double ReadDouble => double.Parse(Read); public static string[] StrArray() => ReadLine.Split(' '); public static int[] IntArray() => ReadLine.Split(' ').Select(int.Parse).ToArray(); public static long[] LongArray() => ReadLine.Split(' ').Select(long.Parse).ToArray(); public static string[] StrArray(int n) { var ret = new string[n]; for (long i = 0; i < n; ++i) ret[i] = Read; return ret; } public static int[] IntArray(int n, int offset = 0, bool sorted = false) { var ret = StrArray(n).Select(x => int.Parse(x) + offset).ToArray(); if (sorted) Array.Sort(ret); return ret; } public static long[] LongArray(int n, long offset = 0, bool sorted = false) { var ret = StrArray(n).Select(x => long.Parse(x) + offset).ToArray(); if (sorted) Array.Sort(ret); return ret; } public static string[,] Str2DArray(int n, int m) { var ret = new string[n, m]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) ret[i, j] = ReadStr; return ret; } public static int[,] Int2DArray(int n, int m, int offset = 0) { var ret = new int[n, m]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) ret[i, j] = ReadInt + offset; return ret; } public static long[,] Long2DArray(int n, int m, long offset = 0) { var ret = new long[n, m]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) ret[i, j] = ReadLong + offset; return ret; } public static Tuple<string[], string[]> StrArrays2(int n) { var ret1 = new string[n]; var ret2 = new string[n]; for (int i = 0; i < n; i++) { ret1[i] = ReadStr; ret2[i] = ReadStr; } return Tuple.Create(ret1, ret2); } public static Tuple<int[], int[]> IntArrays2(int n, int offset1 = 0, int offset2 = 0) { var ret1 = new int[n]; var ret2 = new int[n]; for (int i = 0; i < n; i++) { ret1[i] = ReadInt + offset1; ret2[i] = ReadInt + offset2; } return Tuple.Create(ret1, ret2); } public static Tuple<long[], long[]> LongArrays2(int n, long offset1 = 0, long offset2 = 0) { var ret1 = new long[n]; var ret2 = new long[n]; for (int i = 0; i < n; i++) { ret1[i] = ReadLong + offset1; ret2[i] = ReadLong + offset2; } return Tuple.Create(ret1, ret2); } public static Tuple<string[], string[], string[]> StrArrays3(int n) { var ret1 = new string[n]; var ret2 = new string[n]; var ret3 = new string[n]; for (int i = 0; i < n; i++) { ret1[i] = ReadStr; ret2[i] = ReadStr; } return Tuple.Create(ret1, ret2, ret3); } public static Tuple<int[], int[], int[]> IntArrays3(int n, int offset1 = 0, int offset2 = 0, int offset3 = 0) { var ret1 = new int[n]; var ret2 = new int[n]; var ret3 = new int[n]; for (int i = 0; i < n; i++) { ret1[i] = ReadInt + offset1; ret2[i] = ReadInt + offset2; ret3[i] = ReadInt + offset3; } return Tuple.Create(ret1, ret2, ret3); } public static Tuple<long[], long[], long[]> LongArrays3(int n, long offset1 = 0, long offset2 = 0, long offset3 = 0) { var ret1 = new long[n]; var ret2 = new long[n]; var ret3 = new long[n]; for (int i = 0; i < n; i++) { ret1[i] = ReadLong + offset1; ret2[i] = ReadLong + offset2; ret3[i] = ReadLong + offset3; } return Tuple.Create(ret1, ret2, ret3); } private static bool TypeEquals<T, U>() => typeof(T) == typeof(U); private static T ChangeType<T, U>(U a) => (T) System.Convert.ChangeType(a, typeof(T)); private static T Convert<T>(string s) => TypeEquals<T, int>() ? ChangeType<T, int>(int.Parse(s)) : TypeEquals<T, long>() ? ChangeType<T, long>(long.Parse(s)) : TypeEquals<T, double>() ? ChangeType<T, double>(double.Parse(s)) : TypeEquals<T, char>() ? ChangeType<T, char>(s[0]) : ChangeType<T, string>(s); public static bool In<T>(out T a) { try { a = Convert<T>(Read); return true; } catch { a = default(T); return false; } } public static bool In<T, U>(out T a, out U b) { try { var ar = StrArray(2); a = Convert<T>(ar[0]); b = Convert<U>(ar[1]); return true; } catch { a = default(T); b = default(U); return false; } } public static bool In<T, U, V>(out T a, out U b, out V c) { try { var ar = StrArray(3); a = Convert<T>(ar[0]); b = Convert<U>(ar[1]); c = Convert<V>(ar[2]); return true; } catch { a = default(T); b = default(U); c = default(V); return false; } } public static bool In<T, U, V, W>(out T a, out U b, out V c, out W d) { try { var ar = StrArray(4); a = Convert<T>(ar[0]); b = Convert<U>(ar[1]); c = Convert<V>(ar[2]); d = Convert<W>(ar[3]); return true; } catch { a = default(T); b = default(U); c = default(V); d = default(W); return false; } } public static bool In<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { try { var ar = StrArray(5); a = Convert<T>(ar[0]); b = Convert<U>(ar[1]); c = Convert<V>(ar[2]); d = Convert<W>(ar[3]); e = Convert<X>(ar[4]); return true; } catch { a = default(T); b = default(U); c = default(V); d = default(W); e = default(X); return false; } } } public static class Output { public static void print<T>(T t) => Console.WriteLine(t); public static void print(params object[] o) => Console.WriteLine(o.Join(" ")); public static void PrintBool(bool val, string yes = "Yes", string no = "No") => Console.WriteLine(val ? yes : no); public static void PrintYn(bool val) => PrintBool(val); public static void PrintYN(bool val) => PrintBool(val, "YES", "NO"); public static void PrintPossible(bool val) => PrintBool(val, "Possible", "Impossible"); public static void PrintYay(bool val) => PrintBool(val, "Yay!", ":("); public static void PrintDebug(params object[] args) => Console.Error.WriteLine(string.Join(" ", args)); /// <summary> /// setter で設定された値を標準出力に出力します。 /// </summary> public static object cout { set { Console.WriteLine(value); } } /// <summary> /// Local環境のみ,setter で設定された値を標準出力に出力します。 /// </summary> public static object dout { set { #if LOCAL Console.WriteLine(value); #endif } } /// <summary> /// setter で設定された値を標準エラー出力に出力します。 /// </summary> public static object cerr { set { Console.Error.WriteLine(value); } } public const string endl = "\n"; } public class Program { public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false}; Console.SetOut(sw); new Solver().Main(); Console.Out.Flush(); } } [DebuggerDisplay("({first}, {second})")] public class Pair<T1, T2> : IComparable<Pair<T1, T2>>, IEquatable<Pair<T1, T2>> where T1 : IComparable<T1> where T2 : IComparable<T2> { public Pair(T1 first, T2 second) { this.first = first; this.second = second; } public T1 first; public T2 second; public int CompareTo(Pair<T1, T2> other) { if (ReferenceEquals(this, other)) return 0; if (ReferenceEquals(null, other)) return 1; var firstComparison = first.CompareTo(other.first); return firstComparison != 0 ? firstComparison : second.CompareTo(other.second); } public override string ToString() => $"({first}, {second})"; public bool Equals(Pair<T1, T2> other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return EqualityComparer<T1>.Default.Equals(first, other.first) && EqualityComparer<T2>.Default.Equals(second, other.second); } public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; return obj.GetType() == GetType() && Equals((Pair<T1, T2>) obj); } public override int GetHashCode() { unchecked { return (EqualityComparer<T1>.Default.GetHashCode(first) * 397) ^ EqualityComparer<T2>.Default.GetHashCode(second); } } } #endregion }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; using System.Numerics; using System.Runtime.CompilerServices; using System.Text; using static System.Math; using static Solve.Methods; using static Solve.Input; using static Solve.Output; using pii = Solve.Pair<int, int>; using pll = Solve.Pair<long, long>; using pli = Solve.Pair<long, int>; using pil = Solve.Pair<int, long>; using pss = Solve.Pair<string, string>; using psi = Solve.Pair<string, int>; using lint = System.Collections.Generic.List<int>; using llong = System.Collections.Generic.List<long>; using lstr = System.Collections.Generic.List<string>; using llint = System.Collections.Generic.List<System.Collections.Generic.List<int>>; using llstr = System.Collections.Generic.List<System.Collections.Generic.List<long>>; using lllong = System.Collections.Generic.List<System.Collections.Generic.List<string>>; using lii = System.Collections.Generic.List<Solve.Pair<int, int>>; using lll = System.Collections.Generic.List<Solve.Pair<long, long>>; using lli = System.Collections.Generic.List<Solve.Pair<long, int>>; using lil = System.Collections.Generic.List<Solve.Pair<int, long>>; using ll = System.Int64; namespace Solve { public class Solver { public void Main() { string S = ReadStr; int Q = ReadInt; var deque = new Deque<char>(); foreach(char c in S) deque.PushBack(c); bool isReversed = false; for (int i = 0; i < Q; i++) { int T = ReadInt; if (T == 1) { isReversed = !isReversed; } else { int F = ReadInt; char C = ReadStr[0]; if ((F == 1) ^ isReversed) deque.PushFront(C); else deque.PushBack(C); } } if (isReversed) { while (deque.Count > 0) { Console.Write(deque.PopBack()); } } else { while (deque.Count > 0) { Console.Write(deque.PopFront()); } } Console.WriteLine(); } // ReSharper disable UnusedMember.Local private const int MOD = (int) 1e9 + 7, INF = 1000000010; private const long LINF = 1000000000000000100; } // ライブラリ置き場ここから public class Deque<T> { T[] buf; int offset, capacity; public int Count { get; private set; } public Deque(int cap) { buf = new T[capacity = cap]; } public Deque() { buf = new T[capacity = 16]; } public T this[int index] { get { return buf[getIndex(index)]; } set { buf[getIndex(index)] = value; } } private int getIndex(int index) { if (index >= capacity) throw new IndexOutOfRangeException("out of range"); var ret = index + offset; if (ret >= capacity) ret -= capacity; return ret; } public void PushFront(T item) { if (Count == capacity) Extend(); if (--offset < 0) offset += buf.Length; buf[offset] = item; ++Count; } public T PopFront() { if (Count == 0) throw new InvalidOperationException("collection is empty"); --Count; var ret = buf[offset++]; if (offset >= capacity) offset -= capacity; return ret; } public void PushBack(T item) { if (Count == capacity) Extend(); var id = Count++ + offset; if (id >= capacity) id -= capacity; buf[id] = item; } public T PopBack() { if (Count == 0) throw new InvalidOperationException("collection is empty"); return buf[getIndex(--Count)]; } public void Insert(int index, T item) { if (index > Count) throw new IndexOutOfRangeException(); PushFront(item); for (int i = 0; i < index; i++) this[i] = this[i + 1]; this[index] = item; } public T RemoveAt(int index) { if (index < 0 || index >= Count) throw new IndexOutOfRangeException(); var ret = this[index]; for (int i = index; i > 0; i--) this[i] = this[i - 1]; PopFront(); return ret; } private void Extend() { T[] newBuffer = new T[capacity << 1]; if (offset > capacity - Count) { var len = buf.Length - offset; Array.Copy(buf, offset, newBuffer, 0, len); Array.Copy(buf, 0, newBuffer, len, Count - len); } else Array.Copy(buf, offset, newBuffer, 0, Count); buf = newBuffer; offset = 0; capacity <<= 1; } public T[] Items { get { var a = new T[Count]; for (int i = 0; i < Count; i++) a[i] = this[i]; return a; } } } // ライブラリ置き場ここまで #region Templete #if !LOCAL namespace Library { } #endif public static class Methods { public static readonly int[] dx = {-1, 0, 0, 1}; public static readonly int[] dy = {0, 1, -1, 0}; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Assert(bool b, string message = null) { if (!b) throw new Exception(message ?? "Assert failed."); } /* public static Comparison<T> greater<T>() where T : IComparable<T> => (a, b) => b.CompareTo(a); */ public static string JoinSpace<T>(this IEnumerable<T> source) => source.Join(" "); public static string JoinEndline<T>(this IEnumerable<T> source) => source.Join("\n"); public static string Join<T>(this IEnumerable<T> source, string s) => string.Join(s, source); public static string Join<T>(this IEnumerable<T> source, char c) => string.Join(c.ToString(), source); /// <summary> /// <see cref="Pair{T1, T2}"/> クラスのインスタンスを作成します。 /// </summary> /// <typeparam name="T1">firstの型</typeparam> /// <typeparam name="T2">secondの型</typeparam> /// <param name="first">firstの値</param> /// <param name="second">secondの値</param> /// <returns>作成した<see cref="Pair{T1, T2}"/> クラスのインスタンス</returns> public static Pair<T1, T2> make_pair<T1, T2>(T1 first, T2 second) where T1 : IComparable<T1> where T2 : IComparable<T2> => new Pair<T1, T2>(first, second); /// <summary>aとbをスワップします。</summary> public static void Swap<T>(ref T a, ref T b) where T : struct { var tmp = b; b = a; a = tmp; } /// <summary>aとbの最大公約数を求めます。</summary> /// <returns>aとbの最大公約数</returns> public static long Gcd(long a, long b) { while (true) { if (a < b) Swap(ref a, ref b); if (a % b == 0) return b; var x = a; a = b; b = x % b; } } /// <summary>aとbの最小公倍数を求めます。</summary> /// <returns>aとbの最小公倍数</returns> public static long Lcm(long a, long b) => a / Gcd(a, b) * b; /// <summary> /// 指定した数値が素数であるかを判定します。 /// </summary> /// <remarks>計算量 (sqrt(value)) </remarks> /// <param name="value">判定する数値</param> /// <returns>value が素数であるか</returns> public static bool IsPrime(long value) { if (value <= 1) return false; for (long i = 2; i * i <= value; i++) if (value % i == 0) return false; return true; } /// <summary> /// <see cref="a"/> ^ <see cref="b"/> (mod <see cref="p"/>) を求める /// </summary> /// <returns><see cref="a"/> ^ <see cref="b"/> (mod <see cref="p"/>) の値</returns> public static long PowMod(long a, long b, long p) { long res = 1; while (b > 0) { if (b % 2 != 0) res = res * a % p; a = a * a % p; b >>= 1; } return res; } /// <summary> /// mod pにおけるaの逆元を求めます。 /// </summary> /// <param name="a"></param> /// <param name="p">法</param> /// <returns></returns> public static long ModInv(long a, long p) => PowMod(a, p - 2, p); public static int DivCeil(int left, int right) => left / right + (left % right == 0 ? 0 : 1); public static long DivCeil(long left, long right) => left / right + (left % right == 0L ? 0L : 1L); /// <summary> /// src の順列を求めます。 /// </summary> /// <typeparam name="T">型</typeparam> /// <param name="src">順列を求める配列</param> /// <returns>src の順列</returns> public static IEnumerable<T[]> Permutations<T>(IEnumerable<T> src) { var ret = new List<T[]>(); Search(ret, new Stack<T>(), src.ToArray()); return ret; } private static void Search<T>(ICollection<T[]> perms, Stack<T> stack, T[] a) { int N = a.Length; if (N == 0) perms.Add(stack.Reverse().ToArray()); else { var b = new T[N - 1]; Array.Copy(a, 1, b, 0, N - 1); for (int i = 0; i < a.Length; ++i) { stack.Push(a[i]); Search(perms, stack, b); if (i < b.Length) b[i] = a[i]; stack.Pop(); } } } /// <summary> /// 指定した条件を満たす最小の数値を返します。 /// </summary> /// <param name="low">検索する数値の最小値</param> /// <param name="high">検索する数値の最大値</param> /// <param name="expression">条件</param> /// <returns>条件を満たす最小の数値</returns> public static long BinarySearch(long low, long high, Func<long, bool> expression) { while (low < high) { long middle = (high - low) / 2 + low; if (!expression(middle)) high = middle; else low = middle + 1; } return high; } /// <summary> /// 指定した値以上の先頭のインデクスを返します。 /// </summary> /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="start">開始インデクス [inclusive]</param> /// <param name="end">終了インデクス [exclusive]</param> /// <param name="value">検索する値</param> /// <param name="comparer">比較関数(インターフェイス)</param> /// <returns>指定した値以上の先頭のインデクス</returns> public static int LowerBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; while (low < high) { var mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) < 0) low = mid + 1; else high = mid; } return low; } /// <summary> /// 指定した値以上の先頭のインデクスを返します。 /// </summary> /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="value">検索する値</param> /// <returns>指定した値以上の先頭のインデクス</returns> public static int LowerBound<T>(T[] arr, T value) where T : IComparable { return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default); } /// <summary> /// 指定した値より大きい先頭のインデクスを返します。 /// </summary> /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="start">開始インデクス [inclusive]</param> /// <param name="end">終了インデクス [exclusive]</param> /// <param name="value">検索する値</param> /// <param name="comparer">比較関数(インターフェイス)</param> /// <returns>指定した値より大きい先頭のインデクス</returns> public static int UpperBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; while (low < high) { var mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) <= 0) low = mid + 1; else high = mid; } return low; } /// <summary> /// 指定した値より大きい先頭のインデクスを返します。 /// </summary>Z /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="value">検索する値</param> /// <returns>指定した値より大きい先頭のインデクス</returns> public static int UpperBound<T>(T[] arr, T value) { return UpperBound(arr, 0, arr.Length, value, Comparer<T>.Default); } public static IEnumerable<TResult> SelectNotNull<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TResult> func) => source.Where(val => val != null).Select(func); public static IEnumerable<TSource> WhereNotNull<TSource>(this IEnumerable<TSource> source) => source.Where(val => val != null); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] ArrayOf<T>(params T[] arr) => arr; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<T> ListOf<T>(params T[] arr) => new List<T>(arr); public static IEnumerable<TResult> Repeat<TResult>(TResult value) { while (true) yield return value; // ReSharper disable once IteratorNeverReturns } public static IEnumerable<TResult> Repeat<TResult>(TResult value, int count) => Enumerable.Repeat(value, count); [SuppressMessage("ReSharper", "PossibleMultipleEnumeration")] public static IEnumerable<TResult> Repeat<TResult>(this IEnumerable<TResult> source, int count) { if (source == null) throw new ArgumentNullException(nameof(source)); if (count < 0) throw new ArgumentOutOfRangeException(nameof(count)); for (int i = 0; i < count; i++) foreach (var v in source) yield return v; } [SuppressMessage("ReSharper", "PossibleMultipleEnumeration")] public static IEnumerable<TResult> Repeat<TResult>(this IEnumerable<TResult> source) { if (source == null) throw new ArgumentNullException(nameof(source)); while (true) foreach (var v in source) yield return v; } /// <summary> /// 文字の配列を文字列に変換します。 /// </summary> /// <param name="source">文字の配列</param> /// <returns>変換した文字列</returns> public static string AsString(this IEnumerable<char> source) => new string(source.ToArray()); /// <summary> /// <see cref="source"/> の累積和を返します。 /// </summary> /// <returns><see cref="source"/> の累積和</returns> public static IEnumerable<long> CumSum(this IEnumerable<long> source) { long sum = 0; foreach (var item in source) yield return sum += item; } /// <summary> /// <see cref="source"/> の累積和を返します。 /// </summary> /// <returns><see cref="source"/> の累積和</returns> public static IEnumerable<int> CumSum(this IEnumerable<int> source) { int sum = 0; foreach (var item in source) yield return sum += item; } /// <summary> /// <see cref="value"/>が l以上 r未満の範囲に含まれているかを返します。 /// </summary> /// <typeparam name="T">要素の型</typeparam> /// <param name="value">判定する値</param> /// <param name="l">下限の値 (含まれる)</param> /// <param name="r">上限の値 (含まれない)</param> /// <returns><see cref="value"/> が指定した範囲に含まれているか</returns> public static bool IsIn<T>(this T value, T l, T r) where T : IComparable<T> { if (l.CompareTo(r) > 0) throw new ArgumentException(); return l.CompareTo(value) <= 0 && value.CompareTo(r) < 0; } /// <summary> /// <see cref="start"/> 以上 <see cref="end"/> 未満の値を <see cref="step"/> ずつ増やした結果を列挙します。 /// </summary> /// <param name="start">値の下限 (含まれる)</param> /// <param name="end">値の上限 (含まれない)</param> /// <param name="step">1要素ごとに増やす値</param> /// <returns>範囲の結果</returns> public static IEnumerable<int> Range(int start, int end, int step = 1) { for (var i = start; i < end; i += step) yield return i; } /// <summary> /// 0 以上 <see cref="end"/> 未満の値を 1 ずつ増やした結果を列挙します。 /// </summary> /// <param name="end">値の上限 (含まれない)</param> /// <returns>範囲の結果</returns> public static IEnumerable<int> Range(int end) => Range(0, end); /// <summary> /// <see cref="start"/> 以上 <see cref="end"/> 未満の値を <see cref="step"/> ずつ増やした結果を逆順に列挙します。 /// </summary> /// <param name="start">値の下限 (含まれる)</param> /// <param name="end">値の上限 (含まれない)</param> /// <param name="step">1要素ごとに増やす値</param> /// <returns>範囲の結果</returns> public static IEnumerable<int> RangeReverse(int start, int end, int step = 1) { for (var i = end - 1; i >= start; i -= step) yield return i; } /// <summary> /// 0 以上 <see cref="end"/> 未満の値を 1 ずつ増やした結果を逆順に列挙します。 /// </summary> /// <param name="end">値の上限 (含まれない)</param> /// <returns>範囲の結果</returns> public static IEnumerable<int> RangeReverse(int end) => RangeReverse(0, end); /// <summary> /// 指定した配列をコピーして昇順ソートします。(非破壊的) /// </summary> /// <typeparam name="T">ソートする配列の型</typeparam> /// <param name="arr">ソートする配列</param> /// <returns>ソートされた配列</returns> public static T[] Sort<T>(this T[] arr) { var array = new T[arr.Length]; arr.CopyTo(array, 0); Array.Sort(array); return array; } /// <summary> /// 指定した配列をコピーして降順ソートします。(非破壊的) /// </summary> /// <typeparam name="T">ソートする配列の型</typeparam> /// <param name="arr">ソートする配列</param> /// <returns>ソートされた配列</returns> public static T[] SortDescending<T>(this T[] arr) { var array = new T[arr.Length]; arr.CopyTo(array, 0); Array.Sort(array); Array.Reverse(array); return array; } public static double Log2(double x) => Log(x, 2); 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; } 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; } public static T Min<T>(params T[] col) => col.Min(); public static T Max<T>(params T[] col) => col.Max(); /// <summary> /// 要素数 (a, b) の、defaultValue で満たされたジャグ配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <param name="defaultValue">デフォルト値</param> /// <returns>指定した条件で初期化された配列</returns> public static T[][] JaggedArray2D<T>(int a, int b, T defaultValue = default(T)) { var ret = new T[a][]; for (int i = 0; i < a; i++) { ret[i] = Enumerable.Repeat(defaultValue, b).ToArray(); } return ret; } /// <summary> /// 要素数 (a, b) の,defaultValue で満たされた二次元配列を作成します。 /// </summary> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <param name="defaultValue">デフォルト値</param> /// <typeparam name="T">配列の型</typeparam> public static T[,] Array2D<T>(int a, int b, T defaultValue = default(T)) { var ret = new T[a, b]; for (int i = 0; i < a; i++) for (int j = 0; j < b; j++) ret[i, j] = defaultValue; return ret; } /// <summary> /// ジャグ配列を2次元配列に変換します。配列の各要素の長さがすべて同じである必要があります。 /// </summary> /// <param name="array">ジャグ配列</param> /// <typeparam name="T">二次元配列</typeparam> public static T[,] To2DArray<T>(this T[][] array) { if (!array.Any()) return new T[0, 0]; int len = array[0].Length; if (array.Any(x => x.Length != len)) throw new ArgumentException("array の各要素の長さが異なります。", nameof(array)); var ret = new T[array.Length, len]; for (int i = 0; i < array.Length; i++) { for (int j = 0; j < len; j++) { ret[i, j] = array[i][j]; } } return ret; } // public static vector<T> ToVector<T>(this IEnumerable<T> source) => new vector<T>(source); } public static class Input { private const char _separator = ' '; private static readonly Queue<string> _input = new Queue<string>(); private static readonly StreamReader sr = #if FILE new StreamReader("in.txt"); #else new StreamReader(Console.OpenStandardInput()); #endif public static string ReadLine => sr.ReadLine(); public static string ReadStr => Read; public static string Read { get { if (_input.Count != 0) return _input.Dequeue(); // ReSharper disable once PossibleNullReferenceException var tmp = sr.ReadLine().Split(_separator); foreach (var val in tmp) { _input.Enqueue(val); } return _input.Dequeue(); } } public static int ReadInt => int.Parse(Read); public static long ReadLong => long.Parse(Read); public static double ReadDouble => double.Parse(Read); public static string[] StrArray() => ReadLine.Split(' '); public static int[] IntArray() => ReadLine.Split(' ').Select(int.Parse).ToArray(); public static long[] LongArray() => ReadLine.Split(' ').Select(long.Parse).ToArray(); public static string[] StrArray(int n) { var ret = new string[n]; for (long i = 0; i < n; ++i) ret[i] = Read; return ret; } public static int[] IntArray(int n, int offset = 0, bool sorted = false) { var ret = StrArray(n).Select(x => int.Parse(x) + offset).ToArray(); if (sorted) Array.Sort(ret); return ret; } public static long[] LongArray(int n, long offset = 0, bool sorted = false) { var ret = StrArray(n).Select(x => long.Parse(x) + offset).ToArray(); if (sorted) Array.Sort(ret); return ret; } public static string[,] Str2DArray(int n, int m) { var ret = new string[n, m]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) ret[i, j] = ReadStr; return ret; } public static int[,] Int2DArray(int n, int m, int offset = 0) { var ret = new int[n, m]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) ret[i, j] = ReadInt + offset; return ret; } public static long[,] Long2DArray(int n, int m, long offset = 0) { var ret = new long[n, m]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) ret[i, j] = ReadLong + offset; return ret; } public static Tuple<string[], string[]> StrArrays2(int n) { var ret1 = new string[n]; var ret2 = new string[n]; for (int i = 0; i < n; i++) { ret1[i] = ReadStr; ret2[i] = ReadStr; } return Tuple.Create(ret1, ret2); } public static Tuple<int[], int[]> IntArrays2(int n, int offset1 = 0, int offset2 = 0) { var ret1 = new int[n]; var ret2 = new int[n]; for (int i = 0; i < n; i++) { ret1[i] = ReadInt + offset1; ret2[i] = ReadInt + offset2; } return Tuple.Create(ret1, ret2); } public static Tuple<long[], long[]> LongArrays2(int n, long offset1 = 0, long offset2 = 0) { var ret1 = new long[n]; var ret2 = new long[n]; for (int i = 0; i < n; i++) { ret1[i] = ReadLong + offset1; ret2[i] = ReadLong + offset2; } return Tuple.Create(ret1, ret2); } public static Tuple<string[], string[], string[]> StrArrays3(int n) { var ret1 = new string[n]; var ret2 = new string[n]; var ret3 = new string[n]; for (int i = 0; i < n; i++) { ret1[i] = ReadStr; ret2[i] = ReadStr; } return Tuple.Create(ret1, ret2, ret3); } public static Tuple<int[], int[], int[]> IntArrays3(int n, int offset1 = 0, int offset2 = 0, int offset3 = 0) { var ret1 = new int[n]; var ret2 = new int[n]; var ret3 = new int[n]; for (int i = 0; i < n; i++) { ret1[i] = ReadInt + offset1; ret2[i] = ReadInt + offset2; ret3[i] = ReadInt + offset3; } return Tuple.Create(ret1, ret2, ret3); } public static Tuple<long[], long[], long[]> LongArrays3(int n, long offset1 = 0, long offset2 = 0, long offset3 = 0) { var ret1 = new long[n]; var ret2 = new long[n]; var ret3 = new long[n]; for (int i = 0; i < n; i++) { ret1[i] = ReadLong + offset1; ret2[i] = ReadLong + offset2; ret3[i] = ReadLong + offset3; } return Tuple.Create(ret1, ret2, ret3); } private static bool TypeEquals<T, U>() => typeof(T) == typeof(U); private static T ChangeType<T, U>(U a) => (T) System.Convert.ChangeType(a, typeof(T)); private static T Convert<T>(string s) => TypeEquals<T, int>() ? ChangeType<T, int>(int.Parse(s)) : TypeEquals<T, long>() ? ChangeType<T, long>(long.Parse(s)) : TypeEquals<T, double>() ? ChangeType<T, double>(double.Parse(s)) : TypeEquals<T, char>() ? ChangeType<T, char>(s[0]) : ChangeType<T, string>(s); public static bool In<T>(out T a) { try { a = Convert<T>(Read); return true; } catch { a = default(T); return false; } } public static bool In<T, U>(out T a, out U b) { try { var ar = StrArray(2); a = Convert<T>(ar[0]); b = Convert<U>(ar[1]); return true; } catch { a = default(T); b = default(U); return false; } } public static bool In<T, U, V>(out T a, out U b, out V c) { try { var ar = StrArray(3); a = Convert<T>(ar[0]); b = Convert<U>(ar[1]); c = Convert<V>(ar[2]); return true; } catch { a = default(T); b = default(U); c = default(V); return false; } } public static bool In<T, U, V, W>(out T a, out U b, out V c, out W d) { try { var ar = StrArray(4); a = Convert<T>(ar[0]); b = Convert<U>(ar[1]); c = Convert<V>(ar[2]); d = Convert<W>(ar[3]); return true; } catch { a = default(T); b = default(U); c = default(V); d = default(W); return false; } } public static bool In<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { try { var ar = StrArray(5); a = Convert<T>(ar[0]); b = Convert<U>(ar[1]); c = Convert<V>(ar[2]); d = Convert<W>(ar[3]); e = Convert<X>(ar[4]); return true; } catch { a = default(T); b = default(U); c = default(V); d = default(W); e = default(X); return false; } } } public static class Output { public static void print<T>(T t) => Console.WriteLine(t); public static void print(params object[] o) => Console.WriteLine(o.Join(" ")); public static void PrintBool(bool val, string yes = "Yes", string no = "No") => Console.WriteLine(val ? yes : no); public static void PrintYn(bool val) => PrintBool(val); public static void PrintYN(bool val) => PrintBool(val, "YES", "NO"); public static void PrintPossible(bool val) => PrintBool(val, "Possible", "Impossible"); public static void PrintYay(bool val) => PrintBool(val, "Yay!", ":("); public static void PrintDebug(params object[] args) => Console.Error.WriteLine(string.Join(" ", args)); /// <summary> /// setter で設定された値を標準出力に出力します。 /// </summary> public static object cout { set { Console.WriteLine(value); } } /// <summary> /// Local環境のみ,setter で設定された値を標準出力に出力します。 /// </summary> public static object dout { set { #if LOCAL Console.WriteLine(value); #endif } } /// <summary> /// setter で設定された値を標準エラー出力に出力します。 /// </summary> public static object cerr { set { Console.Error.WriteLine(value); } } public const string endl = "\n"; } public class Program { public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false}; Console.SetOut(sw); new Solver().Main(); Console.Out.Flush(); } } [DebuggerDisplay("({first}, {second})")] public class Pair<T1, T2> : IComparable<Pair<T1, T2>>, IEquatable<Pair<T1, T2>> where T1 : IComparable<T1> where T2 : IComparable<T2> { public Pair(T1 first, T2 second) { this.first = first; this.second = second; } public T1 first; public T2 second; public int CompareTo(Pair<T1, T2> other) { if (ReferenceEquals(this, other)) return 0; if (ReferenceEquals(null, other)) return 1; var firstComparison = first.CompareTo(other.first); return firstComparison != 0 ? firstComparison : second.CompareTo(other.second); } public override string ToString() => $"({first}, {second})"; public bool Equals(Pair<T1, T2> other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return EqualityComparer<T1>.Default.Equals(first, other.first) && EqualityComparer<T2>.Default.Equals(second, other.second); } public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; return obj.GetType() == GetType() && Equals((Pair<T1, T2>) obj); } public override int GetHashCode() { unchecked { return (EqualityComparer<T1>.Default.GetHashCode(first) * 397) ^ EqualityComparer<T2>.Default.GetHashCode(second); } } } #endregion }
[["-", 0, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["-", 0, 57, 75, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 75, 1, 0, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 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
6,147
14
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { LinkedList<string> answer = new LinkedList<string>(); answer.AddLast(Console.ReadLine()); bool reverse = false; long Q = long.Parse(Console.ReadLine()); for (var i = 0; i < Q; i++) { var input = Console.ReadLine().Split(' '); switch (input[0]) { case "1": reverse = !reverse; continue; case "2": switch (input[1]) { case "1": if (reverse) answer.AddLast(input[2]); else answer.AddFirst(input[2]); break; case "2": if (reverse) answer.AddFirst(input[2]); else answer.AddLast(input[2]); break; default: break; } break; default: break; } } var ans = answer.ToArray(); if (reverse) { for (var i = ans.Length - 1; i >= 0; i--) { Console.Write(ans[i]); } } else { for (var i = 0; i < ans.Length; i++) { Console.Write(ans[i]); } } Console.WriteLine(); } }
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { LinkedList<string> answer = new LinkedList<string>(); foreach (var c in Console.ReadLine()) { answer.AddLast(c.ToString()); } bool reverse = false; long Q = long.Parse(Console.ReadLine()); for (var i = 0; i < Q; i++) { var input = Console.ReadLine().Split(' '); switch (input[0]) { case "1": reverse = !reverse; continue; case "2": switch (input[1]) { case "1": if (reverse) answer.AddLast(input[2]); else answer.AddFirst(input[2]); break; case "2": if (reverse) answer.AddFirst(input[2]); else answer.AddLast(input[2]); break; default: break; } break; default: break; } } var ans = answer.ToArray(); if (reverse) { for (var i = ans.Length - 1; i >= 0; i--) { Console.Write(ans[i]); } } else { for (var i = 0; i < ans.Length; i++) { Console.Write(ans[i]); } } Console.WriteLine(); } }
[["+", 8, 201, 0, 195, 8, 196, 0, 210, 0, 266], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 0, 24], ["+", 0, 195, 8, 196, 0, 210, 39, 216, 0, 217], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 31, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 0, 267], ["+", 8, 196, 0, 210, 12, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 210, 12, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 210, 12, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 210, 12, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 210, 12, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 0, 25], ["+", 0, 195, 8, 196, 0, 210, 8, 196, 0, 45], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 210, 8, 196, 0, 46]]
8
297
17
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main(string[] args) { var s = Console.ReadLine(); var q = int.Parse(Console.ReadLine()); var flag = true; var list = new LinkedList<string>(); list.AddLast(s); for (var i = 0; i < q; i++) { var query = Console.ReadLine().Split(); if (query[0] == "1") { flag = !flag; continue; } else if (query[1] == "1") { if (flag) list.AddFirst(query[2]); else list.AddLast(query[2]); } else if (query[1] == "2") { if (flag) list.AddLast(query[2]); else list.AddFirst(query[2]); } } var array = list.ToArray(); var sb = new StringBuilder(); if (flag) { for (var i = 0; i < array.Length; i++) { sb.Append(array[i]); } } else { for (var i = array.Length - 1; i >= 0; i--) { sb.Append(array[i]); } } Console.WriteLine(sb.ToString()); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main(string[] args) { var s = Console.ReadLine(); var q = int.Parse(Console.ReadLine()); var flag = true; var list = new LinkedList<string>(); foreach (var c in s) { list.AddLast(c.ToString()); } for (var i = 0; i < q; i++) { var query = Console.ReadLine().Split(); if (query[0] == "1") { flag = !flag; continue; } else if (query[1] == "1") { if (flag) list.AddFirst(query[2]); else list.AddLast(query[2]); } else if (query[1] == "2") { if (flag) list.AddLast(query[2]); else list.AddFirst(query[2]); } } var array = list.ToArray(); var sb = new StringBuilder(); if (flag) { for (var i = 0; i < array.Length; i++) { sb.Append(array[i]); } } else { for (var i = array.Length - 1; i >= 0; i--) { sb.Append(array[i]); } } Console.WriteLine(sb.ToString()); } }
[["+", 8, 201, 0, 195, 8, 196, 0, 210, 0, 266], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 0, 24], ["+", 0, 195, 8, 196, 0, 210, 39, 216, 0, 217], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 31, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 0, 267], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 0, 25], ["+", 0, 195, 8, 196, 0, 210, 8, 196, 0, 45], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 210, 8, 196, 0, 46]]
8
303
15
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace StringFormation { class Program { static void Main(string[] args) { bool hantenFlg = false; var first = Console.ReadLine().Split(' '); LinkedList<string> kotae = new LinkedList<string>(); foreach (var a in first) { kotae.AddLast(a); } var nagasa = int.Parse(Console.ReadLine().Split(' ')[0]); for (int i = 0; i < nagasa; i++) { var yarukoto = Console.ReadLine().Split(' '); if (yarukoto[0] == "1") { hantenFlg = Hanten(hantenFlg); } else { kotae = Tuika(kotae, int.Parse(yarukoto[1]), yarukoto[2], hantenFlg); } } StringBuilder sb = new StringBuilder(); if (hantenFlg) { foreach (var a in kotae.Reverse()) { sb.Append(a); } } else { foreach (var a in kotae) { sb.Append(a); } } Console.WriteLine(sb); } static bool Hanten(bool hantenFlg) { return !hantenFlg; } static LinkedList<string> Tuika(LinkedList<string> taisho, int sentoFlg, string moji, bool hantenFlg) { if (hantenFlg) { // 反転の状態 if (sentoFlg == 1) { // 末尾に追加 taisho.AddLast(moji); } else { // 先頭に追加 taisho.AddFirst(moji); } } else { // 通常の状態 if (sentoFlg == 1) { // 先頭に追加 taisho.AddFirst(moji); } else { // 末尾に追加 taisho.AddLast(moji); } } return taisho; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace StringFormation { class Program { static void Main(string[] args) { bool hantenFlg = false; var first = Console.ReadLine().Split(' '); LinkedList<string> kotae = new LinkedList<string>(); foreach (var a in first[0]) { kotae.AddLast(a.ToString()); } var nagasa = int.Parse(Console.ReadLine().Split(' ')[0]); for (int i = 0; i < nagasa; i++) { var yarukoto = Console.ReadLine().Split(' '); if (yarukoto[0] == "1") { hantenFlg = Hanten(hantenFlg); } else { kotae = Tuika(kotae, int.Parse(yarukoto[1]), yarukoto[2], hantenFlg); } } StringBuilder sb = new StringBuilder(); if (hantenFlg) { foreach (var a in kotae.Reverse()) { sb.Append(a); } } else { foreach (var a in kotae) { sb.Append(a); } } Console.WriteLine(sb); } static bool Hanten(bool hantenFlg) { return !hantenFlg; } static LinkedList<string> Tuika(LinkedList<string> taisho, int sentoFlg, string moji, bool hantenFlg) { if (hantenFlg) { // 反転の状態 if (sentoFlg == 1) { // 末尾に追加 taisho.AddLast(moji); } else { // 先頭に追加 taisho.AddFirst(moji); } } else { // 通常の状態 if (sentoFlg == 1) { // 先頭に追加 taisho.AddFirst(moji); } else { // 末尾に追加 taisho.AddLast(moji); } } return taisho; } } }
[["+", 8, 196, 0, 210, 12, 204, 206, 207, 0, 70], ["+", 0, 210, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 8, 196, 0, 210, 12, 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]]
8
358
7
using System; using System.Linq; using System.Collections.Generic; using System.Text; namespace AtCoder.Contests.ABC158 { /// <summary> /// /// </summary> static class D { static void Main(string[] args) { var s = Console.ReadLine(); var q = ReadInt(); var forward = true; var f = new StringBuilder(); var b = new StringBuilder(); for (int i = 0; i < q; i++) { var qs = Console.ReadLine().Split(); if (qs.Length == 1) { forward = !forward; continue; } var f1 = qs[1] == "1"; if (forward ^ f1) { f.Append(qs[2]); } else { b.Append(qs[2]); } } if (forward) { var ss = f.ToString(); for (int i = ss.Length - 1; i >= 0; i--) { Console.Write(ss[i]); } Console.Write(s); Console.Write(b.ToString()); } else { var ss = b.ToString(); for (int i = ss.Length - 1; i >= 0; i--) { Console.Write(ss[i]); } Console.Write(s); Console.Write(f.ToString()); } } #region Console 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 } }
using System; using System.Linq; using System.Collections.Generic; using System.Text; namespace AtCoder.Contests.ABC158 { /// <summary> /// /// </summary> static class D { static void Main(string[] args) { var s = Console.ReadLine(); var q = ReadInt(); var forward = true; var f = new StringBuilder(); var b = new StringBuilder(); for (int i = 0; i < q; i++) { var qs = Console.ReadLine().Split(); if (qs.Length == 1) { forward = !forward; continue; } var f1 = qs[1] == "1"; if (forward ^ f1) { b.Append(qs[2]); } else { f.Append(qs[2]); } } if (forward) { var ss = f.ToString(); for (int i = ss.Length - 1; i >= 0; i--) { Console.Write(ss[i]); } Console.Write(s); Console.Write(b.ToString()); } else { var ss = b.ToString(); for (int i = ss.Length - 1; i >= 0; i--) { Console.Write(ss[i]); } for (int i = s.Length - 1; i >= 0; i--) { Console.Write(s[i]); } Console.Write(f.ToString()); } } #region Console 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 } }
[["-", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 57, 75, 196, 0, 7, 0, 88], ["+", 8, 196, 0, 57, 75, 196, 0, 7, 0, 24], ["+", 0, 57, 75, 196, 0, 7, 10, 198, 39, 199], ["+", 75, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 16, 31, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 16, 31, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 16, 31, 214, 141, 22], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 8, 196, 0, 57, 75, 196, 0, 7, 0, 35], ["+", 0, 57, 75, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 57, 75, 196, 0, 7, 15, 16, 17, 20], ["+", 0, 57, 75, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 57, 75, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 57, 75, 196, 0, 7, 26, 223, 0, 68], ["+", 8, 196, 0, 57, 75, 196, 0, 7, 0, 25], ["+", 0, 57, 75, 196, 0, 7, 8, 196, 0, 45], ["+", 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, 57, 75, 196, 0, 7, 8, 196, 0, 46]]
8
656
27
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 line = Console.ReadLine(); int num = int.Parse(Console.ReadLine()); var mozi = new LinkedList<string>(); bool flag = false; foreach (var item in line) { mozi.AddLast(item.ToString()); } for (int i = 0; i < num; i++) { string[] input = Console.ReadLine().Split(' '); if (input[0] == "1") { flag = !flag; } else { if (input.Length < 3) { return; } if ((input[1] == "1" && flag == false) && (input[1] == "2" && flag == true)) { mozi.AddFirst(input[2]); } else { mozi.AddLast(input[2]); } } } var mozi2 = new List<string>(); if (!flag) { mozi2 = mozi.Reverse().ToList(); } else { mozi2 = mozi.ToList(); } var mozi3 = new StringBuilder(); foreach (var item in mozi2) { mozi3.Append(item); } Console.WriteLine(mozi3.ToString()); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Program { static void Main() { string line = Console.ReadLine(); int num = int.Parse(Console.ReadLine()); var mozi = new LinkedList<string>(); Boolean flag = false; foreach (var item in line) { mozi.AddLast(item.ToString()); } for (int i = 0; i < num; i++) { var input = Console.ReadLine().Split(' '); if (input[0] == "1") { flag = !flag; } else { if (input.Length < 3) { return; } if (((input[1] == "1") && flag == false) || ((input[1] == "2") && flag == true)) { mozi.AddFirst(input[2]); } else { mozi.AddLast(input[2]); } } } var mozi2 = new List<string>(); if (flag) { mozi2 = mozi.Reverse().ToList(); } else { mozi2 = mozi.ToList(); } var mozi3 = new StringBuilder(); foreach (var item in mozi2) { mozi3.Append(item); } Console.WriteLine(mozi3.ToString()); } } }
[["-", 0, 195, 54, 55, 0, 220, 39, 224, 39, 199], ["-", 54, 55, 0, 220, 39, 224, 225, 226, 0, 70], ["-", 54, 55, 0, 220, 39, 224, 225, 226, 0, 73], ["-", 8, 201, 0, 195, 54, 55, 0, 220, 141, 22], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 22], ["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 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, 39, 216, 0, 217], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 24], ["+", 15, 16, 31, 23, 0, 16, 31, 23, 0, 25], ["-", 0, 57, 75, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 17, 106], ["+", 15, 16, 12, 23, 0, 16, 31, 23, 0, 24], ["+", 15, 16, 12, 23, 0, 16, 31, 23, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 15, 241, 0, 111]]
8
305
17
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Program { static void Main(string[] args) { var S = Console.ReadLine(); var Q = Console.ReadLine().ToInt(); var l = new LinkedList<string>(); l.AddFirst(S); var isReverse = false; for (int i = 0; i < Q; i++) { var a = Console.ReadLine().Split(' '); var T = a[0].ToInt(); if (T == 1) { isReverse = !isReverse; } else { var F = a[1].ToInt(); var C = a[2]; if (F == 1) { if (isReverse) { l.AddLast(C); } else { l.AddFirst(C); } } else { if (isReverse) { l.AddFirst(C); } else { l.AddLast(C); } } } } var sb = new StringBuilder(); if (isReverse) { foreach (var item in l.Reverse()) { sb.Append(item); } } else { foreach (var item in l) { sb.Append(item); } } Console.WriteLine(sb.ToString()); } } public static class Extentions { public static int ToInt(this object obj) { return int.Parse(obj.ToString()); } public static decimal ToDecimal(this object obj) { return decimal.Parse(obj.ToString()); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Program { static void Main(string[] args) { var S = Console.ReadLine(); var Q = Console.ReadLine().ToInt(); var l = new LinkedList<string>(); foreach (var item in S) { l.AddLast(item.ToString()); } var isReverse = false; for (int i = 0; i < Q; i++) { var a = Console.ReadLine().Split(' '); var T = a[0].ToInt(); if (T == 1) { isReverse = !isReverse; } else { var F = a[1].ToInt(); var C = a[2]; if (F == 1) { if (isReverse) { l.AddLast(C); } else { l.AddFirst(C); } } else { if (isReverse) { l.AddFirst(C); } else { l.AddLast(C); } } } } var sb = new StringBuilder(); if (isReverse) { foreach (var item in l.Reverse()) { sb.Append(item); } } else { foreach (var item in l) { sb.Append(item); } } Console.WriteLine(sb.ToString()); } } public static class Extentions { public static int ToInt(this object obj) { return int.Parse(obj.ToString()); } public static decimal ToDecimal(this object obj) { return decimal.Parse(obj.ToString()); } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 210, 0, 266], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 0, 24], ["+", 0, 195, 8, 196, 0, 210, 39, 216, 0, 217], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 31, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 0, 267], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 0, 25], ["+", 0, 195, 8, 196, 0, 210, 8, 196, 0, 45], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 210, 8, 196, 0, 46]]
8
344
17
using System; using System.Collections.Generic; using System.Linq; namespace CSharp { class Program { static void Main() { var S = Console.ReadLine(); var Q = int.Parse(Console.ReadLine()); var flag = true; var ll = new LinkedList<char>(); ll.AddLast('*'); for (int i = 0; i < Q; i++) { var input = Console.ReadLine(); if (input[0] == '1') { if (flag) { flag = false; } else { flag = true; } continue; } var q = input.Split().ToArray(); if (flag) { if (q[1] == "1") { ll.AddLast(char.Parse(q[2])); } else { ll.AddFirst(char.Parse(q[2])); } } else { if (q[1] == "1") { ll.AddFirst(char.Parse(q[2])); } else { ll.AddLast(char.Parse(q[2])); } } } var str = new string(ll.ToArray()).Replace("*", S); Console.WriteLine(flag ? new string(str.Reverse().ToArray()) : str); } } }
using System; using System.Collections.Generic; using System.Linq; namespace CSharp { class Program { static void Main() { var S = Console.ReadLine(); var Q = int.Parse(Console.ReadLine()); var flag = true; var ll = new LinkedList<char>(); ll.AddLast('*'); for (int i = 0; i < Q; i++) { var input = Console.ReadLine(); if (input[0] == '1') { if (flag) { flag = false; } else { flag = true; } continue; } var q = input.Split().ToArray(); if (flag) { if (q[1] == "1") { ll.AddFirst(char.Parse(q[2])); } else { ll.AddLast(char.Parse(q[2])); } } else { if (q[1] == "1") { ll.AddLast(char.Parse(q[2])); } else { ll.AddFirst(char.Parse(q[2])); } } } var str = new string(ll.ToArray()).Replace("*", S); Console.WriteLine(flag ? str : new string(str.Reverse().ToArray())); } } }
[["-", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 64, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["-", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["-", 0, 213, 3, 4, 0, 28, 0, 41, 75, 22]]
8
294
12
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace AC { class Program { static void Main(string[] args) { var S = Read().ToCharArray(); var Q = ReadInt(); var S1 = new List<string>(); var S2 = new List<string>(); var right = true; var ans = ""; for (int i = 0; i < Q; i++) { var qry = ReadArrayString(); if (qry.Count() == 1) { right = !right; } else { var F = int.Parse(qry[1]); var C = qry[2]; if (right) { if (F == 1) S1.Add(C); else S2.Add(C); } else { if (F == 1) S2.Add(C); else S1.Add(C); } } } if (right) { S1.Reverse(); ans = string.Join("", S1) + string.Join("", S) + string.Join("", S2); } else { S.Reverse(); S2.Reverse(); ans = string.Join("", S2) + string.Join("", S) + string.Join("", S1); } Console.WriteLine(ans); Console.ReadKey(); } static string Read() { return Console.ReadLine(); } static int ReadInt() { return int.Parse(Read()); } static long ReadLong() { return long.Parse(Read()); } static string[] ReadArrayString() { return Read().Split(' '); } static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); } static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace AC { class Program { static void Main(string[] args) { var S = Read().ToList(); var Q = ReadInt(); var right = true; var S1 = new List<char>(); var S2 = new List<char>(); var ans = ""; for (int i = 0; i < Q; i++) { var qry = ReadArrayString(); if (qry.Count() == 1) { right = !right; } else { var F = int.Parse(qry[1]); var C = qry[2][0]; if (right) { if (F == 1) S1.Add(C); else S2.Add(C); } else { if (F == 1) S2.Add(C); else S1.Add(C); } } } if (right) { S1.Reverse(); ans = string.Join("", S1) + string.Join("", S) + string.Join("", S2); } else { S.Reverse(); S2.Reverse(); ans = string.Join("", S2) + string.Join("", S) + string.Join("", S1); } Console.WriteLine(ans); Console.ReadKey(); } static string Read() { return Console.ReadLine(); } static int ReadInt() { return int.Parse(Read()); } static long ReadLong() { return long.Parse(Read()); } static string[] ReadArrayString() { return Read().Split(' '); } static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); } static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); } } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 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, 146], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 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, 146], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 212, 0, 204, 205, 204, 206, 207, 0, 73], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 70], ["+", 0, 212, 0, 204, 206, 207, 0, 28, 0, 203]]
8
452
19
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using AtCoder.Algorithms; using AtCoder.Collections; using AtCoder.Extensions; using AtCoder.Mathematics; namespace AtCoder.ABC158 { public class A : Solver { public override void Solve() { var S = Console.ReadLine(); if (S.Distinct().Count() == 1) { Console.WriteLine("No"); } else { Console.WriteLine("Yes"); } } } public class B : Solver { public override void Solve() { var array = Scanner.ReadLongArray(); var N = array[0]; var A = array[1]; var B = array[2]; if (A == 0) { Console.WriteLine(0); return; } long sum = A + B; long count = N / sum; sum = sum * count; long blue = A * count; long red = B * count; while (sum < N) { if (A > 0) { if ((N - sum) > A) { blue += A; sum += A; } else { var delta = (N - sum); blue += delta; sum += delta; break; } } if (B > 0) { if ((N - sum) > B) { red += B; sum += B; } else { var delta = (N - sum); red += delta; sum += delta; break; } } } Console.WriteLine(blue); } } public class C : Solver { public override void Solve() { var array = Scanner.ReadIntArray(); var A = array[0]; var B = array[1]; var otA = (int)Math.Ceiling(A / 0.08m); var otA2 = (int)Math.Ceiling((A + 1) / 0.08m); var otB = (int)Math.Ceiling(B / 0.10m); var otB2 = (int)Math.Ceiling((B + 1) / 0.10m); var bSet = new MultiSet<int>(); for (int i = otB; i < otB2; i++) { bSet.Insert(i); } var ans = -1; for (int i = otA; i < otA2; i++) { var bInd = bSet.LowerBound(i); if (bInd < bSet.Count() && i == bSet[bInd]) { ans = i; break; } } Console.WriteLine(ans); } } public class D : Solver { public override void Solve() { var S = Console.ReadLine(); var Q = Scanner.ReadInt(); var deq = new Deque<char>(); for (int i = 0; i < S.Length; i++) { deq.PushBack(S[i]); } bool isReverse = false; for (int i = 0; i < Q; i++) { var q = Console.ReadLine(); if (q.StartsWith("1")) { isReverse = !isReverse; } else { var qArray = q.Split(); var F = qArray[1]; var C = qArray[2][0]; if (F == "1" ^ isReverse) { deq.PushFront(C); } else { deq.PushBack(C); } } } Console.WriteLine( new string(isReverse ? deq.Items : deq.Items.Reverse().ToArray())); } } public class E : Solver { public override void Solve() {} } public class F : Solver { public override void Solve() {} } } namespace AtCoder { public abstract class Solver { public abstract void Solve(); } class Program { static void Main(string[] args) { // var solver = new ABC158.A(); // var solver = new ABC158.B(); // var solver = new ABC158.C(); var solver = new ABC158.D(); // var solver = new ABC158.E(); // var solver = new ABC158.F(); solver.Solve(); } } } namespace AtCoder.Algorithms {} namespace AtCoder.Collections { public class Deque<T> { int dx; T[] buf; int mask; public int Count { get; private set; } public Deque() : this(8) {} public Deque(int capacity) { mask = capacity - 1; buf = new T[capacity]; } public T this[int index] { get { return buf[(dx + index) & mask]; } set { buf[(dx + index) & mask] = value; } } public void PushFront(T item) { if (Count == buf.Length) extend(); dx = (dx + buf.Length - 1) & mask; buf[dx] = item; Count++; } public T PopFront() { var ret = buf[dx = (dx + 1) & mask]; Count--; return ret; } public void PushBack(T item) { if (Count == buf.Length) extend(); buf[(dx + Count++) & mask] = item; } public T PopBack() { var ret = buf[(dx + --Count) & mask]; return ret; } public T Last() { return buf[(dx + Count - 1) & mask]; } public T First() { return buf[dx]; } void extend() { var nbuf = new T[buf.Length * 2]; for (int i = 0; i < buf.Length; i++) nbuf[i] = buf[(dx + i) & mask]; mask = mask * 2 + 1; dx = 0; buf = nbuf; } public void Clear() { Count = 0; } public bool Any() { return Count != 0; } public void Insert(int index, T item) { PushFront(item); for (int i = 0; i < index; i++) this[i] = this[i + 1]; this[index] = item; } public T RemoveAt(int index) { var ret = this[index]; for (int i = index; i > 0; i--) this[i] = this[i - 1]; PopFront(); return ret; } public T[] Items { get { var ret = new T[Count]; for (int i = 0; i < Count; i++) ret[i] = this[i]; return ret; } } } public class PriorityQueue<T> : IEnumerable<T> { private readonly List<T> _data = new List<T>(); private readonly IComparer<T> _comparer; private readonly bool _isDescending; public PriorityQueue(IComparer<T> comparer, bool isDescending = true) { _comparer = comparer; _isDescending = isDescending; } public PriorityQueue(Comparison<T> comparison, bool isDescending = true) : this(Comparer<T>.Create(comparison), isDescending) {} public PriorityQueue(bool isDescending = true) : this(Comparer<T>.Default, isDescending) {} public void Enqueue(T item) { _data.Add(item); var childIndex = _data.Count - 1; while (childIndex > 0) { var parentIndex = (childIndex - 1) / 2; if (Compare(_data[childIndex], _data[parentIndex]) >= 0) break; Swap(childIndex, parentIndex); childIndex = parentIndex; } } public T Dequeue() { var lastIndex = _data.Count - 1; var firstItem = _data[0]; _data[0] = _data[lastIndex]; _data.RemoveAt(lastIndex--); var parentIndex = 0; while (true) { var childIndex = parentIndex * 2 + 1; if (childIndex > lastIndex) break; var rightChild = childIndex + 1; if (rightChild <= lastIndex && Compare(_data[rightChild], _data[childIndex]) < 0) childIndex = rightChild; if (Compare(_data[parentIndex], _data[childIndex]) <= 0) break; Swap(parentIndex, childIndex); parentIndex = childIndex; } return firstItem; } public T Peek() { return _data[0]; } private void Swap(int a, int b) { var tmp = _data[a]; _data[a] = _data[b]; _data[b] = tmp; } private int Compare(T a, T b) { return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b); } public int Count => _data.Count; public IEnumerator<T> GetEnumerator() { return _data.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } public class PriorityQueue<TKey, TValue> : IEnumerable<TValue> { private readonly List<KeyValuePair<TKey, TValue>> _data = new List<KeyValuePair<TKey, TValue>>(); private readonly bool _isDescending; private readonly Func<TValue, TKey> _keySelector; private readonly IComparer<TKey> _keyComparer; public PriorityQueue(Func<TValue, TKey> keySelector, bool isDescending = true) : this(keySelector, Comparer<TKey>.Default, isDescending) {} public PriorityQueue(Func<TValue, TKey> keySelector, IComparer<TKey> keyComparer, bool isDescending = true) { _keySelector = keySelector; _keyComparer = keyComparer; _isDescending = isDescending; } public void Enqueue(TValue item) { _data.Add(new KeyValuePair<TKey, TValue>(_keySelector(item), item)); var childIndex = _data.Count - 1; while (childIndex > 0) { var parentIndex = (childIndex - 1) / 2; if (Compare(_data[childIndex].Key, _data[parentIndex].Key) >= 0) break; Swap(childIndex, parentIndex); childIndex = parentIndex; } } public TValue Dequeue() { var lastIndex = _data.Count - 1; var firstItem = _data[0]; _data[0] = _data[lastIndex]; _data.RemoveAt(lastIndex--); var parentIndex = 0; while (true) { var childIndex = parentIndex * 2 + 1; if (childIndex > lastIndex) break; var rightChild = childIndex + 1; if (rightChild <= lastIndex && Compare(_data[rightChild].Key, _data[childIndex].Key) < 0) childIndex = rightChild; if (Compare(_data[parentIndex].Key, _data[childIndex].Key) <= 0) break; Swap(parentIndex, childIndex); parentIndex = childIndex; } return firstItem.Value; } public TValue Peek() { return _data[0].Value; } private void Swap(int a, int b) { var tmp = _data[a]; _data[a] = _data[b]; _data[b] = tmp; } private int Compare(TKey a, TKey b) { return _isDescending ? _keyComparer.Compare(b, a) : _keyComparer.Compare(a, b); } public int Count => _data.Count; public IEnumerator<TValue> GetEnumerator() { return _data.Select(r => r.Value).GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } /// <summary> /// Self-Balancing Binary Search Tree /// (using Randamized BST) /// </summary> public class SB_BinarySearchTree<T> where T : IComparable { public class Node { public T Value; public Node LChild; public Node RChild; public int Count; public Node(T v) { Value = v; Count = 1; } } static readonly Random _rnd = new Random(); public static int Count(Node t) { return t == null ? 0 : t.Count; } static Node Update(Node t) { t.Count = Count(t.LChild) + Count(t.RChild) + 1; return t; } public static Node Merge(Node l, Node r) { if (l == null || r == null) return l == null ? r : l; if (Count(l) / (double)(Count(l) + Count(r)) > _rnd.NextDouble()) { l.RChild = Merge(l.RChild, r); return Update(l); } else { r.LChild = Merge(l, r.LChild); return Update(r); } } /// <summary> /// split as [0, k), [k, n) /// </summary> public static Tuple<Node, Node> Split(Node t, int k) { if (t == null) return new Tuple<Node, Node>(null, null); if (k <= Count(t.LChild)) { var s = Split(t.LChild, k); t.LChild = s.Item2; return new Tuple<Node, Node>(s.Item1, Update(t)); } else { var s = Split(t.RChild, k - Count(t.LChild) - 1); t.RChild = s.Item1; return new Tuple<Node, Node>(Update(t), s.Item2); } } public static Node Remove(Node t, T v) { if (Find(t, v) == null) return t; return RemoveAt(t, LowerBound(t, v)); } public static Node RemoveAt(Node t, int k) { var s = Split(t, k); var s2 = Split(s.Item2, 1); return Merge(s.Item1, s2.Item2); } public static bool Contains(Node t, T v) { return Find(t, v) != null; } public static Node Find(Node t, T v) { while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp > 0) t = t.LChild; else if (cmp < 0) t = t.RChild; else break; } return t; } public static Node FindByIndex(Node t, int idx) { if (t == null) return null; var currentIdx = Count(t) - Count(t.RChild) - 1; while (t != null) { if (currentIdx == idx) return t; if (currentIdx > idx) { t = t.LChild; currentIdx -= (Count(t == null ? null : t.RChild) + 1); } else { t = t.RChild; currentIdx += (Count(t == null ? null : t.LChild) + 1); } } return null; } public static int UpperBound(Node t, T v) { var torg = t; if (t == null) return -1; var ret = int.MaxValue; var idx = Count(t) - Count(t.RChild) - 1; while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp > 0) { ret = Math.Min(ret, idx); t = t.LChild; idx -= (Count(t == null ? null : t.RChild) + 1); } else if (cmp <= 0) { t = t.RChild; idx += (Count(t == null ? null : t.LChild) + 1); } } return ret == int.MaxValue ? Count(torg) : ret; } public static int LowerBound(Node t, T v) { var torg = t; if (t == null) return -1; var idx = Count(t) - Count(t.RChild) - 1; var ret = int.MaxValue; while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp >= 0) { if (cmp == 0) ret = Math.Min(ret, idx); t = t.LChild; if (t == null) ret = Math.Min(ret, idx); idx -= t == null ? 0 : (Count(t.RChild) + 1); } else if (cmp < 0) { t = t.RChild; idx += (Count(t == null ? null : t.LChild) + 1); if (t == null) return idx; } } return ret == int.MaxValue ? Count(torg) : ret; } public static Node Insert(Node t, T v) { var ub = LowerBound(t, v); return InsertByIdx(t, ub, v); } static Node InsertByIdx(Node t, int k, T v) { var s = Split(t, k); return Merge(Merge(s.Item1, new Node(v)), s.Item2); } public static IEnumerable<T> Enumerate(Node t) { var ret = new List<T>(); Enumerate(t, ret); return ret; } static void Enumerate(Node t, List<T> ret) { if (t == null) return; Enumerate(t.LChild, ret); ret.Add(t.Value); Enumerate(t.RChild, ret); } } public class Set<T> where T : IComparable { protected SB_BinarySearchTree<T>.Node _root; public T this[int idx] { get { return ElementAt(idx); } } public int Count() { return SB_BinarySearchTree<T>.Count(_root); } public virtual void Insert(T v) { if (_root == null) _root = new SB_BinarySearchTree<T>.Node(v); else { if (SB_BinarySearchTree<T>.Find(_root, v) != null) return; _root = SB_BinarySearchTree<T>.Insert(_root, v); } } public void Clear() { _root = null; } public void Remove(T v) { _root = SB_BinarySearchTree<T>.Remove(_root, v); } public bool Contains(T v) { return SB_BinarySearchTree<T>.Contains(_root, v); } public T ElementAt(int k) { var node = SB_BinarySearchTree<T>.FindByIndex(_root, k); if (node == null) throw new IndexOutOfRangeException(); return node.Value; } public int Count(T v) { return SB_BinarySearchTree<T>.UpperBound(_root, v) - SB_BinarySearchTree<T>.LowerBound(_root, v); } public int LowerBound(T v) { return SB_BinarySearchTree<T>.LowerBound(_root, v); } public int UpperBound(T v) { return SB_BinarySearchTree<T>.UpperBound(_root, v); } public Tuple<int, int> EqualRange(T v) { if (!Contains(v)) return new Tuple<int, int>(-1, -1); return new Tuple<int, int>(SB_BinarySearchTree<T>.LowerBound(_root, v), SB_BinarySearchTree<T>.UpperBound(_root, v) - 1); } public List<T> ToList() { return new List<T>(SB_BinarySearchTree<T>.Enumerate(_root)); } } public class MultiSet<T> : Set<T> where T : IComparable { public override void Insert(T v) { if (_root == null) _root = new SB_BinarySearchTree<T>.Node(v); else _root = SB_BinarySearchTree<T>.Insert(_root, v); } } public class UnionFind<T> { private Dictionary<T, T> _parent = new Dictionary<T, T>(); private Dictionary<T, int> _size = new Dictionary<T, int>(); public void Unite(T x, T y) { x = Root(x); y = Root(y); if (IsEqual(x, y)) return; var sx = Size(x); var sy = Size(y); if (sx < sy) { var t = x; x = y; y = t; } _size[x] += _size[y]; _size.Remove(y); _parent[y] = x; } public int Size(T x) { var p = Root(x); int s; if (_size.TryGetValue(p, out s)) { return s; } return _size[x] = 1; } public bool IsSameGroup(T x, T y) { return IsEqual(Root(x), Root(y)); } public bool IsRoot(T x) { return IsEqual(Root(x), x); } private T Root(T x) { T r; if (_parent.TryGetValue(x, out r)) { return _parent[x] = Root(r); } return x; } private bool IsEqual(T x, T y) { return EqualityComparer<T>.Default.Equals(x, y); } } } namespace AtCoder.Mathematics { public class MathEx { /// <summary> /// 最小公倍数 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> static long Lcm(long a, long b) { return a / Gcd(a, b) * b; } /// <summary> /// 最大公約数 /// </summary> /// <param name="m"></param> /// <param name="n"></param> /// <returns></returns> static long Gcd(long m, long n) { if (n == 0) return m; return Gcd(n, m % n); } } public struct ModInt { public const long Mod = (int)1e9 + 7; public long num; public ModInt(long n) { num = n; } public override string ToString() { return num.ToString(); } public static ModInt operator +(ModInt l, ModInt r) { l.num += r.num; if (l.num >= Mod) l.num -= Mod; return l; } public static ModInt operator -(ModInt l, ModInt r) { l.num -= r.num; if (l.num < 0) l.num += Mod; return l; } public static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.num * r.num % Mod); } public static ModInt operator /(ModInt l, ModInt r) { return l * Pow(r, Mod - 2); } public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) n += Mod; return new ModInt(n); } public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); } public static ModInt Pow(long v, long k) { long ret = 1; for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod) if ((k & 1) == 1) ret = ret * v % Mod; return new ModInt(ret); } public static ModInt Combination(long n, long r) { ModInt ans = 1; for (int i = 0; i < r; i++) { ans *= n - i; } for (int i = 1; i <= r; i++) { ans /= i; } return ans; } public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); } } } namespace AtCoder.Extensions { public static class Extension { static int BinarySearch<T>(IList<T> source, T value, IComparer<T> comparer, bool isLowerBound) { return BinarySearch(source, 0, source.Count - 1, value, comparer, isLowerBound); } static int BinarySearch<T>(IList<T> source, int start, int end, T value, IComparer<T> comparer, bool isLowerBound) { while (start <= end) { var mid = (start + end) / 2; var result = comparer.Compare(source[mid], value); if (result < 0 || (result == 0 && !isLowerBound)) start = mid + 1; else end = mid - 1; } return start; } public static int LowerBound<T>(this IList<T> source, T value, Comparison<T> f) => BinarySearch(source, value, Comparer<T>.Create(f), true); public static int LowerBound<T>(this IList<T> source, int start, T value, Comparison<T> f) => BinarySearch(source, start, source.Count - 1, value, Comparer<T>.Create(f), true); public static int LowerBound<T>(this IList<T> source, int start, int end, T value, Comparison<T> f) => BinarySearch(source, start, end, value, Comparer<T>.Create(f), true); public static int LowerBound<T>(this IList<T> source, T value) => BinarySearch(source, value, Comparer<T>.Default, true); public static int LowerBound<T>(this IList<T> source, int start, T value) => BinarySearch(source, start, source.Count - 1, value, Comparer<T>.Default, true); public static int LowerBound<T>(this IList<T> source, int start, int end, T value) => BinarySearch(source, start, end, value, Comparer<T>.Default, true); public static int UpperBound<T>(this IList<T> source, T value, Comparison<T> cmp) => BinarySearch(source, value, Comparer<T>.Create(cmp), false); public static int UpperBound<T>(this IList<T> source, int start, T value, Comparison<T> cmp) => BinarySearch(source, start, source.Count - 1, value, Comparer<T>.Create(cmp), false); public static int UpperBound<T>(this IList<T> source, int start, int end, T value, Comparison<T> cmp) => BinarySearch(source, start, end, value, Comparer<T>.Create(cmp), false); public static int UpperBound<T>(this IList<T> source, T value) => BinarySearch(source, value, Comparer<T>.Default, false); public static int UpperBound<T>(this IList<T> source, int start, T value) => BinarySearch(source, start, source.Count - 1, value, Comparer<T>.Default, false); public static int UpperBound<T>(this IList<T> source, int start, int end, T value) => BinarySearch(source, start, end, value, Comparer<T>.Default, false); public static PriorityQueue<T> AsPriorityQueue<T>(this IEnumerable<T> source, bool isDescending = true) { var queue = new PriorityQueue<T>(isDescending); foreach (var item in source) { queue.Enqueue(item); } return queue; } public static PriorityQueue<TKey, TSource> AsPriorityQueue<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, bool isDescending = true) { var queue = new PriorityQueue<TKey, TSource>(keySelector, isDescending); foreach (var item in source) { queue.Enqueue(item); } return queue; } public static bool ChangeMin<T>(this IList<T> source, int index, T value) where T : IComparable { var a = source[index]; if (a.CompareTo(value) > 0) { source[index] = value; return true; } return false; } public static bool ChangeMax<T>(this IList<T> source, int index, T value) where T : IComparable { var a = source[index]; if (a.CompareTo(value) < 0) { source[index] = value; return true; } return false; } } public static class Scanner { public static string ReadString() => Console.ReadLine(); public static int ReadInt() => int.Parse(Console.ReadLine()); public static long ReadLong() => long.Parse(Console.ReadLine()); public static double ReadDouble() => double.Parse(Console.ReadLine()); public static decimal ReadDecimal() => decimal.Parse(Console.ReadLine()); public static string[] ReadStringArray() => Console.ReadLine().Split().ToArray(); public static string[] ReadStringArray(int n) => Enumerable.Range(0, n).Select(_ => Console.ReadLine()).ToArray(); public static int[] ReadIntArray() => Console.ReadLine().Split().Select(int.Parse).ToArray(); public static int[] ReadIntArray(int n) => Enumerable.Range(0, n).Select(_ => ReadInt()).ToArray(); public static long[] ReadLongArray() => Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); public static long[] ReadLongArray(int n) => Enumerable.Range(0, n).Select(_ => ReadLong()).ToArray(); public static double[] ReadDoubleArray() => Console.ReadLine().Split().Select(double.Parse).ToArray(); public static double[] ReadDoubleArray(int n) => Enumerable.Range(0, n).Select(_ => ReadDouble()).ToArray(); public static decimal[] ReadDecimalArray() => Console.ReadLine().Split().Select(decimal.Parse).ToArray(); public static decimal[] ReadDecimalArray(int n) => Enumerable.Range(0, n).Select(_ => ReadDecimal()).ToArray(); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using AtCoder.Algorithms; using AtCoder.Collections; using AtCoder.Extensions; using AtCoder.Mathematics; namespace AtCoder.ABC158 { public class A : Solver { public override void Solve() { var S = Console.ReadLine(); if (S.Distinct().Count() == 1) { Console.WriteLine("No"); } else { Console.WriteLine("Yes"); } } } public class B : Solver { public override void Solve() { var array = Scanner.ReadLongArray(); var N = array[0]; var A = array[1]; var B = array[2]; if (A == 0) { Console.WriteLine(0); return; } long sum = A + B; long count = N / sum; sum = sum * count; long blue = A * count; long red = B * count; while (sum < N) { if (A > 0) { if ((N - sum) > A) { blue += A; sum += A; } else { var delta = (N - sum); blue += delta; sum += delta; break; } } if (B > 0) { if ((N - sum) > B) { red += B; sum += B; } else { var delta = (N - sum); red += delta; sum += delta; break; } } } Console.WriteLine(blue); } } public class C : Solver { public override void Solve() { var array = Scanner.ReadIntArray(); var A = array[0]; var B = array[1]; var otA = (int)Math.Ceiling(A / 0.08m); var otA2 = (int)Math.Ceiling((A + 1) / 0.08m); var otB = (int)Math.Ceiling(B / 0.10m); var otB2 = (int)Math.Ceiling((B + 1) / 0.10m); var bSet = new MultiSet<int>(); for (int i = otB; i < otB2; i++) { bSet.Insert(i); } var ans = -1; for (int i = otA; i < otA2; i++) { var bInd = bSet.LowerBound(i); if (bInd < bSet.Count() && i == bSet[bInd]) { ans = i; break; } } Console.WriteLine(ans); } } public class D : Solver { public override void Solve() { var S = Console.ReadLine(); var Q = Scanner.ReadInt(); var deq = new Deque<char>(); for (int i = 0; i < S.Length; i++) { deq.PushBack(S[i]); } bool isReverse = false; for (int i = 0; i < Q; i++) { var q = Console.ReadLine(); if (q.StartsWith("1")) { isReverse = !isReverse; } else { var qArray = q.Split(); var F = qArray[1]; var C = qArray[2][0]; if (F == "1" ^ isReverse) { deq.PushFront(C); } else { deq.PushBack(C); } } } Console.WriteLine( new string(isReverse ? deq.Items.Reverse().ToArray() : deq.Items)); } } public class E : Solver { public override void Solve() {} } public class F : Solver { public override void Solve() {} } } namespace AtCoder { public abstract class Solver { public abstract void Solve(); } class Program { static void Main(string[] args) { // var solver = new ABC158.A(); // var solver = new ABC158.B(); // var solver = new ABC158.C(); var solver = new ABC158.D(); // var solver = new ABC158.E(); // var solver = new ABC158.F(); solver.Solve(); } } } namespace AtCoder.Algorithms {} namespace AtCoder.Collections { public class Deque<T> { int dx; T[] buf; int mask; public int Count { get; private set; } public Deque() : this(8) {} public Deque(int capacity) { mask = capacity - 1; buf = new T[capacity]; } public T this[int index] { get { return buf[(dx + index) & mask]; } set { buf[(dx + index) & mask] = value; } } public void PushFront(T item) { if (Count == buf.Length) extend(); dx = (dx + buf.Length - 1) & mask; buf[dx] = item; Count++; } public T PopFront() { var ret = buf[dx = (dx + 1) & mask]; Count--; return ret; } public void PushBack(T item) { if (Count == buf.Length) extend(); buf[(dx + Count++) & mask] = item; } public T PopBack() { var ret = buf[(dx + --Count) & mask]; return ret; } public T Last() { return buf[(dx + Count - 1) & mask]; } public T First() { return buf[dx]; } void extend() { var nbuf = new T[buf.Length * 2]; for (int i = 0; i < buf.Length; i++) nbuf[i] = buf[(dx + i) & mask]; mask = mask * 2 + 1; dx = 0; buf = nbuf; } public void Clear() { Count = 0; } public bool Any() { return Count != 0; } public void Insert(int index, T item) { PushFront(item); for (int i = 0; i < index; i++) this[i] = this[i + 1]; this[index] = item; } public T RemoveAt(int index) { var ret = this[index]; for (int i = index; i > 0; i--) this[i] = this[i - 1]; PopFront(); return ret; } public T[] Items { get { var ret = new T[Count]; for (int i = 0; i < Count; i++) ret[i] = this[i]; return ret; } } } public class PriorityQueue<T> : IEnumerable<T> { private readonly List<T> _data = new List<T>(); private readonly IComparer<T> _comparer; private readonly bool _isDescending; public PriorityQueue(IComparer<T> comparer, bool isDescending = true) { _comparer = comparer; _isDescending = isDescending; } public PriorityQueue(Comparison<T> comparison, bool isDescending = true) : this(Comparer<T>.Create(comparison), isDescending) {} public PriorityQueue(bool isDescending = true) : this(Comparer<T>.Default, isDescending) {} public void Enqueue(T item) { _data.Add(item); var childIndex = _data.Count - 1; while (childIndex > 0) { var parentIndex = (childIndex - 1) / 2; if (Compare(_data[childIndex], _data[parentIndex]) >= 0) break; Swap(childIndex, parentIndex); childIndex = parentIndex; } } public T Dequeue() { var lastIndex = _data.Count - 1; var firstItem = _data[0]; _data[0] = _data[lastIndex]; _data.RemoveAt(lastIndex--); var parentIndex = 0; while (true) { var childIndex = parentIndex * 2 + 1; if (childIndex > lastIndex) break; var rightChild = childIndex + 1; if (rightChild <= lastIndex && Compare(_data[rightChild], _data[childIndex]) < 0) childIndex = rightChild; if (Compare(_data[parentIndex], _data[childIndex]) <= 0) break; Swap(parentIndex, childIndex); parentIndex = childIndex; } return firstItem; } public T Peek() { return _data[0]; } private void Swap(int a, int b) { var tmp = _data[a]; _data[a] = _data[b]; _data[b] = tmp; } private int Compare(T a, T b) { return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b); } public int Count => _data.Count; public IEnumerator<T> GetEnumerator() { return _data.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } public class PriorityQueue<TKey, TValue> : IEnumerable<TValue> { private readonly List<KeyValuePair<TKey, TValue>> _data = new List<KeyValuePair<TKey, TValue>>(); private readonly bool _isDescending; private readonly Func<TValue, TKey> _keySelector; private readonly IComparer<TKey> _keyComparer; public PriorityQueue(Func<TValue, TKey> keySelector, bool isDescending = true) : this(keySelector, Comparer<TKey>.Default, isDescending) {} public PriorityQueue(Func<TValue, TKey> keySelector, IComparer<TKey> keyComparer, bool isDescending = true) { _keySelector = keySelector; _keyComparer = keyComparer; _isDescending = isDescending; } public void Enqueue(TValue item) { _data.Add(new KeyValuePair<TKey, TValue>(_keySelector(item), item)); var childIndex = _data.Count - 1; while (childIndex > 0) { var parentIndex = (childIndex - 1) / 2; if (Compare(_data[childIndex].Key, _data[parentIndex].Key) >= 0) break; Swap(childIndex, parentIndex); childIndex = parentIndex; } } public TValue Dequeue() { var lastIndex = _data.Count - 1; var firstItem = _data[0]; _data[0] = _data[lastIndex]; _data.RemoveAt(lastIndex--); var parentIndex = 0; while (true) { var childIndex = parentIndex * 2 + 1; if (childIndex > lastIndex) break; var rightChild = childIndex + 1; if (rightChild <= lastIndex && Compare(_data[rightChild].Key, _data[childIndex].Key) < 0) childIndex = rightChild; if (Compare(_data[parentIndex].Key, _data[childIndex].Key) <= 0) break; Swap(parentIndex, childIndex); parentIndex = childIndex; } return firstItem.Value; } public TValue Peek() { return _data[0].Value; } private void Swap(int a, int b) { var tmp = _data[a]; _data[a] = _data[b]; _data[b] = tmp; } private int Compare(TKey a, TKey b) { return _isDescending ? _keyComparer.Compare(b, a) : _keyComparer.Compare(a, b); } public int Count => _data.Count; public IEnumerator<TValue> GetEnumerator() { return _data.Select(r => r.Value).GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } /// <summary> /// Self-Balancing Binary Search Tree /// (using Randamized BST) /// </summary> public class SB_BinarySearchTree<T> where T : IComparable { public class Node { public T Value; public Node LChild; public Node RChild; public int Count; public Node(T v) { Value = v; Count = 1; } } static readonly Random _rnd = new Random(); public static int Count(Node t) { return t == null ? 0 : t.Count; } static Node Update(Node t) { t.Count = Count(t.LChild) + Count(t.RChild) + 1; return t; } public static Node Merge(Node l, Node r) { if (l == null || r == null) return l == null ? r : l; if (Count(l) / (double)(Count(l) + Count(r)) > _rnd.NextDouble()) { l.RChild = Merge(l.RChild, r); return Update(l); } else { r.LChild = Merge(l, r.LChild); return Update(r); } } /// <summary> /// split as [0, k), [k, n) /// </summary> public static Tuple<Node, Node> Split(Node t, int k) { if (t == null) return new Tuple<Node, Node>(null, null); if (k <= Count(t.LChild)) { var s = Split(t.LChild, k); t.LChild = s.Item2; return new Tuple<Node, Node>(s.Item1, Update(t)); } else { var s = Split(t.RChild, k - Count(t.LChild) - 1); t.RChild = s.Item1; return new Tuple<Node, Node>(Update(t), s.Item2); } } public static Node Remove(Node t, T v) { if (Find(t, v) == null) return t; return RemoveAt(t, LowerBound(t, v)); } public static Node RemoveAt(Node t, int k) { var s = Split(t, k); var s2 = Split(s.Item2, 1); return Merge(s.Item1, s2.Item2); } public static bool Contains(Node t, T v) { return Find(t, v) != null; } public static Node Find(Node t, T v) { while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp > 0) t = t.LChild; else if (cmp < 0) t = t.RChild; else break; } return t; } public static Node FindByIndex(Node t, int idx) { if (t == null) return null; var currentIdx = Count(t) - Count(t.RChild) - 1; while (t != null) { if (currentIdx == idx) return t; if (currentIdx > idx) { t = t.LChild; currentIdx -= (Count(t == null ? null : t.RChild) + 1); } else { t = t.RChild; currentIdx += (Count(t == null ? null : t.LChild) + 1); } } return null; } public static int UpperBound(Node t, T v) { var torg = t; if (t == null) return -1; var ret = int.MaxValue; var idx = Count(t) - Count(t.RChild) - 1; while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp > 0) { ret = Math.Min(ret, idx); t = t.LChild; idx -= (Count(t == null ? null : t.RChild) + 1); } else if (cmp <= 0) { t = t.RChild; idx += (Count(t == null ? null : t.LChild) + 1); } } return ret == int.MaxValue ? Count(torg) : ret; } public static int LowerBound(Node t, T v) { var torg = t; if (t == null) return -1; var idx = Count(t) - Count(t.RChild) - 1; var ret = int.MaxValue; while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp >= 0) { if (cmp == 0) ret = Math.Min(ret, idx); t = t.LChild; if (t == null) ret = Math.Min(ret, idx); idx -= t == null ? 0 : (Count(t.RChild) + 1); } else if (cmp < 0) { t = t.RChild; idx += (Count(t == null ? null : t.LChild) + 1); if (t == null) return idx; } } return ret == int.MaxValue ? Count(torg) : ret; } public static Node Insert(Node t, T v) { var ub = LowerBound(t, v); return InsertByIdx(t, ub, v); } static Node InsertByIdx(Node t, int k, T v) { var s = Split(t, k); return Merge(Merge(s.Item1, new Node(v)), s.Item2); } public static IEnumerable<T> Enumerate(Node t) { var ret = new List<T>(); Enumerate(t, ret); return ret; } static void Enumerate(Node t, List<T> ret) { if (t == null) return; Enumerate(t.LChild, ret); ret.Add(t.Value); Enumerate(t.RChild, ret); } } public class Set<T> where T : IComparable { protected SB_BinarySearchTree<T>.Node _root; public T this[int idx] { get { return ElementAt(idx); } } public int Count() { return SB_BinarySearchTree<T>.Count(_root); } public virtual void Insert(T v) { if (_root == null) _root = new SB_BinarySearchTree<T>.Node(v); else { if (SB_BinarySearchTree<T>.Find(_root, v) != null) return; _root = SB_BinarySearchTree<T>.Insert(_root, v); } } public void Clear() { _root = null; } public void Remove(T v) { _root = SB_BinarySearchTree<T>.Remove(_root, v); } public bool Contains(T v) { return SB_BinarySearchTree<T>.Contains(_root, v); } public T ElementAt(int k) { var node = SB_BinarySearchTree<T>.FindByIndex(_root, k); if (node == null) throw new IndexOutOfRangeException(); return node.Value; } public int Count(T v) { return SB_BinarySearchTree<T>.UpperBound(_root, v) - SB_BinarySearchTree<T>.LowerBound(_root, v); } public int LowerBound(T v) { return SB_BinarySearchTree<T>.LowerBound(_root, v); } public int UpperBound(T v) { return SB_BinarySearchTree<T>.UpperBound(_root, v); } public Tuple<int, int> EqualRange(T v) { if (!Contains(v)) return new Tuple<int, int>(-1, -1); return new Tuple<int, int>(SB_BinarySearchTree<T>.LowerBound(_root, v), SB_BinarySearchTree<T>.UpperBound(_root, v) - 1); } public List<T> ToList() { return new List<T>(SB_BinarySearchTree<T>.Enumerate(_root)); } } public class MultiSet<T> : Set<T> where T : IComparable { public override void Insert(T v) { if (_root == null) _root = new SB_BinarySearchTree<T>.Node(v); else _root = SB_BinarySearchTree<T>.Insert(_root, v); } } public class UnionFind<T> { private Dictionary<T, T> _parent = new Dictionary<T, T>(); private Dictionary<T, int> _size = new Dictionary<T, int>(); public void Unite(T x, T y) { x = Root(x); y = Root(y); if (IsEqual(x, y)) return; var sx = Size(x); var sy = Size(y); if (sx < sy) { var t = x; x = y; y = t; } _size[x] += _size[y]; _size.Remove(y); _parent[y] = x; } public int Size(T x) { var p = Root(x); int s; if (_size.TryGetValue(p, out s)) { return s; } return _size[x] = 1; } public bool IsSameGroup(T x, T y) { return IsEqual(Root(x), Root(y)); } public bool IsRoot(T x) { return IsEqual(Root(x), x); } private T Root(T x) { T r; if (_parent.TryGetValue(x, out r)) { return _parent[x] = Root(r); } return x; } private bool IsEqual(T x, T y) { return EqualityComparer<T>.Default.Equals(x, y); } } } namespace AtCoder.Mathematics { public class MathEx { /// <summary> /// 最小公倍数 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> static long Lcm(long a, long b) { return a / Gcd(a, b) * b; } /// <summary> /// 最大公約数 /// </summary> /// <param name="m"></param> /// <param name="n"></param> /// <returns></returns> static long Gcd(long m, long n) { if (n == 0) return m; return Gcd(n, m % n); } } public struct ModInt { public const long Mod = (int)1e9 + 7; public long num; public ModInt(long n) { num = n; } public override string ToString() { return num.ToString(); } public static ModInt operator +(ModInt l, ModInt r) { l.num += r.num; if (l.num >= Mod) l.num -= Mod; return l; } public static ModInt operator -(ModInt l, ModInt r) { l.num -= r.num; if (l.num < 0) l.num += Mod; return l; } public static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.num * r.num % Mod); } public static ModInt operator /(ModInt l, ModInt r) { return l * Pow(r, Mod - 2); } public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) n += Mod; return new ModInt(n); } public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); } public static ModInt Pow(long v, long k) { long ret = 1; for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod) if ((k & 1) == 1) ret = ret * v % Mod; return new ModInt(ret); } public static ModInt Combination(long n, long r) { ModInt ans = 1; for (int i = 0; i < r; i++) { ans *= n - i; } for (int i = 1; i <= r; i++) { ans /= i; } return ans; } public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); } } } namespace AtCoder.Extensions { public static class Extension { static int BinarySearch<T>(IList<T> source, T value, IComparer<T> comparer, bool isLowerBound) { return BinarySearch(source, 0, source.Count - 1, value, comparer, isLowerBound); } static int BinarySearch<T>(IList<T> source, int start, int end, T value, IComparer<T> comparer, bool isLowerBound) { while (start <= end) { var mid = (start + end) / 2; var result = comparer.Compare(source[mid], value); if (result < 0 || (result == 0 && !isLowerBound)) start = mid + 1; else end = mid - 1; } return start; } public static int LowerBound<T>(this IList<T> source, T value, Comparison<T> f) => BinarySearch(source, value, Comparer<T>.Create(f), true); public static int LowerBound<T>(this IList<T> source, int start, T value, Comparison<T> f) => BinarySearch(source, start, source.Count - 1, value, Comparer<T>.Create(f), true); public static int LowerBound<T>(this IList<T> source, int start, int end, T value, Comparison<T> f) => BinarySearch(source, start, end, value, Comparer<T>.Create(f), true); public static int LowerBound<T>(this IList<T> source, T value) => BinarySearch(source, value, Comparer<T>.Default, true); public static int LowerBound<T>(this IList<T> source, int start, T value) => BinarySearch(source, start, source.Count - 1, value, Comparer<T>.Default, true); public static int LowerBound<T>(this IList<T> source, int start, int end, T value) => BinarySearch(source, start, end, value, Comparer<T>.Default, true); public static int UpperBound<T>(this IList<T> source, T value, Comparison<T> cmp) => BinarySearch(source, value, Comparer<T>.Create(cmp), false); public static int UpperBound<T>(this IList<T> source, int start, T value, Comparison<T> cmp) => BinarySearch(source, start, source.Count - 1, value, Comparer<T>.Create(cmp), false); public static int UpperBound<T>(this IList<T> source, int start, int end, T value, Comparison<T> cmp) => BinarySearch(source, start, end, value, Comparer<T>.Create(cmp), false); public static int UpperBound<T>(this IList<T> source, T value) => BinarySearch(source, value, Comparer<T>.Default, false); public static int UpperBound<T>(this IList<T> source, int start, T value) => BinarySearch(source, start, source.Count - 1, value, Comparer<T>.Default, false); public static int UpperBound<T>(this IList<T> source, int start, int end, T value) => BinarySearch(source, start, end, value, Comparer<T>.Default, false); public static PriorityQueue<T> AsPriorityQueue<T>(this IEnumerable<T> source, bool isDescending = true) { var queue = new PriorityQueue<T>(isDescending); foreach (var item in source) { queue.Enqueue(item); } return queue; } public static PriorityQueue<TKey, TSource> AsPriorityQueue<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, bool isDescending = true) { var queue = new PriorityQueue<TKey, TSource>(keySelector, isDescending); foreach (var item in source) { queue.Enqueue(item); } return queue; } public static bool ChangeMin<T>(this IList<T> source, int index, T value) where T : IComparable { var a = source[index]; if (a.CompareTo(value) > 0) { source[index] = value; return true; } return false; } public static bool ChangeMax<T>(this IList<T> source, int index, T value) where T : IComparable { var a = source[index]; if (a.CompareTo(value) < 0) { source[index] = value; return true; } return false; } } public static class Scanner { public static string ReadString() => Console.ReadLine(); public static int ReadInt() => int.Parse(Console.ReadLine()); public static long ReadLong() => long.Parse(Console.ReadLine()); public static double ReadDouble() => double.Parse(Console.ReadLine()); public static decimal ReadDecimal() => decimal.Parse(Console.ReadLine()); public static string[] ReadStringArray() => Console.ReadLine().Split().ToArray(); public static string[] ReadStringArray(int n) => Enumerable.Range(0, n).Select(_ => Console.ReadLine()).ToArray(); public static int[] ReadIntArray() => Console.ReadLine().Split().Select(int.Parse).ToArray(); public static int[] ReadIntArray(int n) => Enumerable.Range(0, n).Select(_ => ReadInt()).ToArray(); public static long[] ReadLongArray() => Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); public static long[] ReadLongArray(int n) => Enumerable.Range(0, n).Select(_ => ReadLong()).ToArray(); public static double[] ReadDoubleArray() => Console.ReadLine().Split().Select(double.Parse).ToArray(); public static double[] ReadDoubleArray(int n) => Enumerable.Range(0, n).Select(_ => ReadDouble()).ToArray(); public static decimal[] ReadDecimalArray() => Console.ReadLine().Split().Select(decimal.Parse).ToArray(); public static decimal[] ReadDecimalArray(int n) => Enumerable.Range(0, n).Select(_ => ReadDecimal()).ToArray(); } }
[["-", 0, 230, 3, 4, 0, 28, 0, 41, 0, 102], ["-", 63, 214, 205, 213, 63, 214, 205, 214, 205, 22], ["-", 63, 214, 205, 213, 63, 214, 205, 214, 0, 131], ["-", 63, 214, 205, 213, 63, 214, 205, 214, 141, 22], ["+", 0, 230, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 3, 4, 0, 28, 0, 41, 75, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 41, 75, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 41, 75, 214, 141, 22]]
8
6,055
8
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; static void Main() { Sc sc = new Sc(); var t = sc.S; int n = sc.I, p = 0; var li1 = new List<char>(); var li2 = new List<char>(); for (int i = 0; i < n; i++) { var e = sc.Sa; if (e[0] == "1") { p ^= 1; } else { if ((int.Parse(e[1]) + p) % 2 == 1) { li1.Add(e[2][0]); } else { li2.Add(e[2][0]); } } } StringBuilder sb = new StringBuilder(); if (p == 1) { for (int i = li2.Count - 1; i >= 0; i--) { sb.Append(li2[i]); } sb.Append(t); for (int i = 0; i < li1.Count; i++) { sb.Append(li1[i]); } } else { for (int i = li1.Count - 1; i >= 0; i--) { sb.Append(li1[i]); } sb.Append(t); for (int i = 0; i < li2.Count; i++) { sb.Append(li2[i]); } } Console.WriteLine("{0}", sb); } } 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; static class Program { const int mod = (int)1e9 + 7; static void Main() { Sc sc = new Sc(); var t = sc.S; int n = sc.I, p = 0; var li1 = new List<char>(); var li2 = new List<char>(); for (int i = 0; i < n; i++) { var e = sc.Sa; if (e[0] == "1") { p ^= 1; } else { if ((int.Parse(e[1]) + p) % 2 == 1) { li1.Add(e[2][0]); } else { li2.Add(e[2][0]); } } } StringBuilder sb = new StringBuilder(); if (p == 1) { for (int i = li2.Count - 1; i >= 0; i--) { sb.Append(li2[i]); } for (int i = t.Length - 1; i >= 0; i--) { sb.Append(t[i]); } for (int i = 0; i < li1.Count; i++) { sb.Append(li1[i]); } } else { for (int i = li1.Count - 1; i >= 0; i--) { sb.Append(li1[i]); } sb.Append(t); for (int i = 0; i < li2.Count; i++) { sb.Append(li2[i]); } } Console.WriteLine("{0}", sb); } } 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; } }
[["+", 8, 196, 0, 57, 64, 196, 0, 7, 0, 88], ["+", 8, 196, 0, 57, 64, 196, 0, 7, 0, 24], ["+", 0, 57, 64, 196, 0, 7, 10, 198, 39, 199], ["+", 64, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 16, 31, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 16, 31, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 16, 31, 214, 141, 22], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 7, 0, 35], ["+", 0, 57, 64, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 57, 64, 196, 0, 7, 15, 16, 17, 20], ["+", 0, 57, 64, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 57, 64, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 7, 26, 223, 0, 68], ["+", 8, 196, 0, 57, 64, 196, 0, 7, 0, 25], ["+", 0, 57, 64, 196, 0, 7, 8, 196, 0, 45], ["+", 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, 57, 64, 196, 0, 7, 8, 196, 0, 46]]
8
1,328
23
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class MainClass { public const long Giri = 1000000007; public const long DpInf = 99999999999999; public static void Main(string[] args) { var s = Console.ReadLine(); var q = Console.ReadLine().ToInt(); var t = new LinkedList<string>(); t.AddFirst(s); bool normal = true; for (int i = 0; i < q; i++) { var p = Input(); var que = p[0].ToInt(); if (que == 1) { normal = !normal; } else if (que == 2) { if (p[1].ToInt() == 1) { if (normal) t.AddFirst(p[2]); else t.AddLast(p[2]); } else { if (!normal) t.AddFirst(p[2]); else t.AddLast(p[2]); } } } if (normal) { Console.WriteLine(string.Join("", t.ToArray())); } else { string[] ary = t.ToArray(); Array.Reverse(ary); Console.WriteLine(string.Join("", ary)); } } static long GCD(long a, long b) { var v = new[] { a, b }; while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; } return v[0]; } public static string[] Input() { return Console.ReadLine().Split(); } } public static class Smarter { public static int ToInt(this string str) { return int.Parse(str); } public static long ToLong(this string str) { return long.Parse(str); } public static int[] ToInt(this string[] str, int offset = 0) { var r = new int[str.Length]; for (int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset; return r; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class MainClass { public const long Giri = 1000000007; public const long DpInf = 99999999999999; public static void Main(string[] args) { var s = Console.ReadLine(); var q = Console.ReadLine().ToInt(); var t = new LinkedList<string>(); for (int i = 0; i < s.Length; i++) { t.AddLast(s[i].ToString()); } bool normal = true; for (int i = 0; i < q; i++) { var p = Input(); var que = p[0].ToInt(); if (que == 1) { normal = !normal; } else if (que == 2) { if (p[1].ToInt() == 1) { if (normal) t.AddFirst(p[2]); else t.AddLast(p[2]); } else { if (!normal) t.AddFirst(p[2]); else t.AddLast(p[2]); } } } if (normal) { Console.WriteLine(string.Join("", t.ToArray())); } else { string[] ary = t.ToArray(); Array.Reverse(ary); Console.WriteLine(string.Join("", ary)); } } static long GCD(long a, long b) { var v = new[] { a, b }; while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; } return v[0]; } public static string[] Input() { return Console.ReadLine().Split(); } } public static class Smarter { public static int ToInt(this string str) { return int.Parse(str); } public static long ToLong(this string str) { return long.Parse(str); } public static int[] ToInt(this string[] str, int offset = 0) { var r = new int[str.Length]; for (int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset; return r; } }
[["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 88], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 24], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 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, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 8, 196, 0, 7, 15, 16, 12, 214, 205, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 214, 0, 131], ["+", 8, 196, 0, 7, 15, 16, 12, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 25], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 45], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 204, 206, 207, 0, 70], ["+", 63, 214, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 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, 195, 8, 196, 0, 7, 8, 196, 0, 46]]
8
477
27
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using Library; using static Library.Input; namespace AtCoderTemplate { class ProgramD { static void Main() { var S = Line; int Q = NextInt; bool reverse = false; var first = new List<char>(); var last = new List<char>(); for (int i = 0; i < Q; i++) { int type = NextInt; if (type == 1) { reverse = !reverse; } else { int f = NextInt; if ((f == 1) == !reverse) { first.Add(NextWord()[0]); } else { last.Add(NextWord()[0]); } } } if (!reverse) { first.Reverse(); System.Console.WriteLine(string.Join("", first) + S + string.Join("", last)); } else { last.Reverse(); System.Console.WriteLine(string.Join("", last) + S + string.Join("", first)); } } } } namespace Library { class Input { static IEnumerator<string> enumerator = new string[] {}.AsEnumerable().GetEnumerator(); public static string Line => Console.ReadLine(); public static string[] StrArr => Line.Split(' '); public static int NextInt => int.Parse(NextWord()); public static long NextLong => long.Parse(NextWord()); public static List<int> IntList => StrArr.Select(int.Parse).ToList(); public static List<long> LongList => StrArr.Select(long.Parse).ToList(); public static IEnumerable<long[]> TakeLine(int N) { return Enumerable.Repeat(0, N).Select( _ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray()); } public static string NextWord() { while (!enumerator.MoveNext()) { enumerator = StrArr.AsEnumerable().GetEnumerator(); } return enumerator.Current; } } } namespace Library { class Modular { public const int mod = 1000000007; public readonly long value; public Modular(long value) { this.value = value; } public static implicit operator Modular(long a) { var m = a % mod; return new Modular((m < 0) ? m + mod : 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 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, mod - 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) % mod)); } 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; } } } namespace Library { class MyMath { public static long Gcd(long a, long b) { return b == 0 ? a : Gcd(b, a % b); } public static long Sqrt(long n) { if (n < 0) return 0; long a = 0, tmp = 0, b = 0; for (int i = 62; i >= 0; i -= 2) { tmp = (b << 1) + 1 <= (n >> i) ? 1 : 0; a = a << 1 | tmp; n -= (((b << 1) + 1) * tmp) << i; b = (b << 1) + tmp + tmp; } return a; } public static long Nck(int n, int k) { if (k == 0) return 1; if (n == 0) return 0; return n * Nck(n - 1, k - 1) / k; } } } namespace Library { public class PriorityQueue<T> { readonly List<T> _heap = new List<T>(); readonly Comparison<T> _comparison; public PriorityQueue(Comparison<T> comparison) { _comparison = comparison; } public PriorityQueue() : this(Comparer<T>.Default.Compare) {} public PriorityQueue(IComparer<T> comparer) : this(comparer.Compare) {} public void Enqueue(T item) { _heap.Add(item); int childID = _heap.Count - 1; int parentID = (childID - 1) / 2; while (childID > 0 && _comparison(_heap[parentID], _heap[childID]) > 0) { Swap(parentID, childID); childID = parentID; parentID = (parentID - 1) / 2; } } public T Dequeue() { var first = _heap.First(); _heap[0] = _heap.Last(); _heap.RemoveAt(_heap.Count - 1); int parentID = 0; int childID = parentID * 2 + 2; if (childID >= _heap.Count || _comparison(_heap[childID], _heap[childID - 1]) > 0) childID--; while (childID < _heap.Count && _comparison(_heap[parentID], _heap[childID]) > 0) { Swap(parentID, childID); parentID = childID; childID = parentID * 2 + 2; if (childID >= _heap.Count || _comparison(_heap[childID], _heap[childID - 1]) > 0) childID--; } return first; } void Swap(int parent, int child) { var tmp = _heap[parent]; _heap[parent] = _heap[child]; _heap[child] = tmp; } public T Peek() { return _heap[0]; } public int Count => _heap.Count; public bool Any() { return _heap.Any(); } public List<T> Data => _heap; } } namespace Library { public class UnionFind { public int[] Parents { get; set; } public UnionFind(int size) { Parents = Enumerable.Repeat(-1, size).ToArray(); } public int Find(int num) { if (Parents[num] < 0) return num; Parents[num] = Find(Parents[num]); return Parents[num]; } public int Size(int num) { return -Parents[Find(num)]; } public bool Same(int a, int b) { return Find(a) == Find(b); } public void Unite(int a, int b) { int x = Find(a), y = Find(b); if (Size(x) > Size(y)) { Parents[x] += Parents[y]; Parents[y] = x; } else { Parents[y] += Parents[x]; Parents[x] = y; } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using Library; using static Library.Input; namespace AtCoderTemplate { class ProgramD { static void Main() { var S = Line; int Q = NextInt; bool reverse = false; var first = new List<char>(); var last = new List<char>(); for (int i = 0; i < Q; i++) { int type = NextInt; if (type == 1) { reverse = !reverse; } else { int f = NextInt; if ((f == 1) == !reverse) { first.Add(NextWord()[0]); } else { last.Add(NextWord()[0]); } } } if (!reverse) { first.Reverse(); System.Console.WriteLine(string.Join("", first) + S + string.Join("", last)); } else { last.Reverse(); System.Console.WriteLine(string.Join("", last) + string.Join("", S.Reverse()) + string.Join("", first)); } } } } namespace Library { class Input { static IEnumerator<string> enumerator = new string[] {}.AsEnumerable().GetEnumerator(); public static string Line => Console.ReadLine(); public static string[] StrArr => Line.Split(' '); public static int NextInt => int.Parse(NextWord()); public static long NextLong => long.Parse(NextWord()); public static List<int> IntList => StrArr.Select(int.Parse).ToList(); public static List<long> LongList => StrArr.Select(long.Parse).ToList(); public static IEnumerable<long[]> TakeLine(int N) { return Enumerable.Repeat(0, N).Select( _ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray()); } public static string NextWord() { while (!enumerator.MoveNext()) { enumerator = StrArr.AsEnumerable().GetEnumerator(); } return enumerator.Current; } } } namespace Library { class Modular { public const int mod = 1000000007; public readonly long value; public Modular(long value) { this.value = value; } public static implicit operator Modular(long a) { var m = a % mod; return new Modular((m < 0) ? m + mod : 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 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, mod - 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) % mod)); } 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; } } } namespace Library { class MyMath { public static long Gcd(long a, long b) { return b == 0 ? a : Gcd(b, a % b); } public static long Sqrt(long n) { if (n < 0) return 0; long a = 0, tmp = 0, b = 0; for (int i = 62; i >= 0; i -= 2) { tmp = (b << 1) + 1 <= (n >> i) ? 1 : 0; a = a << 1 | tmp; n -= (((b << 1) + 1) * tmp) << i; b = (b << 1) + tmp + tmp; } return a; } public static long Nck(int n, int k) { if (k == 0) return 1; if (n == 0) return 0; return n * Nck(n - 1, k - 1) / k; } } } namespace Library { public class PriorityQueue<T> { readonly List<T> _heap = new List<T>(); readonly Comparison<T> _comparison; public PriorityQueue(Comparison<T> comparison) { _comparison = comparison; } public PriorityQueue() : this(Comparer<T>.Default.Compare) {} public PriorityQueue(IComparer<T> comparer) : this(comparer.Compare) {} public void Enqueue(T item) { _heap.Add(item); int childID = _heap.Count - 1; int parentID = (childID - 1) / 2; while (childID > 0 && _comparison(_heap[parentID], _heap[childID]) > 0) { Swap(parentID, childID); childID = parentID; parentID = (parentID - 1) / 2; } } public T Dequeue() { var first = _heap.First(); _heap[0] = _heap.Last(); _heap.RemoveAt(_heap.Count - 1); int parentID = 0; int childID = parentID * 2 + 2; if (childID >= _heap.Count || _comparison(_heap[childID], _heap[childID - 1]) > 0) childID--; while (childID < _heap.Count && _comparison(_heap[parentID], _heap[childID]) > 0) { Swap(parentID, childID); parentID = childID; childID = parentID * 2 + 2; if (childID >= _heap.Count || _comparison(_heap[childID], _heap[childID - 1]) > 0) childID--; } return first; } void Swap(int parent, int child) { var tmp = _heap[parent]; _heap[parent] = _heap[child]; _heap[child] = tmp; } public T Peek() { return _heap[0]; } public int Count => _heap.Count; public bool Any() { return _heap.Any(); } public List<T> Data => _heap; } } namespace Library { public class UnionFind { public int[] Parents { get; set; } public UnionFind(int size) { Parents = Enumerable.Repeat(-1, size).ToArray(); } public int Find(int num) { if (Parents[num] < 0) return num; Parents[num] = Find(Parents[num]); return Parents[num]; } public int Size(int num) { return -Parents[Find(num)]; } public bool Same(int a, int b) { return Find(a) == Find(b); } public void Unite(int a, int b) { int x = Find(a), y = Find(b); if (Size(x) > Size(y)) { Parents[x] += Parents[y]; Parents[y] = x; } else { Parents[y] += Parents[x]; Parents[x] = y; } } } }
[["+", 0, 16, 31, 16, 12, 213, 63, 214, 205, 199], ["+", 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], ["+", 12, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 16, 31, 16, 12, 213, 3, 4, 0, 21], ["+", 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, 16, 31, 16, 12, 213, 3, 4, 0, 25]]
8
1,628
12
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, p; sc.Multi(out n, out p); var s = sc.Str; if (p == 2 || p == 5) { long ans = 0; for (int i = 0; i < n; i++) { if ((s[i] - '0') % p == 0) { ans += i + 1; } } Prt(ans); } else { int a = 0; var cnt = new int[p]; cnt[0] = 1; long ans = 0; for (int i = n - 1; i >= 0; i--) { a = (a * 10 + s[i] - '0') % p; ans += cnt[a]; ++cnt[a]; } Prt(ans); } } } 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]); } }
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, p; sc.Multi(out n, out p); var s = sc.Str; if (p == 2 || p == 5) { long ans = 0; for (int i = 0; i < n; i++) { if ((s[i] - '0') % p == 0) { ans += i + 1; } } Prt(ans); } else { int a = 0; var cnt = new int[p]; cnt[0] = 1; long ans = 0; int t = 1; for (int i = n - 1; i >= 0; i--) { a = (a + (s[i] - '0') * t) % p; ans += cnt[a]; ++cnt[a]; t = t * 10 % p; } Prt(ans); } } } 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]); } }
[["+", 0, 57, 75, 196, 0, 197, 0, 198, 39, 199], ["+", 75, 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, 196, 0, 57, 75, 196, 0, 197, 0, 35], ["-", 31, 23, 0, 16, 31, 16, 31, 16, 17, 48], ["-", 31, 23, 0, 16, 31, 16, 31, 16, 12, 203], ["+", 31, 23, 0, 16, 12, 16, 31, 23, 0, 24], ["+", 12, 16, 31, 23, 0, 16, 12, 16, 17, 48], ["+", 12, 16, 31, 23, 0, 16, 12, 16, 12, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25], ["+", 75, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 31, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 17, 48], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 109], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 22]]
8
2,335
19
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; long p = Read; string s = Str; n = s.LongCount(); if (p == 2 || p == 5) { var r25 = 0L; var cand = n; foreach (var c in s.Reverse()) { var dig = c.ToDigit(); if (dig % p == 0) { r25 += cand; } cand--; } return r25; } return -1; List<long> cs = new List<long>() { 0L }; long current = 0; long baseMod = 1; foreach (var c in s.Reverse()) { var dig = c.ToDigit(); current += dig * baseMod; current %= p; cs.Add(current); baseMod *= 10; baseMod %= p; } var res = cs.GroupBy(x => x) .Select(x => x.Count()) .Select(x => x * (x - 1) / 2) .Sum(); return res; } public bool SolveBool() { long 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 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'); } class C { public class Tree { public Tree() { to = 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 })); to = 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[]> to; public long[] To(long from) { long[] res = null; if (to.TryGetValue(from, out res)) return res; else return empty; } } 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 int GetFirstIndexGreater(long x, ref List<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 int GetFirstIndexGreater(int x, ref List<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 int GetLastIndexLess(long x, ref List<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 int GetLastIndexLess(int x, ref List<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; long p = Read; string s = Str; n = s.LongCount(); if (p == 2 || p == 5) { var r25 = 0L; var cand = n; foreach (var c in s.Reverse()) { var dig = c.ToDigit(); if (dig % p == 0) { r25 += cand; } cand--; } return r25; } List<long> cs = new List<long>() { 0L }; long current = 0; long baseMod = 1; foreach (var c in s.Reverse()) { var dig = c.ToDigit(); current += dig * baseMod; current %= p; cs.Add(current); baseMod *= 10; baseMod %= p; } var res = cs.GroupBy(x => x) .Select(x => x.Count()) .Select(x => x * (x - 1) / 2) .Sum(); return res; } public bool SolveBool() { long 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 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 Tree { public Tree() { to = 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 })); to = 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[]> to; public long[] To(long from) { long[] res = null; if (to.TryGetValue(from, out res)) return res; else return empty; } } 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 int GetFirstIndexGreater(long x, ref List<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 int GetFirstIndexGreater(int x, ref List<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 int GetLastIndexLess(long x, ref List<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 int GetLastIndexLess(int x, ref List<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; } } }
[["-", 8, 201, 0, 195, 8, 196, 0, 37, 0, 38], ["-", 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, 35], ["+", 0, 195, 8, 306, 0, 74, 51, 23, 0, 25], ["+", 8, 201, 0, 235, 8, 201, 0, 195, 0, 35], ["+", 0, 235, 8, 201, 0, 195, 0, 251, 0, 259], ["+", 0, 235, 8, 201, 0, 195, 0, 251, 0, 115], ["+", 8, 201, 0, 235, 8, 201, 0, 195, 39, 199], ["+", 8, 201, 0, 235, 8, 201, 0, 195, 141, 22], ["+", 0, 235, 8, 201, 0, 195, 307, 308, 0, 18], ["+", 8, 201, 0, 195, 307, 308, 0, 309, 141, 22], ["+", 0, 235, 8, 201, 0, 195, 307, 308, 0, 21], ["+", 0, 235, 8, 201, 0, 195, 307, 308, 0, 47], ["+", 0, 235, 8, 201, 0, 195, 54, 55, 0, 24], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 0, 276], ["+", 0, 195, 54, 55, 0, 220, 39, 236, 141, 22], ["+", 54, 55, 0, 220, 39, 236, 237, 238, 0, 18], ["+", 54, 55, 0, 220, 39, 236, 237, 238, 0, 22], ["+", 54, 55, 0, 220, 39, 236, 237, 238, 0, 21], ["+", 54, 55, 0, 220, 39, 236, 237, 238, 0, 47], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 141, 22], ["+", 0, 235, 8, 201, 0, 195, 54, 55, 0, 25], ["+", 0, 235, 8, 201, 0, 195, 8, 306, 0, 221], ["+", 0, 195, 8, 306, 0, 213, 63, 214, 205, 22], ["+", 0, 195, 8, 306, 0, 213, 63, 214, 0, 131], ["+", 0, 195, 8, 306, 0, 213, 63, 214, 141, 22], ["+", 0, 195, 8, 306, 0, 213, 3, 4, 0, 24]]
8
6,817
30
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using static System.Console; using static System.Math; using static MyIO; using static MyUtil; public class E { public static void Main() => (new Solver()).Solve(); } public class Solver { public void Solve() { long N = GetLong(); long P = GetLong(); var S = GetString(); var num = S.Select(x => (long)(x - '0')).ToArray(); WriteLine((P == 2 || P == 5) ? solve1(N, P, num) : solve2(N, P, num)); } private long solve1(long N, long P, long[] num) { long cnt = 0; for (long i = N - 1; i >= 0; i--) { if (num[i] % P == 0) cnt += i + 1; } return cnt; } private long solve2(long N, long P, long[] num) { long cnt = 0; long r = 0; var dict = new Dictionary<long, long>(); dict[0] = 1; for (long i = N - 1; i >= 0; i--) { r = (r * 10 + num[i]) % P; long c = 0; dict.TryGetValue(r, out c); cnt += c; dict[r] = c + 1; } return cnt; } } public static class MyIO { private static string[] args = null; private static int num = -1; private static int used = -1; private static string getArg() { if (used == num) { args = Console.ReadLine().Split(' '); num = args.Length; used = 0; } return args[used++]; } public static int GetInt() => int.Parse(getArg()); public static long GetLong() => long.Parse(getArg()); public static double GetDouble() => double.Parse(getArg()); public static decimal GetDecimal() => decimal.Parse(getArg()); public static string GetString() => getArg(); public static char GetChar() => getArg()[0]; public static int[] GetInts(long N) => Enumerable.Range(0, (int)N).Select(_ => GetInt()).ToArray(); public static long[] GetLongs(long N) => Enumerable.Range(0, (int)N).Select(_ => GetLong()).ToArray(); public static double[] GetDoubles(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDouble()).ToArray(); public static decimal[] GetDecimals(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDecimal()).ToArray(); public static string[] GetStrings(long N) => Enumerable.Range(0, (int)N).Select(_ => GetString()).ToArray(); } public static class MyUtil { public static void chmax<T>(ref T x, T y) where T : IComparable<T> { if (x.CompareTo(y) < 0) x = y; } public static void chmin<T>(ref T x, T y) where T : IComparable<T> { if (x.CompareTo(y) > 0) x = y; } public static void swap<T>(ref T x, ref T y) { T tmp = x; x = y; y = tmp; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using static System.Console; using static System.Math; using static MyIO; using static MyUtil; public class E { public static void Main() => (new Solver()).Solve(); } public class Solver { public void Solve() { long N = GetLong(); long P = GetLong(); var S = GetString(); var num = S.Select(x => (long)(x - '0')).ToArray(); WriteLine((P == 2 || P == 5) ? solve1(N, P, num) : solve2(N, P, num)); } private long solve1(long N, long P, long[] num) { long cnt = 0; for (long i = N - 1; i >= 0; i--) { if (num[i] % P == 0) cnt += i + 1; } return cnt; } private long solve2(long N, long P, long[] num) { long cnt = 0; var dict = new Dictionary<long, long>(); dict[0] = 1; long r = 0; long pow = 1; for (long i = N - 1; i >= 0; i--) { r = (num[i] * pow + r) % P; pow = (pow * 10) % P; long c = 0; dict.TryGetValue(r, out c); cnt += c; dict[r] = c + 1; } return cnt; } } public static class MyIO { private static string[] args = null; private static int num = -1; private static int used = -1; private static string getArg() { if (used == num) { args = Console.ReadLine().Split(' '); num = args.Length; used = 0; } return args[used++]; } public static int GetInt() => int.Parse(getArg()); public static long GetLong() => long.Parse(getArg()); public static double GetDouble() => double.Parse(getArg()); public static decimal GetDecimal() => decimal.Parse(getArg()); public static string GetString() => getArg(); public static char GetChar() => getArg()[0]; public static int[] GetInts(long N) => Enumerable.Range(0, (int)N).Select(_ => GetInt()).ToArray(); public static long[] GetLongs(long N) => Enumerable.Range(0, (int)N).Select(_ => GetLong()).ToArray(); public static double[] GetDoubles(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDouble()).ToArray(); public static decimal[] GetDecimals(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDecimal()).ToArray(); public static string[] GetStrings(long N) => Enumerable.Range(0, (int)N).Select(_ => GetString()).ToArray(); } public static class MyUtil { public static void chmax<T>(ref T x, T y) where T : IComparable<T> { if (x.CompareTo(y) < 0) x = y; } public static void chmin<T>(ref T x, T y) where T : IComparable<T> { if (x.CompareTo(y) > 0) x = y; } public static void swap<T>(ref T x, ref T y) { T tmp = x; x = y; y = tmp; } }
[["-", 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, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 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, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 12, 16, 31, 23, 0, 16, 31, 16, 31, 22], ["-", 12, 16, 31, 23, 0, 16, 31, 16, 17, 48], ["-", 12, 16, 31, 23, 0, 16, 31, 16, 12, 203], ["-", 0, 11, 12, 16, 31, 23, 0, 16, 17, 72], ["+", 12, 16, 31, 23, 0, 16, 31, 16, 17, 48], ["+", 12, 16, 31, 23, 0, 16, 31, 16, 12, 22], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 12, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 109], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 31, 22], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 17, 48], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 12, 203]]
8
793
33
using System; using System.Linq; using System.Collections.Generic; namespace Contest { class Program { static void Main(string[] args) { ABC158E(); } static void ABC158A() { var str = ReadStr(); Console.WriteLine(str == "AAA" || str == "BBB" ? "No" : "Yes"); } static void ABC158B() { var nab = ReadLongN(); var N = nab[0]; var A = nab[1]; var B = nab[2]; var c = N / (A + B); var m = N - (A + B) * c; Console.WriteLine(c * A + Math.Min(m, A)); } static void ABC158C() { var ab = ReadIntN(); var A = ab[0]; var B = ab[1]; for (int i = 0; i < 2000; ++i) { if (i * 8 / 100 == A && i * 10 / 100 == B) { Console.WriteLine(i); return; } } Console.WriteLine(-1); } static void ABC158D() { var s = ReadStr(); var Q = ReadInt(); var S1 = new List<string>(); var S2 = new List<string>(); bool inv = false; for (int q = 0; q < Q; ++q) { var query = ReadStrN(); if (query[0] == "1") { inv = !inv; } else { var head = inv ^ query[1] == "1"; if (head) { S1.Add(query[2]); } else { S2.Add(query[2]); } } } if (inv) { S2.Reverse(); Console.WriteLine("{0}{1}{2}", String.Join("", S2), String.Join("", s.Reverse()), String.Join("", S1)); } else { S1.Reverse(); Console.WriteLine("{0}{1}{2}", String.Join("", S1), s, String.Join("", S2)); } } static void ABC158E() { var np = ReadIntN(); var N = np[0]; var P = np[1]; var s = ReadStr(); if (P == 5) { long sum = 0; for (int i = 0; i < N; ++i) { var X = s[i] - '0'; if (X == 0 || X == 5) { sum += i + 1; } } Console.WriteLine(sum); return; } else { var NP = new long[N]; long pow10 = 1; for (int i = 0; i < N; ++i) { var X = s[N - i - 1] - '0'; NP[i] = (X * pow10) % P; if (P != 2) { pow10 = (pow10 * 10) % P; } } var Asum = Util.ASum(NP, P); Dictionary<long, long> count = new Dictionary<long, long>(); foreach (var x in Asum) { if (!count.ContainsKey(x)) { count.Add(x, 0); } count[x]++; } long sum = 0; foreach (var kvp in count) { sum += kvp.Value * (kvp.Value - 1) / 2; } Console.WriteLine(sum); } } static void ABC158F() {} class Util { public static readonly long P = 1000000007; public static long Sum(long[] array) { return Sum(array, array.Length); } public static long Sum(long[] array, int n) { long total = 0; for (int i = 0; i < n; ++i) { total += array[i]; } return total; } public static long Count(long[] array, long x) { return Count(array, x, array.Length); } public static long Count(long[] array, long x, int n) { long total = 0; for (int i = 0; i < n; ++i) { total += (array[i] == x ? 1 : 0); } return total; } 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 long[] ASum(long[] array, long P) { var res = new long[array.Length + 1]; for (int i = 0; i < array.Length; ++i) { res[i + 1] = (res[i] + array[i]) % P; } return res; } public static long GCD(long a, long b) { while (b > 0) { var c = a % b; a = b; b = c; } return a; } public static bool IsPrime(long x) { var fact = Factorize(x); return fact.Count == 1 && fact.Values.ElementAt(0) == 1; } public static Dictionary<long, int> Factorize(long x) { var dict = new Dictionary<long, int>(); long minp = 2; while (x > 1) { bool ok = false; for (long p = minp; p * p <= x; ++p) { if (x % p == 0) { if (!dict.ContainsKey(p)) { dict.Add(p, 0); } dict[p]++; minp = p; x /= p; ok = true; break; } } if (!ok) { if (!dict.ContainsKey(x)) { dict.Add(x, 0); } dict[x]++; break; } } return dict; } 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; }; } /// <summary> /// Calc Combin(n,m) where n is large and m<=mMax /// </summary> public static Func<int, int, long> CombinLarge(int mMax, long p) { var inv = Enumerable.Range(0, mMax + 1) .Select(x => Util.Inverse(x, Util.P)) .ToArray(); return (n, m) => { long mult = 1; for (int i = 1; i <= m; ++i) { mult = (((mult * (n + 1 - i)) % Util.P) * inv[i]) % Util.P; } return mult; }; } /// <summary> /// Calc 2^n mod p /// </summary> public static long Power2(long n, long p) { return Power(2, n, p); } public static long Power(long a, long n, long p) { long res = 1; long mult = a; for (int i = 0; i < 40; ++i) { if ((n & ((long)1 << i)) > 0) { res = (res * mult) % p; } mult = (mult * mult) % p; } return res; } public static int Lowerbound<T1, T2>(SortedList<T1, T2> list, T1 x) where T1 : IComparable<T1> { return Lowerbound(list.Keys, x); } public static int Upperbound<T1, T2>(SortedList<T1, T2> list, T1 x) where T1 : IComparable<T1> { return Upperbound(list.Keys, x); } public static int Lowerbound<T>(IList<T> list, T x) where T : IComparable<T> { int min = 0; int max = list.Count; while (min < max) { var mid = (min + max) / 2; if (list[mid].CompareTo(x) >= 0) { max = mid; } else { min = mid + 1; } } return max; } public static int Upperbound<T>(IList<T> list, T x) where T : IComparable<T> { int min = 0; int max = list.Count; while (min < max) { var mid = (min + max) / 2; if (list[mid].CompareTo(x) > 0) { max = mid; } else { min = mid + 1; } } return max; } /// <summary> /// Thanks to yambe2002-san /// </summary> public class BST<T> where T : IComparable { public class Node { public T V; public Node L, R; public int Count; public Node(T v) { V = v; Count = 1; } } static Random _rnd = new Random(); public static int Count(Node t) { return t == null ? 0 : t.Count; } static Node Update(Node t) { t.Count = Count(t.L) + Count(t.R) + 1; return t; } public static Node Merge(Node l, Node r) { if (l == null || r == null) return l == null ? r : l; if ((double)Count(l) / (double)(Count(l) + Count(r)) > _rnd.NextDouble()) { l.R = Merge(l.R, r); return Update(l); } else { r.L = Merge(l, r.L); return Update(r); } } public static Tuple<Node, Node> Split(Node t, int k) { if (t == null) return new Tuple<Node, Node>(null, null); if (k <= Count(t.L)) { var s = Split(t.L, k); t.L = s.Item2; return new Tuple<Node, Node>(s.Item1, Update(t)); } else { var s = Split(t.R, k - Count(t.L) - 1); t.R = s.Item1; return new Tuple<Node, Node>(Update(t), s.Item2); } } public static Node Remove(Node t, T v) { if (Find(t, v) == null) return t; return RemoveAt(t, LowerBound(t, v)); } public static Node RemoveAt(Node t, int k) { var s = Split(t, k); var s2 = Split(s.Item2, 1); return Merge(s.Item1, s2.Item2); } public static bool Contains(Node t, T v) { return Find(t, v) != null; } public static Node Find(Node t, T v) { while (t != null) { var cmp = t.V.CompareTo(v); if (cmp > 0) t = t.L; else if (cmp < 0) t = t.R; else break; } return t; } public static Node FindByIndex(Node t, int idx) { if (t == null) return null; var currentIdx = Count(t) - Count(t.R) - 1; while (t != null) { if (currentIdx == idx) return t; if (currentIdx > idx) { t = t.L; currentIdx -= (Count(t == null ? null : t.R) + 1); } else { t = t.R; currentIdx += (Count(t == null ? null : t.L) + 1); } } return null; } public static int UpperBound(Node t, T v) { var torg = t; if (t == null) return -1; var ret = Int32.MaxValue; var idx = Count(t) - Count(t.R) - 1; while (t != null) { var cmp = t.V.CompareTo(v); if (cmp > 0) { ret = Math.Min(ret, idx); t = t.L; idx -= (Count(t == null ? null : t.R) + 1); } else if (cmp <= 0) { t = t.R; idx += (Count(t == null ? null : t.L) + 1); } } return ret == Int32.MaxValue ? Count(torg) : ret; } public static int LowerBound(Node t, T v) { var torg = t; if (t == null) return -1; var idx = Count(t) - Count(t.R) - 1; var ret = Int32.MaxValue; while (t != null) { var cmp = t.V.CompareTo(v); if (cmp >= 0) { if (cmp == 0) ret = Math.Min(ret, idx); t = t.L; if (t == null) ret = Math.Min(ret, idx); idx -= t == null ? 0 : (Count(t.R) + 1); } else if (cmp < 0) { t = t.R; idx += (Count(t == null ? null : t.L) + 1); if (t == null) return idx; } } return ret == Int32.MaxValue ? Count(torg) : ret; } public static Node Insert(Node t, T v) { var ub = LowerBound(t, v); return InsertByIdx(t, ub, v); } static Node InsertByIdx(Node t, int k, T v) { var s = Split(t, k); return Merge(Merge(s.Item1, new Node(v)), s.Item2); } public static IEnumerable<T> Enumerate(Node t) { var ret = new List<T>(); Enumerate(t, ret); return ret; } static void Enumerate(Node t, List<T> ret) { if (t == null) return; Enumerate(t.L, ret); ret.Add(t.V); Enumerate(t.R, ret); } } public class Set<T> where T : IComparable { protected BST<T>.Node _root; public T this[int idx] { get { return ElementAt(idx); } } public int Count() { return BST<T>.Count(_root); } public virtual void Insert(T v) { if (_root == null) _root = new BST<T>.Node(v); else { if (BST<T>.Find(_root, v) != null) return; _root = BST<T>.Insert(_root, v); } } public void Clear() { _root = null; } public void Remove(T v) { _root = BST<T>.Remove(_root, v); } public bool Contains(T v) { return BST<T>.Contains(_root, v); } public T ElementAt(int k) { var node = BST<T>.FindByIndex(_root, k); if (node == null) throw new IndexOutOfRangeException(); return node.V; } public int Count(T v) { return BST<T>.UpperBound(_root, v) - BST<T>.LowerBound(_root, v); } public int LowerBound(T v) { return BST<T>.LowerBound(_root, v); } public int UpperBound(T v) { return BST<T>.UpperBound(_root, v); } public Tuple<int, int> EqualRange(T v) { if (!Contains(v)) return new Tuple<int, int>(-1, -1); return new Tuple<int, int>(BST<T>.LowerBound(_root, v), BST<T>.UpperBound(_root, v) - 1); } public List<T> ToList() { return new List<T>(BST<T>.Enumerate(_root)); } } public class MultiSet<T> : Set<T> where T : IComparable { public override void Insert(T v) { if (_root == null) { _root = new BST<T>.Node(v); } else { _root = BST<T>.Insert(_root, v); } } } } class Graph { public static HashSet<int> ConnectedComponent(Dictionary<int, HashSet<int>> adj, int idx) { HashSet<int> comp = new HashSet<int>(); comp.Add(idx); List<int> target = new List<int>(); target.Add(idx); while (target.Count > 0) { List<int> next = new List<int>(); foreach (var p in target) { foreach (var f in adj[p]) { if (!comp.Contains(f)) { next.Add(f); comp.Add(f); } } } target = next; } return comp; } } static string ReadStr() { return Console.ReadLine(); } static string[] ReadStrN() { return Console.ReadLine().Split(' '); } static int ReadInt() { return Convert.ToInt32(Console.ReadLine()); } static int[] ReadIntN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt32(s)) .ToArray(); } static long ReadLong() { return Convert.ToInt64(Console.ReadLine()); } static long[] ReadLongN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt64(s)) .ToArray(); } static Tuple<string, string>[] ReadTupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = ReadStrN(); list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<long, long>[] ReadTupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = ReadLongN(); list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<double, double>[] ReadTupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = ReadLongN(); list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); } static Dictionary<int, HashSet<int>> ReadAdjacencyList(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 = ReadIntN(); dict[ab[0]].Add(ab[1]); dict[ab[1]].Add(ab[0]); } return dict; } } }
using System; using System.Linq; using System.Collections.Generic; namespace Contest { class Program { static void Main(string[] args) { ABC158E(); } static void ABC158A() { var str = ReadStr(); Console.WriteLine(str == "AAA" || str == "BBB" ? "No" : "Yes"); } static void ABC158B() { var nab = ReadLongN(); var N = nab[0]; var A = nab[1]; var B = nab[2]; var c = N / (A + B); var m = N - (A + B) * c; Console.WriteLine(c * A + Math.Min(m, A)); } static void ABC158C() { var ab = ReadIntN(); var A = ab[0]; var B = ab[1]; for (int i = 0; i < 2000; ++i) { if (i * 8 / 100 == A && i * 10 / 100 == B) { Console.WriteLine(i); return; } } Console.WriteLine(-1); } static void ABC158D() { var s = ReadStr(); var Q = ReadInt(); var S1 = new List<string>(); var S2 = new List<string>(); bool inv = false; for (int q = 0; q < Q; ++q) { var query = ReadStrN(); if (query[0] == "1") { inv = !inv; } else { var head = inv ^ query[1] == "1"; if (head) { S1.Add(query[2]); } else { S2.Add(query[2]); } } } if (inv) { S2.Reverse(); Console.WriteLine("{0}{1}{2}", String.Join("", S2), String.Join("", s.Reverse()), String.Join("", S1)); } else { S1.Reverse(); Console.WriteLine("{0}{1}{2}", String.Join("", S1), s, String.Join("", S2)); } } static void ABC158E() { var np = ReadIntN(); var N = np[0]; var P = np[1]; var s = ReadStr(); if (P == 2 || P == 5) { long sum = 0; for (int i = 0; i < N; ++i) { var X = s[i] - '0'; if (X % P == 0) { sum += i + 1; } } Console.WriteLine(sum); return; } else { var NP = new long[N]; long pow10 = 1; for (int i = 0; i < N; ++i) { var X = s[N - i - 1] - '0'; NP[i] = (X * pow10) % P; pow10 = (pow10 * 10) % P; } var Asum = Util.ASum(NP, P); Dictionary<long, long> count = new Dictionary<long, long>(); foreach (var x in Asum) { if (!count.ContainsKey(x)) { count.Add(x, 0); } count[x]++; } long sum = 0; foreach (var kvp in count) { sum += kvp.Value * (kvp.Value - 1) / 2; } Console.WriteLine(sum); } } static void ABC158F() {} class Util { public static readonly long P = 1000000007; public static long Sum(long[] array) { return Sum(array, array.Length); } public static long Sum(long[] array, int n) { long total = 0; for (int i = 0; i < n; ++i) { total += array[i]; } return total; } public static long Count(long[] array, long x) { return Count(array, x, array.Length); } public static long Count(long[] array, long x, int n) { long total = 0; for (int i = 0; i < n; ++i) { total += (array[i] == x ? 1 : 0); } return total; } 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 long[] ASum(long[] array, long P) { var res = new long[array.Length + 1]; for (int i = 0; i < array.Length; ++i) { res[i + 1] = (res[i] + array[i]) % P; } return res; } public static long GCD(long a, long b) { while (b > 0) { var c = a % b; a = b; b = c; } return a; } public static bool IsPrime(long x) { var fact = Factorize(x); return fact.Count == 1 && fact.Values.ElementAt(0) == 1; } public static Dictionary<long, int> Factorize(long x) { var dict = new Dictionary<long, int>(); long minp = 2; while (x > 1) { bool ok = false; for (long p = minp; p * p <= x; ++p) { if (x % p == 0) { if (!dict.ContainsKey(p)) { dict.Add(p, 0); } dict[p]++; minp = p; x /= p; ok = true; break; } } if (!ok) { if (!dict.ContainsKey(x)) { dict.Add(x, 0); } dict[x]++; break; } } return dict; } 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; }; } /// <summary> /// Calc Combin(n,m) where n is large and m<=mMax /// </summary> public static Func<int, int, long> CombinLarge(int mMax, long p) { var inv = Enumerable.Range(0, mMax + 1) .Select(x => Util.Inverse(x, Util.P)) .ToArray(); return (n, m) => { long mult = 1; for (int i = 1; i <= m; ++i) { mult = (((mult * (n + 1 - i)) % Util.P) * inv[i]) % Util.P; } return mult; }; } /// <summary> /// Calc 2^n mod p /// </summary> public static long Power2(long n, long p) { return Power(2, n, p); } public static long Power(long a, long n, long p) { long res = 1; long mult = a; for (int i = 0; i < 40; ++i) { if ((n & ((long)1 << i)) > 0) { res = (res * mult) % p; } mult = (mult * mult) % p; } return res; } public static int Lowerbound<T1, T2>(SortedList<T1, T2> list, T1 x) where T1 : IComparable<T1> { return Lowerbound(list.Keys, x); } public static int Upperbound<T1, T2>(SortedList<T1, T2> list, T1 x) where T1 : IComparable<T1> { return Upperbound(list.Keys, x); } public static int Lowerbound<T>(IList<T> list, T x) where T : IComparable<T> { int min = 0; int max = list.Count; while (min < max) { var mid = (min + max) / 2; if (list[mid].CompareTo(x) >= 0) { max = mid; } else { min = mid + 1; } } return max; } public static int Upperbound<T>(IList<T> list, T x) where T : IComparable<T> { int min = 0; int max = list.Count; while (min < max) { var mid = (min + max) / 2; if (list[mid].CompareTo(x) > 0) { max = mid; } else { min = mid + 1; } } return max; } /// <summary> /// Thanks to yambe2002-san /// </summary> public class BST<T> where T : IComparable { public class Node { public T V; public Node L, R; public int Count; public Node(T v) { V = v; Count = 1; } } static Random _rnd = new Random(); public static int Count(Node t) { return t == null ? 0 : t.Count; } static Node Update(Node t) { t.Count = Count(t.L) + Count(t.R) + 1; return t; } public static Node Merge(Node l, Node r) { if (l == null || r == null) return l == null ? r : l; if ((double)Count(l) / (double)(Count(l) + Count(r)) > _rnd.NextDouble()) { l.R = Merge(l.R, r); return Update(l); } else { r.L = Merge(l, r.L); return Update(r); } } public static Tuple<Node, Node> Split(Node t, int k) { if (t == null) return new Tuple<Node, Node>(null, null); if (k <= Count(t.L)) { var s = Split(t.L, k); t.L = s.Item2; return new Tuple<Node, Node>(s.Item1, Update(t)); } else { var s = Split(t.R, k - Count(t.L) - 1); t.R = s.Item1; return new Tuple<Node, Node>(Update(t), s.Item2); } } public static Node Remove(Node t, T v) { if (Find(t, v) == null) return t; return RemoveAt(t, LowerBound(t, v)); } public static Node RemoveAt(Node t, int k) { var s = Split(t, k); var s2 = Split(s.Item2, 1); return Merge(s.Item1, s2.Item2); } public static bool Contains(Node t, T v) { return Find(t, v) != null; } public static Node Find(Node t, T v) { while (t != null) { var cmp = t.V.CompareTo(v); if (cmp > 0) t = t.L; else if (cmp < 0) t = t.R; else break; } return t; } public static Node FindByIndex(Node t, int idx) { if (t == null) return null; var currentIdx = Count(t) - Count(t.R) - 1; while (t != null) { if (currentIdx == idx) return t; if (currentIdx > idx) { t = t.L; currentIdx -= (Count(t == null ? null : t.R) + 1); } else { t = t.R; currentIdx += (Count(t == null ? null : t.L) + 1); } } return null; } public static int UpperBound(Node t, T v) { var torg = t; if (t == null) return -1; var ret = Int32.MaxValue; var idx = Count(t) - Count(t.R) - 1; while (t != null) { var cmp = t.V.CompareTo(v); if (cmp > 0) { ret = Math.Min(ret, idx); t = t.L; idx -= (Count(t == null ? null : t.R) + 1); } else if (cmp <= 0) { t = t.R; idx += (Count(t == null ? null : t.L) + 1); } } return ret == Int32.MaxValue ? Count(torg) : ret; } public static int LowerBound(Node t, T v) { var torg = t; if (t == null) return -1; var idx = Count(t) - Count(t.R) - 1; var ret = Int32.MaxValue; while (t != null) { var cmp = t.V.CompareTo(v); if (cmp >= 0) { if (cmp == 0) ret = Math.Min(ret, idx); t = t.L; if (t == null) ret = Math.Min(ret, idx); idx -= t == null ? 0 : (Count(t.R) + 1); } else if (cmp < 0) { t = t.R; idx += (Count(t == null ? null : t.L) + 1); if (t == null) return idx; } } return ret == Int32.MaxValue ? Count(torg) : ret; } public static Node Insert(Node t, T v) { var ub = LowerBound(t, v); return InsertByIdx(t, ub, v); } static Node InsertByIdx(Node t, int k, T v) { var s = Split(t, k); return Merge(Merge(s.Item1, new Node(v)), s.Item2); } public static IEnumerable<T> Enumerate(Node t) { var ret = new List<T>(); Enumerate(t, ret); return ret; } static void Enumerate(Node t, List<T> ret) { if (t == null) return; Enumerate(t.L, ret); ret.Add(t.V); Enumerate(t.R, ret); } } public class Set<T> where T : IComparable { protected BST<T>.Node _root; public T this[int idx] { get { return ElementAt(idx); } } public int Count() { return BST<T>.Count(_root); } public virtual void Insert(T v) { if (_root == null) _root = new BST<T>.Node(v); else { if (BST<T>.Find(_root, v) != null) return; _root = BST<T>.Insert(_root, v); } } public void Clear() { _root = null; } public void Remove(T v) { _root = BST<T>.Remove(_root, v); } public bool Contains(T v) { return BST<T>.Contains(_root, v); } public T ElementAt(int k) { var node = BST<T>.FindByIndex(_root, k); if (node == null) throw new IndexOutOfRangeException(); return node.V; } public int Count(T v) { return BST<T>.UpperBound(_root, v) - BST<T>.LowerBound(_root, v); } public int LowerBound(T v) { return BST<T>.LowerBound(_root, v); } public int UpperBound(T v) { return BST<T>.UpperBound(_root, v); } public Tuple<int, int> EqualRange(T v) { if (!Contains(v)) return new Tuple<int, int>(-1, -1); return new Tuple<int, int>(BST<T>.LowerBound(_root, v), BST<T>.UpperBound(_root, v) - 1); } public List<T> ToList() { return new List<T>(BST<T>.Enumerate(_root)); } } public class MultiSet<T> : Set<T> where T : IComparable { public override void Insert(T v) { if (_root == null) { _root = new BST<T>.Node(v); } else { _root = BST<T>.Insert(_root, v); } } } } class Graph { public static HashSet<int> ConnectedComponent(Dictionary<int, HashSet<int>> adj, int idx) { HashSet<int> comp = new HashSet<int>(); comp.Add(idx); List<int> target = new List<int>(); target.Add(idx); while (target.Count > 0) { List<int> next = new List<int>(); foreach (var p in target) { foreach (var f in adj[p]) { if (!comp.Contains(f)) { next.Add(f); comp.Add(f); } } } target = next; } return comp; } } static string ReadStr() { return Console.ReadLine(); } static string[] ReadStrN() { return Console.ReadLine().Split(' '); } static int ReadInt() { return Convert.ToInt32(Console.ReadLine()); } static int[] ReadIntN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt32(s)) .ToArray(); } static long ReadLong() { return Convert.ToInt64(Console.ReadLine()); } static long[] ReadLongN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt64(s)) .ToArray(); } static Tuple<string, string>[] ReadTupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = ReadStrN(); list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<long, long>[] ReadTupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = ReadLongN(); list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<double, double>[] ReadTupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = ReadLongN(); list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); } static Dictionary<int, HashSet<int>> ReadAdjacencyList(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 = ReadIntN(); dict[ab[0]].Add(ab[1]); dict[ab[1]].Add(ab[0]); } return dict; } } }
[["+", 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, 31, 16, 17, 109], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["-", 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, 60], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["-", 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, 79], ["-", 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, 45], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
4,415
18
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Numerics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Math; using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute; using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions; public static class P { public static void Main() { var np = Console.ReadLine().Split().Select(int.Parse).ToArray(); var s = Console.ReadLine(); var p = np[1]; var res = 0L; if (p == 2 || p == 5) { for (int i = 0; i < s.Length; i++) { if ((s[i] - '0') % p == 0) { res += i + 1; } } Console.WriteLine(res); return; } var accum = new int[s.Length + 1]; accum[accum.Length - 1] = 0; for (int i = s.Length - 1; i >= 0; i--) { accum[i] = accum[i + 1] * 10 + s[i] - '0'; accum[i] %= p; } foreach (var item in accum.GroupBy(x => x)) { long count = item.Count(); res += count * (count - 1) / 2; } Console.WriteLine(res); } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Numerics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Math; using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute; using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions; public static class P { public static void Main() { var np = Console.ReadLine().Split().Select(int.Parse).ToArray(); var s = Console.ReadLine(); var p = np[1]; var res = 0L; if (p == 2 || p == 5) { for (int i = 0; i < s.Length; i++) { if ((s[i] - '0') % p == 0) { res += i + 1; } } Console.WriteLine(res); return; } var accum = new int[s.Length + 1]; accum[accum.Length - 1] = 0; var pow = 1; for (int i = s.Length - 1; i >= 0; i--) { accum[i] = accum[i + 1] + (s[i] - '0') * pow; accum[i] %= p; pow *= 10; pow %= p; } foreach (var item in accum.GroupBy(x => x)) { long count = item.Count(); res += count * (count - 1) / 2; } Console.WriteLine(res); } }
[["+", 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, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 11, 12, 16, 31, 16, 31, 16, 17, 48], ["-", 0, 11, 12, 16, 31, 16, 31, 16, 12, 203], ["+", 0, 11, 12, 16, 12, 16, 31, 23, 0, 24], ["+", 0, 11, 12, 16, 12, 16, 31, 23, 0, 25], ["+", 0, 1, 0, 11, 12, 16, 12, 16, 17, 48], ["+", 0, 1, 0, 11, 12, 16, 12, 16, 12, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 132], ["+", 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, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 108], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 12, 203]]
8
324
19
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.CompilerServices; namespace V { partial class Solver { public void Solve() { // var n = Read; Write(SolveLong()); // YesNo(SolveBool()); } public long SolveLong() { Mint.Set998244353(); var n = ReadInt; var robots = sc.Pairs(n).OrderByDescending(x => x.X).ToArray(); var xs = robots.Select(x => -x.X).ToArray(); var dp = new Mint[n + 1]; var seg = new C.SegmentTree<int>(Enumerable.Range(0, (int)n).ToArray(), (x, y) => Math.Min(x, y), int.MaxValue); var cdp = new long[n]; dp[0] = new Mint(1); for (int i = 0; i < n; i++) { var r = robots[i]; var xd = r.X + r.Y - 1; var idx = C.BinarySearch.GetLastIndexLess(-xd, xs) + 1; var affected = seg.Query((int)idx, i + 1); seg.Update(i, affected); dp[i + 1] = dp[i] + dp[affected]; } return dp[n].Value; } 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(); } } 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 SafeAdd<T>(this HashSet<T> ts, T t) { if (ts.Contains(t)) { return false; } else { ts.Add(t); return false; } } public static bool SafeRemove<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 SegmentTree<T> { private readonly int valueCount; private readonly int baseCount; private readonly int baseIndex; private readonly T[] nodes; private readonly Func<T, T, T> func; private readonly T defaultValue; public SegmentTree(IReadOnlyList<T> ts, Func<T, T, T> func, T filling = default(T)) { this.func = func; this.defaultValue = filling; valueCount = ts.Count; baseCount = 1; while (valueCount > baseCount) baseCount <<= 1; nodes = new T[baseCount * 2 - 1]; baseIndex = baseCount - 1; for (int i = 0; i < ts.Count; i++) nodes[baseIndex + i] = ts[i]; for (int i = ts.Count; i < baseCount; i++) nodes[baseIndex + i] = filling; for (int i = baseIndex - 1; i >= 0; i--) nodes[i] = func.Invoke(nodes[i * 2 + 1], nodes[i * 2 + 2]); } public void Update(int index, T t) { var i = baseIndex + index; nodes[i] = t; do { i -= 1; i /= 2; nodes[i] = func.Invoke(nodes[i * 2 + 1], nodes[i * 2 + 2]); } while (i > 0); } public T Query(int leftIndex, int rightNextIndex) { T left = defaultValue; T right = defaultValue; int l = leftIndex + baseCount - 1; int r = rightNextIndex + baseCount - 1; for (; l < r; l >>= 1, r >>= 1) { if ((l & 1) == 0) left = func.Invoke(left, nodes[l]); if ((r & 1) == 0) left = func.Invoke(left, nodes[l]); } return func.Invoke(left, right); } } public class UnionFind { private int[] parents; [MethodImpl(MethodImplOptions.AggressiveInlining)] public UnionFind(int count) { parents = Enumerable.Repeat(-1, count).ToArray(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryUnite(int x, int y) { var rootX = GetRoot(x); var rootY = GetRoot(y); if (rootX == rootY) return false; if (parents[rootY] < parents[rootX]) { var temp = rootX; rootX = rootY; rootY = temp; } parents[rootX] += parents[rootY]; parents[rootY] = rootX; return true; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Find(int x, int y) => GetRoot(x) == GetRoot(y); [MethodImpl(MethodImplOptions.AggressiveInlining)] public int GetRoot(int x) { while (parents[x] >= 0) x = parents[x]; return x; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public long GetSize(int x) => -parents[GetRoot(x)]; } public class IterTools { /// <summary> /// 組み合わせ(重複なし) /// n = 4, k = 3 => (0,1,2) (0,1,3) (0,2,3) (1,2,3) /// </summary> [MethodImpl(MethodImplOptions.AggressiveInlining)] 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> [MethodImpl(MethodImplOptions.AggressiveInlining)] 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> [MethodImpl(MethodImplOptions.AggressiveInlining)] 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> [MethodImpl(MethodImplOptions.AggressiveInlining)] 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> [MethodImpl(MethodImplOptions.AggressiveInlining)] 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> [MethodImpl(MethodImplOptions.AggressiveInlining)] 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); } [MethodImpl(MethodImplOptions.AggressiveInlining)] 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); } [MethodImpl(MethodImplOptions.AggressiveInlining)] 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; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] 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(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] 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; } [MethodImpl(MethodImplOptions.AggressiveInlining)] private void ValidateNonEmpty() { if (Count == 0) throw new IndexOutOfRangeException(); } } public class BinaryIndexTree { long length; long[] binaryIndexedTree; [MethodImpl(MethodImplOptions.AggressiveInlining)] public BinaryIndexTree(long length) { this.length = length; binaryIndexedTree = new long[length + 1]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Add(long indexZeroBase, long additional) { // i += i & -i // 1が立っている最下位ビットを足す、の意味 for (long i = indexZeroBase + 1; i <= length; i += i & -i) { binaryIndexedTree[i] += additional; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] 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 { [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long GetFirstIndexGreater<T>(T x, IList<T> listOrdered) where T : IComparable { return GetFirstIndexGreater(x, listOrdered, 0, listOrdered.Count - 1); } [MethodImpl(MethodImplOptions.AggressiveInlining)] 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; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long GetLastIndexLess<T>(T x, IList<T> listOrdered) where T : IComparable { return GetLastIndexLess(x, listOrdered, 0, listOrdered.Count - 1); } [MethodImpl(MethodImplOptions.AggressiveInlining)] 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; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] 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> [MethodImpl(MethodImplOptions.AggressiveInlining)] 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; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Gcd(int a, int b) => Gcd((long)a, (long)b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Gcd(long a, long b) { if (a < b) return GcdImpl(b, a); else return GcdImpl(a, b); } [MethodImpl(MethodImplOptions.AggressiveInlining)] private static long GcdImpl(long a, long b) { var remainder = a % b; if (remainder == 0) return b; else return GcdImpl(b, remainder); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Lcm(int a, int b) => Lcm((long)a, (long)b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Lcm(long a, long b) { return a / Gcd(a, b) * b; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Pow(int n, int p) => Pow((long)n, (long)p); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Pow(long n, long p) { var res = 1L; for (long i = 0; i < p; i++) res *= n; return res; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Dictionary<long, long> Factorize(int n) => Factorize((long)n); [MethodImpl(MethodImplOptions.AggressiveInlining)] 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; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<long> Divisors(int n) => Divisors((long)n); [MethodImpl(MethodImplOptions.AggressiveInlining)] 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; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<int> Loop(int n) { for (int i = 0; i < n; i++) yield return i; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<long> Loop(long n) { for (long i = 0L; i < n; i++) yield return i; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<T> Repeat<T>(T t, long n) { for (long i = 0L; i < n; i++) yield return t; } } struct Mint { public static long Divider { set { divider = value; } } private static long divider = 1000000007L; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Set998244353() { divider = 998244353L; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Set1000000009() { divider = 1000000009L; } public long Value { get; } public override string ToString() => this.Value.ToString(); [MethodImpl(MethodImplOptions.AggressiveInlining)] 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; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator +(Mint a, Mint b) => new Mint((a.Value + b.Value) % divider); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator +(Mint a, long b) => a + new Mint(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator +(Mint a, int b) => a + new Mint(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator -(Mint a, Mint b) { var t = (a.Value - b.Value) % divider; if (t < 0L) t += divider; return new Mint(t); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator -(Mint a, long b) => a - new Mint(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator -(Mint a, int b) => a - new Mint(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator *(Mint a, Mint b) => new Mint((a.Value * b.Value) % divider); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator *(Mint a, long b) => a * new Mint(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator *(Mint a, int b) => a * new Mint(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator /(Mint a, Mint b) => new Mint((a.Value * InvImpl(b.Value)) % divider); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator /(Mint a, long b) => a / new Mint(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator /(Mint a, int b) => a / new Mint(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Mint Pow(long p) => new Mint(PowImpl(Value, p)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint Pow(long a, long p) => new Mint(PowImpl(a, p)); [MethodImpl(MethodImplOptions.AggressiveInlining)] 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; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint Inv(long a) => new Mint(InvImpl(a)); private static readonly Dictionary<long, long> invCache = new Dictionary<long, long>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] 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; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint Fac(long a) => new Mint(FacImpl(a)); private static long[] facCache = new long[262144]; private static long cachedFac = 0L; [MethodImpl(MethodImplOptions.AggressiveInlining)] 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]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] private static void ExtendFacCache(long newSize) { long[] newFacCache = new long[newSize]; facCache.CopyTo(newFacCache, 0); facCache = newFacCache; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint Perm(long n, long r) => new Mint(PermImpl(n, r)); [MethodImpl(MethodImplOptions.AggressiveInlining)] 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; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint Comb(long n, long r) => new Mint(CombImpl(n, r)); [MethodImpl(MethodImplOptions.AggressiveInlining)] 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; using System.Runtime.CompilerServices; namespace V { partial class Solver { public void Solve() { // var n = Read; Write(SolveLong()); // YesNo(SolveBool()); } public long SolveLong() { Mint.Set998244353(); var n = ReadInt; var robots = sc.Pairs(n).OrderByDescending(x => x.X).ToArray(); var xs = robots.Select(x => -x.X).ToArray(); var dp = new Mint[n + 1]; var seg = new C.SegmentTree<int>(Enumerable.Range(0, (int)n).ToArray(), (x, y) => Math.Min(x, y), int.MaxValue); var cdp = new long[n]; dp[0] = new Mint(1); for (int i = 0; i < n; i++) { var r = robots[i]; var xd = r.X + r.Y - 1; var idx = C.BinarySearch.GetLastIndexLess(-xd, xs) + 1; var affected = seg.Query((int)idx, i + 1); seg.Update(i, affected); dp[i + 1] = dp[i] + dp[affected]; } return dp[n].Value; } 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(); } } 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 SafeAdd<T>(this HashSet<T> ts, T t) { if (ts.Contains(t)) { return false; } else { ts.Add(t); return false; } } public static bool SafeRemove<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 SegmentTree<T> { private readonly int valueCount; private readonly int baseCount; private readonly int baseIndex; private readonly T[] nodes; private readonly Func<T, T, T> func; private readonly T defaultValue; public SegmentTree(IReadOnlyList<T> ts, Func<T, T, T> func, T filling = default(T)) { this.func = func; this.defaultValue = filling; valueCount = ts.Count; baseCount = 1; while (valueCount > baseCount) baseCount <<= 1; nodes = new T[baseCount * 2 - 1]; baseIndex = baseCount - 1; for (int i = 0; i < ts.Count; i++) nodes[baseIndex + i] = ts[i]; for (int i = ts.Count; i < baseCount; i++) nodes[baseIndex + i] = filling; for (int i = baseIndex - 1; i >= 0; i--) nodes[i] = func.Invoke(nodes[i * 2 + 1], nodes[i * 2 + 2]); } public void Update(int index, T t) { var i = baseIndex + index; nodes[i] = t; while (i > 0) { i -= 1; i /= 2; nodes[i] = func.Invoke(nodes[i * 2 + 1], nodes[i * 2 + 2]); } } public T Query(int leftIndex, int rightNextIndex) { T left = defaultValue; T right = defaultValue; int l = leftIndex + baseCount - 1; int r = rightNextIndex + baseCount - 1; for (; l < r; l >>= 1, r >>= 1) { if ((l & 1) == 0) left = func.Invoke(left, nodes[l]); if ((r & 1) == 0) left = func.Invoke(left, nodes[l]); } return func.Invoke(left, right); } } public class UnionFind { private int[] parents; [MethodImpl(MethodImplOptions.AggressiveInlining)] public UnionFind(int count) { parents = Enumerable.Repeat(-1, count).ToArray(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryUnite(int x, int y) { var rootX = GetRoot(x); var rootY = GetRoot(y); if (rootX == rootY) return false; if (parents[rootY] < parents[rootX]) { var temp = rootX; rootX = rootY; rootY = temp; } parents[rootX] += parents[rootY]; parents[rootY] = rootX; return true; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Find(int x, int y) => GetRoot(x) == GetRoot(y); [MethodImpl(MethodImplOptions.AggressiveInlining)] public int GetRoot(int x) { while (parents[x] >= 0) x = parents[x]; return x; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public long GetSize(int x) => -parents[GetRoot(x)]; } public class IterTools { /// <summary> /// 組み合わせ(重複なし) /// n = 4, k = 3 => (0,1,2) (0,1,3) (0,2,3) (1,2,3) /// </summary> [MethodImpl(MethodImplOptions.AggressiveInlining)] 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> [MethodImpl(MethodImplOptions.AggressiveInlining)] 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> [MethodImpl(MethodImplOptions.AggressiveInlining)] 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> [MethodImpl(MethodImplOptions.AggressiveInlining)] 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> [MethodImpl(MethodImplOptions.AggressiveInlining)] 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> [MethodImpl(MethodImplOptions.AggressiveInlining)] 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); } [MethodImpl(MethodImplOptions.AggressiveInlining)] 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); } [MethodImpl(MethodImplOptions.AggressiveInlining)] 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; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] 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(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] 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; } [MethodImpl(MethodImplOptions.AggressiveInlining)] private void ValidateNonEmpty() { if (Count == 0) throw new IndexOutOfRangeException(); } } public class BinaryIndexTree { long length; long[] binaryIndexedTree; [MethodImpl(MethodImplOptions.AggressiveInlining)] public BinaryIndexTree(long length) { this.length = length; binaryIndexedTree = new long[length + 1]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Add(long indexZeroBase, long additional) { // i += i & -i // 1が立っている最下位ビットを足す、の意味 for (long i = indexZeroBase + 1; i <= length; i += i & -i) { binaryIndexedTree[i] += additional; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] 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 { [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long GetFirstIndexGreater<T>(T x, IList<T> listOrdered) where T : IComparable { return GetFirstIndexGreater(x, listOrdered, 0, listOrdered.Count - 1); } [MethodImpl(MethodImplOptions.AggressiveInlining)] 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; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long GetLastIndexLess<T>(T x, IList<T> listOrdered) where T : IComparable { return GetLastIndexLess(x, listOrdered, 0, listOrdered.Count - 1); } [MethodImpl(MethodImplOptions.AggressiveInlining)] 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; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] 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> [MethodImpl(MethodImplOptions.AggressiveInlining)] 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; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Gcd(int a, int b) => Gcd((long)a, (long)b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Gcd(long a, long b) { if (a < b) return GcdImpl(b, a); else return GcdImpl(a, b); } [MethodImpl(MethodImplOptions.AggressiveInlining)] private static long GcdImpl(long a, long b) { var remainder = a % b; if (remainder == 0) return b; else return GcdImpl(b, remainder); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Lcm(int a, int b) => Lcm((long)a, (long)b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Lcm(long a, long b) { return a / Gcd(a, b) * b; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Pow(int n, int p) => Pow((long)n, (long)p); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Pow(long n, long p) { var res = 1L; for (long i = 0; i < p; i++) res *= n; return res; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Dictionary<long, long> Factorize(int n) => Factorize((long)n); [MethodImpl(MethodImplOptions.AggressiveInlining)] 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; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<long> Divisors(int n) => Divisors((long)n); [MethodImpl(MethodImplOptions.AggressiveInlining)] 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; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<int> Loop(int n) { for (int i = 0; i < n; i++) yield return i; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<long> Loop(long n) { for (long i = 0L; i < n; i++) yield return i; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<T> Repeat<T>(T t, long n) { for (long i = 0L; i < n; i++) yield return t; } } struct Mint { public static long Divider { set { divider = value; } } private static long divider = 1000000007L; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Set998244353() { divider = 998244353L; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Set1000000009() { divider = 1000000009L; } public long Value { get; } public override string ToString() => this.Value.ToString(); [MethodImpl(MethodImplOptions.AggressiveInlining)] 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; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator +(Mint a, Mint b) => new Mint((a.Value + b.Value) % divider); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator +(Mint a, long b) => a + new Mint(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator +(Mint a, int b) => a + new Mint(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator -(Mint a, Mint b) { var t = (a.Value - b.Value) % divider; if (t < 0L) t += divider; return new Mint(t); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator -(Mint a, long b) => a - new Mint(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator -(Mint a, int b) => a - new Mint(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator *(Mint a, Mint b) => new Mint((a.Value * b.Value) % divider); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator *(Mint a, long b) => a * new Mint(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator *(Mint a, int b) => a * new Mint(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator /(Mint a, Mint b) => new Mint((a.Value * InvImpl(b.Value)) % divider); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator /(Mint a, long b) => a / new Mint(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator /(Mint a, int b) => a / new Mint(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Mint Pow(long p) => new Mint(PowImpl(Value, p)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint Pow(long a, long p) => new Mint(PowImpl(a, p)); [MethodImpl(MethodImplOptions.AggressiveInlining)] 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; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint Inv(long a) => new Mint(InvImpl(a)); private static readonly Dictionary<long, long> invCache = new Dictionary<long, long>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] 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; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint Fac(long a) => new Mint(FacImpl(a)); private static long[] facCache = new long[262144]; private static long cachedFac = 0L; [MethodImpl(MethodImplOptions.AggressiveInlining)] 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]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] private static void ExtendFacCache(long newSize) { long[] newFacCache = new long[newSize]; facCache.CopyTo(newFacCache, 0); facCache = newFacCache; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint Perm(long n, long r) => new Mint(PermImpl(n, r)); [MethodImpl(MethodImplOptions.AggressiveInlining)] 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; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint Comb(long n, long r) => new Mint(CombImpl(n, r)); [MethodImpl(MethodImplOptions.AggressiveInlining)] 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, 201, 0, 195, 8, 196, 0, 82, 0, 170], ["+", 8, 201, 0, 195, 8, 196, 0, 52, 0, 89], ["+", 8, 201, 0, 195, 8, 196, 0, 52, 0, 24], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 52, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 82, 0, 89], ["-", 8, 201, 0, 195, 8, 196, 0, 82, 0, 24], ["-", 0, 195, 8, 196, 0, 82, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 82, 15, 16, 17, 47], ["-", 0, 195, 8, 196, 0, 82, 15, 16, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 82, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 82, 0, 35]]
8
9,593
14
using System; using System.Linq; using System.Collections.Generic; namespace Sample { class Sample { static void Main(string[] args) { string[][] card = new string[3][]; card[0] = Console.ReadLine().Split(' '); card[1] = Console.ReadLine().Split(' '); card[2] = Console.ReadLine().Split(' '); int N = int.Parse(Console.ReadLine()); bool flg = false; for (int i = 1; i <= N; i++) { string num = Console.ReadLine(); for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { if (card[i][j] == num) { card[i][j] = "○"; } if ((card[0][j] == "○") && (card[1][j] == "○") && (card[2][j] == "○")) { flg = true; } } if (card[i][0] == "○" && (card[i][1] == "○") && (card[i][2] == "○")) { flg = true; } } } if ((card[0][0] == "○") && (card[1][1] == "○") && (card[2][2] == "○")) { flg = true; } else if ((card[0][2] == "○") && (card[1][1] == "○") && (card[2][0] == "○")) { flg = true; } if (flg) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
using System; using System.Linq; using System.Collections.Generic; namespace Sample { class Sample { static void Main(string[] args) { string[][] card = new string[3][]; card[0] = Console.ReadLine().Split(' '); card[1] = Console.ReadLine().Split(' '); card[2] = Console.ReadLine().Split(' '); int N = int.Parse(Console.ReadLine()); bool flg = false; for (int i = 1; i <= N; i++) { string num = Console.ReadLine(); for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { if (card[j][k] == num) { card[j][k] = "○"; } if ((card[0][k] == "○") && (card[1][k] == "○") && (card[2][k] == "○")) { flg = true; } } if (card[j][0] == "○" && (card[j][1] == "○") && (card[j][2] == "○")) { flg = true; } } } if ((card[0][0] == "○") && (card[1][1] == "○") && (card[2][2] == "○")) { flg = true; } else if ((card[0][2] == "○") && (card[1][1] == "○") && (card[2][0] == "○")) { flg = true; } if (flg) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
[["-", 31, 204, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 31, 204, 205, 204, 206, 207, 0, 28, 0, 22], ["-", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 22]]
8
431
20
using System; using System.Collections.Generic; using static System.Math; using System.Linq; using System.Text; class DandA { static void Main(string[] args) { string s = ReadLineStr(); if (s.Substring(0, 1) != s.Substring(1, 1) || s.Substring(0, 1) != s.Substring(1, 1)) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } static public void myLoop(int index, int lenght, List<bool> boolList) { myLoop(index, lenght, boolList); } static string Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"; static string[] strAry = new string[] { "L", "R", "U", "D" }; static int[] intArray = new int[10]; static List<int> intList = new List<int>(); static Dictionary<string, int> myTable = new Dictionary<string, int>(); static HashSet<int>[] rtnArrAb = null; static HashSet<int>[] rtnArrCd = null; static int iRtn; static int[] rdx = null; static int[][] lrArr = null; static int[] pArr = null; static private string ReadLineStr() { return Console.ReadLine(); } static private int ReadLineInt() { return int.Parse(Console.ReadLine()); } static private long ReadLineLong() { return long.Parse(Console.ReadLine()); } static private double ReadLineDouble() { return double.Parse(Console.ReadLine()); } static private string[] ReadLineStrArray() { return Console.ReadLine().Trim().Split(); } static private int[] ReadLineIntArray() { return Console.ReadLine() .Trim() .Split() .Select(a => int.Parse(a)) .ToArray(); } static private long[] ReadLineLongArray() { return Console.ReadLine() .Trim() .Split() .Select(a => long.Parse(a)) .ToArray(); } static private double[] ReadLineDoubleArray() { return Console.ReadLine() .Trim() .Split() .Select(a => double.Parse(a)) .ToArray(); } static private decimal[] ReadLineDecimalArray() { return Console.ReadLine() .Trim() .Split() .Select(a => decimal.Parse(a)) .ToArray(); } static private List<int> ReadLineIntList() { return Console.ReadLine().Trim().Split().Select(a => int.Parse(a)).ToList(); } static private List<long> ReadLineLongList() { return Console.ReadLine() .Trim() .Split() .Select(a => long.Parse(a)) .ToList(); } static private string[][] ReadMLineStrArray(int arg) { return new int [arg].Select(_ => Console.ReadLine().Split()).ToArray(); } static private int[][] ReadMLineIntArray(int arg) { return new int [arg] .Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()) .ToArray(); } static private bool IsPrime(int num) { if (num < 2) return false; 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; } static private string IntToNString(int x, int n) { var nstring = ""; var numbers = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" }; int r = 1; int q = x; while (q > 0) { r = q % n; nstring += numbers[r]; q = q / n; } return string.Join("", nstring.Reverse()); } /* 最大公約数 */ static private long Gcd(long m, long n) { long temp; while (m % n != 0) { temp = n; n = m % n; m = temp; } return n; } }
using System; using System.Collections.Generic; using static System.Math; using System.Linq; using System.Text; class DandA { static void Main(string[] args) { string s = ReadLineStr(); if (s.Substring(0, 1) != s.Substring(1, 1) || s.Substring(1, 1) != s.Substring(2, 1)) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } static public void myLoop(int index, int lenght, List<bool> boolList) { myLoop(index, lenght, boolList); } static string Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"; static string[] strAry = new string[] { "L", "R", "U", "D" }; static int[] intArray = new int[10]; static List<int> intList = new List<int>(); static Dictionary<string, int> myTable = new Dictionary<string, int>(); static HashSet<int>[] rtnArrAb = null; static HashSet<int>[] rtnArrCd = null; static int iRtn; static int[] rdx = null; static int[][] lrArr = null; static int[] pArr = null; static private string ReadLineStr() { return Console.ReadLine(); } static private int ReadLineInt() { return int.Parse(Console.ReadLine()); } static private long ReadLineLong() { return long.Parse(Console.ReadLine()); } static private double ReadLineDouble() { return double.Parse(Console.ReadLine()); } static private string[] ReadLineStrArray() { return Console.ReadLine().Trim().Split(); } static private int[] ReadLineIntArray() { return Console.ReadLine() .Trim() .Split() .Select(a => int.Parse(a)) .ToArray(); } static private long[] ReadLineLongArray() { return Console.ReadLine() .Trim() .Split() .Select(a => long.Parse(a)) .ToArray(); } static private double[] ReadLineDoubleArray() { return Console.ReadLine() .Trim() .Split() .Select(a => double.Parse(a)) .ToArray(); } static private decimal[] ReadLineDecimalArray() { return Console.ReadLine() .Trim() .Split() .Select(a => decimal.Parse(a)) .ToArray(); } static private List<int> ReadLineIntList() { return Console.ReadLine().Trim().Split().Select(a => int.Parse(a)).ToList(); } static private List<long> ReadLineLongList() { return Console.ReadLine() .Trim() .Split() .Select(a => long.Parse(a)) .ToList(); } static private string[][] ReadMLineStrArray(int arg) { return new int [arg].Select(_ => Console.ReadLine().Split()).ToArray(); } static private int[][] ReadMLineIntArray(int arg) { return new int [arg] .Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()) .ToArray(); } static private bool IsPrime(int num) { if (num < 2) return false; 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; } static private string IntToNString(int x, int n) { var nstring = ""; var numbers = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" }; int r = 1; int q = x; while (q > 0) { r = q % n; nstring += numbers[r]; q = q / n; } return string.Join("", nstring.Reverse()); } /* 最大公約数 */ static private long Gcd(long m, long n) { long temp; while (m % n != 0) { temp = n; n = m % n; m = temp; } return n; } }
[["-", 12, 16, 31, 213, 3, 4, 0, 28, 0, 203], ["+", 12, 16, 31, 213, 3, 4, 0, 28, 0, 203], ["-", 12, 16, 12, 213, 3, 4, 0, 28, 0, 203], ["+", 12, 16, 12, 213, 3, 4, 0, 28, 0, 203]]
8
979
4
using System; using System.Collections.Generic; using System.IO; using System.Linq; class A { static StreamWriter Out = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; static void Main(string[] args) { string s; Input(out s); switch (s) { case "AAA": case "BBB": case "CCC": Print("Yes"); break; default: Print("No"); break; } Out.Flush(); } static T ChangeT<T>(string s) => (T)Convert.ChangeType(s, typeof(T)); static void Input<A>(out A a) { var words = Console.ReadLine().Split( new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries); a = ChangeT<A>(words[0]); } static void Input<A, B>(out A a, out B b) { var words = Console.ReadLine().Split( new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries); a = ChangeT<A>(words[0]); b = ChangeT<B>(words[1]); } static void Input<A, B, C>(out A a, out B b, out C c) { var words = Console.ReadLine().Split( new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries); a = ChangeT<A>(words[0]); b = ChangeT<B>(words[1]); c = ChangeT<C>(words[2]); } static void Input<A, B, C, D>(out A a, out B b, out C c, out D d) { var words = Console.ReadLine().Split( new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries); a = ChangeT<A>(words[0]); b = ChangeT<B>(words[1]); c = ChangeT<C>(words[2]); d = ChangeT<D>(words[3]); } static void Input<A, B, C, D, E>(out A a, out B b, out C c, out D d, out E e) { var words = Console.ReadLine().Split( new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries); a = ChangeT<A>(words[0]); b = ChangeT<B>(words[1]); c = ChangeT<C>(words[2]); d = ChangeT<D>(words[3]); e = ChangeT<E>(words[4]); } static void Input<A, B, C, D, E, F>(out A a, out B b, out C c, out D d, out E e, out F f) { var words = Console.ReadLine().Split( new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries); a = ChangeT<A>(words[0]); b = ChangeT<B>(words[1]); c = ChangeT<C>(words[2]); d = ChangeT<D>(words[3]); e = ChangeT<E>(words[4]); f = ChangeT<F>(words[5]); } static void InputArray<T>(out T[] array) { array = Console.ReadLine() .Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries) .Select(s => ChangeT<T>(s)) .ToArray(); } static void Print<T>(T s) => Out.WriteLine(s); static void Print<T>(params T[] s) => Out.WriteLine(string.Join(" ", s)); static void Print<T>(IEnumerable<T> e) => Out.WriteLine(string.Join(" ", e)); }
using System; using System.Collections.Generic; using System.IO; using System.Linq; class A { static StreamWriter Out = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; static void Main(string[] args) { string s; Input(out s); switch (s) { case "AAA": case "BBB": Print("No"); break; default: Print("Yes"); break; } Out.Flush(); } static T ChangeT<T>(string s) => (T)Convert.ChangeType(s, typeof(T)); static void Input<A>(out A a) { var words = Console.ReadLine().Split( new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries); a = ChangeT<A>(words[0]); } static void Input<A, B>(out A a, out B b) { var words = Console.ReadLine().Split( new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries); a = ChangeT<A>(words[0]); b = ChangeT<B>(words[1]); } static void Input<A, B, C>(out A a, out B b, out C c) { var words = Console.ReadLine().Split( new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries); a = ChangeT<A>(words[0]); b = ChangeT<B>(words[1]); c = ChangeT<C>(words[2]); } static void Input<A, B, C, D>(out A a, out B b, out C c, out D d) { var words = Console.ReadLine().Split( new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries); a = ChangeT<A>(words[0]); b = ChangeT<B>(words[1]); c = ChangeT<C>(words[2]); d = ChangeT<D>(words[3]); } static void Input<A, B, C, D, E>(out A a, out B b, out C c, out D d, out E e) { var words = Console.ReadLine().Split( new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries); a = ChangeT<A>(words[0]); b = ChangeT<B>(words[1]); c = ChangeT<C>(words[2]); d = ChangeT<D>(words[3]); e = ChangeT<E>(words[4]); } static void Input<A, B, C, D, E, F>(out A a, out B b, out C c, out D d, out E e, out F f) { var words = Console.ReadLine().Split( new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries); a = ChangeT<A>(words[0]); b = ChangeT<B>(words[1]); c = ChangeT<C>(words[2]); d = ChangeT<D>(words[3]); e = ChangeT<E>(words[4]); f = ChangeT<F>(words[5]); } static void InputArray<T>(out T[] array) { array = Console.ReadLine() .Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries) .Select(s => ChangeT<T>(s)) .ToArray(); } static void Print<T>(T s) => Out.WriteLine(s); static void Print<T>(params T[] s) => Out.WriteLine(string.Join(" ", s)); static void Print<T>(IEnumerable<T> e) => Out.WriteLine(string.Join(" ", e)); }
[["-", 0, 99, 8, 254, 0, 239, 0, 264, 0, 173], ["-", 8, 254, 0, 239, 0, 264, 0, 5, 0, 62], ["-", 8, 254, 0, 239, 0, 264, 0, 5, 0, 222], ["-", 0, 99, 8, 254, 0, 239, 0, 264, 0, 102], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
875
9
using System; using System.Linq; using System.Collections.Generic; namespace AtCoderPractice0802 { class MainClass { public static void Main(string[] args) { long[] NAB = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); long N = NAB[0]; long A = NAB[1]; long B = NAB[2]; long ans = 0; long shou = N / (A + B); long mod = N % (A + B); if (A == 0) { Console.WriteLine(ans); } else { Console.WriteLine(A * shou + mod); } } } }
using System; using System.Linq; using System.Collections.Generic; namespace AtCoderPractice0802 { class MainClass { public static void Main(string[] args) { long[] NAB = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); long N = NAB[0]; long A = NAB[1]; long B = NAB[2]; long ans = 0; long shou = N / (A + B); long mod = N % (A + B); if (A == 0) { Console.WriteLine(ans); } else { if (mod >= A) { Console.WriteLine(A * shou + A); } else { Console.WriteLine(A * shou + mod); } } } } }
[["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 24], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 25], ["+", 0, 57, 75, 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], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 48], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 75, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 75, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 95], ["+", 0, 57, 75, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 57, 75, 196, 0, 46]]
8
149
22
using System; namespace abc158_b { class Program { static void Main(string[] args) { string[] NAB = Console.ReadLine().Split(" "); long N = long.Parse(NAB[0]); long A = long.Parse(NAB[1]); long B = long.Parse(NAB[2]); long ans = N / (A + B); long rem = N % (A + B); ans = ans * A + rem; Console.WriteLine(ans); } } }
using System; namespace abc158_b { class Program { static void Main(string[] args) { string[] NAB = Console.ReadLine().Split(" "); long N = long.Parse(NAB[0]); long A = long.Parse(NAB[1]); long B = long.Parse(NAB[2]); long ans = N / (A + B); long rem = N % (A + B); ans = ans * A + Math.Min(rem, A); Console.WriteLine(ans); } } }
[["+", 0, 11, 12, 16, 12, 213, 63, 214, 205, 22], ["+", 0, 11, 12, 16, 12, 213, 63, 214, 0, 131], ["+", 0, 11, 12, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 11, 12, 16, 12, 213, 3, 4, 0, 24], ["+", 0, 11, 12, 16, 12, 213, 3, 4, 0, 21], ["+", 12, 16, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 11, 12, 16, 12, 213, 3, 4, 0, 25]]
8
116
7
using System; using System.Collections.Generic; using static Assistant.Input; using static Assistant.Debug; using System.Linq; using Assistant; namespace ABC158B { class Program { static void Main(string[] args) { var N = RLong; var A = RLong; var B = RLong; long ans = Math.Min(N, A); Console.WriteLine(ans); } } } 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<T>(T[,] map, int mode = 1) { #if DEBUG int W = map.GetLength(0); int H = map.GetLength(1); string[,] map2 = new string[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.ToString(); else if (i == 0) map2[i, j] = (j - 1).ToString(); else if (j == 0) map2[i, j] = (i - 1).ToString(); else map2[i, j] = map[i - 1, j - 1].ToString(); } } for (int i = 0; i < W + 1; i++) { for (int j = 0; j < H + 1; j++) { if (mode == 0) Console.Write(map2[i, j].Last()); if (mode == 1) Console.Write(map2[i, j] + " "); } Console.WriteLine(); } Console.WriteLine(); #endif } public static void Draw1D<T>(T[] 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 ABC158B { class Program { static void Main(string[] args) { var N = RLong; var A = RLong; var B = RLong; long div = N / (A + B); long rem = N % (A + B); long ans = div * A + Math.Min(rem, A); Console.WriteLine(ans); } } } 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<T>(T[,] map, int mode = 1) { #if DEBUG int W = map.GetLength(0); int H = map.GetLength(1); string[,] map2 = new string[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.ToString(); else if (i == 0) map2[i, j] = (j - 1).ToString(); else if (j == 0) map2[i, j] = (i - 1).ToString(); else map2[i, j] = map[i - 1, j - 1].ToString(); } } for (int i = 0; i < W + 1; i++) { for (int j = 0; j < H + 1; j++) { if (mode == 0) Console.Write(map2[i, j].Last()); if (mode == 1) Console.Write(map2[i, j] + " "); } Console.WriteLine(); } Console.WriteLine(); #endif } public static void Draw1D<T>(T[] array, int mode = 0) { #if DEBUG Console.WriteLine(string.Join(" ", array)); #endif } } }
[["+", 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, 85], ["+", 0, 200, 0, 212, 0, 16, 12, 23, 0, 24], ["+", 0, 212, 0, 16, 12, 23, 0, 16, 31, 22], ["+", 0, 212, 0, 16, 12, 23, 0, 16, 17, 72], ["+", 0, 212, 0, 16, 12, 23, 0, 16, 12, 22], ["+", 0, 200, 0, 212, 0, 16, 12, 23, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 109], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 31, 22], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 17, 48], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 12, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["-", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 16, 12, 213, 3, 4, 0, 28, 0, 22]]
8
693
28
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Program { static void Main(string[] args) { var q = ReadLineIntSpilit(); var n = q[0]; var a = q[1]; var b = q[2]; var re = 0; //はみ出た個数 var t = n % (a + b); if (t < a) re = ((n / (a + b)) * a) + t; else re = ((n / (a + b)) * a) + a; Console.WriteLine(re); ReadLine(); } //最大公約数 static int gcd(int a, int b) { if (a > b) { return gcd(b, a); } while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } //最小公倍数 static int lcm(int a, int b) => a * b / gcd(a, b); /// <summary> /// コンビネーション /// </summary> static int nCm(int n, int m) { if (m == 0) return 1; if (n == 0) return 0; return n * nCm(n - 1, m - 1) / m; } public static string ReadLine() => Console.ReadLine(); public static int ReadLineInt() => int.Parse(Console.ReadLine()); public static long ReadLineLongInt() => long.Parse(Console.ReadLine()); public static string[] ReadLineStringSplit(char a = ' ') => ReadLine().Split(a).ToArray(); public static int[] ReadLineIntSpilit(char a = ' ') => ReadLine().Split(a).Select(x => int.Parse(x)).ToArray(); public static long[] ReadLineLongSpilit(char a = ' ') => ReadLine().Split(a).Select(x => long.Parse(x)).ToArray(); static string[] GetAplhaLowerArray() => new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" }; static string[] GetAplhaUpperArray() => new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" }; } }
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) { long[] q = ReadLineLongSpilit(); long n = q[0]; long a = q[1]; long b = q[2]; long re = 0; //はみ出た個数 var t = n % (a + b); if (t < a) re = ((n / (a + b)) * a) + t; else re = ((n / (a + b)) * a) + a; Console.WriteLine(re); ReadLine(); } //最大公約数 static int gcd(int a, int b) { if (a > b) { return gcd(b, a); } while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } //最小公倍数 static int lcm(int a, int b) => a * b / gcd(a, b); /// <summary> /// コンビネーション /// </summary> static int nCm(int n, int m) { if (m == 0) return 1; if (n == 0) return 0; return n * nCm(n - 1, m - 1) / m; } public static string ReadLine() => Console.ReadLine(); public static int ReadLineInt() => int.Parse(Console.ReadLine()); public static long ReadLineLongInt() => long.Parse(Console.ReadLine()); public static string[] ReadLineStringSplit(char a = ' ') => ReadLine().Split(a).ToArray(); public static int[] ReadLineIntSpilit(char a = ' ') => ReadLine().Split(a).Select(x => int.Parse(x)).ToArray(); public static long[] ReadLineLongSpilit(char a = ' ') => ReadLine().Split(a).Select(x => long.Parse(x)).ToArray(); static string[] GetAplhaLowerArray() => new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" }; static string[] GetAplhaUpperArray() => new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" }; } }
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 0, 197, 0, 198, 39, 224, 225, 226, 0, 70], ["+", 0, 197, 0, 198, 39, 224, 225, 226, 0, 73], ["-", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
668
14
using System; using System.Collections.Generic; namespace atcoder { class Program { static void Main(string[] args) { string[] S = Console.ReadLine().Split(' '); int N = int.Parse(S[0]); int A = int.Parse(S[1]); int B = int.Parse(S[2]); int total = A + B; int ans; ans = (N / total) * A; ans += Math.Min(A, (N % total)); Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; namespace atcoder { class Program { static void Main(string[] args) { string[] S = Console.ReadLine().Split(' '); long N = long.Parse(S[0]); long A = long.Parse(S[1]); long B = long.Parse(S[2]); long total = A + B; long ans; ans = (N / total) * A; ans += Math.Min(A, (N % total)); Console.WriteLine(ans); } } }
[["-", 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
128
16
using System; using System.Linq; class Program { static void Main(string[] args) { long[] inp = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray(); long n, a, b; n = inp[0]; a = inp[1]; b = inp[2]; long ans = 0; ans = a * (n / (a + b)); ans += n % (a + b); Console.WriteLine(ans); } }
using System; using System.Linq; class Program { static void Main(string[] args) { long[] inp = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray(); long n, a, b; n = inp[0]; a = inp[1]; b = inp[2]; long ans = 0, tmp = 0; ans = a * (n / (a + b)); tmp = n % (a + b); ans += Math.Min(tmp, a); Console.WriteLine(ans); } }
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 0, 21], ["+", 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], ["-", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 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], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21]]
8
121
19
using System; namespace abc158B { class MainClass { public static void Main(string[] args) { string[] str = Console.ReadLine().Split(); int N = int.Parse(str[0]); int A = int.Parse(str[1]); int B = int.Parse(str[2]); int M = N / (A + B); int L = N % (A + B); if (L >= A) Console.WriteLine(M * A + A); else Console.WriteLine(M * A + L); } } }
using System; namespace abc158B { class MainClass { public static void Main(string[] args) { string[] str = Console.ReadLine().Split(); long N = long.Parse(str[0]); long A = long.Parse(str[1]); long B = long.Parse(str[2]); long M = N / (A + B); long L = N % (A + B); if (L >= A) Console.WriteLine(M * A + A); else Console.WriteLine(M * A + L); } } }
[["-", 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
128
16
using System; using System.Collections.Generic; using System.Linq; class Program { public static void Main() { string[] input = Console.ReadLine().Split(); int N = int.Parse(input[0]); int A = int.Parse(input[1]); int B = int.Parse(input[2]); int ans = ((N / (A + B)) * A) + Math.Min(A, (N % (A + B))); Console.WriteLine(ans); } }
using System; using System.Collections.Generic; using System.Linq; class Program { public static void Main() { string[] input = Console.ReadLine().Split(); long N = long.Parse(input[0]); long A = long.Parse(input[1]); long B = long.Parse(input[2]); long ans = ((N / (A + B)) * A) + Math.Min(A, (N % (A + B))); Console.WriteLine(ans); } }
[["-", 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
122
14
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { // https://atcoder.jp/contests/abc158/tasks/abc158_b class QuestionB { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // 整数配列の入力 var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray(); long n = inputLongArray[0]; long a = inputLongArray[1]; long b = inputLongArray[2]; long ans = 0; if (a == 0) { Console.WriteLine(0); Console.Out.Flush(); } else { ans = (n / (a + b)) * a; long amari = (n % (a + b)); ans += Math.Min(amari, a); } Console.WriteLine(ans); Console.Out.Flush(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { // https://atcoder.jp/contests/abc158/tasks/abc158_b class QuestionB { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // 整数配列の入力 var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray(); long n = inputLongArray[0]; long a = inputLongArray[1]; long b = inputLongArray[2]; long ans = (n / (a + b)) * a; long amari = n % (a + b); ans += Math.Min(amari, a); Console.WriteLine(ans); Console.Out.Flush(); } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 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], ["-", 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], ["-", 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], ["-", 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], ["-", 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, 1, 0, 11, 31, 22], ["-", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["-", 0, 198, 0, 200, 0, 212, 0, 23, 0, 24], ["-", 0, 198, 0, 200, 0, 212, 0, 23, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
220
32
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { class B { public static void Main() { var nab = Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray(); long n = nab[0]; long a = nab[1]; long b = nab[2]; Console.WriteLine(n / (a + b) * a + n % (a + b)); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { class B { public static void Main() { var nab = Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray(); long n = nab[0]; long a = nab[1]; long b = nab[2]; Console.WriteLine(n / (a + b) * a + Math.Min(n % (a + b), a)); } } }
[["+", 0, 28, 0, 16, 12, 213, 63, 214, 205, 22], ["+", 0, 28, 0, 16, 12, 213, 63, 214, 0, 131], ["+", 0, 28, 0, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 16, 12, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25], ["+", 0, 28, 0, 16, 12, 213, 3, 4, 0, 21], ["+", 0, 16, 12, 213, 3, 4, 0, 28, 0, 22]]
8
122
7
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var nab = Console.ReadLine().Split().Select(int.Parse).ToArray(); var n = nab[0]; var a = nab[1]; var b = nab[2]; var ans = (n / (a + b)) * a; var mod = n % (a + b); if (mod != 0) { ans += Math.Min(mod, a); } Console.WriteLine(ans); } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var nab = Console.ReadLine().Split().Select(long.Parse).ToArray(); var n = nab[0]; var a = nab[1]; var b = nab[2]; var ans = (n / (a + b)) * a; var mod = n % (a + b); ans += Math.Min(mod, a); Console.WriteLine(ans); } }
[["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 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, 79], ["-", 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], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
130
10
using System; class Test { public static void Main() { var str = Console.ReadLine().Split(' '); int N = int.Parse(str[0]); int blue = int.Parse(str[1]); int red = int.Parse(str[2]); int sumBlue = 0; sumBlue = N / (blue + red) * blue; if (N % (blue + red) >= blue) { sumBlue += blue; } else { sumBlue += N % (blue + red); } Console.WriteLine(sumBlue); } }
using System; class Test { public static void Main() { var str = Console.ReadLine().Split(' '); long N = long.Parse(str[0]); long blue = long.Parse(str[1]); long red = long.Parse(str[2]); long sumBlue = 0; sumBlue = N / (blue + red) * blue; if (N % (blue + red) >= blue) { sumBlue += blue; } else { sumBlue += N % (blue + red); } Console.WriteLine(sumBlue); } }
[["-", 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
125
14
using System; namespace ABC158B { static class Program { static void Main() { long[] nbrs = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); var total = (nbrs[0] / (nbrs[1] + nbrs[2])) * nbrs[1]; var remaining = Math.Min(nbrs[1], nbrs[0] % nbrs[1]); total += remaining; Console.WriteLine(total); } } }
using System; namespace ABC158B { static class Program { static void Main() { long[] nbrs = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); var total = (nbrs[0] / (nbrs[1] + nbrs[2])) * nbrs[1]; var remaining = Math.Min(nbrs[1], nbrs[0] % (nbrs[1] + nbrs[2])); total += remaining; Console.WriteLine(total); } } }
[["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 24], ["+", 0, 28, 0, 16, 12, 23, 0, 16, 17, 72], ["+", 0, 16, 12, 23, 0, 16, 12, 204, 205, 22], ["+", 12, 23, 0, 16, 12, 204, 206, 207, 0, 70], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 12, 23, 0, 16, 12, 204, 206, 207, 0, 73], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25]]
8
104
7
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Program { static void Main(string[] args) { var arg = Console.ReadLine().Split(' '); var N = arg[0].ToDecimal(); var A = arg[1].ToDecimal(); var B = arg[2].ToDecimal(); decimal ans = 0; if (A == 0) { ans = 0; } else { ans = Math.Floor(N / (A + B)) * A + (N % (A + B)); } Console.WriteLine(ans.ToString()); } } public static class Extentions { public static int ToInt(this object obj) { return int.Parse(obj.ToString()); } public static decimal ToDecimal(this object obj) { return decimal.Parse(obj.ToString()); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Program { static void Main(string[] args) { var arg = Console.ReadLine().Split(' '); var N = arg[0].ToDecimal(); var A = arg[1].ToDecimal(); var B = arg[2].ToDecimal(); // decimal ans = 0; // if (A == 0) //{ // ans = 0; //} // else if (N < A + B) //{ // if(N < A) // { // ans = N; // } // else // { // ans = A; // } //} // else //{ // var mul = Math.Floor(N / (A + B)) * (A + B); // ans = Math.Floor(N / (A + B)) * A; // if (mul + A <= N) // { // ans += B; // } // else if (mul + A > N) // { // ans += N - mul; // } //} var ans = Math.Floor(N / (A + B)) * A; var rem = N % (A + B); ans += Math.Min(rem, A); Console.WriteLine(ans.ToString()); } } public static class Extentions { public static int ToInt(this object obj) { return int.Parse(obj.ToString()); } public static decimal ToDecimal(this object obj) { return decimal.Parse(obj.ToString()); } } }
[["-", 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, 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], ["-", 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], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 75, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["-", 0, 1, 0, 11, 12, 16, 12, 23, 0, 24], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 195, 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], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["-", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
208
37
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace TOPSIC { partial class Program { static void Main(string[] args) { string[] NAB = Console.ReadLine().Split(' '); double N = double.Parse(NAB[0]); double A = double.Parse(NAB[1]); double B = double.Parse(NAB[2]); double ans = 0; ans += (N / (A + B)) * A; ans += Math.Min(A, N % (A + B)); Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace TOPSIC { partial class Program { static void Main(string[] args) { string[] NAB = Console.ReadLine().Split(' '); long N = long.Parse(NAB[0]); long A = long.Parse(NAB[1]); long B = long.Parse(NAB[2]); long ans = 0; ans += (long)(N / (A + B)) * A; ans += Math.Min(A, N % (A + B)); Console.WriteLine(ans); } } }
[["-", 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], ["+", 0, 1, 0, 11, 12, 16, 31, 74, 0, 24], ["+", 0, 1, 0, 11, 12, 16, 31, 74, 39, 199], ["+", 0, 1, 0, 11, 12, 16, 31, 74, 0, 25]]
8
147
17
using System; namespace Count_Balls { class Program { static void Main(string[] args) { String input = Console.ReadLine(); String[] splitted = input.Split(' '); int N = int.Parse(splitted[0]); int A = int.Parse(splitted[1]); int B = int.Parse(splitted[2]); int answer = ((N / (A + B)) * A) + Math.Min((N % (A + B)), A); Console.WriteLine(answer); } } }
using System; namespace Count_Balls { class Program { static void Main(string[] args) { String input = Console.ReadLine(); String[] splitted = input.Split(' '); long N = long.Parse(splitted[0]); long A = long.Parse(splitted[1]); long B = long.Parse(splitted[2]); long answer = ((N / (A + B)) * A) + Math.Min((N % (A + B)), A); Console.WriteLine(answer); } } }
[["-", 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
125
14
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { List<long> NAB = Console.ReadLine().Split(' ').Select(o => long.Parse(o)).ToList(); long N = NAB[0], A = NAB[1], B = NAB[2]; Console.WriteLine(A != 0 ? A * (N / (A + B)) + N % (A + B) : 0); } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { List<long> NAB = Console.ReadLine().Split(' ').Select(o => long.Parse(o)).ToList(); long N = NAB[0], A = NAB[1], B = NAB[2]; Console.WriteLine(A != 0 ? A * (N / (A + B)) + Math.Min(N % (A + B), A) : 0); } }
[["+", 0, 41, 64, 16, 12, 213, 63, 214, 205, 22], ["+", 0, 41, 64, 16, 12, 213, 63, 214, 0, 131], ["+", 0, 41, 64, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 41, 64, 16, 12, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25], ["+", 0, 41, 64, 16, 12, 213, 3, 4, 0, 21], ["+", 64, 16, 12, 213, 3, 4, 0, 28, 0, 22]]
8
118
7
using System; class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); long N = long.Parse(input[0]); long A = long.Parse(input[1]); long B = long.Parse(input[2]); if (A == 0) { Console.WriteLine(0); } else if (N <= A) { Console.Write(N); } else if (N < A + B) { Console.Write(A); } else { long x = N / (A + B); long y = N % (A + B); Console.Write((A * x) + y); } } }
using System; class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); long N = long.Parse(input[0]); long A = long.Parse(input[1]); long B = long.Parse(input[2]); if (A == 0) { Console.WriteLine(0); } else if (N <= A) { Console.Write(N); } else if (N <= A + B) { Console.Write(A); } else { long x = N / (A + B); long y = N % (A + B); if (A < y) { Console.Write((A * x) + A); } else { Console.Write((A * x) + y); } } } }
[["-", 0, 57, 75, 57, 75, 57, 15, 16, 17, 18], ["+", 0, 57, 75, 57, 75, 57, 15, 16, 17, 19], ["+", 0, 200, 0, 212, 0, 16, 12, 23, 0, 25], ["+", 75, 57, 75, 57, 75, 196, 0, 197, 0, 35], ["+", 75, 57, 75, 57, 75, 196, 0, 57, 0, 121], ["+", 75, 57, 75, 57, 75, 196, 0, 57, 0, 24], ["+", 75, 57, 75, 196, 0, 57, 15, 16, 31, 22], ["+", 75, 57, 75, 196, 0, 57, 15, 16, 17, 18], ["+", 75, 57, 75, 196, 0, 57, 15, 16, 12, 22], ["+", 75, 57, 75, 57, 75, 196, 0, 57, 0, 25], ["+", 75, 57, 75, 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], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 24], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 31, 22], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 17, 48], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 12, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 75, 57, 75, 196, 0, 57, 64, 196, 0, 46], ["+", 75, 57, 75, 57, 75, 196, 0, 57, 0, 95], ["+", 75, 57, 75, 196, 0, 57, 75, 196, 0, 45], ["+", 75, 57, 75, 196, 0, 57, 75, 196, 0, 46]]
8
162
26
using System; using System.Linq; namespace ABC158B { class Program { static void Main(string[] args) { var NAB = Console.ReadLine().Split().Select(long.Parse).ToArray(); var N = NAB[0]; var A = NAB[1]; var B = NAB[2]; if (A > N || A + B >= N) { Console.WriteLine(A); return; } var ans = 0L; long rem; var d = Math.DivRem(N, A + B, out rem); ans = A * d + Math.Min(A, rem); Console.WriteLine(ans); } } }
using System; using System.Linq; namespace ABC158B { class Program { static void Main(string[] args) { var NAB = Console.ReadLine().Split().Select(long.Parse).ToArray(); var N = NAB[0]; var A = NAB[1]; var B = NAB[2]; if (N <= A) { Console.WriteLine(N); return; } if (A + B >= N) { Console.WriteLine(A); return; } var ans = 0L; long rem; var d = Math.DivRem(N, A + B, out rem); ans = A * d + Math.Min(A, rem); Console.WriteLine(ans); } } }
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 47], ["+", 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, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 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, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24]]
8
145
17
using System; using System.Collections.Generic; using static System.Math; using System.Linq; using System.Text; class DandA { static void Main(string[] args) { long[] nab = ReadLineLongArray(); if (nab[1] == 0) { Console.WriteLine(0); return; } if (nab[2] == 0) { Console.WriteLine(nab[0]); return; } long cnt = nab[0] / (nab[1] + nab[2]); long amari = 0; amari = nab[0] % (nab[1] + nab[2]); // if () {} Console.WriteLine((cnt * nab[1]) + amari); } static public void myLoop(int index, int lenght, List<bool> boolList) { myLoop(index, lenght, boolList); } static string Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"; static string[] strAry = new string[] { "L", "R", "U", "D" }; static int[] intArray = new int[10]; static List<int> intList = new List<int>(); static Dictionary<string, int> myTable = new Dictionary<string, int>(); static HashSet<int>[] rtnArrAb = null; static HashSet<int>[] rtnArrCd = null; static int iRtn; static int[] rdx = null; static int[][] lrArr = null; static int[] pArr = null; static private string ReadLineStr() { return Console.ReadLine(); } static private int ReadLineInt() { return int.Parse(Console.ReadLine()); } static private long ReadLineLong() { return long.Parse(Console.ReadLine()); } static private double ReadLineDouble() { return double.Parse(Console.ReadLine()); } static private string[] ReadLineStrArray() { return Console.ReadLine().Trim().Split(); } static private int[] ReadLineIntArray() { return Console.ReadLine() .Trim() .Split() .Select(a => int.Parse(a)) .ToArray(); } static private long[] ReadLineLongArray() { return Console.ReadLine() .Trim() .Split() .Select(a => long.Parse(a)) .ToArray(); } static private double[] ReadLineDoubleArray() { return Console.ReadLine() .Trim() .Split() .Select(a => double.Parse(a)) .ToArray(); } static private decimal[] ReadLineDecimalArray() { return Console.ReadLine() .Trim() .Split() .Select(a => decimal.Parse(a)) .ToArray(); } static private List<int> ReadLineIntList() { return Console.ReadLine().Trim().Split().Select(a => int.Parse(a)).ToList(); } static private List<long> ReadLineLongList() { return Console.ReadLine() .Trim() .Split() .Select(a => long.Parse(a)) .ToList(); } static private string[][] ReadMLineStrArray(int arg) { return new int [arg].Select(_ => Console.ReadLine().Split()).ToArray(); } static private int[][] ReadMLineIntArray(int arg) { return new int [arg] .Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()) .ToArray(); } static private bool IsPrime(int num) { if (num < 2) return false; 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; } static private string IntToNString(int x, int n) { var nstring = ""; var numbers = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" }; int r = 1; int q = x; while (q > 0) { r = q % n; nstring += numbers[r]; q = q / n; } return string.Join("", nstring.Reverse()); } /* 最大公約数 */ static private long Gcd(long m, long n) { long temp; while (m % n != 0) { temp = n; n = m % n; m = temp; } return n; } }
using System; using System.Collections.Generic; using static System.Math; using System.Linq; using System.Text; class DandA { static void Main(string[] args) { long[] nab = ReadLineLongArray(); if (nab[1] == 0) { Console.WriteLine(0); return; } if (nab[2] == 0) { Console.WriteLine(nab[0]); return; } long cnt = nab[0] / (nab[1] + nab[2]); long amari = 0; amari = nab[0] % (nab[1] + nab[2]); amari = Math.Min(nab[1], amari); Console.WriteLine((cnt * nab[1]) + amari); } static public void myLoop(int index, int lenght, List<bool> boolList) { myLoop(index, lenght, boolList); } static string Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"; static string[] strAry = new string[] { "L", "R", "U", "D" }; static int[] intArray = new int[10]; static List<int> intList = new List<int>(); static Dictionary<string, int> myTable = new Dictionary<string, int>(); static HashSet<int>[] rtnArrAb = null; static HashSet<int>[] rtnArrCd = null; static int iRtn; static int[] rdx = null; static int[][] lrArr = null; static int[] pArr = null; static private string ReadLineStr() { return Console.ReadLine(); } static private int ReadLineInt() { return int.Parse(Console.ReadLine()); } static private long ReadLineLong() { return long.Parse(Console.ReadLine()); } static private double ReadLineDouble() { return double.Parse(Console.ReadLine()); } static private string[] ReadLineStrArray() { return Console.ReadLine().Trim().Split(); } static private int[] ReadLineIntArray() { return Console.ReadLine() .Trim() .Split() .Select(a => int.Parse(a)) .ToArray(); } static private long[] ReadLineLongArray() { return Console.ReadLine() .Trim() .Split() .Select(a => long.Parse(a)) .ToArray(); } static private double[] ReadLineDoubleArray() { return Console.ReadLine() .Trim() .Split() .Select(a => double.Parse(a)) .ToArray(); } static private decimal[] ReadLineDecimalArray() { return Console.ReadLine() .Trim() .Split() .Select(a => decimal.Parse(a)) .ToArray(); } static private List<int> ReadLineIntList() { return Console.ReadLine().Trim().Split().Select(a => int.Parse(a)).ToList(); } static private List<long> ReadLineLongList() { return Console.ReadLine() .Trim() .Split() .Select(a => long.Parse(a)) .ToList(); } static private string[][] ReadMLineStrArray(int arg) { return new int [arg].Select(_ => Console.ReadLine().Split()).ToArray(); } static private int[][] ReadMLineIntArray(int arg) { return new int [arg] .Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()) .ToArray(); } static private bool IsPrime(int num) { if (num < 2) return false; 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; } static private string IntToNString(int x, int n) { var nstring = ""; var numbers = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" }; int r = 1; int q = x; while (q > 0) { r = q % n; nstring += numbers[r]; q = q / n; } return string.Join("", nstring.Reverse()); } /* 最大公約数 */ static private long Gcd(long m, long n) { long temp; while (m % n != 0) { temp = n; n = m % n; m = temp; } return n; } }
[["+", 0, 195, 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, 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, 203], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
1,024
14
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Threading.Tasks; using System.Globalization; namespace Atcoder { class Program { static void Main(string[] args) { StreamScanner scan = new StreamScanner(System.Console.OpenStandardInput()); long n = scan.Long(); long a = scan.Long(); long b = scan.Long(); long kore = n / (a + b); Console.WriteLine(a * kore + n % (a + b)); } } 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); } } public class UnionFind { public int[] data; public UnionFind(int size) { data = new int[size]; for (int i = 0; i < size; i++) data[i] = -1; } public bool Unite(int x, int y) { x = Root(x); y = Root(y); if (x != y) { if (data[y] < data[x]) { var tmp = y; y = x; x = tmp; } data[x] += data[y]; data[y] = x; } return x != y; } public bool IsSameGroup(int x, int y) { return Root(x) == Root(y); } public int Root(int x) { return data[x] < 0 ? x : data[x] = Root(data[x]); } } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Threading.Tasks; using System.Globalization; namespace Atcoder { class Program { static void Main(string[] args) { StreamScanner scan = new StreamScanner(System.Console.OpenStandardInput()); long n = scan.Long(); long a = scan.Long(); long b = scan.Long(); long kore = n / (a + b); long atomax = Math.Min(n % (a + b), a); Console.WriteLine(a * kore + atomax); } } 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); } } public class UnionFind { public int[] data; public UnionFind(int size) { data = new int[size]; for (int i = 0; i < size; i++) data[i] = -1; } public bool Unite(int x, int y) { x = Root(x); y = Root(y); if (x != y) { if (data[y] < data[x]) { var tmp = y; y = x; x = tmp; } data[x] += data[y]; data[y] = x; } return x != y; } public bool IsSameGroup(int x, int y) { return Root(x) == Root(y); } public int Root(int x) { return data[x] < 0 ? x : data[x] = Root(data[x]); } } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 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], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 31, 22], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 17, 48], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 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], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 48], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
8
682
24
using System; class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int n = int.Parse(input[0]); int a = int.Parse(input[1]); int b = int.Parse(input[2]); int ans = 0; int c = n / (a + b); int d = 0; if (a <= n % (a + b)) { d = a; } else { d = n % (a + b); } Console.WriteLine(c * a + d); } }
using System; class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); long n = long.Parse(input[0]); long a = long.Parse(input[1]); long b = long.Parse(input[2]); long ans = 0; long c = n / (a + b); long d = 0; if (a <= n % (a + b)) { d = a; } else { d = n % (a + b); } Console.WriteLine(c * a + d); } }
[["-", 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
138
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) { var N = cin.ReadLong; var A = cin.ReadLong; var B = cin.ReadLong; WriteLine(N * A / (A + B) + N % (A + B)); } } 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) { var N = cin.ReadLong; var A = cin.ReadLong; var B = cin.ReadLong; var ans1 = N / (A + B); ans1 *= A; var ans2 = N % (A + B) > A ? A : N % (A + B); WriteLine(ans1 + ans2); } } 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, 195, 8, 196, 0, 1, 0, 213, 63, 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], ["-", 0, 28, 0, 16, 31, 16, 31, 16, 17, 48], ["-", 0, 28, 0, 16, 31, 16, 31, 16, 12, 22], ["+", 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, 108], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 0, 212, 0, 41, 15, 16, 31, 16, 31, 22], ["+", 0, 212, 0, 41, 15, 16, 31, 16, 17, 109], ["+", 0, 41, 15, 16, 31, 16, 12, 23, 0, 24], ["+", 15, 16, 31, 16, 12, 23, 0, 16, 31, 22], ["+", 15, 16, 31, 16, 12, 23, 0, 16, 12, 22], ["+", 0, 41, 15, 16, 31, 16, 12, 23, 0, 25], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 17, 47], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 12, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 101], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 64, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 102], ["+", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["+", 8, 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, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
8
466
32
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ClassLibrary1 { public class ListNode { public int val; public ListNode next; public ListNode(int x) { val = x; } } public class Class1 { static Dictionary<Tuple<long, long>, long> dic = new Dictionary<Tuple<long, long>, long>(); static long mod = 1000000007; static long[] factorial = new long[1000001]; static long[] invFactorial = new long[1000001]; private static void calcFanctorial(long N) { factorial[0] = 1; for (int i = 1; i < N + 1; i++) { factorial[i] = factorial[i - 1] * i; factorial[i] %= mod; } invFactorial[N] = inv(factorial[N]); for (int i = (int)N; i > 0; i--) { invFactorial[i - 1] = invFactorial[i] * i % mod; } } static void Main(string[] args) { var NN = ReadLongArr(); long N = NN[0]; long A = NN[1]; long B = NN[2]; long max = Math.Min(N, A); var res = "Yes"; Console.WriteLine(max); } private static void rec(long b, Relation[] rltn, long f, HashSet<long> pass) { // var res = new HashSet<long>(); foreach (var ff in rltn[f].friends) { if (!rltn[b].block.Contains(ff) && !rltn[b].friends.Contains(ff) && b != ff) { // res.Add(ff); pass.Add(ff); rec(b, rltn, ff, pass); } } // return res; } class Relation { public HashSet<long> friends = new HashSet<long>(); public HashSet<long> block = new HashSet<long>(); } static long bin(long a, long x, long n) { long y = a; long res = 1; while (x > 0) { if (x % 2 == 1) { res = res * y % n; } x /= 2; y = y * y % n; } return res; } int cmp(string a, string b) { for (var i = 0; i < Math.Min(a.Length, b.Length); i++) if (a[i] < b[i]) return -1; else if (a[i] > b[i]) return 1; if (a.Length == b.Length) return 0; if (a.Length > b.Length) return 1; else return -1; } private static long nCm(long n, long m) { if (n < m) return 0; if (m < 0) return 0; return (factorial[n] * invFactorial[m] % mod) * invFactorial[n - m] % mod; } private static long nCm2(long n, long m) { if (n < m) return 0; if (m < 0) return 0; long res = 1; for (long i = n; i > n - m; i--) { res *= i; res %= mod; } return res * invFactorial[m] % mod; } public static long pow(long a, long b, long mod) { a %= mod; 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 Lcm(long a, long b) { return a * b % mod * inv(Gcd(a, b)) % mod; } public static long Lcm(long[] a) { List<long> vect = new List<long>(); long lcm = 1; for (int i = 0; i < a.Count(); i++) { var factor = a[i] / GcdVector(vect, a[i]); vect.Add(factor); lcm = lcm * factor % mod; } return lcm; } static long GcdVector(List<long> a, long b) { long ma = 1; for (int i = 0; i < a.Count; i++) ma = ma * a[i] % b; return Gcd(b, ma); } 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; } public static long pow(long a, long b) => pow(a, b, mod); public static long inv(long a) => pow(a, mod - 2); private static char[][] ReadCharMatrix(long h) { char[][] mtx = new char [h][]; for (int i = 0; i < h; i++) { var s = ReadString(); mtx[i] = s.ToCharArray(); } return mtx; } private static int[][] CreateIntMatrix(long h, long w) { int[][] mtx = new int [h][]; for (int i = 0; i < h; i++) { mtx[i] = new int[w]; } return mtx; } private static string ReadString() { return Console.ReadLine(); } private static string[] ReadStringArr() { return Console.ReadLine().Split(' '); } private static long ReadLong() { return long.Parse(Console.ReadLine()); } private static long[] ReadLongArr() { string[] s = ReadStringArr(); long[] l = new long[s.Length]; for (int i = 0; i < l.Length; i++) { l[i] = long.Parse(s[i]); } return l; } } class StringComparator2 : IComparer<string> { int IComparer<string>.Compare(string a, string b) { int length = Math.Min(a.Length, b.Length); // Console.WriteLine("Comparing with length {0}", length); for (int i = 0; i < length; i++) { if (a[i] < b[i]) { // Console.WriteLine("returning -1"); return -1; } else if (a[i] > b[i]) return 1; } if (a.Length < b.Length) return -1; if (a.Length > b.Length) return 1; // Console.WriteLine("Why are we at the end?"); return 0; } } public class PriorityQueue<T> where T : IComparable { private IComparer<T> _comparer = null; private int _type = 0; private T[] _heap; private int _sz = 0; private int _count = 0; /// <summary> /// Priority Queue with custom comparer /// </summary> public PriorityQueue(int maxSize, IComparer<T> comparer) { _heap = new T[maxSize]; _comparer = comparer; } /// <summary> /// Priority queue /// </summary> /// <param name="maxSize">max size</param> /// <param name="type">0: asc, 1:desc</param> public PriorityQueue(int maxSize, int type = 0) { _heap = new T[maxSize]; _type = type; } private int Compare(T x, T y) { if (_comparer != null) return _comparer.Compare(x, y); return _type == 0 ? x.CompareTo(y) : y.CompareTo(x); } public void Push(T x) { _count++; // node number var i = _sz++; while (i > 0) { // parent node number var p = (i - 1) / 2; if (Compare(_heap[p], x) <= 0) break; _heap[i] = _heap[p]; i = p; } _heap[i] = x; } public T Pop() { _count--; T ret = _heap[0]; T x = _heap[--_sz]; int i = 0; while (i * 2 + 1 < _sz) { // children int a = i * 2 + 1; int b = i * 2 + 2; if (b < _sz && Compare(_heap[b], _heap[a]) < 0) a = b; if (Compare(_heap[a], x) >= 0) break; _heap[i] = _heap[a]; i = a; } _heap[i] = x; return ret; } public int Count() { return _count; } public T Peek() { return _heap[0]; } public bool Contains(T x) { for (int i = 0; i < _sz; i++) if (x.Equals(_heap[i])) return true; return false; } public void Clear() { while (this.Count() > 0) this.Pop(); } public IEnumerator<T> GetEnumerator() { var ret = new List<T>(); while (this.Count() > 0) { ret.Add(this.Pop()); } foreach (var r in ret) { this.Push(r); yield return r; } } public T[] ToArray() { T[] array = new T[_sz]; int i = 0; foreach (var r in this) { array[i++] = r; } return array; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ClassLibrary1 { public class ListNode { public int val; public ListNode next; public ListNode(int x) { val = x; } } public class Class1 { static Dictionary<Tuple<long, long>, long> dic = new Dictionary<Tuple<long, long>, long>(); static long mod = 1000000007; static long[] factorial = new long[1000001]; static long[] invFactorial = new long[1000001]; private static void calcFanctorial(long N) { factorial[0] = 1; for (int i = 1; i < N + 1; i++) { factorial[i] = factorial[i - 1] * i; factorial[i] %= mod; } invFactorial[N] = inv(factorial[N]); for (int i = (int)N; i > 0; i--) { invFactorial[i - 1] = invFactorial[i] * i % mod; } } static void Main(string[] args) { var NN = ReadLongArr(); long N = NN[0]; long A = NN[1]; long B = NN[2]; var res = A * (N / (A + B)) + Math.Min(N % (A + B), A); Console.WriteLine(res); } private static void rec(long b, Relation[] rltn, long f, HashSet<long> pass) { // var res = new HashSet<long>(); foreach (var ff in rltn[f].friends) { if (!rltn[b].block.Contains(ff) && !rltn[b].friends.Contains(ff) && b != ff) { // res.Add(ff); pass.Add(ff); rec(b, rltn, ff, pass); } } // return res; } class Relation { public HashSet<long> friends = new HashSet<long>(); public HashSet<long> block = new HashSet<long>(); } static long bin(long a, long x, long n) { long y = a; long res = 1; while (x > 0) { if (x % 2 == 1) { res = res * y % n; } x /= 2; y = y * y % n; } return res; } int cmp(string a, string b) { for (var i = 0; i < Math.Min(a.Length, b.Length); i++) if (a[i] < b[i]) return -1; else if (a[i] > b[i]) return 1; if (a.Length == b.Length) return 0; if (a.Length > b.Length) return 1; else return -1; } private static long nCm(long n, long m) { if (n < m) return 0; if (m < 0) return 0; return (factorial[n] * invFactorial[m] % mod) * invFactorial[n - m] % mod; } private static long nCm2(long n, long m) { if (n < m) return 0; if (m < 0) return 0; long res = 1; for (long i = n; i > n - m; i--) { res *= i; res %= mod; } return res * invFactorial[m] % mod; } public static long pow(long a, long b, long mod) { a %= mod; 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 Lcm(long a, long b) { return a * b % mod * inv(Gcd(a, b)) % mod; } public static long Lcm(long[] a) { List<long> vect = new List<long>(); long lcm = 1; for (int i = 0; i < a.Count(); i++) { var factor = a[i] / GcdVector(vect, a[i]); vect.Add(factor); lcm = lcm * factor % mod; } return lcm; } static long GcdVector(List<long> a, long b) { long ma = 1; for (int i = 0; i < a.Count; i++) ma = ma * a[i] % b; return Gcd(b, ma); } 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; } public static long pow(long a, long b) => pow(a, b, mod); public static long inv(long a) => pow(a, mod - 2); private static char[][] ReadCharMatrix(long h) { char[][] mtx = new char [h][]; for (int i = 0; i < h; i++) { var s = ReadString(); mtx[i] = s.ToCharArray(); } return mtx; } private static int[][] CreateIntMatrix(long h, long w) { int[][] mtx = new int [h][]; for (int i = 0; i < h; i++) { mtx[i] = new int[w]; } return mtx; } private static string ReadString() { return Console.ReadLine(); } private static string[] ReadStringArr() { return Console.ReadLine().Split(' '); } private static long ReadLong() { return long.Parse(Console.ReadLine()); } private static long[] ReadLongArr() { string[] s = ReadStringArr(); long[] l = new long[s.Length]; for (int i = 0; i < l.Length; i++) { l[i] = long.Parse(s[i]); } return l; } } class StringComparator2 : IComparer<string> { int IComparer<string>.Compare(string a, string b) { int length = Math.Min(a.Length, b.Length); // Console.WriteLine("Comparing with length {0}", length); for (int i = 0; i < length; i++) { if (a[i] < b[i]) { // Console.WriteLine("returning -1"); return -1; } else if (a[i] > b[i]) return 1; } if (a.Length < b.Length) return -1; if (a.Length > b.Length) return 1; // Console.WriteLine("Why are we at the end?"); return 0; } } public class PriorityQueue<T> where T : IComparable { private IComparer<T> _comparer = null; private int _type = 0; private T[] _heap; private int _sz = 0; private int _count = 0; /// <summary> /// Priority Queue with custom comparer /// </summary> public PriorityQueue(int maxSize, IComparer<T> comparer) { _heap = new T[maxSize]; _comparer = comparer; } /// <summary> /// Priority queue /// </summary> /// <param name="maxSize">max size</param> /// <param name="type">0: asc, 1:desc</param> public PriorityQueue(int maxSize, int type = 0) { _heap = new T[maxSize]; _type = type; } private int Compare(T x, T y) { if (_comparer != null) return _comparer.Compare(x, y); return _type == 0 ? x.CompareTo(y) : y.CompareTo(x); } public void Push(T x) { _count++; // node number var i = _sz++; while (i > 0) { // parent node number var p = (i - 1) / 2; if (Compare(_heap[p], x) <= 0) break; _heap[i] = _heap[p]; i = p; } _heap[i] = x; } public T Pop() { _count--; T ret = _heap[0]; T x = _heap[--_sz]; int i = 0; while (i * 2 + 1 < _sz) { // children int a = i * 2 + 1; int b = i * 2 + 2; if (b < _sz && Compare(_heap[b], _heap[a]) < 0) a = b; if (Compare(_heap[a], x) >= 0) break; _heap[i] = _heap[a]; i = a; } _heap[i] = x; return ret; } public int Count() { return _count; } public T Peek() { return _heap[0]; } public bool Contains(T x) { for (int i = 0; i < _sz; i++) if (x.Equals(_heap[i])) return true; return false; } public void Clear() { while (this.Count() > 0) this.Pop(); } public IEnumerator<T> GetEnumerator() { var ret = new List<T>(); while (this.Count() > 0) { ret.Add(this.Pop()); } foreach (var r in ret) { this.Push(r); yield return r; } } public T[] ToArray() { T[] array = new T[_sz]; int i = 0; foreach (var r in this) { array[i++] = r; } return array; } } }
[["-", 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, 200, 0, 212, 0, 16, 31, 16, 31, 22], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 17, 48], ["+", 0, 212, 0, 16, 31, 16, 12, 23, 0, 24], ["+", 0, 16, 31, 16, 12, 23, 0, 16, 31, 22], ["+", 0, 16, 31, 16, 12, 23, 0, 16, 17, 85], ["+", 31, 16, 12, 23, 0, 16, 12, 23, 0, 24], ["+", 12, 23, 0, 16, 12, 23, 0, 16, 31, 22], ["+", 12, 23, 0, 16, 12, 23, 0, 16, 17, 72], ["+", 12, 23, 0, 16, 12, 23, 0, 16, 12, 22], ["+", 31, 16, 12, 23, 0, 16, 12, 23, 0, 25], ["+", 0, 212, 0, 16, 31, 16, 12, 23, 0, 25], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 109], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 24], ["+", 0, 28, 0, 16, 12, 23, 0, 16, 31, 22], ["+", 0, 28, 0, 16, 12, 23, 0, 16, 17, 72], ["+", 0, 28, 0, 16, 12, 23, 0, 16, 12, 22], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 5, 0, 62], ["-", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
1,979
31
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { var sol = new Solve(); sol.Exec(); } } class Solve { public void Exec() { var l = Console.ReadLine().Split().Select(long.Parse).ToArray(); long N = l[0], A = l[1], B = l[2]; var div = N / (A + B); var rem = N % (A + B); Console.WriteLine(div * A + rem); } }
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { var sol = new Solve(); sol.Exec(); } } class Solve { public void Exec() { var l = Console.ReadLine().Split().Select(long.Parse).ToArray(); long N = l[0], A = l[1], B = l[2]; var div = N / (A + B); var rem = Math.Min(A, N % (A + B)); Console.WriteLine(div * A + rem); } }
[["+", 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, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25]]
8
134
7
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace CSharpSample01 { class Program { static void Main(string[] args) { // スペース区切りの整数の入力 var inputNum = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var N = inputNum[0]; var A = inputNum[1]; var B = inputNum[2]; // ペア数 var num = N / (A + B); var amari = N % (A + B); var answer = num * A; if (amari >= A) { answer += A; } else { answer += amari; } Console.WriteLine(answer); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace CSharpSample01 { class Program { static void Main(string[] args) { // スペース区切りの整数の入力 var inputNum = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); long N = inputNum[0]; long A = inputNum[1]; long B = inputNum[2]; // ペア数 long num = N / (A + B); long amari = N % (A + B); long answer = num * A; if (amari >= A) { answer += A; } else { answer += amari; } Console.WriteLine(answer); } } }
[["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
147
14
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using Console = System.Console; namespace Atcoder { class Program { static void Main(string[] args) { var NAB = ReadLongArray(); var div = NAB[0] / (NAB[1] + NAB[2]); var lastBlue = NAB[0] % (NAB[1] + NAB[2]); Console.WriteLine(div * NAB[1] + lastBlue); } private static readonly Func<string> Read = () => Console.ReadLine(); private static readonly Func<string[]> ReadStringArray = () => Console.ReadLine().Split(); private static readonly Func<int> ReadInt = () => int.Parse(Console.ReadLine()); private static readonly Func<long> ReadLong = () => long.Parse(Console.ReadLine()); private static readonly Func<int[]> ReadIntArray = () => Console.ReadLine().Split().Select(int.Parse).ToArray(); private static readonly Func<long[]> ReadLongArray = () => Console.ReadLine().Split().Select(long.Parse).ToArray(); private static readonly Action<string> Cw = str => Console.WriteLine(str); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using Console = System.Console; namespace Atcoder { class Program { static void Main(string[] args) { var NAB = ReadLongArray(); var div = NAB[0] / (NAB[1] + NAB[2]); var lastBlue = NAB[0] % (NAB[1] + NAB[2]); lastBlue = lastBlue >= NAB[1] ? NAB[1] : lastBlue; Console.WriteLine(div * NAB[1] + lastBlue); } private static readonly Func<string> Read = () => Console.ReadLine(); private static readonly Func<string[]> ReadStringArray = () => Console.ReadLine().Split(); private static readonly Func<int> ReadInt = () => int.Parse(Console.ReadLine()); private static readonly Func<long> ReadLong = () => long.Parse(Console.ReadLine()); private static readonly Func<int[]> ReadIntArray = () => Console.ReadLine().Split().Select(int.Parse).ToArray(); private static readonly Func<long[]> ReadLongArray = () => Console.ReadLine().Split().Select(long.Parse).ToArray(); private static readonly Action<string> Cw = str => Console.WriteLine(str); } }
[["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 41, 15, 16, 31, 22], ["+", 0, 1, 0, 11, 12, 41, 15, 16, 17, 20], ["+", 0, 11, 12, 41, 15, 16, 12, 204, 205, 22], ["+", 12, 41, 15, 16, 12, 204, 206, 207, 0, 70], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 12, 41, 15, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 12, 41, 0, 101], ["+", 0, 1, 0, 11, 12, 41, 64, 204, 205, 22], ["+", 0, 11, 12, 41, 64, 204, 206, 207, 0, 70], ["+", 12, 41, 64, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 11, 12, 41, 64, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 12, 41, 0, 102], ["+", 8, 196, 0, 1, 0, 11, 12, 41, 75, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
288
16
using System; using System.Collections.Generic; using System.IO; using System.Linq; class B { static StreamWriter Out = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; static void Main(string[] args) { long N, A, B; Input(out N, out A, out B); if (B == 0) { Print(0); } else { long C = N / (A + B); long R = N % (A + B); R = R - A; if (R < 0) { R = 0; } Print(C * B + R); } Out.Flush(); } static T ChangeT<T>(string s) => (T)Convert.ChangeType(s, typeof(T)); static void Input<A>(out A a) { var words = Console.ReadLine().Split( new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries); a = ChangeT<A>(words[0]); } static void Input<A, B>(out A a, out B b) { var words = Console.ReadLine().Split( new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries); a = ChangeT<A>(words[0]); b = ChangeT<B>(words[1]); } static void Input<A, B, C>(out A a, out B b, out C c) { var words = Console.ReadLine().Split( new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries); a = ChangeT<A>(words[0]); b = ChangeT<B>(words[1]); c = ChangeT<C>(words[2]); } static void Input<A, B, C, D>(out A a, out B b, out C c, out D d) { var words = Console.ReadLine().Split( new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries); a = ChangeT<A>(words[0]); b = ChangeT<B>(words[1]); c = ChangeT<C>(words[2]); d = ChangeT<D>(words[3]); } static void Input<A, B, C, D, E>(out A a, out B b, out C c, out D d, out E e) { var words = Console.ReadLine().Split( new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries); a = ChangeT<A>(words[0]); b = ChangeT<B>(words[1]); c = ChangeT<C>(words[2]); d = ChangeT<D>(words[3]); e = ChangeT<E>(words[4]); } static void Input<A, B, C, D, E, F>(out A a, out B b, out C c, out D d, out E e, out F f) { var words = Console.ReadLine().Split( new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries); a = ChangeT<A>(words[0]); b = ChangeT<B>(words[1]); c = ChangeT<C>(words[2]); d = ChangeT<D>(words[3]); e = ChangeT<E>(words[4]); f = ChangeT<F>(words[5]); } static void InputArray<T>(out T[] array) { array = Console.ReadLine() .Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries) .Select(s => ChangeT<T>(s)) .ToArray(); } static void Print<T>(T s) => Out.WriteLine(s); static void Print<T>(params T[] s) => Out.WriteLine(string.Join(" ", s)); static void Print<T>(IEnumerable<T> e) => Out.WriteLine(string.Join(" ", e)); }
using System; using System.Collections.Generic; using System.IO; using System.Linq; class B { static StreamWriter Out = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; static void Main(string[] args) { long N, A, B; Input(out N, out A, out B); if (A == 0) { Print(0); } else { long C = N / (A + B); long R = N % (A + B); if (R > A) { Print(C * A + A); } else { Print(C * A + R); } } Out.Flush(); } static T ChangeT<T>(string s) => (T)Convert.ChangeType(s, typeof(T)); static void Input<A>(out A a) { var words = Console.ReadLine().Split( new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries); a = ChangeT<A>(words[0]); } static void Input<A, B>(out A a, out B b) { var words = Console.ReadLine().Split( new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries); a = ChangeT<A>(words[0]); b = ChangeT<B>(words[1]); } static void Input<A, B, C>(out A a, out B b, out C c) { var words = Console.ReadLine().Split( new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries); a = ChangeT<A>(words[0]); b = ChangeT<B>(words[1]); c = ChangeT<C>(words[2]); } static void Input<A, B, C, D>(out A a, out B b, out C c, out D d) { var words = Console.ReadLine().Split( new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries); a = ChangeT<A>(words[0]); b = ChangeT<B>(words[1]); c = ChangeT<C>(words[2]); d = ChangeT<D>(words[3]); } static void Input<A, B, C, D, E>(out A a, out B b, out C c, out D d, out E e) { var words = Console.ReadLine().Split( new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries); a = ChangeT<A>(words[0]); b = ChangeT<B>(words[1]); c = ChangeT<C>(words[2]); d = ChangeT<D>(words[3]); e = ChangeT<E>(words[4]); } static void Input<A, B, C, D, E, F>(out A a, out B b, out C c, out D d, out E e, out F f) { var words = Console.ReadLine().Split( new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries); a = ChangeT<A>(words[0]); b = ChangeT<B>(words[1]); c = ChangeT<C>(words[2]); d = ChangeT<D>(words[3]); e = ChangeT<E>(words[4]); f = ChangeT<F>(words[5]); } static void InputArray<T>(out T[] array) { array = Console.ReadLine() .Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries) .Select(s => ChangeT<T>(s)) .ToArray(); } static void Print<T>(T s) => Out.WriteLine(s); static void Print<T>(params T[] s) => Out.WriteLine(string.Join(" ", s)); static void Print<T>(IEnumerable<T> e) => Out.WriteLine(string.Join(" ", e)); }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 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, 32], ["-", 75, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["-", 75, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["-", 75, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["-", 0, 57, 75, 196, 0, 57, 15, 16, 17, 18], ["-", 0, 57, 75, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 12, 22], ["-", 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], ["+", 0, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 48], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 95], ["+", 0, 57, 75, 196, 0, 57, 75, 196, 0, 45], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["+", 0, 57, 75, 196, 0, 57, 75, 196, 0, 46]]
8
909
28
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; namespace CsharpSpiral { partial class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = true }; Console.SetOut(sw); new Program().Solve(new ConsoleInput(Console.In, ' ')); Console.Out.Flush(); } public void Solve(ConsoleInput cin) { long N = cin.ReadLong; long A = cin.ReadLong; long B = cin.ReadLong; var sets = N / (A + B); Console.WriteLine(sets * A + (N % (A + B))); } } static class ExtendClass { public static void Swap<T>(this T[] X, int i, int j) { T tmp = X[i]; X[i] = X[j]; X[j] = tmp; } public static string Join<T>(this T[] X, string separator = " ") => string.Join(separator, X); public static S[] Clone<S>(this S[] src) where S : struct { var res = new S[src.Length]; Array.Copy(src, res, src.Length); return res; } } class ConsoleInput { private readonly TextReader _stream; private readonly char _separator = ' '; private readonly Queue<string> inputStream; public ConsoleInput(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.Collections.Generic; using System.IO; using System.Linq; using System.Text; namespace CsharpSpiral { partial class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = true }; Console.SetOut(sw); new Program().Solve(new ConsoleInput(Console.In, ' ')); Console.Out.Flush(); } public void Solve(ConsoleInput cin) { long N = cin.ReadLong; long A = cin.ReadLong; long B = cin.ReadLong; var sets = N / (A + B); Console.WriteLine(sets * A + Math.Min((N % (A + B)), A)); } } static class ExtendClass { public static void Swap<T>(this T[] X, int i, int j) { T tmp = X[i]; X[i] = X[j]; X[j] = tmp; } public static string Join<T>(this T[] X, string separator = " ") => string.Join(separator, X); public static S[] Clone<S>(this S[] src) where S : struct { var res = new S[src.Length]; Array.Copy(src, res, src.Length); return res; } } class ConsoleInput { private readonly TextReader _stream; private readonly char _separator = ' '; private readonly Queue<string> inputStream; public ConsoleInput(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, 28, 0, 16, 12, 213, 63, 214, 205, 22], ["+", 0, 28, 0, 16, 12, 213, 63, 214, 0, 131], ["+", 0, 28, 0, 16, 12, 213, 63, 214, 141, 22], ["+", 12, 213, 3, 4, 0, 28, 0, 23, 0, 24], ["+", 12, 213, 3, 4, 0, 28, 0, 23, 0, 25], ["+", 0, 28, 0, 16, 12, 213, 3, 4, 0, 21], ["+", 0, 16, 12, 213, 3, 4, 0, 28, 0, 22]]
8
620
7
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { partial class Program { static long mod = 1000000007; static void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } static void Main() { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); Solve(); Console.Out.Flush(); Console.ReadKey(); } //ここから static void Solve() { long N; long A; long B; Multi(out N, out A, out B); var ans = N / (A + B) * A + N % (A + B); Console.WriteLine(ans); } } //拡張メソッド public static class Ex { public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.Ordinal); return s.ToList(); } public static string yesno(this bool b) { return b ? "yes" : "no"; } public static string YesNo(this bool b) { return b ? "Yes" : "No"; } public static string YESNO(this bool b) { return b ? "YES" : "NO"; } } partial class Program { static public string GetStr() { return Console.ReadLine().Trim(); } static public char GetChar() { return Console.ReadLine().Trim()[0]; } static public int GetInt() { return int.Parse(Console.ReadLine().Trim()); } static public long GetLong() { return long.Parse(Console.ReadLine().Trim()); } static public double GetDouble() { return double.Parse(Console.ReadLine().Trim()); } static public string[] GetStrArray() { return Console.ReadLine().Trim().Split(' '); } static public int[] GetIntArray() { return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); } static public long[] GetLongArray() { return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); } static public char[] GetCharArray() { return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray(); } static public double[] GetDoubleArray() { return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray(); } static public void WriteObjects<T>(IList<T> values) { var num = values.Count; for (int i = 0; i < num; i++) { Console.Write(values[i]); if (i < num - 1) { Console.Write(" "); } } Console.WriteLine(); } static bool eq<T, U>() => typeof(T).Equals(typeof(U)); static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); static void Multi<T>(out T a) => a = cv<T>(GetStr()); static void Multi<T, U>(out T a, out U b) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); } static void Multi<T, U, V>(out T a, out U b, out V c) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } static 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]); } static 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]); } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { partial class Program { static long mod = 1000000007; static void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } static void Main() { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); Solve(); Console.Out.Flush(); Console.ReadKey(); } //ここから static void Solve() { long N; long A; long B; Multi(out N, out A, out B); var ans = N / (A + B) * A + Math.Min(A, N % (A + B)); Console.WriteLine(ans); } } //拡張メソッド public static class Ex { public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.Ordinal); return s.ToList(); } public static string yesno(this bool b) { return b ? "yes" : "no"; } public static string YesNo(this bool b) { return b ? "Yes" : "No"; } public static string YESNO(this bool b) { return b ? "YES" : "NO"; } } partial class Program { static public string GetStr() { return Console.ReadLine().Trim(); } static public char GetChar() { return Console.ReadLine().Trim()[0]; } static public int GetInt() { return int.Parse(Console.ReadLine().Trim()); } static public long GetLong() { return long.Parse(Console.ReadLine().Trim()); } static public double GetDouble() { return double.Parse(Console.ReadLine().Trim()); } static public string[] GetStrArray() { return Console.ReadLine().Trim().Split(' '); } static public int[] GetIntArray() { return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); } static public long[] GetLongArray() { return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); } static public char[] GetCharArray() { return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray(); } static public double[] GetDoubleArray() { return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray(); } static public void WriteObjects<T>(IList<T> values) { var num = values.Count; for (int i = 0; i < num; i++) { Console.Write(values[i]); if (i < num - 1) { Console.Write(" "); } } Console.WriteLine(); } static bool eq<T, U>() => typeof(T).Equals(typeof(U)); static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); static void Multi<T>(out T a) => a = cv<T>(GetStr()); static void Multi<T, U>(out T a, out U b) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); } static void Multi<T, U, V>(out T a, out U b, out V c) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } static 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]); } static 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]); } } }
[["+", 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], ["+", 0, 212, 0, 16, 12, 213, 3, 4, 0, 24], ["+", 0, 16, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 212, 0, 16, 12, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25]]
8
1,174
7
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; namespace C { public class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } public static void Solve() { var ab = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); var res = -1; var a = ab[0] * 125; var mod = a % 100; if (ab[1] * 100 + mod == a) res = (int)Math.Ceiling(a / 10.0); Console.WriteLine(res); } } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; namespace C { public class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } public static void Solve() { var ab = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); var res = -1; var a = ab[0] * 125; var mod = a % 100; var tmp = ((a / 100) + 1) * 10; if (ab[1] * 100 + mod == a) res = (int)Math.Ceiling(a / 10.0); else if (tmp == ab[1] * 10) res = tmp; Console.WriteLine(res); } } }
[["+", 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, 200, 0, 212, 0, 16, 31, 23, 0, 24], ["+", 0, 16, 31, 23, 0, 16, 31, 23, 0, 24], ["+", 31, 23, 0, 16, 31, 23, 0, 16, 31, 22], ["+", 31, 23, 0, 16, 31, 23, 0, 16, 17, 85], ["+", 31, 23, 0, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 16, 31, 23, 0, 16, 31, 23, 0, 25], ["+", 0, 212, 0, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 212, 0, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 200, 0, 212, 0, 16, 31, 23, 0, 25], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 48], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 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], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 31, 22], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 60], ["+", 75, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 17, 48], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 25], ["+", 0, 57, 75, 57, 64, 1, 0, 11, 31, 22], ["+", 75, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 75, 57, 64, 1, 0, 11, 12, 22]]
8
178
31
using System; using System.Linq; class C { static void Main() { var h = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); var r = Enumerable.Range(1, 1009).FirstOrDefault(x => 2 * x == 25 * h[0] && x == 10 * h[1]); Console.WriteLine(r > 0 ? r : -1); } }
using System; using System.Linq; class C { static void Main() { var h = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); var r = Enumerable.Range(1, 1009).FirstOrDefault( x => (int)(0.08 * x) == h[0] && (int)(0.1 * x) == h[1]); Console.WriteLine(r > 0 ? r : -1); } }
[["-", 0, 218, 8, 16, 31, 16, 31, 16, 31, 203], ["+", 0, 218, 8, 16, 31, 16, 31, 74, 0, 24], ["+", 0, 218, 8, 16, 31, 16, 31, 74, 39, 199], ["+", 0, 218, 8, 16, 31, 16, 31, 74, 0, 25], ["+", 8, 16, 31, 16, 31, 74, 51, 23, 0, 24], ["+", 31, 16, 31, 74, 51, 23, 0, 16, 31, 250], ["+", 8, 16, 31, 16, 31, 74, 51, 23, 0, 25], ["-", 0, 218, 8, 16, 31, 16, 12, 16, 31, 203], ["-", 0, 218, 8, 16, 31, 16, 12, 16, 17, 48], ["+", 0, 218, 8, 16, 12, 16, 31, 74, 0, 24], ["+", 0, 218, 8, 16, 12, 16, 31, 74, 39, 199], ["+", 0, 218, 8, 16, 12, 16, 31, 74, 0, 25], ["+", 8, 16, 12, 16, 31, 74, 51, 23, 0, 24], ["+", 12, 16, 31, 74, 51, 23, 0, 16, 31, 250], ["+", 12, 16, 31, 74, 51, 23, 0, 16, 17, 48], ["+", 8, 16, 12, 16, 31, 74, 51, 23, 0, 25], ["-", 0, 218, 8, 16, 12, 16, 12, 16, 31, 203], ["-", 0, 218, 8, 16, 12, 16, 12, 16, 17, 48]]
8
92
18
using System; using System.Collections.Generic; using System.Linq; namespace test { class MainClass { public static void Main(string[] args) { //問題158 // A <= x * 1.08 < A + 1 // 100 * A <= x * 108 < 100 * A + 100 // B * 100 <= x * 110 < B * 100 + 100 // A * 100 / 108 <= x < (A + 100) / 108 // B * 100 / 110 <= x < (B + 100) / 110 // a <= x * 0.08 string[] line = Console.ReadLine().Split(' '); int a = int.Parse(line[0]); int b = int.Parse(line[1]); for (int i = 1; i <= 100; i++) { if (100 * a <= i * 8 && i * 8 < 100 * a + 100) { if (100 * b <= i * 10 && i * 10 < b * 100 + 100) { Console.WriteLine(i); return; } } } Console.WriteLine(-1); } } }
using System; using System.Collections.Generic; using System.Linq; namespace test { class MainClass { public static void Main(string[] args) { //問題158 // A <= x * 1.08 < A + 1 // 100 * A <= x * 108 < 100 * A + 100 // B * 100 <= x * 110 < B * 100 + 100 // A * 100 / 108 <= x < (A + 100) / 108 // B * 100 / 110 <= x < (B + 100) / 110 // a <= x * 0.08 string[] line = Console.ReadLine().Split(' '); int a = int.Parse(line[0]); int b = int.Parse(line[1]); int first = 100 * a / 8; int last = (100 * a + 100) / 8; for (int i = first; i <= last; i++) { if (100 * a <= i * 8 && i * 8 < 100 * a + 100) { if (100 * b <= i * 10 && i * 10 < b * 100 + 100) { Console.WriteLine(i); return; } } } Console.WriteLine(-1); } } }
[["+", 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, 16, 31, 16, 31, 203], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 17, 48], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 12, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 85], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 200, 0, 212, 0, 16, 31, 23, 0, 24], ["+", 0, 16, 31, 23, 0, 16, 31, 16, 31, 203], ["+", 0, 16, 31, 23, 0, 16, 31, 16, 17, 48], ["+", 0, 16, 31, 23, 0, 16, 31, 16, 12, 22], ["+", 0, 212, 0, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 212, 0, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 200, 0, 212, 0, 16, 31, 23, 0, 25], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22]]
8
163
26
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[] line = Console.ReadLine().Split(' '); float A = float.Parse(line[0]); float B = float.Parse(line[1]); for (int i = 1; i < 100 * 10; i++) { if (((int)(i * 0.08) == A) && ((int)(i * 0.1) == B)) { Console.WriteLine(i); return; } } Console.WriteLine("-1"); } } }
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[] line = Console.ReadLine().Split(' '); float A = float.Parse(line[0]); float B = float.Parse(line[1]); for (int i = 1; i < (int)(100 / 0.08); i++) { if (((int)(i * 0.08) == A) && ((int)(i * 0.1) == B)) { Console.WriteLine(i); return; } } Console.WriteLine("-1"); } } }
[["+", 8, 196, 0, 7, 15, 16, 12, 74, 0, 24], ["+", 8, 196, 0, 7, 15, 16, 12, 74, 39, 199], ["+", 8, 196, 0, 7, 15, 16, 12, 74, 0, 25], ["+", 0, 7, 15, 16, 12, 74, 51, 23, 0, 24], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 48], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 15, 16, 12, 74, 51, 23, 0, 16, 17, 85], ["+", 15, 16, 12, 74, 51, 23, 0, 16, 12, 250], ["+", 0, 7, 15, 16, 12, 74, 51, 23, 0, 25]]
8
156
9
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace TOPSIC { partial class Program { static void Main(string[] args) { string[] AB = Console.ReadLine().Split(' '); int A = int.Parse(AB[0]); int B = int.Parse(AB[1]); double ansA = A / 0.08; double ansB = B / 0.1; double ansA1 = (A + 1) / 0.08; double ansB1 = (B + 1) / 0.1; for (int i = (int)Math.Ceiling(ansA); i <= (int)ansA1; i++) { for (int j = (int)Math.Ceiling(ansB); j <= (int)ansB1; j++) { if (i == j) { Console.WriteLine(i); return; } } } Console.WriteLine("-1"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace TOPSIC { partial class Program { static void Main(string[] args) { string[] AB = Console.ReadLine().Split(' '); int A = int.Parse(AB[0]); int B = int.Parse(AB[1]); double ansA = A / 0.08; double ansB = B / 0.1; double ansA1 = (A + 1) / 0.08; double ansB1 = (B + 1) / 0.1; for (int i = (int)Math.Ceiling(ansA); i < (int)Math.Ceiling(ansA1); i++) { for (int j = (int)Math.Ceiling(ansB); j < (int)Math.Ceiling(ansB1); j++) { if (i == j) { Console.WriteLine(i); return; } } } Console.WriteLine("-1"); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 15, 16, 12, 74, 51, 213, 63, 214, 205, 22], ["+", 15, 16, 12, 74, 51, 213, 63, 214, 0, 131], ["+", 15, 16, 12, 74, 51, 213, 63, 214, 141, 22], ["+", 15, 16, 12, 74, 51, 213, 3, 4, 0, 24], ["+", 15, 16, 12, 74, 51, 213, 3, 4, 0, 25], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18]]
8
207
14
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace C___Tax_Increase { class Program { static void Main(string[] args) { var A_B = Console.ReadLine().Split().Select(int.Parse).ToArray(); int A = A_B[0], B = A_B[1]; int cal_A = (int)(A / 0.08), cal_B = (int)(B / 0.10); for (int i = cal_B; i <= cal_A; i++) { if ((int)(i * 0.08) == A && (int)(i * 0.10) == B) { Console.WriteLine(i); return; } } Console.WriteLine(-1); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace C___Tax_Increase { class Program { static void Main(string[] args) { var A_B = Console.ReadLine().Split().Select(int.Parse).ToArray(); int A = A_B[0], B = A_B[1]; for (int i = 10; i <= 1250; i++) { if ((int)(i * 0.08) == A && (int)(i * 0.10) == B) { Console.WriteLine(i); return; } } Console.WriteLine(-1); } } }
[["-", 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, 200, 0, 212, 0, 74, 51, 23, 0, 24], ["-", 0, 212, 0, 74, 51, 23, 0, 16, 31, 22], ["-", 0, 212, 0, 74, 51, 23, 0, 16, 17, 85], ["-", 0, 212, 0, 74, 51, 23, 0, 16, 12, 250], ["-", 0, 200, 0, 212, 0, 74, 51, 23, 0, 25], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 0, 21], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203]]
8
167
27
using System; using System.Linq; namespace ABC158_C { class Program { static void Main(string[] args) { int[] S = Console.ReadLine() .Trim() .Split(' ') .Select(a => int.Parse(a)) .ToArray(); Console.WriteLine(S[0]); Console.WriteLine(S[1]); for (int i = 0; i <= 1000; i++) { if (Math.Floor(i * 0.08) == S[0] && Math.Floor(i * 0.1) == S[1]) { Console.WriteLine(i); Environment.Exit(0); } } Console.WriteLine(-1); } } }
using System; using System.Linq; namespace ABC158_C { class Program { static void Main(string[] args) { int[] S = Console.ReadLine() .Trim() .Split(' ') .Select(a => int.Parse(a)) .ToArray(); for (int i = 0; i <= 1000; i++) { if (Math.Floor(i * 0.08) == S[0] && Math.Floor(i * 0.1) == S[1]) { Console.WriteLine(i); Environment.Exit(0); } } Console.WriteLine(-1); } } }
[["-", 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, 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], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
155
20
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.Numerics; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); Console.ReadLine(); } public void Solve(ConsoleInput cin) { int[] data = cin.ReadIntArray(2); int amin = (int)(data[0] * 12.5f); //この値は候補に入らないことに注意 float amax = (data[0] + 1) * 12.5f; int bmin = (int)(data[1] * 10); float bmax = (data[1] + 1) * 10; if (amax <= bmin || amin >= bmax) { Console.WriteLine("-1"); } else { Console.WriteLine(Math.Max(amin, bmin)); } } // 以下は消さないこと // a^n mod MODを求める(繰り返し2情報を用いた高速版) 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; } // 最小公倍数 public static long Lcm(long a, long b) { return a * b / Gcd(a, b); } // ユークリッドの互除法 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; } } public class Vector2 { public int x; public int y; public Vector2(int _x, int _y) { x = _x; y = _y; } } 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 ulong ReadULong { get { return ulong.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; } public ulong[] ReadULongArray(long N) { var ret = new ulong[N]; for (long i = 0; i < N; ++i) ret[i] = ReadULong; return ret; } } public class Util { // nCrを計算したいときに使用 public static ModInt Comb(int n, int r) { ModInt res = 1; for (int i = 1; i <= r; i++) { res *= n; res /= i; n--; } return res; } // n^mを計算 public static ModInt Power(ModInt n, long m) { ModInt pow = n; ModInt res = 1; while (m > 0) { if ((m & 1) == 1) res *= pow; pow *= pow; m >>= 1; } return res; } } public struct ModInt { public const int Mod = 1000000007; const long POSITIVIZER = ((long)Mod) << 31; long Data; public ModInt(long data) { if ((Data = data % Mod) < 0) Data += Mod; } public static implicit operator long(ModInt modInt) => modInt.Data; public static implicit operator ModInt(long val) => new ModInt(val); public static ModInt operator -(ModInt a, int b) => new ModInt() { Data = (a.Data - b + POSITIVIZER) % Mod }; public static ModInt operator -(ModInt a, ModInt b) { long res = a.Data - b.Data; return new ModInt() { Data = res < 0 ? res + Mod : res }; } public static ModInt operator *(ModInt a, int b) => new ModInt(a.Data * b); public static ModInt operator *(ModInt a, ModInt b) => new ModInt() { Data = a.Data * b.Data % Mod }; public static ModInt operator /(ModInt a, ModInt b) => new ModInt() { Data = a.Data * GetInverse(b) % Mod }; public override int GetHashCode() => (int)Data; static long GetInverse(long a) { long div, p = Mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1; while (true) { if (p == 1) return x2 + Mod; div = a / p; x1 -= x2 * div; y1 -= y2 * div; a %= p; if (a == 1) return x1 + Mod; div = p / a; x2 -= x1 * div; y2 -= y1 * div; p %= a; } } } }
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.Numerics; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); Console.ReadLine(); } public void Solve(ConsoleInput cin) { int[] data = cin.ReadIntArray(2); int amin = (int)Math.Ceiling(data[0] * 12.5); //この値は候補に入らないことに注意 float amax = (data[0] + 1) * 12.5f; int bmin = (int)Math.Ceiling(data[1] * 10.0); float bmax = (data[1] + 1) * 10; if (amax <= bmin || amin >= bmax) { Console.WriteLine("-1"); } else { Console.WriteLine(Math.Max(amin, bmin)); } } // 以下は消さないこと // a^n mod MODを求める(繰り返し2情報を用いた高速版) 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; } // 最小公倍数 public static long Lcm(long a, long b) { return a * b / Gcd(a, b); } // ユークリッドの互除法 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; } } public class Vector2 { public int x; public int y; public Vector2(int _x, int _y) { x = _x; y = _y; } } 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 ulong ReadULong { get { return ulong.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; } public ulong[] ReadULongArray(long N) { var ret = new ulong[N]; for (long i = 0; i < N; ++i) ret[i] = ReadULong; return ret; } } public class Util { // nCrを計算したいときに使用 public static ModInt Comb(int n, int r) { ModInt res = 1; for (int i = 1; i <= r; i++) { res *= n; res /= i; n--; } return res; } // n^mを計算 public static ModInt Power(ModInt n, long m) { ModInt pow = n; ModInt res = 1; while (m > 0) { if ((m & 1) == 1) res *= pow; pow *= pow; m >>= 1; } return res; } } public struct ModInt { public const int Mod = 1000000007; const long POSITIVIZER = ((long)Mod) << 31; long Data; public ModInt(long data) { if ((Data = data % Mod) < 0) Data += Mod; } public static implicit operator long(ModInt modInt) => modInt.Data; public static implicit operator ModInt(long val) => new ModInt(val); public static ModInt operator -(ModInt a, int b) => new ModInt() { Data = (a.Data - b + POSITIVIZER) % Mod }; public static ModInt operator -(ModInt a, ModInt b) { long res = a.Data - b.Data; return new ModInt() { Data = res < 0 ? res + Mod : res }; } public static ModInt operator *(ModInt a, int b) => new ModInt(a.Data * b); public static ModInt operator *(ModInt a, ModInt b) => new ModInt() { Data = a.Data * b.Data % Mod }; public static ModInt operator /(ModInt a, ModInt b) => new ModInt() { Data = a.Data * GetInverse(b) % Mod }; public override int GetHashCode() => (int)Data; static long GetInverse(long a) { long div, p = Mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1; while (true) { if (p == 1) return x2 + Mod; div = a / p; x1 -= x2 * div; y1 -= y2 * div; a %= p; if (a == 1) return x1 + Mod; div = p / a; x2 -= x1 * div; y2 -= y1 * div; p %= a; } } } }
[["+", 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, 23, 0, 16, 12, 250], ["+", 51, 213, 3, 4, 0, 28, 0, 16, 12, 250], ["-", 0, 212, 0, 74, 51, 23, 0, 16, 12, 203]]
8
1,262
10
using System; using System.Linq; using System.Collections.Generic; using E = System.Linq.Enumerable; public class Program { public static void Main() { var ab = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); var a = ab[0]; var b = ab[1]; for (int i = 1; i <= 100; ++i) { var x8 = i * 8 / 100; var x10 = i * 10 / 100; if (x8 > a || x10 > b) { break; } else if (x8 < a || x10 < b) { continue; } System.Diagnostics.Debug.Assert(x8 == x10); Console.WriteLine(i); return; } Console.WriteLine(-1); } }
using System; using System.Linq; using System.Collections.Generic; using E = System.Linq.Enumerable; public class Program { public static void Main() { var ab = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); var a = ab[0]; var b = ab[1]; for (int i = 1; i <= 1100; ++i) { var x8 = i * 8 / 100; var x10 = i * 10 / 100; if (x8 > a || x10 > b) { break; } else if (x8 < a || x10 < b) { continue; } Console.Error.WriteLine(x8 == x10); Console.WriteLine(i); return; } Console.WriteLine(-1); } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["-", 0, 213, 63, 214, 205, 214, 205, 214, 205, 22], ["-", 0, 213, 63, 214, 205, 214, 205, 214, 0, 131], ["-", 0, 213, 63, 214, 205, 214, 205, 214, 141, 22], ["+", 0, 1, 0, 213, 63, 214, 205, 214, 205, 22], ["-", 0, 1, 0, 213, 63, 214, 205, 214, 141, 22], ["+", 0, 1, 0, 213, 63, 214, 205, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22]]
8
175
10
using System; using System.Collections.Generic; using System.Linq; using static System.Math; using static Panasonic2020.C.Cin; using static Panasonic2020.C.Util; using Pair = Panasonic2020.C.VTuple<long, long>; using Graph = System.Collections.Generic.List<System.Collections.Generic.List<long>>; using System.Text; namespace Panasonic2020 { public class C { public static void Main(string[] args) { long a = rl; long b = rl; long c = rl; long x = a + b - c; if (x * x < 4 * a * b) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } public struct VTuple<T1, T2> : System.IComparable<VTuple<T1, T2>>, System.IEquatable<VTuple<T1, T2>> { public T1 First; public T2 Second; public VTuple(T1 a, T2 b) { First = a; Second = b; } public int CompareTo(VTuple<T1, T2> a) { int b = Comparer<T1>.Default.Compare(First, a.First); if (b != 0) return b; return Comparer<T2>.Default.Compare(Second, a.Second); } public override bool Equals(object a) { return a is VTuple<T1, T2> && Equals((VTuple<T1, T2>)a); } public bool Equals(VTuple<T1, T2> a) { return EqualityComparer<T1>.Default.Equals(First, a.First) && EqualityComparer<T2>.Default.Equals(Second, a.Second); } public override int GetHashCode() { int a = First != null ? First.GetHashCode() : 0; int b = Second != null ? Second.GetHashCode() : 0; uint c = ((uint)a << 5) | ((uint)a >> 27); return ((int)c + a) ^ b; } } public class HashMap<K, V> : System.Collections.Generic.Dictionary<K, V> { V i; static Func<V> j = System.Linq.Expressions.Expression .Lambda<Func<V>>(System.Linq.Expressions.Expression.New(typeof(V))) .Compile(); public HashMap() {} public HashMap(V a) { i = a; } new public V this[K a] { get { V b; if (TryGetValue(a, out b)) return b; else return base[a] = i != null ? i : j(); } set { base[a] = value; } } } public static class Util { public static readonly long INF = (long)1e17; public readonly static long MOD = (long)1e9 + 7; public readonly static int[] DXY4 = { 0, 1, 0, -1, 0 }; public readonly static int[] DXY8 = { 1, 1, 0, 1, -1, 0, -1, -1, 1 }; public static void DontAutoFlush() { var a = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(a); } public static void Flush() { Console.Out.Flush(); } public static T[] Sort<T>(T[] a) { Array.Sort<T>(a); return a; } public static T[] SortDecend<T>(T[] a) { Array.Sort<T>(a); Array.Reverse(a); return a; } public static void Swap<T>(ref T a, ref T b) { T c = a; a = b; b = c; } public static int GCD(int a, int b) { return (b == 0) ? a : GCD(b, a % b); } public static void ChMax(ref long a, long b) { if (a < b) a = b; } public static void ChMin(ref long a, long b) { if (a > b) a = b; } public static long ModAdd(long a, long b) { long c = a + b; if (c >= MOD) return c % MOD; return c; } public static long ModMul(long a, long b) { long c = a * b; if (c >= MOD) return c % MOD; return c; } public static void ChModAdd(ref long a, long b) { a += b; if (a >= MOD) a %= MOD; } public static void ChModMul(ref long a, long b) { a *= b; if (a >= MOD) a %= MOD; } public static void FillArray<T>(T[] a, T b) { int c = a.Length; for (int d = 0; d < c; d++) a[d] = b; } public static void FillArray<T>(T[,] a, T b) { int c = a.GetLength(0); int d = a.GetLength(1); for (int e = 0; e < c; e++) for (int f = 0; f < d; f++) { a[e, f] = b; } } public static void FillArray<T>(T[,,] a, T b) { int c = a.GetLength(0); int d = a.GetLength(1); int e = a.GetLength(2); for (int f = 0; f < c; f++) for (int g = 0; g < d; g++) { for (int h = 0; h < e; h++) { a[f, g, h] = b; } } } public static long[] Accumulate(long[] a) { long[] b = new long[a.Length + 1]; for (int c = 0; c < a.Length; c++) b[c + 1] = b[c] + a[c]; return b; } public static double[] Accumulate(double[] a) { double[] b = new double[a.Length + 1]; for (int c = 0; c < a.Length; c++) b[c + 1] = b[c] + a[c]; return b; } } public static class Cin { public static int ri { get { return ReadInt(); } } public static int[] ria { get { return ReadIntArray(); } } public static long rl { get { return ReadLong(); } } public static long[] rla { get { return ReadLongArray(); } } public static double rd { get { return ReadDouble(); } } public static double[] rda { get { return ReadDoubleArray(); } } public static string rs { get { return ReadString(); } } public static string[] rsa { get { return ReadStringArray(); } } public static int ReadInt() { return int.Parse(i()); } public static long ReadLong() { return long.Parse(i()); } public static double ReadDouble() { return double.Parse(i()); } public static string ReadString() { return i(); } public static int[] ReadIntArray() { g = null; return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long[] ReadLongArray() { g = null; return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static double[] ReadDoubleArray() { g = null; return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse); } public static string[] ReadStringArray() { g = null; return Console.ReadLine().Split(' '); } public static void ReadCol(out long[] a, long b) { a = new long[b]; for (int c = 0; c < b; c++) a[c] = ReadLong(); } public static void ReadCols(out long[] a, out long[] b, long c) { a = new long[c]; b = new long[c]; for (int d = 0; d < c; d++) { a[d] = ReadLong(); b[d] = ReadLong(); } } public static void ReadCols(out long[] a, out long[] b, out long[] c, long d) { a = new long[d]; b = new long[d]; c = new long[d]; for (int e = 0; e < d; e++) { a[e] = ReadLong(); b[e] = ReadLong(); c[e] = ReadLong(); } } public static int[,] ReadIntTable(int a, int b) { g = null; int[,] c = new int[a, b]; for (int d = 0; d < a; d++) for (int e = 0; e < b; e++) { c[d, e] = ReadInt(); } return c; } public static long[,] ReadLongTable(long a, long b) { g = null; long[,] c = new long[a, b]; for (int d = 0; d < a; d++) for (int e = 0; e < b; e++) { c[d, e] = ReadLong(); } return c; } public static char[,] ReadCharTable(int a, int b) { g = null; char[,] c = new char[a, b]; for (int d = 0; d < a; d++) { var e = ReadString(); for (int f = 0; f < b; f++) c[d, f] = e[f]; } return c; } static string[] g; static int h; static string i() { if (g == null || g.Length <= h) { g = Console.ReadLine().Split(' '); h = 0; } return g[h++]; } } } }
using System; using System.Collections.Generic; using System.Linq; using static System.Math; using static Panasonic2020.C.Cin; using static Panasonic2020.C.Util; using Pair = Panasonic2020.C.VTuple<long, long>; using Graph = System.Collections.Generic.List<System.Collections.Generic.List<long>>; using System.Text; namespace Panasonic2020 { public class C { public static void Main(string[] args) { long a = rl; long b = rl; long c = rl; long x = c - a - b; if (x < 0) { Console.WriteLine("No"); return; } if (4 * a * b < x * x) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } public struct VTuple<T1, T2> : System.IComparable<VTuple<T1, T2>>, System.IEquatable<VTuple<T1, T2>> { public T1 First; public T2 Second; public VTuple(T1 a, T2 b) { First = a; Second = b; } public int CompareTo(VTuple<T1, T2> a) { int b = Comparer<T1>.Default.Compare(First, a.First); if (b != 0) return b; return Comparer<T2>.Default.Compare(Second, a.Second); } public override bool Equals(object a) { return a is VTuple<T1, T2> && Equals((VTuple<T1, T2>)a); } public bool Equals(VTuple<T1, T2> a) { return EqualityComparer<T1>.Default.Equals(First, a.First) && EqualityComparer<T2>.Default.Equals(Second, a.Second); } public override int GetHashCode() { int a = First != null ? First.GetHashCode() : 0; int b = Second != null ? Second.GetHashCode() : 0; uint c = ((uint)a << 5) | ((uint)a >> 27); return ((int)c + a) ^ b; } } public class HashMap<K, V> : System.Collections.Generic.Dictionary<K, V> { V i; static Func<V> j = System.Linq.Expressions.Expression .Lambda<Func<V>>(System.Linq.Expressions.Expression.New(typeof(V))) .Compile(); public HashMap() {} public HashMap(V a) { i = a; } new public V this[K a] { get { V b; if (TryGetValue(a, out b)) return b; else return base[a] = i != null ? i : j(); } set { base[a] = value; } } } public static class Util { public static readonly long INF = (long)1e17; public readonly static long MOD = (long)1e9 + 7; public readonly static int[] DXY4 = { 0, 1, 0, -1, 0 }; public readonly static int[] DXY8 = { 1, 1, 0, 1, -1, 0, -1, -1, 1 }; public static void DontAutoFlush() { var a = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(a); } public static void Flush() { Console.Out.Flush(); } public static T[] Sort<T>(T[] a) { Array.Sort<T>(a); return a; } public static T[] SortDecend<T>(T[] a) { Array.Sort<T>(a); Array.Reverse(a); return a; } public static void Swap<T>(ref T a, ref T b) { T c = a; a = b; b = c; } public static int GCD(int a, int b) { return (b == 0) ? a : GCD(b, a % b); } public static void ChMax(ref long a, long b) { if (a < b) a = b; } public static void ChMin(ref long a, long b) { if (a > b) a = b; } public static long ModAdd(long a, long b) { long c = a + b; if (c >= MOD) return c % MOD; return c; } public static long ModMul(long a, long b) { long c = a * b; if (c >= MOD) return c % MOD; return c; } public static void ChModAdd(ref long a, long b) { a += b; if (a >= MOD) a %= MOD; } public static void ChModMul(ref long a, long b) { a *= b; if (a >= MOD) a %= MOD; } public static void FillArray<T>(T[] a, T b) { int c = a.Length; for (int d = 0; d < c; d++) a[d] = b; } public static void FillArray<T>(T[,] a, T b) { int c = a.GetLength(0); int d = a.GetLength(1); for (int e = 0; e < c; e++) for (int f = 0; f < d; f++) { a[e, f] = b; } } public static void FillArray<T>(T[,,] a, T b) { int c = a.GetLength(0); int d = a.GetLength(1); int e = a.GetLength(2); for (int f = 0; f < c; f++) for (int g = 0; g < d; g++) { for (int h = 0; h < e; h++) { a[f, g, h] = b; } } } public static long[] Accumulate(long[] a) { long[] b = new long[a.Length + 1]; for (int c = 0; c < a.Length; c++) b[c + 1] = b[c] + a[c]; return b; } public static double[] Accumulate(double[] a) { double[] b = new double[a.Length + 1]; for (int c = 0; c < a.Length; c++) b[c + 1] = b[c] + a[c]; return b; } } public static class Cin { public static int ri { get { return ReadInt(); } } public static int[] ria { get { return ReadIntArray(); } } public static long rl { get { return ReadLong(); } } public static long[] rla { get { return ReadLongArray(); } } public static double rd { get { return ReadDouble(); } } public static double[] rda { get { return ReadDoubleArray(); } } public static string rs { get { return ReadString(); } } public static string[] rsa { get { return ReadStringArray(); } } public static int ReadInt() { return int.Parse(i()); } public static long ReadLong() { return long.Parse(i()); } public static double ReadDouble() { return double.Parse(i()); } public static string ReadString() { return i(); } public static int[] ReadIntArray() { g = null; return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long[] ReadLongArray() { g = null; return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static double[] ReadDoubleArray() { g = null; return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse); } public static string[] ReadStringArray() { g = null; return Console.ReadLine().Split(' '); } public static void ReadCol(out long[] a, long b) { a = new long[b]; for (int c = 0; c < b; c++) a[c] = ReadLong(); } public static void ReadCols(out long[] a, out long[] b, long c) { a = new long[c]; b = new long[c]; for (int d = 0; d < c; d++) { a[d] = ReadLong(); b[d] = ReadLong(); } } public static void ReadCols(out long[] a, out long[] b, out long[] c, long d) { a = new long[d]; b = new long[d]; c = new long[d]; for (int e = 0; e < d; e++) { a[e] = ReadLong(); b[e] = ReadLong(); c[e] = ReadLong(); } } public static int[,] ReadIntTable(int a, int b) { g = null; int[,] c = new int[a, b]; for (int d = 0; d < a; d++) for (int e = 0; e < b; e++) { c[d, e] = ReadInt(); } return c; } public static long[,] ReadLongTable(long a, long b) { g = null; long[,] c = new long[a, b]; for (int d = 0; d < a; d++) for (int e = 0; e < b; e++) { c[d, e] = ReadLong(); } return c; } public static char[,] ReadCharTable(int a, int b) { g = null; char[,] c = new char[a, b]; for (int d = 0; d < a; d++) { var e = ReadString(); for (int f = 0; f < b; f++) c[d, f] = e[f]; } return c; } static string[] g; static int h; static string i() { if (g == null || g.Length <= h) { g = Console.ReadLine().Split(' '); h = 0; } return g[h++]; } } } }
[["+", 0, 200, 0, 212, 0, 16, 31, 16, 31, 22], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 17, 33], ["-", 0, 200, 0, 212, 0, 16, 31, 16, 17, 72], ["-", 0, 200, 0, 212, 0, 16, 31, 16, 12, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 48], ["+", 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], ["+", 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, 195, 8, 196, 0, 57, 64, 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, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 48], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22]]
8
2,216
29
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; namespace MyProject { class Program { static void Main(string[] args) { #if Local var sw = new Stopwatch(); sw.Start(); Console.SetIn(new StreamReader("input.in")); #endif var solver = new Solver(); solver.Solve(); #if Local Console.WriteLine($"{sw.ElapsedMilliseconds}ms"); #endif } } class Solver { public void Solve() { var item = Console.ReadLine().Split().Select(elem => long.Parse(elem)).ToArray(); var a = item[0]; var b = item[1]; var c = item[2]; var answer = (4 * a * b < Math.Pow(c - a - b, 2)) ? "Yes" : "No"; Console.WriteLine(answer); } } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; namespace MyProject { class Program { static void Main(string[] args) { #if Local var sw = new Stopwatch(); sw.Start(); Console.SetIn(new StreamReader("input.in")); #endif var solver = new Solver(); solver.Solve(); #if Local Console.WriteLine($"{sw.ElapsedMilliseconds}ms"); #endif } } class Solver { public void Solve() { var item = Console.ReadLine().Split().Select(elem => long.Parse(elem)).ToArray(); var a = item[0]; var b = item[1]; var c = item[2]; var d = c - a - b; var answer = (d > 0 && 4 * a * b < d * d) ? "Yes" : "No"; Console.WriteLine(answer); } } }
[["+", 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, 16, 31, 16, 31, 22], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 17, 33], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 12, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 41, 15, 23, 0, 16, 31, 16, 31, 22], ["+", 0, 41, 15, 23, 0, 16, 31, 16, 17, 47], ["+", 0, 41, 15, 23, 0, 16, 31, 16, 12, 203], ["+", 0, 212, 0, 41, 15, 23, 0, 16, 17, 98], ["-", 15, 23, 0, 16, 12, 213, 63, 214, 205, 22], ["-", 15, 23, 0, 16, 12, 213, 63, 214, 0, 131], ["-", 15, 23, 0, 16, 12, 213, 63, 214, 141, 22], ["-", 15, 23, 0, 16, 12, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 31, 22], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 17, 33], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["-", 15, 23, 0, 16, 12, 213, 3, 4, 0, 21], ["-", 0, 16, 12, 213, 3, 4, 0, 28, 0, 203], ["-", 15, 23, 0, 16, 12, 213, 3, 4, 0, 25], ["+", 15, 23, 0, 16, 12, 16, 12, 16, 31, 22], ["+", 15, 23, 0, 16, 12, 16, 12, 16, 17, 48], ["+", 15, 23, 0, 16, 12, 16, 12, 16, 12, 22]]
8
212
28
using System; using System.Linq; using System.Collections.Generic; namespace PANASONIC2020 { class C { static void Main(string[] args) { var x = Console.ReadLine().Split().Select(long.Parse).ToArray(); var a = x[0]; var b = x[1]; var c = x[2]; if (a + b < c) Console.WriteLine("Yes"); else Console.WriteLine("No"); } } }
using System; using System.Linq; using System.Collections.Generic; namespace PANASONIC2020 { class C { static void Main(string[] args) { var x = Console.ReadLine().Split().Select(long.Parse).ToArray(); var a = x[0]; var b = x[1]; var c = x[2]; var d = c - a - b; if (4 * a * b < d * d && d > 0) Console.WriteLine("Yes"); else Console.WriteLine("No"); } } }
[["+", 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, 200, 0, 212, 0, 16, 31, 16, 31, 22], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 17, 33], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 12, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 15, 16, 31, 16, 31, 16, 31, 16, 31, 203], ["+", 15, 16, 31, 16, 31, 16, 31, 16, 17, 48], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 72], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 48], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 48], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 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
109
21
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace C { class Program { static void Main(string[] args) { var abc = Console.ReadLine().Split(' '); var nums = new long[3]; for (int i = 0; i < 3; i++) { nums[i] = long.Parse(abc[i]); } if (Math.Pow((nums[2] - nums[0] - nums[1]), 2) > 4 * nums[0] * nums[1]) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } // Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace C { class Program { static void Main(string[] args) { var abc = Console.ReadLine().Split(' '); var nums = new long[3]; for (int i = 0; i < 3; i++) { nums[i] = long.Parse(abc[i]); } long tmp = nums[2] - nums[0] - nums[1]; if (tmp * tmp > 4 * nums[0] * nums[1] && tmp > 0) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } Console.ReadKey(); } } }
[["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 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], ["-", 31, 213, 3, 4, 0, 28, 0, 23, 0, 24], ["+", 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], ["-", 31, 213, 3, 4, 0, 28, 0, 23, 0, 25], ["-", 0, 57, 15, 16, 31, 213, 3, 4, 0, 21], ["-", 15, 16, 31, 213, 3, 4, 0, 28, 0, 203], ["-", 0, 57, 15, 16, 31, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 48], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 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, 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
164
30
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System; using System.Collections.Generic; using System.Linq; namespace ClassLibrary1 { public class ListNode { public int val; public ListNode next; public ListNode(int x) { val = x; } } public class Class1 { // static Dictionary<Tuple<long, long>, long> dic = new Dictionary<Tuple<long, // long>, long>(); static long mod = 1000000007; static long[] factorial = new long[1000001]; static long[] invFactorial = new long[1000001]; private static void calcFanctorial(long N) { factorial[0] = 1; for (int i = 1; i < N + 1; i++) { factorial[i] = factorial[i - 1] * i; factorial[i] %= mod; } invFactorial[N] = inv(factorial[N]); for (int i = (int)N; i > 0; i--) { invFactorial[i - 1] = invFactorial[i] * i % mod; } } static void Main(string[] args) { var N = ReadLongArr(); var AB = Math.Sqrt(N[0] * N[1]); long pow = (N[2] - N[1] - N[0]) * (N[2] - N[1] - N[0]); long prod = 4 * N[0] * N[1]; if (pow > prod) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } // Console.WriteLine(res); } class Tree { public HashSet<long> conn = new HashSet<long>(); } static long bin(long a, long x, long n) { long y = a; long res = 1; while (x > 0) { if (x % 2 == 1) { res = res * y % n; } x /= 2; y = y * y % n; } return res; } int cmp(string a, string b) { for (var i = 0; i < Math.Min(a.Length, b.Length); i++) if (a[i] < b[i]) return -1; else if (a[i] > b[i]) return 1; if (a.Length == b.Length) return 0; if (a.Length > b.Length) return 1; else return -1; } private static long nCm(long n, long m) { if (n < m) return 0; if (m < 0) return 0; return (factorial[n] * invFactorial[m] % mod) * invFactorial[n - m] % mod; } private static long nCm2(long n, long m) { if (n < m) return 0; if (m < 0) return 0; long res = 1; for (long i = n; i > n - m; i--) { res *= i; res %= mod; } return res * invFactorial[m] % mod; } public static long pow(long a, long b, long mod) { a %= mod; 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 Lcm(long a, long b) { return a * b % mod * inv(Gcd(a, b)) % mod; } public static long Lcm(long[] a) { List<long> vect = new List<long>(); long lcm = 1; for (int i = 0; i < a.Count(); i++) { var factor = a[i] / GcdVector(vect, a[i]); vect.Add(factor); lcm = lcm * factor % mod; } return lcm; } static long GcdVector(List<long> a, long b) { long ma = 1; for (int i = 0; i < a.Count; i++) ma = ma * a[i] % b; return Gcd(b, ma); } 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; } public static long pow(long a, long b) => pow(a, b, mod); public static long inv(long a) => pow(a, mod - 2); private static char[][] ReadCharMatrix(long h) { char[][] mtx = new char [h][]; for (int i = 0; i < h; i++) { var s = ReadString(); mtx[i] = s.ToCharArray(); } return mtx; } private static int[][] CreateIntMatrix(long h, long w) { int[][] mtx = new int [h][]; for (int i = 0; i < h; i++) { mtx[i] = new int[w]; } return mtx; } private static string ReadString() { return Console.ReadLine(); } private static string[] ReadStringArr() { return Console.ReadLine().Split(' '); } private static long ReadLong() { return long.Parse(Console.ReadLine()); } private static long[] ReadLongArr() { string[] s = ReadStringArr(); long[] l = new long[s.Length]; for (int i = 0; i < l.Length; i++) { l[i] = long.Parse(s[i]); } return l; } } class StringComparator2 : IComparer<string> { int IComparer<string>.Compare(string a, string b) { int length = Math.Min(a.Length, b.Length); // Console.WriteLine("Comparing with length {0}", length); for (int i = 0; i < length; i++) { if (a[i] < b[i]) { // Console.WriteLine("returning -1"); return -1; } else if (a[i] > b[i]) return 1; } if (a.Length < b.Length) return -1; if (a.Length > b.Length) return 1; // Console.WriteLine("Why are we at the end?"); return 0; } } public class PriorityQueue<T> where T : IComparable { private IComparer<T> _comparer = null; private int _type = 0; private T[] _heap; private int _sz = 0; private int _count = 0; /// <summary> /// Priority Queue with custom comparer /// </summary> public PriorityQueue(int maxSize, IComparer<T> comparer) { _heap = new T[maxSize]; _comparer = comparer; } /// <summary> /// Priority queue /// </summary> /// <param name="maxSize">max size</param> /// <param name="type">0: asc, 1:desc</param> public PriorityQueue(int maxSize, int type = 0) { _heap = new T[maxSize]; _type = type; } private int Compare(T x, T y) { if (_comparer != null) return _comparer.Compare(x, y); return _type == 0 ? x.CompareTo(y) : y.CompareTo(x); } public void Push(T x) { _count++; // node number var i = _sz++; while (i > 0) { // parent node number var p = (i - 1) / 2; if (Compare(_heap[p], x) <= 0) break; _heap[i] = _heap[p]; i = p; } _heap[i] = x; } public T Pop() { _count--; T ret = _heap[0]; T x = _heap[--_sz]; int i = 0; while (i * 2 + 1 < _sz) { // children int a = i * 2 + 1; int b = i * 2 + 2; if (b < _sz && Compare(_heap[b], _heap[a]) < 0) a = b; if (Compare(_heap[a], x) >= 0) break; _heap[i] = _heap[a]; i = a; } _heap[i] = x; return ret; } public int Count() { return _count; } public T Peek() { return _heap[0]; } public bool Contains(T x) { for (int i = 0; i < _sz; i++) if (x.Equals(_heap[i])) return true; return false; } public void Clear() { while (this.Count() > 0) this.Pop(); } public IEnumerator<T> GetEnumerator() { var ret = new List<T>(); while (this.Count() > 0) { ret.Add(this.Pop()); } foreach (var r in ret) { this.Push(r); yield return r; } } public T[] ToArray() { T[] array = new T[_sz]; int i = 0; foreach (var r in this) { array[i++] = r; } return array; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System; using System.Collections.Generic; using System.Linq; namespace ClassLibrary1 { public class ListNode { public int val; public ListNode next; public ListNode(int x) { val = x; } } public class Class1 { // static Dictionary<Tuple<long, long>, long> dic = new Dictionary<Tuple<long, // long>, long>(); static long mod = 1000000007; static long[] factorial = new long[1000001]; static long[] invFactorial = new long[1000001]; private static void calcFanctorial(long N) { factorial[0] = 1; for (int i = 1; i < N + 1; i++) { factorial[i] = factorial[i - 1] * i; factorial[i] %= mod; } invFactorial[N] = inv(factorial[N]); for (int i = (int)N; i > 0; i--) { invFactorial[i - 1] = invFactorial[i] * i % mod; } } static void Main(string[] args) { var N = ReadLongArr(); if ((N[2] - N[1] - N[0] < 0)) { Console.WriteLine("No"); return; } long pow = (N[2] - N[1] - N[0]) * (N[2] - N[1] - N[0]); long prod = 4 * N[0] * N[1]; if (pow > prod) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } // Console.WriteLine(res); } class Tree { public HashSet<long> conn = new HashSet<long>(); } static long bin(long a, long x, long n) { long y = a; long res = 1; while (x > 0) { if (x % 2 == 1) { res = res * y % n; } x /= 2; y = y * y % n; } return res; } int cmp(string a, string b) { for (var i = 0; i < Math.Min(a.Length, b.Length); i++) if (a[i] < b[i]) return -1; else if (a[i] > b[i]) return 1; if (a.Length == b.Length) return 0; if (a.Length > b.Length) return 1; else return -1; } private static long nCm(long n, long m) { if (n < m) return 0; if (m < 0) return 0; return (factorial[n] * invFactorial[m] % mod) * invFactorial[n - m] % mod; } private static long nCm2(long n, long m) { if (n < m) return 0; if (m < 0) return 0; long res = 1; for (long i = n; i > n - m; i--) { res *= i; res %= mod; } return res * invFactorial[m] % mod; } public static long pow(long a, long b, long mod) { a %= mod; 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 Lcm(long a, long b) { return a * b % mod * inv(Gcd(a, b)) % mod; } public static long Lcm(long[] a) { List<long> vect = new List<long>(); long lcm = 1; for (int i = 0; i < a.Count(); i++) { var factor = a[i] / GcdVector(vect, a[i]); vect.Add(factor); lcm = lcm * factor % mod; } return lcm; } static long GcdVector(List<long> a, long b) { long ma = 1; for (int i = 0; i < a.Count; i++) ma = ma * a[i] % b; return Gcd(b, ma); } 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; } public static long pow(long a, long b) => pow(a, b, mod); public static long inv(long a) => pow(a, mod - 2); private static char[][] ReadCharMatrix(long h) { char[][] mtx = new char [h][]; for (int i = 0; i < h; i++) { var s = ReadString(); mtx[i] = s.ToCharArray(); } return mtx; } private static int[][] CreateIntMatrix(long h, long w) { int[][] mtx = new int [h][]; for (int i = 0; i < h; i++) { mtx[i] = new int[w]; } return mtx; } private static string ReadString() { return Console.ReadLine(); } private static string[] ReadStringArr() { return Console.ReadLine().Split(' '); } private static long ReadLong() { return long.Parse(Console.ReadLine()); } private static long[] ReadLongArr() { string[] s = ReadStringArr(); long[] l = new long[s.Length]; for (int i = 0; i < l.Length; i++) { l[i] = long.Parse(s[i]); } return l; } } class StringComparator2 : IComparer<string> { int IComparer<string>.Compare(string a, string b) { int length = Math.Min(a.Length, b.Length); // Console.WriteLine("Comparing with length {0}", length); for (int i = 0; i < length; i++) { if (a[i] < b[i]) { // Console.WriteLine("returning -1"); return -1; } else if (a[i] > b[i]) return 1; } if (a.Length < b.Length) return -1; if (a.Length > b.Length) return 1; // Console.WriteLine("Why are we at the end?"); return 0; } } public class PriorityQueue<T> where T : IComparable { private IComparer<T> _comparer = null; private int _type = 0; private T[] _heap; private int _sz = 0; private int _count = 0; /// <summary> /// Priority Queue with custom comparer /// </summary> public PriorityQueue(int maxSize, IComparer<T> comparer) { _heap = new T[maxSize]; _comparer = comparer; } /// <summary> /// Priority queue /// </summary> /// <param name="maxSize">max size</param> /// <param name="type">0: asc, 1:desc</param> public PriorityQueue(int maxSize, int type = 0) { _heap = new T[maxSize]; _type = type; } private int Compare(T x, T y) { if (_comparer != null) return _comparer.Compare(x, y); return _type == 0 ? x.CompareTo(y) : y.CompareTo(x); } public void Push(T x) { _count++; // node number var i = _sz++; while (i > 0) { // parent node number var p = (i - 1) / 2; if (Compare(_heap[p], x) <= 0) break; _heap[i] = _heap[p]; i = p; } _heap[i] = x; } public T Pop() { _count--; T ret = _heap[0]; T x = _heap[--_sz]; int i = 0; while (i * 2 + 1 < _sz) { // children int a = i * 2 + 1; int b = i * 2 + 2; if (b < _sz && Compare(_heap[b], _heap[a]) < 0) a = b; if (Compare(_heap[a], x) >= 0) break; _heap[i] = _heap[a]; i = a; } _heap[i] = x; return ret; } public int Count() { return _count; } public T Peek() { return _heap[0]; } public bool Contains(T x) { for (int i = 0; i < _sz; i++) if (x.Equals(_heap[i])) return true; return false; } public void Clear() { while (this.Count() > 0) this.Pop(); } public IEnumerator<T> GetEnumerator() { var ret = new List<T>(); while (this.Count() > 0) { ret.Add(this.Pop()); } foreach (var r in ret) { this.Push(r); yield return r; } } public T[] ToArray() { T[] array = new T[_sz]; int i = 0; foreach (var r in this) { array[i++] = r; } return array; } } }
[["-", 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, 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], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 48], ["+", 15, 23, 0, 16, 31, 16, 31, 16, 17, 33], ["+", 31, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 57, 15, 23, 0, 16, 31, 16, 17, 33], ["+", 15, 23, 0, 16, 31, 16, 12, 204, 205, 22], ["+", 0, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["+", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 8, 196, 0, 57, 15, 23, 0, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 23, 0, 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, 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, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
1,909
32
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; using System.Numerics; using System.Runtime.CompilerServices; using System.Text; using static System.Math; using static Solve.Methods; using static Solve.Input; using static Solve.Output; using pii = Solve.Pair<int, int>; using pll = Solve.Pair<long, long>; using pli = Solve.Pair<long, int>; using pil = Solve.Pair<int, long>; using pss = Solve.Pair<string, string>; using psi = Solve.Pair<string, int>; using lint = System.Collections.Generic.List<int>; using llong = System.Collections.Generic.List<long>; using lstr = System.Collections.Generic.List<string>; using llint = System.Collections.Generic.List<System.Collections.Generic.List<int>>; using llstr = System.Collections.Generic.List<System.Collections.Generic.List<long>>; using lllong = System.Collections.Generic.List<System.Collections.Generic.List<string>>; using lii = System.Collections.Generic.List<Solve.Pair<int, int>>; using lll = System.Collections.Generic.List<Solve.Pair<long, long>>; using lli = System.Collections.Generic.List<Solve.Pair<long, int>>; using lil = System.Collections.Generic.List<Solve.Pair<int, long>>; using ll = System.Int64; namespace Solve { public class Solver { public void Main() { long a, b, c; a = ReadLong; b = ReadLong; c = ReadLong; // sqrt(a) + sqrt(b) < sqrt(c) // 両辺を2乗して sqrt(a), sqrt(b), sqrt(c) > 0 より // 2 sqrt(ab) + a + b < c // 移項して // 2 sqrt(ab) < c - a - b // 両辺を2乗して // 4ab < (c - a - b)^2 var left = 4 * a * b; var right = c - a - b; right *= right; PrintBool(left < right); } // ReSharper disable UnusedMember.Local private const int MOD = (int) 1e9 + 7, INF = 1000000010; private const long LINF = 1000000000000000100; } // ライブラリ置き場ここから // ライブラリ置き場ここまで #region Templete #if !LOCAL namespace Library { } #endif public static class Methods { public static readonly int[] dx = {-1, 0, 0, 1}; public static readonly int[] dy = {0, 1, -1, 0}; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Assert(bool b, string message = null) { if (!b) throw new Exception(message ?? "Assert failed."); } /* public static Comparison<T> greater<T>() where T : IComparable<T> => (a, b) => b.CompareTo(a); */ public static string JoinSpace<T>(this IEnumerable<T> source) => source.Join(" "); public static string JoinEndline<T>(this IEnumerable<T> source) => source.Join("\n"); public static string Join<T>(this IEnumerable<T> source, string s) => string.Join(s, source); public static string Join<T>(this IEnumerable<T> source, char c) => string.Join(c.ToString(), source); /// <summary> /// <see cref="Pair{T1, T2}"/> クラスのインスタンスを作成します。 /// </summary> /// <typeparam name="T1">firstの型</typeparam> /// <typeparam name="T2">secondの型</typeparam> /// <param name="first">firstの値</param> /// <param name="second">secondの値</param> /// <returns>作成した<see cref="Pair{T1, T2}"/> クラスのインスタンス</returns> public static Pair<T1, T2> make_pair<T1, T2>(T1 first, T2 second) where T1 : IComparable<T1> where T2 : IComparable<T2> => new Pair<T1, T2>(first, second); /// <summary>aとbをスワップします。</summary> public static void Swap<T>(ref T a, ref T b) where T : struct { var tmp = b; b = a; a = tmp; } /// <summary>aとbの最大公約数を求めます。</summary> /// <returns>aとbの最大公約数</returns> public static long Gcd(long a, long b) { while (true) { if (a < b) Swap(ref a, ref b); if (a % b == 0) return b; var x = a; a = b; b = x % b; } } /// <summary>aとbの最小公倍数を求めます。</summary> /// <returns>aとbの最小公倍数</returns> public static long Lcm(long a, long b) => a / Gcd(a, b) * b; /// <summary> /// 指定した数値が素数であるかを判定します。 /// </summary> /// <remarks>計算量 (sqrt(value)) </remarks> /// <param name="value">判定する数値</param> /// <returns>value が素数であるか</returns> public static bool IsPrime(long value) { if (value <= 1) return false; for (long i = 2; i * i <= value; i++) if (value % i == 0) return false; return true; } /// <summary> /// <see cref="a"/> ^ <see cref="b"/> (mod <see cref="p"/>) を求める /// </summary> /// <returns><see cref="a"/> ^ <see cref="b"/> (mod <see cref="p"/>) の値</returns> public static long PowMod(long a, long b, long p) { long res = 1; while (b > 0) { if (b % 2 != 0) res = res * a % p; a = a * a % p; b >>= 1; } return res; } /// <summary> /// mod pにおけるaの逆元を求めます。 /// </summary> /// <param name="a"></param> /// <param name="p">法</param> /// <returns></returns> public static long ModInv(long a, long p) => PowMod(a, p - 2, p); public static int DivCeil(int left, int right) => left / right + (left % right == 0 ? 0 : 1); public static long DivCeil(long left, long right) => left / right + (left % right == 0L ? 0L : 1L); /// <summary> /// src の順列を求めます。 /// </summary> /// <typeparam name="T">型</typeparam> /// <param name="src">順列を求める配列</param> /// <returns>src の順列</returns> public static IEnumerable<T[]> Permutations<T>(IEnumerable<T> src) { var ret = new List<T[]>(); Search(ret, new Stack<T>(), src.ToArray()); return ret; } private static void Search<T>(ICollection<T[]> perms, Stack<T> stack, T[] a) { int N = a.Length; if (N == 0) perms.Add(stack.Reverse().ToArray()); else { var b = new T[N - 1]; Array.Copy(a, 1, b, 0, N - 1); for (int i = 0; i < a.Length; ++i) { stack.Push(a[i]); Search(perms, stack, b); if (i < b.Length) b[i] = a[i]; stack.Pop(); } } } /// <summary> /// 指定した条件を満たす最小の数値を返します。 /// </summary> /// <param name="low">検索する数値の最小値</param> /// <param name="high">検索する数値の最大値</param> /// <param name="expression">条件</param> /// <returns>条件を満たす最小の数値</returns> public static long BinarySearch(long low, long high, Func<long, bool> expression) { while (low < high) { long middle = (high - low) / 2 + low; if (!expression(middle)) high = middle; else low = middle + 1; } return high; } /// <summary> /// 指定した値以上の先頭のインデクスを返します。 /// </summary> /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="start">開始インデクス [inclusive]</param> /// <param name="end">終了インデクス [exclusive]</param> /// <param name="value">検索する値</param> /// <param name="comparer">比較関数(インターフェイス)</param> /// <returns>指定した値以上の先頭のインデクス</returns> public static int LowerBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; while (low < high) { var mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) < 0) low = mid + 1; else high = mid; } return low; } /// <summary> /// 指定した値以上の先頭のインデクスを返します。 /// </summary> /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="value">検索する値</param> /// <returns>指定した値以上の先頭のインデクス</returns> public static int LowerBound<T>(T[] arr, T value) where T : IComparable { return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default); } /// <summary> /// 指定した値より大きい先頭のインデクスを返します。 /// </summary> /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="start">開始インデクス [inclusive]</param> /// <param name="end">終了インデクス [exclusive]</param> /// <param name="value">検索する値</param> /// <param name="comparer">比較関数(インターフェイス)</param> /// <returns>指定した値より大きい先頭のインデクス</returns> public static int UpperBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; while (low < high) { var mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) <= 0) low = mid + 1; else high = mid; } return low; } /// <summary> /// 指定した値より大きい先頭のインデクスを返します。 /// </summary>Z /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="value">検索する値</param> /// <returns>指定した値より大きい先頭のインデクス</returns> public static int UpperBound<T>(T[] arr, T value) { return UpperBound(arr, 0, arr.Length, value, Comparer<T>.Default); } public static IEnumerable<TResult> SelectNotNull<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TResult> func) => source.Where(val => val != null).Select(func); public static IEnumerable<TSource> WhereNotNull<TSource>(this IEnumerable<TSource> source) => source.Where(val => val != null); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] ArrayOf<T>(params T[] arr) => arr; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<T> ListOf<T>(params T[] arr) => new List<T>(arr); public static IEnumerable<TResult> Repeat<TResult>(TResult value) { while (true) yield return value; // ReSharper disable once IteratorNeverReturns } public static IEnumerable<TResult> Repeat<TResult>(TResult value, int count) => Enumerable.Repeat(value, count); [SuppressMessage("ReSharper", "PossibleMultipleEnumeration")] public static IEnumerable<TResult> Repeat<TResult>(this IEnumerable<TResult> source, int count) { if (source == null) throw new ArgumentNullException(nameof(source)); if (count < 0) throw new ArgumentOutOfRangeException(nameof(count)); for (int i = 0; i < count; i++) foreach (var v in source) yield return v; } [SuppressMessage("ReSharper", "PossibleMultipleEnumeration")] public static IEnumerable<TResult> Repeat<TResult>(this IEnumerable<TResult> source) { if (source == null) throw new ArgumentNullException(nameof(source)); while (true) foreach (var v in source) yield return v; } /// <summary> /// 文字の配列を文字列に変換します。 /// </summary> /// <param name="source">文字の配列</param> /// <returns>変換した文字列</returns> public static string AsString(this IEnumerable<char> source) => new string(source.ToArray()); /// <summary> /// <see cref="source"/> の累積和を返します。 /// </summary> /// <returns><see cref="source"/> の累積和</returns> public static IEnumerable<long> CumSum(this IEnumerable<long> source) { long sum = 0; foreach (var item in source) yield return sum += item; } /// <summary> /// <see cref="source"/> の累積和を返します。 /// </summary> /// <returns><see cref="source"/> の累積和</returns> public static IEnumerable<int> CumSum(this IEnumerable<int> source) { int sum = 0; foreach (var item in source) yield return sum += item; } /// <summary> /// <see cref="value"/>が l以上 r未満の範囲に含まれているかを返します。 /// </summary> /// <typeparam name="T">要素の型</typeparam> /// <param name="value">判定する値</param> /// <param name="l">下限の値 (含まれる)</param> /// <param name="r">上限の値 (含まれない)</param> /// <returns><see cref="value"/> が指定した範囲に含まれているか</returns> public static bool IsIn<T>(this T value, T l, T r) where T : IComparable<T> { if (l.CompareTo(r) > 0) throw new ArgumentException(); return l.CompareTo(value) <= 0 && value.CompareTo(r) < 0; } /// <summary> /// <see cref="start"/> 以上 <see cref="end"/> 未満の値を <see cref="step"/> ずつ増やした結果を列挙します。 /// </summary> /// <param name="start">値の下限 (含まれる)</param> /// <param name="end">値の上限 (含まれない)</param> /// <param name="step">1要素ごとに増やす値</param> /// <returns>範囲の結果</returns> public static IEnumerable<int> Range(int start, int end, int step = 1) { for (var i = start; i < end; i += step) yield return i; } /// <summary> /// 0 以上 <see cref="end"/> 未満の値を 1 ずつ増やした結果を列挙します。 /// </summary> /// <param name="end">値の上限 (含まれない)</param> /// <returns>範囲の結果</returns> public static IEnumerable<int> Range(int end) => Range(0, end); /// <summary> /// <see cref="start"/> 以上 <see cref="end"/> 未満の値を <see cref="step"/> ずつ増やした結果を逆順に列挙します。 /// </summary> /// <param name="start">値の下限 (含まれる)</param> /// <param name="end">値の上限 (含まれない)</param> /// <param name="step">1要素ごとに増やす値</param> /// <returns>範囲の結果</returns> public static IEnumerable<int> RangeReverse(int start, int end, int step = 1) { for (var i = end - 1; i >= start; i -= step) yield return i; } /// <summary> /// 0 以上 <see cref="end"/> 未満の値を 1 ずつ増やした結果を逆順に列挙します。 /// </summary> /// <param name="end">値の上限 (含まれない)</param> /// <returns>範囲の結果</returns> public static IEnumerable<int> RangeReverse(int end) => RangeReverse(0, end); /// <summary> /// 指定した配列をコピーして昇順ソートします。(非破壊的) /// </summary> /// <typeparam name="T">ソートする配列の型</typeparam> /// <param name="arr">ソートする配列</param> /// <returns>ソートされた配列</returns> public static T[] Sort<T>(this T[] arr) { var array = new T[arr.Length]; arr.CopyTo(array, 0); Array.Sort(array); return array; } /// <summary> /// 指定した配列をコピーして降順ソートします。(非破壊的) /// </summary> /// <typeparam name="T">ソートする配列の型</typeparam> /// <param name="arr">ソートする配列</param> /// <returns>ソートされた配列</returns> public static T[] SortDescending<T>(this T[] arr) { var array = new T[arr.Length]; arr.CopyTo(array, 0); Array.Sort(array); Array.Reverse(array); return array; } public static double Log2(double x) => Log(x, 2); 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; } 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; } public static T Min<T>(params T[] col) => col.Min(); public static T Max<T>(params T[] col) => col.Max(); /// <summary> /// 要素数 (a, b) の、defaultValue で満たされたジャグ配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <param name="defaultValue">デフォルト値</param> /// <returns>指定した条件で初期化された配列</returns> public static T[][] JaggedArray2D<T>(int a, int b, T defaultValue = default(T)) { var ret = new T[a][]; for (int i = 0; i < a; i++) { ret[i] = Enumerable.Repeat(defaultValue, b).ToArray(); } return ret; } /// <summary> /// 要素数 (a, b) の,defaultValue で満たされた二次元配列を作成します。 /// </summary> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <param name="defaultValue">デフォルト値</param> /// <typeparam name="T">配列の型</typeparam> public static T[,] Array2D<T>(int a, int b, T defaultValue = default(T)) { var ret = new T[a, b]; for (int i = 0; i < a; i++) for (int j = 0; j < b; j++) ret[i, j] = defaultValue; return ret; } /// <summary> /// ジャグ配列を2次元配列に変換します。配列の各要素の長さがすべて同じである必要があります。 /// </summary> /// <param name="array">ジャグ配列</param> /// <typeparam name="T">二次元配列</typeparam> public static T[,] To2DArray<T>(this T[][] array) { if (!array.Any()) return new T[0, 0]; int len = array[0].Length; if (array.Any(x => x.Length != len)) throw new ArgumentException("array の各要素の長さが異なります。", nameof(array)); var ret = new T[array.Length, len]; for (int i = 0; i < array.Length; i++) { for (int j = 0; j < len; j++) { ret[i, j] = array[i][j]; } } return ret; } // public static vector<T> ToVector<T>(this IEnumerable<T> source) => new vector<T>(source); } public static class Input { private const char _separator = ' '; private static readonly Queue<string> _input = new Queue<string>(); private static readonly StreamReader sr = #if FILE new StreamReader("in.txt"); #else new StreamReader(Console.OpenStandardInput()); #endif public static string ReadLine => sr.ReadLine(); public static string ReadStr => Read; public static string Read { get { if (_input.Count != 0) return _input.Dequeue(); // ReSharper disable once PossibleNullReferenceException var tmp = sr.ReadLine().Split(_separator); foreach (var val in tmp) { _input.Enqueue(val); } return _input.Dequeue(); } } public static int ReadInt => int.Parse(Read); public static long ReadLong => long.Parse(Read); public static double ReadDouble => double.Parse(Read); public static string[] StrArray() => ReadLine.Split(' '); public static int[] IntArray() => ReadLine.Split(' ').Select(int.Parse).ToArray(); public static long[] LongArray() => ReadLine.Split(' ').Select(long.Parse).ToArray(); public static string[] StrArray(int n) { var ret = new string[n]; for (long i = 0; i < n; ++i) ret[i] = Read; return ret; } public static int[] IntArray(int n, int offset = 0, bool sorted = false) { var ret = StrArray(n).Select(x => int.Parse(x) + offset).ToArray(); if (sorted) Array.Sort(ret); return ret; } public static long[] LongArray(int n, long offset = 0, bool sorted = false) { var ret = StrArray(n).Select(x => long.Parse(x) + offset).ToArray(); if (sorted) Array.Sort(ret); return ret; } public static string[,] Str2DArray(int n, int m) { var ret = new string[n, m]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) ret[i, j] = ReadStr; return ret; } public static int[,] Int2DArray(int n, int m, int offset = 0) { var ret = new int[n, m]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) ret[i, j] = ReadInt + offset; return ret; } public static long[,] Long2DArray(int n, int m, long offset = 0) { var ret = new long[n, m]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) ret[i, j] = ReadLong + offset; return ret; } public static Tuple<string[], string[]> StrArrays2(int n) { var ret1 = new string[n]; var ret2 = new string[n]; for (int i = 0; i < n; i++) { ret1[i] = ReadStr; ret2[i] = ReadStr; } return Tuple.Create(ret1, ret2); } public static Tuple<int[], int[]> IntArrays2(int n, int offset1 = 0, int offset2 = 0) { var ret1 = new int[n]; var ret2 = new int[n]; for (int i = 0; i < n; i++) { ret1[i] = ReadInt + offset1; ret2[i] = ReadInt + offset2; } return Tuple.Create(ret1, ret2); } public static Tuple<long[], long[]> LongArrays2(int n, long offset1 = 0, long offset2 = 0) { var ret1 = new long[n]; var ret2 = new long[n]; for (int i = 0; i < n; i++) { ret1[i] = ReadLong + offset1; ret2[i] = ReadLong + offset2; } return Tuple.Create(ret1, ret2); } public static Tuple<string[], string[], string[]> StrArrays3(int n) { var ret1 = new string[n]; var ret2 = new string[n]; var ret3 = new string[n]; for (int i = 0; i < n; i++) { ret1[i] = ReadStr; ret2[i] = ReadStr; } return Tuple.Create(ret1, ret2, ret3); } public static Tuple<int[], int[], int[]> IntArrays3(int n, int offset1 = 0, int offset2 = 0, int offset3 = 0) { var ret1 = new int[n]; var ret2 = new int[n]; var ret3 = new int[n]; for (int i = 0; i < n; i++) { ret1[i] = ReadInt + offset1; ret2[i] = ReadInt + offset2; ret3[i] = ReadInt + offset3; } return Tuple.Create(ret1, ret2, ret3); } public static Tuple<long[], long[], long[]> LongArrays3(int n, long offset1 = 0, long offset2 = 0, long offset3 = 0) { var ret1 = new long[n]; var ret2 = new long[n]; var ret3 = new long[n]; for (int i = 0; i < n; i++) { ret1[i] = ReadLong + offset1; ret2[i] = ReadLong + offset2; ret3[i] = ReadLong + offset3; } return Tuple.Create(ret1, ret2, ret3); } private static bool TypeEquals<T, U>() => typeof(T) == typeof(U); private static T ChangeType<T, U>(U a) => (T) System.Convert.ChangeType(a, typeof(T)); private static T Convert<T>(string s) => TypeEquals<T, int>() ? ChangeType<T, int>(int.Parse(s)) : TypeEquals<T, long>() ? ChangeType<T, long>(long.Parse(s)) : TypeEquals<T, double>() ? ChangeType<T, double>(double.Parse(s)) : TypeEquals<T, char>() ? ChangeType<T, char>(s[0]) : ChangeType<T, string>(s); public static bool In<T>(out T a) { try { a = Convert<T>(Read); return true; } catch { a = default(T); return false; } } public static bool In<T, U>(out T a, out U b) { try { var ar = StrArray(2); a = Convert<T>(ar[0]); b = Convert<U>(ar[1]); return true; } catch { a = default(T); b = default(U); return false; } } public static bool In<T, U, V>(out T a, out U b, out V c) { try { var ar = StrArray(3); a = Convert<T>(ar[0]); b = Convert<U>(ar[1]); c = Convert<V>(ar[2]); return true; } catch { a = default(T); b = default(U); c = default(V); return false; } } public static bool In<T, U, V, W>(out T a, out U b, out V c, out W d) { try { var ar = StrArray(4); a = Convert<T>(ar[0]); b = Convert<U>(ar[1]); c = Convert<V>(ar[2]); d = Convert<W>(ar[3]); return true; } catch { a = default(T); b = default(U); c = default(V); d = default(W); return false; } } public static bool In<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { try { var ar = StrArray(5); a = Convert<T>(ar[0]); b = Convert<U>(ar[1]); c = Convert<V>(ar[2]); d = Convert<W>(ar[3]); e = Convert<X>(ar[4]); return true; } catch { a = default(T); b = default(U); c = default(V); d = default(W); e = default(X); return false; } } } public static class Output { public static void print<T>(T t) => Console.WriteLine(t); public static void print(params object[] o) => Console.WriteLine(o.Join(" ")); public static void PrintBool(bool val, string yes = "Yes", string no = "No") => Console.WriteLine(val ? yes : no); public static void PrintYn(bool val) => PrintBool(val); public static void PrintYN(bool val) => PrintBool(val, "YES", "NO"); public static void PrintPossible(bool val) => PrintBool(val, "Possible", "Impossible"); public static void PrintYay(bool val) => PrintBool(val, "Yay!", ":("); public static void PrintDebug(params object[] args) => Console.Error.WriteLine(string.Join(" ", args)); /// <summary> /// setter で設定された値を標準出力に出力します。 /// </summary> public static object cout { set { Console.WriteLine(value); } } /// <summary> /// Local環境のみ,setter で設定された値を標準出力に出力します。 /// </summary> public static object dout { set { #if LOCAL Console.WriteLine(value); #endif } } /// <summary> /// setter で設定された値を標準エラー出力に出力します。 /// </summary> public static object cerr { set { Console.Error.WriteLine(value); } } public const string endl = "\n"; } public class Program { public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false}; Console.SetOut(sw); new Solver().Main(); Console.Out.Flush(); Console.Read(); } } [DebuggerDisplay("({first}, {second})")] public class Pair<T1, T2> : IComparable<Pair<T1, T2>>, IEquatable<Pair<T1, T2>> where T1 : IComparable<T1> where T2 : IComparable<T2> { public Pair(T1 first, T2 second) { this.first = first; this.second = second; } public T1 first; public T2 second; public int CompareTo(Pair<T1, T2> other) { if (ReferenceEquals(this, other)) return 0; if (ReferenceEquals(null, other)) return 1; var firstComparison = first.CompareTo(other.first); return firstComparison != 0 ? firstComparison : second.CompareTo(other.second); } public override string ToString() => $"({first}, {second})"; public bool Equals(Pair<T1, T2> other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return EqualityComparer<T1>.Default.Equals(first, other.first) && EqualityComparer<T2>.Default.Equals(second, other.second); } public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; return obj.GetType() == GetType() && Equals((Pair<T1, T2>) obj); } public override int GetHashCode() { unchecked { return (EqualityComparer<T1>.Default.GetHashCode(first) * 397) ^ EqualityComparer<T2>.Default.GetHashCode(second); } } } #endregion }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; using System.Numerics; using System.Runtime.CompilerServices; using System.Text; using static System.Math; using static Solve.Methods; using static Solve.Input; using static Solve.Output; using pii = Solve.Pair<int, int>; using pll = Solve.Pair<long, long>; using pli = Solve.Pair<long, int>; using pil = Solve.Pair<int, long>; using pss = Solve.Pair<string, string>; using psi = Solve.Pair<string, int>; using lint = System.Collections.Generic.List<int>; using llong = System.Collections.Generic.List<long>; using lstr = System.Collections.Generic.List<string>; using llint = System.Collections.Generic.List<System.Collections.Generic.List<int>>; using llstr = System.Collections.Generic.List<System.Collections.Generic.List<long>>; using lllong = System.Collections.Generic.List<System.Collections.Generic.List<string>>; using lii = System.Collections.Generic.List<Solve.Pair<int, int>>; using lll = System.Collections.Generic.List<Solve.Pair<long, long>>; using lli = System.Collections.Generic.List<Solve.Pair<long, int>>; using lil = System.Collections.Generic.List<Solve.Pair<int, long>>; using ll = System.Int64; namespace Solve { public class Solver { public void Main() { long a, b, c; a = ReadLong; b = ReadLong; c = ReadLong; if (c - a - b <= 0) { Console.WriteLine("No"); return; } // sqrt(a) + sqrt(b) < sqrt(c) // 両辺を2乗して sqrt(a), sqrt(b), sqrt(c) > 0 より // 2 sqrt(ab) + a + b < c // 移項して // 2 sqrt(ab) < c - a - b // 両辺を2乗して // 4ab < (c - a - b)^2 var left = 4 * a * b; var right = c - a - b; right *= right; PrintBool(left < right); } // ReSharper disable UnusedMember.Local private const int MOD = (int) 1e9 + 7, INF = 1000000010; private const long LINF = 1000000000000000100; } // ライブラリ置き場ここから // ライブラリ置き場ここまで #region Templete #if !LOCAL namespace Library { } #endif public static class Methods { public static readonly int[] dx = {-1, 0, 0, 1}; public static readonly int[] dy = {0, 1, -1, 0}; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Assert(bool b, string message = null) { if (!b) throw new Exception(message ?? "Assert failed."); } /* public static Comparison<T> greater<T>() where T : IComparable<T> => (a, b) => b.CompareTo(a); */ public static string JoinSpace<T>(this IEnumerable<T> source) => source.Join(" "); public static string JoinEndline<T>(this IEnumerable<T> source) => source.Join("\n"); public static string Join<T>(this IEnumerable<T> source, string s) => string.Join(s, source); public static string Join<T>(this IEnumerable<T> source, char c) => string.Join(c.ToString(), source); /// <summary> /// <see cref="Pair{T1, T2}"/> クラスのインスタンスを作成します。 /// </summary> /// <typeparam name="T1">firstの型</typeparam> /// <typeparam name="T2">secondの型</typeparam> /// <param name="first">firstの値</param> /// <param name="second">secondの値</param> /// <returns>作成した<see cref="Pair{T1, T2}"/> クラスのインスタンス</returns> public static Pair<T1, T2> make_pair<T1, T2>(T1 first, T2 second) where T1 : IComparable<T1> where T2 : IComparable<T2> => new Pair<T1, T2>(first, second); /// <summary>aとbをスワップします。</summary> public static void Swap<T>(ref T a, ref T b) where T : struct { var tmp = b; b = a; a = tmp; } /// <summary>aとbの最大公約数を求めます。</summary> /// <returns>aとbの最大公約数</returns> public static long Gcd(long a, long b) { while (true) { if (a < b) Swap(ref a, ref b); if (a % b == 0) return b; var x = a; a = b; b = x % b; } } /// <summary>aとbの最小公倍数を求めます。</summary> /// <returns>aとbの最小公倍数</returns> public static long Lcm(long a, long b) => a / Gcd(a, b) * b; /// <summary> /// 指定した数値が素数であるかを判定します。 /// </summary> /// <remarks>計算量 (sqrt(value)) </remarks> /// <param name="value">判定する数値</param> /// <returns>value が素数であるか</returns> public static bool IsPrime(long value) { if (value <= 1) return false; for (long i = 2; i * i <= value; i++) if (value % i == 0) return false; return true; } /// <summary> /// <see cref="a"/> ^ <see cref="b"/> (mod <see cref="p"/>) を求める /// </summary> /// <returns><see cref="a"/> ^ <see cref="b"/> (mod <see cref="p"/>) の値</returns> public static long PowMod(long a, long b, long p) { long res = 1; while (b > 0) { if (b % 2 != 0) res = res * a % p; a = a * a % p; b >>= 1; } return res; } /// <summary> /// mod pにおけるaの逆元を求めます。 /// </summary> /// <param name="a"></param> /// <param name="p">法</param> /// <returns></returns> public static long ModInv(long a, long p) => PowMod(a, p - 2, p); public static int DivCeil(int left, int right) => left / right + (left % right == 0 ? 0 : 1); public static long DivCeil(long left, long right) => left / right + (left % right == 0L ? 0L : 1L); /// <summary> /// src の順列を求めます。 /// </summary> /// <typeparam name="T">型</typeparam> /// <param name="src">順列を求める配列</param> /// <returns>src の順列</returns> public static IEnumerable<T[]> Permutations<T>(IEnumerable<T> src) { var ret = new List<T[]>(); Search(ret, new Stack<T>(), src.ToArray()); return ret; } private static void Search<T>(ICollection<T[]> perms, Stack<T> stack, T[] a) { int N = a.Length; if (N == 0) perms.Add(stack.Reverse().ToArray()); else { var b = new T[N - 1]; Array.Copy(a, 1, b, 0, N - 1); for (int i = 0; i < a.Length; ++i) { stack.Push(a[i]); Search(perms, stack, b); if (i < b.Length) b[i] = a[i]; stack.Pop(); } } } /// <summary> /// 指定した条件を満たす最小の数値を返します。 /// </summary> /// <param name="low">検索する数値の最小値</param> /// <param name="high">検索する数値の最大値</param> /// <param name="expression">条件</param> /// <returns>条件を満たす最小の数値</returns> public static long BinarySearch(long low, long high, Func<long, bool> expression) { while (low < high) { long middle = (high - low) / 2 + low; if (!expression(middle)) high = middle; else low = middle + 1; } return high; } /// <summary> /// 指定した値以上の先頭のインデクスを返します。 /// </summary> /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="start">開始インデクス [inclusive]</param> /// <param name="end">終了インデクス [exclusive]</param> /// <param name="value">検索する値</param> /// <param name="comparer">比較関数(インターフェイス)</param> /// <returns>指定した値以上の先頭のインデクス</returns> public static int LowerBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; while (low < high) { var mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) < 0) low = mid + 1; else high = mid; } return low; } /// <summary> /// 指定した値以上の先頭のインデクスを返します。 /// </summary> /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="value">検索する値</param> /// <returns>指定した値以上の先頭のインデクス</returns> public static int LowerBound<T>(T[] arr, T value) where T : IComparable { return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default); } /// <summary> /// 指定した値より大きい先頭のインデクスを返します。 /// </summary> /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="start">開始インデクス [inclusive]</param> /// <param name="end">終了インデクス [exclusive]</param> /// <param name="value">検索する値</param> /// <param name="comparer">比較関数(インターフェイス)</param> /// <returns>指定した値より大きい先頭のインデクス</returns> public static int UpperBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; while (low < high) { var mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) <= 0) low = mid + 1; else high = mid; } return low; } /// <summary> /// 指定した値より大きい先頭のインデクスを返します。 /// </summary>Z /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="value">検索する値</param> /// <returns>指定した値より大きい先頭のインデクス</returns> public static int UpperBound<T>(T[] arr, T value) { return UpperBound(arr, 0, arr.Length, value, Comparer<T>.Default); } public static IEnumerable<TResult> SelectNotNull<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TResult> func) => source.Where(val => val != null).Select(func); public static IEnumerable<TSource> WhereNotNull<TSource>(this IEnumerable<TSource> source) => source.Where(val => val != null); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] ArrayOf<T>(params T[] arr) => arr; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<T> ListOf<T>(params T[] arr) => new List<T>(arr); public static IEnumerable<TResult> Repeat<TResult>(TResult value) { while (true) yield return value; // ReSharper disable once IteratorNeverReturns } public static IEnumerable<TResult> Repeat<TResult>(TResult value, int count) => Enumerable.Repeat(value, count); [SuppressMessage("ReSharper", "PossibleMultipleEnumeration")] public static IEnumerable<TResult> Repeat<TResult>(this IEnumerable<TResult> source, int count) { if (source == null) throw new ArgumentNullException(nameof(source)); if (count < 0) throw new ArgumentOutOfRangeException(nameof(count)); for (int i = 0; i < count; i++) foreach (var v in source) yield return v; } [SuppressMessage("ReSharper", "PossibleMultipleEnumeration")] public static IEnumerable<TResult> Repeat<TResult>(this IEnumerable<TResult> source) { if (source == null) throw new ArgumentNullException(nameof(source)); while (true) foreach (var v in source) yield return v; } /// <summary> /// 文字の配列を文字列に変換します。 /// </summary> /// <param name="source">文字の配列</param> /// <returns>変換した文字列</returns> public static string AsString(this IEnumerable<char> source) => new string(source.ToArray()); /// <summary> /// <see cref="source"/> の累積和を返します。 /// </summary> /// <returns><see cref="source"/> の累積和</returns> public static IEnumerable<long> CumSum(this IEnumerable<long> source) { long sum = 0; foreach (var item in source) yield return sum += item; } /// <summary> /// <see cref="source"/> の累積和を返します。 /// </summary> /// <returns><see cref="source"/> の累積和</returns> public static IEnumerable<int> CumSum(this IEnumerable<int> source) { int sum = 0; foreach (var item in source) yield return sum += item; } /// <summary> /// <see cref="value"/>が l以上 r未満の範囲に含まれているかを返します。 /// </summary> /// <typeparam name="T">要素の型</typeparam> /// <param name="value">判定する値</param> /// <param name="l">下限の値 (含まれる)</param> /// <param name="r">上限の値 (含まれない)</param> /// <returns><see cref="value"/> が指定した範囲に含まれているか</returns> public static bool IsIn<T>(this T value, T l, T r) where T : IComparable<T> { if (l.CompareTo(r) > 0) throw new ArgumentException(); return l.CompareTo(value) <= 0 && value.CompareTo(r) < 0; } /// <summary> /// <see cref="start"/> 以上 <see cref="end"/> 未満の値を <see cref="step"/> ずつ増やした結果を列挙します。 /// </summary> /// <param name="start">値の下限 (含まれる)</param> /// <param name="end">値の上限 (含まれない)</param> /// <param name="step">1要素ごとに増やす値</param> /// <returns>範囲の結果</returns> public static IEnumerable<int> Range(int start, int end, int step = 1) { for (var i = start; i < end; i += step) yield return i; } /// <summary> /// 0 以上 <see cref="end"/> 未満の値を 1 ずつ増やした結果を列挙します。 /// </summary> /// <param name="end">値の上限 (含まれない)</param> /// <returns>範囲の結果</returns> public static IEnumerable<int> Range(int end) => Range(0, end); /// <summary> /// <see cref="start"/> 以上 <see cref="end"/> 未満の値を <see cref="step"/> ずつ増やした結果を逆順に列挙します。 /// </summary> /// <param name="start">値の下限 (含まれる)</param> /// <param name="end">値の上限 (含まれない)</param> /// <param name="step">1要素ごとに増やす値</param> /// <returns>範囲の結果</returns> public static IEnumerable<int> RangeReverse(int start, int end, int step = 1) { for (var i = end - 1; i >= start; i -= step) yield return i; } /// <summary> /// 0 以上 <see cref="end"/> 未満の値を 1 ずつ増やした結果を逆順に列挙します。 /// </summary> /// <param name="end">値の上限 (含まれない)</param> /// <returns>範囲の結果</returns> public static IEnumerable<int> RangeReverse(int end) => RangeReverse(0, end); /// <summary> /// 指定した配列をコピーして昇順ソートします。(非破壊的) /// </summary> /// <typeparam name="T">ソートする配列の型</typeparam> /// <param name="arr">ソートする配列</param> /// <returns>ソートされた配列</returns> public static T[] Sort<T>(this T[] arr) { var array = new T[arr.Length]; arr.CopyTo(array, 0); Array.Sort(array); return array; } /// <summary> /// 指定した配列をコピーして降順ソートします。(非破壊的) /// </summary> /// <typeparam name="T">ソートする配列の型</typeparam> /// <param name="arr">ソートする配列</param> /// <returns>ソートされた配列</returns> public static T[] SortDescending<T>(this T[] arr) { var array = new T[arr.Length]; arr.CopyTo(array, 0); Array.Sort(array); Array.Reverse(array); return array; } public static double Log2(double x) => Log(x, 2); 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; } 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; } public static T Min<T>(params T[] col) => col.Min(); public static T Max<T>(params T[] col) => col.Max(); /// <summary> /// 要素数 (a, b) の、defaultValue で満たされたジャグ配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <param name="defaultValue">デフォルト値</param> /// <returns>指定した条件で初期化された配列</returns> public static T[][] JaggedArray2D<T>(int a, int b, T defaultValue = default(T)) { var ret = new T[a][]; for (int i = 0; i < a; i++) { ret[i] = Enumerable.Repeat(defaultValue, b).ToArray(); } return ret; } /// <summary> /// 要素数 (a, b) の,defaultValue で満たされた二次元配列を作成します。 /// </summary> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <param name="defaultValue">デフォルト値</param> /// <typeparam name="T">配列の型</typeparam> public static T[,] Array2D<T>(int a, int b, T defaultValue = default(T)) { var ret = new T[a, b]; for (int i = 0; i < a; i++) for (int j = 0; j < b; j++) ret[i, j] = defaultValue; return ret; } /// <summary> /// ジャグ配列を2次元配列に変換します。配列の各要素の長さがすべて同じである必要があります。 /// </summary> /// <param name="array">ジャグ配列</param> /// <typeparam name="T">二次元配列</typeparam> public static T[,] To2DArray<T>(this T[][] array) { if (!array.Any()) return new T[0, 0]; int len = array[0].Length; if (array.Any(x => x.Length != len)) throw new ArgumentException("array の各要素の長さが異なります。", nameof(array)); var ret = new T[array.Length, len]; for (int i = 0; i < array.Length; i++) { for (int j = 0; j < len; j++) { ret[i, j] = array[i][j]; } } return ret; } // public static vector<T> ToVector<T>(this IEnumerable<T> source) => new vector<T>(source); } public static class Input { private const char _separator = ' '; private static readonly Queue<string> _input = new Queue<string>(); private static readonly StreamReader sr = #if FILE new StreamReader("in.txt"); #else new StreamReader(Console.OpenStandardInput()); #endif public static string ReadLine => sr.ReadLine(); public static string ReadStr => Read; public static string Read { get { if (_input.Count != 0) return _input.Dequeue(); // ReSharper disable once PossibleNullReferenceException var tmp = sr.ReadLine().Split(_separator); foreach (var val in tmp) { _input.Enqueue(val); } return _input.Dequeue(); } } public static int ReadInt => int.Parse(Read); public static long ReadLong => long.Parse(Read); public static double ReadDouble => double.Parse(Read); public static string[] StrArray() => ReadLine.Split(' '); public static int[] IntArray() => ReadLine.Split(' ').Select(int.Parse).ToArray(); public static long[] LongArray() => ReadLine.Split(' ').Select(long.Parse).ToArray(); public static string[] StrArray(int n) { var ret = new string[n]; for (long i = 0; i < n; ++i) ret[i] = Read; return ret; } public static int[] IntArray(int n, int offset = 0, bool sorted = false) { var ret = StrArray(n).Select(x => int.Parse(x) + offset).ToArray(); if (sorted) Array.Sort(ret); return ret; } public static long[] LongArray(int n, long offset = 0, bool sorted = false) { var ret = StrArray(n).Select(x => long.Parse(x) + offset).ToArray(); if (sorted) Array.Sort(ret); return ret; } public static string[,] Str2DArray(int n, int m) { var ret = new string[n, m]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) ret[i, j] = ReadStr; return ret; } public static int[,] Int2DArray(int n, int m, int offset = 0) { var ret = new int[n, m]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) ret[i, j] = ReadInt + offset; return ret; } public static long[,] Long2DArray(int n, int m, long offset = 0) { var ret = new long[n, m]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) ret[i, j] = ReadLong + offset; return ret; } public static Tuple<string[], string[]> StrArrays2(int n) { var ret1 = new string[n]; var ret2 = new string[n]; for (int i = 0; i < n; i++) { ret1[i] = ReadStr; ret2[i] = ReadStr; } return Tuple.Create(ret1, ret2); } public static Tuple<int[], int[]> IntArrays2(int n, int offset1 = 0, int offset2 = 0) { var ret1 = new int[n]; var ret2 = new int[n]; for (int i = 0; i < n; i++) { ret1[i] = ReadInt + offset1; ret2[i] = ReadInt + offset2; } return Tuple.Create(ret1, ret2); } public static Tuple<long[], long[]> LongArrays2(int n, long offset1 = 0, long offset2 = 0) { var ret1 = new long[n]; var ret2 = new long[n]; for (int i = 0; i < n; i++) { ret1[i] = ReadLong + offset1; ret2[i] = ReadLong + offset2; } return Tuple.Create(ret1, ret2); } public static Tuple<string[], string[], string[]> StrArrays3(int n) { var ret1 = new string[n]; var ret2 = new string[n]; var ret3 = new string[n]; for (int i = 0; i < n; i++) { ret1[i] = ReadStr; ret2[i] = ReadStr; } return Tuple.Create(ret1, ret2, ret3); } public static Tuple<int[], int[], int[]> IntArrays3(int n, int offset1 = 0, int offset2 = 0, int offset3 = 0) { var ret1 = new int[n]; var ret2 = new int[n]; var ret3 = new int[n]; for (int i = 0; i < n; i++) { ret1[i] = ReadInt + offset1; ret2[i] = ReadInt + offset2; ret3[i] = ReadInt + offset3; } return Tuple.Create(ret1, ret2, ret3); } public static Tuple<long[], long[], long[]> LongArrays3(int n, long offset1 = 0, long offset2 = 0, long offset3 = 0) { var ret1 = new long[n]; var ret2 = new long[n]; var ret3 = new long[n]; for (int i = 0; i < n; i++) { ret1[i] = ReadLong + offset1; ret2[i] = ReadLong + offset2; ret3[i] = ReadLong + offset3; } return Tuple.Create(ret1, ret2, ret3); } private static bool TypeEquals<T, U>() => typeof(T) == typeof(U); private static T ChangeType<T, U>(U a) => (T) System.Convert.ChangeType(a, typeof(T)); private static T Convert<T>(string s) => TypeEquals<T, int>() ? ChangeType<T, int>(int.Parse(s)) : TypeEquals<T, long>() ? ChangeType<T, long>(long.Parse(s)) : TypeEquals<T, double>() ? ChangeType<T, double>(double.Parse(s)) : TypeEquals<T, char>() ? ChangeType<T, char>(s[0]) : ChangeType<T, string>(s); public static bool In<T>(out T a) { try { a = Convert<T>(Read); return true; } catch { a = default(T); return false; } } public static bool In<T, U>(out T a, out U b) { try { var ar = StrArray(2); a = Convert<T>(ar[0]); b = Convert<U>(ar[1]); return true; } catch { a = default(T); b = default(U); return false; } } public static bool In<T, U, V>(out T a, out U b, out V c) { try { var ar = StrArray(3); a = Convert<T>(ar[0]); b = Convert<U>(ar[1]); c = Convert<V>(ar[2]); return true; } catch { a = default(T); b = default(U); c = default(V); return false; } } public static bool In<T, U, V, W>(out T a, out U b, out V c, out W d) { try { var ar = StrArray(4); a = Convert<T>(ar[0]); b = Convert<U>(ar[1]); c = Convert<V>(ar[2]); d = Convert<W>(ar[3]); return true; } catch { a = default(T); b = default(U); c = default(V); d = default(W); return false; } } public static bool In<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { try { var ar = StrArray(5); a = Convert<T>(ar[0]); b = Convert<U>(ar[1]); c = Convert<V>(ar[2]); d = Convert<W>(ar[3]); e = Convert<X>(ar[4]); return true; } catch { a = default(T); b = default(U); c = default(V); d = default(W); e = default(X); return false; } } } public static class Output { public static void print<T>(T t) => Console.WriteLine(t); public static void print(params object[] o) => Console.WriteLine(o.Join(" ")); public static void PrintBool(bool val, string yes = "Yes", string no = "No") => Console.WriteLine(val ? yes : no); public static void PrintYn(bool val) => PrintBool(val); public static void PrintYN(bool val) => PrintBool(val, "YES", "NO"); public static void PrintPossible(bool val) => PrintBool(val, "Possible", "Impossible"); public static void PrintYay(bool val) => PrintBool(val, "Yay!", ":("); public static void PrintDebug(params object[] args) => Console.Error.WriteLine(string.Join(" ", args)); /// <summary> /// setter で設定された値を標準出力に出力します。 /// </summary> public static object cout { set { Console.WriteLine(value); } } /// <summary> /// Local環境のみ,setter で設定された値を標準出力に出力します。 /// </summary> public static object dout { set { #if LOCAL Console.WriteLine(value); #endif } } /// <summary> /// setter で設定された値を標準エラー出力に出力します。 /// </summary> public static object cerr { set { Console.Error.WriteLine(value); } } public const string endl = "\n"; } public class Program { public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false}; Console.SetOut(sw); new Solver().Main(); Console.Out.Flush(); Console.Read(); } } [DebuggerDisplay("({first}, {second})")] public class Pair<T1, T2> : IComparable<Pair<T1, T2>>, IEquatable<Pair<T1, T2>> where T1 : IComparable<T1> where T2 : IComparable<T2> { public Pair(T1 first, T2 second) { this.first = first; this.second = second; } public T1 first; public T2 second; public int CompareTo(Pair<T1, T2> other) { if (ReferenceEquals(this, other)) return 0; if (ReferenceEquals(null, other)) return 1; var firstComparison = first.CompareTo(other.first); return firstComparison != 0 ? firstComparison : second.CompareTo(other.second); } public override string ToString() => $"({first}, {second})"; public bool Equals(Pair<T1, T2> other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return EqualityComparer<T1>.Default.Equals(first, other.first) && EqualityComparer<T2>.Default.Equals(second, other.second); } public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; return obj.GetType() == GetType() && Equals((Pair<T1, T2>) obj); } public override int GetHashCode() { unchecked { return (EqualityComparer<T1>.Default.GetHashCode(first) * 397) ^ EqualityComparer<T2>.Default.GetHashCode(second); } } } #endregion }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 33], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 33], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 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], ["+", 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, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
5,464
23
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; public class Hello { static public int mod = 1000000007; public static void Main() { long[] num = longa(); long ab2 = num[0] * num[1] * 4; long cba = num[2] - num[1] - num[0]; cba = cba * cba; if (cba > ab2) { WriteLine("Yes"); } else { WriteLine("No"); } } static int ncr(int n, int r) { r = Min(r, n - r); long nn = 1; for (int i = n - r + 1; i <= n; i++) { nn = nn * i % mod; } long rr = 1; for (int i = 1; i <= r; i++) { rr = rr * i % mod; } rr = square((int)rr, mod - 2); nn = nn * rr % mod; return (int)nn; } // a^b mod static int square(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; } // static int square2(long a,long b,long m){var list = new List<int>();int // temp = 1;long n2 = a;list.Add(1);int count = 1;while(temp < // b){list.Add((int)n2);temp*=2;count++;n2 = n2*n2%m;}long ret = 1;while(b > // 0){if(temp <= b){b -= temp;ret = // ret*list[count]%1000000007;}count--;temp/=2;}return(int)ret;} 各種読取 static string rstr() { return ReadLine(); } static int rint() { return int.Parse(ReadLine()); } static long rlong() { return long.Parse(ReadLine()); } static string[] stra() { return ReadLine().Split(' '); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static int[,] inta2(int num_array, int in_array) { int[,] int_array2 = new int[num_array, in_array]; for (int i = 0; i < num_array; i++) { int[] temp_array = inta(); for (int j = 0; j < in_array; j++) { int_array2[i, j] = temp_array[j]; } } return int_array2; } static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; } static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_double_array; } // ----------------------------- static long divideup(long divided, long divid) { long temp_divide = divided / divid; if (divided % divid > 0) { temp_divide++; } return temp_divide; } static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; public class Hello { static public int mod = 1000000007; public static void Main() { long[] num = longa(); long ab2 = num[0] * num[1] * 4; long cba = num[2] - num[1] - num[0]; if (cba < 0) { WriteLine("No"); } else { cba = cba * cba; if (cba > ab2) { WriteLine("Yes"); } else { WriteLine("No"); } } } static int ncr(int n, int r) { r = Min(r, n - r); long nn = 1; for (int i = n - r + 1; i <= n; i++) { nn = nn * i % mod; } long rr = 1; for (int i = 1; i <= r; i++) { rr = rr * i % mod; } rr = square((int)rr, mod - 2); nn = nn * rr % mod; return (int)nn; } // a^b mod static int square(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; } // static int square2(long a,long b,long m){var list = new List<int>();int // temp = 1;long n2 = a;list.Add(1);int count = 1;while(temp < // b){list.Add((int)n2);temp*=2;count++;n2 = n2*n2%m;}long ret = 1;while(b > // 0){if(temp <= b){b -= temp;ret = // ret*list[count]%1000000007;}count--;temp/=2;}return(int)ret;} 各種読取 static string rstr() { return ReadLine(); } static int rint() { return int.Parse(ReadLine()); } static long rlong() { return long.Parse(ReadLine()); } static string[] stra() { return ReadLine().Split(' '); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static int[,] inta2(int num_array, int in_array) { int[,] int_array2 = new int[num_array, in_array]; for (int i = 0; i < num_array; i++) { int[] temp_array = inta(); for (int j = 0; j < in_array; j++) { int_array2[i, j] = temp_array[j]; } } return int_array2; } static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; } static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_double_array; } // ----------------------------- static long divideup(long divided, long divid) { long temp_divide = divided / divid; if (divided % divid > 0) { temp_divide++; } return temp_divide; } static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } }
[["+", 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, 18], ["+", 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], ["+", 0, 57, 64, 196, 0, 1, 0, 213, 63, 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, 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, 75, 196, 0, 46]]
8
844
18
using System; using System.Linq; using System.Text; using System.Collections.Generic; class Program { static void Main(string[] args) { //読み込む string[] line = Console.ReadLine().Split(' '); ulong a = ulong.Parse(line[0]); ulong b = ulong.Parse(line[1]); ulong c = ulong.Parse(line[2]); bool less = false; // root(4ab) < c - a - bとなれば良い ulong diff = c - a - b; if (diff > 0) { ulong left = 4 * a * b; ulong right = diff * diff; if (left < right) { less = true; } } if (less) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } }
using System; using System.Linq; using System.Text; using System.Collections.Generic; class Program { static void Main(string[] args) { //読み込む string[] line = Console.ReadLine().Split(' '); long a = long.Parse(line[0]); long b = long.Parse(line[1]); long c = long.Parse(line[2]); bool less = false; // root(4ab) < c - a - bとなれば良い long diff = c - a - b; if (diff > 0) { long left = 4 * a * b; long right = diff * diff; if (left < right) { less = true; } } if (less) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } }
[["-", 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], ["-", 0, 57, 64, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 57, 64, 196, 0, 197, 0, 198, 39, 199]]
8
171
18
using System; class Program { static void Main() { var lines = Console.ReadLine().Split(' '); var H = long.Parse(lines[0]); var M = long.Parse(lines[1]); var L = long.Parse(lines[2]); var N = (L - H - M) * (L - H - M) - 4 * H * M; if (N > 0) Console.WriteLine("Yes"); else Console.WriteLine("No"); } }
using System; class Program { static void Main() { var lines = Console.ReadLine().Split(' '); var H = long.Parse(lines[0]); var M = long.Parse(lines[1]); var L = long.Parse(lines[2]); if (L - H - M < 0) Console.WriteLine("No"); else { var N = (L - H - M) * (L - H - M) - 4 * H * M; if (N > 0) 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, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 33], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 33], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 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], ["+", 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, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
119
22
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(' '); var a = long.Parse(input[0]); var b = long.Parse(input[1]); var c = long.Parse(input[2]); if (4 * a * b < (c - a - b) * (c - a - b)) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } Console.ReadLine(); } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(' '); var a = long.Parse(input[0]); var b = long.Parse(input[1]); var c = long.Parse(input[2]); if (c - a - b > 0) { if (4 * a * b < (c - a - b) * (c - a - b)) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } else { Console.WriteLine("No"); } } }
[["+", 0, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 33], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 33], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 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], ["+", 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, 75, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
143
20