buggy_code
stringlengths
11
625k
fixed_code
stringlengths
17
625k
bug_type
stringlengths
2
4.45k
language
int64
0
8
token_count
int64
5
200k
change_count
int64
0
100
using System; using System.Collections.Generic; using System.Linq; using System.Numerics; class Program { static void MakeDepth(int[] depth, int index, int dtemp, List<int>[] children, int maxDepth) { // depth[index] = dtemp; // foreach(int i in children[index]) // { // MakeDepth(depth, i, dtemp + 1, children); // } var que = new Queue<int>(); que.Enqueue(index); int count = dtemp; while (que.Any() && maxDepth >= count) { int queCount = que.Count; foreach (int i in Enumerable.Range(0, queCount)) { int p = que.Dequeue(); depth[p] = count; foreach (int child in children[p]) que.Enqueue(child); } count++; } } static int GetParent(int[] parents, int index, int depth) { // if(depth == 0) // return index; // return GetParent(parents, parents[index], depth - 1); while (depth > 0) { index = parents[index]; depth--; } return index; } public void Slove() { var inputs = Console.ReadLine().Split(); int n = int.Parse(inputs[0]); int k = int.Parse(inputs[1]); var children = Enumerable.Range(0, n).Select(x => new List<int>()).ToArray(); var parents = Console.ReadLine().Split().Select(x => int.Parse(x) - 1).ToArray(); int result = 0; if (parents[0] != 0) { parents[0] = 0; result++; } foreach (var item in parents.Select((x, i) => new { Parent = x, Child = i }) .Skip(1)) { children[item.Parent].Add(item.Child); } int[] depth = new int[n]; MakeDepth(depth, 0, 0, children, n); foreach (int i in Enumerable.Range(0, n).OrderByDescending(x => depth[x])) { if (depth[i] > k) { int parent = GetParent(parents, i, k - 1); MakeDepth(depth, parent, 1, children, k - 1); result++; } } System.Console.WriteLine(result); } static void Main(string[] args) { new Program().Slove(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Numerics; class Program { static void MakeDepth(int[] depth, int index, int dtemp, List<int>[] children, int maxDepth) { // depth[index] = dtemp; // foreach(int i in children[index]) // { // MakeDepth(depth, i, dtemp + 1, children); // } var que = new Queue<int>(); que.Enqueue(index); int count = dtemp; while (que.Any() && maxDepth >= count) { int queCount = que.Count; foreach (int i in Enumerable.Range(0, queCount)) { int p = que.Dequeue(); depth[p] = count; foreach (int child in children[p]) que.Enqueue(child); } count++; } } static int GetParent(int[] parents, int index, int depth) { // if(depth == 0) // return index; // return GetParent(parents, parents[index], depth - 1); while (depth > 0) { index = parents[index]; depth--; } return index; } public void Slove() { var inputs = Console.ReadLine().Split(); int n = int.Parse(inputs[0]); int k = int.Parse(inputs[1]); var children = Enumerable.Range(0, n).Select(x => new List<int>()).ToArray(); var parents = Console.ReadLine().Split().Select(x => int.Parse(x) - 1).ToArray(); int result = 0; if (parents[0] != 0) { parents[0] = 0; result++; } foreach (var item in parents.Select((x, i) => new { Parent = x, Child = i }) .Skip(1)) { children[item.Parent].Add(item.Child); } int[] depth = new int[n]; MakeDepth(depth, 0, 0, children, n); foreach (int i in Enumerable.Range(0, n).OrderByDescending(x => depth[x])) { if (depth[i] > k) { int parent = GetParent(parents, i, k - 1); MakeDepth(depth, parent, 1, children, k); result++; } } System.Console.WriteLine(result); } static void Main(string[] args) { new Program().Slove(); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
496
2
using System; using static System.Console; class main { public static void Main() { int n = int.Parse(ReadLine()); int k = int.Parse(ReadLine()); int x = int.Parse(ReadLine()); int y = int.Parse(ReadLine()); int sum = 0; sum += k * x; if (n > k) { sum += (n - k) * y; } WriteLine(sum); } }
using System; using static System.Console; class main { public static void Main() { int n = int.Parse(ReadLine()); int k = int.Parse(ReadLine()); int x = int.Parse(ReadLine()); int y = int.Parse(ReadLine()); int sum = 0; sum += n * x; if (n > k) { sum -= (n - k) * (x - y); } WriteLine(sum); } }
[["-", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 24], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 31, 22], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 17, 33], ["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 25]]
8
103
8
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC044A { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int K = int.Parse(Console.ReadLine()); int X = int.Parse(Console.ReadLine()); int Y = int.Parse(Console.ReadLine()); if (N <= K) Console.WriteLine(K * X + (N - K) * Y); else Console.WriteLine(N * X); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC044A { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int K = int.Parse(Console.ReadLine()); int X = int.Parse(Console.ReadLine()); int Y = int.Parse(Console.ReadLine()); if (N >= K) Console.WriteLine(K * X + (N - K) * Y); else Console.WriteLine(N * X); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20]]
8
135
2
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; class Program { static void Main() { //入力 // int[] input = Console.ReadLine().Split().Select(i => // int.Parse(i)).ToArray(); string[] input = // Console.ReadLine().Split().Select(i => i).ToArray(); string input= // Console.ReadLine(); int[] input = new int[4]; for (int a = 0; a < input.Length; a++) { input[a] = int.Parse(Console.ReadLine()); } Console.WriteLine(input[0] < input[1] ? input[2] * input[0] : input[2] + (input[0] - input[1]) * input[3]); /* //処理速度計測 var sw = new System.Diagnostics.Stopwatch(); sw.Start(); //解法 //処理速度表示 sw.Stop(); TimeSpan ts = sw.Elapsed; Console.WriteLine((int)(Math.Floor((ts).TotalMilliseconds))+"ms"); */ Console.ReadLine(); } }
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; class Program { static void Main() { //入力 // int[] input = Console.ReadLine().Split().Select(i => // int.Parse(i)).ToArray(); string[] input = // Console.ReadLine().Split().Select(i => i).ToArray(); string input= // Console.ReadLine(); int[] input = new int[4]; for (int a = 0; a < input.Length; a++) { input[a] = int.Parse(Console.ReadLine()); } Console.WriteLine(input[0] < input[1] ? input[2] * input[0] : input[2] * input[1] + (input[0] - input[1]) * input[3]); /* //処理速度計測 var sw = new System.Diagnostics.Stopwatch(); sw.Start(); //解法 //処理速度表示 sw.Stop(); TimeSpan ts = sw.Elapsed; Console.WriteLine((int)(Math.Floor((ts).TotalMilliseconds))+"ms"); */ Console.ReadLine(); } }
[["+", 0, 28, 0, 41, 75, 16, 31, 16, 17, 48], ["+", 0, 41, 75, 16, 31, 16, 12, 204, 205, 22], ["+", 75, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["+", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 75, 16, 31, 16, 12, 204, 206, 207, 0, 73]]
8
141
5
using System; using System.Linq; namespace practice6 { class MainClass { public static void Main(string[] args) { int N = Int32.Parse(Console.ReadLine()); int K = Int32.Parse(Console.ReadLine()); int X = Int32.Parse(Console.ReadLine()); int Y = Int32.Parse(Console.ReadLine()); int x; if (N > X) x = K * X + (N - K) * Y; else x = N * X; Console.WriteLine(x.ToString()); } } }
using System; using System.Linq; namespace practice6 { class MainClass { public static void Main(string[] args) { int N = Int32.Parse(Console.ReadLine()); int K = Int32.Parse(Console.ReadLine()); int X = Int32.Parse(Console.ReadLine()); int Y = Int32.Parse(Console.ReadLine()); int x; if (N > K) x = K * X + (N - K) * Y; else x = N * X; Console.WriteLine(x.ToString()); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22]]
8
125
2
using System; namespace a { public class buri { public static void Main() { int n = int.Parse(Console.ReadLine()), k = int.Parse(Console.ReadLine()), x = int.Parse(Console.ReadLine()), y = int.Parse(Console.ReadLine()); if (k <= n) { Console.WriteLine(k * x + (n - k) * y); } else { Console.WriteLine(k * x); } } } }
using System; namespace a { public class buri { public static void Main() { int n = int.Parse(Console.ReadLine()), k = int.Parse(Console.ReadLine()), x = int.Parse(Console.ReadLine()), y = int.Parse(Console.ReadLine()); if (k <= n) { Console.WriteLine(k * x + (n - k) * y); } else { Console.WriteLine(n * x); } } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22]]
8
110
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class _C { void _() { // var N = _Ns()[0]; var K = _Ns()[0]; var X = _Ns()[0]; var Y = _Ns()[0]; var ans = N * X; if (N - K > 1) ans -= ((N - K) * (X - Y)); Console.WriteLine(ans); } static void Main(string[] args) { new _C()._(); } #region string _S() { return Console.ReadLine(); } string[] _Ss() { return Console.ReadLine().Split(); } int[] _N(int n) { var x = new int[n]; for (var i = 0; i < n; i++) { x[i] = int.Parse(Console.ReadLine()); } return x; } int[] _Ns() { var ss = Console.ReadLine().Split(); var x = new int[ss.Length]; for (var i = 0; i < ss.Length; i++) x[i] = int.Parse(ss[i]); return x; } #endregion }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class _C { void _() { // var N = _Ns()[0]; var K = _Ns()[0]; var X = _Ns()[0]; var Y = _Ns()[0]; var ans = N * X; if (N - K >= 1) ans -= ((N - K) * (X - Y)); Console.WriteLine(ans); } static void Main(string[] args) { new _C()._(); } #region string _S() { return Console.ReadLine(); } string[] _Ss() { return Console.ReadLine().Split(); } int[] _N(int n) { var x = new int[n]; for (var i = 0; i < n; i++) { x[i] = int.Parse(Console.ReadLine()); } return x; } int[] _Ns() { var ss = Console.ReadLine().Split(); var x = new int[ss.Length]; for (var i = 0; i < ss.Length; i++) x[i] = int.Parse(ss[i]); return x; } #endregion }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20]]
8
292
2
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using static System.Console; using static System.Math; namespace Atcoder { class Program { static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; static void Main(string[] args) { try { SetOut(sw); Solve.Answer(); Out.Flush(); } catch (Exception ex) { WriteLine(ex.ToString()); } } } public class Solve { public static void Answer() { var s = ReadLine(); var dic = new Dictionary<char, int>(); for (int i = 0; i < s.Length; i++) { if (!dic.ContainsKey(s[i])) { dic.Add(s[i], 1); } else { dic[s[i]]++; } } var l = dic.Select(x => x.Value).Where(x => x % 2 == 1).ToList(); IO.WriteLineYes_or_No(l.Count > 0); } public class IO { #region Input public static string ReadString => ReadLine(); public static int ReadInt => int.Parse(ReadLine()); public static long ReadLong => long.Parse(ReadLine()); public static double ReadDouble => double.Parse(ReadLine()); public static List<string> ReadSplitString => ReadLine().Split().ToList(); public static List<int> ReadSplitInt => ReadLine().Split().Select(s => int.Parse(s)).ToList(); public static List<long> ReadSplitLong => ReadLine().Split().Select(s => long.Parse(s)).ToList(); public static List<double> ReadSplitdouble => ReadLine().Split().Select(s => double.Parse(s)).ToList(); #endregion #region Output public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list)); public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No"); #endregion } public class Mod { #region private readonly static long M = 1000000007; public static long Add(long a, long b) => (a * b) % M; public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M; public static long Multi(long a, long b) => (a * b) % M; #endregion } public static int GCD(int x, int y) { if (x < y) Swap(ref x, ref y); if (y == 0) return x; else return GCD(x % y, y); } public static void Swap(ref int x, ref int y) { int tmp = x; x = y; y = tmp; } public static long Choice2(long n) { #region if (n <= 1) return 0; if (n == 2) return 1; else return n * (n - 1) / 2; #endregion } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using static System.Console; using static System.Math; namespace Atcoder { class Program { static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; static void Main(string[] args) { try { SetOut(sw); Solve.Answer(); Out.Flush(); } catch (Exception ex) { WriteLine(ex.ToString()); } } } public class Solve { public static void Answer() { var s = ReadLine(); var dic = new Dictionary<char, int>(); for (int i = 0; i < s.Length; i++) { if (!dic.ContainsKey(s[i])) { dic.Add(s[i], 1); } else { dic[s[i]]++; } } var l = dic.Select(x => x.Value).Where(x => x % 2 == 1).ToList(); IO.WriteLineYes_or_No(l.Count == 0); } public class IO { #region Input public static string ReadString => ReadLine(); public static int ReadInt => int.Parse(ReadLine()); public static long ReadLong => long.Parse(ReadLine()); public static double ReadDouble => double.Parse(ReadLine()); public static List<string> ReadSplitString => ReadLine().Split().ToList(); public static List<int> ReadSplitInt => ReadLine().Split().Select(s => int.Parse(s)).ToList(); public static List<long> ReadSplitLong => ReadLine().Split().Select(s => long.Parse(s)).ToList(); public static List<double> ReadSplitdouble => ReadLine().Split().Select(s => double.Parse(s)).ToList(); #endregion #region Output public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list)); public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No"); #endregion } public class Mod { #region private readonly static long M = 1000000007; public static long Add(long a, long b) => (a * b) % M; public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M; public static long Multi(long a, long b) => (a * b) % M; #endregion } public static int GCD(int x, int y) { if (x < y) Swap(ref x, ref y); if (y == 0) return x; else return GCD(x % y, y); } public static void Swap(ref int x, ref int y) { int tmp = x; x = y; y = tmp; } public static long Choice2(long n) { #region if (n <= 1) return 0; if (n == 2) return 1; else return n * (n - 1) / 2; #endregion } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 47], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 60]]
8
696
2
using System; using System.Collections.Generic; using System.Linq; namespace ABC099 { class Program { static void Main(string[] args) { List<string> list = new List<string>(); while (true) { string line = Console.ReadLine(); if (line == null) break; list.Add(line); } var ss = list[0].ToCharArray(); var sss = ss.OrderBy(z => z); Boolean b = true; foreach (var item in sss) { if (sss.Where(x => x == item).Count() % 2 == 0) { b = true; } else { b = false; } } if (b == true) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
using System; using System.Collections.Generic; using System.Linq; namespace ABC099 { class Program { static void Main(string[] args) { List<string> list = new List<string>(); while (true) { string line = Console.ReadLine(); if (line == null) break; list.Add(line); } var ss = list[0].ToCharArray(); var sss = ss.OrderBy(z => z); Boolean b = true; foreach (var item in sss) { if (sss.Where(x => x == item).Count() % 2 == 0) { b = true; } else { b = false; break; } } if (b == true) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
[["+", 8, 196, 0, 57, 75, 196, 0, 93, 0, 94], ["+", 8, 196, 0, 57, 75, 196, 0, 93, 0, 35]]
8
179
2
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Globalization; using System.Diagnostics; class Myon { public Myon() {} public static int Main() { new Myon().calc(); return 0; } Scanner cin; void calc() { cin = new Scanner(); string S = cin.next(); char[] cs = S.ToCharArray(); if (S.Length % 2 == 1) { Console.WriteLine("No"); return; } Array.Sort(cs); for (int i = 0; i < S.Length; i += 2) { if (S[i] != S[i + 1]) { Console.WriteLine("No"); return; } } Console.WriteLine("Yes"); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Globalization; using System.Diagnostics; class Myon { public Myon() {} public static int Main() { new Myon().calc(); return 0; } Scanner cin; void calc() { cin = new Scanner(); string S = cin.next(); char[] cs = S.ToCharArray(); if (S.Length % 2 == 1) { Console.WriteLine("No"); return; } Array.Sort(cs); for (int i = 0; i < S.Length; i += 2) { if (cs[i] != cs[i + 1]) { Console.WriteLine("No"); return; } } Console.WriteLine("Yes"); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } }
[["-", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 204, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 204, 205, 22]]
8
541
4
using System; using System.Linq; namespace AtCoder20170211 { class Program { static void Main(string[] args) { // QuestionOne(); QuestionTwo(); } static void QuestionOne() { decimal n = Convert.ToDecimal(Console.ReadLine()); decimal k = Convert.ToDecimal(Console.ReadLine()); decimal x = Convert.ToDecimal(Console.ReadLine()); decimal y = Convert.ToDecimal(Console.ReadLine()); decimal result = 0; if (n > k) { result = k * x; result += (n - k) * y; } else { result = n * x; } Console.WriteLine(result); } static void QuestionTwo() { var w = Console.ReadLine(); for (var i = 'a'; i <= 'z'; i++) { var count = w.Select(c => c == i).Count(); if (count % 2 != 0) { Console.WriteLine("No"); return; } } Console.WriteLine("Yes"); } } }
using System; using System.Linq; namespace AtCoder20170211 { class Program { static void Main(string[] args) { // QuestionOne(); QuestionTwo(); } static void QuestionOne() { decimal n = Convert.ToDecimal(Console.ReadLine()); decimal k = Convert.ToDecimal(Console.ReadLine()); decimal x = Convert.ToDecimal(Console.ReadLine()); decimal y = Convert.ToDecimal(Console.ReadLine()); decimal result = 0; if (n > k) { result = k * x; result += (n - k) * y; } else { result = n * x; } Console.WriteLine(result); } static void QuestionTwo() { var w = Console.ReadLine(); for (var i = 'a'; i <= 'z'; i++) { var count = w.Where(c => c == i).Count(); if (count % 2 != 0) { Console.WriteLine("No"); return; } } Console.WriteLine("Yes"); } } }
[["-", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22]]
8
224
2
using System; using System.Collections.Generic; using System.Linq; namespace ABC044_C { class Program { static void Main() { var array = Utility.ReadIntArray(); var N = array[0]; var A = array[1]; var X = Utility.ReadIntArray(); var dp = new long[N + 1, N + 1, (N + 1) * A]; dp[0, 0, 0] = 1; for (var i = 0; i < N; i++) { for (var j = 0; j < N; j++) { for (var k = 0; k < dp.GetLength(2); k++) { if (dp[i, j, k] != 0) { dp[i + 1, j, k] += dp[i, j, k]; dp[i + 1, j + 1, k + X[i]] += dp[i, j, k]; } } } } long ans = 0; for (var i = 1; i <= N; i++) { ans += dp[N, i, i * A]; } Console.WriteLine($"{ans}"); } } public static class Utility { public static string ReadString() => Console.ReadLine(); public static string[] ReadStringArray() => ReadString().Split(' '); public static int ReadInt() => int.Parse(ReadString()); public static int[] ReadIntArray() => ReadStringArray().ParseInt().ToArray(); public static IEnumerable<int> ParseInt(this IEnumerable<string> source) => source.Select(v => int.Parse(v)); } }
using System; using System.Collections.Generic; using System.Linq; namespace ABC044_C { class Program { static void Main() { var array = Utility.ReadIntArray(); var N = array[0]; var A = array[1]; var X = Utility.ReadIntArray(); var dp = new long[N + 1, N + 1, (N + 1) * 50]; dp[0, 0, 0] = 1; for (var i = 0; i < N; i++) { for (var j = 0; j < N; j++) { for (var k = 0; k < dp.GetLength(2); k++) { if (dp[i, j, k] != 0) { dp[i + 1, j, k] += dp[i, j, k]; dp[i + 1, j + 1, k + X[i]] += dp[i, j, k]; } } } } long ans = 0; for (var i = 1; i <= N; i++) { ans += dp[N, i, i * A]; } Console.WriteLine($"{ans}"); } } public static class Utility { public static string ReadString() => Console.ReadLine(); public static string[] ReadStringArray() => ReadString().Split(' '); public static int ReadInt() => int.Parse(ReadString()); public static int[] ReadIntArray() => ReadStringArray().ParseInt().ToArray(); public static IEnumerable<int> ParseInt(this IEnumerable<string> source) => source.Select(v => int.Parse(v)); } }
[["-", 0, 227, 39, 224, 225, 226, 0, 16, 12, 22], ["+", 0, 227, 39, 224, 225, 226, 0, 16, 12, 203]]
8
364
2
using System; using System.Linq; namespace ABC044_C_TakAndCards { /// <summary> /// 復習 /// </summary> public static class ABC044_C_Review { static void Main(string[] args) { string[] split = Console.ReadLine().Split(' '); int N = int.Parse(split[0]); int A = int.Parse(split[1]); int[] X = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); // 場合の数[選んだ枚数, 合計]のDP表 int S = X.Sum(); ulong[,] dp = new ulong[N + 1, S + 1]; dp[0, 0] = 1; foreach (int x in X) { for (int i = N; i >= 0; i--) { for (int j = S; j >= 0; j--) { if (dp[i, j] == 0) { continue; } dp[i + 1, j + x] += dp[i, j]; } } } ulong answerCount = 0; for (int i = 1; i <= N; i++) { for (int j = 0; j <= S; j++) { if (S == A * j) { answerCount += dp[i, j]; } } } Console.WriteLine(answerCount); } } }
using System; using System.Linq; namespace ABC044_C_TakAndCards { /// <summary> /// 復習 /// </summary> public static class ABC044_C_Review { static void Main(string[] args) { string[] split = Console.ReadLine().Split(' '); int N = int.Parse(split[0]); int A = int.Parse(split[1]); int[] X = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); // 場合の数[選んだ枚数, 合計]のDP表 int S = X.Sum(); ulong[,] dp = new ulong[N + 1, S + 1]; dp[0, 0] = 1; foreach (int x in X) { for (int i = N; i >= 0; i--) { for (int j = S; j >= 0; j--) { if (dp[i, j] == 0) { continue; } dp[i + 1, j + x] += dp[i, j]; } } } ulong answerCount = 0; for (int i = 1; i <= N; i++) { for (int j = 0; j <= S; j++) { if (j == A * i) { answerCount += dp[i, j]; } } } Console.WriteLine(answerCount); } } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22]]
8
284
4
using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Text; using System.Text.RegularExpressions; using System.Linq; public class AtCoder { static long n, s; static void Main() { n = long.Parse(Console.ReadLine()); s = long.Parse(Console.ReadLine()); if (s == n) { Console.WriteLine(n + 1); return; } int rootn = (int)Math.Sqrt(n); for (int b = 1; b < rootn; b++) { if (b >= 2) { if (function(b, n) == s) { Console.WriteLine(b); return; } } } for (int p = rootn; p >= 1; p--) { int b = (int)(((n - s) / p) + 1); if (b < 2) { continue; } if (function(b, n) == s) { Console.WriteLine(b); return; } } Console.WriteLine(-1); } static long function(long b, long n) { if (n < b) { return n; } return function(b, n / b) + n % b; } }
using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Text; using System.Text.RegularExpressions; using System.Linq; public class AtCoder { static long n, s; static void Main() { n = long.Parse(Console.ReadLine()); s = long.Parse(Console.ReadLine()); if (s == n) { Console.WriteLine(n + 1); return; } int rootn = (int)Math.Sqrt(n); for (int b = 1; b < rootn; b++) { if (b >= 2) { if (function(b, n) == s) { Console.WriteLine(b); return; } } } for (int p = rootn; p >= 1; p--) { long b = (long)(((n - s) / p) + 1); if (b < 2) { continue; } if (function(b, n) == s) { Console.WriteLine(b); return; } } Console.WriteLine(-1); } static long function(long b, long n) { if (n < b) { return n; } return function(b, n / b) + n % b; } }
[["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199]]
8
274
4
using System; using System.Linq; using System.Collections.Generic; using System.Text; using static System.Console; using static System.Math; class Program { static void Main(string[] args) { int[] NA = ReadLineParseIntArray(); long N = NA[0]; long A = NA[1]; long[] X = ReadLine().Split(' ').Select(x => int.Parse(x) - A).ToArray(); long max = X.Max(); long[] dp = new long[2 * max * N + 1]; dp[N * max] = 1; for (int i = 0; i < N; i++) { long first = Max(0, X[i]); long last = Min(dp.Length, dp.Length + X[i]); if (X[i] <= 0) for (long t = first; t < last; t++) dp[t] += dp[t - X[i]]; else for (long t = last - 1; t >= first; t--) dp[t] += dp[t - X[i]]; } WriteLine(dp[N * max] - 1); } static int ReadLineParseInt() => int.Parse(ReadLine()); static int[] ReadLineParseIntArray() => ReadLine().Split(' ').Select(int.Parse).ToArray(); }
using System; using System.Linq; using System.Collections.Generic; using System.Text; using static System.Console; using static System.Math; class Program { static void Main(string[] args) { int[] NA = ReadLineParseIntArray(); long N = NA[0]; long A = NA[1]; long[] X = ReadLine().Split(' ').Select(x => int.Parse(x) - A).ToArray(); long max = Abs(X.Max()); long[] dp = new long[2 * max * N + 1]; dp[N * max] = 1; for (int i = 0; i < N; i++) { long first = Max(0, X[i]); long last = Min(dp.Length, dp.Length + X[i]); if (X[i] <= 0) for (long t = first; t < last; t++) dp[t] += dp[t - X[i]]; else for (long t = last - 1; t >= first; t--) dp[t] += dp[t - X[i]]; } WriteLine(dp[N * max] - 1); } static int ReadLineParseInt() => int.Parse(ReadLine()); static int[] ReadLineParseIntArray() => ReadLine().Split(' ').Select(int.Parse).ToArray(); }
[["+", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
316
3
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; class TEST { static void Main() { Sol mySol = new Sol(); mySol.Solve(); } } class Sol { public void Solve() { var B = (int[])A.Clone(); Array.Sort(B); HashSet<int> H = new HashSet<int>(); for (int i = 0; i < N; i += 2) H.Add(B[i]); int cnt = 0; for (int i = 0; i < N; i += 2) if (H.Contains(A[i])) cnt++; Console.WriteLine(cnt); } int N; int[] A; public Sol() { N = ri(); A = new int[N]; for (int i = 0; i < N; i++) A[i] = ri(); } static String rs() { return Console.ReadLine(); } static int ri() { return int.Parse(Console.ReadLine()); } static long rl() { return long.Parse(Console.ReadLine()); } static double rd() { return double.Parse(Console.ReadLine()); } static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); } static int[] ria(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); } static long[] rla(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); } static double[] rda(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; class TEST { static void Main() { Sol mySol = new Sol(); mySol.Solve(); } } class Sol { public void Solve() { var B = (int[])A.Clone(); Array.Sort(B); HashSet<int> H = new HashSet<int>(); for (int i = 0; i < N; i += 2) H.Add(B[i]); int cnt = 0; for (int i = 0; i < N; i += 2) if (!H.Contains(A[i])) cnt++; Console.WriteLine(cnt); } int N; int[] A; public Sol() { N = ri(); A = new int[N]; for (int i = 0; i < N; i++) A[i] = ri(); } static String rs() { return Console.ReadLine(); } static int ri() { return int.Parse(Console.ReadLine()); } static long rl() { return long.Parse(Console.ReadLine()); } static double rd() { return double.Parse(Console.ReadLine()); } static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); } static int[] ria(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); } static long[] rla(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); } static double[] rda(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); } }
[["+", 8, 196, 0, 7, 8, 57, 15, 241, 0, 111]]
8
435
1
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Text; using System.Linq; using E = System.Linq.Enumerable; internal partial class Solver { public void Run() { var s = ns(); int from = -1, to = -1; foreach (var d in new[] { 1, 2 }) { for (int i = 0; i + d < s.Length; i++) { if (s[i] == s[i + d]) { from = i; to = i + d; break; } } } cout.WriteLine("{0} {1}", from, to); } } public struct ModInt : IEquatable<ModInt> { private static int mod = 0; private long _value; public ModInt(long x) { _value = x; Normalize(); } private static long RegularMod(long x, int mod) { if (x >= mod) { if (x < 2 * mod) { return x - mod; } return x % mod; } if (x >= 0) { return x; } x = mod - RegularMod(-x, mod); if (x == mod) { return 0; } return x; } public static int SetModValue(int m) { return mod = m; } private void Normalize() { _value = RegularMod(_value, mod); } public override string ToString() { return _value.ToString(CultureInfo.InvariantCulture); } public int ToInt() { return (int)_value; } public static bool operator ==(ModInt c1, ModInt c2) { return c1._value == c2._value; } public static bool operator !=(ModInt c1, ModInt c2) { return !(c1 == c2); } public static ModInt operator +(ModInt x, ModInt y) { return new ModInt(x._value + y._value); } public static ModInt operator -(ModInt x, ModInt y) { return new ModInt(x._value - y._value); } public static ModInt operator -(ModInt x) { return new ModInt(-x._value); } public static ModInt operator *(ModInt x, ModInt y) { return new ModInt(x._value * y._value); } public static ModInt operator /(ModInt x, ModInt y) { return new ModInt(x._value * Inverse(y._value, mod)); } public static ModInt operator ++(ModInt x) { return x + 1; } public static ModInt operator --(ModInt x) { return x - 1; } public static ModInt Pow(ModInt x, long n) { ModInt r = 1; while (n > 0) { if ((n & 1) != 0) { r *= x; } x *= x; n >>= 1; } return r; } private static long ExtendedGcd(long a, long b, ref long x, ref long y) { if (b == 0) { x = 1; y = 0; return a; } else { var d = ExtendedGcd(b, a % b, ref y, ref x); y -= a / b * x; return d; } } private static long Inverse(long a, long mod) { long x = 0, y = 0; if (ExtendedGcd(a, mod, ref x, ref y) == 1) { return (x + mod) % mod; } else { throw new Exception("Invalid inverse " + a + " " + mod); } } public static implicit operator ModInt(long x) { return new ModInt(x); } public override bool Equals(object obj) { if (obj == null) { return false; } return _value.Equals(((ModInt)obj)._value); } public override int GetHashCode() { return _value.GetHashCode(); } public bool Equals(ModInt other) { return _value.Equals(other._value); } } // PREWRITEN CODE BEGINS FROM HERE static public class StringExtensions { static public string JoinToString<T>(this IEnumerable<T> source, string separator = " ") { return string.Join(separator, source); } } internal partial class Solver : Scanner { public static void Main() { #if LOCAL byte[] inputBuffer = new byte[1000000]; var inputStream = Console.OpenStandardInput(inputBuffer.Length); using (var reader = new StreamReader(inputStream, Console.InputEncoding, false, inputBuffer.Length)) { Console.SetIn(reader); new Solver(Console.In, Console.Out).Run(); } #else Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new Solver(Console.In, Console.Out).Run(); Console.Out.Flush(); #endif } #pragma warning disable IDE0052 private readonly TextReader cin; private readonly TextWriter cout; private readonly TextWriter cerr; #pragma warning restore IDE0052 public Solver(TextReader reader, TextWriter writer) : base(reader) { cin = reader; cout = writer; cerr = Console.Error; } public Solver(string input, TextWriter writer) : this(new StringReader(input), writer) {} #pragma warning disable IDE1006 #pragma warning disable IDE0051 private int ni() { return NextInt(); } private int[] ni(int n) { return NextIntArray(n); } private long nl() { return NextLong(); } private long[] nl(int n) { return NextLongArray(n); } private double nd() { return NextDouble(); } private double[] nd(int n) { return NextDoubleArray(n); } private string ns() { return Next(); } private string[] ns(int n) { return NextArray(n); } #pragma warning restore IDE1006 #pragma warning restore IDE0051 } #if DEBUG internal static class LinqPadExtension { public static string TextDump<T>(this T obj) { if (obj is IEnumerable) return (obj as IEnumerable).Cast<object>().JoinToString().Dump(); else return obj.ToString().Dump(); } public static T Dump<T>(this T obj) { return LINQPad.Extensions.Dump(obj); } } #endif public class Scanner { private readonly TextReader Reader; private readonly CultureInfo ci = CultureInfo.InvariantCulture; private readonly char[] buffer = new char[2 * 1024]; private int cursor = 0, length = 0; private string Token; private readonly StringBuilder sb = new StringBuilder(1024); public Scanner() : this(Console.In) {} public Scanner(TextReader reader) { Reader = reader; } public int NextInt() { return checked((int)NextLong()); } public long NextLong() { var s = Next(); long r = 0; int i = 0; bool negative = false; if (s[i] == '-') { negative = true; i++; } for (; i < s.Length; i++) { r = r * 10 + (s[i] - '0'); #if DEBUG if (!char.IsDigit(s[i])) throw new FormatException(); #endif } return negative ? -r : r; } public double NextDouble() { return double.Parse(Next(), ci); } public string[] NextArray(int size) { string[] array = new string[size]; for (int i = 0; i < size; i++) { array[i] = Next(); } return array; } public int[] NextIntArray(int size) { int[] array = new int[size]; for (int i = 0; i < size; i++) { array[i] = NextInt(); } return array; } public long[] NextLongArray(int size) { long[] array = new long[size]; for (int i = 0; i < size; i++) { array[i] = NextLong(); } return array; } public double[] NextDoubleArray(int size) { double[] array = new double[size]; for (int i = 0; i < size; i++) { array[i] = NextDouble(); } return array; } public string Next() { if (Token == null) { if (!StockToken()) { throw new Exception(); } } var token = Token; Token = null; return token; } public bool HasNext() { if (Token != null) { return true; } return StockToken(); } private bool StockToken() { while (true) { sb.Clear(); while (true) { if (cursor >= length) { cursor = 0; if ((length = Reader.Read(buffer, 0, buffer.Length)) <= 0) { break; } } var c = buffer[cursor++]; if (33 <= c && c <= 126) { sb.Append(c); } else { if (sb.Length > 0) break; } } if (sb.Length > 0) { Token = sb.ToString(); return true; } return false; } } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Text; using System.Linq; using E = System.Linq.Enumerable; internal partial class Solver { public void Run() { var s = ns(); int from = -1, to = -1; foreach (var d in new[] { 1, 2 }) { for (int i = 0; i + d < s.Length; i++) { if (s[i] == s[i + d]) { from = i + 1; to = i + d + 1; break; } } } cout.WriteLine("{0} {1}", from, to); } } public struct ModInt : IEquatable<ModInt> { private static int mod = 0; private long _value; public ModInt(long x) { _value = x; Normalize(); } private static long RegularMod(long x, int mod) { if (x >= mod) { if (x < 2 * mod) { return x - mod; } return x % mod; } if (x >= 0) { return x; } x = mod - RegularMod(-x, mod); if (x == mod) { return 0; } return x; } public static int SetModValue(int m) { return mod = m; } private void Normalize() { _value = RegularMod(_value, mod); } public override string ToString() { return _value.ToString(CultureInfo.InvariantCulture); } public int ToInt() { return (int)_value; } public static bool operator ==(ModInt c1, ModInt c2) { return c1._value == c2._value; } public static bool operator !=(ModInt c1, ModInt c2) { return !(c1 == c2); } public static ModInt operator +(ModInt x, ModInt y) { return new ModInt(x._value + y._value); } public static ModInt operator -(ModInt x, ModInt y) { return new ModInt(x._value - y._value); } public static ModInt operator -(ModInt x) { return new ModInt(-x._value); } public static ModInt operator *(ModInt x, ModInt y) { return new ModInt(x._value * y._value); } public static ModInt operator /(ModInt x, ModInt y) { return new ModInt(x._value * Inverse(y._value, mod)); } public static ModInt operator ++(ModInt x) { return x + 1; } public static ModInt operator --(ModInt x) { return x - 1; } public static ModInt Pow(ModInt x, long n) { ModInt r = 1; while (n > 0) { if ((n & 1) != 0) { r *= x; } x *= x; n >>= 1; } return r; } private static long ExtendedGcd(long a, long b, ref long x, ref long y) { if (b == 0) { x = 1; y = 0; return a; } else { var d = ExtendedGcd(b, a % b, ref y, ref x); y -= a / b * x; return d; } } private static long Inverse(long a, long mod) { long x = 0, y = 0; if (ExtendedGcd(a, mod, ref x, ref y) == 1) { return (x + mod) % mod; } else { throw new Exception("Invalid inverse " + a + " " + mod); } } public static implicit operator ModInt(long x) { return new ModInt(x); } public override bool Equals(object obj) { if (obj == null) { return false; } return _value.Equals(((ModInt)obj)._value); } public override int GetHashCode() { return _value.GetHashCode(); } public bool Equals(ModInt other) { return _value.Equals(other._value); } } // PREWRITEN CODE BEGINS FROM HERE static public class StringExtensions { static public string JoinToString<T>(this IEnumerable<T> source, string separator = " ") { return string.Join(separator, source); } } internal partial class Solver : Scanner { public static void Main() { #if LOCAL byte[] inputBuffer = new byte[1000000]; var inputStream = Console.OpenStandardInput(inputBuffer.Length); using (var reader = new StreamReader(inputStream, Console.InputEncoding, false, inputBuffer.Length)) { Console.SetIn(reader); new Solver(Console.In, Console.Out).Run(); } #else Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new Solver(Console.In, Console.Out).Run(); Console.Out.Flush(); #endif } #pragma warning disable IDE0052 private readonly TextReader cin; private readonly TextWriter cout; private readonly TextWriter cerr; #pragma warning restore IDE0052 public Solver(TextReader reader, TextWriter writer) : base(reader) { cin = reader; cout = writer; cerr = Console.Error; } public Solver(string input, TextWriter writer) : this(new StringReader(input), writer) {} #pragma warning disable IDE1006 #pragma warning disable IDE0051 private int ni() { return NextInt(); } private int[] ni(int n) { return NextIntArray(n); } private long nl() { return NextLong(); } private long[] nl(int n) { return NextLongArray(n); } private double nd() { return NextDouble(); } private double[] nd(int n) { return NextDoubleArray(n); } private string ns() { return Next(); } private string[] ns(int n) { return NextArray(n); } #pragma warning restore IDE1006 #pragma warning restore IDE0051 } #if DEBUG internal static class LinqPadExtension { public static string TextDump<T>(this T obj) { if (obj is IEnumerable) return (obj as IEnumerable).Cast<object>().JoinToString().Dump(); else return obj.ToString().Dump(); } public static T Dump<T>(this T obj) { return LINQPad.Extensions.Dump(obj); } } #endif public class Scanner { private readonly TextReader Reader; private readonly CultureInfo ci = CultureInfo.InvariantCulture; private readonly char[] buffer = new char[2 * 1024]; private int cursor = 0, length = 0; private string Token; private readonly StringBuilder sb = new StringBuilder(1024); public Scanner() : this(Console.In) {} public Scanner(TextReader reader) { Reader = reader; } public int NextInt() { return checked((int)NextLong()); } public long NextLong() { var s = Next(); long r = 0; int i = 0; bool negative = false; if (s[i] == '-') { negative = true; i++; } for (; i < s.Length; i++) { r = r * 10 + (s[i] - '0'); #if DEBUG if (!char.IsDigit(s[i])) throw new FormatException(); #endif } return negative ? -r : r; } public double NextDouble() { return double.Parse(Next(), ci); } public string[] NextArray(int size) { string[] array = new string[size]; for (int i = 0; i < size; i++) { array[i] = Next(); } return array; } public int[] NextIntArray(int size) { int[] array = new int[size]; for (int i = 0; i < size; i++) { array[i] = NextInt(); } return array; } public long[] NextLongArray(int size) { long[] array = new long[size]; for (int i = 0; i < size; i++) { array[i] = NextLong(); } return array; } public double[] NextDoubleArray(int size) { double[] array = new double[size]; for (int i = 0; i < size; i++) { array[i] = NextDouble(); } return array; } public string Next() { if (Token == null) { if (!StockToken()) { throw new Exception(); } } var token = Token; Token = null; return token; } public bool HasNext() { if (Token != null) { return true; } return StockToken(); } private bool StockToken() { while (true) { sb.Clear(); while (true) { if (cursor >= length) { cursor = 0; if ((length = Reader.Read(buffer, 0, buffer.Length)) <= 0) { break; } } var c = buffer[cursor++]; if (33 <= c && c <= 126) { sb.Append(c); } else { if (sb.Length > 0) break; } } if (sb.Length > 0) { Token = sb.ToString(); return true; } return false; } } }
[["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 12, 203]]
8
1,932
4
using System; using System.Collections; 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); Solve(); Console.Out.Flush(); } static void Solve() { var S = sc.ReadStr(); var N = S.Length; if (S.All(c => c == S[0])) { Console.WriteLine($"{1} {N}"); return; } for (int i = 0; i < N - 2; i++) { var s = S.Substring(i, 2); if (s.Distinct().Count() <= 2) { Console.WriteLine($"{i + 1} {i + 3}"); return; } } Console.WriteLine($"{-1} {-1}"); } static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public 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; 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); Solve(); Console.Out.Flush(); } static void Solve() { var S = sc.ReadStr(); var N = S.Length; if (S.All(c => c == S[0])) { Console.WriteLine($"{1} {N}"); return; } for (int i = 0; i < N - 2; i++) { var s = S.Substring(i, 3); if (s.Distinct().Count() <= 2) { Console.WriteLine($"{i + 1} {i + 3}"); return; } } Console.WriteLine($"{-1} {-1}"); } static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public 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, 212, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 203]]
8
1,190
2
using Yorukatsu045.Questions; using Yorukatsu045.Extensions; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; namespace Yorukatsu045.Questions { /// <summary> /// ARC059 D /// </summary> public class QuestionE : AtCoderQuestionBase { public override IEnumerable<object> Solve(TextReader inputStream) { var s = inputStream.ReadLine(); for (int begin = 0; begin < s.Length - 1; begin++) { if (s[begin] == s[begin + 1]) { yield return $"{begin} {begin + 1}"; yield break; } else if (begin + 2 < s.Length && s[begin] == s[begin + 2]) { yield return $"{begin} {begin + 2}"; yield break; } } yield return "-1 -1"; } } } namespace Yorukatsu045 { class Program { static void Main(string[] args) { IAtCoderQuestion question = new QuestionE(); // 問題に合わせて書き換え var answers = question.Solve(Console.In); foreach (var answer in answers) { Console.WriteLine(answer); } } } } #region Base Classes namespace Yorukatsu045.Questions { public interface IAtCoderQuestion { IEnumerable<object> Solve(string input); IEnumerable<object> Solve(TextReader inputStream); } public abstract class AtCoderQuestionBase : IAtCoderQuestion { public IEnumerable<object> Solve(string input) { var stream = new MemoryStream(Encoding.Unicode.GetBytes(input)); var reader = new StreamReader(stream, Encoding.Unicode); return Solve(reader); } public abstract IEnumerable<object> Solve(TextReader inputStream); } } #endregion #region Extensions namespace Yorukatsu045.Extensions { internal static class TextReaderExtensions { internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader)); internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader)); internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader)); internal static string ReadString(this TextReader reader) => reader.ReadLine(); internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray(); internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray(); internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray(); internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator); } } #endregion
using Yorukatsu045.Questions; using Yorukatsu045.Extensions; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; namespace Yorukatsu045.Questions { /// <summary> /// ARC059 D /// </summary> public class QuestionE : AtCoderQuestionBase { public override IEnumerable<object> Solve(TextReader inputStream) { var s = inputStream.ReadLine(); for (int begin = 0; begin < s.Length - 1; begin++) { if (s[begin] == s[begin + 1]) { yield return $"{begin + 1} {begin + 2}"; yield break; } else if (begin + 2 < s.Length && s[begin] == s[begin + 2]) { yield return $"{begin + 1} {begin + 3}"; yield break; } } yield return "-1 -1"; } } } namespace Yorukatsu045 { class Program { static void Main(string[] args) { IAtCoderQuestion question = new QuestionE(); // 問題に合わせて書き換え var answers = question.Solve(Console.In); foreach (var answer in answers) { Console.WriteLine(answer); } } } } #region Base Classes namespace Yorukatsu045.Questions { public interface IAtCoderQuestion { IEnumerable<object> Solve(string input); IEnumerable<object> Solve(TextReader inputStream); } public abstract class AtCoderQuestionBase : IAtCoderQuestion { public IEnumerable<object> Solve(string input) { var stream = new MemoryStream(Encoding.Unicode.GetBytes(input)); var reader = new StreamReader(stream, Encoding.Unicode); return Solve(reader); } public abstract IEnumerable<object> Solve(TextReader inputStream); } } #endregion #region Extensions namespace Yorukatsu045.Extensions { internal static class TextReaderExtensions { internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader)); internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader)); internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader)); internal static string ReadString(this TextReader reader) => reader.ReadLine(); internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray(); internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray(); internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray(); internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator); } } #endregion
[["+", 0, 285, 0, 283, 0, 284, 0, 16, 17, 72], ["+", 0, 285, 0, 283, 0, 284, 0, 16, 12, 203], ["-", 0, 285, 0, 283, 0, 284, 0, 16, 12, 203]]
8
567
8
using System; using System.Linq; //リストの使用 using System.Collections.Generic; using System.Text; //テキストの高速出力に必要 class Program { static void Main() { string s = Console.ReadLine(); int n = s.Length; int answerFirst = -1; int answerSecond = -1; for (int i = 0; i < n - 1; i++) { if (s[i] == s[i + 1]) { answerFirst = i; answerSecond = i + 1; } } for (int i = 0; i < n - 2; i++) { if (s[i] == s[i + 2]) { answerFirst = i; answerSecond = i + 2; } } Console.WriteLine(answerFirst + " " + answerSecond); } }
using System; using System.Linq; //リストの使用 using System.Collections.Generic; using System.Text; //テキストの高速出力に必要 class Program { static void Main() { string s = Console.ReadLine(); int n = s.Length; int answerFirst = -1; int answerSecond = -1; for (int i = 0; i < n - 1; i++) { if (s[i] == s[i + 1]) { answerFirst = i + 1; answerSecond = i + 2; } } for (int i = 0; i < n - 2; i++) { if (s[i] == s[i + 2]) { answerFirst = i + 1; answerSecond = i + 3; } } Console.WriteLine(answerFirst + " " + answerSecond); } }
[["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 12, 203]]
8
162
8
using System; using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Collections.Generic; using System.Diagnostics; using System.Numerics; using Enu = System.Linq.Enumerable; public class Program { public void Solve() { var A = Reader.String().Select(c => c - 'a').ToArray(); for (int c = 0; c < 26; c++) { var x = new List<int>(); for (int i = 0; i < A.Length; i++) if (A[i] == c) x.Add(i + 1); for (int i = 0; i + 1 < x.Count; i++) if (x[i + 1] - x[i] <= 2) { Console.WriteLine(x[i] + " " + x[i + 1]); return; } } Console.WriteLine(-1); } } class Entry { static void Main() { new Program().Solve(); } } class Reader { static TextReader reader = Console.In; static readonly char[] separator = { ' ' }; static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries; static string[] A = new string[0]; static int i; static void Init() { A = new string[0]; } public static void Set(TextReader r) { reader = r; Init(); } public static void Set(string file) { reader = new StreamReader(file); Init(); } public static bool HasNext() { return CheckNext(); } public static string String() { return Next(); } public static int Int() { return int.Parse(Next()); } public static long Long() { return long.Parse(Next()); } public static double Double() { return double.Parse(Next()); } public static int[] IntLine() { return Array.ConvertAll(Split(Line()), int.Parse); } public static int[] IntArray(int N) { return Range(N, Int); } public static int[][] IntTable(int H) { return Range(H, IntLine); } public static string[] StringArray(int N) { return Range(N, Next); } public static string[][] StringTable(int N) { return Range(N, () => Split(Line())); } public static string Line() { return reader.ReadLine().Trim(); } public static T[] Range<T>(int N, Func<T> f) { var r = new T[N]; for (int i = 0; i < N; r[i++] = f()) ; return r; } static string[] Split(string s) { return s.Split(separator, op); } static string Next() { CheckNext(); return A[i++]; } static bool CheckNext() { if (i < A.Length) return true; string line = reader.ReadLine(); if (line == null) return false; if (line == "") return CheckNext(); A = Split(line); i = 0; return true; } }
using System; using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Collections.Generic; using System.Diagnostics; using System.Numerics; using Enu = System.Linq.Enumerable; public class Program { public void Solve() { var A = Reader.String().Select(c => c - 'a').ToArray(); for (int c = 0; c < 26; c++) { var x = new List<int>(); for (int i = 0; i < A.Length; i++) if (A[i] == c) x.Add(i + 1); for (int i = 0; i + 1 < x.Count; i++) if (x[i + 1] - x[i] <= 2) { Console.WriteLine(x[i] + " " + x[i + 1]); return; } } Console.WriteLine("-1 -1"); } } class Entry { static void Main() { new Program().Solve(); } } class Reader { static TextReader reader = Console.In; static readonly char[] separator = { ' ' }; static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries; static string[] A = new string[0]; static int i; static void Init() { A = new string[0]; } public static void Set(TextReader r) { reader = r; Init(); } public static void Set(string file) { reader = new StreamReader(file); Init(); } public static bool HasNext() { return CheckNext(); } public static string String() { return Next(); } public static int Int() { return int.Parse(Next()); } public static long Long() { return long.Parse(Next()); } public static double Double() { return double.Parse(Next()); } public static int[] IntLine() { return Array.ConvertAll(Split(Line()), int.Parse); } public static int[] IntArray(int N) { return Range(N, Int); } public static int[][] IntTable(int H) { return Range(H, IntLine); } public static string[] StringArray(int N) { return Range(N, Next); } public static string[][] StringTable(int N) { return Range(N, () => Split(Line())); } public static string Line() { return reader.ReadLine().Trim(); } public static T[] Range<T>(int N, Func<T> f) { var r = new T[N]; for (int i = 0; i < N; r[i++] = f()) ; return r; } static string[] Split(string s) { return s.Split(separator, op); } static string Next() { CheckNext(); return A[i++]; } static bool CheckNext() { if (i < A.Length) return true; string line = reader.ReadLine(); if (line == null) return false; if (line == "") return CheckNext(); A = Split(line); i = 0; return true; } }
[["-", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["-", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
714
5
using System; class Program { static void Main(string[] args) { string str = Console.ReadLine(); int N = str.Length - 1; for (int i = 0; i < N - 1; i++) { if (str[i] == str[i + 1]) { Console.WriteLine("{0} {1}", i + 1, i + 2); return; } } for (int i = 0; i < N - 2; i++) { if (str[i] == str[i + 2]) { Console.WriteLine("{0} {1}", i + 1, i + 3); return; } } Console.WriteLine("-1 -1"); } }
using System; class Program { static void Main(string[] args) { string str = Console.ReadLine(); int N = str.Length; for (int i = 0; i < N - 1; i++) { if (str[i] == str[i + 1]) { Console.WriteLine("{0} {1}", i + 1, i + 2); return; } } for (int i = 0; i < N - 2; i++) { if (str[i] == str[i + 2]) { Console.WriteLine("{0} {1}", i + 1, i + 3); return; } } Console.WriteLine("-1 -1"); } }
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
151
2
using System; class Program { static void Main(string[] args) { long M = 1000000007; string[] str = Console.ReadLine().Split(' '); int N = int.Parse(str[0]); int C = int.Parse(str[1]); str = Console.ReadLine().Split(' '); long[] A = new long[N + 1]; long[] B = new long[N + 1]; for (int i = 0; i < N; i++) { A[i] = long.Parse(str[i]); } str = Console.ReadLine().Split(' '); for (int i = 0; i < N; i++) { B[i] = long.Parse(str[i]); } int tableSize = 401; long[,] table = new long[tableSize, tableSize]; for (int j = 0; j < tableSize; j++) { table[0, j] = 1; for (int i = 1; i < tableSize; i++) { table[i, j] = table[i - 1, j] * ((long)j) % M; } } for (int i = 0; i < tableSize; i++) { for (int j = 1; j < tableSize; j++) { table[i, j] += table[i, j - 1]; table[i, j] %= M; } } long[,] dp = new long[N, C + 1]; for (int i = 0; i < N; i++) { for (int j = 0; j < C + 1; j++) { dp[i, j] = 0; } } dp[N - 1, 0] = (table[0, B[N - 1]] - table[0, A[N - 1] - 1]) % M; for (int j = 1; j < C + 1; j++) { dp[N - 1, j] = (M + table[j, B[N - 1]] - table[j, A[N - 1] - 1]) % M; } for (int i = N - 2; i > -1; i--) { for (int j = 0; j < C + 1; j++) { for (int k = 0; k <= j; k++) { dp[i, j] += ((table[k, B[i]] - table[k, A[i] - 1]) * dp[i + 1, j - k] % M) % M; dp[i, j] %= M; } } } Console.WriteLine(dp[0, C] % M); } }
using System; class Program { static void Main(string[] args) { long M = 1000000007; string[] str = Console.ReadLine().Split(' '); int N = int.Parse(str[0]); int C = int.Parse(str[1]); str = Console.ReadLine().Split(' '); long[] A = new long[N + 1]; long[] B = new long[N + 1]; for (int i = 0; i < N; i++) { A[i] = long.Parse(str[i]); } str = Console.ReadLine().Split(' '); for (int i = 0; i < N; i++) { B[i] = long.Parse(str[i]); } int tableSize = 401; long[,] table = new long[tableSize, tableSize]; for (int j = 0; j < tableSize; j++) { table[0, j] = 1; for (int i = 1; i < tableSize; i++) { table[i, j] = table[i - 1, j] * ((long)j) % M; } } for (int i = 0; i < tableSize; i++) { for (int j = 1; j < tableSize; j++) { table[i, j] += table[i, j - 1]; table[i, j] %= M; } } long[,] dp = new long[N, C + 1]; for (int i = 0; i < N; i++) { for (int j = 0; j < C + 1; j++) { dp[i, j] = 0; } } dp[N - 1, 0] = (table[0, B[N - 1]] - table[0, A[N - 1] - 1]) % M; for (int j = 1; j < C + 1; j++) { dp[N - 1, j] = (M + table[j, B[N - 1]] - table[j, A[N - 1] - 1]) % M; } for (int i = N - 2; i > -1; i--) { for (int j = 0; j < C + 1; j++) { for (int k = 0; k <= j; k++) { dp[i, j] += ((M + table[k, B[i]] - table[k, A[i] - 1]) * dp[i + 1, j - k] % M) % M; dp[i, j] %= M; } } } Console.WriteLine(dp[0, C] % M); } }
[["+", 31, 16, 31, 23, 0, 16, 31, 16, 31, 22], ["+", 31, 16, 31, 23, 0, 16, 31, 16, 17, 72]]
8
608
2
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 r = int.Parse(Console.ReadLine()); int ret = 0; for (int i = 0; i < r; i++) { ret += i; } Console.WriteLine(ret); } } }
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 r = int.Parse(Console.ReadLine()); int ret = 0; for (int i = 0; i < r; i++) { ret += i + 1; } Console.WriteLine(ret); } } }
[["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203]]
8
97
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC043A { class Program { static void Main(string[] args) { int n; int s; int i; // n 個数 // s 人数 //にんずうを入力 n = int.Parse(Console.ReadLine()); //ひつようなこすうをにゅうりょく s = 0; // 0にしょきか for (i = 1; i <= n; i++)    //1>>nの繰り返し { s = s + i;       //sをi増やす Console.WriteLine(s); } Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC043A { class Program { static void Main(string[] args) { int n; int s; int i; // n 個数 // s 人数 //にんずうを入力 n = int.Parse(Console.ReadLine()); //ひつようなこすうをにゅうりょく s = 0; // 0にしょきか for (i = 1; i <= n; i++) // 1>>nの繰り返し { s = s + i; // sをi増やす } Console.WriteLine(s); Console.ReadKey(); } } }
[["-", 0, 235, 8, 201, 0, 195, 8, 196, 0, 7], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 10, 11], ["-", 0, 195, 8, 196, 0, 7, 10, 11, 31, 22], ["-", 8, 196, 0, 7, 10, 11, 31, 22, 0, 202], ["-", 0, 7, 10, 11, 31, 22, 0, 202, 12, 203], ["-", 10, 11, 31, 22, 0, 202, 12, 203, 15, 16], ["-", 31, 22, 0, 202, 12, 203, 15, 16, 31, 22], ["-", 0, 202, 12, 203, 15, 16, 31, 22, 12, 22], ["-", 12, 203, 15, 16, 31, 22, 12, 22, 26, 223], ["-", 15, 16, 31, 22, 12, 22, 26, 223, 0, 22], ["-", 31, 22, 12, 22, 26, 223, 0, 22, 0, 169], ["-", 12, 22, 26, 223, 0, 22, 0, 169, 8, 196], ["-", 26, 223, 0, 22, 0, 169, 8, 196, 0, 1], ["-", 0, 22, 0, 169, 8, 196, 0, 1, 0, 11], ["-", 0, 169, 8, 196, 0, 1, 0, 11, 0, 169], ["-", 8, 196, 0, 1, 0, 11, 0, 169, 0, 1], ["-", 0, 1, 0, 11, 0, 169, 0, 1, 0, 213], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 8, 196], ["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 1], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 11], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 31, 22, 0, 202], ["-", 0, 1, 0, 11, 31, 22, 0, 202, 12, 16], ["-", 0, 11, 31, 22, 0, 202, 12, 16, 0, 169], ["-", 31, 22, 0, 202, 12, 16, 0, 169, 0, 1], ["-", 0, 202, 12, 16, 0, 169, 0, 1, 0, 213], ["-", 12, 16, 0, 169, 0, 1, 0, 213, 63, 214], ["-", 0, 169, 0, 1, 0, 213, 63, 214, 3, 4], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46]]
8
115
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC043A { class Program { static void Main(string[] args) { int a, b, i; a = int.Parse(Console.ReadLine()); b = 0; for (i = 1; i <= a; i++) ; { b += i; } Console.WriteLine(b); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC043A { class Program { static void Main(string[] args) { int a, b, i; a = int.Parse(Console.ReadLine()); b = 0; for (i = 1; i <= a; i++) { b = b + i; } Console.WriteLine(b); Console.ReadKey(); } } }
[["-", 0, 195, 8, 196, 0, 7, 8, 260, 0, 35], ["-", 0, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 72]]
8
103
5
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication3 { class Program { static void Main(string[] args) { int N; //人数 int S; //必要な個数 int i; //人数Nを入力 N = int.Parse(Console.ReadLine()); //必要な個数Sを求める //(合計を求めるアルゴリズム) S = 0; for (i = 0; i <= N; i++)     { S = S + 1; } // SをI増やす S+=Iでもよい // Sを出力(表示) Console.WriteLine(S); //入力待ちに Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication3 { class Program { static void Main(string[] args) { int N; //人数 int S; //必要な個数 int i; //人数Nを入力 N = int.Parse(Console.ReadLine()); //必要な個数Sを求める //(合計を求めるアルゴリズム) S = 0; for (i = 0; i <= N; i++)     { S = S + i; } // SをI増やす S+=Iでもよい // Sを出力(表示) Console.WriteLine(S); //入力待ちに Console.ReadKey(); } } }
[["-", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 22]]
8
115
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC_043A { class Program { static void Main(string[] args) { int N; int s; int i; N = int.Parse(Console.ReadLine()); s = 0; for (i = 1; i < N; i++) { s = s + i; } Console.WriteLine(s); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC_043A { class Program { static void Main(string[] args) { int N; int s; int i; N = int.Parse(Console.ReadLine()); s = 0; for (i = 1; i <= N; i++) { s = s + i; } Console.WriteLine(s); Console.ReadKey(); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
106
2
using System; using System.Linq; using System.Collections.Generic; namespace program { class Program { static void Main() { int N = Input.ScanInt(); int Sum = Enumerable.Range(0, N).ToArray().Sum(); Console.WriteLine(Sum); } } static class Input { static public int ScanInt() { return int.Parse(Console.ReadLine()); } static public uint ScanUint() { return uint.Parse(Console.ReadLine()); } static public long ScanLong() { return long.Parse(Console.ReadLine()); } static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); } static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); } static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); } static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); } static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); } static public string ScanStr() { return Console.ReadLine(); } static public string[] ScanStrArray() { return ScanStr().Split(' '); } } static class MyMath { 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 ulong GCD(ulong a, ulong b) { Func<ulong, ulong, ulong> gcd = null; gcd = (x, y) => y == 0 ? x : gcd(y, x % y); return a > b ? gcd(a, b) : gcd(b, a); } public static int LCM(int a, int b) { return a * b / GCD(a, b); } public static ulong LCM(ulong a, ulong b) { return a * b / GCD(a, b); } } }
using System; using System.Linq; using System.Collections.Generic; namespace program { class Program { static void Main() { int N = Input.ScanInt(); int Sum = Enumerable.Range(1, N).ToArray().Sum(); Console.WriteLine(Sum); } } static class Input { static public int ScanInt() { return int.Parse(Console.ReadLine()); } static public uint ScanUint() { return uint.Parse(Console.ReadLine()); } static public long ScanLong() { return long.Parse(Console.ReadLine()); } static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); } static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); } static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); } static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); } static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); } static public string ScanStr() { return Console.ReadLine(); } static public string[] ScanStrArray() { return ScanStr().Split(' '); } } static class MyMath { 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 ulong GCD(ulong a, ulong b) { Func<ulong, ulong, ulong> gcd = null; gcd = (x, y) => y == 0 ? x : gcd(y, x % y); return a > b ? gcd(a, b) : gcd(b, a); } public static int LCM(int a, int b) { return a * b / GCD(a, b); } public static ulong LCM(ulong a, ulong b) { return a * b / GCD(a, b); } } }
[["-", 63, 214, 205, 213, 3, 4, 0, 28, 0, 203], ["+", 63, 214, 205, 213, 3, 4, 0, 28, 0, 203]]
8
537
2
using System; class Unti { public static void Main() { var x = int.Parse(Console.ReadLine()); var count = 0; for (int i = 0; i < x; i++) { count += i; } Console.WriteLine(count); } }
using System; class Unti { public static void Main() { var x = int.Parse(Console.ReadLine()); var count = 0; for (int i = 1; i <= x; i++) { count += i; } Console.WriteLine(count); } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
61
4
using System; public class P { public static void Main() { int a = int.Parse(Console.ReadLine()); Console.WriteLine(a * (a - 1) / 2); } }
using System; public class P { public static void Main() { int a = int.Parse(Console.ReadLine()); Console.WriteLine(a * (a + 1) / 2); } }
[["-", 0, 16, 31, 16, 12, 23, 0, 16, 17, 33], ["+", 0, 16, 31, 16, 12, 23, 0, 16, 17, 72]]
8
45
2
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; namespace AtCoder.B { public class Program { public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); } private static object GetResult() { var text = new Stack<char>(); foreach (var s in ReadText().ToArray()) { if (s == '0' || s == '1') { text.Push(s); } else if (text.Any()) { text.Pop(); } } return new string(text.ToArray()); } #region Console.Read public static string ReadText() { return Console.ReadLine(); } public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); } public static long ReadLong() { return long.Parse(Console.ReadLine()); } public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); } public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); } public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); } public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); } public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); } #endregion } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; namespace AtCoder.B { public class Program { public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); } private static object GetResult() { var text = new Stack<char>(); foreach (var s in ReadText().ToArray()) { if (s == '0' || s == '1') { text.Push(s); } else if (text.Any()) { text.Pop(); } } return new string(text.Reverse().ToArray()); } #region Console.Read public static string ReadText() { return Console.ReadLine(); } public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); } public static long ReadLong() { return long.Parse(Console.ReadLine()); } public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); } public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); } public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); } public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); } public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); } #endregion } }
[["+", 0, 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]]
8
430
4
using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace Competitive { internal class Solution { public long N, S; public void Run() { N = Input.ReadLong(); S = Input.ReadLong(); if (N == S) { Console.WriteLine(N + 1); } else if (N < S) { Console.WriteLine(N); } else { for (int i = 2; i < 1000000; i++) { if (Success(i)) { Console.WriteLine(i); return; } } for (int m = 1000000; m >= 1; m--) { if (SuccessMod(m) != -1) { Console.WriteLine(SuccessMod(m)); return; } } Console.WriteLine(-1); } } public bool Success(int b) { long s = 0; long n = N; while (n > 0) { s += n % b; n /= b; } return s == S; } public long SuccessMod(int m) { if (S - m < 0) return -1; long x = N - (S - m); if (x < 0) return -1; if (x % m != 0) return -1; long b = x / m; if (b <= S - m) return -1; return b; } } // libs ---------- // common ---------- internal static class Input { public static string ReadString() { string line = Console.ReadLine(); return line; } public static int ReadInt() { string line = Console.ReadLine(); return int.Parse(line); } public static int[] ReadIntArray() { string line = Console.ReadLine(); return line.Split(' ').Select(int.Parse).ToArray(); } public static long ReadLong() { string line = Console.ReadLine(); return long.Parse(line); } public static long[] ReadLongArray() { string line = Console.ReadLine(); return line.Split(' ').Select(long.Parse).ToArray(); } public static double[] ReadDoubleArray() { string line = Console.ReadLine(); return line.Split(' ').Select(double.Parse).ToArray(); } } internal class Program { public static void Main(string[] args) { var s = new Solution(); s.Run(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace Competitive { internal class Solution { public long N, S; public void Run() { N = Input.ReadLong(); S = Input.ReadLong(); if (N == S) { Console.WriteLine(N + 1); } else if (N < S) { Console.WriteLine(-1); } else { for (int i = 2; i < 1000000; i++) { if (Success(i)) { Console.WriteLine(i); return; } } for (int m = 1000000; m >= 1; m--) { if (SuccessMod(m) != -1) { Console.WriteLine(SuccessMod(m)); return; } } Console.WriteLine(-1); } } public bool Success(int b) { long s = 0; long n = N; while (n > 0) { s += n % b; n /= b; } return s == S; } public long SuccessMod(int m) { if (S - m < 0) return -1; long x = N - (S - m); if (x < 0) return -1; if (x % m != 0) return -1; long b = x / m; if (b <= S - m) return -1; return b; } } // libs ---------- // common ---------- internal static class Input { public static string ReadString() { string line = Console.ReadLine(); return line; } public static int ReadInt() { string line = Console.ReadLine(); return int.Parse(line); } public static int[] ReadIntArray() { string line = Console.ReadLine(); return line.Split(' ').Select(int.Parse).ToArray(); } public static long ReadLong() { string line = Console.ReadLine(); return long.Parse(line); } public static long[] ReadLongArray() { string line = Console.ReadLine(); return line.Split(' ').Select(long.Parse).ToArray(); } public static double[] ReadDoubleArray() { string line = Console.ReadLine(); return line.Split(' ').Select(double.Parse).ToArray(); } } internal class Program { public static void Main(string[] args) { var s = new Solution(); s.Run(); } } }
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203]]
8
523
3
using System; using System.Collections.Generic; class Solve { public long n; public long s; public Solve() {} public static int Main() { new Solve().Calc(); return 0; } void Calc() { getinput(); if (n <= s) { if (n == s) { Console.WriteLine(n + 1); } else { Console.WriteLine(-1); } } else { long i; for (i = 2; i * i <= n; i++) { long sum = 0; long a = n; while (a > 0) { sum += a % i; a /= i; } if (sum == s) { Console.WriteLine(i); return; } } if (i > s) i = s; for (; i >= 1; i--) { if ((n - s + i) % i == 0 && (n - s + i) / i > i && s - i < (n - s + i) / i) { Console.WriteLine((n - s + i) / i); return; } } Console.WriteLine(-1); } } void getinput() { n = int.Parse(Console.ReadLine()); s = int.Parse(Console.ReadLine()); } }
using System; using System.Collections.Generic; class Solve { public long n; public long s; public Solve() {} public static int Main() { new Solve().Calc(); return 0; } void Calc() { getinput(); if (n <= s) { if (n == s) { Console.WriteLine(n + 1); } else { Console.WriteLine(-1); } } else { long i; for (i = 2; i * i <= n; i++) { long sum = 0; long a = n; while (a > 0) { sum += a % i; a /= i; } if (sum == s) { Console.WriteLine(i); return; } } if (i > s) i = s; for (; i >= 1; i--) { if ((n - s + i) % i == 0 && (n - s + i) / i > i && s - i < (n - s + i) / i) { Console.WriteLine((n - s + i) / i); return; } } Console.WriteLine(-1); } } void getinput() { n = Int64.Parse(Console.ReadLine()); s = Int64.Parse(Console.ReadLine()); } }
[["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22]]
8
283
4
using System; using System.Text; class A { int N; int maxN = 100005; long L; int Q; long[] x; int[,] l; public A() { x = new long[maxN]; l = new int[20, maxN]; } public int calc(int a, int b) { if (a == b) return 0; if (b <= l[0, a]) return 1; for (int i = 1; i < 20; i++) { int h = (int)(1 << i); if (l[i, a] <= b && l[i + 1, a] > b) { return h + calc(l[i, a], b); } } return 0; } public string F() { return Console.ReadLine(); } public void run() { N = int.Parse(F()); string[] ss = F().Split(' '); for (int i = 0; i < N; i++) { x[i] = long.Parse(ss[i]); } x[N] = x[N - 1] + 1; N = N + 1; L = long.Parse(F()); Q = int.Parse(F()); int p = 1; for (int i = 0; i < N; i++) { while (p < N && x[p] - x[i] <= L) p++; p--; l[0, i] = p; } for (int k = 1; k < 20; k++) { for (int i = 0; i < N; i++) { l[k, i] = l[k - 1, l[k - 1, i]]; } } /* for(int k=0;k<20;k++){ for(int i=0;i<N;i++){ Console.Write(l[k,i]+" "); } Console.WriteLine(); } */ StringBuilder sb = new StringBuilder("", 12 * Q); for (int _ = 0; _ < Q; _++) { ss = F().Split(' '); int a = int.Parse(ss[0]) - 1; int b = int.Parse(ss[1]) - 1; if (a > b) { int tmp = a; a = b; b = tmp; } sb.Append(calc(a, b) + "\n"); } Console.WriteLine(sb.ToString()); } } class Program { static void Main(string[] args) { A a = new A(); a.run(); } }
using System; using System.Text; class A { int N; int maxN = 100005; long L; int Q; long[] x; int[,] l; public A() { x = new long[maxN]; l = new int[20, maxN]; } public int calc(int a, int b) { if (a == b) return 0; if (b <= l[0, a]) return 1; for (int i = 0; i < 19; i++) { int h = (int)(1 << i); if (l[i, a] <= b && l[i + 1, a] > b) { return h + calc(l[i, a], b); } } return -1; } public string F() { return Console.ReadLine(); } public void run() { N = int.Parse(F()); string[] ss = F().Split(' '); for (int i = 0; i < N; i++) { x[i] = long.Parse(ss[i]); } x[N] = x[N - 1] + 1; N = N + 1; L = long.Parse(F()); Q = int.Parse(F()); int p = 1; for (int i = 0; i < N; i++) { while (p < N && x[p] - x[i] <= L) p++; p--; l[0, i] = p; } for (int k = 1; k < 20; k++) { for (int i = 0; i < N; i++) { l[k, i] = l[k - 1, l[k - 1, i]]; } } StringBuilder sb = new StringBuilder("", 12 * Q); for (int _ = 0; _ < Q; _++) { ss = F().Split(' '); int a = int.Parse(ss[0]) - 1; int b = int.Parse(ss[1]) - 1; if (a > b) { int tmp = a; a = b; b = tmp; } sb.Append(calc(a, b) + "\n"); } Console.WriteLine(sb.ToString()); } } class Program { static void Main(string[] args) { A a = new A(); a.run(); } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 37, 0, 203], ["+", 0, 195, 8, 196, 0, 37, 0, 241, 0, 33], ["+", 0, 195, 8, 196, 0, 37, 0, 241, 0, 203]]
8
547
7
using System; using System.IO; using System.Linq; class E { static void Main() { new K(); } } class K { int F() { return int.Parse(Console.ReadLine()); } int[] G() { return Console.ReadLine().Split().Select(_ => int.Parse(_)).ToArray(); } public K() { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); var N = F(); var x = G(); int L = F(), Q = F(); var r = new int[N]; for (var i = 0; i < N; i++) r[i] = FirstBinary(i, N, k => x[k] > x[i] + L) - 1; var rn = new int [20][]; rn[0] = r; for (var c = 1; c < 20; c++) { rn[c] = new int[N]; for (var i = 0; i < N; i++) rn[c][i] = rn[c - 1][rn[c - 1][i]]; } for (var q = 0; q < Q; q++) { var I = G(); Array.Sort(I); Console.WriteLine(FirstBinary(1, N, d => { var p = I[0]; for (var c = 0; c < 20; c++) if ((d & (1 << c)) != 0) p = rn[c][p]; return p >= I[1]; })); } Console.Out.Flush(); } int FirstBinary(int s, int t, Predicate<int> p) { while (s < t) { var m = (s + t) / 2; if (p(m)) t = m; else s = m + 1; } return s; } }
using System; using System.IO; using System.Linq; class E { static void Main() { new K(); } } class K { int F() { return int.Parse(Console.ReadLine()); } int[] G() { return Console.ReadLine().Split().Select(_ => int.Parse(_)).ToArray(); } public K() { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); var N = F(); var x = G(); int L = F(), Q = F(); var r = new int[N]; for (var i = 0; i < N; i++) r[i] = FirstBinary(i, N, k => x[k] > x[i] + L) - 1; var rn = new int [20][]; rn[0] = r; for (var c = 1; c < 20; c++) { rn[c] = new int[N]; for (var i = 0; i < N; i++) rn[c][i] = rn[c - 1][rn[c - 1][i]]; } for (var q = 0; q < Q; q++) { var I = G(); Array.Sort(I); Console.WriteLine(FirstBinary(1, N, d => { var p = I[0] - 1; for (var c = 0; c < 20; c++) if ((d & (1 << c)) != 0) p = rn[c][p]; return p >= I[1] - 1; })); } Console.Out.Flush(); } int FirstBinary(int s, int t, Predicate<int> p) { while (s < t) { var m = (s + t) / 2; if (p(m)) t = m; else s = m + 1; } return s; } }
[["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 8, 196, 0, 37, 0, 16, 12, 16, 17, 33], ["+", 8, 196, 0, 37, 0, 16, 12, 16, 12, 203]]
8
441
4
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Numerics; using System.Threading; using System.Runtime.CompilerServices; using System.Diagnostics; using static System.Math; using static System.Array; using static AtCoder.Cout; 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 / 3; 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 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; // Testcase = Cin.Int; for (var _ = 0; _ < Testcase; _++) Solve(); } static void Solve() { var S = Cin.Str; if (S.Contains('N') ^ S.Contains('S')) { OutL("No"); return; } if (S.Contains('S') ^ S.Contains('W')) { OutL("No"); return; } OutL("Yes"); } 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; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator ModInt(long a) { var ret = a % MOD; return new ModInt(ret < 0 ? (ret + MOD) : ret); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator +(ModInt a, ModInt b) => (a.value + b.value); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator -(ModInt a, ModInt b) => (a.value - b.value); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator *(ModInt a, ModInt b) => (a.value * b.value); [MethodImpl(MethodImplOptions.AggressiveInlining)] 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; [MethodImpl(MethodImplOptions.AggressiveInlining)] 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 }; [MethodImpl(MethodImplOptions.AggressiveInlining)] 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]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt nCr(long n, long r) { if (n < 0 || r < 0) return 0; return n < r ? 0 : Fac(n) / (Fac(r) * Fac(n - r)); } public static explicit operator int(ModInt a) => (int)a.value; } public class Rolling_Hash { const ulong m30 = (1UL << 30) - 1; const ulong m31 = (1UL << 31) - 1; const ulong MOD = (1UL << 61) - 1; const ulong Pl = (MOD << 1) << 1; private uint B; private string S; ulong[] hash; ulong[] pw; public Rolling_Hash(string str) { S = str; B = (uint) new Random().Next(1 << 12 + 1, int.MaxValue); int L = S.Length; hash = new ulong[L + 1]; pw = new ulong[L + 1]; hash[0] = 0; pw[0] = 1; for (var i = 0; i < L; i++) { hash[i + 1] = CalcMod(Mul(hash[i], B) + S[i]); pw[i + 1] = CalcMod(Mul(pw[i], B)); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public ulong GetHashValue(int idx) => hash[idx]; [MethodImpl(MethodImplOptions.AggressiveInlining)] // segment [l,r] public ulong Hash_fold(int l, int r) => CalcMod(Pl + hash[r + 1] - Mul(hash[l], pw[r - l + 1])); [MethodImpl( MethodImplOptions.AggressiveInlining)] // segment[start,start+len-1] public ulong Hash_sub(int start, int len) => CalcMod(Pl + hash[start + len] - Mul(hash[start], pw[len])); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ulong[] GetHashArray() => hash; [MethodImpl(MethodImplOptions.AggressiveInlining)] ulong Mul(ulong a, ulong b) { ulong au = a >> 31; ulong ad = a & m31; ulong bu = b >> 31; ulong bd = b & m31; ulong mid = ad * bu + au * bd; ulong midu = mid >> 30; ulong midd = mid & m30; return au * bu * 2 + midu + (midd << 31) + ad * bd; } [MethodImpl(MethodImplOptions.AggressiveInlining)] ulong CalcMod(ulong x) { ulong xu = x >> 61; ulong xd = x & MOD; ulong res = xu + xd; if (res >= MOD) res -= MOD; return res; } } public class Priority_Queue<T> { private List<T> Q; private readonly Comparison<T> Func_Compare; public Priority_Queue(Comparison<T> comp) { Func_Compare = comp; Q = new List<T>(); } private void PushHeap(List<T> list, T item) { int n = list.Count(); list.Add(item); while (n != 0) { int pIndex = (n - 1) / 2; if (Func_Compare(list[n], list[pIndex]) < 0) { Swap(Q, n, pIndex); } else { break; } n = pIndex; } } private void PopHeap(List<T> list) { int n = list.Count() - 1; list[0] = list[n]; list.RemoveAt(n); int cur = 0; int comp; while (2 * cur + 1 <= n - 1) { int c1 = 2 * cur + 1; int c2 = 2 * (cur + 1); if (c1 == n - 1) { comp = c1; } else { comp = Func_Compare(list[c1], list[c2]) < 0 ? c1 : c2; } if (Func_Compare(list[cur], list[comp]) > 0) { Swap(Q, cur, comp); } else { break; } cur = comp; } } private void Swap(List<T> list, int a, int b) { T keep = list[a]; list[a] = list[b]; list[b] = keep; } public void Enqueue(T value) { PushHeap(Q, value); } public T Dequeue() { T ret = Q[0]; PopHeap(Q); return ret; } public T Peek() { return Q[0]; } public int Count() { return Q.Count(); } public bool Any() { return Q.Any(); } } public class SegmentTree<T> { // 1-indexed type int n; T[] Tree; Func<T, T, T> f; T ex; int L; [MethodImpl(MethodImplOptions.AggressiveInlining)] public SegmentTree(int size, Func<T, T, T> fun, T exvalue) { ex = exvalue; f = fun; n = 1; while (n < size) n <<= 1; Tree = new T[n << 1]; L = (n << 1) - 1; for (var i = 0; i <= L; i++) Tree[i] = ex; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public SegmentTree(int size, Func<T, T, T> fun, T exvalue, T[] initial) { ex = exvalue; n = 1; while (n < size) n <<= 1; f = fun; Tree = new T[n << 1]; L = (n << 1) - 1; for (var i = 0; i <= L; i++) Tree[i] = (n <= i && i <= n + initial.Length - 1) ? initial[i - n] : ex; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Set_All() { for (var i = n - 1; i >= 1; i--) Tree[i] = f(Tree[i << 1], Tree[(i << 1) | 1]); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Assign(int idx, T nxt) => Tree[idx + n] = nxt; [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Update(int idx) { int now = idx + n; while (now > 1) { now >>= 1; Tree[now] = f(Tree[now << 1], Tree[now << 1 | 1]); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Query_Update(int idx, T nxt) { Assign(idx, nxt); Update(idx); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Query_Update_func(int idx, T y) { Assign(idx, f(Peek(idx), y)); Update(idx); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Query_Fold(int l, int r) { int L = n + l; int R = n + r; T vL = ex, vR = ex; while (L < R) { if (L % 2 == 1) { vL = f(vL, Tree[L]); L++; } if (R % 2 == 1) { vR = f(Tree[R - 1], vR); R--; } L >>= 1; R >>= 1; } return f(vL, vR); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Peek(int idx) => Tree[idx + n]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Display(int len) { for (var i = 0; i < len; i++) Console.Write($"{Tree[i + n]} "); Console.WriteLine(); } } public class UnionFind { private int[] parent; private int[] rank; private int[] size; public UnionFind(int n) { parent = new int[n]; rank = new int[n]; size = new int[n]; for (var i = 0; i < n; i++) { parent[i] = i; rank[i] = 0; size[i] = 1; } } public int Root(int x) { return parent[x] == x ? x : parent[x] = Root(parent[x]); } public bool SameRoot(int x, int y) { return Root(x) == Root(y); } public void Unite(int x, int y) { x = Root(x); y = Root(y); if (x == y) { return; } if (rank[x] < rank[y]) { parent[x] = y; size[y] += size[x]; size[x] = 0; } else { parent[y] = x; if (rank[x] == rank[y]) { rank[x]++; } size[x] += size[y]; size[y] = 0; } } public int SizeOf(int x) { return size[Root(x)]; } } static class Cin { 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]); } } static class Cout { 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 System.Runtime.CompilerServices; using System.Diagnostics; using static System.Math; using static System.Array; using static AtCoder.Cout; 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 / 3; 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 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; // Testcase = Cin.Int; for (var _ = 0; _ < Testcase; _++) Solve(); } static void Solve() { var S = Cin.Str; if (S.Contains('N') ^ S.Contains('S')) { OutL("No"); return; } if (S.Contains('E') ^ S.Contains('W')) { OutL("No"); return; } OutL("Yes"); } 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; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator ModInt(long a) { var ret = a % MOD; return new ModInt(ret < 0 ? (ret + MOD) : ret); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator +(ModInt a, ModInt b) => (a.value + b.value); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator -(ModInt a, ModInt b) => (a.value - b.value); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator *(ModInt a, ModInt b) => (a.value * b.value); [MethodImpl(MethodImplOptions.AggressiveInlining)] 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; [MethodImpl(MethodImplOptions.AggressiveInlining)] 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 }; [MethodImpl(MethodImplOptions.AggressiveInlining)] 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]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt nCr(long n, long r) { if (n < 0 || r < 0) return 0; return n < r ? 0 : Fac(n) / (Fac(r) * Fac(n - r)); } public static explicit operator int(ModInt a) => (int)a.value; } public class Rolling_Hash { const ulong m30 = (1UL << 30) - 1; const ulong m31 = (1UL << 31) - 1; const ulong MOD = (1UL << 61) - 1; const ulong Pl = (MOD << 1) << 1; private uint B; private string S; ulong[] hash; ulong[] pw; public Rolling_Hash(string str) { S = str; B = (uint) new Random().Next(1 << 12 + 1, int.MaxValue); int L = S.Length; hash = new ulong[L + 1]; pw = new ulong[L + 1]; hash[0] = 0; pw[0] = 1; for (var i = 0; i < L; i++) { hash[i + 1] = CalcMod(Mul(hash[i], B) + S[i]); pw[i + 1] = CalcMod(Mul(pw[i], B)); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public ulong GetHashValue(int idx) => hash[idx]; [MethodImpl(MethodImplOptions.AggressiveInlining)] // segment [l,r] public ulong Hash_fold(int l, int r) => CalcMod(Pl + hash[r + 1] - Mul(hash[l], pw[r - l + 1])); [MethodImpl( MethodImplOptions.AggressiveInlining)] // segment[start,start+len-1] public ulong Hash_sub(int start, int len) => CalcMod(Pl + hash[start + len] - Mul(hash[start], pw[len])); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ulong[] GetHashArray() => hash; [MethodImpl(MethodImplOptions.AggressiveInlining)] ulong Mul(ulong a, ulong b) { ulong au = a >> 31; ulong ad = a & m31; ulong bu = b >> 31; ulong bd = b & m31; ulong mid = ad * bu + au * bd; ulong midu = mid >> 30; ulong midd = mid & m30; return au * bu * 2 + midu + (midd << 31) + ad * bd; } [MethodImpl(MethodImplOptions.AggressiveInlining)] ulong CalcMod(ulong x) { ulong xu = x >> 61; ulong xd = x & MOD; ulong res = xu + xd; if (res >= MOD) res -= MOD; return res; } } public class Priority_Queue<T> { private List<T> Q; private readonly Comparison<T> Func_Compare; public Priority_Queue(Comparison<T> comp) { Func_Compare = comp; Q = new List<T>(); } private void PushHeap(List<T> list, T item) { int n = list.Count(); list.Add(item); while (n != 0) { int pIndex = (n - 1) / 2; if (Func_Compare(list[n], list[pIndex]) < 0) { Swap(Q, n, pIndex); } else { break; } n = pIndex; } } private void PopHeap(List<T> list) { int n = list.Count() - 1; list[0] = list[n]; list.RemoveAt(n); int cur = 0; int comp; while (2 * cur + 1 <= n - 1) { int c1 = 2 * cur + 1; int c2 = 2 * (cur + 1); if (c1 == n - 1) { comp = c1; } else { comp = Func_Compare(list[c1], list[c2]) < 0 ? c1 : c2; } if (Func_Compare(list[cur], list[comp]) > 0) { Swap(Q, cur, comp); } else { break; } cur = comp; } } private void Swap(List<T> list, int a, int b) { T keep = list[a]; list[a] = list[b]; list[b] = keep; } public void Enqueue(T value) { PushHeap(Q, value); } public T Dequeue() { T ret = Q[0]; PopHeap(Q); return ret; } public T Peek() { return Q[0]; } public int Count() { return Q.Count(); } public bool Any() { return Q.Any(); } } public class SegmentTree<T> { // 1-indexed type int n; T[] Tree; Func<T, T, T> f; T ex; int L; [MethodImpl(MethodImplOptions.AggressiveInlining)] public SegmentTree(int size, Func<T, T, T> fun, T exvalue) { ex = exvalue; f = fun; n = 1; while (n < size) n <<= 1; Tree = new T[n << 1]; L = (n << 1) - 1; for (var i = 0; i <= L; i++) Tree[i] = ex; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public SegmentTree(int size, Func<T, T, T> fun, T exvalue, T[] initial) { ex = exvalue; n = 1; while (n < size) n <<= 1; f = fun; Tree = new T[n << 1]; L = (n << 1) - 1; for (var i = 0; i <= L; i++) Tree[i] = (n <= i && i <= n + initial.Length - 1) ? initial[i - n] : ex; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Set_All() { for (var i = n - 1; i >= 1; i--) Tree[i] = f(Tree[i << 1], Tree[(i << 1) | 1]); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Assign(int idx, T nxt) => Tree[idx + n] = nxt; [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Update(int idx) { int now = idx + n; while (now > 1) { now >>= 1; Tree[now] = f(Tree[now << 1], Tree[now << 1 | 1]); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Query_Update(int idx, T nxt) { Assign(idx, nxt); Update(idx); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Query_Update_func(int idx, T y) { Assign(idx, f(Peek(idx), y)); Update(idx); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Query_Fold(int l, int r) { int L = n + l; int R = n + r; T vL = ex, vR = ex; while (L < R) { if (L % 2 == 1) { vL = f(vL, Tree[L]); L++; } if (R % 2 == 1) { vR = f(Tree[R - 1], vR); R--; } L >>= 1; R >>= 1; } return f(vL, vR); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Peek(int idx) => Tree[idx + n]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Display(int len) { for (var i = 0; i < len; i++) Console.Write($"{Tree[i + n]} "); Console.WriteLine(); } } public class UnionFind { private int[] parent; private int[] rank; private int[] size; public UnionFind(int n) { parent = new int[n]; rank = new int[n]; size = new int[n]; for (var i = 0; i < n; i++) { parent[i] = i; rank[i] = 0; size[i] = 1; } } public int Root(int x) { return parent[x] == x ? x : parent[x] = Root(parent[x]); } public bool SameRoot(int x, int y) { return Root(x) == Root(y); } public void Unite(int x, int y) { x = Root(x); y = Root(y); if (x == y) { return; } if (rank[x] < rank[y]) { parent[x] = y; size[y] += size[x]; size[x] = 0; } else { parent[y] = x; if (rank[x] == rank[y]) { rank[x]++; } size[x] += size[y]; size[y] = 0; } } public int SizeOf(int x) { return size[Root(x)]; } } static class Cin { 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]); } } static class Cout { 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)); } }
[["-", 31, 213, 3, 4, 0, 28, 0, 252, 0, 253], ["+", 31, 213, 3, 4, 0, 28, 0, 252, 0, 253]]
8
3,743
2
using System; class A { static void Main() { char[] S = Console.ReadLine().ToCharArray(); bool N = false; bool So = false; bool W = false; bool E = false; for (int i = 0; i < S.Length; i++) { if (S[i].ToString() == "N") N = true; else if (S[i].ToString() == "S") So = true; else if (S[i].ToString() == "W") W = true; else if (S[i].ToString() == "E") E = true; } if (N == So || E == W) Console.WriteLine("No"); else Console.WriteLine("Yes"); } }
using System; class A { static void Main() { char[] S = Console.ReadLine().ToCharArray(); bool N = false; bool So = false; bool W = false; bool E = false; for (int i = 0; i < S.Length; i++) { if (S[i].ToString() == "N") N = true; else if (S[i].ToString() == "S") So = true; else if (S[i].ToString() == "W") W = true; else if (S[i].ToString() == "E") E = true; } if (N != So || E != W) Console.WriteLine("No"); else Console.WriteLine("Yes"); } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 79], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 79]]
8
175
4
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Numerics; 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() { var S = GetStr(); var n = S.Contains('n'); var s = S.Contains('s'); var w = S.Contains('w'); var e = S.Contains('e'); var ans = (n == s && w == e).YesNo(); 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 T[][] CreateJaggedArray<T>(int H, int W, T value) { return Enumerable.Repeat(0, H) .Select(s => Enumerable.Repeat(value, W).ToArray()) .ToArray(); } static public int[][] GetIntJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetIntArray().ToArray()) .ToArray(); } static public long[][] GetLongJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetLongArray().ToArray()) .ToArray(); } static public char[][] GetCharJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetStr().ToCharArray()) .ToArray(); } static public double[][] GetDoubleJaggedArray(int N) { return Enumerable.Repeat(0, N).Select(s => GetDoubleArray()).ToArray(); } static public void WriteObjects<T>(IReadOnlyCollection<T> values) { var array = values.ToArray(); var num = array.Length; if (num == 0) return; Console.Write(array[0]); for (int i = 1; i < num; i++) { Console.Write(" " + array[i]); } 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]); } static void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Numerics; 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() { var S = GetStr(); var n = S.Contains('N'); var s = S.Contains('S'); var w = S.Contains('W'); var e = S.Contains('E'); var ans = (n == s && w == e).YesNo(); 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 T[][] CreateJaggedArray<T>(int H, int W, T value) { return Enumerable.Repeat(0, H) .Select(s => Enumerable.Repeat(value, W).ToArray()) .ToArray(); } static public int[][] GetIntJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetIntArray().ToArray()) .ToArray(); } static public long[][] GetLongJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetLongArray().ToArray()) .ToArray(); } static public char[][] GetCharJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetStr().ToCharArray()) .ToArray(); } static public double[][] GetDoubleJaggedArray(int N) { return Enumerable.Repeat(0, N).Select(s => GetDoubleArray()).ToArray(); } static public void WriteObjects<T>(IReadOnlyCollection<T> values) { var array = values.ToArray(); var num = array.Length; if (num == 0) return; Console.Write(array[0]); for (int i = 1; i < num; i++) { Console.Write(" " + array[i]); } 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]); } static void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 252, 0, 253], ["+", 0, 213, 3, 4, 0, 28, 0, 252, 0, 253]]
8
1,564
8
using System; using System.Collections.Generic; using System.Linq; using System.Text; // using System.Numerics; using System.Runtime.CompilerServices; using System.Diagnostics; using ll=System.Int64; using static Contest_A.Lib_IO; using static Contest_A.Lib_Minifunc; public static class Contest_A { public static void Main() { checked{ string s; Lib_IO.rm(out s); HashSet<char> hs = new HashSet<char>(); foreach (var e in s) { hs.Add(e); } string ans = "No"; if(hs.Count==2&&hs.Contains('W')&&hs.Contains('W')) ans = "Yes"; if(hs.Count==2&&hs.Contains('N')&&hs.Contains('S')) ans = "Yes"; if(hs.Count==4) ans = "Yes"; Lib_IO.wm(ans); } } #region BaseModule public static class Lib_Minifunc{ [MethodImpl(256)] public static void swap1<T>(ref T a, ref T b) { T t = a; a = b; b = t; } [MethodImpl(256)] public static void swap2<T>(ref T a, ref T b) where T : IComparable { if (a.CompareTo(b)==1) swap1(ref a, ref b); } // b の方が小さければ交換 [MethodImpl(256)] public static bool chmin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b)== 1) { a = b; return true; } return false; } // b の方が小さければ a を更新 [MethodImpl(256)] public static bool chmax<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b)==-1) { a = b; return true; } return false; } // b の方が大きければ a を更新 [MethodImpl(256)] public static bool inside(long i, long n) => (0<=i&&i<n); [MethodImpl(256)] public static bool inside(long x, long y, long w, long h) => (inside(x,w)&&inside(y,h)); [MethodImpl(256)] public static T min<T>(params T[] a) where T : IComparable => a.Min(); [MethodImpl(256)] public static T max<T>(params T[] a) where T : IComparable => a.Max(); [MethodImpl(256)] public static long mod(long a, long m=MOD1) { var v = a%m; return (v<0?v+m:v); } [MethodImpl(256)] public static long ceiling(long a, long b) => (a%b==0?a/b:a/b+1); // 整数商の切り上げ [MethodImpl(256)] public static P<T,U> initp<T,U>(T a,U b) => new P<T,U>(a,b); [MethodImpl(256)] public static P<T,U,V> initp<T,U,V>(T a,U b,V c) => new P<T,U,V>(a,b,c); [MethodImpl(256)] public static P<T,U,V,W> initp<T,U,V,W>(T a,U b,V c,W d) => new P<T,U,V,W>(a,b,c,d); [MethodImpl(256)] public static bool initd<T,U>(Dictionary<T,U> d, T k) { if(d.ContainsKey(k)) { return false; } else { d[k] = default(U); return true; } } public static T[] inita<T>(long len1) where T : new() { var m = new T[len1]; for (int i=0;i<m.Length;i++) m[i] = new T(); return m; } public static T[][] initm<T>(long len1,long len2,T val) where T : struct { var m = new T[len1][]; for (int i=0;i<m.Length;i++) m[i] = Enumerable.Repeat(val,(int)len2).ToArray(); return m; } public static T[][][] initm<T>(long len1,long len2,long len3,T val) where T : struct { var m = new T[len1][][]; for (int i=0;i<m.Length;i++) m[i] = initm(len2,len3,val); return m; } public const long MOD1 = 1000000007; // 10^9+7 public const double EPS1 = 1e-8; public const long INF1 = 1000000000000000; // 10^15 } public struct P<T,U> { public T A; public U B; public P(T a,U b) { A = a; B = b; } public static implicit operator KeyValuePair<T,U>(P<T,U> a) => new KeyValuePair<T,U>(a.A,a.B); public static implicit operator P<T,U>(KeyValuePair<T,U> a) => new P<T,U>(a.Key,a.Value); } public struct P<T,U,V> { public T A; public U B; public V C; public P(T a,U b,V c) { A = a; B = b; C = c; } } public struct P<T,U,V,W> { public T A; public U B; public V C; public W D; public P(T a,U b,V c,W d) { A = a; B = b; C = c; D = d; } } public static class Lib_IO { class Prt : System.IO.StreamWriter { public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } } public Prt(System.IO.Stream s) : base(s,new UTF8Encoding(false,true)) {} public Prt(System.IO.Stream s,Encoding e) : base(s,e) {} } static Prt sw = new Prt(Console.OpenStandardOutput()); static char[] sp = new char[] {' '}; [MethodImpl(256)] static bool eq<T,U>() => typeof(T).Equals(typeof(U)); [MethodImpl(256)] static T ct<T,U>(U a) => (T)Convert.ChangeType(a,typeof(T)); [MethodImpl(256)] static T cv<T>(string s) => eq<T,int>() ? ct<T,int>(int.Parse(s)) : eq<T,long>() ? ct<T,long>(long.Parse(s)) : eq<T,double>() ? ct<T,double>(double.Parse(s,System.Globalization.CultureInfo.InvariantCulture)) : eq<T,char>() ? ct<T,char>(s[0]) : ct<T,string>(s); public static string[] rm<T>(out T a) { var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries); a = cv<T>(z[0]); return z; } public static string[] rm<T,U>(out T a,out U b) { var z = rm<T>(out a); b = cv<U>(z[1]); return z; } public static string[] rm<T,U,V>(out T a,out U b,out V c) { var z = rm<T,U>(out a,out b); c = cv<V>(z[2]); return z; } public static string[] rm<T,U,V,W>(out T a,out U b,out V c,out W d) { var z = rm<T,U,V>(out a,out b,out c); d = cv<W>(z[3]); return z; } public static string[] rm<T,U,V,W,X>(out T a,out U b,out V c,out W d,out X e) { var z = rm<T,U,V,W>(out a,out b,out c,out d); e = cv<X>(z[4]); return z; } public static string[] rm<T,U,V,W,X,Y>(out T a,out U b,out V c,out W d,out X e,out Y f) { var z = rm<T,U,V,W,X>(out a,out b,out c,out d,out e); f = cv<Y>(z[5]); return z; } public static string[] ra<T>(out T[] a) { var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries); a = z.Select(cv<T>).ToArray(); return z; } public static string[][] rl<T>(long n,out T[] a) { a = new T[n]; var y = new string[n][]; for(int i=0;i<n;i++) y[i] = rm(out a[i]); return y; } public static string[][] rl<T,U>(long n,out P<T,U>[] a) { a = new P<T,U>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; y[i] = rm(out o,out p); a[i] = new P<T,U>(o,p); } return y; } public static string[][] rl<T,U,V>(long n,out P<T,U,V>[] a) { a = new P<T,U,V>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; V q; y[i] = rm(out o,out p,out q); a[i] = new P<T,U,V>(o,p,q); } return y; } public static string[][] rl<T,U,V,W>(long n,out P<T,U,V,W>[] a) { a = new P<T,U,V,W>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; V q; W r; y[i] = rm(out o,out p,out q,out r); a[i] = new P<T,U,V,W>(o,p,q,r); } return y; } public static string[][] rx<T>(long n,out T[][] a) { a = new T[n][]; var y = new string[n][]; for(int i=0;i<n;i++) y[i] = ra(out a[i]); return y; } static void wwp(Action act){ sw.AutoFlush = false; Console.SetOut(sw); act(); Console.Out.Flush(); sw.AutoFlush = true; Console.SetOut(sw); } [MethodImpl(256)] static string wfm(Type t) =>t.Equals(typeof(double)) ? "{0:F10}" : "{0}"; public static void wm(params object[] a) { wwp(()=>{ for(int i=0;i<a.Length-1;i++) Console.Write(wfm(a[i].GetType())+" ",a[i]); Console.WriteLine(wfm(a[a.Length-1].GetType()),a[a.Length-1]); }); } public static void wa<T>(IList<T> a) { wxa(new IList<T>[]{a}, " "); } public static void wl<T>(IList<T> a) { wwp(()=>{ var f = wfm(typeof(T)); foreach(T x in a) Console.WriteLine(f,x); }); } static void wxa<T>(IList<IList<T>> a, string s) { wwp(()=>{ var f = wfm(typeof(T)); var g = f + s; foreach(var b in a) { for(int i=0;i<b.Count-1;i++) Console.Write(g,b[i]); Console.WriteLine(f,b[b.Count-1]); } }); } public static void wx<T>(IList<IList<T>> a) { wxa(a, " "); } public static void wg<T>(IList<IList<T>> a) { wxa(a, ""); } } #endregion }
using System; using System.Collections.Generic; using System.Linq; using System.Text; // using System.Numerics; using System.Runtime.CompilerServices; using System.Diagnostics; using ll=System.Int64; using static Contest_A.Lib_IO; using static Contest_A.Lib_Minifunc; public static class Contest_A { public static void Main() { checked{ string s; Lib_IO.rm(out s); HashSet<char> hs = new HashSet<char>(); foreach (var e in s) { hs.Add(e); } string ans = "No"; if(hs.Count==2&&hs.Contains('W')&&hs.Contains('E')) ans = "Yes"; if(hs.Count==2&&hs.Contains('N')&&hs.Contains('S')) ans = "Yes"; if(hs.Count==4) ans = "Yes"; Lib_IO.wm(ans); } } #region BaseModule public static class Lib_Minifunc{ [MethodImpl(256)] public static void swap1<T>(ref T a, ref T b) { T t = a; a = b; b = t; } [MethodImpl(256)] public static void swap2<T>(ref T a, ref T b) where T : IComparable { if (a.CompareTo(b)==1) swap1(ref a, ref b); } // b の方が小さければ交換 [MethodImpl(256)] public static bool chmin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b)== 1) { a = b; return true; } return false; } // b の方が小さければ a を更新 [MethodImpl(256)] public static bool chmax<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b)==-1) { a = b; return true; } return false; } // b の方が大きければ a を更新 [MethodImpl(256)] public static bool inside(long i, long n) => (0<=i&&i<n); [MethodImpl(256)] public static bool inside(long x, long y, long w, long h) => (inside(x,w)&&inside(y,h)); [MethodImpl(256)] public static T min<T>(params T[] a) where T : IComparable => a.Min(); [MethodImpl(256)] public static T max<T>(params T[] a) where T : IComparable => a.Max(); [MethodImpl(256)] public static long mod(long a, long m=MOD1) { var v = a%m; return (v<0?v+m:v); } [MethodImpl(256)] public static long ceiling(long a, long b) => (a%b==0?a/b:a/b+1); // 整数商の切り上げ [MethodImpl(256)] public static P<T,U> initp<T,U>(T a,U b) => new P<T,U>(a,b); [MethodImpl(256)] public static P<T,U,V> initp<T,U,V>(T a,U b,V c) => new P<T,U,V>(a,b,c); [MethodImpl(256)] public static P<T,U,V,W> initp<T,U,V,W>(T a,U b,V c,W d) => new P<T,U,V,W>(a,b,c,d); [MethodImpl(256)] public static bool initd<T,U>(Dictionary<T,U> d, T k) { if(d.ContainsKey(k)) { return false; } else { d[k] = default(U); return true; } } public static T[] inita<T>(long len1) where T : new() { var m = new T[len1]; for (int i=0;i<m.Length;i++) m[i] = new T(); return m; } public static T[][] initm<T>(long len1,long len2,T val) where T : struct { var m = new T[len1][]; for (int i=0;i<m.Length;i++) m[i] = Enumerable.Repeat(val,(int)len2).ToArray(); return m; } public static T[][][] initm<T>(long len1,long len2,long len3,T val) where T : struct { var m = new T[len1][][]; for (int i=0;i<m.Length;i++) m[i] = initm(len2,len3,val); return m; } public const long MOD1 = 1000000007; // 10^9+7 public const double EPS1 = 1e-8; public const long INF1 = 1000000000000000; // 10^15 } public struct P<T,U> { public T A; public U B; public P(T a,U b) { A = a; B = b; } public static implicit operator KeyValuePair<T,U>(P<T,U> a) => new KeyValuePair<T,U>(a.A,a.B); public static implicit operator P<T,U>(KeyValuePair<T,U> a) => new P<T,U>(a.Key,a.Value); } public struct P<T,U,V> { public T A; public U B; public V C; public P(T a,U b,V c) { A = a; B = b; C = c; } } public struct P<T,U,V,W> { public T A; public U B; public V C; public W D; public P(T a,U b,V c,W d) { A = a; B = b; C = c; D = d; } } public static class Lib_IO { class Prt : System.IO.StreamWriter { public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } } public Prt(System.IO.Stream s) : base(s,new UTF8Encoding(false,true)) {} public Prt(System.IO.Stream s,Encoding e) : base(s,e) {} } static Prt sw = new Prt(Console.OpenStandardOutput()); static char[] sp = new char[] {' '}; [MethodImpl(256)] static bool eq<T,U>() => typeof(T).Equals(typeof(U)); [MethodImpl(256)] static T ct<T,U>(U a) => (T)Convert.ChangeType(a,typeof(T)); [MethodImpl(256)] static T cv<T>(string s) => eq<T,int>() ? ct<T,int>(int.Parse(s)) : eq<T,long>() ? ct<T,long>(long.Parse(s)) : eq<T,double>() ? ct<T,double>(double.Parse(s,System.Globalization.CultureInfo.InvariantCulture)) : eq<T,char>() ? ct<T,char>(s[0]) : ct<T,string>(s); public static string[] rm<T>(out T a) { var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries); a = cv<T>(z[0]); return z; } public static string[] rm<T,U>(out T a,out U b) { var z = rm<T>(out a); b = cv<U>(z[1]); return z; } public static string[] rm<T,U,V>(out T a,out U b,out V c) { var z = rm<T,U>(out a,out b); c = cv<V>(z[2]); return z; } public static string[] rm<T,U,V,W>(out T a,out U b,out V c,out W d) { var z = rm<T,U,V>(out a,out b,out c); d = cv<W>(z[3]); return z; } public static string[] rm<T,U,V,W,X>(out T a,out U b,out V c,out W d,out X e) { var z = rm<T,U,V,W>(out a,out b,out c,out d); e = cv<X>(z[4]); return z; } public static string[] rm<T,U,V,W,X,Y>(out T a,out U b,out V c,out W d,out X e,out Y f) { var z = rm<T,U,V,W,X>(out a,out b,out c,out d,out e); f = cv<Y>(z[5]); return z; } public static string[] ra<T>(out T[] a) { var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries); a = z.Select(cv<T>).ToArray(); return z; } public static string[][] rl<T>(long n,out T[] a) { a = new T[n]; var y = new string[n][]; for(int i=0;i<n;i++) y[i] = rm(out a[i]); return y; } public static string[][] rl<T,U>(long n,out P<T,U>[] a) { a = new P<T,U>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; y[i] = rm(out o,out p); a[i] = new P<T,U>(o,p); } return y; } public static string[][] rl<T,U,V>(long n,out P<T,U,V>[] a) { a = new P<T,U,V>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; V q; y[i] = rm(out o,out p,out q); a[i] = new P<T,U,V>(o,p,q); } return y; } public static string[][] rl<T,U,V,W>(long n,out P<T,U,V,W>[] a) { a = new P<T,U,V,W>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; V q; W r; y[i] = rm(out o,out p,out q,out r); a[i] = new P<T,U,V,W>(o,p,q,r); } return y; } public static string[][] rx<T>(long n,out T[][] a) { a = new T[n][]; var y = new string[n][]; for(int i=0;i<n;i++) y[i] = ra(out a[i]); return y; } static void wwp(Action act){ sw.AutoFlush = false; Console.SetOut(sw); act(); Console.Out.Flush(); sw.AutoFlush = true; Console.SetOut(sw); } [MethodImpl(256)] static string wfm(Type t) =>t.Equals(typeof(double)) ? "{0:F10}" : "{0}"; public static void wm(params object[] a) { wwp(()=>{ for(int i=0;i<a.Length-1;i++) Console.Write(wfm(a[i].GetType())+" ",a[i]); Console.WriteLine(wfm(a[a.Length-1].GetType()),a[a.Length-1]); }); } public static void wa<T>(IList<T> a) { wxa(new IList<T>[]{a}, " "); } public static void wl<T>(IList<T> a) { wwp(()=>{ var f = wfm(typeof(T)); foreach(T x in a) Console.WriteLine(f,x); }); } static void wxa<T>(IList<IList<T>> a, string s) { wwp(()=>{ var f = wfm(typeof(T)); var g = f + s; foreach(var b in a) { for(int i=0;i<b.Count-1;i++) Console.Write(g,b[i]); Console.WriteLine(f,b[b.Count-1]); } }); } public static void wx<T>(IList<IList<T>> a) { wxa(a, " "); } public static void wg<T>(IList<IList<T>> a) { wxa(a, ""); } } #endregion }
[["-", 12, 213, 3, 4, 0, 28, 0, 252, 0, 253], ["+", 12, 213, 3, 4, 0, 28, 0, 252, 0, 253]]
8
3,006
2
using System; using System.Linq; namespace ABC042C { public class Program { public static void Main(string[] args) { var sr = new StreamReader(); //--------------------------------- var N = sr.Next<int>(); var K = sr.Next<int>(); var D = sr.Next<int>(K); for (var i = N; i < 10000; i++) { if (!i.ToString().ToList().Exists(c => D.Contains(c - '0'))) { Console.WriteLine(i); return; } } //--------------------------------- } } public class StreamReader { private readonly char[] _c = { ' ' }; private int _index = -1; private string[] _input = new string[0]; public T Next<T>() { if (_index == _input.Length - 1) { _index = -1; while (true) { string rl = Console.ReadLine(); if (rl == null) { if (typeof(T).IsClass) return default(T); return (T) typeof(T).GetField("MinValue").GetValue(null); } if (rl != "") { _input = rl.Split(_c, StringSplitOptions.RemoveEmptyEntries); break; } } } return (T)Convert.ChangeType( _input[++_index], typeof(T), System.Globalization.CultureInfo.InvariantCulture); } public T[] Next<T>(int x) { var ret = new T[x]; for (var i = 0; i < x; ++i) ret[i] = Next<T>(); return ret; } public T[][] Next<T>(int y, int x) { var ret = new T[y][]; for (var i = 0; i < y; ++i) ret[i] = Next<T>(x); return ret; } } }
using System; using System.Linq; namespace ABC042C { public class Program { public static void Main(string[] args) { var sr = new StreamReader(); //--------------------------------- var N = sr.Next<int>(); var K = sr.Next<int>(); var D = sr.Next<int>(K); for (var i = N; i < 100000; i++) { if (!i.ToString().ToList().Exists(c => D.Contains(c - '0'))) { Console.WriteLine(i); return; } } //--------------------------------- } } public class StreamReader { private readonly char[] _c = { ' ' }; private int _index = -1; private string[] _input = new string[0]; public T Next<T>() { if (_index == _input.Length - 1) { _index = -1; while (true) { string rl = Console.ReadLine(); if (rl == null) { if (typeof(T).IsClass) return default(T); return (T) typeof(T).GetField("MinValue").GetValue(null); } if (rl != "") { _input = rl.Split(_c, StringSplitOptions.RemoveEmptyEntries); break; } } } return (T)Convert.ChangeType( _input[++_index], typeof(T), System.Globalization.CultureInfo.InvariantCulture); } public T[] Next<T>(int x) { var ret = new T[x]; for (var i = 0; i < x; ++i) ret[i] = Next<T>(); return ret; } public T[][] Next<T>(int y, int x) { var ret = new T[y][]; for (var i = 0; i < y; ++i) ret[i] = Next<T>(x); return ret; } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203]]
8
419
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { const int MOD = 1000000007; const int INF = 1 << 30; static void Main(string[] args) { Solve(); } static void Solve() { Scaner sc = new Scaner(); write wr = new write(); Math2 mmath = new Math2(); //ここから var x = sc.IntArr; long H = x[0]; long W = x[1]; long A = x[2]; long B = x[3]; mmath.FactoricalModSet(200000); H--; W--; long ans = 0; for (int i = 0; i <= H - A; ++i) { ans += mmath.nCrMod(B + i - 1, i) * mmath.nCrMod(H - i + W - B, H - i) % MOD; } wr.wri(ans); } } class PriorityQueue<T> { private readonly List<T> heap; private readonly Comparison<T> compare; private int size; public PriorityQueue() : this(Comparer<T>.Default) {} public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) {} public PriorityQueue(Comparison<T> comparison) : this(16, comparison) {} public PriorityQueue(int capacity, Comparison<T> comparison) { this.heap = new List<T>(capacity); this.compare = comparison; } public void Enqueue(T item) { this.heap.Add(item); var i = size++; while (i > 0) { var p = (i - 1) >> 1; if (compare(this.heap[p], item) <= 0) break; this.heap[i] = heap[p]; i = p; } this.heap[i] = item; } public T Dequeue() { var ret = this.heap[0]; var x = this.heap[--size]; var i = 0; while ((i << 1) + 1 < size) { var a = (i << 1) + 1; var b = (i << 1) + 2; if (b < size && compare(heap[b], heap[a]) < 0) a = b; if (compare(heap[a], x) >= 0) break; heap[i] = heap[a]; i = a; } heap[i] = x; heap.RemoveAt(size); return ret; } public T Peek() { return heap[0]; } public int Count { get { return size; } } public bool Any() { return size > 0; } } class Math2 { public long[] Fact; // Nまでの階乗 public long[] invFact; //階乗の逆元 // Nまでの階乗をセットしておく public void FactoricalModSet(long N, long MOD = 1000000007) { Fact = new long[N + 1]; invFact = new long[N + 1]; Fact[0] = 1; for (long i = 1; i <= N; ++i) { Fact[i] = Fact[i - 1] * i % MOD; } invFact[N] = powMOD(Fact[N], MOD - 2); for (long i = N; i > 0; --i) { invFact[i - 1] = invFact[i] * i % MOD; } } public long nCrMod(long n, long r, long MOD = 1000000007) { return (Fact[n] * invFact[r] % MOD * invFact[n - r] % MOD); } public long powMOD(long x, long n, long MOD = 1000000007) { long res = 1; while (n > 0) { if ((n & 1) != 0) res = res * x % MOD; x = x * x % MOD; n >>= 1; } return res; } static long GCD(long x, long y) { if (y == 0) return x; return GCD(y, x % y); } static long LCM(long x, long y) { return x * y / GCD(x, y); } } class Scaner { public string Str => Console.ReadLine(); public string[] StrArr => Str.Split(' '); public long[] LongArr => StrArr.Select(long.Parse).ToArray(); public int[] IntArr => StrArr.Select(int.Parse).ToArray(); public char[] CharArr => Str.ToArray(); public long Long1 => LongArr[0]; public int Int1 => IntArr[0]; } class write { public void wri<T>(T x) { Console.WriteLine(x); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { const int MOD = 1000000007; const int INF = 1 << 30; static void Main(string[] args) { Solve(); } static void Solve() { Scaner sc = new Scaner(); write wr = new write(); Math2 mmath = new Math2(); //ここから var x = sc.IntArr; long H = x[0]; long W = x[1]; long A = x[2]; long B = x[3]; mmath.FactoricalModSet(1000000); H--; W--; long ans = 0; for (int i = 0; i <= H - A; ++i) { ans += mmath.nCrMod(B + i - 1, i) % MOD * mmath.nCrMod(H - i + W - B, H - i) % MOD; } wr.wri(ans % MOD); } } class PriorityQueue<T> { private readonly List<T> heap; private readonly Comparison<T> compare; private int size; public PriorityQueue() : this(Comparer<T>.Default) {} public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) {} public PriorityQueue(Comparison<T> comparison) : this(16, comparison) {} public PriorityQueue(int capacity, Comparison<T> comparison) { this.heap = new List<T>(capacity); this.compare = comparison; } public void Enqueue(T item) { this.heap.Add(item); var i = size++; while (i > 0) { var p = (i - 1) >> 1; if (compare(this.heap[p], item) <= 0) break; this.heap[i] = heap[p]; i = p; } this.heap[i] = item; } public T Dequeue() { var ret = this.heap[0]; var x = this.heap[--size]; var i = 0; while ((i << 1) + 1 < size) { var a = (i << 1) + 1; var b = (i << 1) + 2; if (b < size && compare(heap[b], heap[a]) < 0) a = b; if (compare(heap[a], x) >= 0) break; heap[i] = heap[a]; i = a; } heap[i] = x; heap.RemoveAt(size); return ret; } public T Peek() { return heap[0]; } public int Count { get { return size; } } public bool Any() { return size > 0; } } class Math2 { public long[] Fact; // Nまでの階乗 public long[] invFact; //階乗の逆元 // Nまでの階乗をセットしておく public void FactoricalModSet(long N, long MOD = 1000000007) { Fact = new long[N + 1]; invFact = new long[N + 1]; Fact[0] = 1; for (long i = 1; i <= N; ++i) { Fact[i] = Fact[i - 1] * i % MOD; } invFact[N] = powMOD(Fact[N], MOD - 2); for (long i = N; i > 0; --i) { invFact[i - 1] = invFact[i] * i % MOD; } } public long nCrMod(long n, long r, long MOD = 1000000007) { return (Fact[n] * invFact[r] % MOD * invFact[n - r] % MOD); } public long powMOD(long x, long n, long MOD = 1000000007) { long res = 1; while (n > 0) { if ((n & 1) != 0) res = res * x % MOD; x = x * x % MOD; n >>= 1; } return res; } static long GCD(long x, long y) { if (y == 0) return x; return GCD(y, x % y); } static long LCM(long x, long y) { return x * y / GCD(x, y); } } class Scaner { public string Str => Console.ReadLine(); public string[] StrArr => Str.Split(' '); public long[] LongArr => StrArr.Select(long.Parse).ToArray(); public int[] IntArr => StrArr.Select(int.Parse).ToArray(); public char[] CharArr => Str.ToArray(); public long Long1 => LongArr[0]; public int Int1 => IntArr[0]; } class write { public void wri<T>(T x) { Console.WriteLine(x); } }
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 11, 12, 16, 31, 16, 31, 16, 17, 109], ["+", 0, 11, 12, 16, 31, 16, 31, 16, 12, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 109], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
8
1,005
6
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Security.Cryptography.X509Certificates; namespace AtCoder.Contest.A { static class Program { public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Scanner cin = new Scanner(); int n = cin.NextInt(); var l = cin.ArrayInt(n).ToList(); l.Sort(); int ans = 0; for (int i = 0; i < n; i++) { if (i % 2 == 1) ans += l[i]; } Console.WriteLine(ans); Console.Out.Flush(); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string Next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return Next(); i = 0; return s[i++]; } public int NextInt() { return int.Parse(Next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = NextInt() + add; } return Array; } public long NextLong() { return long.Parse(Next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = NextLong() + add; } return Array; } public double NextDouble() { return double.Parse(Next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = NextDouble() + add; } return Array; } } }
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Security.Cryptography.X509Certificates; namespace AtCoder.Contest.A { static class Program { public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Scanner cin = new Scanner(); int n = cin.NextInt(); var l = cin.ArrayInt(2 * n).ToList(); l.Sort(); int ans = 0; for (int i = 0; i < 2 * n; i++) { if (i % 2 == 0) ans += l[i]; } Console.WriteLine(ans); Console.Out.Flush(); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string Next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return Next(); i = 0; return s[i++]; } public int NextInt() { return int.Parse(Next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = NextInt() + add; } return Array; } public long NextLong() { return long.Parse(Next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = NextLong() + add; } return Array; } public double NextDouble() { return double.Parse(Next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = NextDouble() + add; } return Array; } } }
[["+", 205, 213, 3, 4, 0, 28, 0, 16, 31, 203], ["+", 205, 213, 3, 4, 0, 28, 0, 16, 17, 48], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 31, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 48], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203]]
8
529
6
using System; public class c { public static void Main() { int N = int.Parse(Console.ReadLine()); string[] s = Console.ReadLine().Split(' '); int[] L = new int[N * 2]; for (int i = 0; i < 2 * N; i++) { L[i] = int.Parse(s[i]); } Array.Sort(L); int x = 0; for (int i = 0; i < N; i++) { x += L[i]; } Console.WriteLine(x); } }
using System; public class c { public static void Main() { int N = int.Parse(Console.ReadLine()); string[] s = Console.ReadLine().Split(' '); int[] L = new int[N * 2]; for (int i = 0; i < 2 * N; i++) { L[i] = int.Parse(s[i]); } Array.Sort(L); int x = 0; for (int i = 0; i < N; i++) { x += L[2 * i]; } Console.WriteLine(x); } }
[["+", 12, 204, 206, 207, 0, 28, 0, 16, 31, 203], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 48]]
8
136
2
using System; using System.Linq; class A { static void Main() { int n = int.Parse(Console.ReadLine()); int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray(); int ans = 0; Array.Sort(a); for (int i = 0; i < n; i++) { ans += a[i * 2 + 1]; } Console.WriteLine(ans); } }
using System; using System.Linq; class A { static void Main() { int n = int.Parse(Console.ReadLine()); int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray(); int ans = 0; Array.Sort(a); for (int i = 0; i < n; i++) { ans += a[i * 2]; } Console.WriteLine(ans); } }
[["-", 12, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
105
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[] L = Console.ReadLine().Split().Select(int.Parse).ToArray(); int ans = 0; Array.Sort(L); for (int i = 0; i < N / 2; i++) { ans += L[2 * i]; } Console.WriteLine(ans.ToString()); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[] L = Console.ReadLine().Split().Select(int.Parse).ToArray(); int ans = 0; Array.Sort(L); for (int i = 0; i < N; i++) { ans += L[2 * i]; } Console.WriteLine(ans.ToString()); } }
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 85], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
132
2
using System; using System.Linq; namespace agc001_a { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray(); Array.Sort(x); int a = x.Sum(); for (int i = 0; i < n; i++) { a -= x[i * 2]; } Console.WriteLine(a); } } }
using System; using System.Linq; namespace agc001_a { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray(); Array.Sort(x); int a = x.Sum(); for (int i = 1; i <= n; i++) { a -= x[i * 2 - 1]; } Console.WriteLine(a); } } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
115
6
using System; using System.Linq; namespace EasyBBQ { class MainClass { public static void Main(string[] args) { var combSetNum = int.Parse(Console.ReadLine()) / 2; var lengths = Console.ReadLine().Split(' '); var lengthsInt = lengths.Select(_ => int.Parse(_)).ToList(); lengthsInt = lengthsInt.OrderByDescending(_ => _).ToList(); var totalNum = 0; for (int i = 0; i < combSetNum; i++) { totalNum += lengthsInt[1]; lengthsInt.RemoveAt(0); lengthsInt.RemoveAt(0); } Console.WriteLine(totalNum); } } }
using System; using System.Linq; namespace EasyBBQ { class MainClass { public static void Main(string[] args) { var combSetNum = int.Parse(Console.ReadLine()); var lengths = Console.ReadLine().Split(' '); var lengthsInt = lengths.Select(_ => int.Parse(_)).ToList(); lengthsInt = lengthsInt.OrderByDescending(_ => _).ToList(); var totalNum = 0; for (int i = 0; i < combSetNum; i++) { totalNum += lengthsInt[1]; lengthsInt.RemoveAt(0); lengthsInt.RemoveAt(0); } Console.WriteLine(totalNum); } } }
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 85], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
145
2
using System; using System.Collections.Generic; using System.Linq; using System.Numerics; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { var str = Console.ReadLine(); var n = Int32.Parse(str); var l = new int[n]; var strs = Console.ReadLine().Split(); for (int i = 0; i < 2 * n; i++) { l[i] = Int32.Parse(strs[i]); } Console.WriteLine(Solver.Solve(l)); } } public class Solver { public static int Solve(int[] l) { var ret = 0; l = l.OrderByDescending(v => v).ToArray(); for (int i = 0; i < l.Length - 1; i += 2) ret += Math.Min(l[i], l[i + 1]); return ret; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Numerics; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { var str = Console.ReadLine(); var n = Int32.Parse(str); var l = new int[2 * n]; var strs = Console.ReadLine().Split(); for (int i = 0; i < 2 * n; i++) { l[i] = Int32.Parse(strs[i]); } Console.WriteLine(Solver.Solve(l)); } } public class Solver { public static int Solve(int[] l) { var ret = 0; l = l.OrderByDescending(v => v).ToArray(); for (int i = 0; i < l.Length - 1; i += 2) ret += Math.Min(l[i], l[i + 1]); return ret; } } }
[["+", 0, 227, 39, 224, 225, 226, 0, 16, 31, 203], ["+", 0, 227, 39, 224, 225, 226, 0, 16, 17, 48]]
8
215
2
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Convert; using static System.Math; // using Debug; // using static System.Globalization.CultureInfo; using System.Text; class Program { static void Main(string[] args) { Solve(); // WriteLine(Solve()); } static void Solve() { var nx = Input.arL; WriteLine(nx[0] + f(nx[1], nx[0] - nx[1])); } static long f(long a, long b) { var max = Max(a, b); var min = Min(a, b); if (max % min == 0) return max / min * 2 - min; return max / min * min * 2 + f(max % min, min); } } public class Input { public static string read => ReadLine(); public static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse); public static int num => ToInt32(read); public static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse); public static long numL => ToInt64(read); public static char[][] gred(int h) => Enumerable.Repeat(0, h).Select(v => read.ToCharArray()).ToArray(); public static int[][] ar2D(int num) => Enumerable.Repeat(0, num).Select(v => ar).ToArray(); public static long[][] arL2D(int num) => Enumerable.Repeat(0, num).Select(v => arL).ToArray(); public const long Inf = (long)1e18; public const double eps = 1e-6; public const string Alfa = "abcdefghijklmnopqrstuvwxyz"; public const int MOD = 1000000007; }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Convert; using static System.Math; // using Debug; // using static System.Globalization.CultureInfo; using System.Text; class Program { static void Main(string[] args) { Solve(); // WriteLine(Solve()); } static void Solve() { var nx = Input.arL; WriteLine(nx[0] + f(nx[1], nx[0] - nx[1])); } static long f(long a, long b) { var max = Max(a, b); var min = Min(a, b); if (max % min == 0) return max * 2 - min; return max / min * min * 2 + f(max % min, min); } } public class Input { public static string read => ReadLine(); public static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse); public static int num => ToInt32(read); public static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse); public static long numL => ToInt64(read); public static char[][] gred(int h) => Enumerable.Repeat(0, h).Select(v => read.ToCharArray()).ToArray(); public static int[][] ar2D(int num) => Enumerable.Repeat(0, num).Select(v => ar).ToArray(); public static long[][] arL2D(int num) => Enumerable.Repeat(0, num).Select(v => arL).ToArray(); public const long Inf = (long)1e18; public const double eps = 1e-6; public const string Alfa = "abcdefghijklmnopqrstuvwxyz"; public const int MOD = 1000000007; }
[["-", 64, 37, 0, 16, 31, 16, 31, 16, 17, 85], ["-", 64, 37, 0, 16, 31, 16, 31, 16, 12, 22]]
8
387
2
using System; class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int x = int.Parse(input[1]); int y = int.Parse(input[0]) - x; int sum = 0; sum += x; sum += y; while (x != 0) { sum += (2 * x) * (y / x); int tmp = y; y = x; x = tmp % x; } sum -= y; Console.WriteLine(sum); } }
using System; class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); ulong x = ulong.Parse(input[1]); ulong y = ulong.Parse(input[0]) - x; ulong sum = 0; sum += x; sum += y; while (x != 0) { sum += (2 * x) * (y / x); ulong tmp = y; y = x; x = tmp % x; } sum -= y; Console.WriteLine(sum); } }
[["-", 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, 212, 0, 16, 31, 213, 63, 214, 205, 199], ["+", 0, 212, 0, 16, 31, 213, 63, 214, 205, 199], ["-", 0, 52, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 52, 8, 196, 0, 197, 0, 198, 39, 199]]
8
125
12
using System; using System.Linq; //リストの使用 using System.Collections.Generic; class Program { static void Main() { string[] input = Console.ReadLine().Split( ' '); // Splitで区切り文字を指定して複数個受け取る。 long n = long.Parse(input[0]); long x = long.Parse(input[1]); long answer = 0; long a = 0; long b = 0; answer += n; a = Math.Min(x, n - x); b = Math.Max(x, n - x); while (true) { // Console.WriteLine(a + " " + b + " " + answer); answer += 2 * a * (b / a); if (b % a == 0) { answer -= a; break; } else { a = b % a; long temp = a; a = b; b = temp; } } Console.WriteLine(answer); // WriteLineをWriteとすると、改行なしで出力。 } }
using System; using System.Linq; //リストの使用 using System.Collections.Generic; class Program { static void Main() { string[] input = Console.ReadLine().Split( ' '); // Splitで区切り文字を指定して複数個受け取る。 long n = long.Parse(input[0]); long x = long.Parse(input[1]); long answer = 0; long a = 0; long b = 0; answer += n; a = Math.Min(x, n - x); b = Math.Max(x, n - x); while (true) { // Console.WriteLine(a + " " + b + " " + answer); answer += 2 * a * (b / a); if (b % a == 0) { answer -= a; break; } else { b = b % a; long temp = a; a = b; b = temp; } } Console.WriteLine(answer); // WriteLineをWriteとすると、改行なしで出力。 } }
[["-", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22]]
8
182
2
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using static System.Console; using static System.Math; //using CS_Contest.Graph; using CS_Contest.Loop; using CS_Contest.Utils; using static Nakov.IO.Cin; using static CS_Contest.IO.IO; using static CS_Contest.Utils.MyMath; namespace CS_Contest { using Li = List<int>; using LLi = List<List<int>>; using Ll = List<long>; using ti3 = Tuple<int, int, int>; using ti2 = Tuple<int, int>; internal class Program { private static void Main(string[] args) { var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; SetOut(sw); new Calc().Solve(); Out.Flush(); } public class Calc { public void Solve() { int N = NextInt(), X = NextInt(); Func<long, long, long> rc = null; rc = (a, b) => { var x = Min(a, b); var y = Max(a, b); if (y % x == 0) return y / x * x * 2 - x; return 2 * x * (y / x) + rc(x, y % x); }; (N + rc(X, N - X)).WL(); } } } } namespace Nakov.IO { using System; using System.Text; using System.Globalization; public static class Cin { public static string NextToken() { StringBuilder tokenChars = new StringBuilder(); bool tokenFinished = false; bool skipWhiteSpaceMode = true; while (!tokenFinished) { int nextChar = Console.Read(); if (nextChar == -1) { tokenFinished = true; } else { char ch = (char)nextChar; if (char.IsWhiteSpace(ch)) { if (!skipWhiteSpaceMode) { tokenFinished = true; if (ch == '\r' && (Environment.NewLine == "\r\n")) { Console.Read(); } } } else { skipWhiteSpaceMode = false; tokenChars.Append(ch); } } } string token = tokenChars.ToString(); return token; } public static int NextInt() { string token = Cin.NextToken(); return int.Parse(token); } public static long NextLong() { string token = Cin.NextToken(); return long.Parse(token); } public static double NextDouble(bool acceptAnyDecimalSeparator = true) { string token = Cin.NextToken(); if (acceptAnyDecimalSeparator) { token = token.Replace(',', '.'); double result = double.Parse(token, CultureInfo.InvariantCulture); return result; } else { double result = double.Parse(token); return result; } } public static decimal NextDecimal(bool acceptAnyDecimalSeparator = true) { string token = Cin.NextToken(); if (acceptAnyDecimalSeparator) { token = token.Replace(',', '.'); decimal result = decimal.Parse(token, CultureInfo.InvariantCulture); return result; } else { decimal result = decimal.Parse(token); return result; } } } } namespace CS_Contest.Loop { [DebuggerStepThrough] public static class Loop { public static void REP(this int n, Action<int> act) { for (var i = 0; i < n; i++) { act(i); } } public static void ForeachWith<T>(this IEnumerable<T> ie, Action<int, T> act) { var i = 0; foreach (var item in ie) { act(i, item); i++; } } public static void Foreach<T>(this IEnumerable<T> ie, Action<T> act) { foreach (var item in ie) { act(item); } } } } namespace CS_Contest.IO { using Li = List<int>; using Ll = List<long>; public static class IO { public static void WL(this object obj) => WriteLine(obj); public static void WL(this string obj) => WriteLine(obj); public static void WL<T>(this IEnumerable<T> list) => list.ToList().ForEach(x => x.WL()); public static Li NextIntList() => ReadLine().Split().Select(int.Parse).ToList(); public static Ll NextLongList() => ReadLine().Split().Select(long.Parse).ToList(); public static T Tee<T>(this T t, Func<T, string> formatter = null) { if (formatter == null) formatter = arg => arg.ToString(); formatter(t).WL(); return t; } public static void JoinWL<T>(this IEnumerable<T> @this, string sp = " ") => @this.StringJoin(sp).WL(); public static void W(this object @this) => Write(@this); } } namespace CS_Contest.Utils { using Li = List<int>; using Ll = List<long>; [DebuggerStepThrough] public static class Utils { public static List<T> Repeat<T>(Func<int, T> result, int range) => Enumerable.Range(0, range).Select(result).ToList(); public static bool Within(int x, int y, int lx, int ly) => !(x < 0 || x >= lx || y < 0 || y >= ly); public static void Add<T1, T2>(this List<Tuple<T1, T2>> list, T1 t1, T2 t2) => list.Add(new Tuple<T1, T2>(t1, t2)); public static string StringJoin<T>(this IEnumerable<T> l, string separator = "") => string.Join(separator, l); public static Queue<T> ToQueue<T>(this IEnumerable<T> iEnumerable) { var rt = new Queue<T>(); foreach (var item in iEnumerable) { rt.Enqueue(item); } return rt; } public static void Swap<T>(ref T x, ref T y) { var tmp = x; x = y; y = tmp; } public static Dictionary<TKey, int> CountUp<TKey>(this IEnumerable<TKey> l) { var dic = new Dictionary<TKey, int>(); foreach (var item in l) { if (dic.ContainsKey(item)) dic[item]++; else dic.Add(item, 1); } return dic; } public static int Count<T>(this IEnumerable<T> l, T target) => l.Count(x => x.Equals(target)); public static IEnumerable<T> SkipAt<T>(this IEnumerable<T> @this, int at) { var enumerable = @this as T[] ?? @this.ToArray(); for (var i = 0; i < enumerable.Count(); i++) { if (i == at) continue; yield return enumerable.ElementAt(i); } } } public class Map<TKey, TValue> : Dictionary<TKey, TValue> { public Map() : base() { } public Map(int capacity) : base(capacity) { } public new TValue this[TKey index] { get { TValue v; return this.TryGetValue(index, out v) ? v : base[index] = default(TValue); } set { base[index] = value; } } } public static class MyMath { public static T EMin<T>(params T[] a) where T : IComparable<T> => a.Min(); public static T EMax<T>(params T[] a) where T : IComparable<T> => a.Max(); } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using static System.Console; using static System.Math; //using CS_Contest.Graph; using CS_Contest.Loop; using CS_Contest.Utils; using static Nakov.IO.Cin; using static CS_Contest.IO.IO; using static CS_Contest.Utils.MyMath; namespace CS_Contest { using Li = List<int>; using LLi = List<List<int>>; using Ll = List<long>; using ti3 = Tuple<int, int, int>; using ti2 = Tuple<int, int>; internal class Program { private static void Main(string[] args) { var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; SetOut(sw); new Calc().Solve(); Out.Flush(); } public class Calc { public void Solve() { long N = NextLong(), X = NextLong(); Func<long, long, long> rc = null; rc = (a, b) => { var x = Min(a, b); var y = Max(a, b); if (y % x == 0) return y / x * x * 2 - x; return 2 * x * (y / x) + rc(x, y % x); }; (N + rc(X, N - X)).WL(); } } } } namespace Nakov.IO { using System; using System.Text; using System.Globalization; public static class Cin { public static string NextToken() { StringBuilder tokenChars = new StringBuilder(); bool tokenFinished = false; bool skipWhiteSpaceMode = true; while (!tokenFinished) { int nextChar = Console.Read(); if (nextChar == -1) { tokenFinished = true; } else { char ch = (char)nextChar; if (char.IsWhiteSpace(ch)) { if (!skipWhiteSpaceMode) { tokenFinished = true; if (ch == '\r' && (Environment.NewLine == "\r\n")) { Console.Read(); } } } else { skipWhiteSpaceMode = false; tokenChars.Append(ch); } } } string token = tokenChars.ToString(); return token; } public static int NextInt() { string token = Cin.NextToken(); return int.Parse(token); } public static long NextLong() { string token = Cin.NextToken(); return long.Parse(token); } public static double NextDouble(bool acceptAnyDecimalSeparator = true) { string token = Cin.NextToken(); if (acceptAnyDecimalSeparator) { token = token.Replace(',', '.'); double result = double.Parse(token, CultureInfo.InvariantCulture); return result; } else { double result = double.Parse(token); return result; } } public static decimal NextDecimal(bool acceptAnyDecimalSeparator = true) { string token = Cin.NextToken(); if (acceptAnyDecimalSeparator) { token = token.Replace(',', '.'); decimal result = decimal.Parse(token, CultureInfo.InvariantCulture); return result; } else { decimal result = decimal.Parse(token); return result; } } } } namespace CS_Contest.Loop { [DebuggerStepThrough] public static class Loop { public static void REP(this int n, Action<int> act) { for (var i = 0; i < n; i++) { act(i); } } public static void ForeachWith<T>(this IEnumerable<T> ie, Action<int, T> act) { var i = 0; foreach (var item in ie) { act(i, item); i++; } } public static void Foreach<T>(this IEnumerable<T> ie, Action<T> act) { foreach (var item in ie) { act(item); } } } } namespace CS_Contest.IO { using Li = List<int>; using Ll = List<long>; public static class IO { public static void WL(this object obj) => WriteLine(obj); public static void WL(this string obj) => WriteLine(obj); public static void WL<T>(this IEnumerable<T> list) => list.ToList().ForEach(x => x.WL()); public static Li NextIntList() => ReadLine().Split().Select(int.Parse).ToList(); public static Ll NextLongList() => ReadLine().Split().Select(long.Parse).ToList(); public static T Tee<T>(this T t, Func<T, string> formatter = null) { if (formatter == null) formatter = arg => arg.ToString(); formatter(t).WL(); return t; } public static void JoinWL<T>(this IEnumerable<T> @this, string sp = " ") => @this.StringJoin(sp).WL(); public static void W(this object @this) => Write(@this); } } namespace CS_Contest.Utils { using Li = List<int>; using Ll = List<long>; [DebuggerStepThrough] public static class Utils { public static List<T> Repeat<T>(Func<int, T> result, int range) => Enumerable.Range(0, range).Select(result).ToList(); public static bool Within(int x, int y, int lx, int ly) => !(x < 0 || x >= lx || y < 0 || y >= ly); public static void Add<T1, T2>(this List<Tuple<T1, T2>> list, T1 t1, T2 t2) => list.Add(new Tuple<T1, T2>(t1, t2)); public static string StringJoin<T>(this IEnumerable<T> l, string separator = "") => string.Join(separator, l); public static Queue<T> ToQueue<T>(this IEnumerable<T> iEnumerable) { var rt = new Queue<T>(); foreach (var item in iEnumerable) { rt.Enqueue(item); } return rt; } public static void Swap<T>(ref T x, ref T y) { var tmp = x; x = y; y = tmp; } public static Dictionary<TKey, int> CountUp<TKey>(this IEnumerable<TKey> l) { var dic = new Dictionary<TKey, int>(); foreach (var item in l) { if (dic.ContainsKey(item)) dic[item]++; else dic.Add(item, 1); } return dic; } public static int Count<T>(this IEnumerable<T> l, T target) => l.Count(x => x.Equals(target)); public static IEnumerable<T> SkipAt<T>(this IEnumerable<T> @this, int at) { var enumerable = @this as T[] ?? @this.ToArray(); for (var i = 0; i < enumerable.Count(); i++) { if (i == at) continue; yield return enumerable.ElementAt(i); } } } public class Map<TKey, TValue> : Dictionary<TKey, TValue> { public Map() : base() { } public Map(int capacity) : base(capacity) { } public new TValue this[TKey index] { get { TValue v; return this.TryGetValue(index, out v) ? v : base[index] = default(TValue); } set { base[index] = value; } } } public static class MyMath { public static T EMin<T>(params T[] a) where T : IComparable<T> => a.Min(); public static T EMax<T>(params T[] a) where T : IComparable<T> => a.Max(); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22]]
8
1,650
6
using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; namespace CF317 { internal class Program { private static void Main(string[] args) { var sr = new InputReader(Console.In); // var sr = new InputReader(new StreamReader("input.txt")); var task = new Task(); using (var sw = Console.Out) // using (var sw = new StreamWriter("output.txt")) { task.Solve(sr, sw); // Console.ReadKey(); } } } internal class Task { public void Solve(InputReader sr, TextWriter sw) { var input = sr.ReadArray(Int64.Parse); var n = input[0]; var x = input[1]; sw.WriteLine(Count(x, n - x, true, x)); } private long Count(long curr, long step, bool isEven, long currCount) { if (isEven) { if (curr % step == 0) return currCount + 2 * (curr / step); currCount += (2L * (curr / step) + 1L) * step; return Count(step, curr - (curr / step) * step, false, currCount); } if (curr % step == 0) return currCount + (2 * (curr / step) - 1L) * step; currCount += (2L * (curr / step)) * step; return Count(step, curr - (curr / step) * step, false, currCount); } } } internal class InputReader : IDisposable { private bool isDispose; private readonly TextReader sr; public InputReader(TextReader stream) { sr = stream; } public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } public string NextString() { var result = sr.ReadLine(); return result; } public int NextInt32() { return Int32.Parse(NextString()); } public long NextInt64() { return Int64.Parse(NextString()); } public string[] NextSplitStrings() { return NextString().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); } public T[] ReadArray<T>(Func<string, CultureInfo, T> func) { return NextSplitStrings() .Select(s => func(s, CultureInfo.InvariantCulture)) .ToArray(); } public T[] ReadArrayFromString<T>(Func<string, CultureInfo, T> func, string str) { return str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .Select(s => func(s, CultureInfo.InvariantCulture)) .ToArray(); } protected void Dispose(bool dispose) { if (!isDispose) { if (dispose) sr.Close(); isDispose = true; } } ~InputReader() { Dispose(false); } }
using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; namespace CF317 { internal class Program { private static void Main(string[] args) { var sr = new InputReader(Console.In); // var sr = new InputReader(new StreamReader("input.txt")); var task = new Task(); using (var sw = Console.Out) // using (var sw = new StreamWriter("output.txt")) { task.Solve(sr, sw); // Console.ReadKey(); } } } internal class Task { public void Solve(InputReader sr, TextWriter sw) { var input = sr.ReadArray(Int64.Parse); var n = input[0]; var x = input[1]; sw.WriteLine(Count(x, n - x, true, x)); } private long Count(long curr, long step, bool isEven, long currCount) { if (isEven) { if (curr % step == 0) return currCount + (2 * (curr / step)) * step; currCount += (2L * (curr / step) + 1L) * step; return Count(step, curr - (curr / step) * step, false, currCount); } if (curr % step == 0) return currCount + (2 * (curr / step) - 1L) * step; currCount += (2L * (curr / step)) * step; return Count(step, curr - (curr / step) * step, false, currCount); } } } internal class InputReader : IDisposable { private bool isDispose; private readonly TextReader sr; public InputReader(TextReader stream) { sr = stream; } public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } public string NextString() { var result = sr.ReadLine(); return result; } public int NextInt32() { return Int32.Parse(NextString()); } public long NextInt64() { return Int64.Parse(NextString()); } public string[] NextSplitStrings() { return NextString().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); } public T[] ReadArray<T>(Func<string, CultureInfo, T> func) { return NextSplitStrings() .Select(s => func(s, CultureInfo.InvariantCulture)) .ToArray(); } public T[] ReadArrayFromString<T>(Func<string, CultureInfo, T> func, string str) { return str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .Select(s => func(s, CultureInfo.InvariantCulture)) .ToArray(); } protected void Dispose(bool dispose) { if (!isDispose) { if (dispose) sr.Close(); isDispose = true; } } ~InputReader() { Dispose(false); } }
[["+", 64, 37, 0, 16, 12, 16, 31, 23, 0, 24], ["+", 12, 16, 31, 23, 0, 16, 12, 23, 0, 25], ["+", 0, 57, 64, 37, 0, 16, 12, 16, 17, 48], ["+", 0, 57, 64, 37, 0, 16, 12, 16, 12, 22]]
8
565
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using Pair = System.Collections.Generic.KeyValuePair<int, int>; class Program { public Program() {} static void Main(string[] args) { new Program().prog(); } Scanner cin; const int MOD = 1000000007; const int INF = int.MaxValue; const double EPS = 1e-7; const double PI = 3.1415926536; void prog() { cin = new Scanner(); int[,] dir8 = new int[8, 2] { { -1, -1 }, { -1, 0 }, { -1, 1 }, { 0, -1 }, { 0, 1 }, { 1, -1 }, { 1, 0 }, { 1, 1 } }; int[,] dir4 = new int[4, 2] { { -1, 0 }, { 0, -1 }, { 0, 1 }, { 1, 0 } }; long N = cin.nextInt(); long X = cin.nextInt(); long gcd = Gcd(N, X); Console.WriteLine(gcd * ((N / gcd - 1) * 3)); } // 最大公約数 long Gcd(long a, long b) { if (b == 0) return a; else return Gcd(b, a % b); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return next(); } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using Pair = System.Collections.Generic.KeyValuePair<int, int>; class Program { public Program() {} static void Main(string[] args) { new Program().prog(); } Scanner cin; const int MOD = 1000000007; const int INF = int.MaxValue; const double EPS = 1e-7; const double PI = 3.1415926536; void prog() { cin = new Scanner(); int[,] dir8 = new int[8, 2] { { -1, -1 }, { -1, 0 }, { -1, 1 }, { 0, -1 }, { 0, 1 }, { 1, -1 }, { 1, 0 }, { 1, 1 } }; int[,] dir4 = new int[4, 2] { { -1, 0 }, { 0, -1 }, { 0, 1 }, { 1, 0 } }; long N = cin.nextLong(); long X = cin.nextLong(); long gcd = Gcd(N, X); Console.WriteLine(gcd * ((N / gcd - 1) * 3)); } // 最大公約数 long Gcd(long a, long b) { if (b == 0) return a; else return Gcd(b, a % b); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return next(); } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22]]
8
466
4
using System; using System.Collections.Generic; using System.Linq; using System.IO; class Program { const int M = 1000000007; const double eps = 1e-9; static int[] dd = { 0, 1, 0, -1, 0 }; static void Main() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; var sc = new Scan(); var a = sc.IntArr; var mt = new mymath(); var g = mt.gcd(a[0], a[1]); sw.WriteLine((a[0] / g - 1) * 3 * g); sw.Flush(); } static void swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } static T[] copy<T>(T[] a) { var ret = new T[a.Length]; for (int i = 0; i < a.Length; i++) ret[i] = a[i]; return ret; } static T[][] copy2<T>(T[][] a) { var ret = new T[a.Length][]; for (int i = 0; i < a.Length; i++) { ret[i] = new T[a[0].Length]; for (int j = 0; j < a[0].Length; j++) ret[i][j] = a[i][j]; } return ret; } } class Scan { public int Int { get { return int.Parse(Str); } } public long Long { get { return long.Parse(Str); } } public double Double { get { return double.Parse(Str); } } public string Str { get { return Console.ReadLine().Trim(); } } public int[] IntArr { get { return StrArr.Select(int.Parse).ToArray(); } } public int[] IntArrWithSep(char sep) { return Str.Split(sep).Select(int.Parse).ToArray(); } public long[] LongArr { get { return StrArr.Select(long.Parse).ToArray(); } } public double[] DoubleArr { get { return StrArr.Select(double.Parse).ToArray(); } } public string[] StrArr { get { return Str.Split(); } } public void Multi(out int a, out int b) { var arr = IntArr; a = arr[0]; b = arr[1]; } public void Multi(out int a, out int b, out int c) { var arr = IntArr; a = arr[0]; b = arr[1]; c = arr[2]; } public void Multi(out int a, out string b) { var arr = StrArr; a = int.Parse(arr[0]); b = arr[1]; } public void Multi(out string a, out int b) { var arr = StrArr; a = arr[0]; b = int.Parse(arr[1]); } public void Multi(out int a, out char b) { var arr = StrArr; a = int.Parse(arr[0]); b = arr[1][0]; } public void Multi(out char a, out int b) { var arr = StrArr; a = arr[0][0]; b = int.Parse(arr[1]); } public void Multi(out long a, out long b) { var arr = LongArr; a = arr[0]; b = arr[1]; } public void Multi(out long a, out int b) { var arr = LongArr; a = arr[0]; b = (int)arr[1]; } public void Multi(out int a, out long b) { var arr = LongArr; a = (int)arr[0]; b = arr[1]; } public void Multi(out string a, out string b) { var arr = StrArr; a = arr[0]; b = arr[1]; } } class mymath { public bool isprime(long a) { if (a < 2) return false; for (long i = 2; i * i <= a; i++) if (a % i == 0) return false; return true; } public long[][] powmat(long[][] A, long n, int M) { var E = new long [A.Length][]; for (int i = 0; i < A.Length; i++) { E[i] = new long[A.Length]; E[i][i] = 1; } if (n == 0) return E; var t = powmat(A, n / 2, M); if ((n & 1) == 0) return mulmat(t, t, M); return mulmat(mulmat(t, t, M), A, M); } public long[] mulmat(long[][] A, long[] x, int M) { var ans = new long[A.Length]; for (int i = 0; i < A.Length; i++) for (int j = 0; j < x.Length; j++) ans[i] = (ans[i] + x[j] * A[i][j]) % M; return ans; } public long[][] mulmat(long[][] A, long[][] B, int M) { var ans = new long [A.Length][]; for (int i = 0; i < A.Length; i++) { ans[i] = new long[B[0].Length]; for (int j = 0; j < B[0].Length; j++) for (int k = 0; k < B.Length; k++) ans[i][j] = (ans[i][j] + A[i][k] * B[k][j]) % M; } return ans; } public long powmod(long a, long b, long M) { if (a == 0) return 0; if (b == 0) return 1; var t = powmod(a, b / 2, M); if ((b & 1) == 0) return t * t % M; return t * t % M * a % M; } public long gcd(long a, long b) { while (b > 0) { var t = a % b; a = b; b = t; } return a; } public long lcm(long a, long b) { return a * (b / gcd(a, b)); } public long Comb(int n, int r) { const int M = 1000000007; if (n < 0 || r < 0 || r > n) return 0; if (n - r < r) r = n - r; if (r == 0) return 1; if (r == 1) return n; var numerator = new int[r]; var denominator = new int[r]; for (int k = 0; k < r; k++) { numerator[k] = n - r + k + 1; denominator[k] = k + 1; } for (int p = 2; p <= r; p++) { int pivot = denominator[p - 1]; if (pivot > 1) { int offset = (n - r) % p; for (int k = p - 1; k < r; k += p) { numerator[k - offset] /= pivot; denominator[k] /= pivot; } } } long result = 1; for (int k = 0; k < r; k++) if (numerator[k] > 1) result = result * numerator[k] % M; return result; } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; class Program { const int M = 1000000007; const double eps = 1e-9; static int[] dd = { 0, 1, 0, -1, 0 }; static void Main() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; var sc = new Scan(); var a = sc.LongArr; var mt = new mymath(); var g = mt.gcd(a[0], a[1]); sw.WriteLine((a[0] / g - 1) * 3 * g); sw.Flush(); } static void swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } static T[] copy<T>(T[] a) { var ret = new T[a.Length]; for (int i = 0; i < a.Length; i++) ret[i] = a[i]; return ret; } static T[][] copy2<T>(T[][] a) { var ret = new T[a.Length][]; for (int i = 0; i < a.Length; i++) { ret[i] = new T[a[0].Length]; for (int j = 0; j < a[0].Length; j++) ret[i][j] = a[i][j]; } return ret; } } class Scan { public int Int { get { return int.Parse(Str); } } public long Long { get { return long.Parse(Str); } } public double Double { get { return double.Parse(Str); } } public string Str { get { return Console.ReadLine().Trim(); } } public int[] IntArr { get { return StrArr.Select(int.Parse).ToArray(); } } public int[] IntArrWithSep(char sep) { return Str.Split(sep).Select(int.Parse).ToArray(); } public long[] LongArr { get { return StrArr.Select(long.Parse).ToArray(); } } public double[] DoubleArr { get { return StrArr.Select(double.Parse).ToArray(); } } public string[] StrArr { get { return Str.Split(); } } public void Multi(out int a, out int b) { var arr = IntArr; a = arr[0]; b = arr[1]; } public void Multi(out int a, out int b, out int c) { var arr = IntArr; a = arr[0]; b = arr[1]; c = arr[2]; } public void Multi(out int a, out string b) { var arr = StrArr; a = int.Parse(arr[0]); b = arr[1]; } public void Multi(out string a, out int b) { var arr = StrArr; a = arr[0]; b = int.Parse(arr[1]); } public void Multi(out int a, out char b) { var arr = StrArr; a = int.Parse(arr[0]); b = arr[1][0]; } public void Multi(out char a, out int b) { var arr = StrArr; a = arr[0][0]; b = int.Parse(arr[1]); } public void Multi(out long a, out long b) { var arr = LongArr; a = arr[0]; b = arr[1]; } public void Multi(out long a, out int b) { var arr = LongArr; a = arr[0]; b = (int)arr[1]; } public void Multi(out int a, out long b) { var arr = LongArr; a = (int)arr[0]; b = arr[1]; } public void Multi(out string a, out string b) { var arr = StrArr; a = arr[0]; b = arr[1]; } } class mymath { public bool isprime(long a) { if (a < 2) return false; for (long i = 2; i * i <= a; i++) if (a % i == 0) return false; return true; } public long[][] powmat(long[][] A, long n, int M) { var E = new long [A.Length][]; for (int i = 0; i < A.Length; i++) { E[i] = new long[A.Length]; E[i][i] = 1; } if (n == 0) return E; var t = powmat(A, n / 2, M); if ((n & 1) == 0) return mulmat(t, t, M); return mulmat(mulmat(t, t, M), A, M); } public long[] mulmat(long[][] A, long[] x, int M) { var ans = new long[A.Length]; for (int i = 0; i < A.Length; i++) for (int j = 0; j < x.Length; j++) ans[i] = (ans[i] + x[j] * A[i][j]) % M; return ans; } public long[][] mulmat(long[][] A, long[][] B, int M) { var ans = new long [A.Length][]; for (int i = 0; i < A.Length; i++) { ans[i] = new long[B[0].Length]; for (int j = 0; j < B[0].Length; j++) for (int k = 0; k < B.Length; k++) ans[i][j] = (ans[i][j] + A[i][k] * B[k][j]) % M; } return ans; } public long powmod(long a, long b, long M) { if (a == 0) return 0; if (b == 0) return 1; var t = powmod(a, b / 2, M); if ((b & 1) == 0) return t * t % M; return t * t % M * a % M; } public long gcd(long a, long b) { while (b > 0) { var t = a % b; a = b; b = t; } return a; } public long lcm(long a, long b) { return a * (b / gcd(a, b)); } public long Comb(int n, int r) { const int M = 1000000007; if (n < 0 || r < 0 || r > n) return 0; if (n - r < r) r = n - r; if (r == 0) return 1; if (r == 1) return n; var numerator = new int[r]; var denominator = new int[r]; for (int k = 0; k < r; k++) { numerator[k] = n - r + k + 1; denominator[k] = k + 1; } for (int p = 2; p <= r; p++) { int pivot = denominator[p - 1]; if (pivot > 1) { int offset = (n - r) % p; for (int k = p - 1; k < r; k += p) { numerator[k - offset] /= pivot; denominator[k] /= pivot; } } } long result = 1; for (int k = 0; k < r; k++) if (numerator[k] > 1) result = result * numerator[k] % M; return result; } }
[["-", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22]]
8
1,718
2
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Globalization; using System.Diagnostics; class Myon { public Myon() {} public static int Main() { new Myon().calc(); return 0; } Scanner cin; List<int>[] es; void calc() { cin = new Scanner(); int N = cin.nextInt(); int K = cin.nextInt(); es = new List<int>[N]; for (int i = 0; i < N; i++) { es[i] = new List<int>(); } for (int i = 0; i < N - 1; i++) { int a = cin.nextInt() - 1; int b = cin.nextInt() - 1; es[a].Add(b); es[b].Add(a); } int ans = 0; for (int i = 0; i < N; i++) { List<int> over = new List<int>(); List<int> under = new List<int>(); foreach (var item in es[i]) { over.Add(dfs(item, i, (K + 1) / 2)); under.Add(dfs(item, i, (K + 1) / 2)); } int sum = under.Sum(); for (int j = 0; j < over.Count; j++) { ans = Math.Max(ans, sum - under[j] + over[j] + 1); } } ans = N - ans; Console.WriteLine(ans); } int dfs(int a, int pre, int dep) { if (dep <= 0) return 0; int ans = 1; foreach (var next in es[a]) { if (next == pre) continue; ans += dfs(next, a, dep - 1); } return ans; } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Globalization; using System.Diagnostics; class Myon { public Myon() {} public static int Main() { new Myon().calc(); return 0; } Scanner cin; List<int>[] es; void calc() { cin = new Scanner(); int N = cin.nextInt(); int K = cin.nextInt(); es = new List<int>[N]; for (int i = 0; i < N; i++) { es[i] = new List<int>(); } for (int i = 0; i < N - 1; i++) { int a = cin.nextInt() - 1; int b = cin.nextInt() - 1; es[a].Add(b); es[b].Add(a); } int ans = 0; for (int i = 0; i < N; i++) { List<int> over = new List<int>(); List<int> under = new List<int>(); foreach (var item in es[i]) { over.Add(dfs(item, i, (K + 1) / 2)); under.Add(dfs(item, i, (K) / 2)); } int sum = under.Sum(); for (int j = 0; j < over.Count; j++) { ans = Math.Max(ans, sum - under[j] + over[j] + 1); } } ans = N - ans; Console.WriteLine(ans); } int dfs(int a, int pre, int dep) { if (dep <= 0) return 0; int ans = 1; foreach (var next in es[a]) { if (next == pre) continue; ans += dfs(next, a, dep - 1); } return ans; } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } }
[["-", 0, 28, 0, 16, 31, 23, 0, 16, 17, 72], ["-", 0, 28, 0, 16, 31, 23, 0, 16, 12, 203]]
8
790
2
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; class Myon { public Myon() {} public static int Main() { new Myon().calc(); return 0; } Scanner cin; int ans; int N, K; List<int>[] es; void calc() { cin = new Scanner(); N = cin.nextInt(); K = cin.nextInt(); es = new List<int>[N]; for (int i = 0; i < N; i++) { es[i] = new List<int>(); } for (int i = 0; i < N - 1; i++) { int a = cin.nextInt() - 1; int b = cin.nextInt() - 1; es[a].Add(b); es[b].Add(a); } ans = 99999; for (int i = 0; i < N; i++) { if (K % 2 == 0) calc(i, i); else { foreach (int j in es[i]) { if (i < j) calc(i, j); } } } Console.WriteLine(ans); } void calc(int a, int b) { int[] dist; Queue<int> q; int MAX = 99999; dist = new int[N]; for (int i = 0; i < N; i++) { dist[i] = MAX; } dist[a] = 0; dist[b] = 0; q = new Queue<int>(); q.Enqueue(a); q.Enqueue(b); int cnt = 0; while (q.Count != 0) { int now = q.Dequeue(); if (dist[now] > K / 2) break; cnt++; foreach (var next in es[now]) { if (dist[next] != MAX) continue; dist[next] = dist[now] + 1; q.Enqueue(next); } } ans = Math.Min(ans, N - cnt); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; class Myon { public Myon() {} public static int Main() { new Myon().calc(); return 0; } Scanner cin; int ans; int N, K; List<int>[] es; void calc() { cin = new Scanner(); N = cin.nextInt(); K = cin.nextInt(); es = new List<int>[N]; for (int i = 0; i < N; i++) { es[i] = new List<int>(); } for (int i = 0; i < N - 1; i++) { int a = cin.nextInt() - 1; int b = cin.nextInt() - 1; es[a].Add(b); es[b].Add(a); } ans = 99999; for (int i = 0; i < N; i++) { if (K % 2 == 0) calc(i, i); else { foreach (int j in es[i]) { if (i < j) calc(i, j); } } } Console.WriteLine(ans); } void calc(int a, int b) { int[] dist; Queue<int> q; int MAX = 99999; dist = new int[N]; for (int i = 0; i < N; i++) { dist[i] = MAX; } dist[a] = 0; dist[b] = 0; q = new Queue<int>(); q.Enqueue(a); if (a != b) q.Enqueue(b); int cnt = 0; while (q.Count != 0) { int now = q.Dequeue(); if (dist[now] > K / 2) break; cnt++; foreach (var next in es[now]) { if (dist[next] != MAX) continue; dist[next] = dist[now] + 1; q.Enqueue(next); } } ans = Math.Min(ans, N - cnt); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } }
[["+", 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, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25]]
8
814
6
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; class TEST { static void Main() { Sol mySol = new Sol(); mySol.Solve(); } } class Sol { public void Solve() { int ans = N; switch (K % 2) { case 0: // there exists the center vertex when diam%2 == 0 for (int i = 0; i < N; i++) { int[] depth = new int[N]; int[] parent = new int[N]; int root = i; depth[root] = 0; parent[root] = -1; var Q = new Queue<int>(); Q.Enqueue(root); while (Q.Count > 0) { var now = Q.Dequeue(); foreach (var nxt in E[now]) { if (nxt != parent[now]) { parent[nxt] = now; depth[nxt] = depth[now] + 1; Q.Enqueue(nxt); } } } int mustRemove = depth.Count(e => e > K / 2); ans = Math.Min(ans, mustRemove); } break; case 1: // there exists the center edge when diam%2 == 1 for (int i = 0; i < N; i++) { int[] depth = new int[N]; int[] parent = new int[N]; int root = i; foreach (var adj in E[root]) { if (adj < root) continue; depth[root] = 0; parent[root] = -1; depth[adj] = 0; parent[adj] = -1; var Q = new Queue<int>(); Q.Enqueue(root); Q.Enqueue(adj); while (Q.Count > 0) { var now = Q.Dequeue(); foreach (var nxt in E[now]) { if (nxt != parent[now]) { parent[nxt] = now; depth[nxt] = depth[now] + 1; Q.Enqueue(nxt); } } } int mustRemove = depth.Count(e => e > K / 2); ans = Math.Min(ans, mustRemove); } } break; } Console.WriteLine(ans); } int N, K; List<int>[] E; public Sol() { var d = ria(); N = d[0]; K = d[1]; E = new List<int>[N]; for (int i = 0; i < N; i++) { E[i] = new List<int>(); } for (int i = 0; i < N - 1; i++) { d = ria(); E[d[0] - 1].Add(d[1] - 1); E[d[1] - 1].Add(d[0] - 1); } } static String rs() { return Console.ReadLine(); } static int ri() { return int.Parse(Console.ReadLine()); } static long rl() { return long.Parse(Console.ReadLine()); } static double rd() { return double.Parse(Console.ReadLine()); } static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); } static int[] ria(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); } static long[] rla(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); } static double[] rda(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; class TEST { static void Main() { Sol mySol = new Sol(); mySol.Solve(); } } class Sol { public void Solve() { int ans = N; switch (K % 2) { case 0: // there exists the center vertex when diam%2 == 0 for (int i = 0; i < N; i++) { int[] depth = new int[N]; int[] parent = new int[N]; int root = i; depth[root] = 0; parent[root] = -1; var Q = new Queue<int>(); Q.Enqueue(root); while (Q.Count > 0) { var now = Q.Dequeue(); foreach (var nxt in E[now]) { if (nxt != parent[now]) { parent[nxt] = now; depth[nxt] = depth[now] + 1; Q.Enqueue(nxt); } } } int mustRemove = depth.Count(e => e > K / 2); ans = Math.Min(ans, mustRemove); } break; case 1: // there exists the center edge when diam%2 == 1 for (int i = 0; i < N; i++) { int[] depth = new int[N]; int[] parent = new int[N]; int root = i; foreach (var adj in E[root]) { if (adj < root) continue; depth[root] = 0; parent[root] = adj; depth[adj] = 0; parent[adj] = root; var Q = new Queue<int>(); Q.Enqueue(root); Q.Enqueue(adj); while (Q.Count > 0) { var now = Q.Dequeue(); foreach (var nxt in E[now]) { if (nxt != parent[now]) { parent[nxt] = now; depth[nxt] = depth[now] + 1; Q.Enqueue(nxt); } } } // Console.WriteLine(String.Join(" ",depth)); int mustRemove = depth.Count(e => e > K / 2); ans = Math.Min(ans, mustRemove); } } break; } Console.WriteLine(ans); } int N, K; List<int>[] E; public Sol() { var d = ria(); N = d[0]; K = d[1]; E = new List<int>[N]; for (int i = 0; i < N; i++) { E[i] = new List<int>(); } for (int i = 0; i < N - 1; i++) { d = ria(); E[d[0] - 1].Add(d[1] - 1); E[d[1] - 1].Add(d[0] - 1); } } static String rs() { return Console.ReadLine(); } static int ri() { return int.Parse(Console.ReadLine()); } static long rl() { return long.Parse(Console.ReadLine()); } static double rd() { return double.Parse(Console.ReadLine()); } static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); } static int[] ria(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); } static long[] rla(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); } static double[] rda(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); } }
[["-", 8, 196, 0, 1, 0, 11, 12, 241, 0, 33], ["-", 8, 196, 0, 1, 0, 11, 12, 241, 0, 203], ["+", 0, 210, 8, 196, 0, 1, 0, 11, 12, 22]]
8
847
6
using System; using System.Collections.Generic; using System.IO; using System.Linq; using static System.Math; using System.Text; using System.Threading; using System.Globalization; using System.Runtime.CompilerServices; using Library; namespace Program { public static class ProblemA { static bool SAIKI = false; static public int numberOfRandomCases = 0; static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker) {} static public void Solve() { var s = NS; var st = new Stack<char>(); foreach (var item in s) { if (item == 'B') { if (st.Count > 0) st.Pop(); } else st.Push(item); } foreach (var item in st) { Console.Write(item); } Console.WriteLine(); } class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; } public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; } } static LIB_FastIO fastio = new LIB_FastIODebug(); static public void Main(string[] args) { if (args.Length == 0) { fastio = new LIB_FastIO(); Console.SetOut(new Printer(Console.OpenStandardOutput())); } if (SAIKI) { var t = new Thread(Solve, 134217728); t.Start(); t.Join(); } else Solve(); Console.Out.Flush(); } static long NN => fastio.Long(); static double ND => fastio.Double(); static string NS => fastio.Scan(); static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray(); static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray(); static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray(); static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred); static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n); static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c); static IOrderedEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x, _ => xorshift); static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x.OrderByRand(), e => e); static IOrderedEnumerable<T1> OrderBy<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderBy(x.OrderByRand(), selector); static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x) => Enumerable.OrderByDescending(x.OrderByRand(), e => e); static IOrderedEnumerable<T1> OrderByDescending<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderByDescending(x.OrderByRand(), selector); static IOrderedEnumerable<string> OrderBy(this IEnumerable<string> x) => x.OrderByRand().OrderBy(e => e, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderBy(selector, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<string> OrderByDescending(this IEnumerable<string> x) => x.OrderByRand().OrderByDescending(e => e, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderByDescending(selector, StringComparer.OrdinalIgnoreCase); static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } } static IEnumerator<uint> _xsi = _xsc(); static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } } } } namespace Library { class LIB_FastIO { [MethodImpl(MethodImplOptions.AggressiveInlining)] public LIB_FastIO() { str = Console.OpenStandardInput(); } readonly Stream str; readonly byte[] buf = new byte[1024]; int len, ptr; public bool isEof = false; public bool IsEndOfStream { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return isEof; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] 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++]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; } [MethodImpl(MethodImplOptions.AggressiveInlining)] virtual public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] virtual 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'; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] virtual public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); } } class LIB_FastIODebug : LIB_FastIO { Queue<string> param = new Queue<string>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public LIB_FastIODebug() {} [MethodImpl(MethodImplOptions.AggressiveInlining)] public override string Scan() => NextString(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public override long Long() => long.Parse(NextString()); [MethodImpl(MethodImplOptions.AggressiveInlining)] public override double Double() => double.Parse(NextString()); } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using static System.Math; using System.Text; using System.Threading; using System.Globalization; using System.Runtime.CompilerServices; using Library; namespace Program { public static class ProblemA { static bool SAIKI = false; static public int numberOfRandomCases = 0; static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker) {} static public void Solve() { var s = NS; var st = new Stack<char>(); foreach (var item in s) { if (item == 'B') { if (st.Count > 0) st.Pop(); } else st.Push(item); } foreach (var item in st.Reverse()) { Console.Write(item); } Console.WriteLine(); } class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; } public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; } } static LIB_FastIO fastio = new LIB_FastIODebug(); static public void Main(string[] args) { if (args.Length == 0) { fastio = new LIB_FastIO(); Console.SetOut(new Printer(Console.OpenStandardOutput())); } if (SAIKI) { var t = new Thread(Solve, 134217728); t.Start(); t.Join(); } else Solve(); Console.Out.Flush(); } static long NN => fastio.Long(); static double ND => fastio.Double(); static string NS => fastio.Scan(); static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray(); static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray(); static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray(); static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred); static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n); static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c); static IOrderedEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x, _ => xorshift); static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x.OrderByRand(), e => e); static IOrderedEnumerable<T1> OrderBy<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderBy(x.OrderByRand(), selector); static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x) => Enumerable.OrderByDescending(x.OrderByRand(), e => e); static IOrderedEnumerable<T1> OrderByDescending<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderByDescending(x.OrderByRand(), selector); static IOrderedEnumerable<string> OrderBy(this IEnumerable<string> x) => x.OrderByRand().OrderBy(e => e, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderBy(selector, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<string> OrderByDescending(this IEnumerable<string> x) => x.OrderByRand().OrderByDescending(e => e, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderByDescending(selector, StringComparer.OrdinalIgnoreCase); static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } } static IEnumerator<uint> _xsi = _xsc(); static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } } } } namespace Library { class LIB_FastIO { [MethodImpl(MethodImplOptions.AggressiveInlining)] public LIB_FastIO() { str = Console.OpenStandardInput(); } readonly Stream str; readonly byte[] buf = new byte[1024]; int len, ptr; public bool isEof = false; public bool IsEndOfStream { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return isEof; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] 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++]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; } [MethodImpl(MethodImplOptions.AggressiveInlining)] virtual public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] virtual 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'; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] virtual public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); } } class LIB_FastIODebug : LIB_FastIO { Queue<string> param = new Queue<string>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public LIB_FastIODebug() {} [MethodImpl(MethodImplOptions.AggressiveInlining)] public override string Scan() => NextString(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public override long Long() => long.Parse(NextString()); [MethodImpl(MethodImplOptions.AggressiveInlining)] public override double Double() => double.Parse(NextString()); } }
[["+", 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, 201, 0, 195, 8, 196, 0, 210, 0, 25]]
8
1,578
4
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Contest.B { static class Program { public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var cin = new Scanner(); string s = cin.Next(); string ans = ""; for (int i = 0; i < s.Length; i++) { if (s[i] == 'B') { if (ans.Length > 0) ans = ans.Substring(i, ans.Length - 1); } else ans = ans + s[i]; } Console.WriteLine(ans); Console.Out.Flush(); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string Next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return Next(); i = 0; return s[i++]; } public int NextInt() { return int.Parse(Next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = NextInt() + add; } return Array; } public long NextLong() { return long.Parse(Next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = NextLong() + add; } return Array; } public double NextDouble() { return double.Parse(Next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = NextDouble() + add; } return Array; } } }
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Contest.B { static class Program { public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var cin = new Scanner(); string s = cin.Next(); string ans = ""; for (int i = 0; i < s.Length; i++) { if (s[i] == 'B') { if (ans.Length > 0) ans = ans.Substring(0, ans.Length - 1); } else ans = ans + s[i]; } Console.WriteLine(ans); Console.Out.Flush(); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string Next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return Next(); i = 0; return s[i++]; } public int NextInt() { return int.Parse(Next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = NextInt() + add; } return Array; } public long NextLong() { return long.Parse(Next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = NextLong() + add; } return Array; } public double NextDouble() { return double.Parse(Next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = NextDouble() + add; } return Array; } } }
[["-", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 203]]
8
534
2
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Program { static void Main(string[] args) { abc043_b(); } static void abc043_b() { // B - バイナリハックイージー string S = Console.ReadLine().Trim(); char[] Sarr = S.ToCharArray(); var stack = new Stack<char>(); foreach (var c in Sarr) { if (c == 'B') { if (stack.Count > 0) stack.Pop(); } else { stack.Push(c); } } string ans = string.Join("", stack); Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Program { static void Main(string[] args) { abc043_b(); } static void abc043_b() { // B - バイナリハックイージー string S = Console.ReadLine().Trim(); char[] Sarr = S.ToCharArray(); var stack = new Stack<char>(); foreach (var c in Sarr) { if (c == 'B') { if (stack.Count > 0) stack.Pop(); } else { stack.Push(c); } } string ans = string.Join("", stack.Reverse()); Console.WriteLine(ans); } } }
[["+", 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, 200, 0, 212, 0, 213, 3, 4, 0, 25]]
8
144
4
using System; namespace ABC043_B { class Program { static void Main(string[] args) { var S = Console.ReadLine().ToCharArray(); var str = ""; foreach (var c in S) { if (c == '0' || c == '1') { str += 1; } else if (str.Length > 0) { str = str.Substring(0, str.Length - 1); } } Console.WriteLine(str); } } }
using System; namespace ABC043_B { class Program { static void Main(string[] args) { var S = Console.ReadLine().ToCharArray(); var str = ""; foreach (var c in S) { if (c == '0' || c == '1') { str += c; } else if (str.Length > 0) { str = str.Substring(0, str.Length - 1); } } Console.WriteLine(str); } } }
[["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22]]
8
103
2
using System; using System.Collections.Generic; class program { static void Main(string[] args) { string input = Console.ReadLine(); List<char> output = new List<char>(); for (int i = 0; i < input.Length; i++) { switch (input[i]) { case '0': output.Add('0'); break; case '1': output.Add('!'); break; default: if (output.Count > 0) output.RemoveAt(output.Count - 1); break; } } char[] final = new char[output.Count]; for (int i = 0; i < output.Count; i++) { final[i] = output[i]; } Console.WriteLine(final); } }
using System; using System.Collections.Generic; class program { static void Main(string[] args) { string input = Console.ReadLine(); List<char> output = new List<char>(); for (int i = 0; i < input.Length; i++) { switch (input[i]) { case '0': output.Add('0'); break; case '1': output.Add('1'); break; default: if (output.Count > 0) output.RemoveAt(output.Count - 1); break; } } char[] final = new char[output.Count]; for (int i = 0; i < output.Count; i++) { final[i] = output[i]; } Console.WriteLine(final); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 252, 0, 253], ["+", 0, 213, 3, 4, 0, 28, 0, 252, 0, 253]]
8
178
2
using System; using System.Linq; using System.Collections.Generic; using System.Text.RegularExpressions; class MainClass { public static void Main(string[] args) { // 入力 var str = Console.ReadLine(); //処理 var stack = new Stack<char>(); foreach (var s in str) { if (s == '0' || s == '1') { stack.Push(s); } else { try { stack.Pop(); } catch (Exception e) { } } } //出力 foreach (Object obj in stack) { Console.Write("{0}", obj); } Console.WriteLine(""); } }
using System; using System.Linq; using System.Collections.Generic; using System.Text.RegularExpressions; class MainClass { public static void Main(string[] args) { // 入力 var str = Console.ReadLine(); //処理 var stack = new Stack<char>(); foreach (var s in str) { if (s == '0' || s == '1') { stack.Push(s); } else { try { stack.Pop(); } catch (Exception e) { } } } //出力 foreach (Object obj in stack.Reverse()) { Console.Write("{0}", obj); } Console.WriteLine(""); } }
[["+", 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, 201, 0, 195, 8, 196, 0, 210, 0, 25]]
8
140
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main(string[] args) { // List<int> values = new List<int>(Console.ReadLine().Split(' ').Select(s // => int.Parse(s))); List<int> values = new List<int>(); string input = Console.ReadLine(); // int n = int.Parse(input.Split(' ')[0]); // int m = int.Parse(input.Split(' ')[1]); // int k = int.Parse(input.Split(' ')[2]); string ss = ""; foreach (var item in input) { if (item.Equals('B')) { if (ss.Length != 0) { ss.Remove(ss.Length - 1, 1); } } else { ss += item; } } Console.WriteLine(ss); input = Console.ReadLine(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main(string[] args) { // List<int> values = new List<int>(Console.ReadLine().Split(' ').Select(s // => int.Parse(s))); List<int> values = new List<int>(); string input = Console.ReadLine(); // int n = int.Parse(input.Split(' ')[0]); // int m = int.Parse(input.Split(' ')[1]); // int k = int.Parse(input.Split(' ')[2]); string ss = ""; foreach (var item in input) { if (item.Equals('B')) { if (ss.Length != 0) { ss = ss.Remove(ss.Length - 1, 1); } } else { ss += item; } } Console.WriteLine(ss); input = Console.ReadLine(); } }
[["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22]]
8
122
2
using System; namespace VirtualAtCorder { class Program { static void Main(string[] args) { string inputs = Console.ReadLine(); string output = ""; foreach (char c in inputs) { if ('0' == c) { output += c; } else if ('1' == c) { output += c; } else if ('B' == c) { if (string.IsNullOrEmpty(output)) output = output.Remove(output.Length - 1, 1); } } if (string.IsNullOrEmpty(output)) { output = " "; } Console.WriteLine(output); Console.ReadKey(); } } }
using System; namespace VirtualAtCorder { class Program { static void Main(string[] args) { string inputs = Console.ReadLine(); string output = ""; foreach (char c in inputs) { if ('0' == c) { output += c; } else if ('1' == c) { output += c; } else if ('B' == c) { if (!string.IsNullOrEmpty(output)) output = output.Remove(output.Length - 1, 1); } } if (string.IsNullOrEmpty(output)) { output = " "; } Console.WriteLine(output); Console.ReadKey(); } } }
[["+", 75, 57, 64, 196, 0, 57, 15, 241, 0, 111]]
8
140
1
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { int[,] dp = new int[50, 2501]; static void Main(string[] args) { new Calc().calc(); return; } public class Calc { public void calc() { string s = ReadLine<string>(); Stack<char> ans = new Stack<char>(); foreach (var item in s) { if (item == 'B') { if (ans.Count > 0) { ans.Pop(); } } else { ans.Push(item); } } ans.Docking().WL(); return; } } public static T[] ReadLine<T>(params char[] separators) { return Console.ReadLine() .Split(separators) .Where(_ => _.Length > 0) .Select(_ => (T)Convert.ChangeType(_, typeof(T))) .ToArray(); } public static T ReadLine<T>() { return (T)Convert.ChangeType(Console.ReadLine(), typeof(T)); } public static List<T> ReadLines<T>(int N) { List<T> rt = new List<T>(); for (int i = 0; i < N; i++) { T item = (T)Convert.ChangeType(Console.ReadLine(), typeof(T)); rt.Add(item); } return rt; } } public static class Utils { public static void WL(this object obj) { Console.WriteLine(obj); } public static string Docking<T>(this IEnumerable<T> collection, Func<T, string> filter = null) { StringBuilder sb = new StringBuilder(); foreach (var item in collection) { string str = filter != null ? filter(item) : item.ToString(); sb.Append(str); } return sb.ToString(); } public static string RangeDocking<T>(this IEnumerable<T> collection, int start, int end, Func<T, string> filter = null) { if (start > collection.Count()) throw new IndexOutOfRangeException(); if (end < 0) throw new IndexOutOfRangeException(); StringBuilder sb = new StringBuilder(); for (int i = start; i < end; i++) { string str = filter != null ? filter(collection.ElementAt(i)) : collection.ElementAt(i).ToString(); sb.Append(str); } return sb.ToString(); } public static void WriteLineAll<T>(this IEnumerable<T> collection) { foreach (var item in collection) { item.WL(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { int[,] dp = new int[50, 2501]; static void Main(string[] args) { new Calc().calc(); return; } public class Calc { public void calc() { string s = ReadLine<string>(); Stack<char> ans = new Stack<char>(); foreach (var item in s) { if (item == 'B') { if (ans.Count > 0) { ans.Pop(); } } else { ans.Push(item); } } ans.Reverse().Docking().WL(); return; } } public static T[] ReadLine<T>(params char[] separators) { return Console.ReadLine() .Split(separators) .Where(_ => _.Length > 0) .Select(_ => (T)Convert.ChangeType(_, typeof(T))) .ToArray(); } public static T ReadLine<T>() { return (T)Convert.ChangeType(Console.ReadLine(), typeof(T)); } public static List<T> ReadLines<T>(int N) { List<T> rt = new List<T>(); for (int i = 0; i < N; i++) { T item = (T)Convert.ChangeType(Console.ReadLine(), typeof(T)); rt.Add(item); } return rt; } } public static class Utils { public static void WL(this object obj) { Console.WriteLine(obj); } public static string Docking<T>(this IEnumerable<T> collection, Func<T, string> filter = null) { StringBuilder sb = new StringBuilder(); foreach (var item in collection) { string str = filter != null ? filter(item) : item.ToString(); sb.Append(str); } return sb.ToString(); } public static string RangeDocking<T>(this IEnumerable<T> collection, int start, int end, Func<T, string> filter = null) { if (start > collection.Count()) throw new IndexOutOfRangeException(); if (end < 0) throw new IndexOutOfRangeException(); StringBuilder sb = new StringBuilder(); for (int i = start; i < end; i++) { string str = filter != null ? filter(collection.ElementAt(i)) : collection.ElementAt(i).ToString(); sb.Append(str); } return sb.ToString(); } public static void WriteLineAll<T>(this IEnumerable<T> collection) { foreach (var item in collection) { item.WL(); } } }
[["+", 205, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131]]
8
586
4
using System; class A { static void Main() { string a = ""; string s = Console.ReadLine(); for (int i = 0; i < s.Length; i++) { // string y = s.Substring(i, 1); if (s[i] != 'B') { a += s[i]; } else { if (!string.IsNullOrEmpty(a)) { a = s.Substring(0, a.Length - 1); } } } Console.WriteLine(a); } }
using System; class A { static void Main() { string a = ""; string s = Console.ReadLine(); for (int i = 0; i < s.Length; i++) { // string y = s.Substring(i, 1); if (s[i] != 'B') { a += s[i]; } else { if (!string.IsNullOrEmpty(a)) { a = a.Substring(0, a.Length - 1); } } } Console.WriteLine(a); } }
[["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22]]
8
105
2
using System; using System.Collections.Generic; using System.Linq; namespace ABC { class B043 { static void Main() { string str = Console.ReadLine(); Stack<char> chars = new Stack<char>(); foreach (char key in str) { if (key == '0') chars.Push('0'); if (key == '1') chars.Push('1'); if (key == 'B' && chars.Count() != 0) chars.Pop(); } Console.WriteLine(new string(chars.ToArray())); } } }
using System; using System.Collections.Generic; using System.Linq; namespace ABC { class B043 { static void Main() { string str = Console.ReadLine(); Stack<char> chars = new Stack<char>(); foreach (char key in str) { if (key == '0') chars.Push('0'); if (key == '1') chars.Push('1'); if (key == 'B' && chars.Count() != 0) chars.Pop(); } Console.WriteLine(new string(chars.Reverse().ToArray())); } } }
[["+", 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]]
8
133
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class GFG { static public void Main() { try { var n = Console.ReadLine(); // var input1 = Console.ReadLine().Split(' '); // var n = int.Parse(input1[0]); // var L = int.Parse(input1[1]); // var aar = Console.ReadLine().Split(' ').Select(x => // Int32.Parse(x)).ToArray(); SubString(n); } catch (Exception ex) { Console.Write(ex); } } static void SubString(string s) { for (int i = 0; i < s.Length; i++) { if (s[i] == s[i + 1]) { Console.Write((i + 1) + " " + (i + 2)); return; } if (i + 2 < s.Length && s[i] == s[i + 2]) { Console.Write((i + 1) + " " + (i + 3)); return; } } Console.Write("-1 -1"); } static bool UnBal(string s) { if (s.Length <= 1) return false; var ss = s.ToCharArray(); int n = ss.Length; var group = ss.GroupBy(x => x).Select(g => new { l = g.Key, count = g.Count() }); foreach (var cc in group) { if (cc.count > (n / 2)) return true; } return false; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class GFG { static public void Main() { try { var n = Console.ReadLine(); // var input1 = Console.ReadLine().Split(' '); // var n = int.Parse(input1[0]); // var L = int.Parse(input1[1]); // var aar = Console.ReadLine().Split(' ').Select(x => // Int32.Parse(x)).ToArray(); SubString(n); } catch (Exception ex) { Console.Write(ex); } } static void SubString(string s) { for (int i = 0; i < s.Length - 1; i++) { if (s[i] == s[i + 1]) { Console.Write((i + 1) + " " + (i + 2)); return; } if (i + 2 < s.Length && s[i] == s[i + 2]) { Console.Write((i + 1) + " " + (i + 3)); return; } } Console.Write("-1 -1"); } static bool UnBal(string s) { if (s.Length <= 1) return false; var ss = s.ToCharArray(); int n = ss.Length; var group = ss.GroupBy(x => x).Select(g => new { l = g.Key, count = g.Count() }); foreach (var cc in group) { if (cc.count > (n / 2)) return true; } return false; } }
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
288
2
using System; using System.Linq; using System.Collections.Generic; using System.IO; namespace atcorder2 { class Program { public static long Read() { return long.Parse(Console.ReadLine()); } public static long[] Reads() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); } static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var ab = Reads(); var a = ab[0]; var b = ab[1]; if (a <= 0 && b >= 0) Console.WriteLine("Zero"); if (a > 0 && b > 0) Console.WriteLine("Positive"); if (a < 0 && b < 0) Console.WriteLine(b - a % 2 == 0 ? "Negative" : "Positive"); Console.Out.Flush(); } } }
using System; using System.Linq; using System.Collections.Generic; using System.IO; namespace atcorder2 { class Program { public static long Read() { return long.Parse(Console.ReadLine()); } public static long[] Reads() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); } static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var ab = Reads(); var a = ab[0]; var b = ab[1]; if (a <= 0 && b >= 0) Console.WriteLine("Zero"); if (a > 0 && b > 0) Console.WriteLine("Positive"); if (a < 0 && b < 0) Console.WriteLine((b - a) % 2 == 0 ? "Negative" : "Positive"); Console.Out.Flush(); } } }
[["+", 0, 41, 15, 16, 31, 16, 31, 23, 0, 24], ["+", 0, 41, 15, 16, 31, 16, 31, 23, 0, 25]]
8
216
2
using System; class Abc { static void Main() { int[] ab = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); int a = ab[0]; int b = ab[1]; if (0 < a) Console.WriteLine("Positive"); else if (b < 0 && b - a + 1 % 2 == 0) Console.WriteLine("Positive"); else if (b < 0 && b - a + 1 % 2 != 0) Console.WriteLine("Negative"); else if (a <= 0 && b >= 0) Console.WriteLine("Zero"); } }
using System; class Abc { static void Main() { int[] ab = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); int a = ab[0]; int b = ab[1]; if (0 < a) Console.WriteLine("Positive"); else if (b < 0 && (b - a + 1) % 2 == 0) Console.WriteLine("Positive"); else if (b < 0 && (b - a + 1) % 2 != 0) Console.WriteLine("Negative"); else if (a <= 0 && b >= 0) Console.WriteLine("Zero"); } }
[["+", 15, 16, 12, 16, 31, 16, 31, 23, 0, 24], ["+", 15, 16, 12, 16, 31, 16, 31, 23, 0, 25]]
8
144
4
using System; using System.Collections.Generic; using System.Linq; namespace kakomon { class Program { static void Main(string[] args) { agc002_a(); } static void agc002_a() { // A - Range Product long[] input = Console.ReadLine().Trim().Split().Select(long.Parse).ToArray(); long a = input[0]; long b = input[1]; string ans; // すべて1以上なら積は正 if (0 < a) ans = "Positive"; // 0を含む区間なら積は0 else if (a <= 0 && 0 <= b) ans = "Zero"; // bが0より小さい、すべて負の値の場合 else { // 同じ値なら、積は正の値 if (a == b) ans = "Positive"; // 個数が偶数なら、積は正の値 else if (b - a + 1 % 2 == 0) ans = "Positive"; // 個数が奇数なら、積は負の値 else ans = "Negative"; } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; namespace kakomon { class Program { static void Main(string[] args) { agc002_a(); } static void agc002_a() { // A - Range Product long[] input = Console.ReadLine().Trim().Split().Select(long.Parse).ToArray(); long a = input[0]; long b = input[1]; string ans; // すべて1以上なら積は正 if (0 < a) ans = "Positive"; // 0を含む区間なら積は0 else if (a <= 0 && 0 <= b) ans = "Zero"; // bが0より小さい、すべて負の値の場合 else { // 同じ値なら、積は正の値 if (a == b) ans = "Positive"; // 個数が偶数なら、積は正の値 else if ((b - a + 1) % 2 == 0) ans = "Positive"; // 個数が奇数なら、積は負の値 else ans = "Negative"; } Console.WriteLine(ans); } } }
[["+", 75, 57, 15, 16, 31, 16, 31, 23, 0, 24], ["+", 75, 57, 15, 16, 31, 16, 31, 23, 0, 25]]
8
178
2
using System; using System.Linq; using System.Collections.Generic; namespace Contest { class Program { static void Main(string[] args) { AGC002.A(); } class AGC002 { public static void A() { var A = Read.Long(); var B = Read.Long(); if (A * B <= 0) { Console.WriteLine("Zero"); return; } Console.WriteLine(A > 0 || B - A % 2 == 1 ? "Positive" : "Negative"); } public static void B() { var N = Read.Int(); var M = Read.Int(); var XY = Read.TupleInt(M); bool[] possible = new bool[N]; int[] count = Enumerable.Range(0, N).Select(i => 1).ToArray(); possible[0] = true; foreach (var xy in XY) { var x = xy.Item1 - 1; var y = xy.Item2 - 1; possible[y] |= possible[x]; count[x]--; count[y]++; if (count[x] == 0) { possible[x] = false; } } Console.WriteLine( Enumerable.Range(0, N).Count(i => count[i] > 0 && possible[i])); } public static void C() { var N = Read.Int(); var L = Read.Long(); var A = Read.LongN(); int idx = -1; for (int i = 0; i < N - 1; ++i) { if (A[i] + A[i + 1] >= L) { idx = i; break; } } if (idx < 0) { Console.WriteLine("Impossible"); return; } Console.WriteLine("Possible"); for (int i = 0; i < idx; ++i) { Console.WriteLine(i + 1); } for (int i = N - 2; i > idx; --i) { Console.WriteLine(i + 1); } Console.WriteLine(idx + 1); } } class Util {} static class Read { static Queue<string> queue = new Queue<string>(); static void Enqueue() { var ss = Console.ReadLine().Split(' '); foreach (var s in ss) { queue.Enqueue(s); } } public static int Int() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt32(queue.Dequeue()); } public static long Long() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt64(queue.Dequeue()); } public static string Str() { if (queue.Count == 0) { Enqueue(); } return queue.Dequeue(); } public static int[] IntN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt32(s)) .ToArray(); } public static long[] LongN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt64(s)) .ToArray(); } public static string[] StrN() { return Console.ReadLine().Split(' '); } public static Tuple<int, int>[] TupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = Read.IntN(); list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<long, long>[] TupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<string, string>[] TupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = Read.StrN(); list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<double, double>[] TupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); } public static long[,] LongMatrix(int r, int c) { var mat = new long[r, c]; for (int i = 0; i < r; ++i) { var x = Read.LongN(); for (int j = 0; j < c; ++j) { mat[i, j] = x[j]; } } return mat; } public static Dictionary<int, HashSet<int>> AdjacencyList(int N, int M) { Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new HashSet<int>()); } for (int i = 0; i < M; ++i) { var ab = Read.IntN(); dict[ab[0]].Add(ab[1]); dict[ab[1]].Add(ab[0]); } return dict; } public static Dictionary<int, Dictionary<int, long>> AdjacencyListWithWeight(int N, int M) { Dictionary<int, Dictionary<int, long>> dict = new Dictionary<int, Dictionary<int, long>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new Dictionary<int, long>()); } for (int i = 0; i < M; ++i) { var ab = Read.IntN(); dict[ab[0]].Add(ab[1], ab[2]); dict[ab[1]].Add(ab[0], ab[2]); } return dict; } } } }
using System; using System.Linq; using System.Collections.Generic; namespace Contest { class Program { static void Main(string[] args) { AGC002.A(); } class AGC002 { public static void A() { var A = Read.Long(); var B = Read.Long(); if (A * B <= 0) { Console.WriteLine("Zero"); return; } Console.WriteLine(A > 0 || (B - A) % 2 == 1 ? "Positive" : "Negative"); } public static void B() { var N = Read.Int(); var M = Read.Int(); var XY = Read.TupleInt(M); bool[] possible = new bool[N]; int[] count = Enumerable.Range(0, N).Select(i => 1).ToArray(); possible[0] = true; foreach (var xy in XY) { var x = xy.Item1 - 1; var y = xy.Item2 - 1; possible[y] |= possible[x]; count[x]--; count[y]++; if (count[x] == 0) { possible[x] = false; } } Console.WriteLine( Enumerable.Range(0, N).Count(i => count[i] > 0 && possible[i])); } public static void C() { var N = Read.Int(); var L = Read.Long(); var A = Read.LongN(); int idx = -1; for (int i = 0; i < N - 1; ++i) { if (A[i] + A[i + 1] >= L) { idx = i; break; } } if (idx < 0) { Console.WriteLine("Impossible"); return; } Console.WriteLine("Possible"); for (int i = 0; i < idx; ++i) { Console.WriteLine(i + 1); } for (int i = N - 2; i > idx; --i) { Console.WriteLine(i + 1); } Console.WriteLine(idx + 1); } } class Util {} static class Read { static Queue<string> queue = new Queue<string>(); static void Enqueue() { var ss = Console.ReadLine().Split(' '); foreach (var s in ss) { queue.Enqueue(s); } } public static int Int() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt32(queue.Dequeue()); } public static long Long() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt64(queue.Dequeue()); } public static string Str() { if (queue.Count == 0) { Enqueue(); } return queue.Dequeue(); } public static int[] IntN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt32(s)) .ToArray(); } public static long[] LongN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt64(s)) .ToArray(); } public static string[] StrN() { return Console.ReadLine().Split(' '); } public static Tuple<int, int>[] TupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = Read.IntN(); list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<long, long>[] TupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<string, string>[] TupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = Read.StrN(); list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<double, double>[] TupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); } public static long[,] LongMatrix(int r, int c) { var mat = new long[r, c]; for (int i = 0; i < r; ++i) { var x = Read.LongN(); for (int j = 0; j < c; ++j) { mat[i, j] = x[j]; } } return mat; } public static Dictionary<int, HashSet<int>> AdjacencyList(int N, int M) { Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new HashSet<int>()); } for (int i = 0; i < M; ++i) { var ab = Read.IntN(); dict[ab[0]].Add(ab[1]); dict[ab[1]].Add(ab[0]); } return dict; } public static Dictionary<int, Dictionary<int, long>> AdjacencyListWithWeight(int N, int M) { Dictionary<int, Dictionary<int, long>> dict = new Dictionary<int, Dictionary<int, long>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new Dictionary<int, long>()); } for (int i = 0; i < M; ++i) { var ab = Read.IntN(); dict[ab[0]].Add(ab[1], ab[2]); dict[ab[1]].Add(ab[0], ab[2]); } return dict; } } } }
[["+", 15, 16, 12, 16, 31, 16, 31, 23, 0, 24], ["+", 15, 16, 12, 16, 31, 16, 31, 23, 0, 25]]
8
1,490
2
using System; using System.Linq; class A { static void Main() { var h = Console.ReadLine().Split().Select(int.Parse).ToArray(); int a = h[0], b = h[1]; Console.WriteLine(a > 0 ? "Positive" : b >= 0 ? "Zero" : b - a % 2 == 1 ? "Positive" : "Negative"); } }
using System; using System.Linq; class A { static void Main() { var h = Console.ReadLine().Split().Select(int.Parse).ToArray(); int a = h[0], b = h[1]; Console.WriteLine(a > 0 ? "Positive" : b >= 0 ? "Zero" : (b - a) % 2 == 1 ? "Positive" : "Negative"); } }
[["+", 75, 41, 15, 16, 31, 16, 31, 23, 0, 24], ["+", 75, 41, 15, 16, 31, 16, 31, 23, 0, 25]]
8
95
2
using System; using System.Linq; using System.Collections.Generic; public class Hello { public static void Main() { var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var a = input[0]; var b = input[1]; var ans = ""; if (1 <= b) { if (1 <= a) { ans = "POSITIVE"; } else { ans = "ZERO"; } } else if (b == 0) { ans = "ZERO"; } else { if ((Math.Abs(a - b) + 1) % 2 == 0) { ans = "POSITIVE"; } else { ans = "NEGATIVE"; } } Console.WriteLine(ans); } }
using System; using System.Linq; using System.Collections.Generic; public class Hello { public static void Main() { var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var a = input[0]; var b = input[1]; var ans = ""; if (1 <= b) { if (1 <= a) { ans = "Positive"; } else { ans = "Zero"; } } else if (b == 0) { ans = "Zero"; } else { if ((Math.Abs(a - b) + 1) % 2 == 0) { ans = "Positive"; } else { ans = "Negative"; } } Console.WriteLine(ans); } }
[["-", 64, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["-", 75, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["+", 75, 196, 0, 1, 0, 11, 12, 5, 0, 222]]
8
169
10
using System; using System.Linq; //リストの使用 using System.Collections.Generic; using System.Text; //テキストの高速出力に必要 class Program { static void Main() { string[] input = Console.ReadLine().Split( ' '); // Splitで区切り文字を指定して複数個受け取る。 long a = long.Parse(input[0]); long b = long.Parse(input[1]); if (0 < a) Console.WriteLine("Positive"); else { if (0 <= b) Console.WriteLine("Zero"); else { long c = b - a; if (c % 2 == 1) Console.WriteLine("Negative"); else Console.WriteLine("Positive"); } } } }
using System; using System.Linq; //リストの使用 using System.Collections.Generic; using System.Text; //テキストの高速出力に必要 class Program { static void Main() { string[] input = Console.ReadLine().Split( ' '); // Splitで区切り文字を指定して複数個受け取る。 long a = long.Parse(input[0]); long b = long.Parse(input[1]); if (0 < a) Console.WriteLine("Positive"); else { if (0 <= b) Console.WriteLine("Zero"); else { long c = b - a; if (c % 2 == 0) Console.WriteLine("Negative"); else Console.WriteLine("Positive"); } } } }
[["-", 0, 57, 75, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 12, 203]]
8
148
2
using System; using System.Linq; class Program { static void Main() { int[] ab = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); int a = ab[0], b = ab[1]; if (a > 0) Console.WriteLine("Positive"); else if (a <= 0 && b >= 0) Console.WriteLine("Zero"); else if ((b - a + 1) % 2 == 0) Console.WriteLine("Negative"); else Console.WriteLine("Positive"); } }
using System; using System.Linq; class Program { static void Main() { int[] ab = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); int a = ab[0], b = ab[1]; if (a > 0) Console.WriteLine("Positive"); else if (a <= 0 && b >= 0) Console.WriteLine("Zero"); else if ((b - a + 1) % 2 != 0) Console.WriteLine("Negative"); else Console.WriteLine("Positive"); } }
[["-", 0, 57, 75, 57, 75, 57, 15, 16, 17, 60], ["+", 0, 57, 75, 57, 75, 57, 15, 16, 17, 79]]
8
137
2
using System; using System.Linq; class Program { static void Main(string[] args) { var a = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); if (a[0] <= 0 && a[1] >= 0) Console.WriteLine("Zero"); else if (a[0] > 0) Console.WriteLine("Positive"); else if (a[1] < 0) { Console.WriteLine((a[0] + a[1] + 1) / 2 == 0 ? "Positive" : "Negative"); } } }
using System; using System.Linq; class Program { static void Main(string[] args) { var a = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); if (a[0] <= 0 && a[1] >= 0) Console.WriteLine("Zero"); else if (a[0] > 0) Console.WriteLine("Positive"); else if (a[1] < 0) { Console.WriteLine((a[0] + a[1] + 1) % 2 == 0 ? "Positive" : "Negative"); } } }
[["-", 0, 28, 0, 41, 15, 16, 31, 16, 17, 85], ["+", 0, 28, 0, 41, 15, 16, 31, 16, 17, 109]]
8
142
2
using System; using System.Linq; using System.Collections.Generic; class P { static void Main() { int[] a = Console.ReadLine().Split().Select(int.Parse).OrderBy(x => x).ToArray(); string res = ""; if (0 < a[0] && 0 < a[1]) { res = "Positive"; } else if (0 > a[0] && 0 > a[1]) { if (a[1] - a[0] % 2 == 1) { res = "Positive"; } else { res = "Negative"; } } else { res = "Zero"; } Console.WriteLine(res); } }
using System; using System.Linq; using System.Collections.Generic; class P { static void Main() { int[] a = Console.ReadLine().Split().Select(int.Parse).OrderBy(x => x).ToArray(); string res = ""; if (0 < a[0] && 0 < a[1]) { res = "Positive"; } else if (0 > a[0] && 0 > a[1]) { if ((a[1] - a[0]) % 2 == 1) { res = "Positive"; } else { res = "Negative"; } } else { res = "Zero"; } Console.WriteLine(res); } }
[["+", 0, 57, 15, 16, 31, 16, 31, 23, 0, 24], ["+", 0, 57, 15, 16, 31, 16, 31, 23, 0, 25]]
8
157
2
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Globalization; using System.Diagnostics; class Myon { public Myon() {} public static int Main() { new Myon().calc(); return 0; } Scanner cin; void calc() { cin = new Scanner(); long a = cin.nextLong(); long b = cin.nextLong(); if (a <= 0 && b >= 0) { Console.WriteLine("Zero"); } else if (a > 0 || b - a % 2 == 1) { Console.WriteLine("Positive"); } else { Console.WriteLine("Negative"); } } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Globalization; using System.Diagnostics; class Myon { public Myon() {} public static int Main() { new Myon().calc(); return 0; } Scanner cin; void calc() { cin = new Scanner(); long a = cin.nextLong(); long b = cin.nextLong(); if (a <= 0 && b >= 0) { Console.WriteLine("Zero"); } else if (a > 0 || (b - a) % 2 == 1) { Console.WriteLine("Positive"); } else { Console.WriteLine("Negative"); } } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } }
[["+", 15, 16, 12, 16, 31, 16, 31, 23, 0, 24], ["+", 15, 16, 12, 16, 31, 16, 31, 23, 0, 25]]
8
513
2
using System; using System.Collections.Generic; using System.Linq; class Program { static int ReadInt() { return int.Parse(Console.ReadLine()); } static int[] ReadInts() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); } static string[] ReadStrings() { return Console.ReadLine().Split(); } static int Calc(int a, int b) { if (a > 0) return 1; if (a == 0 || b == 0) return 0; if (a < 0 && b > 0) return 0; int n = Math.Min(-1, b) - a; if (n % 2 == 0) return 1; return -1; } static void Main() { var ab = ReadInts(); int a = ab[0], b = ab[1]; int ans = Calc(a, b); if (ans > 0) Console.WriteLine("Positive"); else if (ans == 0) Console.WriteLine("Zero"); else Console.WriteLine("Negative"); } }
using System; using System.Collections.Generic; using System.Linq; class Program { static int ReadInt() { return int.Parse(Console.ReadLine()); } static int[] ReadInts() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); } static string[] ReadStrings() { return Console.ReadLine().Split(); } static int Calc(int a, int b) { if (a > 0) return 1; if (a == 0 || b == 0) return 0; if (a < 0 && b > 0) return 0; int n = Math.Min(-1, b) - a + 1; if (n % 2 == 0) return 1; return -1; } static void Main() { var ab = ReadInts(); int a = ab[0], b = ab[1]; int ans = Calc(a, b); if (ans > 0) Console.WriteLine("Positive"); else if (ans == 0) Console.WriteLine("Zero"); else Console.WriteLine("Negative"); } }
[["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
246
2
using System; namespace RangeProduct { class Program { static void Main(string[] args) { int a, b; string[] str = Console.ReadLine().Split(' '); a = int.Parse(str[0]); b = int.Parse(str[1]); if (a > 0 && b >= a) { Console.WriteLine("Positive"); } else if (a >= 0 && b <= 0) { Console.WriteLine("Zero"); } else if ((b - a + 1) % 2 == 0) { Console.WriteLine("Positive"); } else if ((b - a + 1) % 2 == 1) { Console.WriteLine("Negative"); } } } }
using System; namespace RangeProduct { class Program { static void Main(string[] args) { int a, b; string[] str = Console.ReadLine().Split(' '); a = int.Parse(str[0]); b = int.Parse(str[1]); if (a > 0 && b >= a) { Console.WriteLine("Positive"); } else if (a <= 0 && b >= 0) { Console.WriteLine("Zero"); } else if ((b - a + 1) % 2 == 0) { Console.WriteLine("Positive"); } else if ((b - a + 1) % 2 == 1) { Console.WriteLine("Negative"); } } } }
[["-", 0, 57, 75, 57, 15, 16, 31, 16, 17, 20], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 17, 19], ["-", 0, 57, 75, 57, 15, 16, 12, 16, 17, 19], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 17, 20]]
8
164
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class AGC002 { static void Main(string[] args) { var spl = Console.ReadLine().Split(); long a = long.Parse(spl[0]); long b = long.Parse(spl[1]); if (a > 0 && b > 0) { Console.WriteLine("Positive"); } else if (a < 0 && b < 0) { if (a % 2 == 0 && b % 2 == 0) Console.WriteLine("Negative"); if (a % 2 == -1 && b % 2 == -1) Console.WriteLine("Negative"); else Console.WriteLine("Positive"); } else { Console.WriteLine("Zero"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class AGC002 { static void Main(string[] args) { var spl = Console.ReadLine().Split(); long a = long.Parse(spl[0]); long b = long.Parse(spl[1]); if (a > 0 && b > 0) { Console.WriteLine("Positive"); } else if (a < 0 && b < 0) { if (a % 2 == 0 && b % 2 == 0) Console.WriteLine("Negative"); else if (a % 2 == -1 && b % 2 == -1) Console.WriteLine("Negative"); else Console.WriteLine("Positive"); } else { Console.WriteLine("Zero"); } } }
[["+", 0, 57, 75, 57, 64, 196, 0, 57, 0, 95]]
8
185
1
using System; class Program { static void Main() { int[] s = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); bool[] b = new bool[s[0] + 1]; int[] h = new int[s[0] + 1]; int ans = 1; b[1] = true; for (int i = 1; i < s[0]; i++) { h[i] = 1; } for (int i = 0; i < s[1]; i++) { int[] q = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); h[q[0]]--; h[q[1]]++; if (b[q[0]] && (!b[q[1]])) { b[q[1]] = true; ans++; } if (h[q[0]] == 0 && b[q[0]]) { b[q[0]] = false; ans--; } } Console.WriteLine("{0}", ans); } }
using System; class Program { static void Main() { int[] s = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); bool[] b = new bool[s[0] + 1]; int[] h = new int[s[0] + 1]; int ans = 1; b[1] = true; for (int i = 1; i <= s[0]; i++) { h[i] = 1; } for (int i = 0; i < s[1]; i++) { int[] q = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); h[q[0]]--; h[q[1]]++; if (b[q[0]] && (!b[q[1]])) { b[q[1]] = true; ans++; } if (h[q[0]] == 0 && b[q[0]]) { b[q[0]] = false; ans--; } } Console.WriteLine("{0}", ans); } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
251
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class GFG { static public void Main() { try { var input1 = Console.ReadLine().Split(' '); var n = int.Parse(input1[0]); var L = int.Parse(input1[1]); var aar = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray(); KnotPuzzle(n, L, aar); } catch (Exception ex) { Console.Write(ex); } } static void KnotPuzzle(int n, int L, int[] arr) { int index = 0; for (int i = 1; i < n; i++) { if (arr[i] + arr[i - 1] >= L) { index = i; break; } } if (index > 0) { Console.Write("Possible"); for (int k = 1; k < index; k++) { Console.Write(k); Console.WriteLine(); } for (int k = n - 1; k >= index; k--) { Console.Write(k); Console.WriteLine(); } } else { Console.Write("Impossible"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class GFG { static public void Main() { try { var input1 = Console.ReadLine().Split(' '); var n = int.Parse(input1[0]); var L = int.Parse(input1[1]); var aar = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray(); KnotPuzzle(n, L, aar); } catch (Exception ex) { Console.Write(ex); } } static void KnotPuzzle(int n, int L, int[] arr) { int index = 0; for (int i = 1; i < n; i++) { if (arr[i] + arr[i - 1] >= L) { index = i; break; } } if (index > 0) { Console.Write("Possible"); Console.WriteLine(); for (int k = 1; k < index; k++) { Console.Write(k); Console.WriteLine(); } for (int k = n - 1; k >= index; k--) { Console.Write(k); Console.WriteLine(); } } else { Console.Write("Impossible"); } } }
[["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
8
284
6
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using static System.Math; using static System.Array; using static AtCoder.Tool; namespace AtCoder { class AC { const int MOD = 1000000007; const int INF = int.MaxValue / 2; const long SINF = long.MaxValue / 2; const double EPS = 1e-8; static readonly int[] dx = { 0, 1, 0, -1 }; static readonly int[] dy = { 1, 0, -1, 0 }; // 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 cin = new Scanner(); var input = cin.SplitRead(); int N = input[0]; int L = input[1]; var a = cin.SplitRead(); int st = -1; for (var i = 0; i < N - 1; i++) { if (a[i] + a[i + 1] >= L) { st = i + 1; break; } } if (st == -1) { Console.WriteLine("Impossible"); Console.Out.Flush(); return; } var ans = new Stack<int>(); ans.Push(st); for (var i = 1; i < st; i++) { ans.Push(i); } for (var j = st + 1; j < N; j++) { ans.Push(j); } Console.WriteLine("Possible"); foreach (var ind in ans) { Console.WriteLine(ind); } Console.Out.Flush(); } 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 Pair<T, U> : IComparable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U> { public T first; public U second; private readonly bool CompWithFirst; public Pair(T f, U s, int comp) { first = f; second = s; CompWithFirst = comp == 1; } public Pair(T f, U s) { first = f; second = s; CompWithFirst = true; } public int CompareTo(Pair<T, U> other) { return CompWithFirst ? first.CompareTo(other.first) : second.CompareTo(other.second); } } } public class PriorityQueue<T> where T : IComparable<T> { private List<T> Q; private readonly int r; public PriorityQueue(bool ascending) { if (ascending) { r = 1; } else { r = -1; } Q = new List<T>(); } private void PushHeap(List<T> list, T item) { int n = list.Count(); list.Add(item); while (n != 0) { int pIndex = (n - 1) / 2; if (list[n].CompareTo(list[pIndex]) * r > 0) { Swap(Q, n, pIndex); } else { break; } n = pIndex; } } private void PopHeap(List<T> list) { int n = list.Count() - 1; list[0] = list[n]; list.RemoveAt(n); int cur = 0; int comp; while (2 * cur + 1 <= n - 1) { int c1 = 2 * cur + 1; int c2 = 2 * (cur + 1); if (c1 == n - 1) { comp = c1; } else { comp = list[c1].CompareTo(list[c2]) * r > 0 ? c1 : c2; } if (list[cur].CompareTo(list[comp]) * r < 0) { Swap(Q, cur, comp); } else { break; } cur = comp; } } private void Swap(List<T> list, int a, int b) { T keep = list[a]; list[a] = list[b]; list[b] = keep; } public void Enqueue(T value) { PushHeap(Q, value); } public T Dequeue() { T ret = Q[0]; PopHeap(Q); return ret; } public T Peek() { return Q[0]; } public int Count() { return Q.Count(); } public bool Contains(T search) { return Q.Contains(search); } } public class Scanner { public int[] SplitRead() { int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray(); return array; } public long[] SplitReadL() { long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray(); return array; } } public static class Tool { static public void Initialize<T>(ref T[] array, T initialvalue) { for (var i = 0; i < array.Length; i++) { array[i] = initialvalue; } } static public T MaxLot<T>(params T[] val) where T : IComparable<T> { T ret = val[0]; for (var i = 1; i < val.Count(); i++) { if (ret.CompareTo(val[i]) < 0) { ret = val[i]; } } return ret; } static public T MinLot<T>(params T[] val) where T : IComparable<T> { T ret = val[0]; for (var i = 1; i < val.Count(); i++) { if (ret.CompareTo(val[i]) > 0) { ret = val[i]; } } return ret; } } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using static System.Math; using static System.Array; using static AtCoder.Tool; namespace AtCoder { class AC { const int MOD = 1000000007; const int INF = int.MaxValue / 2; const long SINF = long.MaxValue / 2; const double EPS = 1e-8; static readonly int[] dx = { 0, 1, 0, -1 }; static readonly int[] dy = { 1, 0, -1, 0 }; // 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 cin = new Scanner(); var input = cin.SplitRead(); int N = input[0]; int L = input[1]; var a = cin.SplitRead(); int st = -1; for (var i = 0; i < N - 1; i++) { if (a[i] + a[i + 1] >= L) { st = i + 1; break; } } if (st == -1) { Console.WriteLine("Impossible"); Console.Out.Flush(); return; } var ans = new Stack<int>(); ans.Push(st); for (var i = st - 1; i >= 1; i--) { ans.Push(i); } for (var j = st + 1; j < N; j++) { ans.Push(j); } Console.WriteLine("Possible"); foreach (var ind in ans) { Console.WriteLine(ind); } Console.Out.Flush(); } 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 Pair<T, U> : IComparable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U> { public T first; public U second; private readonly bool CompWithFirst; public Pair(T f, U s, int comp) { first = f; second = s; CompWithFirst = comp == 1; } public Pair(T f, U s) { first = f; second = s; CompWithFirst = true; } public int CompareTo(Pair<T, U> other) { return CompWithFirst ? first.CompareTo(other.first) : second.CompareTo(other.second); } } } public class PriorityQueue<T> where T : IComparable<T> { private List<T> Q; private readonly int r; public PriorityQueue(bool ascending) { if (ascending) { r = 1; } else { r = -1; } Q = new List<T>(); } private void PushHeap(List<T> list, T item) { int n = list.Count(); list.Add(item); while (n != 0) { int pIndex = (n - 1) / 2; if (list[n].CompareTo(list[pIndex]) * r > 0) { Swap(Q, n, pIndex); } else { break; } n = pIndex; } } private void PopHeap(List<T> list) { int n = list.Count() - 1; list[0] = list[n]; list.RemoveAt(n); int cur = 0; int comp; while (2 * cur + 1 <= n - 1) { int c1 = 2 * cur + 1; int c2 = 2 * (cur + 1); if (c1 == n - 1) { comp = c1; } else { comp = list[c1].CompareTo(list[c2]) * r > 0 ? c1 : c2; } if (list[cur].CompareTo(list[comp]) * r < 0) { Swap(Q, cur, comp); } else { break; } cur = comp; } } private void Swap(List<T> list, int a, int b) { T keep = list[a]; list[a] = list[b]; list[b] = keep; } public void Enqueue(T value) { PushHeap(Q, value); } public T Dequeue() { T ret = Q[0]; PopHeap(Q); return ret; } public T Peek() { return Q[0]; } public int Count() { return Q.Count(); } public bool Contains(T search) { return Q.Contains(search); } } public class Scanner { public int[] SplitRead() { int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray(); return array; } public long[] SplitReadL() { long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray(); return array; } } public static class Tool { static public void Initialize<T>(ref T[] array, T initialvalue) { for (var i = 0; i < array.Length; i++) { array[i] = initialvalue; } } static public T MaxLot<T>(params T[] val) where T : IComparable<T> { T ret = val[0]; for (var i = 1; i < val.Count(); i++) { if (ret.CompareTo(val[i]) < 0) { ret = val[i]; } } return ret; } static public T MinLot<T>(params T[] val) where T : IComparable<T> { T ret = val[0]; for (var i = 1; i < val.Count(); i++) { if (ret.CompareTo(val[i]) > 0) { ret = val[i]; } } return ret; } } }
[["+", 10, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 68]]
8
1,299
8
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCorder { public class Program { const long MOD = 1000000007; static void Main(string[] args) { var cin = new Scanner2(); int n = cin.Int(); int l = cin.Int(); long[] a = cin.ArrayLong(n); int index = -1; for (int i = 0; i < n - 1; i++) { if (a[i] + a[i + 1] >= l) { index = i; break; } } if (index == -1) { Console.WriteLine("Impossible"); return; } var sb = new StringBuilder(); for (int i = 0; i < index; i++) { sb.AppendLine((i + 1).ToString()); } for (int i = n - 1; i > index; i--) { sb.AppendLine((i + 1).ToString()); } sb.AppendLine((index + 1).ToString()); Console.WriteLine("Possible"); Console.WriteLine(sb.ToString()); } } public class Scanner2 { private readonly char[] delimiter_ = new char[] { ' ' }; private readonly string filePath_; private string[] buf_; private int index_; Func<string> reader_; public Scanner2(string file = "") { if (string.IsNullOrWhiteSpace(file)) { reader_ = Console.ReadLine; } else { filePath_ = file; var fs = new StreamReader(file); reader_ = fs.ReadLine; } buf_ = new string[0]; index_ = 0; } public string Next() { if (index_ < buf_.Length) { return buf_[index_++]; } string st = reader_(); while (st == "") { st = reader_(); } buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries); if (buf_.Length == 0) { return Next(); } index_ = 0; return buf_[index_++]; } public int Int() => int.Parse(Next()); public long Long() => long.Parse(Next()); public double Double() => double.Parse(Next()); public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = Int() + add; } return Array; } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = Long() + add; } return Array; } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = Double() + add; } return Array; } public void Save(string text) { if (string.IsNullOrWhiteSpace(filePath_)) { return; } File.WriteAllText(filePath_ + "_output.txt", text); } } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCorder { public class Program { const long MOD = 1000000007; static void Main(string[] args) { var cin = new Scanner2(); int n = cin.Int(); int l = cin.Int(); long[] a = cin.ArrayLong(n); int index = -1; for (int i = 0; i < n - 1; i++) { if (a[i] + a[i + 1] >= l) { index = i; break; } } if (index == -1) { Console.WriteLine("Impossible"); return; } var sb = new StringBuilder(); for (int i = 0; i < index; i++) { sb.AppendLine((i + 1).ToString()); } for (int i = n - 2; i > index; i--) { sb.AppendLine((i + 1).ToString()); } sb.AppendLine((index + 1).ToString()); Console.WriteLine("Possible"); Console.WriteLine(sb.ToString()); } } public class Scanner2 { private readonly char[] delimiter_ = new char[] { ' ' }; private readonly string filePath_; private string[] buf_; private int index_; Func<string> reader_; public Scanner2(string file = "") { if (string.IsNullOrWhiteSpace(file)) { reader_ = Console.ReadLine; } else { filePath_ = file; var fs = new StreamReader(file); reader_ = fs.ReadLine; } buf_ = new string[0]; index_ = 0; } public string Next() { if (index_ < buf_.Length) { return buf_[index_++]; } string st = reader_(); while (st == "") { st = reader_(); } buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries); if (buf_.Length == 0) { return Next(); } index_ = 0; return buf_[index_++]; } public int Int() => int.Parse(Next()); public long Long() => long.Parse(Next()); public double Double() => double.Parse(Next()); public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = Int() + add; } return Array; } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = Long() + add; } return Array; } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = Double() + add; } return Array; } public void Save(string text) { if (string.IsNullOrWhiteSpace(filePath_)) { return; } File.WriteAllText(filePath_ + "_output.txt", text); } } }
[["-", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
717
2
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 s = Console.ReadLine().Split(); var n = long.Parse(s[0]); var l = long.Parse(s[1]); var a = Console.ReadLine().Split().Select(long.Parse).ToArray(); var pos = new long(); bool flag = true; for (int i = 0; i < n - 1; i++) { if (a[i + 1] + a[i] > l) { flag = false; pos = i; break; } } if (!flag) { Console.WriteLine("Possible"); for (long i = 0; i < pos; i++) { Console.WriteLine(i + 1); } for (long i = n - 1; i > pos; i--) { Console.WriteLine(i); } } else { Console.WriteLine("Impossible"); } } } }
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 s = Console.ReadLine().Split(); var n = long.Parse(s[0]); var l = long.Parse(s[1]); var a = Console.ReadLine().Split().Select(long.Parse).ToArray(); var pos = new long(); bool flag = true; for (int i = 0; i < n - 1; i++) { if (a[i + 1] + a[i] >= l) { flag = false; pos = i; break; } } if (!flag) { Console.WriteLine("Possible"); for (long i = 0; i < pos; i++) { Console.WriteLine(i + 1); } for (long i = n - 1; i > pos; i--) { Console.WriteLine(i); } } else { Console.WriteLine("Impossible"); } } } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20]]
8
246
2
using System; using System.Linq; using System.Collections.Generic; using System.Text.RegularExpressions; using System.Text; public class Program { public void Proc() { Reader.IsDebug = false; long[] inpt = Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray(); int itemCount = (int)inpt[0]; long minLength = inpt[1]; long[] list = Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray(); for (int i = 1; i < list.Length; i++) { if (list[i - 1] + list[i] >= minLength) { Console.WriteLine("Possible"); StringBuilder ans = new StringBuilder(); for (int j = 0; j < i - 1; j++) { ans.AppendLine((j + 1).ToString()); } for (int j = list.Length - 2; j >= i; j++) { ans.AppendLine((j + 1).ToString()); } ans.AppendLine(i.ToString()); Console.Write(ans.ToString()); return; } } Console.WriteLine("Impossible"); } public class Reader { public static bool IsDebug = true; private static System.IO.StringReader SReader; private static string InitText = @" 2 21 10 10 "; public static string ReadLine() { if (IsDebug) { if (SReader == null) { SReader = new System.IO.StringReader(InitText.Trim()); } return SReader.ReadLine(); } else { return Console.ReadLine(); } } } public static void Main(string[] args) { Program prg = new Program(); prg.Proc(); } }
using System; using System.Linq; using System.Collections.Generic; using System.Text.RegularExpressions; using System.Text; public class Program { public void Proc() { Reader.IsDebug = false; long[] inpt = Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray(); int itemCount = (int)inpt[0]; long minLength = inpt[1]; long[] list = Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray(); for (int i = 1; i < list.Length; i++) { if (list[i - 1] + list[i] >= minLength) { Console.WriteLine("Possible"); StringBuilder ans = new StringBuilder(); for (int j = 0; j < i - 1; j++) { ans.AppendLine((j + 1).ToString()); } for (int j = list.Length - 2; j >= i; j--) { ans.AppendLine((j + 1).ToString()); } ans.AppendLine(i.ToString()); Console.Write(ans.ToString()); return; } } Console.WriteLine("Impossible"); } public class Reader { public static bool IsDebug = true; private static System.IO.StringReader SReader; private static string InitText = @" 2 21 10 10 "; public static string ReadLine() { if (IsDebug) { if (SReader == null) { SReader = new System.IO.StringReader(InitText.Trim()); } return SReader.ReadLine(); } else { return Console.ReadLine(); } } } public static void Main(string[] args) { Program prg = new Program(); prg.Proc(); } }
[["-", 0, 57, 64, 196, 0, 7, 26, 223, 0, 29], ["+", 0, 57, 64, 196, 0, 7, 26, 223, 0, 68]]
8
395
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AGC002_C { class Program { static void Main(string[] args) { var z = scan(); var a = scan(); int last = 0; bool flag = false; for (int i = 0; i < z[0] - 1; i++) { if (a[i] + a[i + 1] >= z[1]) { last = i + 1; flag = true; break; } } if (flag) { var sb = new StringBuilder(); sb.AppendLine("Possoble"); for (int i = 1; i < last; i++) { sb.AppendLine(i.ToString()); } for (int i = z[0] - 1; i > last; i--) { sb.AppendLine(i.ToString()); } sb.AppendLine(last.ToString()); Console.Write(sb); } else { Console.WriteLine("Impossible"); } } static int[] scan() { return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AGC002_C { class Program { static void Main(string[] args) { var z = scan(); var a = scan(); int last = 0; bool flag = false; for (int i = 0; i < z[0] - 1; i++) { if (a[i] + a[i + 1] >= z[1]) { last = i + 1; flag = true; break; } } if (flag) { var sb = new StringBuilder(); sb.AppendLine("Possible"); for (int i = 1; i < last; i++) { sb.AppendLine(i.ToString()); } for (int i = z[0] - 1; i > last; i--) { sb.AppendLine(i.ToString()); } sb.AppendLine(last.ToString()); Console.Write(sb); } else { Console.WriteLine("Impossible"); } } static int[] scan() { return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
268
2
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; // using static System.Linq.Enumerable; using static System.Console; using static AtCoder.Util; using static AtCoder.Cin; using static System.Math; using static AtCoder.MyMath; using static AtCoder.StreamExtensions; using static AtCoder.Matrix; namespace AtCoder { using VI = VectorInt2; static class Program { static void Main() { var n = ReadInt(); var k = ReadInt(); var d = ReadInt(k); // n.Iterate(Plus(1)).First(x => // x.ToDigits().Intersect(d).isEmpty()).WriteLine(); while (true) { WriteLine(n); var digits = n.ToDigits().ToList(); if (digits[0].In(d)) { n = (digits[0] + 1) * (int)10. Pow((long)digits.Count - 1); continue; } // WriteLine($"->{n}"); if (n.ToDigits().Intersect(d).isEmpty()) { n.WriteLine(); return; } n++; } } } } /* ***************** Following Contents are my common library ******** */ namespace AtCoder { static class Algorithm { public static LongRange BinSearch(LongRange range, Func<long, bool> isBigger, long width) => BinSearch(range, isBigger, x => range.Right - range.Left < width); public static LongRange BinSearch(LongRange range, Func<long, bool> isBigger, Func<LongRange, bool> stopCondition) { if (stopCondition(range)) return range; var middle = range.Left + (range.Right - range.Left) / 2; return isBigger(middle) ? BinSearch(new LongRange(range.Left, middle), isBigger, stopCondition) : BinSearch(new LongRange(middle, range.Right), isBigger, stopCondition); } } static class MyMath { public static int DivRoundUp(int a, int b) { var q = a / b; if (a % b != 0) q++; return q; } public static long GCD(long a, long b) => a<b? GCD(b, a) : b> 0 ? GCD(b, a % b) : a; public static long GCD(this IEnumerable<long> source) => source.Aggregate(GCD); public static long LCM(long a, long b) { var g = GCD(a, b); var a1 = a / g; var b1 = b / g; return g * a1 * b1; } public static long LCM(this IEnumerable<long> source) => source.Aggregate(LCM); public static long Factorial(this long n) => Range(1, n).Aggregate(1L, Mul); public static long nPr(int n, int r) => r < 0 || r > n? 0 : FromTo(n - r + 1, n) .Select(x => (long)x) .Aggregate(1L, Mul); public static long nCr(int n, int r) => nPr(n, r) / Factorial(r); public static long Inc(long i) => i + 1; public static long Dec(long i) => i - 1; public static long Plus(long i, long j) => i + j; public static Func<long, long> Plus(long j) => i => i + j; public static long Minus(long i, long j) => i - j; public static Func<long, long> Minus(long j) => i => i - j; public static long Mul(long i, long j) => i * j; public static Func<long, long> Mul(long j) => i => i * j; public static long Div(long i, long j) => j / j; public static Func<long, long> Div(long j) => i => i * j; public static long Mod(long i, long j) => i % j; public static Func<long, long> Mod(long j) => i => i % j; public static Func<long, bool> Leq(long j) => i => i <= j; public static Func<long, bool> Gt(long j) => i => i > j; public static Func<long, bool> Geq(long j) => i => i >= j; public static Func<long, bool> Eq(long j) => i => i == j; public static Func<long, bool> Neq(long j) => i => i != j; public static int Plus(int i, int j) => i + j; public static Func<int, int> Plus(int j) => i => i + j; public static int Minus(int i, int j) => i - j; public static Func<int, int> Minus(int j) => i => i - j; public static int Mul(int i, int j) => i * j; public static Func<int, int> Mul(int j) => i => i * j; public static int Div(int i, int j) => j / j; public static Func<int, int> Div(int j) => i => i * j; public static int Mod(int i, int j) => i % j; public static Func<int, int> Mod(int j) => i => i % j; public static Func<int, bool> Lt(int j) => i => i < j; public static Func<int, bool> Leq(int j) => i => i <= j; public static Func<int, bool> Gt(int j) => i => i > j; public static Func<int, bool> Geq(int j) => i => i >= j; public static Func<int, bool> Eq(int j) => i => i == j; public static Func<int, bool> Neq(int j) => i => i != j; public static long Max(params long[] ns) => ns.Max(); public static long LowerBound(this long m, long lbound) => Max(m, lbound); public static long UpperBound(this long m, long ubound) => Min(m, ubound); public static long Bound(this long m, long lowerBound, long UpperBound) => m.LowerBound(lowerBound).UpperBound(UpperBound); public static long LowerBound(this int m, long lbound) => Max(m, lbound); public static long UpperBound(this int m, long ubound) => Min(m, ubound); public static long Bound(this int m, long lowerBound, long UpperBound) => m.LowerBound(lowerBound).UpperBound(UpperBound); public static bool InRange(this long x, long min, long max) => min <= x && x <= max; public static bool IsEven(this int x) => x % 2 == 0; public static bool IsOdd(this int x) => x % 2 != 0; public static bool IsEven(this long x) => x % 2 == 0; public static bool IsOdd(this long x) => x % 2 != 0; public static IEnumerable<int> ToDigits(this long n) => n.ToString().Select(x => x.ToInt()); public static IEnumerable<int> ToDigits(this int n) => ((long)n).ToDigits(); public static IEnumerable<int> Factors(this int n) { for (int i = 1; i <= n; i++) if (n % i == 0) yield return i; } public static IEnumerable<long> Factors(this long n) { for (long i = 1; i <= n; i++) if (n % i == 0) yield return i; } public static MultiSet<long> Factorize(this long n) { var factors = new MultiSet<long>(); for (long i = 2; i * i <= n; i++) { while (n % i == 0) { n /= i; factors[i]++; } } if (n > 1) factors.Add(n); return factors; } public static IEnumerable<int> Natural() { for (int i = 0;; i++) yield return i; } public static IEnumerable<int> Positive() => Natural().Skip(1); public static long Pow(this long i, long exp) => (exp == 0) ? 1 : i * Pow(i, exp - 1); public static long Pow(this int i, long exp) => (exp == 0) ? 1 : i * Pow(i, exp - 1); public static int IntLog(this long n, long baseNum) { int count = 0; while (n >= baseNum) { n /= baseNum; count++; } return count; } } static class Util { public static InvalidOperationException UnreachableException = new InvalidOperationException("unreachable."); public static string Show(this IEnumerable<char> source) => new string(source.ToArray()); public static HashSet<T> ToHashSet<T>(this IEnumerable<T> source) => new HashSet<T>(source); public static MultiSet<T> ToMultiSet<T>(this IEnumerable<T> t) => new MultiSet<T>(t); public static bool IsPalindrome(string s) { for (int i = 0; i < s.Length / 2; i++) { if (s[i] != s[s.Length - 1 - i]) return false; } return true; } public readonly static VectorInt2[] Dir8 = { new VectorInt2(-1, -1), new VectorInt2(-1, 0), new VectorInt2(-1, 1), new VectorInt2(0, -1), new VectorInt2(0, 1), new VectorInt2(1, -1), new VectorInt2(1, 0), new VectorInt2(1, 1) }; public const long MODCONST = 1000000007; public static T debug<T>(this T value) { Console.Error.WriteLine($"debug:{value}"); return value; } public static T Id<T>(T t) => t; public static long ToLong(this String s) => long.Parse(s); public static long ToLong(this char c) => c - '0'; public static int ToInt(this String s) => int.Parse(s); public static int ToInt(this char c) => c - '0'; public static VectorInt2 ReadVectorInt2() => new VectorInt2(ReadInt(), ReadInt()); public static VectorDouble2 ReadVectorDouble2() => new VectorDouble2(ReadInt(), ReadInt()); public static string ReplaceX(this string input, string pattern, string replace) => Regex.Replace(input, pattern, replace); public static IEnumerable<int> Range(int i, int j) => Enumerable.Range(i, j); public static IEnumerable<long> Range(long i, long j) { for (long k = i; k < i + j; k++) yield return k; } public static void Swap<T>(this IList<T> enumerable, int i, int j) { var buf = enumerable[i]; enumerable[i] = enumerable[j]; enumerable[j] = buf; } public static bool In<T>(this T t, IEnumerable<T> range) => range.Contains(t); } static class ParametricExtensions { public static Func<S, U> Then<S, T, U>(this Func<S, T> f, Func<T, U> g) => x => g(f(x)); public static Func<S, U> Compose<S, T, U>(this Func<T, U> f, Func<S, T> g) => x => f(g(x)); public static void Call<T>(this T t, Action<T> action) => action(t); public static void WriteLine<T>(this T t) => Console.WriteLine(t); public static void Write<T>(this T t) => Console.Write(t); public static T Call<S, T>(this S s, Func<S, T> func) => func(s); public static S Call<S>(this S s, Func<S, S> func, int times) => times == 0 ? s : Call(func(s), func, times - 1); } static class StreamExtensions { public static void ReverseRange<T>(this IList<T> enumerable, int i, int j) { int half = (j - i) / 2; for (int k = 0; k <= half; k++) enumerable.Swap(i + k, j - k); } public static bool isEmpty<T>(this IEnumerable<T> enumerable) => !enumerable.Any(); public static void Times(this int n, Action action) { for (int i = 0; i < n; i++) action(); } public static void Times(this long n, Action action) { for (long i = 0; i < n; i++) action(); } public static IEnumerable<T> Times<T>(this int n, Func<T> func) { for (long i = 0; i < n; i++) yield return func(); } public static IEnumerable<T> Times<T>(this long n, Func<T> func) { for (long i = 0; i < n; i++) yield return func(); } public static IEnumerable<T> Iterate<T>(this T init, Func<T, T> f) { yield return init; foreach (var item in Iterate(f(init), f)) yield return item; } public static void ForEach<T>(this IEnumerable<T> e, Action<T> action) { foreach (var v in e) action(v); } public static long Prod(this IEnumerable<long> source) => source.Aggregate(Mul); public static IEnumerable<int> FromTo(int a, int b) => Range(a, Max(b - a + 1, 0)); public static IEnumerable<T> Repeat<T>(T t) { while (true) yield return t; } public static IEnumerable<T> Replicate<T>(int n, T t) => Repeat(t).Take(n); public static IEnumerable<T> Cycle<T>(this IEnumerable<T> e) { while (true) foreach (var v in e) yield return v; } public static IEnumerable<T> Scan<S, T>(this IEnumerable<S> source, T init, Func<T, S, T> accumulator) { var result = init; foreach (var item in source) { result = accumulator(result, item); yield return result; } } public static T[] ToArray<T>(params T[] ns) => ns; public static List<T> ToList<T>(params T[] ns) => ns.ToList(); public static Dictionary<T1, T2> ToDictionary<T1, T2>(this IEnumerable<KeyValuePair<T1, T2>> source) { var dict = new Dictionary<T1, T2>(); source.ForEach(x => dict.Add(x.Key, x.Value)); return dict; } public static SortedDictionary<T1, T2> ToSortedDictionary<T1, T2>(this IEnumerable<KeyValuePair<T1, T2>> source) => new SortedDictionary<T1, T2>(source.ToDictionary()); public static MultiSet<T> ToMultiSet<T>(this IEnumerable<KeyValuePair<T, long>> source) => new MultiSet<T>(source); public static SortedMultiSet<T> ToSortedMultiSet<T>(this IEnumerable<KeyValuePair<T, long>> source) => new SortedMultiSet<T>(source); public static IEnumerable<T> Scan0<S, T>(this IEnumerable<S> source, T init, Func<T, S, T> accumulator) { yield return init; foreach (var item in Scan(source, init, accumulator)) yield return item; } public static IEnumerable<Tuple<T1, T2>> Cartesian<T1, T2>(IEnumerable<T1> s1, IEnumerable<T2> s2) => from v1 in s1 from v2 in s2 select new Tuple<T1, T2>(v1, v2); public static IEnumerable<Tuple<T1, T2, T3>> Cartesian<T1, T2, T3>( IEnumerable<T1> s1, IEnumerable<T2> s2, IEnumerable<T3> s3) => from v1 in s1 from v2 in s2 from v3 in s3 select new Tuple<T1, T2, T3>(v1, v2, v3); public static IEnumerable<Tuple<T1, T2, T3, T4>> Cartesian<T1, T2, T3, T4>(IEnumerable<T1> s1, IEnumerable<T2> s2, IEnumerable<T3> s3, IEnumerable<T4> s4) => from v1 in s1 from v2 in s2 from v3 in s3 from v4 in s4 select new Tuple<T1, T2, T3, T4>(v1, v2, v3, v4); public static IEnumerable<Tuple<int, T>> Enumerate<T>(IEnumerable<T> source) { int i = 0; foreach (var item in source) { yield return new Tuple<int, T>(i, item); i++; } } public static IEnumerable<List<T>> Buffer<T>(this IEnumerable<T> source, int length) { while (source.Any()) { yield return source.Take(length).ToList(); source = source.Skip(length); } } public static T MaxBy<T>(this IEnumerable<T> source, Func<T, long> selector) { T max = source.First(); foreach (var item in source) if (selector(item) > selector(max)) max = item; return max; } public static T MinBy<T>(this IEnumerable<T> source, Func<T, long> selector) { T min = source.First(); foreach (var item in source) if (selector(item) < selector(min)) min = item; return min; } public static int IndexOf<T>(this IList<T> source, Func<T, bool> condition) { for (int i = 0; i < source.Count; i++) if (condition(source[i])) return i; return -1; } public static IEnumerable<List<T>> ChunkBy<T>(this IEnumerable<T> source) => ChunkBy(source, Id, EqualityComparer<T>.Default); public static IEnumerable<List<T>> ChunkBy<S, T>(this IEnumerable<T> source, Func<T, S> selector) => ChunkBy(source, selector, EqualityComparer<S>.Default); public static IEnumerable<List<T>> ChunkBy<S, T>(this IEnumerable<T> source, Func<T, S> selector, IEqualityComparer<S> comparer) { while (source.Any()) { var v = selector(source.First()); var l = source.TakeWhile(x => comparer.Equals(selector(x), v)).ToList(); yield return l; source = source.Skip(l.Count()); } } } static class Matrix { public static List<List<T>> Transpose<T>(this List<List<T>> source) => Range(0, source[0].Count) .Select(i => source.Select(x => x[i]).ToList()) .ToList(); public static void WriteMatrix(this IEnumerable<IEnumerable<char>> source) { foreach (var line in source) line.Show().WriteLine(); } public static List<List<long>> ReadLongMatrix(int h, int w) => h.Times(() => ReadLong(w)).ToList(); public static List<List<T>> SelectMatrix<S, T>(this List<List<S>> source, Func<S, T> f) => source.Select(x => x.Select(f).ToList()).ToList(); } static class Cin { private static Queue<string> tokens; static Cin() { string line; tokens = new Queue<string>(); while ((line = Console.ReadLine()) != null) { foreach (var token in line.Split(' ')) { tokens.Enqueue(token); } } } static public int ReadInt() => int.Parse(tokens.Dequeue()); static public List<int> ReadInt(long n) { var list = new List<int>(); n.Times(() => list.Add(ReadInt())); return list; } static public long ReadLong() => long.Parse(tokens.Dequeue()); static public List<long> ReadLong(long n) { var list = new List<long>(); n.Times(() => list.Add(ReadLong())); return list; } static public string ReadString() => tokens.Dequeue(); static public List<string> ReadString(long n) { var list = new List<string>(); n.Times(() => list.Add(ReadString())); return list; } static public void SayYesNo(this bool b) => (b ? "Yes" : "No").WriteLine(); static public void SayYESNO(this bool b) => (b ? "YES" : "NO").WriteLine(); } public struct VectorInt2 { public int X { get; set; } public int Y { get; set; } public VectorInt2(int x, int y) { X = x; Y = y; } static public VectorInt2 operator +(VectorInt2 v1, VectorInt2 v2) => new VectorInt2(v1.X + v2.X, v1.Y + v2.Y); static public VectorInt2 operator -(VectorInt2 v1, VectorInt2 v2) => new VectorInt2(v1.X - v2.X, v1.Y - v2.Y); static public VectorInt2 operator *(VectorInt2 v1, VectorInt2 v2) => new VectorInt2(v1.X * v2.X, v1.Y *v2.Y); static public VectorInt2 operator *(VectorInt2 v1, int i) => new VectorInt2(v1.X * i, v1.Y *i); static public VectorInt2 operator *(int i, VectorInt2 v2) => new VectorInt2(i * v2.X, i *v2.Y); static public VectorInt2 operator /(VectorInt2 v1, int i) => new VectorInt2(v1.X / i, v1.Y / i); public override string ToString() => $"({X}, {Y})"; } struct VectorDouble2 { public double X { get; set; } public double Y { get; set; } public VectorDouble2(double x, double y) { X = x; Y = y; } static public VectorDouble2 operator +(VectorDouble2 v1, VectorDouble2 v2) => new VectorDouble2(v1.X + v2.X, v1.Y + v2.Y); static public VectorDouble2 operator -(VectorDouble2 v1, VectorDouble2 v2) => new VectorDouble2(v1.X - v2.X, v1.Y - v2.Y); static public VectorDouble2 operator *(VectorDouble2 v1, VectorDouble2 v2) => new VectorDouble2(v1.X * v2.X, v1.Y *v2.Y); static public VectorDouble2 operator *(VectorDouble2 v1, int i) => new VectorDouble2(v1.X * i, v1.Y *i); static public VectorDouble2 operator *(int i, VectorDouble2 v2) => new VectorDouble2(i * v2.X, i *v2.Y); static public VectorDouble2 operator /(VectorDouble2 v1, double i) => new VectorDouble2(v1.X / i, v1.Y / i); public override string ToString() => $"({X}, {Y})"; public VectorDouble2 Turn(double radian) => new VectorDouble2(X * Cos(radian) - Y * Sin(radian), X *Sin(radian) + Y * Cos(radian)); } public struct LongRange { public long Left; public long Right; public LongRange(long left, long right) { Left = left; Right = right; } } public struct LongFromToVector { public VectorInt2 Start; public VectorInt2 End; public LongFromToVector(VectorInt2 start, VectorInt2 end) { Start = start; End = end; } } } namespace AtCoder { using System.Collections.Generic; using System.Collections; using System.Linq; using System; class MultiSet<T> : ICollection<T> { // TODO: 順番がグチャグチャなので整理する Dictionary<T, long> occurrence; public MultiSet() { occurrence = new Dictionary<T, long>(); } public MultiSet(MultiSet<T> source) : this(source.occurrence) {} public MultiSet(Dictionary<T, long> source) { occurrence = new Dictionary<T, long>(source); Validate(); } public MultiSet(IEnumerable<T> source) { occurrence = new Dictionary<T, long>(); AddRange(source); } public MultiSet(IEnumerable<KeyValuePair<T, long>> source) { occurrence = new Dictionary<T, long>(); foreach (var item in source) this[item.Key] += item.Value; } public void Add(T data) { if (!occurrence.ContainsKey(data)) { occurrence[data] = 1; return; } occurrence[data]++; } public void Clear() => occurrence.Clear(); public void Add(T key, int value) { if (value <= 0) throw new ArgumentException(); if (!occurrence.ContainsKey(key)) { occurrence[key] = value; return; } occurrence[key] += value; } public void Add(KeyValuePair<T, int> pair) => Add(pair.Key, pair.Value); public void AddRange(IEnumerable<T> source) => source.ToList().ForEach(Add); public bool Remove(T data) { if (!occurrence.ContainsKey(data)) return false; occurrence[data]--; if (occurrence[data] == 0) occurrence.Remove(data); return true; } // IDictionary public long this[T key] { get { return occurrence.ContainsKey(key) ? occurrence[key] : 0; } set { if (value <= 0) throw new ArgumentException(); occurrence[key] = value; } } public ICollection<T> Keys { get { return occurrence.Keys; } } public ICollection<long> Values { get { return occurrence.Values; } } public IEnumerable<KeyValuePair<T, long>> KeyValuePairs { get { foreach (var pair in occurrence) yield return pair; } } public bool ContainsKey(T key) => occurrence.ContainsKey(key); public bool Contains(T key) => ContainsKey(key); public bool TryGetValue(T key, out long value) { value = this[key]; return true; } // /IDictionary public long LongCount() => occurrence.Values.Sum(); public int Count => (int)occurrence.Values.Sum(); public bool IsReadOnly => false; public void CopyTo(T[] array, int index) { foreach (var pair in occurrence) { for (int i = 0; i < pair.Value; i++) { array[index] = pair.Key; index++; } } } public IEnumerator<T> GetEnumerator() { foreach (var pair in occurrence) for (int i = 0; i < pair.Value; i++) yield return pair.Key; } IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); public void Validate() { if (occurrence.Values.Any(x => x <= 0)) throw new ArgumentException(); } } class SortedMultiSet<T> : ICollection<T> { // TODO: 順番がグチャグチャなので整理する SortedDictionary<T, long> occurrence; public SortedMultiSet() { occurrence = new SortedDictionary<T, long>(); } public SortedMultiSet(SortedMultiSet<T> source) : this(source.occurrence) {} public SortedMultiSet(SortedDictionary<T, long> source) { occurrence = new SortedDictionary<T, long>(source); Validate(); } public SortedMultiSet(IEnumerable<T> source) { occurrence = new SortedDictionary<T, long>(); AddRange(source); } public SortedMultiSet(IEnumerable<KeyValuePair<T, long>> source) { occurrence = new SortedDictionary<T, long>(); foreach (var item in source) this[item.Key] += item.Value; } public void Add(T data) { if (!occurrence.ContainsKey(data)) { occurrence[data] = 1; return; } occurrence[data]++; } public void Clear() => occurrence.Clear(); public void Add(T key, int value) { if (value <= 0) throw new ArgumentException(); if (!occurrence.ContainsKey(key)) { occurrence[key] = value; return; } occurrence[key] += value; } public long LongCount() => occurrence.Values.Sum(); public int Count => (int)occurrence.Values.Sum(); public void Add(KeyValuePair<T, int> pair) => Add(pair.Key, pair.Value); public void AddRange(IEnumerable<T> source) => source.ToList().ForEach(Add); public bool Remove(T data) { if (!occurrence.ContainsKey(data)) return false; occurrence[data]--; if (occurrence[data] == 0) occurrence.Remove(data); return true; } // IDictionary public long this[T key] { get { return occurrence.ContainsKey(key) ? occurrence[key] : 0; } set { if (value <= 0) throw new ArgumentException(); occurrence[key] = value; } } public ICollection<T> Keys => occurrence.Keys; public ICollection<long> Values => occurrence.Values; public bool ContainsKey(T key) => occurrence.ContainsKey(key); public bool Contains(T key) => ContainsKey(key); public bool TryGetValue(T key, out long value) { value = this[key]; return true; } // /IDictionary public bool IsReadOnly => false; public void CopyTo(T[] array, int index) { foreach (var pair in occurrence) { for (int i = 0; i < pair.Value; i++) { array[index] = pair.Key; index++; } } } public IEnumerator<T> GetEnumerator() { foreach (var pair in occurrence) for (int i = 0; i < pair.Value; i++) yield return pair.Key; } IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); public void Validate() { if (occurrence.Values.Any(x => x <= 0)) throw new ArgumentException(); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; // using static System.Linq.Enumerable; using static System.Console; using static AtCoder.Util; using static AtCoder.Cin; using static System.Math; using static AtCoder.MyMath; using static AtCoder.StreamExtensions; using static AtCoder.Matrix; namespace AtCoder { using VI = VectorInt2; static class Program { static void Main() { var n = ReadInt(); var k = ReadInt(); var d = ReadInt(k); // TLE する // n.Iterate(Plus(1)).First(x => // x.ToDigits().Intersect(d).isEmpty()).WriteLine(); while (true) { // 最上位だけ賢くスキップする var digits = n.ToDigits().ToList(); if (digits[0].In(d)) { n = (digits[0] + 1) * (int)10. Pow((long)digits.Count - 1); continue; } if (n.ToDigits().Intersect(d).isEmpty()) { n.WriteLine(); return; } n++; } } } } /* ***************** Following Contents are my common library ******** */ namespace AtCoder { static class Algorithm { public static LongRange BinSearch(LongRange range, Func<long, bool> isBigger, long width) => BinSearch(range, isBigger, x => range.Right - range.Left < width); public static LongRange BinSearch(LongRange range, Func<long, bool> isBigger, Func<LongRange, bool> stopCondition) { if (stopCondition(range)) return range; var middle = range.Left + (range.Right - range.Left) / 2; return isBigger(middle) ? BinSearch(new LongRange(range.Left, middle), isBigger, stopCondition) : BinSearch(new LongRange(middle, range.Right), isBigger, stopCondition); } } static class MyMath { public static int DivRoundUp(int a, int b) { var q = a / b; if (a % b != 0) q++; return q; } public static long GCD(long a, long b) => a<b? GCD(b, a) : b> 0 ? GCD(b, a % b) : a; public static long GCD(this IEnumerable<long> source) => source.Aggregate(GCD); public static long LCM(long a, long b) { var g = GCD(a, b); var a1 = a / g; var b1 = b / g; return g * a1 * b1; } public static long LCM(this IEnumerable<long> source) => source.Aggregate(LCM); public static long Factorial(this long n) => Range(1, n).Aggregate(1L, Mul); public static long nPr(int n, int r) => r < 0 || r > n? 0 : FromTo(n - r + 1, n) .Select(x => (long)x) .Aggregate(1L, Mul); public static long nCr(int n, int r) => nPr(n, r) / Factorial(r); public static long Inc(long i) => i + 1; public static long Dec(long i) => i - 1; public static long Plus(long i, long j) => i + j; public static Func<long, long> Plus(long j) => i => i + j; public static long Minus(long i, long j) => i - j; public static Func<long, long> Minus(long j) => i => i - j; public static long Mul(long i, long j) => i * j; public static Func<long, long> Mul(long j) => i => i * j; public static long Div(long i, long j) => j / j; public static Func<long, long> Div(long j) => i => i * j; public static long Mod(long i, long j) => i % j; public static Func<long, long> Mod(long j) => i => i % j; public static Func<long, bool> Leq(long j) => i => i <= j; public static Func<long, bool> Gt(long j) => i => i > j; public static Func<long, bool> Geq(long j) => i => i >= j; public static Func<long, bool> Eq(long j) => i => i == j; public static Func<long, bool> Neq(long j) => i => i != j; public static int Plus(int i, int j) => i + j; public static Func<int, int> Plus(int j) => i => i + j; public static int Minus(int i, int j) => i - j; public static Func<int, int> Minus(int j) => i => i - j; public static int Mul(int i, int j) => i * j; public static Func<int, int> Mul(int j) => i => i * j; public static int Div(int i, int j) => j / j; public static Func<int, int> Div(int j) => i => i * j; public static int Mod(int i, int j) => i % j; public static Func<int, int> Mod(int j) => i => i % j; public static Func<int, bool> Lt(int j) => i => i < j; public static Func<int, bool> Leq(int j) => i => i <= j; public static Func<int, bool> Gt(int j) => i => i > j; public static Func<int, bool> Geq(int j) => i => i >= j; public static Func<int, bool> Eq(int j) => i => i == j; public static Func<int, bool> Neq(int j) => i => i != j; public static long Max(params long[] ns) => ns.Max(); public static long LowerBound(this long m, long lbound) => Max(m, lbound); public static long UpperBound(this long m, long ubound) => Min(m, ubound); public static long Bound(this long m, long lowerBound, long UpperBound) => m.LowerBound(lowerBound).UpperBound(UpperBound); public static long LowerBound(this int m, long lbound) => Max(m, lbound); public static long UpperBound(this int m, long ubound) => Min(m, ubound); public static long Bound(this int m, long lowerBound, long UpperBound) => m.LowerBound(lowerBound).UpperBound(UpperBound); public static bool InRange(this long x, long min, long max) => min <= x && x <= max; public static bool IsEven(this int x) => x % 2 == 0; public static bool IsOdd(this int x) => x % 2 != 0; public static bool IsEven(this long x) => x % 2 == 0; public static bool IsOdd(this long x) => x % 2 != 0; public static IEnumerable<int> ToDigits(this long n) => n.ToString().Select(x => x.ToInt()); public static IEnumerable<int> ToDigits(this int n) => ((long)n).ToDigits(); public static IEnumerable<int> Factors(this int n) { for (int i = 1; i <= n; i++) if (n % i == 0) yield return i; } public static IEnumerable<long> Factors(this long n) { for (long i = 1; i <= n; i++) if (n % i == 0) yield return i; } public static MultiSet<long> Factorize(this long n) { var factors = new MultiSet<long>(); for (long i = 2; i * i <= n; i++) { while (n % i == 0) { n /= i; factors[i]++; } } if (n > 1) factors.Add(n); return factors; } public static IEnumerable<int> Natural() { for (int i = 0;; i++) yield return i; } public static IEnumerable<int> Positive() => Natural().Skip(1); public static long Pow(this long i, long exp) => (exp == 0) ? 1 : i * Pow(i, exp - 1); public static long Pow(this int i, long exp) => (exp == 0) ? 1 : i * Pow(i, exp - 1); public static int IntLog(this long n, long baseNum) { int count = 0; while (n >= baseNum) { n /= baseNum; count++; } return count; } } static class Util { public static InvalidOperationException UnreachableException = new InvalidOperationException("unreachable."); public static string Show(this IEnumerable<char> source) => new string(source.ToArray()); public static HashSet<T> ToHashSet<T>(this IEnumerable<T> source) => new HashSet<T>(source); public static MultiSet<T> ToMultiSet<T>(this IEnumerable<T> t) => new MultiSet<T>(t); public static bool IsPalindrome(string s) { for (int i = 0; i < s.Length / 2; i++) { if (s[i] != s[s.Length - 1 - i]) return false; } return true; } public readonly static VectorInt2[] Dir8 = { new VectorInt2(-1, -1), new VectorInt2(-1, 0), new VectorInt2(-1, 1), new VectorInt2(0, -1), new VectorInt2(0, 1), new VectorInt2(1, -1), new VectorInt2(1, 0), new VectorInt2(1, 1) }; public const long MODCONST = 1000000007; public static T debug<T>(this T value) { Console.Error.WriteLine($"debug:{value}"); return value; } public static T Id<T>(T t) => t; public static long ToLong(this String s) => long.Parse(s); public static long ToLong(this char c) => c - '0'; public static int ToInt(this String s) => int.Parse(s); public static int ToInt(this char c) => c - '0'; public static VectorInt2 ReadVectorInt2() => new VectorInt2(ReadInt(), ReadInt()); public static VectorDouble2 ReadVectorDouble2() => new VectorDouble2(ReadInt(), ReadInt()); public static string ReplaceX(this string input, string pattern, string replace) => Regex.Replace(input, pattern, replace); public static IEnumerable<int> Range(int i, int j) => Enumerable.Range(i, j); public static IEnumerable<long> Range(long i, long j) { for (long k = i; k < i + j; k++) yield return k; } public static void Swap<T>(this IList<T> enumerable, int i, int j) { var buf = enumerable[i]; enumerable[i] = enumerable[j]; enumerable[j] = buf; } public static bool In<T>(this T t, IEnumerable<T> range) => range.Contains(t); } static class ParametricExtensions { public static Func<S, U> Then<S, T, U>(this Func<S, T> f, Func<T, U> g) => x => g(f(x)); public static Func<S, U> Compose<S, T, U>(this Func<T, U> f, Func<S, T> g) => x => f(g(x)); public static void Call<T>(this T t, Action<T> action) => action(t); public static void WriteLine<T>(this T t) => Console.WriteLine(t); public static void Write<T>(this T t) => Console.Write(t); public static T Call<S, T>(this S s, Func<S, T> func) => func(s); public static S Call<S>(this S s, Func<S, S> func, int times) => times == 0 ? s : Call(func(s), func, times - 1); } static class StreamExtensions { public static void ReverseRange<T>(this IList<T> enumerable, int i, int j) { int half = (j - i) / 2; for (int k = 0; k <= half; k++) enumerable.Swap(i + k, j - k); } public static bool isEmpty<T>(this IEnumerable<T> enumerable) => !enumerable.Any(); public static void Times(this int n, Action action) { for (int i = 0; i < n; i++) action(); } public static void Times(this long n, Action action) { for (long i = 0; i < n; i++) action(); } public static IEnumerable<T> Times<T>(this int n, Func<T> func) { for (long i = 0; i < n; i++) yield return func(); } public static IEnumerable<T> Times<T>(this long n, Func<T> func) { for (long i = 0; i < n; i++) yield return func(); } public static IEnumerable<T> Iterate<T>(this T init, Func<T, T> f) { yield return init; foreach (var item in Iterate(f(init), f)) yield return item; } public static void ForEach<T>(this IEnumerable<T> e, Action<T> action) { foreach (var v in e) action(v); } public static long Prod(this IEnumerable<long> source) => source.Aggregate(Mul); public static IEnumerable<int> FromTo(int a, int b) => Range(a, Max(b - a + 1, 0)); public static IEnumerable<T> Repeat<T>(T t) { while (true) yield return t; } public static IEnumerable<T> Replicate<T>(int n, T t) => Repeat(t).Take(n); public static IEnumerable<T> Cycle<T>(this IEnumerable<T> e) { while (true) foreach (var v in e) yield return v; } public static IEnumerable<T> Scan<S, T>(this IEnumerable<S> source, T init, Func<T, S, T> accumulator) { var result = init; foreach (var item in source) { result = accumulator(result, item); yield return result; } } public static T[] ToArray<T>(params T[] ns) => ns; public static List<T> ToList<T>(params T[] ns) => ns.ToList(); public static Dictionary<T1, T2> ToDictionary<T1, T2>(this IEnumerable<KeyValuePair<T1, T2>> source) { var dict = new Dictionary<T1, T2>(); source.ForEach(x => dict.Add(x.Key, x.Value)); return dict; } public static SortedDictionary<T1, T2> ToSortedDictionary<T1, T2>(this IEnumerable<KeyValuePair<T1, T2>> source) => new SortedDictionary<T1, T2>(source.ToDictionary()); public static MultiSet<T> ToMultiSet<T>(this IEnumerable<KeyValuePair<T, long>> source) => new MultiSet<T>(source); public static SortedMultiSet<T> ToSortedMultiSet<T>(this IEnumerable<KeyValuePair<T, long>> source) => new SortedMultiSet<T>(source); public static IEnumerable<T> Scan0<S, T>(this IEnumerable<S> source, T init, Func<T, S, T> accumulator) { yield return init; foreach (var item in Scan(source, init, accumulator)) yield return item; } public static IEnumerable<Tuple<T1, T2>> Cartesian<T1, T2>(IEnumerable<T1> s1, IEnumerable<T2> s2) => from v1 in s1 from v2 in s2 select new Tuple<T1, T2>(v1, v2); public static IEnumerable<Tuple<T1, T2, T3>> Cartesian<T1, T2, T3>( IEnumerable<T1> s1, IEnumerable<T2> s2, IEnumerable<T3> s3) => from v1 in s1 from v2 in s2 from v3 in s3 select new Tuple<T1, T2, T3>(v1, v2, v3); public static IEnumerable<Tuple<T1, T2, T3, T4>> Cartesian<T1, T2, T3, T4>(IEnumerable<T1> s1, IEnumerable<T2> s2, IEnumerable<T3> s3, IEnumerable<T4> s4) => from v1 in s1 from v2 in s2 from v3 in s3 from v4 in s4 select new Tuple<T1, T2, T3, T4>(v1, v2, v3, v4); public static IEnumerable<Tuple<int, T>> Enumerate<T>(IEnumerable<T> source) { int i = 0; foreach (var item in source) { yield return new Tuple<int, T>(i, item); i++; } } public static IEnumerable<List<T>> Buffer<T>(this IEnumerable<T> source, int length) { while (source.Any()) { yield return source.Take(length).ToList(); source = source.Skip(length); } } public static T MaxBy<T>(this IEnumerable<T> source, Func<T, long> selector) { T max = source.First(); foreach (var item in source) if (selector(item) > selector(max)) max = item; return max; } public static T MinBy<T>(this IEnumerable<T> source, Func<T, long> selector) { T min = source.First(); foreach (var item in source) if (selector(item) < selector(min)) min = item; return min; } public static int IndexOf<T>(this IList<T> source, Func<T, bool> condition) { for (int i = 0; i < source.Count; i++) if (condition(source[i])) return i; return -1; } public static IEnumerable<List<T>> ChunkBy<T>(this IEnumerable<T> source) => ChunkBy(source, Id, EqualityComparer<T>.Default); public static IEnumerable<List<T>> ChunkBy<S, T>(this IEnumerable<T> source, Func<T, S> selector) => ChunkBy(source, selector, EqualityComparer<S>.Default); public static IEnumerable<List<T>> ChunkBy<S, T>(this IEnumerable<T> source, Func<T, S> selector, IEqualityComparer<S> comparer) { while (source.Any()) { var v = selector(source.First()); var l = source.TakeWhile(x => comparer.Equals(selector(x), v)).ToList(); yield return l; source = source.Skip(l.Count()); } } } static class Matrix { public static List<List<T>> Transpose<T>(this List<List<T>> source) => Range(0, source[0].Count) .Select(i => source.Select(x => x[i]).ToList()) .ToList(); public static void WriteMatrix(this IEnumerable<IEnumerable<char>> source) { foreach (var line in source) line.Show().WriteLine(); } public static List<List<long>> ReadLongMatrix(int h, int w) => h.Times(() => ReadLong(w)).ToList(); public static List<List<T>> SelectMatrix<S, T>(this List<List<S>> source, Func<S, T> f) => source.Select(x => x.Select(f).ToList()).ToList(); } static class Cin { private static Queue<string> tokens; static Cin() { string line; tokens = new Queue<string>(); while ((line = Console.ReadLine()) != null) { foreach (var token in line.Split(' ')) { tokens.Enqueue(token); } } } static public int ReadInt() => int.Parse(tokens.Dequeue()); static public List<int> ReadInt(long n) { var list = new List<int>(); n.Times(() => list.Add(ReadInt())); return list; } static public long ReadLong() => long.Parse(tokens.Dequeue()); static public List<long> ReadLong(long n) { var list = new List<long>(); n.Times(() => list.Add(ReadLong())); return list; } static public string ReadString() => tokens.Dequeue(); static public List<string> ReadString(long n) { var list = new List<string>(); n.Times(() => list.Add(ReadString())); return list; } static public void SayYesNo(this bool b) => (b ? "Yes" : "No").WriteLine(); static public void SayYESNO(this bool b) => (b ? "YES" : "NO").WriteLine(); } public struct VectorInt2 { public int X { get; set; } public int Y { get; set; } public VectorInt2(int x, int y) { X = x; Y = y; } static public VectorInt2 operator +(VectorInt2 v1, VectorInt2 v2) => new VectorInt2(v1.X + v2.X, v1.Y + v2.Y); static public VectorInt2 operator -(VectorInt2 v1, VectorInt2 v2) => new VectorInt2(v1.X - v2.X, v1.Y - v2.Y); static public VectorInt2 operator *(VectorInt2 v1, VectorInt2 v2) => new VectorInt2(v1.X * v2.X, v1.Y *v2.Y); static public VectorInt2 operator *(VectorInt2 v1, int i) => new VectorInt2(v1.X * i, v1.Y *i); static public VectorInt2 operator *(int i, VectorInt2 v2) => new VectorInt2(i * v2.X, i *v2.Y); static public VectorInt2 operator /(VectorInt2 v1, int i) => new VectorInt2(v1.X / i, v1.Y / i); public override string ToString() => $"({X}, {Y})"; } struct VectorDouble2 { public double X { get; set; } public double Y { get; set; } public VectorDouble2(double x, double y) { X = x; Y = y; } static public VectorDouble2 operator +(VectorDouble2 v1, VectorDouble2 v2) => new VectorDouble2(v1.X + v2.X, v1.Y + v2.Y); static public VectorDouble2 operator -(VectorDouble2 v1, VectorDouble2 v2) => new VectorDouble2(v1.X - v2.X, v1.Y - v2.Y); static public VectorDouble2 operator *(VectorDouble2 v1, VectorDouble2 v2) => new VectorDouble2(v1.X * v2.X, v1.Y *v2.Y); static public VectorDouble2 operator *(VectorDouble2 v1, int i) => new VectorDouble2(v1.X * i, v1.Y *i); static public VectorDouble2 operator *(int i, VectorDouble2 v2) => new VectorDouble2(i * v2.X, i *v2.Y); static public VectorDouble2 operator /(VectorDouble2 v1, double i) => new VectorDouble2(v1.X / i, v1.Y / i); public override string ToString() => $"({X}, {Y})"; public VectorDouble2 Turn(double radian) => new VectorDouble2(X * Cos(radian) - Y * Sin(radian), X *Sin(radian) + Y * Cos(radian)); } public struct LongRange { public long Left; public long Right; public LongRange(long left, long right) { Left = left; Right = right; } } public struct LongFromToVector { public VectorInt2 Start; public VectorInt2 End; public LongFromToVector(VectorInt2 start, VectorInt2 end) { Start = start; End = end; } } } namespace AtCoder { using System.Collections.Generic; using System.Collections; using System.Linq; using System; class MultiSet<T> : ICollection<T> { // TODO: 順番がグチャグチャなので整理する Dictionary<T, long> occurrence; public MultiSet() { occurrence = new Dictionary<T, long>(); } public MultiSet(MultiSet<T> source) : this(source.occurrence) {} public MultiSet(Dictionary<T, long> source) { occurrence = new Dictionary<T, long>(source); Validate(); } public MultiSet(IEnumerable<T> source) { occurrence = new Dictionary<T, long>(); AddRange(source); } public MultiSet(IEnumerable<KeyValuePair<T, long>> source) { occurrence = new Dictionary<T, long>(); foreach (var item in source) this[item.Key] += item.Value; } public void Add(T data) { if (!occurrence.ContainsKey(data)) { occurrence[data] = 1; return; } occurrence[data]++; } public void Clear() => occurrence.Clear(); public void Add(T key, int value) { if (value <= 0) throw new ArgumentException(); if (!occurrence.ContainsKey(key)) { occurrence[key] = value; return; } occurrence[key] += value; } public void Add(KeyValuePair<T, int> pair) => Add(pair.Key, pair.Value); public void AddRange(IEnumerable<T> source) => source.ToList().ForEach(Add); public bool Remove(T data) { if (!occurrence.ContainsKey(data)) return false; occurrence[data]--; if (occurrence[data] == 0) occurrence.Remove(data); return true; } // IDictionary public long this[T key] { get { return occurrence.ContainsKey(key) ? occurrence[key] : 0; } set { if (value <= 0) throw new ArgumentException(); occurrence[key] = value; } } public ICollection<T> Keys { get { return occurrence.Keys; } } public ICollection<long> Values { get { return occurrence.Values; } } public IEnumerable<KeyValuePair<T, long>> KeyValuePairs { get { foreach (var pair in occurrence) yield return pair; } } public bool ContainsKey(T key) => occurrence.ContainsKey(key); public bool Contains(T key) => ContainsKey(key); public bool TryGetValue(T key, out long value) { value = this[key]; return true; } // /IDictionary public long LongCount() => occurrence.Values.Sum(); public int Count => (int)occurrence.Values.Sum(); public bool IsReadOnly => false; public void CopyTo(T[] array, int index) { foreach (var pair in occurrence) { for (int i = 0; i < pair.Value; i++) { array[index] = pair.Key; index++; } } } public IEnumerator<T> GetEnumerator() { foreach (var pair in occurrence) for (int i = 0; i < pair.Value; i++) yield return pair.Key; } IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); public void Validate() { if (occurrence.Values.Any(x => x <= 0)) throw new ArgumentException(); } } class SortedMultiSet<T> : ICollection<T> { // TODO: 順番がグチャグチャなので整理する SortedDictionary<T, long> occurrence; public SortedMultiSet() { occurrence = new SortedDictionary<T, long>(); } public SortedMultiSet(SortedMultiSet<T> source) : this(source.occurrence) {} public SortedMultiSet(SortedDictionary<T, long> source) { occurrence = new SortedDictionary<T, long>(source); Validate(); } public SortedMultiSet(IEnumerable<T> source) { occurrence = new SortedDictionary<T, long>(); AddRange(source); } public SortedMultiSet(IEnumerable<KeyValuePair<T, long>> source) { occurrence = new SortedDictionary<T, long>(); foreach (var item in source) this[item.Key] += item.Value; } public void Add(T data) { if (!occurrence.ContainsKey(data)) { occurrence[data] = 1; return; } occurrence[data]++; } public void Clear() => occurrence.Clear(); public void Add(T key, int value) { if (value <= 0) throw new ArgumentException(); if (!occurrence.ContainsKey(key)) { occurrence[key] = value; return; } occurrence[key] += value; } public long LongCount() => occurrence.Values.Sum(); public int Count => (int)occurrence.Values.Sum(); public void Add(KeyValuePair<T, int> pair) => Add(pair.Key, pair.Value); public void AddRange(IEnumerable<T> source) => source.ToList().ForEach(Add); public bool Remove(T data) { if (!occurrence.ContainsKey(data)) return false; occurrence[data]--; if (occurrence[data] == 0) occurrence.Remove(data); return true; } // IDictionary public long this[T key] { get { return occurrence.ContainsKey(key) ? occurrence[key] : 0; } set { if (value <= 0) throw new ArgumentException(); occurrence[key] = value; } } public ICollection<T> Keys => occurrence.Keys; public ICollection<long> Values => occurrence.Values; public bool ContainsKey(T key) => occurrence.ContainsKey(key); public bool Contains(T key) => ContainsKey(key); public bool TryGetValue(T key, out long value) { value = this[key]; return true; } // /IDictionary public bool IsReadOnly => false; public void CopyTo(T[] array, int index) { foreach (var pair in occurrence) { for (int i = 0; i < pair.Value; i++) { array[index] = pair.Key; index++; } } } public IEnumerator<T> GetEnumerator() { foreach (var pair in occurrence) for (int i = 0; i < pair.Value; i++) yield return pair.Key; } IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); public void Validate() { if (occurrence.Values.Any(x => x <= 0)) throw new ArgumentException(); } } }
[["-", 0, 52, 8, 196, 0, 1, 0, 213, 63, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35]]
8
6,537
5
using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; using System.Text; using System.Threading; // (づ°ω°)づミe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜ public class Solver { const int MOD = 1000000007; long[] f, rf, inv; void InitFacts(int size) { f = new long[size + 1]; rf = new long[size + 1]; inv = new long[size + 1]; f[0] = f[1] = rf[0] = rf[1] = inv[1] = 1; for (int i = 2; i <= size; i++) { f[i] = f[i - 1] * i % MOD; inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD; rf[i] = inv[i] * rf[i - 1] % MOD; } } long Ways(int n, int m) { return f[n + m - 2] * rf[m - 1] % MOD * rf[n - 1] % MOD; } public void Solve() { InitFacts(200000); int n = ReadInt(); int m = ReadInt(); int h = ReadInt(); int w = ReadInt(); long ans = 0; for (int i = w; i < m; i++) { ans += Ways(n - h, i + 1) * Ways(h, m - i); } Write(ans % MOD); } #region Main protected static TextReader reader; protected static TextWriter writer; static void Main() { #if DEBUG reader = new StreamReader("..\\..\\input.txt"); // reader = new StreamReader(Console.OpenStandardInput()); writer = Console.Out; // writer = new StreamWriter("..\\..\\output.txt"); #else reader = new StreamReader(Console.OpenStandardInput()); writer = new StreamWriter(Console.OpenStandardOutput()); // reader = new StreamReader("input.txt"); // writer = new StreamWriter("output.txt"); #endif try { new Solver().Solve(); // var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128); // thread.Start(); // thread.Join(); } catch (Exception ex) { #if DEBUG Console.WriteLine(ex); #else throw; #endif } reader.Close(); writer.Close(); } #endregion #region Read / Write private static Queue<string> currentLineTokens = new Queue<string>(); private static string[] ReadAndSplitLine() { return reader.ReadLine().Split( new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); } public static string ReadToken() { while (currentLineTokens.Count == 0) currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); } public static int ReadInt() { return int.Parse(ReadToken()); } public static long ReadLong() { return long.Parse(ReadToken()); } public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); } public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); } public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); } public static double[] ReadDoubleArray() { return ReadAndSplitLine() .Select(s => double.Parse(s, CultureInfo.InvariantCulture)) .ToArray(); } public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int [numberOfRows][]; for (int i = 0; i < numberOfRows; i++) matrix[i] = ReadIntArray(); return matrix; } public static int[][] ReadAndTransposeIntMatrix(int numberOfRows) { int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][]; for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++) ret[i][j] = matrix[j][i]; } return ret; } public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++) lines[i] = reader.ReadLine().Trim(); return lines; } public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); } public static void Write(params object[] array) { WriteArray(array); } public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array) writer.WriteLine(a); } private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue> { public new TValue this[TKey key] { get { return ContainsKey(key) ? base[key] : default(TValue); } set { base[key] = value; } } } private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++) ret[i] = new T(); return ret; } #endregion }
using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; using System.Text; using System.Threading; // (づ°ω°)づミe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜ public class Solver { const int MOD = 1000000007; long[] f, rf, inv; void InitFacts(int size) { f = new long[size + 1]; rf = new long[size + 1]; inv = new long[size + 1]; f[0] = f[1] = rf[0] = rf[1] = inv[1] = 1; for (int i = 2; i <= size; i++) { f[i] = f[i - 1] * i % MOD; inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD; rf[i] = inv[i] * rf[i - 1] % MOD; } } long Ways(int n, int m) { return f[n + m - 2] * rf[m - 1] % MOD * rf[n - 1] % MOD; } public void Solve() { InitFacts(200000); int n = ReadInt(); int m = ReadInt(); int h = ReadInt(); int w = ReadInt(); long ans = 0; for (int i = w; i < m; i++) { ans += Ways(n - h, i + 1) * Ways(h, m - i) % MOD; } Write(ans % MOD); } #region Main protected static TextReader reader; protected static TextWriter writer; static void Main() { #if DEBUG reader = new StreamReader("..\\..\\input.txt"); // reader = new StreamReader(Console.OpenStandardInput()); writer = Console.Out; // writer = new StreamWriter("..\\..\\output.txt"); #else reader = new StreamReader(Console.OpenStandardInput()); writer = new StreamWriter(Console.OpenStandardOutput()); // reader = new StreamReader("input.txt"); // writer = new StreamWriter("output.txt"); #endif try { new Solver().Solve(); // var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128); // thread.Start(); // thread.Join(); } catch (Exception ex) { #if DEBUG Console.WriteLine(ex); #else throw; #endif } reader.Close(); writer.Close(); } #endregion #region Read / Write private static Queue<string> currentLineTokens = new Queue<string>(); private static string[] ReadAndSplitLine() { return reader.ReadLine().Split( new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); } public static string ReadToken() { while (currentLineTokens.Count == 0) currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); } public static int ReadInt() { return int.Parse(ReadToken()); } public static long ReadLong() { return long.Parse(ReadToken()); } public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); } public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); } public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); } public static double[] ReadDoubleArray() { return ReadAndSplitLine() .Select(s => double.Parse(s, CultureInfo.InvariantCulture)) .ToArray(); } public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int [numberOfRows][]; for (int i = 0; i < numberOfRows; i++) matrix[i] = ReadIntArray(); return matrix; } public static int[][] ReadAndTransposeIntMatrix(int numberOfRows) { int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][]; for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++) ret[i][j] = matrix[j][i]; } return ret; } public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++) lines[i] = reader.ReadLine().Trim(); return lines; } public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); } public static void Write(params object[] array) { WriteArray(array); } public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array) writer.WriteLine(a); } private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue> { public new TValue this[TKey key] { get { return ContainsKey(key) ? base[key] : default(TValue); } set { base[key] = value; } } } private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++) ret[i] = new T(); return ret; } #endregion }
[["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 109], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 22]]
8
1,101
2
using System.Linq; using System; using static System.Console; class E { static void Main() => new K(); } class K { const int MOD = 1000000007; public K() { var I = ReadLine().Split().Select(int.Parse).ToArray(); int N = I[0], X = I[1], Y = I[2], Z = I[3]; var M = 1 << (X + Y + Z); var m = M - 1; var n = (1 << (Z - 1)) | (1 << (Y + Z - 1)) | (1 << (X + Y + Z - 1)); var d = new long[N + 1, M]; d[0, 0] = 1; for (var i = 0; i < N; i++) for (var s = 0; s < M; s++) if (d[i, s] != 0) for (var a = 1; a <= 10; a++) { var t = ((s << a) | (1 << (a - 1))) & m; if ((t & n) != n) d[i + 1, t] = (d[i + 1, t] + d[i, s]) % MOD; } var p = 1L; for (var i = 0; i < N; i++) p = p * 10 % MOD; for (var s = 0; s < M; s++) p += MOD - d[N, s]; WriteLine(p); } }
using System.Linq; using System; using static System.Console; class E { static void Main() => new K(); } class K { const int MOD = 1000000007; public K() { var I = ReadLine().Split().Select(int.Parse).ToArray(); int N = I[0], X = I[1], Y = I[2], Z = I[3]; var M = 1 << (X + Y + Z); var m = M - 1; var n = (1 << (Z - 1)) | (1 << (Y + Z - 1)) | (1 << (X + Y + Z - 1)); var d = new long[N + 1, M]; d[0, 0] = 1; for (var i = 0; i < N; i++) for (var s = 0; s < M; s++) if (d[i, s] != 0) for (var a = 1; a <= 10; a++) { var t = ((s << a) | (1 << (a - 1))) & m; if ((t & n) != n) d[i + 1, t] = (d[i + 1, t] + d[i, s]) % MOD; } var p = 1L; for (var i = 0; i < N; i++) p = p * 10 % MOD; for (var s = 0; s < M; s++) p += MOD - d[N, s]; WriteLine(p % MOD); } }
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 109], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
8
351
2
using System; class A { static void Main(string[] args) { string s = Console.ReadLine().Trim(); string O = "NO"; if (s == "5 5 7" || s == "5 7 5" || s == "7 5 5") { O = "Yes"; } Console.WriteLine(O); } }
using System; class A { static void Main(string[] args) { string s = Console.ReadLine().Trim(); string O = "NO"; if (s == "5 5 7" || s == "5 7 5" || s == "7 5 5") { O = "YES"; } Console.WriteLine(O); } }
[["-", 64, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 11, 12, 5, 0, 222]]
8
73
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC042A { class Program { static void Main(string[] args) { int A, B, C; var word = Console.ReadLine().Split(' '); A = int.Parse(word[0]); B = int.Parse(word[1]); C = int.Parse(word[2]); if (A == 5 && B == 7 && C == 5 || A == 7 && B == 5 && C == 5 || A == 5 && B == 5 && C == 7) 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 ABC042A { class Program { static void Main(string[] args) { int A, B, C; var word = Console.ReadLine().Split(' '); A = int.Parse(word[0]); B = int.Parse(word[1]); C = int.Parse(word[2]); if (A == 5 && B == 7 && C == 5 || A == 7 && B == 5 && C == 5 || A == 5 && B == 5 && C == 7) Console.WriteLine("YES"); else Console.WriteLine("NO"); Console.ReadKey(); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
168
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC042A { class Program { static void Main(string[] args) { int a, b, c, d; var word = Console.ReadLine().Split(' '); a = int.Parse(word[0]); b = int.Parse(word[1]); c = int.Parse(word[2]); d = a + b + c; if (d == 17) 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 ABC042A { class Program { static void Main(string[] args) { int a, b, c, d; var word = Console.ReadLine().Split(' '); a = int.Parse(word[0]); b = int.Parse(word[1]); c = int.Parse(word[2]); d = a + b + c; if (d == 17) Console.WriteLine("YES"); else Console.WriteLine("NO"); Console.ReadKey(); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
146
4
using System; class Program { static void Main(string[] args) { // スペース区切りの整数の入力 string[] input = Console.ReadLine().Split(' '); Array.Sort(input); if (input[0] == "5" && input[1] == "5" && input[2] == "7") { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } }
using System; class Program { static void Main(string[] args) { // スペース区切りの整数の入力 string[] input = Console.ReadLine().Split(' '); Array.Sort(input); if (input[0] == "5" && input[1] == "5" && input[2] == "7") { Console.WriteLine("YES"); } else { Console.WriteLine("NO"); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
96
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC042A { class Program { static void Main(string[] args) { int A, B, C, x; String X; var word = Console.ReadLine().Split(' '); A = int.Parse(word[0]); B = int.Parse(word[1]); C = int.Parse(word[2]); x = A + B + C; if (x == 17 && (A == 5 && (B == 5 || C == 5) || B == 5 && C == 5)) { X = "Yes"; } else { X = "No"; } Console.WriteLine(X); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC042A { class Program { static void Main(string[] args) { int A, B, C, x; String X; var word = Console.ReadLine().Split(' '); A = int.Parse(word[0]); B = int.Parse(word[1]); C = int.Parse(word[2]); x = A + B + C; if (x == 17 && (A == 5 && (B == 5 || C == 5) || B == 5 && C == 5)) { X = "YES"; } else { X = "NO"; } Console.WriteLine(X); Console.ReadKey(); } } }
[["-", 64, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["-", 75, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["+", 75, 196, 0, 1, 0, 11, 12, 5, 0, 222]]
8
178
4