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; class IDONTKNOWCSHARP { public static void Main() { long[] values = Convert(GetLines()); long N = values[0]; long M = values[1]; long[] values2 = Convert(GetLines()); long sum = 0; foreach (long v in values) { sum += v; } long ans = N - sum; if (ans < 0) Console.WriteLine("-1"); else Console.WriteLine(ans); } static long[] Convert(string[] v) { var temp = new long[v.Length]; for (int i = 0; i < temp.Length; i++) { temp[i] = long.Parse(v[i]); } return temp; } static string[] GetLines() { return Console.ReadLine().Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); } }
using System; class IDONTKNOWCSHARP { public static void Main() { long[] values = Convert(GetLines()); long N = values[0]; long M = values[1]; long[] values2 = Convert(GetLines()); long sum = 0; foreach (long v in values2) { sum += v; } long ans = N - sum; if (ans < 0) Console.WriteLine("-1"); else Console.WriteLine(ans); } static long[] Convert(string[] v) { var temp = new long[v.Length]; for (int i = 0; i < temp.Length; i++) { temp[i] = long.Parse(v[i]); } return temp; } static string[] GetLines() { return Console.ReadLine().Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); } }
[["-", 8, 201, 0, 195, 8, 196, 0, 210, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 12, 22]]
8
196
2
using System; using System.Linq; using System.Text; using CompLib.Util; public class Program { int N, A, B, C; string[] S; char[] Ans; bool Flag; long Sum; public void Solve() { var sc = new Scanner(); N = sc.NextInt(); A = sc.NextInt(); B = sc.NextInt(); C = sc.NextInt(); S = new string[N]; for (int i = 0; i < N; i++) { S[i] = sc.Next(); } Sum = A + B + C; Flag = false; Ans = new char[N]; Search(0, A, B); if (!Flag) { Console.WriteLine("No"); } } public void Search(int i, long a, long b) { if (Flag) return; if (i >= N) { Console.WriteLine("Yes"); Console.WriteLine(string.Join("\n", Ans)); Flag = true; return; } long c = Sum - a - b; if (S[i] == "AB") { if (a == 0 && b == 0) return; if (a > b) { Ans[i] = 'B'; Search(i + 1, a - 1, b + 1); if (Flag) return; Ans[i] = 'A'; if (b > 0) Search(i + 1, a + 1, b - 1); } else { Ans[i] = 'A'; Search(i + 1, a + 1, b - 1); if (Flag) return; Ans[i] = 'B'; if (a > 0) Search(i + 1, a - 1, b + 1); } } if (S[i] == "AC") { if (a == 0 && c == 0) return; if (a > c) { Ans[i] = 'C'; Search(i + 1, a - 1, b); if (Flag) return; Ans[i] = 'A'; if (c > 0) Search(i + 1, a + 1, b); } else { Ans[i] = 'A'; Search(i + 1, a + 1, b); if (Flag) return; Ans[i] = 'C'; if (a > 0) Search(i + 1, a - 1, b); } } if (S[i] == "BC") { if (b == 0 && c == 0) return; if (b > c) { Ans[i] = 'C'; Search(i + 1, a, b - 1); if (Flag) return; Ans[i] = 'B'; if (c > 0) Search(i + 1, a, b + 1); } else { Ans[i] = 'B'; Search(i + 1, a, b - 1); if (Flag) return; Ans[i] = 'C'; if (b > 0) Search(i + 1, a, b - 1); } } } public static void Main(string[] args) => new Program().Solve(); } namespace CompLib.Util { using System; using System.Linq; class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
using System; using System.Linq; using System.Text; using CompLib.Util; public class Program { int N, A, B, C; string[] S; char[] Ans; bool Flag; long Sum; public void Solve() { var sc = new Scanner(); N = sc.NextInt(); A = sc.NextInt(); B = sc.NextInt(); C = sc.NextInt(); S = new string[N]; for (int i = 0; i < N; i++) { S[i] = sc.Next(); } Sum = A + B + C; Flag = false; Ans = new char[N]; Search(0, A, B); if (!Flag) { Console.WriteLine("No"); } } public void Search(int i, long a, long b) { if (Flag) return; if (i >= N) { Console.WriteLine("Yes"); Console.WriteLine(string.Join("\n", Ans)); Flag = true; return; } long c = Sum - a - b; if (S[i] == "AB") { if (a == 0 && b == 0) return; if (a > b) { Ans[i] = 'B'; Search(i + 1, a - 1, b + 1); if (Flag) return; Ans[i] = 'A'; if (b > 0) Search(i + 1, a + 1, b - 1); } else { Ans[i] = 'A'; Search(i + 1, a + 1, b - 1); if (Flag) return; Ans[i] = 'B'; if (a > 0) Search(i + 1, a - 1, b + 1); } } if (S[i] == "AC") { if (a == 0 && c == 0) return; if (a > c) { Ans[i] = 'C'; Search(i + 1, a - 1, b); if (Flag) return; Ans[i] = 'A'; if (c > 0) Search(i + 1, a + 1, b); } else { Ans[i] = 'A'; Search(i + 1, a + 1, b); if (Flag) return; Ans[i] = 'C'; if (a > 0) Search(i + 1, a - 1, b); } } if (S[i] == "BC") { if (b == 0 && c == 0) return; if (b > c) { Ans[i] = 'C'; Search(i + 1, a, b - 1); if (Flag) return; Ans[i] = 'B'; if (c > 0) Search(i + 1, a, b + 1); } else { Ans[i] = 'B'; Search(i + 1, a, b + 1); if (Flag) return; Ans[i] = 'C'; if (b > 0) Search(i + 1, a, b - 1); } } } public static void Main(string[] args) => new Program().Solve(); } namespace CompLib.Util { using System; using System.Linq; class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72]]
8
1,024
2
using System; using System.Collections.Generic; using System.Linq; public class Solution { static string NextIn0(ref long A, ref long B, ref long C, string s) { var ans = ""; switch (s) { case "AB": if (A + B == 0) { return null; } if (A == 0) { ans = "A"; } else { ans = "B"; } break; case "BC": if (B + C == 0) { return null; } if (B == 0) { ans = "B"; } else { ans = "C"; } break; case "AC": if (A + C == 0) { return null; } if (A == 0) { ans = "A"; } else { ans = "C"; } break; } Apply(ref A, ref B, ref C, s, ans); return ans; } static void Apply(ref long A, ref long B, ref long C, string s, string choice) { var notChoice = s.Replace(choice, ""); switch (choice) { case "A": A++; break; case "B": B++; break; case "C": C++; break; } switch (notChoice) { case "A": A--; break; case "B": B--; break; case "C": C--; break; } } static string Next(ref long A, ref long B, ref long C, string next, string nnext) { if (nnext == null) { return NextIn0(ref A, ref B, ref C, next); } foreach (var c in "ABC") { if (next.Contains(c) && nnext.Contains(c)) { var choice = c.ToString(); Apply(ref A, ref B, ref C, next, choice); return choice; } } throw new Exception(); } static int GetZeroCount(long A, long B, long C, string s) { int count = 0; foreach (var c in s) { switch (c) { case 'A': if (A == 0) { count++; } break; case 'B': if (B == 0) { count++; } break; case 'C': if (C == 0) { count++; } break; } } return count; } public static void Main() { var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var N = vals[0]; long A = vals[1]; long B = vals[2]; long C = vals[3]; var S = new string[N]; for (int i = 0; i < N; i++) { S[i] = Console.ReadLine(); } if (A + B + C == 0) { Console.WriteLine("No"); } var answer = new List<string>(); if (A + B + C == 1) { foreach (var s in S) { var ans = NextIn0(ref A, ref B, ref C, s); if (ans == null) { Console.WriteLine("No"); return; } answer.Add(ans); } } else { var first = S.First(); if (GetZeroCount(A, B, C, first) == 2) { Console.WriteLine("No"); return; } for (int i = 0; i < N; i++) { var s = S[i]; if (GetZeroCount(A, B, C, s) == 1) { var ans = NextIn0(ref A, ref B, ref C, s); answer.Add(ans); } else { string ss = i + 1 == N ? null : S[i + 1]; var ans = Next(ref A, ref B, ref C, s, ss); answer.Add(ans); } } } Console.WriteLine("Yes"); Console.WriteLine(string.Join(Environment.NewLine, answer)); } }
using System; using System.Collections.Generic; using System.Linq; public class Solution { static string NextIn0(ref long A, ref long B, ref long C, string s) { var ans = ""; switch (s) { case "AB": if (A + B == 0) { return null; } if (A == 0) { ans = "A"; } else { ans = "B"; } break; case "BC": if (B + C == 0) { return null; } if (B == 0) { ans = "B"; } else { ans = "C"; } break; case "AC": if (A + C == 0) { return null; } if (A == 0) { ans = "A"; } else { ans = "C"; } break; } Apply(ref A, ref B, ref C, s, ans); return ans; } static void Apply(ref long A, ref long B, ref long C, string s, string choice) { var notChoice = s.Replace(choice, ""); switch (choice) { case "A": A++; break; case "B": B++; break; case "C": C++; break; } switch (notChoice) { case "A": A--; break; case "B": B--; break; case "C": C--; break; } } static string Next(ref long A, ref long B, ref long C, string next, string nnext) { if (nnext == null) { return NextIn0(ref A, ref B, ref C, next); } foreach (var c in "ABC") { if (next.Contains(c) && nnext.Contains(c)) { var choice = c.ToString(); Apply(ref A, ref B, ref C, next, choice); return choice; } } throw new Exception(); } static int GetZeroCount(long A, long B, long C, string s) { int count = 0; foreach (var c in s) { switch (c) { case 'A': if (A == 0) { count++; } break; case 'B': if (B == 0) { count++; } break; case 'C': if (C == 0) { count++; } break; } } return count; } public static void Main() { var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var N = vals[0]; long A = vals[1]; long B = vals[2]; long C = vals[3]; var S = new string[N]; for (int i = 0; i < N; i++) { S[i] = Console.ReadLine(); } if (A + B + C == 0) { Console.WriteLine("No"); return; } var answer = new List<string>(); if (A + B + C == 1) { foreach (var s in S) { var ans = NextIn0(ref A, ref B, ref C, s); if (ans == null) { Console.WriteLine("No"); return; } answer.Add(ans); } } else { var first = S.First(); if (GetZeroCount(A, B, C, first) == 2) { Console.WriteLine("No"); return; } for (int i = 0; i < N; i++) { var s = S[i]; if (GetZeroCount(A, B, C, s) == 1) { var ans = NextIn0(ref A, ref B, ref C, s); answer.Add(ans); } else { string ss = i + 1 == N ? null : S[i + 1]; var ans = Next(ref A, ref B, ref C, s, ss); answer.Add(ans); } } } Console.WriteLine("Yes"); Console.WriteLine(string.Join(Environment.NewLine, answer)); } }
[["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35]]
8
891
2
using System; namespace q1 { class q2 { static void Main() { int K = int.Parse(Console.ReadLine()); string[] AB = Console.ReadLine().Split(); int A = int.Parse(AB[0]); int B = int.Parse(AB[1]); if (A / K == B / K) { Console.WriteLine("NG"); } else { Console.WriteLine("OK"); } } } }
using System; namespace q1 { class q2 { static void Main() { int K = int.Parse(Console.ReadLine()); string[] AB = Console.ReadLine().Split(); int A = int.Parse(AB[0]); int B = int.Parse(AB[1]); if ((A - 1) / K == B / K) { Console.WriteLine("NG"); } else { Console.WriteLine("OK"); } } } }
[["+", 0, 57, 15, 16, 31, 16, 31, 23, 0, 24], ["+", 15, 16, 31, 16, 31, 23, 0, 16, 17, 33], ["+", 15, 16, 31, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 16, 31, 23, 0, 25]]
8
106
4
using System; using System.Collections.Generic; using System.Linq; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { class A_165_WeLoveGolf { // https://atcoder.jp/contests/abc165/tasks/abc165_a public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // 整数の入力 int K = int.Parse(Console.ReadLine()); // 整数配列の入力 var array = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray(); int A = array[0]; int B = array[1]; for (int i = A; i < B + 1; i++) { if (i % K == 0) { Console.WriteLine("OK"); break; } else if (i == B) { Console.WriteLine("NG"); } Console.Out.Flush(); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { class A_165_WeLoveGolf { // https://atcoder.jp/contests/abc165/tasks/abc165_a public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // 整数の入力 int K = int.Parse(Console.ReadLine()); // 整数配列の入力 var array = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray(); int A = array[0]; int B = array[1]; for (int i = A; i < B + 1; i++) { if (i % K == 0) { Console.WriteLine("OK"); break; } else if (i == B) { Console.WriteLine("NG"); } } Console.Out.Flush(); } } }
[["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46]]
8
215
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { // 問題: class A_165_We_Love_Golf { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // 整数の入力 int n = int.Parse(Console.ReadLine()); // 整数配列の入力 var inputintArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray(); int a = inputintArray[0]; int b = inputintArray[1]; for (int i = 0; i < b - a + 1; i++) { if ((a + i) % n == 0) { Console.WriteLine("OK"); return; } else if ((a + i) % n != 0 && i == b - a) { Console.WriteLine("NG"); } } Console.Out.Flush(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { // 問題: class A_165_We_Love_Golf { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // 整数の入力 int n = int.Parse(Console.ReadLine()); // 整数配列の入力 var inputintArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray(); int a = inputintArray[0]; int b = inputintArray[1]; for (int i = 0; i < b - a + 1; i++) { if ((a + i) % n == 0) { Console.WriteLine("OK"); break; } else if ((a + i) % n != 0 && i == b - a) { Console.WriteLine("NG"); } } Console.Out.Flush(); } } }
[["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94]]
8
226
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { class A_165_WeLoveGolf { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // 整数の入力 long K = long.Parse(Console.ReadLine()); // 整数配列の入力 var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray(); long A = inputLongArray[0]; long B = inputLongArray[1]; string result = ""; for (int i = 0; i < B - A - 1; i++) { if ((B + i) % K == 0) { result = "OK"; break; } else { result = "NG"; } } Console.WriteLine(result); Console.Out.Flush(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { class A_165_WeLoveGolf { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // 整数の入力 long K = long.Parse(Console.ReadLine()); // 整数配列の入力 var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray(); long A = inputLongArray[0]; long B = inputLongArray[1]; string result = ""; for (int i = 0; i < B - A + 1; i++) { if ((A + i) % K == 0) { result = "OK"; break; } else { result = "NG"; } } Console.WriteLine(result); Console.Out.Flush(); } } }
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["-", 15, 16, 31, 16, 31, 23, 0, 16, 31, 22], ["+", 15, 16, 31, 16, 31, 23, 0, 16, 31, 22]]
8
214
4
using System; class Program { static void Main(string[] args) { var a = long.Parse(Console.ReadLine()); var b = Console.ReadLine().Split(" "); var times = 1000 / a + 1; for (var i = 1; times >= i; i++) { if (int.Parse(b[0]) < a * i && a * i < int.Parse(b[1])) { Console.WriteLine("OK"); break; } if (i == times) { Console.WriteLine("NG"); break; } } } }
using System; class Program { static void Main(string[] args) { var a = long.Parse(Console.ReadLine()); var b = Console.ReadLine().Split(" "); var times = 1000 / a + 1; for (var i = 1; times >= i; i++) { if (int.Parse(b[0]) <= a * i && a * i <= int.Parse(b[1])) { Console.WriteLine("OK"); break; } if (i == times) { Console.WriteLine("NG"); break; } } } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 19], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19]]
8
135
4
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder.Question { public class QuestionA { public static void Main(string[] args) { var k = ReadHelper.ReadValue<int>(); var (a, b) = ReadHelper.ReadValue<int, int>(); var mod = a % k; Console.WriteLine(b >= a + k - mod ? "OK" : "NG"); } static class ReadHelper { internal static T ReadValue<T>() { return (T)Convert.ChangeType(Console.ReadLine(), typeof(T)); } internal static (T1, T2) ReadValue<T1, T2>() { var input = Console.ReadLine().Split(' '); return ((T1)Convert.ChangeType(input[0], typeof(T1)), (T2)Convert.ChangeType(input[1], typeof(T2))); } internal static (T1, T2, T3) ReadValue<T1, T2, T3>() { var input = Console.ReadLine().Split(' '); return ((T1)Convert.ChangeType(input[0], typeof(T1)), (T2)Convert.ChangeType(input[1], typeof(T2)), (T3)Convert.ChangeType(input[2], typeof(T3))); } internal static (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>() { var input = Console.ReadLine().Split(' '); return ((T1)Convert.ChangeType(input[0], typeof(T1)), (T2)Convert.ChangeType(input[1], typeof(T2)), (T3)Convert.ChangeType(input[2], typeof(T3)), (T4)Convert.ChangeType(input[3], typeof(T4))); } internal static T[] ReadValues<T>() { var input = Console.ReadLine().Split(' '); return input.Select(x => (T)Convert.ChangeType(x, typeof(T))).ToArray(); } } static class MathAlgorithm { internal static bool IsPrime(long n) { if (n == 2) return true; if (n < 2 || n % 2 == 0) return false; var sqrt = Math.Sqrt(n); for (int i = 3; i <= sqrt; i += 2) if (n % i == 0) return false; return true; } internal static IEnumerable<long> EnumeratePrimes(long n) { var i = 2L; while (i * i <= n) { if (n % i == 0) { n /= i; yield return i; } else { i += i == 2 ? 1 : 2; } } if (n != 1) yield return n; } } } }
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder.Question { public class QuestionA { public static void Main(string[] args) { var k = ReadHelper.ReadValue<int>(); var (a, b) = ReadHelper.ReadValue<int, int>(); var mod = a % k; Console.WriteLine(mod == 0 || b >= a + k - mod ? "OK" : "NG"); } static class ReadHelper { internal static T ReadValue<T>() { return (T)Convert.ChangeType(Console.ReadLine(), typeof(T)); } internal static (T1, T2) ReadValue<T1, T2>() { var input = Console.ReadLine().Split(' '); return ((T1)Convert.ChangeType(input[0], typeof(T1)), (T2)Convert.ChangeType(input[1], typeof(T2))); } internal static (T1, T2, T3) ReadValue<T1, T2, T3>() { var input = Console.ReadLine().Split(' '); return ((T1)Convert.ChangeType(input[0], typeof(T1)), (T2)Convert.ChangeType(input[1], typeof(T2)), (T3)Convert.ChangeType(input[2], typeof(T3))); } internal static (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>() { var input = Console.ReadLine().Split(' '); return ((T1)Convert.ChangeType(input[0], typeof(T1)), (T2)Convert.ChangeType(input[1], typeof(T2)), (T3)Convert.ChangeType(input[2], typeof(T3)), (T4)Convert.ChangeType(input[3], typeof(T4))); } internal static T[] ReadValues<T>() { var input = Console.ReadLine().Split(' '); return input.Select(x => (T)Convert.ChangeType(x, typeof(T))).ToArray(); } } static class MathAlgorithm { internal static bool IsPrime(long n) { if (n == 2) return true; if (n < 2 || n % 2 == 0) return false; var sqrt = Math.Sqrt(n); for (int i = 3; i <= sqrt; i += 2) if (n % i == 0) return false; return true; } internal static IEnumerable<long> EnumeratePrimes(long n) { var i = 2L; while (i * i <= n) { if (n % i == 0) { n /= i; yield return i; } else { i += i == 2 ? 1 : 2; } } if (n != 1) yield return n; } } } }
[["+", 0, 28, 0, 41, 15, 16, 31, 16, 31, 22], ["+", 0, 28, 0, 41, 15, 16, 31, 16, 17, 60], ["+", 0, 28, 0, 41, 15, 16, 31, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 106]]
8
617
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml; namespace Program1 { class Program { static void Main(string[] args) { var line = Console.ReadLine(); var num = int.Parse(line); // K倍 var line2 = Console.ReadLine(); var num2 = line2.Split(' '); var A = int.Parse(num2[0]); // A var B = int.Parse(num2[1]); // B (A <= Kx <= B) Boolean flag = false; for (var i = A; i < B + 1; i++) { if (i % num == 0) { Console.WriteLine("OK"); flag = true; } } if (flag == false) { Console.WriteLine("NG"); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml; namespace Program1 { class Program { static void Main(string[] args) { var line = Console.ReadLine(); var num = int.Parse(line); // K倍 var line2 = Console.ReadLine(); var num2 = line2.Split(' '); var A = int.Parse(num2[0]); // A var B = int.Parse(num2[1]); // B (A <= Kx <= B) Boolean flag = false; for (var i = A; i < B + 1; i++) { if (i % num == 0) { Console.WriteLine("OK"); flag = true; break; } } if (flag == false) { Console.WriteLine("NG"); } } } }
[["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 35]]
8
183
2
using System; using System.Collections.Generic; using System.Linq; namespace atcoder { class Program { static void Main(string[] args) { var k = int.Parse(Console.ReadLine()); var ab = Console.ReadLine().Split(' ').Select(num => int.Parse(num)).ToArray(); if (ab[0] % k == 0) Console.WriteLine("OK"); Console.WriteLine((ab[0] + (k - ab[0] % k)) <= ab[1] ? "OK" : "NG"); } } }
using System; using System.Collections.Generic; using System.Linq; namespace atcoder { class Program { static void Main(string[] args) { var k = int.Parse(Console.ReadLine()); var ab = Console.ReadLine().Split(' ').Select(num => int.Parse(num)).ToArray(); if (ab[0] % k == 0) { Console.WriteLine("OK"); return; } Console.WriteLine((ab[0] + k - ab[0] % k) <= ab[1] ? "OK" : "NG"); } } }
[["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 15, 16, 31, 23, 0, 16, 12, 23, 0, 24], ["-", 15, 16, 31, 23, 0, 16, 12, 23, 0, 25]]
8
136
6
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp55 { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); //.Split(' ').Select(int.Parse) var ab = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); for (var i = 1; i < 1000; i++) { var r = check(N * i, ab); if (r == 1) { Console.WriteLine("OK"); return; } } Console.WriteLine("NG"); } static int check(int c, int[] ab) { if (c < ab[1]) return -1; return ab[0] <= c && c <= ab[1] ? 1 : 0; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp55 { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); //.Split(' ').Select(int.Parse) var ab = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); for (var i = 1; i < 1000; i++) { var r = check(N * i, ab); if (r == 1) { Console.WriteLine("OK"); return; } } Console.WriteLine("NG"); } static int check(int c, int[] ab) { if (ab[1] < c) return -1; return ab[0] <= c && c <= ab[1] ? 1 : 0; } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22]]
8
190
4
using System; public class Hello { public static void Main() { var s = int.Parse(Console.ReadLine()); var command = Console.ReadLine().Split(); int a = int.Parse(command[0]); int b = int.Parse(command[1]); var result = 0; for (var i = a; i <= b; i++) { if (i % s == 0) { Console.WriteLine("OK"); result = 1; break; } } if (result != 1) { Console.WriteLine("NO"); } } }
using System; public class Hello { public static void Main() { var s = int.Parse(Console.ReadLine()); var command = Console.ReadLine().Split(); int a = int.Parse(command[0]); int b = int.Parse(command[1]); var result = 0; for (var i = a; i <= b; i++) { if (i % s == 0) { Console.WriteLine("OK"); result = 1; break; } } if (result != 1) { Console.WriteLine("NG"); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
132
2
using System; namespace abc165A { class MainClass { public static void Main(string[] args) { int K = int.Parse(Console.ReadLine()); string[] str = Console.ReadLine().Split(); int A = int.Parse(str[0]); int B = int.Parse(str[1]); if ((A / K) - (B - 1) / K == 0) Console.WriteLine("NG"); else Console.WriteLine("OK"); } } }
using System; namespace abc165A { class MainClass { public static void Main(string[] args) { int K = int.Parse(Console.ReadLine()); string[] str = Console.ReadLine().Split(); int A = int.Parse(str[0]); int B = int.Parse(str[1]); if ((B / K) - (A - 1) / K == 0) Console.WriteLine("NG"); else Console.WriteLine("OK"); } } }
[["-", 15, 16, 31, 16, 31, 23, 0, 16, 31, 22], ["+", 15, 16, 31, 16, 31, 23, 0, 16, 31, 22], ["-", 31, 16, 12, 16, 31, 23, 0, 16, 31, 22], ["+", 31, 16, 12, 16, 31, 23, 0, 16, 31, 22]]
8
115
4
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { // kの倍数 int k = int.Parse(Console.ReadLine()); int[] ab = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var ans = new List<int>(); for (var i = ab[0]; i < ab[1]; i++) { if (i % k == 0) { ans.Add(i); } } if (ans.Count() >= 1) { Console.WriteLine("OK"); } else { Console.WriteLine("NG"); } } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { // kの倍数 int k = int.Parse(Console.ReadLine()); int[] ab = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var ans = new List<int>(); for (var i = ab[0]; i <= ab[1]; i++) { if (i % k == 0) { ans.Add(i); } } if (ans.Count() >= 1) { Console.WriteLine("OK"); } else { Console.WriteLine("NG"); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
162
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; using static System.Math; namespace AtTest.ABC_165 { class A { static void Main(string[] args) { var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false }; SetOut(sw); Method(args); Out.Flush(); } static void Method(string[] args) { int k = ReadInt(); int[] ab = ReadInts(); int a = ab[0]; int b = ab[1]; if (a % k == 0 || b % k == 0) { WriteLine("OK"); } else { int aDiv = a / k; int bDiv = b / k; WriteLine(a < b ? "OK" : "NG"); } } private static string Read() { return ReadLine(); } private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; using static System.Math; namespace AtTest.ABC_165 { class A { static void Main(string[] args) { var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false }; SetOut(sw); Method(args); Out.Flush(); } static void Method(string[] args) { int k = ReadInt(); int[] ab = ReadInts(); int a = ab[0]; int b = ab[1]; if (a % k == 0 || b % k == 0) { WriteLine("OK"); } else { int aDiv = a / k; int bDiv = b / k; WriteLine(aDiv < bDiv ? "OK" : "NG"); } } private static string Read() { return ReadLine(); } private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } } }
[["-", 3, 4, 0, 28, 0, 41, 15, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 31, 22], ["-", 3, 4, 0, 28, 0, 41, 15, 16, 12, 22], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 22]]
8
369
4
using System; using System.Collections; using System.Collections.Generic; using System.IO.Pipes; using System.Linq; using System.Numerics; using System.Text; using System.Threading; namespace ForATCODER { public class Program { public static void Main(string[] args) { int k = s2i(Console.ReadLine()); int[] a = s2iarray(Console.ReadLine().Split(' ')); for (int i = 1; i <= int.MaxValue; i++) { int n = k * i; if (a[0] >= n && a[1] <= n) { RESULT("OK"); return; } else if (a[1] < n) break; } RESULT("NG"); } public static ulong pow(int a, int b) { ulong res = 1; for (int i = 0; i < b; i++) { res *= (ulong)a; } return res; } public static void sortT<T>(T[] arr, int index) { // If the index is negative, // it represents the bitwise // complement of the next larger // element in the array. if (index < 0) { index = ~index; if (index == 0) Console.Write("beginning of array"); else Console.Write("{0} and ", arr[index - 1]); if (index == arr.Length) Console.WriteLine("end of array."); else Console.WriteLine("{0}", arr[index]); } } static int s2i(String s) { return Convert.ToInt32(s); } static ulong s2l(String s) { return Convert.ToUInt64(s); } static void RESULT(double res) { Console.WriteLine(res); } static void RESULT(long res) { Console.WriteLine(res); } static void RESULT(ulong res) { Console.WriteLine(res); } static void RESULT(int res) { Console.WriteLine(res); } static void RESULT(String res) { Console.WriteLine(res); } static String[] ReadLineAll(int count) { String[] res = new String[count]; for (int i = 0; i < count; i++) { res[i] = Console.ReadLine(); } return res; } static int[] s2iarray(String[] src) { int len = src.Length; int[] res = new int[len]; for (int i = 0; i < len; i++) { res[i] = Convert.ToInt32(src[i]); } return res; } static long[] s2larray(String[] src) { int len = src.Length; long[] res = new long[len]; for (int i = 0; i < len; i++) { res[i] = Convert.ToInt64(src[i]); } return res; } static ulong[] s2larray2(String[] src) { int len = src.Length; ulong[] res = new ulong[len]; for (int i = 0; i < len; i++) { res[i] = Convert.ToUInt64(src[i]); } return res; } } }
using System; using System.Collections; using System.Collections.Generic; using System.IO.Pipes; using System.Linq; using System.Numerics; using System.Text; using System.Threading; namespace ForATCODER { public class Program { public static void Main(string[] args) { int k = s2i(Console.ReadLine()); int[] a = s2iarray(Console.ReadLine().Split(' ')); for (int i = 1; i <= int.MaxValue; i++) { int n = k * i; if (a[0] <= n && a[1] >= n) { RESULT("OK"); return; } else if (a[1] < n) break; } RESULT("NG"); } public static ulong pow(int a, int b) { ulong res = 1; for (int i = 0; i < b; i++) { res *= (ulong)a; } return res; } public static void sortT<T>(T[] arr, int index) { // If the index is negative, // it represents the bitwise // complement of the next larger // element in the array. if (index < 0) { index = ~index; if (index == 0) Console.Write("beginning of array"); else Console.Write("{0} and ", arr[index - 1]); if (index == arr.Length) Console.WriteLine("end of array."); else Console.WriteLine("{0}", arr[index]); } } static int s2i(String s) { return Convert.ToInt32(s); } static ulong s2l(String s) { return Convert.ToUInt64(s); } static void RESULT(double res) { Console.WriteLine(res); } static void RESULT(long res) { Console.WriteLine(res); } static void RESULT(ulong res) { Console.WriteLine(res); } static void RESULT(int res) { Console.WriteLine(res); } static void RESULT(String res) { Console.WriteLine(res); } static String[] ReadLineAll(int count) { String[] res = new String[count]; for (int i = 0; i < count; i++) { res[i] = Console.ReadLine(); } return res; } static int[] s2iarray(String[] src) { int len = src.Length; int[] res = new int[len]; for (int i = 0; i < len; i++) { res[i] = Convert.ToInt32(src[i]); } return res; } static long[] s2larray(String[] src) { int len = src.Length; long[] res = new long[len]; for (int i = 0; i < len; i++) { res[i] = Convert.ToInt64(src[i]); } return res; } static ulong[] s2larray2(String[] src) { int len = src.Length; ulong[] res = new ulong[len]; for (int i = 0; i < len; i++) { res[i] = Convert.ToUInt64(src[i]); } return res; } } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 20], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 19], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 20]]
8
671
4
using System; using System.Collections.Generic; class Program { static void Main() { int i = 1; int K = int.Parse(Console.ReadLine()); string[] AB = Console.ReadLine().Split(' '); int A = int.Parse(AB[0]); int B = int.Parse(AB[1]); while (true) { int L = K; i += 1; K *= i; if (K > B) { Console.WriteLine("NG"); break; } if (K >= A && K <= B) { if (K >= A && K <= B) { Console.WriteLine("OK"); } else { Console.WriteLine("NG"); } break; } K = L; } } }
using System; using System.Collections.Generic; class Program { static void Main() { int i = 0; int K = int.Parse(Console.ReadLine()); string[] AB = Console.ReadLine().Split(' '); int A = int.Parse(AB[0]); int B = int.Parse(AB[1]); while (true) { int L = K; i += 1; K *= i; if (K > B) { Console.WriteLine("NG"); break; } if (K >= A && K <= B) { if (K >= A && K <= B) { Console.WriteLine("OK"); } else { Console.WriteLine("NG"); } break; } K = L; } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
8
173
2
using System; using System.Collections.Generic; public class WeLoveGolf { public static void Main() { var K = int.Parse(Console.ReadLine()); var input = Console.ReadLine().Split(' '); var A = int.Parse(input[0]); var B = int.Parse(input[1]); var result = "NG"; for (int i = A; A <= B; i++) { if (i % A == 0) { result = "OK"; break; } } Console.WriteLine(result); } }
using System; using System.Collections.Generic; public class WeLoveGolf { public static void Main() { var K = int.Parse(Console.ReadLine()); var input = Console.ReadLine().Split(' '); var A = int.Parse(input[0]); var B = int.Parse(input[1]); var result = "NG"; for (int i = A; i <= B; i++) { if (i % K == 0) { result = "OK"; break; } } Console.WriteLine(result); } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22]]
8
127
4
using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.Design; using System.IO.Compression; using System.Linq; using System.Numerics; using System.Text; namespace Atcoder { class Program { private const long COMDIV = 1000000007; static void Main(string[] args) { var K = int.Parse(Console.ReadLine()); var AB = Console.ReadLine().Split().Select(int.Parse).ToArray(); for (int i = AB[0]; i <= AB[1]; i++) { if (i % K == 0) { Console.WriteLine("OK"); return; } } Console.WriteLine("NO"); } } }
using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.Design; using System.IO.Compression; using System.Linq; using System.Numerics; using System.Text; namespace Atcoder { class Program { private const long COMDIV = 1000000007; static void Main(string[] args) { var K = int.Parse(Console.ReadLine()); var AB = Console.ReadLine().Split().Select(int.Parse).ToArray(); for (int i = AB[0]; i <= AB[1]; i++) { if (i % K == 0) { Console.WriteLine("OK"); return; } } Console.WriteLine("NG"); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
165
2
using System; using System.Linq; namespace _20200502 { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int[] inputLongArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray(); int x = inputLongArray[0] / n; //商 int y = inputLongArray[0] % n; //あまり int a = inputLongArray[0] - n * x; int b = inputLongArray[1] - n * x; if (n <= inputLongArray[1] + 1 - inputLongArray[0]) { Console.WriteLine("OK"); } else if (a == n) { Console.WriteLine("OK"); } else if (b == n) { Console.WriteLine("OK"); } else if (a == 0) { Console.WriteLine("OK"); } else if (b == 0) { Console.WriteLine("OK"); } else if (a < n && b < n) { Console.WriteLine("NG"); } else { Console.WriteLine("EROOR"); } } } }
using System; using System.Linq; namespace _20200502 { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int[] inputLongArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray(); int x = inputLongArray[0] / n; //商 int y = inputLongArray[0] % n; //あまり int a = inputLongArray[0] - n * x; int b = inputLongArray[1] - n * x; if (n <= inputLongArray[1] + 1 - inputLongArray[0]) { Console.WriteLine("OK"); } else if (a == n) { Console.WriteLine("OK"); } else if (b == n) { Console.WriteLine("OK"); } else if (a == 0) { Console.WriteLine("OK"); } else if (b == 0) { Console.WriteLine("OK"); } else if (a < n && b < n) { Console.WriteLine("NG"); } else { Console.WriteLine("OK"); } } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
254
2
using System; using System.Collections.Generic; using System.Text; namespace CSharpTest { class A_WeLoveGolf { static void Main(string[] args) { double K = double.Parse(Console.ReadLine()); string[] AB = Console.ReadLine().Split(); double A = double.Parse(AB[0]); double B = double.Parse(AB[1]); if (Math.Ceiling(A / K) == Math.Floor(B / K)) Console.WriteLine("NG"); else Console.WriteLine("OK"); return; } } }
using System; using System.Collections.Generic; using System.Text; namespace CSharpTest { class A_WeLoveGolf { static void Main(string[] args) { double K = double.Parse(Console.ReadLine()); string[] AB = Console.ReadLine().Split(); double A = double.Parse(AB[0]); double B = double.Parse(AB[1]); if (Math.Ceiling(A / K) > Math.Floor(B / K)) Console.WriteLine("NG"); else Console.WriteLine("OK"); return; } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47]]
8
130
2
using System; using System.Linq; namespace ConsoleApp1 { public class Class1 { static void Main(string[] args) { int f = int.Parse(Console.ReadLine()); int[] nums = Console.ReadLine() .Trim() .Split(' ') .Select(_ => int.Parse(_)) .ToArray(); bool b = false; for (var i = nums[0]; i < nums[1]; i++) { if (i % f == 0) { b = true; break; } } if (b) { Console.Write("OK"); } else { Console.Write("NG"); } } } }
using System; using System.Linq; namespace ConsoleApp1 { public class Class1 { static void Main(string[] args) { int f = int.Parse(Console.ReadLine()); int[] nums = Console.ReadLine() .Trim() .Split(' ') .Select(_ => int.Parse(_)) .ToArray(); bool b = false; for (var i = nums[0]; i <= nums[1]; i++) { if (i % f == 0) { b = true; break; } } if (b) { Console.Write("OK"); } else { Console.Write("NG"); } } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
150
2
using System; using System.Numerics; using System.Linq; using System.Collections.Generic; using System.Text; namespace debug { // 2つを関連付けてソートする例 class ProgramA { static void Main(string[] args) { int k = int.Parse(Console.ReadLine()); //入力 string[] a = Console.ReadLine().Split(' '); int s = int.Parse(a[0]); int l = int.Parse(a[1]); //羊が多いとき(s > l)のときは生き残る、それ以外は死ぬ for (int i = s; i <= l; i++) { if (i % k == 0) { Console.WriteLine("Yes"); return; } } Console.WriteLine("No"); } } }
using System; using System.Numerics; using System.Linq; using System.Collections.Generic; using System.Text; namespace debug { // 2つを関連付けてソートする例 class ProgramA { static void Main(string[] args) { int k = int.Parse(Console.ReadLine()); //入力 string[] a = Console.ReadLine().Split(' '); int s = int.Parse(a[0]); int l = int.Parse(a[1]); //羊が多いとき(s > l)のときは生き残る、それ以外は死ぬ for (int i = s; i <= l; i++) { if (i % k == 0) { Console.WriteLine("OK"); return; } } Console.WriteLine("NG"); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
151
4
using System; using System.Linq; using System.Collections; using System.Collections.Generic; namespace Main { class Program { static void Main(string[] args) { //ここから // string[] str = Console.ReadLine().Split(' '); // int n = int.Parse(Console.ReadLine()); int n = int.Parse(Console.ReadLine()); // string[] str = Console.ReadLine().Split(' '); int a = int.Parse(str[0]); int b = int.Parse(str[1]); if (a / n != b / n) Console.WriteLine("OK"); else if (a % n == 0 && b % n == 0) Console.WriteLine("OK"); else Console.WriteLine("NG"); //ここまで } } }
using System; using System.Linq; using System.Collections; using System.Collections.Generic; namespace Main { class Program { static void Main(string[] args) { //ここから // string[] str = Console.ReadLine().Split(' '); // int n = int.Parse(Console.ReadLine()); int n = int.Parse(Console.ReadLine()); // string[] str = Console.ReadLine().Split(' '); int a = int.Parse(str[0]); int b = int.Parse(str[1]); if (a / n != b / n) Console.WriteLine("OK"); else if (a % n == 0) Console.WriteLine("OK"); else Console.WriteLine("NG"); //ここまで } } }
[["-", 8, 196, 0, 57, 75, 57, 15, 16, 17, 98], ["-", 75, 57, 15, 16, 12, 16, 31, 16, 31, 22], ["-", 75, 57, 15, 16, 12, 16, 31, 16, 17, 109], ["-", 75, 57, 15, 16, 12, 16, 31, 16, 12, 22], ["-", 0, 57, 75, 57, 15, 16, 12, 16, 17, 60], ["-", 0, 57, 75, 57, 15, 16, 12, 16, 12, 203]]
8
155
6
using System; using System.Collections.Generic; using System.Linq; namespace ClassLibrary1 { public class ListNode { public int val; public ListNode next; public ListNode(int x) { val = x; } } class StringComparator2 : IComparer<string> { int IComparer<string>.Compare(string a, string b) { int length = Math.Min(a.Length, b.Length); // Console.WriteLine("Comparing with length {0}", length); for (int i = 0; i < length; i++) { if (a[i] < b[i]) { // Console.WriteLine("returning -1"); return -1; } else if (a[i] > b[i]) return 1; } if (a.Length < b.Length) return -1; if (a.Length > b.Length) return 1; // Console.WriteLine("Why are we at the end?"); return 0; } } class StringComparator3 : IEqualityComparer<string> { public bool Equals(string b1, string b2) { return Compare(b1, b2) == 0; } public int GetHashCode(string bx) { return bx.GetHashCode(); } int Compare(string a, string b) { int length = Math.Min(a.Length, b.Length); // Console.WriteLine("Comparing with length {0}", length); for (int i = 0; i < length; i++) { if (a[i] < b[i]) { // Console.WriteLine("returning -1"); return -1; } else if (a[i] > b[i]) return 1; } if (a.Length < b.Length) return -1; if (a.Length > b.Length) return 1; // Console.WriteLine("Why are we at the end?"); return 0; } } public class PriorityQueue<T> where T : IComparable { private IComparer<T> _comparer = null; private int _type = 0; private T[] _heap; private int _sz = 0; private int _count = 0; /// <summary> /// Priority Queue with custom comparer /// </summary> public PriorityQueue(int maxSize, IComparer<T> comparer) { _heap = new T[maxSize]; _comparer = comparer; } /// <summary> /// Priority queue /// </summary> /// <param name="maxSize">max size</param> /// <param name="type">0: asc, 1:desc</param> public PriorityQueue(int maxSize, int type = 0) { _heap = new T[maxSize]; _type = type; } private int Compare(T x, T y) { if (_comparer != null) return _comparer.Compare(x, y); return _type == 0 ? x.CompareTo(y) : y.CompareTo(x); } public void Push(T x) { _count++; // node number var i = _sz++; while (i > 0) { // parent node number var p = (i - 1) / 2; if (Compare(_heap[p], x) <= 0) break; _heap[i] = _heap[p]; i = p; } _heap[i] = x; } public T Pop() { _count--; T ret = _heap[0]; T x = _heap[--_sz]; int i = 0; while (i * 2 + 1 < _sz) { // children int a = i * 2 + 1; int b = i * 2 + 2; if (b < _sz && Compare(_heap[b], _heap[a]) < 0) a = b; if (Compare(_heap[a], x) >= 0) break; _heap[i] = _heap[a]; i = a; } _heap[i] = x; return ret; } public int Count() { return _count; } public T Peek() { return _heap[0]; } public bool Contains(T x) { for (int i = 0; i < _sz; i++) if (x.Equals(_heap[i])) return true; return false; } public void Clear() { while (this.Count() > 0) this.Pop(); } public IEnumerator<T> GetEnumerator() { var ret = new List<T>(); while (this.Count() > 0) { ret.Add(this.Pop()); } foreach (var r in ret) { this.Push(r); yield return r; } } public T[] ToArray() { T[] array = new T[_sz]; int i = 0; foreach (var r in this) { array[i++] = r; } return array; } } public class Class1 { // static Dictionary<Tuple<long, long>, long> dic = new Dictionary<Tuple<long, // long>, long>(); static long mod = 1000000007; static long[] factorial = new long[1000001]; static long[] invFactorial = new long[1000001]; private static void calcFanctorial(long N) { factorial[0] = 1; for (int i = 1; i < N + 1; i++) { factorial[i] = factorial[i - 1] * i; factorial[i] %= mod; } invFactorial[N] = inv(factorial[N]); for (int i = (int)N; i > 0; i--) { invFactorial[i - 1] = invFactorial[i] * i % mod; } } class Tree { public HashSet<long> conn = new HashSet<long>(); } static long bin(long a, long x, long n) { long y = a; long res = 1; while (x > 0) { if (x % 2 == 1) { res = res * y % n; } x /= 2; y = y * y % n; } return res; } int cmp(string a, string b) { for (var i = 0; i < Math.Min(a.Length, b.Length); i++) if (a[i] < b[i]) return -1; else if (a[i] > b[i]) return 1; if (a.Length == b.Length) return 0; if (a.Length > b.Length) return 1; else return -1; } private static long nCm(long n, long m) { if (n < m) return 0; if (m < 0) return 0; return (factorial[n] * invFactorial[m] % mod) * invFactorial[n - m] % mod; } private static long nCm2(long n, long m) { if (n < m) return 0; if (m < 0) return 0; long res = 1; for (long i = n; i > n - m; i--) { res *= i; res %= mod; } return res * invFactorial[m] % mod; } public static long pow(long a, long b, long mod) { a %= mod; if (b <= 0) return 1; var t = pow(a, b / 2, mod); if ((b & 1) == 0) return t * t % mod; return t * t % mod * a % mod; } public static long Lcm(long a, long b) { return a * b % mod * inv(Gcd(a, b)) % mod; } public static long Lcm(long[] a) { List<long> vect = new List<long>(); long lcm = 1; for (int i = 0; i < a.Count(); i++) { var factor = a[i] / GcdVector(vect, a[i]); vect.Add(factor); lcm = lcm * factor % mod; } return lcm; } static long GcdVector(List<long> a, long b) { long ma = 1; for (int i = 0; i < a.Count; i++) ma = ma * a[i] % b; return Gcd(b, ma); } public static long Gcd(long a, long b) { if (a < b) // 引数を入替えて自分を呼び出す return Gcd(b, a); while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } public static long pow(long a, long b) => pow(a, b, mod); public static long inv(long a) => pow(a, mod - 2); private static char[][] ReadCharMatrix(long h) { char[][] mtx = new char [h][]; for (int i = 0; i < h; i++) { var s = ReadString(); mtx[i] = s.ToCharArray(); } return mtx; } private static int[][] CreateIntMatrix(long h, long w) { int[][] mtx = new int [h][]; for (int i = 0; i < h; i++) { mtx[i] = new int[w]; } return mtx; } private static string ReadString() { return Console.ReadLine(); } private static string[] ReadStringArr() { return Console.ReadLine().Split(' '); } private static long ReadLong() { return long.Parse(Console.ReadLine()); } private static long[] ReadLongArr() { string[] s = ReadStringArr(); long[] l = new long[s.Length]; for (int i = 0; i < l.Length; i++) { l[i] = long.Parse(s[i]); } return l; } static void Main(string[] args) { var N = ReadLong(); var AB = ReadLongArr(); for (long i = AB[0]; i <= AB[1]; i++) { if (N % i == 0) { Console.WriteLine("OK"); return; } } Console.WriteLine("NG"); } } }
using System; using System.Collections.Generic; using System.Linq; namespace ClassLibrary1 { public class ListNode { public int val; public ListNode next; public ListNode(int x) { val = x; } } class StringComparator2 : IComparer<string> { int IComparer<string>.Compare(string a, string b) { int length = Math.Min(a.Length, b.Length); // Console.WriteLine("Comparing with length {0}", length); for (int i = 0; i < length; i++) { if (a[i] < b[i]) { // Console.WriteLine("returning -1"); return -1; } else if (a[i] > b[i]) return 1; } if (a.Length < b.Length) return -1; if (a.Length > b.Length) return 1; // Console.WriteLine("Why are we at the end?"); return 0; } } class StringComparator3 : IEqualityComparer<string> { public bool Equals(string b1, string b2) { return Compare(b1, b2) == 0; } public int GetHashCode(string bx) { return bx.GetHashCode(); } int Compare(string a, string b) { int length = Math.Min(a.Length, b.Length); // Console.WriteLine("Comparing with length {0}", length); for (int i = 0; i < length; i++) { if (a[i] < b[i]) { // Console.WriteLine("returning -1"); return -1; } else if (a[i] > b[i]) return 1; } if (a.Length < b.Length) return -1; if (a.Length > b.Length) return 1; // Console.WriteLine("Why are we at the end?"); return 0; } } public class PriorityQueue<T> where T : IComparable { private IComparer<T> _comparer = null; private int _type = 0; private T[] _heap; private int _sz = 0; private int _count = 0; /// <summary> /// Priority Queue with custom comparer /// </summary> public PriorityQueue(int maxSize, IComparer<T> comparer) { _heap = new T[maxSize]; _comparer = comparer; } /// <summary> /// Priority queue /// </summary> /// <param name="maxSize">max size</param> /// <param name="type">0: asc, 1:desc</param> public PriorityQueue(int maxSize, int type = 0) { _heap = new T[maxSize]; _type = type; } private int Compare(T x, T y) { if (_comparer != null) return _comparer.Compare(x, y); return _type == 0 ? x.CompareTo(y) : y.CompareTo(x); } public void Push(T x) { _count++; // node number var i = _sz++; while (i > 0) { // parent node number var p = (i - 1) / 2; if (Compare(_heap[p], x) <= 0) break; _heap[i] = _heap[p]; i = p; } _heap[i] = x; } public T Pop() { _count--; T ret = _heap[0]; T x = _heap[--_sz]; int i = 0; while (i * 2 + 1 < _sz) { // children int a = i * 2 + 1; int b = i * 2 + 2; if (b < _sz && Compare(_heap[b], _heap[a]) < 0) a = b; if (Compare(_heap[a], x) >= 0) break; _heap[i] = _heap[a]; i = a; } _heap[i] = x; return ret; } public int Count() { return _count; } public T Peek() { return _heap[0]; } public bool Contains(T x) { for (int i = 0; i < _sz; i++) if (x.Equals(_heap[i])) return true; return false; } public void Clear() { while (this.Count() > 0) this.Pop(); } public IEnumerator<T> GetEnumerator() { var ret = new List<T>(); while (this.Count() > 0) { ret.Add(this.Pop()); } foreach (var r in ret) { this.Push(r); yield return r; } } public T[] ToArray() { T[] array = new T[_sz]; int i = 0; foreach (var r in this) { array[i++] = r; } return array; } } public class Class1 { // static Dictionary<Tuple<long, long>, long> dic = new Dictionary<Tuple<long, // long>, long>(); static long mod = 1000000007; static long[] factorial = new long[1000001]; static long[] invFactorial = new long[1000001]; private static void calcFanctorial(long N) { factorial[0] = 1; for (int i = 1; i < N + 1; i++) { factorial[i] = factorial[i - 1] * i; factorial[i] %= mod; } invFactorial[N] = inv(factorial[N]); for (int i = (int)N; i > 0; i--) { invFactorial[i - 1] = invFactorial[i] * i % mod; } } class Tree { public HashSet<long> conn = new HashSet<long>(); } static long bin(long a, long x, long n) { long y = a; long res = 1; while (x > 0) { if (x % 2 == 1) { res = res * y % n; } x /= 2; y = y * y % n; } return res; } int cmp(string a, string b) { for (var i = 0; i < Math.Min(a.Length, b.Length); i++) if (a[i] < b[i]) return -1; else if (a[i] > b[i]) return 1; if (a.Length == b.Length) return 0; if (a.Length > b.Length) return 1; else return -1; } private static long nCm(long n, long m) { if (n < m) return 0; if (m < 0) return 0; return (factorial[n] * invFactorial[m] % mod) * invFactorial[n - m] % mod; } private static long nCm2(long n, long m) { if (n < m) return 0; if (m < 0) return 0; long res = 1; for (long i = n; i > n - m; i--) { res *= i; res %= mod; } return res * invFactorial[m] % mod; } public static long pow(long a, long b, long mod) { a %= mod; if (b <= 0) return 1; var t = pow(a, b / 2, mod); if ((b & 1) == 0) return t * t % mod; return t * t % mod * a % mod; } public static long Lcm(long a, long b) { return a * b % mod * inv(Gcd(a, b)) % mod; } public static long Lcm(long[] a) { List<long> vect = new List<long>(); long lcm = 1; for (int i = 0; i < a.Count(); i++) { var factor = a[i] / GcdVector(vect, a[i]); vect.Add(factor); lcm = lcm * factor % mod; } return lcm; } static long GcdVector(List<long> a, long b) { long ma = 1; for (int i = 0; i < a.Count; i++) ma = ma * a[i] % b; return Gcd(b, ma); } public static long Gcd(long a, long b) { if (a < b) // 引数を入替えて自分を呼び出す return Gcd(b, a); while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } public static long pow(long a, long b) => pow(a, b, mod); public static long inv(long a) => pow(a, mod - 2); private static char[][] ReadCharMatrix(long h) { char[][] mtx = new char [h][]; for (int i = 0; i < h; i++) { var s = ReadString(); mtx[i] = s.ToCharArray(); } return mtx; } private static int[][] CreateIntMatrix(long h, long w) { int[][] mtx = new int [h][]; for (int i = 0; i < h; i++) { mtx[i] = new int[w]; } return mtx; } private static string ReadString() { return Console.ReadLine(); } private static string[] ReadStringArr() { return Console.ReadLine().Split(' '); } private static long ReadLong() { return long.Parse(Console.ReadLine()); } private static long[] ReadLongArr() { string[] s = ReadStringArr(); long[] l = new long[s.Length]; for (int i = 0; i < l.Length; i++) { l[i] = long.Parse(s[i]); } return l; } static void Main(string[] args) { var N = ReadLong(); var AB = ReadLongArr(); for (long i = AB[0]; i <= AB[1]; i++) { if (i % N == 0) { Console.WriteLine("OK"); return; } } Console.WriteLine("NG"); } } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22]]
8
1,998
4
using System; using System.Linq; public class Test { public static void Main() { // my code goes here int k = int.Parse(Console.ReadLine()); var c = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); int a = c[0]; int b = c[1]; int counter = 0; for (int i = a; i != b; i++) { if (i % k == 0) { counter++; } } if (counter == 0) { Console.WriteLine("NG"); } else { Console.WriteLine("OK"); } } }
using System; using System.Linq; public class Test { public static void Main() { // my code goes here int k = int.Parse(Console.ReadLine()); var c = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); int a = c[0]; int b = c[1]; int counter = 0; for (int i = a; i != b + 1; i++) { if (i % k == 0) { counter++; } } if (counter == 0) { Console.WriteLine("NG"); } else { Console.WriteLine("OK"); } } }
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
144
2
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var inp = Console.ReadLine().Split(' '); int k = int.Parse(inp[0]); var inp2 = Console.ReadLine().Split(' '); int a = int.Parse(inp2[0]); int b = int.Parse(inp2[1]); for (int i = a; i <= b; i++) { if (i % k == 0) { Console.WriteLine("OK"); break; } } Console.WriteLine("NG"); } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var inp = Console.ReadLine().Split(' '); int k = int.Parse(inp[0]); var inp2 = Console.ReadLine().Split(' '); int a = int.Parse(inp2[0]); int b = int.Parse(inp2[1]); for (int i = a; i <= b; i++) { if (i % k == 0) { Console.WriteLine("OK"); return; } } Console.WriteLine("NG"); } }
[["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38]]
8
147
2
using System; namespace abc165_b { class Program { static void Main(string[] args) { var afterBankDeposit = Int64.Parse(Console.ReadLine()); var year = 0; var bankDeposit = 100d; while (bankDeposit < afterBankDeposit) { bankDeposit += bankDeposit / 100; year++; } Console.WriteLine(year); } } }
using System; namespace abc165_b { class Program { static void Main(string[] args) { var afterBankDeposit = Int64.Parse(Console.ReadLine()); var year = 0; var bankDeposit = 100L; while (bankDeposit < afterBankDeposit) { bankDeposit += bankDeposit / 100; year++; } Console.WriteLine(year); } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 250], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
8
70
2
using System; public class Hello { public static void Main() { long x = long.Parse(Console.ReadLine()); long a = 100; var i = 0; while (a <= x) { a += a / 100; i++; } Console.WriteLine(i); } }
using System; public class Hello { public static void Main() { long x = long.Parse(Console.ReadLine()); long a = 100; var i = 0; while (a < x) { a += a / 100; i++; } Console.WriteLine(i); } }
[["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 18]]
8
64
2
using System; namespace Sample { class Sample { static void Main(string[] args) { int x = int.Parse(Console.ReadLine()); int zandaka = 100; int ans = 0; while (zandaka < x) { zandaka += (zandaka / 100); ans = ans + 1; } Console.WriteLine(ans); } } }
using System; namespace Sample { class Sample { static void Main(string[] args) { long x = long.Parse(Console.ReadLine()); long zandaka = 100; int ans = 0; while (zandaka < x) { zandaka += (zandaka / 100); ans = ans + 1; } Console.WriteLine(ans); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
8
75
6
using System; using System.Diagnostics.CodeAnalysis; using System.Reflection; using System.Runtime.InteropServices; using System.Runtime.Serialization; using System.Security.Cryptography.X509Certificates; namespace hello_world { class Program { static void Main(string[] args) { int x = int.Parse(Console.ReadLine()); long sum = 100; int year = 0; while (sum < x) { sum += (sum / 100); year++; } Console.WriteLine(year); } } }
using System; using System.Diagnostics.CodeAnalysis; using System.Reflection; using System.Runtime.InteropServices; using System.Runtime.Serialization; using System.Security.Cryptography.X509Certificates; namespace hello_world { class Program { static void Main(string[] args) { long x = long.Parse(Console.ReadLine()); long sum = 100; int year = 0; while (sum < x) { sum += (sum / 100); year++; } Console.WriteLine(year); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
8
107
4
using System; using System.Text; using System.Collections.Generic; using static System.Math; using System.Linq; using static System.Array; namespace ConsoleApp2 { class Program { static void Main(string[] args) { var X = long.Parse(Console.ReadLine()); var tmp = 100; var count = 0; while (tmp < X) { X = (long)(1.01 * X); count++; } Console.WriteLine(count); } } }
using System; using System.Text; using System.Collections.Generic; using static System.Math; using System.Linq; using static System.Array; namespace ConsoleApp2 { class Program { static void Main(string[] args) { var X = long.Parse(Console.ReadLine()); var tmp = 100L; var count = 0; while (tmp < X) { tmp = (long)(1.01 * tmp); count++; } Console.WriteLine(count); } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 0, 11, 12, 74, 51, 23, 0, 16, 12, 22], ["+", 0, 11, 12, 74, 51, 23, 0, 16, 12, 22]]
8
104
6
using System; using System.ComponentModel; namespace ConsoleApp1 { class Program { static void Main(string[] args) { int yokin = 100; int X = int.Parse(Console.ReadLine()); int year = 0; while (yokin < X) { year += 1; yokin = (int)(Math.Floor(yokin * 1.01)); } Console.WriteLine(year); } } }
using System; using System.ComponentModel; namespace ConsoleApp1 { class Program { static void Main(string[] args) { long yokin = 100; long X = long.Parse(Console.ReadLine()); long year = 0; while (yokin < X) { year += 1; yokin = (long)(Math.Floor(yokin * 1.01)); } Console.WriteLine(year); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 8, 196, 0, 1, 0, 11, 12, 74, 39, 199], ["+", 8, 196, 0, 1, 0, 11, 12, 74, 39, 199]]
8
86
10
using System; using System.Linq; public class Test { public static void Main() { // my code goes here ulong x = ulong.Parse(Console.ReadLine()); int counter = 0; decimal a = 100; while (a <= x) { a = a * (decimal)1.01; a = Math.Floor(a); counter++; } Console.WriteLine(counter); } }
using System; using System.Linq; public class Test { public static void Main() { // my code goes here ulong x = ulong.Parse(Console.ReadLine()); int counter = 0; decimal a = 100; while (a < x) { a = a * (decimal)1.01; a = Math.Floor(a); counter++; } Console.WriteLine(counter); } }
[["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 18]]
8
82
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Program { static void Main(string[] args) { var n = ReadLineLongInt(); var money = 100d; var year = 0; while (money <= n) { money = Math.Floor((money * 0.01) + money); year++; } Console.WriteLine(year); ReadLine(); } //最大公約数 static int gcd(int a, int b) { if (a > b) { return gcd(b, a); } while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } //最小公倍数 static int lcm(int a, int b) => a * b / gcd(a, b); /// <summary> /// コンビネーション /// </summary> static int nCm(int n, int m) { if (m == 0) return 1; if (n == 0) return 0; return n * nCm(n - 1, m - 1) / m; } public static string ReadLine() => Console.ReadLine(); public static int ReadLineInt() => int.Parse(Console.ReadLine()); public static long ReadLineLongInt() => long.Parse(Console.ReadLine()); public static string[] ReadLineStringSplit(char a = ' ') => ReadLine().Split(a).ToArray(); public static int[] ReadLineIntSpilit(char a = ' ') => ReadLine().Split(a).Select(x => int.Parse(x)).ToArray(); public static long[] ReadLineLongSpilit(char a = ' ') => ReadLine().Split(a).Select(x => long.Parse(x)).ToArray(); static string[] GetAplhaLowerArray() => new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" }; static string[] GetAplhaUpperArray() => new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" }; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Program { static void Main(string[] args) { var n = ReadLineLongInt(); var money = 100d; var year = 0; while (money < n) { money = Math.Floor(money * 0.01) + money; year++; } Console.WriteLine(year); ReadLine(); } //最大公約数 static int gcd(int a, int b) { if (a > b) { return gcd(b, a); } while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } //最小公倍数 static int lcm(int a, int b) => a * b / gcd(a, b); /// <summary> /// コンビネーション /// </summary> static int nCm(int n, int m) { if (m == 0) return 1; if (n == 0) return 0; return n * nCm(n - 1, m - 1) / m; } public static string ReadLine() => Console.ReadLine(); public static int ReadLineInt() => int.Parse(Console.ReadLine()); public static long ReadLineLongInt() => long.Parse(Console.ReadLine()); public static string[] ReadLineStringSplit(char a = ' ') => ReadLine().Split(a).ToArray(); public static int[] ReadLineIntSpilit(char a = ' ') => ReadLine().Split(a).Select(x => int.Parse(x)).ToArray(); public static long[] ReadLineLongSpilit(char a = ' ') => ReadLine().Split(a).Select(x => long.Parse(x)).ToArray(); static string[] GetAplhaLowerArray() => new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" }; static string[] GetAplhaUpperArray() => new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" }; } }
[["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 18], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25]]
8
620
4
using System; class Program { static void Main(string[] args) { // 整数の入力 long initialMoney = long.Parse(Console.ReadLine()); long money = 100; int year = 0; double rate = 0; while (money < initialMoney) { rate = money * 0.01f; money = money + (long)rate; year++; } Console.WriteLine(year); } }
using System; class Program { static void Main(string[] args) { // 整数の入力 long initialMoney = long.Parse(Console.ReadLine()); long money = 100; int year = 0; long rate = 0; while (money < initialMoney) { rate = money / 100; money = money + (long)rate; year++; } Console.WriteLine(year); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 12, 250], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 85], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203]]
8
81
6
using System; using System.Collections.Generic; using System.Linq; using System.Numerics; using System.Text; using System.Threading; using System.Threading.Tasks; namespace ConsoleApp2 { class Program { static void Main(string[] args) { var X = decimal.Parse(Console.ReadLine()); decimal ans = 0; decimal sum = 100; while (sum <= X) { sum = Math.Floor(sum * (decimal)1.01); ans++; } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Numerics; using System.Text; using System.Threading; using System.Threading.Tasks; namespace ConsoleApp2 { class Program { static void Main(string[] args) { var X = decimal.Parse(Console.ReadLine()); decimal ans = 0; decimal sum = 100; while (sum < X) { sum = Math.Floor(sum * (decimal)1.01); ans++; } Console.WriteLine(ans); } } }
[["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 18]]
8
112
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; using static System.Math; class Program { public static void Main() { long i = 100; var n = long.Parse(ReadLine()); int count = 0; while (i < n) { i += (long)(i / 100f); count++; } WriteLine($"{count}"); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; using static System.Math; class Program { public static void Main() { long i = 100; var n = long.Parse(ReadLine()); long count = 0; while (i < n) { i += (long)(i / 100d); count++; } WriteLine($"{count}"); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 11, 12, 74, 51, 23, 0, 16, 12, 250], ["+", 0, 11, 12, 74, 51, 23, 0, 16, 12, 250]]
8
97
4
using System; namespace AtCoder { public static class AtCoder { public static void Main() { double a = 100; decimal x = decimal.Parse(Console.ReadLine()); long ans = 1; while (true) { a += Math.Floor(a * 0.01); if ((decimal)a >= x) { break; } ans++; } Console.WriteLine(ans); } } }
using System; namespace AtCoder { public static class AtCoder { public static void Main() { decimal a = 100; decimal x = decimal.Parse(Console.ReadLine()); long ans = 1; while (true) { a += (decimal)Math.Floor(a * 0.01m); if ((decimal)a >= x) { break; } ans++; } Console.WriteLine(ans); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 1, 0, 11, 12, 74, 0, 24], ["+", 8, 196, 0, 1, 0, 11, 12, 74, 39, 199], ["+", 8, 196, 0, 1, 0, 11, 12, 74, 0, 25], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 12, 250], ["+", 51, 213, 3, 4, 0, 28, 0, 16, 12, 250]]
8
85
7
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcorder_text { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int SV = int.Parse(input[0]); int HW = int.Parse(input[1]); int[] HWList = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); int HWday = HWList.Sum(); int Freeday = SV - HWday; if (Freeday >= SV) { Console.Write("-1"); } else { Console.Write(Freeday); } Console.Read(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcorder_text { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int SV = int.Parse(input[0]); int HW = int.Parse(input[1]); int[] HWList = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); int HWday = HWList.Sum(); int Freeday = SV - HWday; if (HWday > SV) { Console.Write("-1"); } else { Console.Write(Freeday); } Console.Read(); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47]]
8
173
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { class Abc162F { public static void Main() { var input = Console.ReadLine().Split(' '); var d = long.Parse(input[0]); var m = long.Parse(input[1]); var a = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); var sum = a.Sum(); if (sum < d) Console.Write("-1"); if (sum == d) Console.Write("0"); if (sum > d) Console.Write((d - sum)); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { class Abc162F { public static void Main() { var input = Console.ReadLine().Split(' '); var d = long.Parse(input[0]); var m = long.Parse(input[1]); var a = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); var sum = a.Sum(); if (sum > d) Console.Write("-1"); if (sum == d) Console.Write("0"); if (sum < d) Console.Write((d - sum)); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18]]
8
173
4
using System; using static System.Console; using System.Linq; namespace Main { class Program { static void Main(string[] args) { long[] tmp; tmp = ReadLine().Split(' ').Select(long.Parse).ToArray(); long N = tmp[0]; long M = tmp[1]; tmp = ReadLine().Split(' ').Select(long.Parse).ToArray(); WriteLine(N > tmp.Sum() ? N - tmp.Sum() : -1); } } }
using System; using static System.Console; using System.Linq; namespace Main { class Program { static void Main(string[] args) { long[] tmp; tmp = ReadLine().Split(' ').Select(long.Parse).ToArray(); long N = tmp[0]; long M = tmp[1]; tmp = ReadLine().Split(' ').Select(long.Parse).ToArray(); WriteLine(N >= tmp.Sum() ? N - tmp.Sum() : -1); } } }
[["-", 3, 4, 0, 28, 0, 41, 15, 16, 17, 47], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 20]]
8
124
2
using System.Collections.Generic; using System.Linq; public class Hello { public static void Main() { hoge(); // System.Console.ReadLine(); } public static void hoge() { var vars = System.Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); var n = vars[0]; var m = vars[1]; var a = System.Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); var sum = a.Sum(); System.Console.WriteLine(n - sum > 0 ? n - sum : -1); } }
using System.Collections.Generic; using System.Linq; public class Hello { public static void Main() { hoge(); // System.Console.ReadLine(); } public static void hoge() { var vars = System.Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); var n = vars[0]; var m = vars[1]; var a = System.Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); var sum = a.Sum(); System.Console.WriteLine(n - sum >= 0 ? n - sum : -1); } }
[["-", 3, 4, 0, 28, 0, 41, 15, 16, 17, 47], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 20]]
8
141
2
using System; using System.Linq; using System.Collections.Generic; namespace B { class Program { static void Main(string[] args) { var nm = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); var N = nm[0]; var M = nm[1]; var input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); long sum = 0; foreach (var d in input) { sum += d; } Console.WriteLine($"{(N - sum > 0 ? N - sum : -1)}"); } } }
using System; using System.Linq; using System.Collections.Generic; namespace B { class Program { static void Main(string[] args) { var nm = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); var N = nm[0]; var M = nm[1]; var input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); long sum = 0; foreach (var d in input) { sum += d; } Console.WriteLine($"{(N - sum >= 0 ? N - sum : -1)}"); } } }
[["-", 0, 284, 0, 23, 0, 41, 15, 16, 17, 47], ["+", 0, 284, 0, 23, 0, 41, 15, 16, 17, 20]]
8
156
2
using System; using System.Linq; namespace AtCoderMake.ABC163 { class ABC163B { static void Main(string[] args) { var a = Console.ReadLine().Split().Select((x) => int.Parse(x)).ToArray(); var b = Console.ReadLine().Split().Select((x) => int.Parse(x)); var n = a[0]; var sum = b.Sum(); if (n > sum) { Console.WriteLine(n - sum); } else { Console.WriteLine(-1); } } } }
using System; using System.Linq; namespace AtCoderMake.ABC163 { class ABC163B { static void Main(string[] args) { var a = Console.ReadLine().Split().Select((x) => int.Parse(x)).ToArray(); var b = Console.ReadLine().Split().Select((x) => int.Parse(x)); var n = a[0]; var sum = b.Sum(); if (n >= sum) { Console.WriteLine(n - sum); } else { Console.WriteLine(-1); } } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20]]
8
132
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Collections.Generic; namespace AtCoder { class Abc162F { static long[] A = new long[200010]; static int[] ans = new int[200010]; public static void Main() { var n = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); for (int i = 1; i <= a.Length; i++) { A[i] = a[i - 1]; } for (int i = 1; i < n; i++) { ans[A[i]]++; } for (int i = 0; i < n + 1; i++) { Console.Write(ans[i]); Console.WriteLine(); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Collections.Generic; namespace AtCoder { class Abc162F { static long[] A = new long[200010]; static int[] ans = new int[200010]; public static void Main() { var n = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); for (int i = 1; i <= a.Length; i++) { A[i] = a[i - 1]; } for (int i = 1; i < n; i++) { ans[A[i]]++; } for (int i = 1; i < n + 1; i++) { Console.Write(ans[i]); Console.WriteLine(); } } } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
8
209
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); string[] string2 = Console.ReadLine().Split(' '); int day, task, res; day = int.Parse(input[0]); int cost = 0; int[] underworker = new int[string2.Count()]; int[] result = new int[string2.Count() + 1]; for (int i = 0; i < string2.Count(); i++) { result[i] = 0; underworker[i] += int.Parse(string2[i]); } for (int j = 0; j < underworker.Count(); j++) { result[underworker[j] - 1]++; } for (int i = 0; i < underworker.Count(); i++) { Console.WriteLine(result[i]); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); string[] string2 = Console.ReadLine().Split(' '); int day, task, res; day = int.Parse(input[0]); int cost = 0; int[] underworker = new int[string2.Count()]; int[] result = new int[string2.Count() + 1]; for (int i = 0; i < string2.Count(); i++) { result[i] = 0; underworker[i] += int.Parse(string2[i]); } for (int j = 0; j < underworker.Count(); j++) { result[underworker[j] - 1]++; } for (int i = 0; i < underworker.Count() + 1; i++) { Console.WriteLine(result[i]); } } } }
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
241
2
using System; class Program { static void Main(string[] args) { var inp = Console.ReadLine().Split(' '); long n = long.Parse(inp[0]); var inp2 = Console.ReadLine().Split(' '); int[] buka = new int[n]; for (int i = 0; i < inp2.Length; i++) { buka[int.Parse(inp2[i])]++; } for (int i = 0; i < n; i++) { Console.WriteLine(buka[i]); } } }
using System; class Program { static void Main(string[] args) { var inp = Console.ReadLine().Split(' '); long n = long.Parse(inp[0]); var inp2 = Console.ReadLine().Split(' '); int[] buka = new int[n]; for (int i = 0; i < inp2.Length; i++) { buka[int.Parse(inp2[i]) - 1]++; } for (int i = 0; i < n; i++) { Console.WriteLine(buka[i]); } } }
[["+", 0, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
132
2
using System; using System.Linq; namespace AtCoderMake.ABC163 { class ABC163C { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split().Select((x) => int.Parse(x)); int[] mane = new int[n]; mane.Select((x) => 0); foreach (int ai in a) { mane[ai] = mane[ai] + 1; } foreach (int m in mane) { Console.WriteLine(m); } } } }
using System; using System.Linq; namespace AtCoderMake.ABC163 { class ABC163C { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split().Select((x) => int.Parse(x)); int[] mane = new int[n]; mane.Select((x) => 0); foreach (int ai in a) { mane[ai - 1] = mane[ai - 1] + 1; } foreach (int m in mane) { Console.WriteLine(m); } } } }
[["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
129
4
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace cysharp_test { class Program { static void Main(string[] args) { new Program().solve(); } void solve() { int N = int.Parse(Console.ReadLine()); int[] As = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int[] nums = new int[N]; for (int i = 0; i < N - 1; i++) { nums[As[i] - 1]++; } for (int i = 0; i < N - 1; i++) Console.WriteLine(nums[i]); } } class Vector2 { public Vector2(long x, long y) { this.x = x; this.y = y; } long x, y; public static Vector2 operator +(Vector2 a, Vector2 b) { return new Vector2(a.x + b.x, a.y + b.y); } public static Vector2 operator -(Vector2 a, Vector2 b) { return new Vector2(a.x - b.x, a.y - b.y); } public static Vector2 operator *(Vector2 a, long scala) { return new Vector2(a.x * scala, a.y + scala); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace cysharp_test { class Program { static void Main(string[] args) { new Program().solve(); } void solve() { int N = int.Parse(Console.ReadLine()); int[] As = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int[] nums = new int[N]; for (int i = 0; i < N - 1; i++) { nums[As[i] - 1]++; } for (int i = 0; i < N; i++) Console.WriteLine(nums[i]); } } class Vector2 { public Vector2(long x, long y) { this.x = x; this.y = y; } long x, y; public static Vector2 operator +(Vector2 a, Vector2 b) { return new Vector2(a.x + b.x, a.y + b.y); } public static Vector2 operator -(Vector2 a, Vector2 b) { return new Vector2(a.x - b.x, a.y - b.y); } public static Vector2 operator *(Vector2 a, long scala) { return new Vector2(a.x * scala, a.y + scala); } } }
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
296
2
using System; using System.Numerics; using System.Linq; using System.Collections.Generic; using System.Text; namespace debug { class ProgramC { static void Main(string[] args) { //入力 int n = int.Parse(Console.ReadLine()); string[] a = Console.ReadLine().Split(' '); int[] boss = new int[n]; for (int i = 0; i < n - 1; i++) { boss[int.Parse(a[i]) - 1]++; } for (int i = 0; i < n - 1; i++) { // sの位置に応じて場合分けする Console.WriteLine(boss[i]); } } } }
using System; using System.Numerics; using System.Linq; using System.Collections.Generic; using System.Text; namespace debug { class ProgramC { static void Main(string[] args) { //入力 int n = int.Parse(Console.ReadLine()); string[] a = Console.ReadLine().Split(' '); int[] boss = new int[n]; for (int i = 0; i < n - 1; i++) { boss[int.Parse(a[i]) - 1]++; } for (int i = 0; i < n; i++) { // sの位置に応じて場合分けする Console.WriteLine(boss[i]); } } } }
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
151
2
using System; //この問題を解きやすいように解釈すると // 0,1,2,3,...,nのうちs個(s=k~n+1)取った時を考えればよい //またこの時の最大値、最小値は // Min=0+1+...+(s-1) // Max=(n-s+1)+...+n //この間は全て存在する //計算を省略するため連続する数の和の公式も使う // f(l,r)=l+(l+1)+..+r=(l+r)(r-l+1)/2 class Program { static readonly int M = (int)Math.Pow(10, 9) + 7; static void Main() { string[] In = Console.ReadLine().Split(' '); int n = int.Parse(In[0]); int k = int.Parse(In[1]); long max, min; long sum = 0; for (int i = k; i <= n + 1; i++) { max = Wa(n - i + 1, n); min = Wa(0, i - 1); sum += (max - min + 1); sum %= M; } Console.WriteLine(sum); } static long Wa(int l, int r) { return (l + r) * (r - l + 1) / 2; } } // class Program //{ // static readonly int M = (int)Math.Pow(10, 9) + 7; // static void Main() // { // string[] In = Console.ReadLine().Split(' '); // int n = int.Parse(In[0]); // int k = int.Parse(In[1]); // int max, min; // long sum=0; // for(int i = k; i <= n + 1; i++) // { // max = 0; // for(int j = n - i + 1; j <= n; j ++) // { // max += j; // } // min = 0; // for(int j = 0; j <= i - 1; j++) // { // min += j; // } // sum += max - min+1; // sum %= M; // } // Console.WriteLine(sum); // } //}
using System; //この問題を解きやすいように解釈すると // 0,1,2,3,...,nのうちs個(s=k~n+1)取った時を考えればよい //またこの時の最大値、最小値は // Min=0+1+...+(s-1) // Max=(n-s+1)+...+n //この間は全て存在する //計算を省略するため連続する数の和の公式も使う // f(l,r)=l+(l+1)+..+r=(l+r)(r-l+1)/2 class Program { static readonly int M = (int)Math.Pow(10, 9) + 7; static void Main() { string[] In = Console.ReadLine().Split(' '); int n = int.Parse(In[0]); int k = int.Parse(In[1]); long max, min; long sum = 0; for (int i = k; i <= n + 1; i++) { max = Wa(n - i + 1, n); min = Wa(0, i - 1); sum += (max - min + 1); sum %= M; } Console.WriteLine(sum); } //ここのlong l, long rに注意 static long Wa(long l, long r) { return (l + r) * (r - l + 1) / 2; } } // class Program //{ // static readonly int M = (int)Math.Pow(10, 9) + 7; // static void Main() // { // string[] In = Console.ReadLine().Split(' '); // int n = int.Parse(In[0]); // int k = int.Parse(In[1]); // int max, min; // long sum=0; // for(int i = k; i <= n + 1; i++) // { // max = 0; // for(int j = n - i + 1; j <= n; j ++) // { // max += j; // } // min = 0; // for(int j = 0; j <= i - 1; j++) // { // min += j; // } // sum += max - min+1; // sum %= M; // } // Console.WriteLine(sum); // } //}
[["-", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199]]
8
215
4
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using static System.Console; using static System.Math; namespace Atcoder { class Program { static void Main(string[] args) { try { Solve.Answer(); } catch (Exception ex) { WriteLine(ex.ToString()); } } } public class Solve { public static void Answer() { long M = 1000000007; var nk = IO.ReadSplitLong; long ans = 0; for (long i = nk[1]; i <= nk[0] + 1; i++) { ans = (ans + i * nk[0] % M) % M; ans = (ans - i * i % M) % M; ans = (ans + i) % M; ans = (ans + 1) % M; } WriteLine(ans); } 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 class Scanner { #region public string Str => Console.ReadLine().Trim(); public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray(); public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray(); // public char[][] Grid(int n) => Create(n, () => Str.ToCharArray()); // public int[] ArrInt1D(int n) => Create(n, () => Int); // public long[] ArrLong1D(int n) => Create(n, () => Long); // public int[][] ArrInt2D(int n) => Create(n, () => ArrInt); // public long[][] ArrLong2D(int n) => Create(n, () => ArrLong); private Queue<string> q = new Queue<string>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] // インライン化を推奨する public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); } public void Make<T1>(out T1 v1) => v1 = Next<T1>(); public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); } public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); } public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); } #endregion } public static long GCD(long x, long y) { #region if (x < y) { var tmp = x; x = y; y = tmp; } while (true) { if (x % y == 0) { return y; } else { var tmp = x; x = y; y = tmp % y; } } #endregion } 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.Linq; using System.Runtime.CompilerServices; using System.Text; using static System.Console; using static System.Math; namespace Atcoder { class Program { static void Main(string[] args) { try { Solve.Answer(); } catch (Exception ex) { WriteLine(ex.ToString()); } } } public class Solve { public static void Answer() { long M = 1000000007; var nk = IO.ReadSplitLong; long ans = 0; for (long i = nk[1]; i <= nk[0] + 1; i++) { ans = (ans + i * nk[0] % M) % M; ans = Mod.Sub(ans, i * i % M); ans = (ans + i) % M; ans = (ans + 1) % M; } WriteLine(ans); } 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 class Scanner { #region public string Str => Console.ReadLine().Trim(); public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray(); public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray(); // public char[][] Grid(int n) => Create(n, () => Str.ToCharArray()); // public int[] ArrInt1D(int n) => Create(n, () => Int); // public long[] ArrLong1D(int n) => Create(n, () => Long); // public int[][] ArrInt2D(int n) => Create(n, () => ArrInt); // public long[][] ArrLong2D(int n) => Create(n, () => ArrLong); private Queue<string> q = new Queue<string>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] // インライン化を推奨する public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); } public void Make<T1>(out T1 v1) => v1 = Next<T1>(); public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); } public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); } public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); } #endregion } public static long GCD(long x, long y) { #region if (x < y) { var tmp = x; x = y; y = tmp; } while (true) { if (x % y == 0) { return y; } else { var tmp = x; x = y; y = tmp % y; } } #endregion } 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, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["-", 0, 11, 12, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 109], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 12, 22]]
8
1,126
7
using System; using System.Linq; class AtCoderCS { static void Main(string[] args) { int[] NK = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray(); int N = NK[0], K = NK[1]; long ans = 0, min = 0, max = N; for (int i = 1; i < N + 1; i++) { min += i; max += N - i; if (i >= K - 1) ans += (max - min + 1) % 1000000007; } Console.WriteLine(ans % 1000000007); } }
using System; using System.Linq; class AtCoderCS { static void Main(string[] args) { int[] NK = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray(); int N = NK[0], K = NK[1]; long ans = 0, min = 0, max = 0; for (int i = 0; i < N + 1; i++) { min += i; max += N - i; if (i >= K - 1) ans += (max - min + 1) % 1000000007; } Console.WriteLine(ans % 1000000007); } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
8
142
4
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var inputs = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); var n = inputs[0]; var k = inputs[1]; Modint result = 0; for (long i = k; i <= n + 1; i++) { result += i * (n - i + 1) + 1; } Console.WriteLine(result); } /// <summary> /// モジュラス数学 割り算をしたときの余りのみ注目 /// </summary> public struct Modint { private const int M = 1000000007; public long Value { get; } private static readonly List<int> _factorialCache = new List<int> { 1 }; public Modint(long value) { Value = value; } public static implicit operator Modint(long a) { var m = a % M; return new Modint((m < 0) ? m + M : m); } public static Modint operator +(Modint a, Modint b) => a.Value + b.Value; public static Modint operator -(Modint a, Modint b) => a.Value - b.Value; public static Modint operator *(Modint a, Modint b) => a.Value * b.Value; // フェルマーの小定理 public static Modint operator /(Modint a, Modint b) => a * Pow(b, M - 2); /// <summary> /// a^n (繰り返し2累乗法) /// </summary> public static Modint Pow(Modint a, int n) { if (n == 0) return 1; if (n == 1) return a; var p = Pow(a, n / 2); return p * p * Pow(a, n % 2); } /// <summary> /// 階乗 n! /// </summary> public static Modint Fac(int n) { for (int i = _factorialCache.Count; i <= n; i++) { _factorialCache.Add((int)(Math.BigMul(_factorialCache.Last(), i) % M)); } return _factorialCache[n]; } public static Modint nCr(int n, int r) => (n < r) ? 0 : (n == r) ? 1 : Fac(n) / (Fac(r) * Fac(n - r)); } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var inputs = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); var n = inputs[0]; var k = inputs[1]; Modint result = 0; for (long i = k; i <= n + 1; i++) { result += i * (n - i + 1) + 1; } Console.WriteLine(result.Value); } /// <summary> /// モジュラス数学 割り算をしたときの余りのみ注目 /// </summary> public struct Modint { private const int M = 1000000007; public long Value { get; } private static readonly List<int> _factorialCache = new List<int> { 1 }; public Modint(long value) { Value = value; } public static implicit operator Modint(long a) { var m = a % M; return new Modint((m < 0) ? m + M : m); } public static Modint operator +(Modint a, Modint b) => a.Value + b.Value; public static Modint operator -(Modint a, Modint b) => a.Value - b.Value; public static Modint operator *(Modint a, Modint b) => a.Value * b.Value; // フェルマーの小定理 public static Modint operator /(Modint a, Modint b) => a * Pow(b, M - 2); /// <summary> /// a^n (繰り返し2累乗法) /// </summary> public static Modint Pow(Modint a, int n) { if (n == 0) return 1; if (n == 1) return a; var p = Pow(a, n / 2); return p * p * Pow(a, n % 2); } /// <summary> /// 階乗 n! /// </summary> public static Modint Fac(int n) { for (int i = _factorialCache.Count; i <= n; i++) { _factorialCache.Add((int)(Math.BigMul(_factorialCache.Last(), i) % M)); } return _factorialCache[n]; } public static Modint nCr(int n, int r) => (n < r) ? 0 : (n == r) ? 1 : Fac(n) / (Fac(r) * Fac(n - r)); } }
[["+", 0, 213, 3, 4, 0, 28, 0, 214, 0, 131], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 141, 22]]
8
461
2
using System; using static System.Console; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Threading; namespace Atcoder_Answer { class Program { const Int32 mod = 1000000007; static void Main(string[] args) { int X = int.Parse(ReadLine()); int M = 100; for (int loop = 1;; loop++) { M = (int)(M * 1.01); if (X <= M) { WriteLine(loop.ToString()); return; } } } } public static class Extension { #region 拡張 : bool #region キャスト関連 public static int ToInt(this bool Bool) { if (Bool) return 1; else return 0; } public static string ToString(this bool Bool, string TrueStr, string FalseStr) { if (Bool) return TrueStr; else return FalseStr; } #endregion #endregion #region 拡張 : int #region キャスト関連 public static char ToAlphaBets(this int Base) => (char)Base; #endregion #endregion #region 拡張 : char #region 変換関連 public static char NextAlpha(this char Char) => (char)((Char) + 1); //次の文字を取得 #endregion #endregion #region 拡張 : int[] public static long Sum(this int[] Array) { int Ret = 0; for (int loop = 0; loop < Array.Length; loop++) Ret += Array[loop]; return Ret; } #endregion #region 拡張 : string public static string Multi(this string THIS, int Value) { string RetValue = ""; for (int loop = 0; loop < Value; loop++) RetValue += THIS; return RetValue; } #endregion #region 拡張 : List < string> public static string Sum(this List<string> THIS, string Split) { string RetValue = ""; for (int loop = 0; loop < THIS.Count; loop++) { RetValue += THIS[loop]; } return RetValue; } #endregion } }
using System; using static System.Console; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Threading; namespace Atcoder_Answer { class Program { const Int32 mod = 1000000007; static void Main(string[] args) { long X = long.Parse(ReadLine()); long M = 100; for (int loop = 1;; loop++) { M = (long)(M * 1.01); if (X <= M) { WriteLine(loop.ToString()); return; } } } } public static class Extension { #region 拡張 : bool #region キャスト関連 public static int ToInt(this bool Bool) { if (Bool) return 1; else return 0; } public static string ToString(this bool Bool, string TrueStr, string FalseStr) { if (Bool) return TrueStr; else return FalseStr; } #endregion #endregion #region 拡張 : int #region キャスト関連 public static char ToAlphaBets(this int Base) => (char)Base; #endregion #endregion #region 拡張 : char #region 変換関連 public static char NextAlpha(this char Char) => (char)((Char) + 1); //次の文字を取得 #endregion #endregion #region 拡張 : int[] public static long Sum(this int[] Array) { int Ret = 0; for (int loop = 0; loop < Array.Length; loop++) Ret += Array[loop]; return Ret; } #endregion #region 拡張 : string public static string Multi(this string THIS, int Value) { string RetValue = ""; for (int loop = 0; loop < Value; loop++) RetValue += THIS; return RetValue; } #endregion #region 拡張 : List < string> public static string Sum(this List<string> THIS, string Split) { string RetValue = ""; for (int loop = 0; loop < THIS.Count; loop++) { RetValue += THIS[loop]; } return RetValue; } #endregion } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 8, 196, 0, 1, 0, 11, 12, 74, 39, 199], ["+", 8, 196, 0, 1, 0, 11, 12, 74, 39, 199]]
8
397
8
using System; using System.Linq; using System.Collections.Generic; using System.IO; using static System.Console; 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(); } public static long gcd(long x, long y) { if (y < x) gcd(y, x); while (y != 0) { var z = x % y; x = y; y = z; } return x; } public static long keta(long x) { var z = 1; while (x > 0) { x /= 10; z++; } return z; } static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var abn = Reads(); var a = abn[0]; var b = abn[1]; var n = abn[2]; long x = 0; if (n >= b) x = n - 1; else x = n; WriteLine(Math.Floor((decimal)a * x / b) - a * Math.Floor((decimal)x / b)); Console.Out.Flush(); } } }
using System; using System.Linq; using System.Collections.Generic; using System.IO; using static System.Console; 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(); } public static long gcd(long x, long y) { if (y < x) gcd(y, x); while (y != 0) { var z = x % y; x = y; y = z; } return x; } public static long keta(long x) { var z = 1; while (x > 0) { x /= 10; z++; } return z; } static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var abn = Reads(); var a = abn[0]; var b = abn[1]; var n = abn[2]; long x = 0; if (n >= b) x = b - 1; else x = n; WriteLine(Math.Floor((decimal)a * x / b) - a * Math.Floor((decimal)x / b)); Console.Out.Flush(); } } }
[["-", 0, 57, 64, 1, 0, 11, 12, 16, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 31, 22]]
8
299
2
using System; using System.Linq; using System.Collections.Generic; namespace ABC { class ProgramD { static void Main(string[] args) { var inputs = Console.ReadLine().Split(" "); var a = double.Parse(inputs[0]); var b = double.Parse(inputs[1]); var n = double.Parse(inputs[2]); var x = Math.Min(b, n); var result = Math.Floor(a * x / b) - (a * Math.Floor(x / b)); Console.WriteLine(result); } } }
using System; using System.Linq; using System.Collections.Generic; namespace ABC { class ProgramD { static void Main(string[] args) { var inputs = Console.ReadLine().Split(" "); var a = double.Parse(inputs[0]); var b = double.Parse(inputs[1]); var n = double.Parse(inputs[2]); var x = Math.Min(b - 1, n); var result = Math.Floor(a * x / b) - (a * Math.Floor(x / b)); Console.WriteLine(result); } } }
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
135
2
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; using static System.Math; using static AtCoderTemplate.MyLibrary; namespace AtCoderTemplate { class Program { static void Main(string[] args) { string[] str; str = Console.ReadLine().Split(' '); int A = int.Parse(str[0]); long B = long.Parse(str[1]); long N = long.Parse(str[2]); long ans = 0; if (N <= B) { ans = A * N / B; } else { ans = A * (B - 1) / B; } Console.Write(ans); } } class MyLibrary { public static int GCD(int a, int b) { if (a % b == 0) return b; return GCD(b, a % b); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; using static System.Math; using static AtCoderTemplate.MyLibrary; namespace AtCoderTemplate { class Program { static void Main(string[] args) { string[] str; str = Console.ReadLine().Split(' '); int A = int.Parse(str[0]); long B = long.Parse(str[1]); long N = long.Parse(str[2]); long ans = 0; if (N < B) { ans = A * N / B; } else { ans = A * (B - 1) / B; } Console.Write(ans); } } class MyLibrary { public static int GCD(int a, int b) { if (a % b == 0) return b; return GCD(b, a % b); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18]]
8
202
2
using System; using System.Collections.Generic; using System.Linq; class Program { public static void Main() { var input = Console.ReadLine().Split().Select(int.Parse).ToArray(); long A = input[0]; long B = input[1]; long N = input[2]; long x = Math.Min(B - 1, N); Console.WriteLine(Convert.ToInt64(A * x / B)); } }
using System; using System.Collections.Generic; using System.Linq; class Program { public static void Main() { var input = Console.ReadLine().Split().Select(long.Parse).ToArray(); long A = input[0]; long B = input[1]; long N = input[2]; long x = Math.Min(B - 1, N); Console.WriteLine(Convert.ToInt64(A * x / B)); } }
[["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199]]
8
105
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp57 { class Program { static int A, B, N; static void Main(string[] args) { var l = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); A = l[0]; B = l[1]; N = l[2]; int x = 0; if (B - 1 > N) { x = N; } else { x = B - 1; } var min = (A * (x)) / B; Console.WriteLine(min); // Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp57 { class Program { static long A, B, N; static void Main(string[] args) { var l = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); A = l[0]; B = l[1]; N = l[2]; long x = 0; if (B - 1 > N) { x = N; } else { x = B - 1; } var min = (A * (x)) / B; Console.WriteLine(min); // Console.ReadKey(); } } }
[["-", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["+", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
151
6
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main(string[] args) { double[] arr = Console.ReadLine().Split(' ').Select(v => double.Parse(v)).ToArray(); double a = arr[0]; double b = arr[1]; double n = arr[2]; double nMax = n < a ? n : a - 1; long ans = (long)(a * nMax / b) - (long)a * (long)(nMax / b); Console.WriteLine(ans); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main(string[] args) { double[] arr = Console.ReadLine().Split(' ').Select(v => double.Parse(v)).ToArray(); double a = arr[0]; double b = arr[1]; double n = arr[2]; double nMax = n < b ? n : b - 1; long ans = (long)(a * nMax / b) - (long)a * (long)(nMax / b); Console.WriteLine(ans); } }
[["-", 0, 200, 0, 212, 0, 41, 15, 16, 12, 22], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 12, 22], ["-", 0, 200, 0, 212, 0, 41, 75, 16, 31, 22], ["+", 0, 200, 0, 212, 0, 41, 75, 16, 31, 22]]
8
141
4
using System; namespace D { class Program { static void Main(string[] args) { var abn = Console.ReadLine().Split(' '); var a = long.Parse(abn[0]); var b = long.Parse(abn[1]); var n = decimal.Parse(abn[2]); var tmp = Math.Clamp(b - 1, 0, n); Console.WriteLine(a * tmp / b); } } }
using System; namespace D { class Program { static void Main(string[] args) { var abn = Console.ReadLine().Split(' '); var a = long.Parse(abn[0]); var b = long.Parse(abn[1]); var n = long.Parse(abn[2]); long tmp = Math.Clamp(b - 1, 0, n); Console.WriteLine(a * tmp / b); } } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
104
4
using System; public class Hello { public static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var a = long.Parse(line[0]); var b = long.Parse(line[1]); var n = long.Parse(line[2]); getAns(a, b, n); } static void getAns(long a, long b, long n) { long x; if (b >= n - 1) x = b - 1; else x = b; var ans = a * (x % b) / b; Console.WriteLine(ans); } }
using System; public class Hello { public static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var a = long.Parse(line[0]); var b = long.Parse(line[1]); var n = long.Parse(line[2]); getAns(a, b, n); } static void getAns(long a, long b, long n) { long x; if (n >= b - 1) x = b - 1; else x = n; var ans = a * (x % b) / b; Console.WriteLine(ans); } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 57, 75, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 57, 75, 1, 0, 11, 12, 22]]
8
143
6
using System; using System.Collections.Generic; using System.Linq; using System.Numerics; using System.Text; using System.Threading; using System.Threading.Tasks; namespace ConsoleApp2 { class Program { static void Main(string[] args) { var ABN = Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray(); var A = ABN[0]; var B = ABN[1]; var N = ABN[2]; long X = N; if (N >= B - 1) { X = N; } Console.WriteLine(A * X / B - A * (X / B)); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Numerics; using System.Text; using System.Threading; using System.Threading.Tasks; namespace ConsoleApp2 { class Program { static void Main(string[] args) { var ABN = Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray(); var A = ABN[0]; var B = ABN[1]; var N = ABN[2]; long X = N; if (N >= B - 1) { X = B - 1; } Console.WriteLine(A * X / B - A * (X / B)); } } }
[["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 12, 203]]
8
147
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder2 { class Program { static void Main(string[] args) { var inputArray = retreiveLongArray(); var inputCount = 3; // 不正な入力は処理しない if (inputArray.Length != inputCount) { Console.WriteLine("invalid input"); return; } long A = inputArray[0]; long B = inputArray[1]; long N = inputArray[2]; // n = i*B + jとする var l = A % B; long maxW = 0; var BB = B * B; if (B >= N) { maxW = N % B; } else { maxW = B - 1; } /* for (long n = 1; n <= N; n++) { var i = n / B; var j = n % B; var w = j % B; if(maxW < w) { maxW = w; } }*/ //答えの出力 var ans = (A * maxW) / B - A * (maxW / B); Console.WriteLine(ans); } /// <summary> /// スペースで区切られた文字列配列の入力を受け取る /// </summary> /// <returns></returns> private static string[] retreiveStringArray() { var inputArray = Console.ReadLine().Split(' '); return inputArray; } /// <summary> /// スペースで区切られた整数配列の入力を受け取る /// </summary> /// <returns></returns> private static long[] retreiveLongArray() { var inputArray = Console.ReadLine().Split(' '); var longArray = inputArray.Select(s => long.Parse(s)); return longArray.ToArray(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder2 { class Program { static void Main(string[] args) { var inputArray = retreiveLongArray(); var inputCount = 3; // 不正な入力は処理しない if (inputArray.Length != inputCount) { Console.WriteLine("invalid input"); return; } long A = inputArray[0]; long B = inputArray[1]; long N = inputArray[2]; // n = i*B + jとする var l = A % B; long maxW = 0; var BB = B * B; if (B > N) { maxW = N % B; } else { maxW = B - 1; } /* for (long n = 1; n <= N; n++) { var i = n / B; var j = n % B; var w = j % B; if(maxW < w) { maxW = w; } }*/ //答えの出力 var ans = (A * maxW) / B - A * (maxW / B); Console.WriteLine(ans); } /// <summary> /// スペースで区切られた文字列配列の入力を受け取る /// </summary> /// <returns></returns> private static string[] retreiveStringArray() { var inputArray = Console.ReadLine().Split(' '); return inputArray; } /// <summary> /// スペースで区切られた整数配列の入力を受け取る /// </summary> /// <returns></returns> private static long[] retreiveLongArray() { var inputArray = Console.ReadLine().Split(' '); var longArray = inputArray.Select(s => long.Parse(s)); return longArray.ToArray(); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47]]
8
262
2
using System; using System.Numerics; using System.Linq; using System.Collections.Generic; using System.Text; namespace debug { // 2つを関連付けてソートする例 class ProgramA { static void Main(string[] args) { string[] z = Console.ReadLine().Split(' '); long a = long.Parse(z[0]); long b = long.Parse(z[1]); long n = long.Parse(z[2]); long temp = Math.Max(b - 1, n) / b; Console.WriteLine(a * Math.Max(b - 1, n) / b - a * temp); } } }
using System; using System.Numerics; using System.Linq; using System.Collections.Generic; using System.Text; namespace debug { // 2つを関連付けてソートする例 class ProgramA { static void Main(string[] args) { string[] z = Console.ReadLine().Split(' '); long a = long.Parse(z[0]); long b = long.Parse(z[1]); long n = long.Parse(z[2]); long temp = Math.Min(b - 1, n) / b; Console.WriteLine(a * Math.Min(b - 1, n) / b - a * temp); } } }
[["-", 0, 212, 0, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 212, 0, 16, 31, 213, 63, 214, 141, 22], ["-", 31, 16, 31, 16, 12, 213, 63, 214, 141, 22], ["+", 31, 16, 31, 16, 12, 213, 63, 214, 141, 22]]
8
142
4
using System; using System.Collections.Generic; namespace abc165 { class Program { static void Main() { var nmq = Console.ReadLine().Split(' '); var a = long.Parse(nmq[0]); var b = long.Parse(nmq[1]); var n = long.Parse(nmq[2]); if (n > b) { Console.WriteLine((a * (b - 1)) / b); } else { Console.WriteLine((a * n) / b); } } } }
using System; using System.Collections.Generic; namespace abc165 { class Program { static void Main() { var nmq = Console.ReadLine().Split(' '); var a = long.Parse(nmq[0]); var b = long.Parse(nmq[1]); var n = long.Parse(nmq[2]); if (n >= b) { Console.WriteLine((a * (b - 1)) / b); } else { Console.WriteLine((a * n) / b); } } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20]]
8
121
2
using System; using System.Linq; class Program { static void Main() { long[] N = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray(); long ans = 0; long x = N[2]; if (N[2] > N[1]) { x = N[1] - 1; } ans = N[0] * x / N[1]; Console.WriteLine(ans); } }
using System; using System.Linq; class Program { static void Main() { long[] N = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray(); long ans = 0; long x = N[2]; if (N[2] >= N[1]) { x = N[1] - 1; } ans = N[0] * x / N[1]; Console.WriteLine(ans); } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20]]
8
110
2
using System; using System.Linq; using System.Collections; using System.Collections.Generic; namespace Main { class Program { static void Main(string[] args) { //ここから // string[] str = Console.ReadLine().Split(' '); // int n = int.Parse(Console.ReadLine()); string[] str = Console.ReadLine().Split(' '); var a = long.Parse(str[0]); var b = long.Parse(str[1]); var n = long.Parse(str[2]); long mae = a * n / b; long usiro = n / b; long max = mae - a * usiro; if (b < n) { max = Max(max, a * (b - 1) / b); } /*for (long i = 1; i < n; i++) { mae = a * i / b; usiro = i / b; long temp = mae-a*usiro; Console.WriteLine("{0} notoki {1}", i, temp); max = Max(temp, max); if (i > b) break; }*/ Console.WriteLine(max); //ここまで } static long Max(long a, long b) { if (a > b) return a; else return b; } } }
using System; using System.Linq; using System.Collections; using System.Collections.Generic; namespace Main { class Program { static void Main(string[] args) { //ここから // string[] str = Console.ReadLine().Split(' '); // int n = int.Parse(Console.ReadLine()); string[] str = Console.ReadLine().Split(' '); var a = long.Parse(str[0]); var b = long.Parse(str[1]); var n = long.Parse(str[2]); long mae = a * n / b; long usiro = n / b; long max = mae - a * usiro; if (b <= n) { max = Max(max, a * (b - 1) / b); } /*for (long i = 1; i < n; i++) { mae = a * i / b; usiro = i / b; long temp = mae-a*usiro; Console.WriteLine("{0} notoki {1}", i, temp); max = Max(temp, max); if (i > b) break; }*/ Console.WriteLine(max); //ここまで } static long Max(long a, long b) { if (a > b) return a; else return b; } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19]]
8
183
2
using System; using System.Linq; namespace AtCoder { class Program { static void Main() { int[] abn = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int a = abn[0], b = abn[1], n = abn[2]; int x = b - 1 <= n ? b - 1 : x = n; Console.WriteLine(a * x / b - a * (x / b)); } } }
using System; using System.Linq; namespace AtCoder { class Program { static void Main() { long[] abn = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); long a = abn[0], b = abn[1], n = abn[2]; long x = b - 1 <= n ? b - 1 : x = n; Console.WriteLine(a * x / b - a * (x / b)); } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
110
8
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Diagnostics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Numerics; using System.IO; using System.Runtime.InteropServices; using static System.Math; using static Math2; using static io; using static Utils; public class CompetitiveProgramming { public void Solve() { var (A, B, N) = Cin<long, long, long>(); long ma = -INF; for (long i = N; i >= Max(0, N - 100000); --i) { ma = Max(ma, (A * i) / B - (i / B) * A); } for (long i = B; i >= Max(0, B - 100000); --i) { ma = Max(ma, (A * i) / B - (i / B) * A); } for (int i = 0; i <= Min(N, 100000); ++i) { ma = Max(ma, (A * i) / B - A * (i / B)); } Write(ma); } } public static class Math2 { public const int INF = 1 << 29; public const long INFL = 1L << 60; public const long MOD = 1000000007; public const int MOD2 = 998244353; public static long Power(long a, long b, long MOD = 1000000007) // i^N { long res = 1; while (b > 0) { if ((b & 1) != 0) res = res * a % MOD; a = a * a % MOD; b >>= 1; } return res; } public static long Power2(long a, long b) // i^N { long res = 1; while (b > 0) { if ((b & 1) != 0) res = res * a; a = a * a; b >>= 1; } return res; } public static long GCD(long a, long b) { if (a < b) return GCD(b, a); while (b != 0) { var r = a % b; a = b; b = r; } return a; } public static long LCM(long a, long b) => (b / GCD(a, b)) * a; public static long Comb(long n, long r, int MOD = 1000000007) { long ret = 1; long x = 1; for (long i = n; i >= n - r + 1; --i) { ret = ret / x * i; ret %= MOD; x++; } return ret; } public static long Comb2(long n, long r) { long Nume = 1; long Deno = 1; if (r > n - r) r = n - r; for (long i = 1; i <= r; ++i) { Deno *= i; Nume *= n - i + 1; } return Nume / Deno; } } public static class Utils { public static void Swap<T>(ref T A, ref T B) { T x = A; A = B; B = x; } public static int DigitSum(string N) { int ret = 0; for (int i = 0; i < N.Length; ++i) ret += N[i] - '0'; return ret; } } class Program { static void Main(string[] args) { var CompetitiveProgramming = new CompetitiveProgramming(); CompetitiveProgramming.Solve(); } } public static class io { public static string Str => Console.ReadLine(); public static string[] Strs => Str.Split(' '); public static long[] Longs => Strs.Select(long.Parse).ToArray(); public static int[] Ints => Strs.Select(int.Parse).ToArray(); public static char[] Chars => Str.ToArray(); public static double[] Doubles => Strs.Select(double.Parse).ToArray(); public static long Long1 => Longs[0]; public static int Int1 => Ints[0]; public static char Char1 => Chars[0]; public static double Double1 => Doubles[0]; public static long[] VerticalRead(int N) { long[] A = new long[N]; for (int i = 0; i < N; ++i) A[i] = Long1; return A; } public static void Write(string a) => Console.WriteLine(a); public static void Write(params object[] i) => Write(string.Join(" ", i)); public static void Write<T>(IEnumerable<T> a) => Write(string.Join(" ", a)); public static void Verticalwrite<T>(IEnumerable<T> a) { foreach (var z in a) Write(z); } public static void YN(bool i) { if (i) Write("Yes"); else Write("No"); } public static bool IsTypeEqual<T, U>() => typeof(T).Equals(typeof(U)); public static T ConvertType<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); public static T Cast<T>(string s) { if (IsTypeEqual<T, int>()) return ConvertType<T, int>(int.Parse(s)); else if (IsTypeEqual<T, long>()) return ConvertType<T, long>(long.Parse(s)); else if (IsTypeEqual<T, double>()) return ConvertType<T, double>(double.Parse(s)); else if (IsTypeEqual<T, char>()) return ConvertType<T, char>(char.Parse(s)); else return ConvertType<T, string>(s); } public static T Cin<T>() { var t = Strs; return (Cast<T>(t[0])); } public static (T, U) Cin<T, U>() { var t = Strs; return (Cast<T>(t[0]), Cast<U>(t[1])); } public static (T, U, V) Cin<T, U, V>() { var t = Strs; return (Cast<T>(t[0]), Cast<U>(t[1]), Cast<V>(t[2])); } public static (T, U, V, W) Cin<T, U, V, W>() { var t = Strs; return (Cast<T>(t[0]), Cast<U>(t[1]), Cast<V>(t[2]), Cast<W>(t[3])); } public static (T, U, V, W, X) Cin<T, U, V, W, X>() { var t = Strs; return (Cast<T>(t[0]), Cast<U>(t[1]), Cast<V>(t[2]), Cast<W>(t[3]), Cast<X>(t[4])); } public static (T, U, V, W, X, Y) Cin<T, U, V, W, X, Y>() { var t = Strs; return (Cast<T>(t[0]), Cast<U>(t[1]), Cast<V>(t[2]), Cast<W>(t[3]), Cast<X>(t[4]), Cast<Y>(t[5])); } public static (T, U, V, W, X, Y, Z) Cin<T, U, V, W, X, Y, Z>() { var t = Strs; return (Cast<T>(t[0]), Cast<U>(t[1]), Cast<V>(t[2]), Cast<W>(t[3]), Cast<X>(t[4]), Cast<Y>(t[5]), Cast<Z>(t[6])); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Diagnostics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Numerics; using System.IO; using System.Runtime.InteropServices; using static System.Math; using static Math2; using static io; using static Utils; public class CompetitiveProgramming { public void Solve() { var (A, B, N) = Cin<long, long, long>(); long ma = -INF; for (long i = N; i >= Max(0, N - 100000); --i) { ma = Max(ma, (A * i) / B - (i / B) * A); } for (long i = Min(N, B); i >= Max(0, B - 100000); --i) { ma = Max(ma, (A * i) / B - (i / B) * A); } for (int i = 0; i <= Min(N, 100000); ++i) { ma = Max(ma, (A * i) / B - A * (i / B)); } Write(ma); } } public static class Math2 { public const int INF = 1 << 29; public const long INFL = 1L << 60; public const long MOD = 1000000007; public const int MOD2 = 998244353; public static long Power(long a, long b, long MOD = 1000000007) // i^N { long res = 1; while (b > 0) { if ((b & 1) != 0) res = res * a % MOD; a = a * a % MOD; b >>= 1; } return res; } public static long Power2(long a, long b) // i^N { long res = 1; while (b > 0) { if ((b & 1) != 0) res = res * a; a = a * a; b >>= 1; } return res; } public static long GCD(long a, long b) { if (a < b) return GCD(b, a); while (b != 0) { var r = a % b; a = b; b = r; } return a; } public static long LCM(long a, long b) => (b / GCD(a, b)) * a; public static long Comb(long n, long r, int MOD = 1000000007) { long ret = 1; long x = 1; for (long i = n; i >= n - r + 1; --i) { ret = ret / x * i; ret %= MOD; x++; } return ret; } public static long Comb2(long n, long r) { long Nume = 1; long Deno = 1; if (r > n - r) r = n - r; for (long i = 1; i <= r; ++i) { Deno *= i; Nume *= n - i + 1; } return Nume / Deno; } } public static class Utils { public static void Swap<T>(ref T A, ref T B) { T x = A; A = B; B = x; } public static int DigitSum(string N) { int ret = 0; for (int i = 0; i < N.Length; ++i) ret += N[i] - '0'; return ret; } } class Program { static void Main(string[] args) { var CompetitiveProgramming = new CompetitiveProgramming(); CompetitiveProgramming.Solve(); } } public static class io { public static string Str => Console.ReadLine(); public static string[] Strs => Str.Split(' '); public static long[] Longs => Strs.Select(long.Parse).ToArray(); public static int[] Ints => Strs.Select(int.Parse).ToArray(); public static char[] Chars => Str.ToArray(); public static double[] Doubles => Strs.Select(double.Parse).ToArray(); public static long Long1 => Longs[0]; public static int Int1 => Ints[0]; public static char Char1 => Chars[0]; public static double Double1 => Doubles[0]; public static long[] VerticalRead(int N) { long[] A = new long[N]; for (int i = 0; i < N; ++i) A[i] = Long1; return A; } public static void Write(string a) => Console.WriteLine(a); public static void Write(params object[] i) => Write(string.Join(" ", i)); public static void Write<T>(IEnumerable<T> a) => Write(string.Join(" ", a)); public static void Verticalwrite<T>(IEnumerable<T> a) { foreach (var z in a) Write(z); } public static void YN(bool i) { if (i) Write("Yes"); else Write("No"); } public static bool IsTypeEqual<T, U>() => typeof(T).Equals(typeof(U)); public static T ConvertType<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); public static T Cast<T>(string s) { if (IsTypeEqual<T, int>()) return ConvertType<T, int>(int.Parse(s)); else if (IsTypeEqual<T, long>()) return ConvertType<T, long>(long.Parse(s)); else if (IsTypeEqual<T, double>()) return ConvertType<T, double>(double.Parse(s)); else if (IsTypeEqual<T, char>()) return ConvertType<T, char>(char.Parse(s)); else return ConvertType<T, string>(s); } public static T Cin<T>() { var t = Strs; return (Cast<T>(t[0])); } public static (T, U) Cin<T, U>() { var t = Strs; return (Cast<T>(t[0]), Cast<U>(t[1])); } public static (T, U, V) Cin<T, U, V>() { var t = Strs; return (Cast<T>(t[0]), Cast<U>(t[1]), Cast<V>(t[2])); } public static (T, U, V, W) Cin<T, U, V, W>() { var t = Strs; return (Cast<T>(t[0]), Cast<U>(t[1]), Cast<V>(t[2]), Cast<W>(t[3])); } public static (T, U, V, W, X) Cin<T, U, V, W, X>() { var t = Strs; return (Cast<T>(t[0]), Cast<U>(t[1]), Cast<V>(t[2]), Cast<W>(t[3]), Cast<X>(t[4])); } public static (T, U, V, W, X, Y) Cin<T, U, V, W, X, Y>() { var t = Strs; return (Cast<T>(t[0]), Cast<U>(t[1]), Cast<V>(t[2]), Cast<W>(t[3]), Cast<X>(t[4]), Cast<Y>(t[5])); } public static (T, U, V, W, X, Y, Z) Cin<T, U, V, W, X, Y, Z>() { var t = Strs; return (Cast<T>(t[0]), Cast<U>(t[1]), Cast<V>(t[2]), Cast<W>(t[3]), Cast<X>(t[4]), Cast<Y>(t[5]), Cast<Z>(t[6])); } }
[["+", 10, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25]]
8
1,790
5
using System; using System.Collections.Generic; using System.Linq; class D { static void Main() { #if DEBUG string exampleInput = @"5 7 4 "; Console.SetIn(new System.IO.StringReader(exampleInput)); #endif var ABN = Console.ReadLine().Split(' ').Select(long.Parse).ToList(); var A = ABN[0]; var B = ABN[1]; var N = ABN[2]; var rmax = A * N / B + A * (N / B); if (N >= B) { var kmax = (N + 1) / B; for (long k = kmax; k >= Math.Max(1, kmax - 10000); k--) { var x = k * B - 1; var r = A * x / B + A * (x / B); rmax = Math.Max(rmax, r); } Console.WriteLine(rmax); } Console.Out.Flush(); } }
using System; using System.Collections.Generic; using System.Linq; class D { static void Main() { #if DEBUG string exampleInput = @"50000 700000 40000000000 "; Console.SetIn(new System.IO.StringReader(exampleInput)); #endif var ABN = Console.ReadLine().Split(' ').Select(long.Parse).ToList(); var A = ABN[0]; var B = ABN[1]; var N = ABN[2]; var rmax = A * N / B - A * (N / B); if (N >= B) { var kmax = (N + 1) / B; for (long k = kmax; k >= Math.Max(1, kmax - 10000); k--) { var x = k * B - 1; var r = A * x / B - A * (x / B); rmax = Math.Max(rmax, r); } } Console.WriteLine(rmax); Console.Out.Flush(); } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 258], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 258], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
215
8
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Text; class Program { static void Main(string[] args) { // 入力 // var s = Console.ReadLine(); // var n = int.Parse(Console.ReadLine()); decimal[] abn = Console.ReadLine().Split().Select(decimal.Parse).ToArray(); var a = abn[0]; var b = abn[1]; var n = abn[2]; decimal ans = 0; if (b >= n) { ans = Math.Floor((a * n) / b) - a * Math.Floor(n / b); } else { ans = Math.Floor((a * (b - 1) / b)) - a * Math.Floor((b - 1) / b); } // 出力 Console.WriteLine(ans); } }
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Text; class Program { static void Main(string[] args) { // 入力 // var s = Console.ReadLine(); // var n = int.Parse(Console.ReadLine()); decimal[] abn = Console.ReadLine().Split().Select(decimal.Parse).ToArray(); var a = abn[0]; var b = abn[1]; var n = abn[2]; decimal ans = 0; if (b > n) { ans = Math.Floor((a * n) / b) - a * Math.Floor(n / b); } else { ans = Math.Floor((a * (b - 1) / b)) - a * Math.Floor((b - 1) / b); } // 出力 Console.WriteLine(ans); } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47]]
8
177
2
using System; namespace D { class Program { static void Main(string[] args) { var ABN = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); var A = ABN[0]; var B = ABN[1]; var N = ABN[2]; if (B - 1 <= N) Console.WriteLine(calc(B - 1, A, B)); else Console.WriteLine(calc(N, A, B)); } static long calc(long x, long A, long B) { return ((A * x) / B) - A * (x / B); } } }
using System; namespace D { class Program { static void Main(string[] args) { var ABN = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); var A = ABN[0]; var B = ABN[1]; var N = ABN[2]; if (B - 1 <= N) Console.WriteLine(calc(B - 1, A, B)); else Console.WriteLine(calc(N, A, B)); } static long calc(long x, long A, long B) { return ((A * x) / B) - A * (x / B); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 205, 199]]
8
144
2
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Threading.Tasks; using System.Globalization; using System.Collections; namespace Atcoder { public class CPair<T, U> : IComparable where T : IComparable<T> { public readonly T Item1; public readonly U Item2; public int CompareTo(object obj) { CPair<T, U> castedObj = (CPair<T, U>)obj; return this.Item1.CompareTo(castedObj.Item1); } public CPair(T t, U u) { Item1 = t; Item2 = u; } } class Pair : IComparable { public int x; public int y; public int z; public Pair(int X, int Y, int Z) { x = X; y = Y; z = Z; } public int CompareTo(object obj) { Pair kore = (Pair)obj; return x.CompareTo(kore.x); } public static bool operator <=(Pair p1, Pair p2) { if (p1.x != p2.x) { return p1.x <= p2.x; } else { return p1.y <= p2.y; } } public static bool operator >=(Pair p1, Pair p2) { if (p1.x != p2.x) { return p1.x >= p2.x; } else { return p1.y >= p2.y; } } } class Program { static bool[] visited; static List<int>[] togo; static void Main(string[] args) { long mod = 1000000007; StreamScanner scan = new StreamScanner(System.Console.OpenStandardInput()); long a = scan.Long(); long b = scan.Long(); long n = scan.Long(); Console.WriteLine((a * Math.Min(n, b)) / b); } static bool DFS(int now, int last) { visited[now] = true; for (int i = 0; i < togo[now].Count; i++) { if (togo[now][i] == last) { continue; } if (visited[togo[now][i]]) { return false; } if (!DFS(togo[now][i], now)) { return false; } } return true; } static int binary_search<T>(T key, T[] moto, Func<int, T, T[], bool> isok) { int ng = -1; int ok = moto.Length; while (Math.Abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (isok(mid, key, moto)) { ok = mid; } else { ng = mid; } } return ok; } static int binary_search(int key, int[] moto) { int ng = -1; int ok = moto.Length; while (Math.Abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (isOK(mid, key, moto)) { ok = mid; } else { ng = mid; } } return ok; } static int[] Togo; static bool CheckBipartite(int now, int prev, List<int>[] g, int c = 0) // 0,-1が想定 { if (Togo == null) Togo = Enumerable.Repeat(-1, g.Length).ToArray(); foreach (var next in g[now]) { if (next == prev) continue; var nextc = Togo[next]; if (nextc >= 0 && nextc == c) return false; if (nextc >= 0) continue; Togo[next] = (c + 1) % 2; var res = CheckBipartite(next, now, g, (c + 1) % 2); if (res == false) return false; } return true; } static bool isOK(int index, int key, int[] moto) { return moto[index] > key; } public static int bitCount(int k) { uint i = (uint)k; i = i - ((i >> 1) & 0x55555555); i = (i & 0x33333333) + ((i >> 2) & 0x33333333); i = (i + (i >> 4)) & 0x0f0f0f0f; i = i + (i >> 8); i = i + (i >> 16); return (int)i & 0x3f; } static int check(long moto, long tai) { if (tai % moto != 0) { return 0; } while (tai > 1) { if (tai % moto == 0) { tai /= moto; } else if (tai > moto) { tai %= moto; } else { tai -= moto; } } if (tai == 1) { return 1; } else { return 0; } } static bool NextPermutation(int[] array) { var size = array.Length; var ok = false; // array[i]<array[i+1]を満たす最大のiを求める int i = size - 2; for (; 0 <= i; i--) { if (array[i] < array[i + 1]) { ok = true; break; } } //全ての要素が降順の場合、NextPermutationは存在しない if (ok == false) return false; // array[i]<array[j]を満たす最大のjを求める int j = size - 1; for (;; j--) { if (array[i] < array[j]) break; } // iとjの要素をswapする var tmp = array[i]; array[i] = array[j]; array[j] = tmp; // i以降の要素を反転させる Array.Reverse(array, i + 1, size - (i + 1)); return true; } static List<int[]> GetAllPermutation(int N) { var res = new List<int[]>(); var array = Enumerable.Range(0, N).ToArray(); do { var copy = new int[N]; array.CopyTo(copy, 0); res.Add(copy); } while (NextPermutation(array)); return res; } static List<int[]> GetAllPermutation(int[] array) { var size = array.Length; var res = new List<int[]>(); do { var copy = new int[size]; array.CopyTo(copy, 0); res.Add(copy); } while (NextPermutation(array)); return res; } static long Syakutori( int[] a, long k) //しゃくとり法モデル:連続部分列に含まれるすべての要素の値の和がK以上 { long sum = 0; int right = 0; long ans = 0; for (int left = 0; left < a.Length; left++) { while (right < a.Length && sum < k) { sum += a[right]; right++; } if (k <= sum) { ans += a.Length - right + 1; } if (left == right) { right++; } else { sum -= a[left]; } } return ans; } static int[] zalgo(String s) { int n = s.Length; int[] ret = new int[n]; ret[0] = n; int i = 1, j = 0; while (i < n) { while (i + j < n && s[j] == s[i + j]) ++j; ret[i] = j; if (j == 0) { ++i; continue; } int k = 1; while (i + k < n && k + ret[k] < j) { ret[i + k] = ret[k]; ++k; } i += k; j -= k; } return ret; } static int gcd(int a, int b) { if (a % b == 0) { return b; } return gcd(b, a % b); } static long gcd(long a, long b) { if (a % b == 0) { return b; } return gcd(b, a % b); } public static List<long> factorialMemo = new List<long>() { 1 }; static long Fact(int x) { for (int i = factorialMemo.Count; i <= x; i++) factorialMemo.Add(factorialMemo.Last() * i); return factorialMemo[x]; } static int[] yousogotoplus(int[] a, int[] b) { int[] c = new int[a.Length]; for (int i = 0; i < a.Length; i++) { c[i] = a[i] + b[i]; } return c; } static int[] yousogotoplus(int[] a, int[,] b, int l) { int[] c = new int[a.Length]; for (int i = 0; i < a.Length; i++) { c[i] = a[i] + b[l, i]; } return c; } static int[] yousogotoplus(int[,] a, int l) { int[] c = new int[a.GetLength(1)]; for (int i = 0; i < a.GetLength(1); i++) { c[i] = a[l, i]; } return c; } public static long LowerBound(long[] a, long key) { long l = 0; long r = a.Length; long mid; while (l < r) { mid = ((r - l) / 2) + l; if (a[mid] <= key) l = mid + 1; else r = mid; } return l; } public static long LIS(long[] a) { var dp = Enumerable.Range(0, a.Length).Select(x => long.MaxValue).ToArray(); for (int i = 0; i < a.Length; i++) { dp[LowerBound(dp, a[i])] = a[i]; } return LowerBound(dp, long.MaxValue - 1); } static long DivideWith(long m, long n, List<long> primes) { while (m % n == 0) { primes.Add(n); m = m / n; } return m; } static List<CPair<long, long>> SoinsuBunkai(long num) { List<CPair<long, long>> primes = new List<CPair<long, long>>(); List<long> yakusu = new List<long>(); List<long> yakusu2 = new List<long>(); for (int i = 2; i * i <= num; i++) { if (num % i != 0) { continue; } yakusu.Add(i); if (i * i != num) { yakusu2.Add(num / i); } } for (int i = 0; i < yakusu.Count; i++) { if (num % yakusu[i] != 0) { continue; } int j = 0; for (j = 0; num % yakusu[i] == 0; j++) { num /= yakusu[i]; } primes.Add(new CPair<long, long>(yakusu[i], j)); } for (int i = yakusu2.Count - 1; i > 0; i--) { if (num % yakusu2[i] != 0) { continue; } int j = 0; for (j = 0; num % yakusu2[i] == 0; j++) { num /= yakusu2[i]; } primes.Add(new CPair<long, long>(yakusu2[i], j)); } return primes; } static IEnumerable<int> Primes(int maxnum) { // var sieve = new BitArray(maxnum + 1, true); bool[] sieve = Enumerable.Repeat(true, maxnum + 1).ToArray(); int squareroot = (int)Math.Sqrt(maxnum); for (int i = 2; i <= squareroot; i++) { if (sieve[i] == false) continue; for (int n = i * 2; n <= maxnum; n += i) sieve[n] = false; } for (int i = 2; i <= maxnum; i++) if (sieve[i] == true) yield return i; } /* static long[] SoinsuBunkai(long num) { if (num == 1) return new long[] { 1 }; List<long> primes = new List<long>(); long n = DivideWith(num, 2, primes); n = DivideWith(n, 3, primes); n = DivideWith(n, 5, primes); long i = 0; while (n > 1) { int[] ps = { 7, 11, 13, 17, 19, 23, 29, 31 }; foreach (var p in ps) { // 30m+2, 30m+3, 30m+4, 30m+5, 30m+6、30m+8... は割る必要はない。 n = DivideWith(n, i + p, primes); if (n == 1) break; } i += 30; } return primes.ToArray(); }*/ public static int h; public static int w; public static int BFS(int height, int width, char[,] map) { int[] dx = new int[] { -1, 0, 0, 1 }; int[] dy = new int[] { 0, 1, -1, 0 }; bool[,] visited = new bool[h, w]; int[,] len = new int[h, w]; var queue = new Queue<Tuple<int, int>>(); queue.Enqueue(new Tuple<int, int>(height, width)); int max = 0; visited[height, width] = true; while (queue.Count > 0) { var now = queue.Dequeue(); for (int i = 0; i < 4; i++) { int ny = now.Item1 + dy[i]; int nx = now.Item2 + dx[i]; if (ny >= h || ny < 0 || nx >= w || nx < 0) continue; if (visited[ny, nx] || map[ny, nx] == '#') continue; visited[ny, nx] = true; len[ny, nx] = len[now.Item1, now.Item2] + 1; max = Math.Max(max, len[ny, nx]); queue.Enqueue(new Tuple<int, int>(ny, nx)); } } return max; } static public List<int> Topological_Sort(List<List<Edge>> G) { var ret = new List<int>(); var Nodes = new Queue<int>(); int N = G.Count(); var Link = new int[N]; for (var i = 0; i < N; i++) { Link[i] = 0; } for (var i = 0; i < N; i++) { foreach (var nx in G[i]) { Link[nx.to]++; } } for (var i = 0; i < N; i++) { if (Link[i] == 0) { Nodes.Enqueue(i); } } while (Nodes.Any()) { var nd = Nodes.Dequeue(); ret.Add(nd); foreach (var nx in G[nd]) { Link[nx.to]--; if (Link[nx.to] == 0) { Nodes.Enqueue(nx.to); } } } return ret; } static public bool Bit(long x, int dig) => ((1L << dig) & x) != 0; static public void Swap<T>(ref T a, ref T b) { T keep = a; a = b; b = keep; } static public void Initialize<T>(ref T[] array, T initialvalue) { array = Array.ConvertAll(array, x => initialvalue); } } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } private readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) throw new EndOfStreamException(); if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; } public char[] Char(int n) { char[] kore = new char[n]; for (int i = 0; i < n; i++) { kore[i] = Char(); } return kore; } public char[,] Char(int n, int m) { char[,] kore = new char[n, m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { kore[i, j] = Char(); } } return kore; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public long Long() { long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != '-' && (b < '0' || '9' < b)); if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } public long[] Long(long n) { long[] kore = new long[n]; for (int i = 0; i < n; i++) { kore[i] = Long(); } return kore; } public Mlong[] MLong(long n) { Mlong[] kore = new Mlong[n]; for (int i = 0; i < n; i++) { kore[i] = Long(); } return kore; } public long[,] Long(long h, long w) { long[,] kore = new long[h, w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { kore[i, j] = Long(); } } return kore; } public int Integer() { return (int)Long(); } public Mint[] MInteger(long n) { Mint[] kore = new Mint[n]; for (int i = 0; i < n; i++) { kore[i] = Integer(); } return kore; } public int[] Integer(long n) { int[] kore = new int[n]; for (int i = 0; i < n; i++) { kore[i] = (int)Long(); } return kore; } public int[,] Integer(long h, long w) { int[,] kore = new int[h, w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { kore[i, j] = (int)Long(); } } return kore; } public int[] StringToInt(int n) { char[] s = Scan().ToCharArray(); int[] kore = new int[n]; for (int i = 0; i < n; i++) { kore[i] = s[i] - '0'; } return kore; } public int[,] StringToInt(int h, int w) { int[,] kore = new int[h, w]; for (int i = 0; i < h; i++) { char[] s = Scan().ToCharArray(); for (int j = 0; j < w; j++) { kore[i, j] = s[j] - '0'; } } return kore; } public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); } } public class UnionFind { public int[] data; public UnionFind(int size) { data = new int[size]; for (int i = 0; i < size; i++) data[i] = -1; } public bool Unite(int x, int y) { x = Root(x); y = Root(y); if (x != y) { if (data[y] < data[x]) { var tmp = y; y = x; x = tmp; } data[x] += data[y]; data[y] = x; } return x != y; } public bool IsSameGroup(int x, int y) { return Root(x) == Root(y); } public int Root(int x) { return data[x] < 0 ? x : data[x] = Root(data[x]); } } public class Mlong : IComparable { private static long mod = 1000000007; public long num; public Mlong(long num) { this.num = num; } public override int GetHashCode() { return num.GetHashCode(); } public override bool Equals(object obj) { return num.Equals(obj); } public static Mlong operator +(Mlong x, Mlong y) { return new Mlong((x.num + y.num) % mod); } public static Mlong operator -(Mlong x, Mlong y) { return new Mlong((x.num - y.num + mod) % mod); } public static Mlong operator *(Mlong x, Mlong y) { return new Mlong((long)(((1L * x.num) * y.num) % mod)); } public Mlong hutujyo(Mlong x) { return new Mlong(num / x.num); } static long GetInverse(long a) { long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1; while (true) { if (p == 1) return x2 + mod; div = a / p; x1 -= x2 * div; y1 -= y2 * div; a %= p; if (a == 1) return x1 + mod; div = p / a; x2 -= x1 * div; y2 -= y1 * div; p %= a; } } public Mlong modjyo(Mlong x) { return num * GetInverse(x.num) % mod; } public static implicit operator Mlong(long x) { return new Mlong(x); } public static Mlong operator %(Mlong x, Mlong y) { return new Mlong(x.num % y.num); } public static explicit operator long(Mlong x) { return x.num; } public static bool operator ==(Mlong x, Mlong y) { return x.num == y.num; } public static bool operator !=(Mlong x, Mlong y) { return x.num != y.num; } public static bool operator<(Mlong x, Mlong y) { return x.num < y.num; } public static bool operator>(Mlong x, Mlong y) { return x.num > y.num; } public static bool operator <=(Mlong x, Mlong y) { return x.num <= y.num; } public static bool operator >=(Mlong x, Mlong y) { return x.num >= y.num; } public Mlong Pow(Mlong n) { Mlong pow = this; Mlong res = 1; while (n > 0) { if (n % 2 == 1) { res *= pow; } pow *= pow; n.hutujyo(2); } /* if (n == 1) { return this % mod; } if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; } Mint buf = Pow(n.hutujyo(2)); return (buf * buf) % mod;*/ return res; } public static Mlong Pow(Mlong a, Mlong n) { return a.Pow(n); } public static List<Mlong> factorialMemo = new List<Mlong>() { 1 }; static Mlong Factorial(int x) { for (int i = factorialMemo.Count; i <= x; i++) factorialMemo.Add(factorialMemo.Last() * i); return factorialMemo[x]; } public static Mlong Comb(Mlong n, Mlong a) { Mlong buf1 = 1; Mlong buf2 = 1; for (long i = 0; i < a.num; i++) { buf1 *= n - i; buf2 *= (i + 1); } return buf1.modjyo(buf2); } public static Mlong Comb(int n, int r) { return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r)); } public static void WriteLine(Mlong x) { Console.WriteLine(x.num); } public int CompareTo(object obj) { Mlong kore = (Mlong)obj; return num.CompareTo(kore.num); } } public class Mint : IComparable { public static int mod = 1000000007; public int num; public Mint(int Num) { num = Num; } public override int GetHashCode() { return num.GetHashCode(); } public override bool Equals(object obj) { return num.Equals(obj); } public static Mint operator +(Mint x, Mint y) { return new Mint((x.num + y.num) % mod); } public static Mint operator -(Mint x, Mint y) { return new Mint((x.num - y.num + mod) % mod); } public static Mint operator *(Mint x, Mint y) { return new Mint((int)(((1L * x.num) * y.num) % mod)); } public Mint hutujyo(Mint x) { return new Mint(num / x.num); } static int GetInverse(long a) { long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1; while (true) { if (p == 1) return (int)(x2 + mod); div = a / p; x1 -= x2 * div; y1 -= y2 * div; a %= p; if (a == 1) return (int)(x1 + mod); div = p / a; x2 -= x1 * div; y2 -= y1 * div; p %= a; } } public Mint modjyo(Mint x) { return num * GetInverse(x.num) % mod; } /* public Mint modjyo(Mint x) { return num * x.Pow(mod - 2); }*/ public static implicit operator Mint(int x) { return new Mint(x); } public static Mint[] Toarray(int[] x) { Mint[] buf = new Mint[x.Length]; for (int i = 0; i < x.Length; i++) { buf[i] = x[i]; } return buf; } public static explicit operator int(Mint x) { return x.num; } public static Mint operator %(Mint x, Mint y) { return new Mint(x.num % y.num); } public static bool operator ==(Mint x, Mint y) { return x.num == y.num; } public static bool operator !=(Mint x, Mint y) { return x.num != y.num; } public static bool operator<(Mint x, Mint y) { return x.num < y.num; } public static bool operator>(Mint x, Mint y) { return x.num > y.num; } public static bool operator <=(Mint x, Mint y) { return x.num <= y.num; } public static bool operator >=(Mint x, Mint y) { return x.num >= y.num; } public Mint Pow(Mint n) { Mint pow = this; Mint res = 1; while (n > 0) { if (n % 2 == 1) { res *= pow; } pow *= pow; n.hutujyo(2); } /* if (n == 1) { return this % mod; } if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; } Mint buf = Pow(n.hutujyo(2)); return (buf * buf) % mod;*/ return res; } public static Mint Pow(Mint a, Mint n) { return a.Pow(n); } public static List<Mint> factorialMemo = new List<Mint>() { 1 }; static Mint Factorial(int x) { for (int i = factorialMemo.Count; i <= x; i++) factorialMemo.Add(factorialMemo.Last() * i); return factorialMemo[x]; } public static Mint Comb(int n, int r) { return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r)); } public static void WriteLine(Mint x) { Console.WriteLine(x.num); } public int CompareTo(object obj) { Mint kore = (Mint)obj; return num.CompareTo(kore.num); } } public class PriorityQueue<T> : IEnumerable<T> { private readonly List<T> _data = new List<T>(); private readonly IComparer<T> _comparer; private readonly bool _isDescending; public PriorityQueue(IComparer<T> comparer, bool isDescending = true) { _comparer = comparer; _isDescending = isDescending; } public PriorityQueue(Comparison<T> comparison, bool isDescending = true) : this(Comparer<T>.Create(comparison), isDescending) {} public PriorityQueue(bool isDescending = true) : this(Comparer<T>.Default, isDescending) {} public void Enqueue(T item) { _data.Add(item); var childIndex = _data.Count - 1; while (childIndex > 0) { var parentIndex = (childIndex - 1) / 2; if (Compare(_data[childIndex], _data[parentIndex]) >= 0) break; Swap(childIndex, parentIndex); childIndex = parentIndex; } } public T Dequeue() { var lastIndex = _data.Count - 1; var firstItem = _data[0]; _data[0] = _data[lastIndex]; _data.RemoveAt(lastIndex--); var parentIndex = 0; while (true) { var childIndex = parentIndex * 2 + 1; if (childIndex > lastIndex) break; var rightChild = childIndex + 1; if (rightChild <= lastIndex && Compare(_data[rightChild], _data[childIndex]) < 0) childIndex = rightChild; if (Compare(_data[parentIndex], _data[childIndex]) <= 0) break; Swap(parentIndex, childIndex); parentIndex = childIndex; } return firstItem; } public T Peek() { return _data[0]; } private void Swap(int a, int b) { var tmp = _data[a]; _data[a] = _data[b]; _data[b] = tmp; } private int Compare(T a, T b) { return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b); } public int Count => _data.Count; public IEnumerator<T> GetEnumerator() { return _data.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } public class Tree { public Node[] Nodes; public List<int[]> hen; public class Node { public int? parent = null; public List<int[]> children = new List<int[]>(); public int parentcolor = -1; } public Tree(int kosu) { Nodes = new Node[kosu]; for (int i = 0; i < Nodes.Length; i++) { Nodes[i] = new Node(); } hen = new List<int[]>(); } public void Connect(int oya, int ko, int id) { hen.Add(new int[] { oya, ko, 0 }); Nodes[oya].children.Add(new int[] { ko, id }); Nodes[ko].parent = oya; } } /// <summary> /// Self-Balancing Binary Search Tree /// (using Randamized BST) /// </summary> public class SB_BinarySearchTree<T> where T : IComparable { public class Node { public T Value; public Node LChild; public Node RChild; public int Count; // size of the sub tree public Node(T v) { Value = v; Count = 1; } } static Random _rnd = new Random(); public static int Count(Node t) { return t == null ? 0 : t.Count; } static Node Update(Node t) { t.Count = Count(t.LChild) + Count(t.RChild) + 1; return t; } public static Node Merge(Node l, Node r) { if (l == null || r == null) return l == null ? r : l; if ((double)Count(l) / (double)(Count(l) + Count(r)) > _rnd.NextDouble()) { l.RChild = Merge(l.RChild, r); return Update(l); } else { r.LChild = Merge(l, r.LChild); return Update(r); } } /// <summary> /// split as [0, k), [k, n) /// </summary> public static Tuple<Node, Node> Split(Node t, int k) { if (t == null) return new Tuple<Node, Node>(null, null); if (k <= Count(t.LChild)) { var s = Split(t.LChild, k); t.LChild = s.Item2; return new Tuple<Node, Node>(s.Item1, Update(t)); } else { var s = Split(t.RChild, k - Count(t.LChild) - 1); t.RChild = s.Item1; return new Tuple<Node, Node>(Update(t), s.Item2); } } public static Node Remove(Node t, T v) { if (Find(t, v) == null) return t; return RemoveAt(t, LowerBound(t, v)); } public static Node RemoveAt(Node t, int k) { var s = Split(t, k); var s2 = Split(s.Item2, 1); return Merge(s.Item1, s2.Item2); } public static bool Contains(Node t, T v) { return Find(t, v) != null; } public static Node Find(Node t, T v) { while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp > 0) t = t.LChild; else if (cmp < 0) t = t.RChild; else break; } return t; } public static Node FindByIndex(Node t, int idx) { if (t == null) return null; var currentIdx = Count(t) - Count(t.RChild) - 1; while (t != null) { if (currentIdx == idx) return t; if (currentIdx > idx) { t = t.LChild; currentIdx -= (Count(t == null ? null : t.RChild) + 1); } else { t = t.RChild; currentIdx += (Count(t == null ? null : t.LChild) + 1); } } return null; } public static int UpperBound(Node t, T v) { var torg = t; if (t == null) return -1; var ret = Int32.MaxValue; var idx = Count(t) - Count(t.RChild) - 1; while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp > 0) { ret = Math.Min(ret, idx); t = t.LChild; idx -= (Count(t == null ? null : t.RChild) + 1); } else if (cmp <= 0) { t = t.RChild; idx += (Count(t == null ? null : t.LChild) + 1); } } return ret == Int32.MaxValue ? Count(torg) : ret; } public static int LowerBound(Node t, T v) { var torg = t; if (t == null) return -1; var idx = Count(t) - Count(t.RChild) - 1; var ret = Int32.MaxValue; while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp >= 0) { if (cmp == 0) ret = Math.Min(ret, idx); t = t.LChild; if (t == null) ret = Math.Min(ret, idx); idx -= t == null ? 0 : (Count(t.RChild) + 1); } else if (cmp < 0) { t = t.RChild; idx += (Count(t == null ? null : t.LChild) + 1); if (t == null) return idx; } } // return ret; return ret == Int32.MaxValue ? Count(torg) : ret; } public static Node Insert(Node t, T v) { var ub = LowerBound(t, v); return InsertByIdx(t, ub, v); } static Node InsertByIdx(Node t, int k, T v) { var s = Split(t, k); return Merge(Merge(s.Item1, new Node(v)), s.Item2); } public static IEnumerable<T> Enumerate(Node t) { var ret = new List<T>(); Enumerate(t, ret); return ret; } static void Enumerate(Node t, List<T> ret) { if (t == null) return; Enumerate(t.LChild, ret); ret.Add(t.Value); Enumerate(t.RChild, ret); } } /// <summary> /// C-like set /// </summary> public class Set<T> where T : IComparable { protected SB_BinarySearchTree<T>.Node _root; public T this[int idx] { get { return ElementAt(idx); } } public int Count() { return SB_BinarySearchTree<T>.Count(_root); } public virtual void Insert(T v) { if (_root == null) _root = new SB_BinarySearchTree<T>.Node(v); else { if (SB_BinarySearchTree<T>.Find(_root, v) != null) return; _root = SB_BinarySearchTree<T>.Insert(_root, v); } } public void Clear() { _root = null; } public void Remove(T v) { _root = SB_BinarySearchTree<T>.Remove(_root, v); } public bool Contains(T v) { return SB_BinarySearchTree<T>.Contains(_root, v); } public T ElementAt(int k) { var node = SB_BinarySearchTree<T>.FindByIndex(_root, k); if (node == null) throw new IndexOutOfRangeException(); return node.Value; } public int Count(T v) { return SB_BinarySearchTree<T>.UpperBound(_root, v) - SB_BinarySearchTree<T>.LowerBound(_root, v); } public int LowerBound(T v) { return SB_BinarySearchTree<T>.LowerBound(_root, v); } public int UpperBound(T v) { return SB_BinarySearchTree<T>.UpperBound(_root, v); } public Tuple<int, int> EqualRange(T v) { if (!Contains(v)) return new Tuple<int, int>(-1, -1); return new Tuple<int, int>(SB_BinarySearchTree<T>.LowerBound(_root, v), SB_BinarySearchTree<T>.UpperBound(_root, v) - 1); } public List<T> ToList() { return new List<T>(SB_BinarySearchTree<T>.Enumerate(_root)); } } /// <summary> /// C-like multiset /// </summary> public class MultiSet<T> : Set<T> where T : IComparable { public override void Insert(T v) { if (_root == null) _root = new SB_BinarySearchTree<T>.Node(v); else _root = SB_BinarySearchTree<T>.Insert(_root, v); } } public class RollingHashSlow { public const long B = (long)1e5 + 7; public const long MOD = (long)1e9 + 7; public string S { get; set; } public int N { get; set; } public long[] Power { get; set; } public long[] Hash { get; set; } public RollingHashSlow(string s) { this.S = s; this.N = s.Length; // B^nを計算しておく this.Power = new long[this.N + 1]; this.Power[0] = 1; for (int i = 0; i < N; i++) { this.Power[i + 1] = (this.Power[i] * B) % MOD; } // ハッシュを前計算する this.Hash = new long[this.N + 1]; for (int i = 0; i < N; i++) { this.Hash[i + 1] = (this.Hash[i] * B + S[i]) % MOD; } } // S[l, r) のハッシュ値を求める public long Get(int l, int r) { var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l] % MOD); if (hash < 0) hash += MOD; return hash; } } class RollingHashFast { public const ulong B = (ulong)1e9 + 7; public string S { get; set; } public int N { get; set; } public ulong[] Power { get; set; } public ulong[] Hash { get; set; } public RollingHashFast(string s) { this.S = s; this.N = s.Length; // B^nを計算しておく this.Power = new ulong[this.N + 1]; this.Power[0] = 1; for (int i = 0; i < N; i++) { this.Power[i + 1] = this.Power[i] * B; } // ハッシュを前計算する this.Hash = new ulong[this.N + 1]; for (int i = 0; i < N; i++) { this.Hash[i + 1] = this.Hash[i] * B + S[i]; } } // [l, r) のハッシュ値を求める public ulong Get(int l, int r) { var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l]); return hash; } } class Segtree<T> { int n; T[] tree; Func<T, T, T> f; T exnum; public Segtree(int m, Func<T, T, T> f, T ex) { this.f = f; this.exnum = ex; n = 1; while (n < m) n <<= 1; tree = new T[(n << 1) - 1]; for (int i = 0; i < tree.Length; i++) tree[i] = ex; } public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) { for (int i = 0; i < m; ++i) tree[i + n - 1] = ini; all_update(); } public void assign_without_update(int j, T x) { tree[j + n - 1] = x; } public void update(int j, T x) { int i = j + n - 1; tree[i] = x; while (i > 0) { i = (i - 1) >> 1; tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]); } } public void all_update() { for (int i = n - 2; i >= 0; i--) tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]); } public T look(int i) { return tree[i + n - 1]; } // [s, t) public T run(int s, int t) { return query(s, t, 0, 0, n); } T query(int s, int t, int k, int l, int r) { if (r <= s || t <= l) return exnum; if (s <= l && r <= t) return tree[k]; return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1), query(s, t, (k + 1) << 1, (l + r) >> 1, r)); } } public class WarshallFloyd { public int V { get; set; } public long[,] DP { get; set; } public long INF = long.MaxValue; public bool[] Negative; public WarshallFloyd(int v) { this.V = v; this.DP = new long[V, V]; for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { this.DP[i, j] = INF; } this.DP[i, i] = 0; } } public void SetCost(int a, int b, int c = 1) { this.DP[a, b] = c; } public long[,] CalcMinCost() { this.Negative = new bool[V]; for (int k = 0; k < V; k++) { for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { if (DP[i, k] == INF || DP[k, j] == INF) continue; DP[i, j] = Math.Min(DP[i, j], DP[i, k] + DP[k, j]); } } } for (int k = 0; k < V; k++) { for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { if (DP[i, k] == INF || DP[k, j] == INF) continue; if (DP[i, j] > DP[i, k] + DP[k, j]) { this.Negative[i] = true; this.Negative[j] = true; this.Negative[k] = true; } } } } return DP; } public long GetMinCost(int a, int b) { return DP[a, b]; } public bool IsINF(int a, int b) { return DP[a, b] >= INF; } public bool IsNegative(params int[] vs) { if (vs.Length == 0) vs = Enumerable.Range(0, V).ToArray(); foreach (var v in vs) { if (Negative[v]) return true; } return false; } } /// <summary> /// Get min cost between two points /// </summary> public class Dijkstra { private int maxIndex = -1; private const int INF = Int32.MaxValue; private int[,] _edgeArray; /// <summary> /// Dijkstra, get min cost between two points /// should not contain negatie cost path /// </summary> /// <param name="size">max index of vertices</param> public Dijkstra(int size) { maxIndex = size + 1; _edgeArray = new int[maxIndex, maxIndex]; for (int i = 0; i < _edgeArray.GetLength(0); i++) { for (int j = 0; j < _edgeArray.GetLength(1); j++) { _edgeArray[i, j] = INF; if (i == j) _edgeArray[i, j] = 0; } } } // Add a path(no direction) with its cost public void AddPath(int s, int t, int cost) { _edgeArray[s, t] = Math.Min(_edgeArray[s, t], cost); _edgeArray[t, s] = _edgeArray[s, t]; } // Get the min cost between s and t // return Int32.MaxValue if no path public int GetMinCost(int s, int t) { int[] cost = new int[maxIndex]; for (int i = 0; i < cost.Length; i++) cost[i] = INF; cost[s] = 0; var priorityQueue = new PriorityQueue<CPair<int, int>>(); priorityQueue.Enqueue(new CPair<int, int>(0, s)); while (priorityQueue.Count() > 0) { var costDestinationPair = priorityQueue.Dequeue(); if (cost[costDestinationPair.Item2] < costDestinationPair.Item1) continue; for (int i = 0; i < maxIndex; i++) { int newCostToi = _edgeArray[costDestinationPair.Item2, i] == INF ? INF : costDestinationPair.Item1 + _edgeArray[costDestinationPair.Item2, i]; if (newCostToi < cost[i]) { cost[i] = newCostToi; priorityQueue.Enqueue(new CPair<int, int>(newCostToi, i)); } } } return cost[t]; } } class Deque<T> : IEnumerable<T> { public T this[int i] { get { return this.Buffer[(this.FirstIndex + i) % this.Capacity]; } set { if (i < 0) throw new ArgumentOutOfRangeException(); this.Buffer[(this.FirstIndex + i) % this.Capacity] = value; } } private T[] Buffer; private int Capacity; private int FirstIndex; private int LastIndex { get { return (this.FirstIndex + this.Length) % this.Capacity; } } public int Length; public Deque(int capacity = 16) { this.Capacity = capacity; this.Buffer = new T[this.Capacity]; this.FirstIndex = 0; } public void PushBack(T data) { if (this.Length == this.Capacity) this.Resize(); this.Buffer[this.LastIndex] = data; this.Length++; } public void PushFront(T data) { if (this.Length == this.Capacity) this.Resize(); var index = this.FirstIndex - 1; if (index < 0) index = this.Capacity - 1; this.Buffer[index] = data; this.Length++; this.FirstIndex = index; } public T PopBack() { if (this.Length == 0) throw new InvalidOperationException("データが空です。"); var data = this[this.Length - 1]; this.Length--; return data; } public T PopFront() { if (this.Length == 0) throw new InvalidOperationException("データが空です。"); var data = this[0]; this.FirstIndex++; this.FirstIndex %= this.Capacity; this.Length--; return data; } private void Resize() { var newArray = new T[this.Capacity * 2]; for (int i = 0; i < this.Length; i++) { newArray[i] = this[i]; } this.FirstIndex = 0; this.Capacity *= 2; this.Buffer = newArray; } public IEnumerator<T> GetEnumerator() { for (int i = 0; i < this.Length; i++) { yield return this[i]; } } IEnumerator IEnumerable.GetEnumerator() { for (int i = 0; i < this.Length; i++) { yield return this[i]; } } } 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; } } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Threading.Tasks; using System.Globalization; using System.Collections; namespace Atcoder { public class CPair<T, U> : IComparable where T : IComparable<T> { public readonly T Item1; public readonly U Item2; public int CompareTo(object obj) { CPair<T, U> castedObj = (CPair<T, U>)obj; return this.Item1.CompareTo(castedObj.Item1); } public CPair(T t, U u) { Item1 = t; Item2 = u; } } class Pair : IComparable { public int x; public int y; public int z; public Pair(int X, int Y, int Z) { x = X; y = Y; z = Z; } public int CompareTo(object obj) { Pair kore = (Pair)obj; return x.CompareTo(kore.x); } public static bool operator <=(Pair p1, Pair p2) { if (p1.x != p2.x) { return p1.x <= p2.x; } else { return p1.y <= p2.y; } } public static bool operator >=(Pair p1, Pair p2) { if (p1.x != p2.x) { return p1.x >= p2.x; } else { return p1.y >= p2.y; } } } class Program { static bool[] visited; static List<int>[] togo; static void Main(string[] args) { long mod = 1000000007; StreamScanner scan = new StreamScanner(System.Console.OpenStandardInput()); long a = scan.Long(); long b = scan.Long(); long n = scan.Long(); Console.WriteLine((a * Math.Min(n, b - 1)) / b); } static bool DFS(int now, int last) { visited[now] = true; for (int i = 0; i < togo[now].Count; i++) { if (togo[now][i] == last) { continue; } if (visited[togo[now][i]]) { return false; } if (!DFS(togo[now][i], now)) { return false; } } return true; } static int binary_search<T>(T key, T[] moto, Func<int, T, T[], bool> isok) { int ng = -1; int ok = moto.Length; while (Math.Abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (isok(mid, key, moto)) { ok = mid; } else { ng = mid; } } return ok; } static int binary_search(int key, int[] moto) { int ng = -1; int ok = moto.Length; while (Math.Abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (isOK(mid, key, moto)) { ok = mid; } else { ng = mid; } } return ok; } static int[] Togo; static bool CheckBipartite(int now, int prev, List<int>[] g, int c = 0) // 0,-1が想定 { if (Togo == null) Togo = Enumerable.Repeat(-1, g.Length).ToArray(); foreach (var next in g[now]) { if (next == prev) continue; var nextc = Togo[next]; if (nextc >= 0 && nextc == c) return false; if (nextc >= 0) continue; Togo[next] = (c + 1) % 2; var res = CheckBipartite(next, now, g, (c + 1) % 2); if (res == false) return false; } return true; } static bool isOK(int index, int key, int[] moto) { return moto[index] > key; } public static int bitCount(int k) { uint i = (uint)k; i = i - ((i >> 1) & 0x55555555); i = (i & 0x33333333) + ((i >> 2) & 0x33333333); i = (i + (i >> 4)) & 0x0f0f0f0f; i = i + (i >> 8); i = i + (i >> 16); return (int)i & 0x3f; } static int check(long moto, long tai) { if (tai % moto != 0) { return 0; } while (tai > 1) { if (tai % moto == 0) { tai /= moto; } else if (tai > moto) { tai %= moto; } else { tai -= moto; } } if (tai == 1) { return 1; } else { return 0; } } static bool NextPermutation(int[] array) { var size = array.Length; var ok = false; // array[i]<array[i+1]を満たす最大のiを求める int i = size - 2; for (; 0 <= i; i--) { if (array[i] < array[i + 1]) { ok = true; break; } } //全ての要素が降順の場合、NextPermutationは存在しない if (ok == false) return false; // array[i]<array[j]を満たす最大のjを求める int j = size - 1; for (;; j--) { if (array[i] < array[j]) break; } // iとjの要素をswapする var tmp = array[i]; array[i] = array[j]; array[j] = tmp; // i以降の要素を反転させる Array.Reverse(array, i + 1, size - (i + 1)); return true; } static List<int[]> GetAllPermutation(int N) { var res = new List<int[]>(); var array = Enumerable.Range(0, N).ToArray(); do { var copy = new int[N]; array.CopyTo(copy, 0); res.Add(copy); } while (NextPermutation(array)); return res; } static List<int[]> GetAllPermutation(int[] array) { var size = array.Length; var res = new List<int[]>(); do { var copy = new int[size]; array.CopyTo(copy, 0); res.Add(copy); } while (NextPermutation(array)); return res; } static long Syakutori( int[] a, long k) //しゃくとり法モデル:連続部分列に含まれるすべての要素の値の和がK以上 { long sum = 0; int right = 0; long ans = 0; for (int left = 0; left < a.Length; left++) { while (right < a.Length && sum < k) { sum += a[right]; right++; } if (k <= sum) { ans += a.Length - right + 1; } if (left == right) { right++; } else { sum -= a[left]; } } return ans; } static int[] zalgo(String s) { int n = s.Length; int[] ret = new int[n]; ret[0] = n; int i = 1, j = 0; while (i < n) { while (i + j < n && s[j] == s[i + j]) ++j; ret[i] = j; if (j == 0) { ++i; continue; } int k = 1; while (i + k < n && k + ret[k] < j) { ret[i + k] = ret[k]; ++k; } i += k; j -= k; } return ret; } static int gcd(int a, int b) { if (a % b == 0) { return b; } return gcd(b, a % b); } static long gcd(long a, long b) { if (a % b == 0) { return b; } return gcd(b, a % b); } public static List<long> factorialMemo = new List<long>() { 1 }; static long Fact(int x) { for (int i = factorialMemo.Count; i <= x; i++) factorialMemo.Add(factorialMemo.Last() * i); return factorialMemo[x]; } static int[] yousogotoplus(int[] a, int[] b) { int[] c = new int[a.Length]; for (int i = 0; i < a.Length; i++) { c[i] = a[i] + b[i]; } return c; } static int[] yousogotoplus(int[] a, int[,] b, int l) { int[] c = new int[a.Length]; for (int i = 0; i < a.Length; i++) { c[i] = a[i] + b[l, i]; } return c; } static int[] yousogotoplus(int[,] a, int l) { int[] c = new int[a.GetLength(1)]; for (int i = 0; i < a.GetLength(1); i++) { c[i] = a[l, i]; } return c; } public static long LowerBound(long[] a, long key) { long l = 0; long r = a.Length; long mid; while (l < r) { mid = ((r - l) / 2) + l; if (a[mid] <= key) l = mid + 1; else r = mid; } return l; } public static long LIS(long[] a) { var dp = Enumerable.Range(0, a.Length).Select(x => long.MaxValue).ToArray(); for (int i = 0; i < a.Length; i++) { dp[LowerBound(dp, a[i])] = a[i]; } return LowerBound(dp, long.MaxValue - 1); } static long DivideWith(long m, long n, List<long> primes) { while (m % n == 0) { primes.Add(n); m = m / n; } return m; } static List<CPair<long, long>> SoinsuBunkai(long num) { List<CPair<long, long>> primes = new List<CPair<long, long>>(); List<long> yakusu = new List<long>(); List<long> yakusu2 = new List<long>(); for (int i = 2; i * i <= num; i++) { if (num % i != 0) { continue; } yakusu.Add(i); if (i * i != num) { yakusu2.Add(num / i); } } for (int i = 0; i < yakusu.Count; i++) { if (num % yakusu[i] != 0) { continue; } int j = 0; for (j = 0; num % yakusu[i] == 0; j++) { num /= yakusu[i]; } primes.Add(new CPair<long, long>(yakusu[i], j)); } for (int i = yakusu2.Count - 1; i > 0; i--) { if (num % yakusu2[i] != 0) { continue; } int j = 0; for (j = 0; num % yakusu2[i] == 0; j++) { num /= yakusu2[i]; } primes.Add(new CPair<long, long>(yakusu2[i], j)); } return primes; } static IEnumerable<int> Primes(int maxnum) { // var sieve = new BitArray(maxnum + 1, true); bool[] sieve = Enumerable.Repeat(true, maxnum + 1).ToArray(); int squareroot = (int)Math.Sqrt(maxnum); for (int i = 2; i <= squareroot; i++) { if (sieve[i] == false) continue; for (int n = i * 2; n <= maxnum; n += i) sieve[n] = false; } for (int i = 2; i <= maxnum; i++) if (sieve[i] == true) yield return i; } /* static long[] SoinsuBunkai(long num) { if (num == 1) return new long[] { 1 }; List<long> primes = new List<long>(); long n = DivideWith(num, 2, primes); n = DivideWith(n, 3, primes); n = DivideWith(n, 5, primes); long i = 0; while (n > 1) { int[] ps = { 7, 11, 13, 17, 19, 23, 29, 31 }; foreach (var p in ps) { // 30m+2, 30m+3, 30m+4, 30m+5, 30m+6、30m+8... は割る必要はない。 n = DivideWith(n, i + p, primes); if (n == 1) break; } i += 30; } return primes.ToArray(); }*/ public static int h; public static int w; public static int BFS(int height, int width, char[,] map) { int[] dx = new int[] { -1, 0, 0, 1 }; int[] dy = new int[] { 0, 1, -1, 0 }; bool[,] visited = new bool[h, w]; int[,] len = new int[h, w]; var queue = new Queue<Tuple<int, int>>(); queue.Enqueue(new Tuple<int, int>(height, width)); int max = 0; visited[height, width] = true; while (queue.Count > 0) { var now = queue.Dequeue(); for (int i = 0; i < 4; i++) { int ny = now.Item1 + dy[i]; int nx = now.Item2 + dx[i]; if (ny >= h || ny < 0 || nx >= w || nx < 0) continue; if (visited[ny, nx] || map[ny, nx] == '#') continue; visited[ny, nx] = true; len[ny, nx] = len[now.Item1, now.Item2] + 1; max = Math.Max(max, len[ny, nx]); queue.Enqueue(new Tuple<int, int>(ny, nx)); } } return max; } static public List<int> Topological_Sort(List<List<Edge>> G) { var ret = new List<int>(); var Nodes = new Queue<int>(); int N = G.Count(); var Link = new int[N]; for (var i = 0; i < N; i++) { Link[i] = 0; } for (var i = 0; i < N; i++) { foreach (var nx in G[i]) { Link[nx.to]++; } } for (var i = 0; i < N; i++) { if (Link[i] == 0) { Nodes.Enqueue(i); } } while (Nodes.Any()) { var nd = Nodes.Dequeue(); ret.Add(nd); foreach (var nx in G[nd]) { Link[nx.to]--; if (Link[nx.to] == 0) { Nodes.Enqueue(nx.to); } } } return ret; } static public bool Bit(long x, int dig) => ((1L << dig) & x) != 0; static public void Swap<T>(ref T a, ref T b) { T keep = a; a = b; b = keep; } static public void Initialize<T>(ref T[] array, T initialvalue) { array = Array.ConvertAll(array, x => initialvalue); } } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } private readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) throw new EndOfStreamException(); if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; } public char[] Char(int n) { char[] kore = new char[n]; for (int i = 0; i < n; i++) { kore[i] = Char(); } return kore; } public char[,] Char(int n, int m) { char[,] kore = new char[n, m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { kore[i, j] = Char(); } } return kore; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public long Long() { long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != '-' && (b < '0' || '9' < b)); if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } public long[] Long(long n) { long[] kore = new long[n]; for (int i = 0; i < n; i++) { kore[i] = Long(); } return kore; } public Mlong[] MLong(long n) { Mlong[] kore = new Mlong[n]; for (int i = 0; i < n; i++) { kore[i] = Long(); } return kore; } public long[,] Long(long h, long w) { long[,] kore = new long[h, w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { kore[i, j] = Long(); } } return kore; } public int Integer() { return (int)Long(); } public Mint[] MInteger(long n) { Mint[] kore = new Mint[n]; for (int i = 0; i < n; i++) { kore[i] = Integer(); } return kore; } public int[] Integer(long n) { int[] kore = new int[n]; for (int i = 0; i < n; i++) { kore[i] = (int)Long(); } return kore; } public int[,] Integer(long h, long w) { int[,] kore = new int[h, w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { kore[i, j] = (int)Long(); } } return kore; } public int[] StringToInt(int n) { char[] s = Scan().ToCharArray(); int[] kore = new int[n]; for (int i = 0; i < n; i++) { kore[i] = s[i] - '0'; } return kore; } public int[,] StringToInt(int h, int w) { int[,] kore = new int[h, w]; for (int i = 0; i < h; i++) { char[] s = Scan().ToCharArray(); for (int j = 0; j < w; j++) { kore[i, j] = s[j] - '0'; } } return kore; } public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); } } public class UnionFind { public int[] data; public UnionFind(int size) { data = new int[size]; for (int i = 0; i < size; i++) data[i] = -1; } public bool Unite(int x, int y) { x = Root(x); y = Root(y); if (x != y) { if (data[y] < data[x]) { var tmp = y; y = x; x = tmp; } data[x] += data[y]; data[y] = x; } return x != y; } public bool IsSameGroup(int x, int y) { return Root(x) == Root(y); } public int Root(int x) { return data[x] < 0 ? x : data[x] = Root(data[x]); } } public class Mlong : IComparable { private static long mod = 1000000007; public long num; public Mlong(long num) { this.num = num; } public override int GetHashCode() { return num.GetHashCode(); } public override bool Equals(object obj) { return num.Equals(obj); } public static Mlong operator +(Mlong x, Mlong y) { return new Mlong((x.num + y.num) % mod); } public static Mlong operator -(Mlong x, Mlong y) { return new Mlong((x.num - y.num + mod) % mod); } public static Mlong operator *(Mlong x, Mlong y) { return new Mlong((long)(((1L * x.num) * y.num) % mod)); } public Mlong hutujyo(Mlong x) { return new Mlong(num / x.num); } static long GetInverse(long a) { long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1; while (true) { if (p == 1) return x2 + mod; div = a / p; x1 -= x2 * div; y1 -= y2 * div; a %= p; if (a == 1) return x1 + mod; div = p / a; x2 -= x1 * div; y2 -= y1 * div; p %= a; } } public Mlong modjyo(Mlong x) { return num * GetInverse(x.num) % mod; } public static implicit operator Mlong(long x) { return new Mlong(x); } public static Mlong operator %(Mlong x, Mlong y) { return new Mlong(x.num % y.num); } public static explicit operator long(Mlong x) { return x.num; } public static bool operator ==(Mlong x, Mlong y) { return x.num == y.num; } public static bool operator !=(Mlong x, Mlong y) { return x.num != y.num; } public static bool operator<(Mlong x, Mlong y) { return x.num < y.num; } public static bool operator>(Mlong x, Mlong y) { return x.num > y.num; } public static bool operator <=(Mlong x, Mlong y) { return x.num <= y.num; } public static bool operator >=(Mlong x, Mlong y) { return x.num >= y.num; } public Mlong Pow(Mlong n) { Mlong pow = this; Mlong res = 1; while (n > 0) { if (n % 2 == 1) { res *= pow; } pow *= pow; n.hutujyo(2); } /* if (n == 1) { return this % mod; } if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; } Mint buf = Pow(n.hutujyo(2)); return (buf * buf) % mod;*/ return res; } public static Mlong Pow(Mlong a, Mlong n) { return a.Pow(n); } public static List<Mlong> factorialMemo = new List<Mlong>() { 1 }; static Mlong Factorial(int x) { for (int i = factorialMemo.Count; i <= x; i++) factorialMemo.Add(factorialMemo.Last() * i); return factorialMemo[x]; } public static Mlong Comb(Mlong n, Mlong a) { Mlong buf1 = 1; Mlong buf2 = 1; for (long i = 0; i < a.num; i++) { buf1 *= n - i; buf2 *= (i + 1); } return buf1.modjyo(buf2); } public static Mlong Comb(int n, int r) { return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r)); } public static void WriteLine(Mlong x) { Console.WriteLine(x.num); } public int CompareTo(object obj) { Mlong kore = (Mlong)obj; return num.CompareTo(kore.num); } } public class Mint : IComparable { public static int mod = 1000000007; public int num; public Mint(int Num) { num = Num; } public override int GetHashCode() { return num.GetHashCode(); } public override bool Equals(object obj) { return num.Equals(obj); } public static Mint operator +(Mint x, Mint y) { return new Mint((x.num + y.num) % mod); } public static Mint operator -(Mint x, Mint y) { return new Mint((x.num - y.num + mod) % mod); } public static Mint operator *(Mint x, Mint y) { return new Mint((int)(((1L * x.num) * y.num) % mod)); } public Mint hutujyo(Mint x) { return new Mint(num / x.num); } static int GetInverse(long a) { long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1; while (true) { if (p == 1) return (int)(x2 + mod); div = a / p; x1 -= x2 * div; y1 -= y2 * div; a %= p; if (a == 1) return (int)(x1 + mod); div = p / a; x2 -= x1 * div; y2 -= y1 * div; p %= a; } } public Mint modjyo(Mint x) { return num * GetInverse(x.num) % mod; } /* public Mint modjyo(Mint x) { return num * x.Pow(mod - 2); }*/ public static implicit operator Mint(int x) { return new Mint(x); } public static Mint[] Toarray(int[] x) { Mint[] buf = new Mint[x.Length]; for (int i = 0; i < x.Length; i++) { buf[i] = x[i]; } return buf; } public static explicit operator int(Mint x) { return x.num; } public static Mint operator %(Mint x, Mint y) { return new Mint(x.num % y.num); } public static bool operator ==(Mint x, Mint y) { return x.num == y.num; } public static bool operator !=(Mint x, Mint y) { return x.num != y.num; } public static bool operator<(Mint x, Mint y) { return x.num < y.num; } public static bool operator>(Mint x, Mint y) { return x.num > y.num; } public static bool operator <=(Mint x, Mint y) { return x.num <= y.num; } public static bool operator >=(Mint x, Mint y) { return x.num >= y.num; } public Mint Pow(Mint n) { Mint pow = this; Mint res = 1; while (n > 0) { if (n % 2 == 1) { res *= pow; } pow *= pow; n.hutujyo(2); } /* if (n == 1) { return this % mod; } if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; } Mint buf = Pow(n.hutujyo(2)); return (buf * buf) % mod;*/ return res; } public static Mint Pow(Mint a, Mint n) { return a.Pow(n); } public static List<Mint> factorialMemo = new List<Mint>() { 1 }; static Mint Factorial(int x) { for (int i = factorialMemo.Count; i <= x; i++) factorialMemo.Add(factorialMemo.Last() * i); return factorialMemo[x]; } public static Mint Comb(int n, int r) { return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r)); } public static void WriteLine(Mint x) { Console.WriteLine(x.num); } public int CompareTo(object obj) { Mint kore = (Mint)obj; return num.CompareTo(kore.num); } } public class PriorityQueue<T> : IEnumerable<T> { private readonly List<T> _data = new List<T>(); private readonly IComparer<T> _comparer; private readonly bool _isDescending; public PriorityQueue(IComparer<T> comparer, bool isDescending = true) { _comparer = comparer; _isDescending = isDescending; } public PriorityQueue(Comparison<T> comparison, bool isDescending = true) : this(Comparer<T>.Create(comparison), isDescending) {} public PriorityQueue(bool isDescending = true) : this(Comparer<T>.Default, isDescending) {} public void Enqueue(T item) { _data.Add(item); var childIndex = _data.Count - 1; while (childIndex > 0) { var parentIndex = (childIndex - 1) / 2; if (Compare(_data[childIndex], _data[parentIndex]) >= 0) break; Swap(childIndex, parentIndex); childIndex = parentIndex; } } public T Dequeue() { var lastIndex = _data.Count - 1; var firstItem = _data[0]; _data[0] = _data[lastIndex]; _data.RemoveAt(lastIndex--); var parentIndex = 0; while (true) { var childIndex = parentIndex * 2 + 1; if (childIndex > lastIndex) break; var rightChild = childIndex + 1; if (rightChild <= lastIndex && Compare(_data[rightChild], _data[childIndex]) < 0) childIndex = rightChild; if (Compare(_data[parentIndex], _data[childIndex]) <= 0) break; Swap(parentIndex, childIndex); parentIndex = childIndex; } return firstItem; } public T Peek() { return _data[0]; } private void Swap(int a, int b) { var tmp = _data[a]; _data[a] = _data[b]; _data[b] = tmp; } private int Compare(T a, T b) { return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b); } public int Count => _data.Count; public IEnumerator<T> GetEnumerator() { return _data.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } public class Tree { public Node[] Nodes; public List<int[]> hen; public class Node { public int? parent = null; public List<int[]> children = new List<int[]>(); public int parentcolor = -1; } public Tree(int kosu) { Nodes = new Node[kosu]; for (int i = 0; i < Nodes.Length; i++) { Nodes[i] = new Node(); } hen = new List<int[]>(); } public void Connect(int oya, int ko, int id) { hen.Add(new int[] { oya, ko, 0 }); Nodes[oya].children.Add(new int[] { ko, id }); Nodes[ko].parent = oya; } } /// <summary> /// Self-Balancing Binary Search Tree /// (using Randamized BST) /// </summary> public class SB_BinarySearchTree<T> where T : IComparable { public class Node { public T Value; public Node LChild; public Node RChild; public int Count; // size of the sub tree public Node(T v) { Value = v; Count = 1; } } static Random _rnd = new Random(); public static int Count(Node t) { return t == null ? 0 : t.Count; } static Node Update(Node t) { t.Count = Count(t.LChild) + Count(t.RChild) + 1; return t; } public static Node Merge(Node l, Node r) { if (l == null || r == null) return l == null ? r : l; if ((double)Count(l) / (double)(Count(l) + Count(r)) > _rnd.NextDouble()) { l.RChild = Merge(l.RChild, r); return Update(l); } else { r.LChild = Merge(l, r.LChild); return Update(r); } } /// <summary> /// split as [0, k), [k, n) /// </summary> public static Tuple<Node, Node> Split(Node t, int k) { if (t == null) return new Tuple<Node, Node>(null, null); if (k <= Count(t.LChild)) { var s = Split(t.LChild, k); t.LChild = s.Item2; return new Tuple<Node, Node>(s.Item1, Update(t)); } else { var s = Split(t.RChild, k - Count(t.LChild) - 1); t.RChild = s.Item1; return new Tuple<Node, Node>(Update(t), s.Item2); } } public static Node Remove(Node t, T v) { if (Find(t, v) == null) return t; return RemoveAt(t, LowerBound(t, v)); } public static Node RemoveAt(Node t, int k) { var s = Split(t, k); var s2 = Split(s.Item2, 1); return Merge(s.Item1, s2.Item2); } public static bool Contains(Node t, T v) { return Find(t, v) != null; } public static Node Find(Node t, T v) { while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp > 0) t = t.LChild; else if (cmp < 0) t = t.RChild; else break; } return t; } public static Node FindByIndex(Node t, int idx) { if (t == null) return null; var currentIdx = Count(t) - Count(t.RChild) - 1; while (t != null) { if (currentIdx == idx) return t; if (currentIdx > idx) { t = t.LChild; currentIdx -= (Count(t == null ? null : t.RChild) + 1); } else { t = t.RChild; currentIdx += (Count(t == null ? null : t.LChild) + 1); } } return null; } public static int UpperBound(Node t, T v) { var torg = t; if (t == null) return -1; var ret = Int32.MaxValue; var idx = Count(t) - Count(t.RChild) - 1; while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp > 0) { ret = Math.Min(ret, idx); t = t.LChild; idx -= (Count(t == null ? null : t.RChild) + 1); } else if (cmp <= 0) { t = t.RChild; idx += (Count(t == null ? null : t.LChild) + 1); } } return ret == Int32.MaxValue ? Count(torg) : ret; } public static int LowerBound(Node t, T v) { var torg = t; if (t == null) return -1; var idx = Count(t) - Count(t.RChild) - 1; var ret = Int32.MaxValue; while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp >= 0) { if (cmp == 0) ret = Math.Min(ret, idx); t = t.LChild; if (t == null) ret = Math.Min(ret, idx); idx -= t == null ? 0 : (Count(t.RChild) + 1); } else if (cmp < 0) { t = t.RChild; idx += (Count(t == null ? null : t.LChild) + 1); if (t == null) return idx; } } // return ret; return ret == Int32.MaxValue ? Count(torg) : ret; } public static Node Insert(Node t, T v) { var ub = LowerBound(t, v); return InsertByIdx(t, ub, v); } static Node InsertByIdx(Node t, int k, T v) { var s = Split(t, k); return Merge(Merge(s.Item1, new Node(v)), s.Item2); } public static IEnumerable<T> Enumerate(Node t) { var ret = new List<T>(); Enumerate(t, ret); return ret; } static void Enumerate(Node t, List<T> ret) { if (t == null) return; Enumerate(t.LChild, ret); ret.Add(t.Value); Enumerate(t.RChild, ret); } } /// <summary> /// C-like set /// </summary> public class Set<T> where T : IComparable { protected SB_BinarySearchTree<T>.Node _root; public T this[int idx] { get { return ElementAt(idx); } } public int Count() { return SB_BinarySearchTree<T>.Count(_root); } public virtual void Insert(T v) { if (_root == null) _root = new SB_BinarySearchTree<T>.Node(v); else { if (SB_BinarySearchTree<T>.Find(_root, v) != null) return; _root = SB_BinarySearchTree<T>.Insert(_root, v); } } public void Clear() { _root = null; } public void Remove(T v) { _root = SB_BinarySearchTree<T>.Remove(_root, v); } public bool Contains(T v) { return SB_BinarySearchTree<T>.Contains(_root, v); } public T ElementAt(int k) { var node = SB_BinarySearchTree<T>.FindByIndex(_root, k); if (node == null) throw new IndexOutOfRangeException(); return node.Value; } public int Count(T v) { return SB_BinarySearchTree<T>.UpperBound(_root, v) - SB_BinarySearchTree<T>.LowerBound(_root, v); } public int LowerBound(T v) { return SB_BinarySearchTree<T>.LowerBound(_root, v); } public int UpperBound(T v) { return SB_BinarySearchTree<T>.UpperBound(_root, v); } public Tuple<int, int> EqualRange(T v) { if (!Contains(v)) return new Tuple<int, int>(-1, -1); return new Tuple<int, int>(SB_BinarySearchTree<T>.LowerBound(_root, v), SB_BinarySearchTree<T>.UpperBound(_root, v) - 1); } public List<T> ToList() { return new List<T>(SB_BinarySearchTree<T>.Enumerate(_root)); } } /// <summary> /// C-like multiset /// </summary> public class MultiSet<T> : Set<T> where T : IComparable { public override void Insert(T v) { if (_root == null) _root = new SB_BinarySearchTree<T>.Node(v); else _root = SB_BinarySearchTree<T>.Insert(_root, v); } } public class RollingHashSlow { public const long B = (long)1e5 + 7; public const long MOD = (long)1e9 + 7; public string S { get; set; } public int N { get; set; } public long[] Power { get; set; } public long[] Hash { get; set; } public RollingHashSlow(string s) { this.S = s; this.N = s.Length; // B^nを計算しておく this.Power = new long[this.N + 1]; this.Power[0] = 1; for (int i = 0; i < N; i++) { this.Power[i + 1] = (this.Power[i] * B) % MOD; } // ハッシュを前計算する this.Hash = new long[this.N + 1]; for (int i = 0; i < N; i++) { this.Hash[i + 1] = (this.Hash[i] * B + S[i]) % MOD; } } // S[l, r) のハッシュ値を求める public long Get(int l, int r) { var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l] % MOD); if (hash < 0) hash += MOD; return hash; } } class RollingHashFast { public const ulong B = (ulong)1e9 + 7; public string S { get; set; } public int N { get; set; } public ulong[] Power { get; set; } public ulong[] Hash { get; set; } public RollingHashFast(string s) { this.S = s; this.N = s.Length; // B^nを計算しておく this.Power = new ulong[this.N + 1]; this.Power[0] = 1; for (int i = 0; i < N; i++) { this.Power[i + 1] = this.Power[i] * B; } // ハッシュを前計算する this.Hash = new ulong[this.N + 1]; for (int i = 0; i < N; i++) { this.Hash[i + 1] = this.Hash[i] * B + S[i]; } } // [l, r) のハッシュ値を求める public ulong Get(int l, int r) { var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l]); return hash; } } class Segtree<T> { int n; T[] tree; Func<T, T, T> f; T exnum; public Segtree(int m, Func<T, T, T> f, T ex) { this.f = f; this.exnum = ex; n = 1; while (n < m) n <<= 1; tree = new T[(n << 1) - 1]; for (int i = 0; i < tree.Length; i++) tree[i] = ex; } public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) { for (int i = 0; i < m; ++i) tree[i + n - 1] = ini; all_update(); } public void assign_without_update(int j, T x) { tree[j + n - 1] = x; } public void update(int j, T x) { int i = j + n - 1; tree[i] = x; while (i > 0) { i = (i - 1) >> 1; tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]); } } public void all_update() { for (int i = n - 2; i >= 0; i--) tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]); } public T look(int i) { return tree[i + n - 1]; } // [s, t) public T run(int s, int t) { return query(s, t, 0, 0, n); } T query(int s, int t, int k, int l, int r) { if (r <= s || t <= l) return exnum; if (s <= l && r <= t) return tree[k]; return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1), query(s, t, (k + 1) << 1, (l + r) >> 1, r)); } } public class WarshallFloyd { public int V { get; set; } public long[,] DP { get; set; } public long INF = long.MaxValue; public bool[] Negative; public WarshallFloyd(int v) { this.V = v; this.DP = new long[V, V]; for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { this.DP[i, j] = INF; } this.DP[i, i] = 0; } } public void SetCost(int a, int b, int c = 1) { this.DP[a, b] = c; } public long[,] CalcMinCost() { this.Negative = new bool[V]; for (int k = 0; k < V; k++) { for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { if (DP[i, k] == INF || DP[k, j] == INF) continue; DP[i, j] = Math.Min(DP[i, j], DP[i, k] + DP[k, j]); } } } for (int k = 0; k < V; k++) { for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { if (DP[i, k] == INF || DP[k, j] == INF) continue; if (DP[i, j] > DP[i, k] + DP[k, j]) { this.Negative[i] = true; this.Negative[j] = true; this.Negative[k] = true; } } } } return DP; } public long GetMinCost(int a, int b) { return DP[a, b]; } public bool IsINF(int a, int b) { return DP[a, b] >= INF; } public bool IsNegative(params int[] vs) { if (vs.Length == 0) vs = Enumerable.Range(0, V).ToArray(); foreach (var v in vs) { if (Negative[v]) return true; } return false; } } /// <summary> /// Get min cost between two points /// </summary> public class Dijkstra { private int maxIndex = -1; private const int INF = Int32.MaxValue; private int[,] _edgeArray; /// <summary> /// Dijkstra, get min cost between two points /// should not contain negatie cost path /// </summary> /// <param name="size">max index of vertices</param> public Dijkstra(int size) { maxIndex = size + 1; _edgeArray = new int[maxIndex, maxIndex]; for (int i = 0; i < _edgeArray.GetLength(0); i++) { for (int j = 0; j < _edgeArray.GetLength(1); j++) { _edgeArray[i, j] = INF; if (i == j) _edgeArray[i, j] = 0; } } } // Add a path(no direction) with its cost public void AddPath(int s, int t, int cost) { _edgeArray[s, t] = Math.Min(_edgeArray[s, t], cost); _edgeArray[t, s] = _edgeArray[s, t]; } // Get the min cost between s and t // return Int32.MaxValue if no path public int GetMinCost(int s, int t) { int[] cost = new int[maxIndex]; for (int i = 0; i < cost.Length; i++) cost[i] = INF; cost[s] = 0; var priorityQueue = new PriorityQueue<CPair<int, int>>(); priorityQueue.Enqueue(new CPair<int, int>(0, s)); while (priorityQueue.Count() > 0) { var costDestinationPair = priorityQueue.Dequeue(); if (cost[costDestinationPair.Item2] < costDestinationPair.Item1) continue; for (int i = 0; i < maxIndex; i++) { int newCostToi = _edgeArray[costDestinationPair.Item2, i] == INF ? INF : costDestinationPair.Item1 + _edgeArray[costDestinationPair.Item2, i]; if (newCostToi < cost[i]) { cost[i] = newCostToi; priorityQueue.Enqueue(new CPair<int, int>(newCostToi, i)); } } } return cost[t]; } } class Deque<T> : IEnumerable<T> { public T this[int i] { get { return this.Buffer[(this.FirstIndex + i) % this.Capacity]; } set { if (i < 0) throw new ArgumentOutOfRangeException(); this.Buffer[(this.FirstIndex + i) % this.Capacity] = value; } } private T[] Buffer; private int Capacity; private int FirstIndex; private int LastIndex { get { return (this.FirstIndex + this.Length) % this.Capacity; } } public int Length; public Deque(int capacity = 16) { this.Capacity = capacity; this.Buffer = new T[this.Capacity]; this.FirstIndex = 0; } public void PushBack(T data) { if (this.Length == this.Capacity) this.Resize(); this.Buffer[this.LastIndex] = data; this.Length++; } public void PushFront(T data) { if (this.Length == this.Capacity) this.Resize(); var index = this.FirstIndex - 1; if (index < 0) index = this.Capacity - 1; this.Buffer[index] = data; this.Length++; this.FirstIndex = index; } public T PopBack() { if (this.Length == 0) throw new InvalidOperationException("データが空です。"); var data = this[this.Length - 1]; this.Length--; return data; } public T PopFront() { if (this.Length == 0) throw new InvalidOperationException("データが空です。"); var data = this[0]; this.FirstIndex++; this.FirstIndex %= this.Capacity; this.Length--; return data; } private void Resize() { var newArray = new T[this.Capacity * 2]; for (int i = 0; i < this.Length; i++) { newArray[i] = this[i]; } this.FirstIndex = 0; this.Capacity *= 2; this.Buffer = newArray; } public IEnumerator<T> GetEnumerator() { for (int i = 0; i < this.Length; i++) { yield return this[i]; } } IEnumerator IEnumerable.GetEnumerator() { for (int i = 0; i < this.Length; i++) { yield return this[i]; } } } 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; } } }
[["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
10,679
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using static System.Console; using static System.Math; using static MyIO; using static MyUtil; public class F { public static void Main() => (new Solver()).Solve(); } public class Solver { private const long INF = long.MaxValue / 2; private long N; private long[] a; private List<long>[] adj; private long[] ans; private long[] dp; private Stack<(long, long)> stack; public void Solve() { N = GetLong(); a = GetLongs(N); adj = Range(0, N).Select(_ => new List<long>()).ToArray(); for (long i = 0; i < N - 1; i++) { long u = GetLong() - 1; long v = GetLong() - 1; adj[u].Add(v); adj[v].Add(u); } ans = new long[N]; dp = Enumerable.Repeat(INF, (int)N + 1).ToArray(); stack = new Stack<(long, long)>(); dfs(0); WriteLine(string.Join("\n", ans)); } private void dfs(long v) { long pos = bs(a[v]); stack.Push((pos, dp[pos])); dp[pos] = a[v]; ans[v] = length(); foreach (var u in adj[v]) { if (ans[u] != 0) continue; dfs(u); } var pair = stack.Pop(); dp[pair.Item1] = pair.Item2; } private long bs(long key) { long ng = -1; long ok = N; while (Abs(ok - ng) > 1) { long mid = (ok + ng) / 2; if (dp[mid] > key) ok = mid; else ng = mid; } return ok; } private long length() { long ng = N; long ok = -1; while (Abs(ok - ng) > 1) { long mid = (ok + ng) / 2; if (dp[mid] < INF) ok = mid; else ng = mid; } return ok + 1; } } public static class MyIO { private static string[] args = new string[0]; private static int cnt = 0; private static IEnumerable<string> getArgs(long N) => Range(0, N).Select(_ => getArg()); private static string getArg() { if (cnt == args.Length) { args = Console.ReadLine().Split(); cnt = 0; } return args[cnt++]; } public static int GetInt() => int.Parse(getArg()); public static long GetLong() => long.Parse(getArg()); public static double GetDouble() => double.Parse(getArg()); public static decimal GetDecimal() => decimal.Parse(getArg()); public static string GetString() => getArg(); public static char GetChar() => getArg()[0]; public static int[] GetInts(long N) => getArgs(N).Select(int.Parse).ToArray(); public static long[] GetLongs(long N) => getArgs(N).Select(long.Parse).ToArray(); public static double[] GetDoubles(long N) => getArgs(N).Select(double.Parse).ToArray(); public static decimal[] GetDecimals(long N) => getArgs(N).Select(decimal.Parse).ToArray(); public static string[] GetStrings(long N) => getArgs(N).ToArray(); } public static class MyUtil { public static void chmax<T>(ref T x, T y) where T : IComparable<T> { if (x.CompareTo(y) < 0) x = y; } public static void chmin<T>(ref T x, T y) where T : IComparable<T> { if (x.CompareTo(y) > 0) x = y; } public static void swap<T>(ref T x, ref T y) { T tmp = x; x = y; y = tmp; } public static long rightShift(long x, long y) => (x >> (int)y); public static long leftShift(long x, long y) => (x << (int)y); public static bool contains(long s, long x) => (rightShift(s, x) & 1L) == 1L; public static long gcd(long x, long y) => (y == 0) ? x : gcd(y, x % y); public static long lcm(long x, long y) => (x / gcd(x, y)) * y; public static IEnumerable<int> Range(long start, long count) => Enumerable.Range((int)start, (int)count); public static void Sort(this List<string> source) => source.Sort(StringComparer.Ordinal); }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using static System.Console; using static System.Math; using static MyIO; using static MyUtil; public class F { public static void Main() => (new Solver()).Solve(); } public class Solver { private const long INF = long.MaxValue / 2; private long N; private long[] a; private List<long>[] adj; private long[] ans; private long[] dp; private Stack<(long, long)> stack; public void Solve() { N = GetLong(); a = GetLongs(N); adj = Range(0, N).Select(_ => new List<long>()).ToArray(); for (long i = 0; i < N - 1; i++) { long u = GetLong() - 1; long v = GetLong() - 1; adj[u].Add(v); adj[v].Add(u); } ans = new long[N]; dp = Enumerable.Repeat(INF, (int)N + 1).ToArray(); stack = new Stack<(long, long)>(); dfs(0); WriteLine(string.Join("\n", ans)); } private void dfs(long v) { long pos = bs(a[v]); stack.Push((pos, dp[pos])); dp[pos] = a[v]; ans[v] = length(); foreach (var u in adj[v]) { if (ans[u] != 0) continue; dfs(u); } var pair = stack.Pop(); dp[pair.Item1] = pair.Item2; } private long bs(long key) { long ng = -1; long ok = N; while (Abs(ok - ng) > 1) { long mid = (ok + ng) / 2; if (dp[mid] >= key) ok = mid; else ng = mid; } return ok; } private long length() { long ng = N; long ok = -1; while (Abs(ok - ng) > 1) { long mid = (ok + ng) / 2; if (dp[mid] < INF) ok = mid; else ng = mid; } return ok + 1; } } public static class MyIO { private static string[] args = new string[0]; private static int cnt = 0; private static IEnumerable<string> getArgs(long N) => Range(0, N).Select(_ => getArg()); private static string getArg() { if (cnt == args.Length) { args = Console.ReadLine().Split(); cnt = 0; } return args[cnt++]; } public static int GetInt() => int.Parse(getArg()); public static long GetLong() => long.Parse(getArg()); public static double GetDouble() => double.Parse(getArg()); public static decimal GetDecimal() => decimal.Parse(getArg()); public static string GetString() => getArg(); public static char GetChar() => getArg()[0]; public static int[] GetInts(long N) => getArgs(N).Select(int.Parse).ToArray(); public static long[] GetLongs(long N) => getArgs(N).Select(long.Parse).ToArray(); public static double[] GetDoubles(long N) => getArgs(N).Select(double.Parse).ToArray(); public static decimal[] GetDecimals(long N) => getArgs(N).Select(decimal.Parse).ToArray(); public static string[] GetStrings(long N) => getArgs(N).ToArray(); } public static class MyUtil { public static void chmax<T>(ref T x, T y) where T : IComparable<T> { if (x.CompareTo(y) < 0) x = y; } public static void chmin<T>(ref T x, T y) where T : IComparable<T> { if (x.CompareTo(y) > 0) x = y; } public static void swap<T>(ref T x, ref T y) { T tmp = x; x = y; y = tmp; } public static long rightShift(long x, long y) => (x >> (int)y); public static long leftShift(long x, long y) => (x << (int)y); public static bool contains(long s, long x) => (rightShift(s, x) & 1L) == 1L; public static long gcd(long x, long y) => (y == 0) ? x : gcd(y, x % y); public static long lcm(long x, long y) => (x / gcd(x, y)) * y; public static IEnumerable<int> Range(long start, long count) => Enumerable.Range((int)start, (int)count); public static void Sort(this List<string> source) => source.Sort(StringComparer.Ordinal); }
[["-", 0, 52, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 17, 20]]
8
1,122
2
using System; using System.Collections.Generic; using System.Collections; using System.Collections.Specialized; using System.Linq; using System.Text; using System.IO; using System.Reflection; using static System.Math; using System.Numerics; using nint = System.Int64; static class Program { const int mod = (int)1e9 + 7; const long inf = (long)1e18; static List<int>[] li; static bool[] b; static int[] h, ans; static Avls avl = new Avls(true, true); static void Main() { Sc sc = new Sc(); var s = sc.Ia; int n = s[0], m = n - 1; li = new List<int>[n + 1]; b = new bool[n + 1]; h = sc.Ia2; ans = new int[n]; for (int i = 1; i <= n; i++) { li[i] = new List<int>(); } for (int i = 0; i < m; i++) { var e = sc.Ia; li[e[0]].Add(e[1]); li[e[1]].Add(e[0]); } Fu(1, 1); Console.WriteLine("{0}", String.Join("\n", ans)); } static void Fu(int a, int g) { b[a] = true; var e = avl.Rd(0, h[a]); var p = e.d < 0 ? 1 : (e.d + 1); g = Max((int)p, g); ans[a - 1] = g; avl.Ud(h[a], a, p); for (int i = 0; i < li[a].Count; i++) { if (!b[li[a][i]]) { Fu(li[a][i], g); } } avl.Dl(h[a], a); } } public class Avls { private const int m = 20, f = (1 << m) - 1; private readonly(long n, long k, long d) dv = (-1, -1, -1); private Avl avl; public Avls(bool bo, bool bb) { avl = new Avl(bo, bb); } public void Ud(nint n, int k, long d) { avl.Ud((n << m) + k, d); } public bool Dl(nint n, int k) { return avl.Dl((n << m) + k); } public (long n, long k, long d) Rd(nint a, nint b) { var e = avl.Rd(a << m, ((b + 1) << m) - 1); return e != avl.du ? (e.n >> m, e.n & f, e.d) : dv; } public (long n, long k, long d) Hs(nint n) { var e = avl.Lb(n << m); return e.n >> m == n ? (e.n >> m, e.n & f, e.d) : dv; } public (long n, long k, long d) Hs(nint n, int k) { var e = avl.Hs((n << m) + k); return e != avl.du ? (e.n >> m, e.n & f, e.d) : dv; } public (long n, long k, long d) Lb(nint n) { var e = avl.Lb(n << m); return e != avl.du ? (e.n >> m, e.n & f, e.d) : dv; } public (long n, long k, long d) Ub(nint n) { var e = avl.Ub(((n + 1) << m) - 1); return e != avl.du ? (e.n >> m, e.n & f, e.d) : dv; } public int Rg(nint a, nint b) { return avl.Rg(a << m, ((b + 1) << m) - 1); } public (long n, long k, long d) Gl(nint a, nint b, long d) { var e = avl.Gl(a << m, ((b + 1) << m) - 1, d); return e != avl.du ? (e.n >> m, e.n & f, e.d) : dv; } public (long n, long k, long d) Gr(nint a, nint b, long d) { var e = avl.Gr(a << m, ((b + 1) << m) - 1, d); return e != avl.du ? (e.n >> m, e.n & f, e.d) : dv; } } public class Avl { public class Nd { public int h = 1, c = 1; public readonly nint n; public long d; public Nd l, r, nx; public Nd(nint n, long d, Nd du) { this.n = n; this.d = d; nx = this; l = du; r = du; } public override string ToString() => "n:" + n.ToString() + " d:" + d.ToString(); } private static Func<long, long, bool> compare; private static Action<Nd> compare2; public Nd root, du; public int cnt = 0; public bool bb; public Avl(bool bo, bool bb) { if (bo) { du = new Nd(nint.MinValue, long.MinValue, du); compare = CoMax; compare2 = CoMax; } else { du = new Nd(nint.MinValue, long.MaxValue, du); compare = CoMin; compare2 = CoMin; } this.bb = bb; du.h = 0; du.c = 0; root = du; } private bool CoMax(long a, long b) { return a >= b; } private bool CoMin(long a, long b) { return a <= b; } private void CoMax(Nd t) { t.nx = t; if (t.nx.d < t.l.nx.d) { t.nx = t.l.nx; } if (t.nx.d < t.r.nx.d) { t.nx = t.r.nx; } } private void CoMin(Nd t) { t.nx = t; if (t.nx.d > t.l.nx.d) { t.nx = t.l.nx; } if (t.nx.d > t.r.nx.d) { t.nx = t.r.nx; } } public void Ud(nint n, long d) { if (root == du) { root = new Nd(n, d, du); cnt++; } else if (root.n == n) { if (bb) { root.d += d; } else { root.d = d; } compare2(root); } else if (Fu(root, n, d)) { if (Abs(root.l.h - root.r.h) > 1) { root = Rotate(root); } cnt++; } } private bool Fu(Nd t, nint n, long d) { bool bo = false; if (t.n > n) { if (t.l != du) { if (t.l.n == n) { if (bb) { t.l.d += d; } else { t.l.d = d; } compare2(t.l); } else if (bo = Fu(t.l, n, d)) { t.c++; if (Abs(t.l.l.h - t.l.r.h) > 1) { t.l = Rotate(t.l); } t.h = Max(t.l.h, t.r.h) + 1; } compare2(t); } else { t.l = new Nd(n, d, du); bo = true; t.c++; t.h = Max(t.l.h, t.r.h) + 1; t.nx = compare(t.nx.d, t.l.d) ? t.nx : t.l; } } else { if (t.r != du) { if (t.r.n == n) { if (bb) { t.r.d += d; } else { t.r.d = d; } compare2(t.r); } else if (bo = Fu(t.r, n, d)) { t.c++; if (Abs(t.r.l.h - t.r.r.h) > 1) { t.r = Rotate(t.r); } t.h = Max(t.l.h, t.r.h) + 1; } compare2(t); } else { t.r = new Nd(n, d, du); bo = true; t.c++; t.h = Max(t.l.h, t.r.h) + 1; t.nx = compare(t.nx.d, t.r.d) ? t.nx : t.r; } } return bo; } private Nd Rotate(Nd t) { Nd nd = du; if (t.l.h > t.r.h) { if (t.l.l.h > t.l.r.h) { nd = t.l; t.l = t.l.r; nd.r = t; Ft(t); } else { nd = t.l.r; t.l.r = nd.l; nd.l = t.l; Ft(t.l); t.l = nd.r; nd.r = t; Ft(t); } } else { if (t.r.l.h > t.r.r.h) { nd = t.r.l; t.r.l = nd.r; nd.r = t.r; Ft(t.r); t.r = nd.l; nd.l = t; Ft(t); } else { nd = t.r; t.r = t.r.l; nd.l = t; Ft(t); } } Ft(nd); return nd; } private void Ft(Nd t) { t.h = Max(t.l.h, t.r.h) + 1; t.c = t.l.c + t.r.c + 1; compare2(t); } public bool Dl(nint n) { if (cnt == 0) { return false; } Nd t = root; if (t.n == n) { root = Fd2(root); if (cnt == 0) { return true; } else if (Abs(root.l.h - root.r.h) > 1) { root = Rotate(root); } else { Ft(root); } return true; } bool bo = Fd1(root, n); if (Abs(root.l.h - root.r.h) > 1) { root = Rotate(root); } else { Ft(root); } return bo; } private bool Fd1(Nd t, nint n) { if (t.n > n) { if (t.l == du) { return false; } else if (t.l.n != n) { bool bo = Fd1(t.l, n); if (Abs(t.l.l.h - t.l.r.h) > 1) { t.l = Rotate(t.l); } else { Ft(t.l); } return bo; } else { t.l = Fd2(t.l); Ft(t); return true; } } else { if (t.r == du) { return false; } else if (t.r.n != n) { bool bo = Fd1(t.r, n); if (Abs(t.r.l.h - t.r.r.h) > 1) { t.r = Rotate(t.r); } else { Ft(t.r); } return bo; } else { t.r = Fd2(t.r); Ft(t); return true; } } } private Nd Fd2(Nd dn) { cnt--; if (dn.l == du) { return dn.r; } if (dn.r == du) { return dn.l; } Nd u = dn.l; if (u.r == du) { u.r = dn.r; Ft(u); return u; } u = Fd3(u, dn); if (Abs(dn.l.l.h - dn.l.r.h) > 1) { u.l = Rotate(dn.l); } else { Ft(dn.l); } Ft(u); return u; } private Nd Fd3(Nd u, Nd dn) { if (u.r.r != du) { Nd v = Fd3(u.r, dn); if (Abs(u.r.l.h - u.r.r.h) > 1) { u.r = Rotate(u.r); } else { Ft(u.r); } return v; } else { Nd v = u.r; u.r = u.r.l; v.l = dn.l; v.r = dn.r; return v; } } public Nd Hs(nint n) { Nd t = root; if (cnt == 0) { return du; } if (t.n == n) { return t; } Nd a = du; while (true) { if (t.n > n) { if (t.l == du) { break; } else if (t.l.n != n) { t = t.l; } else { a = t.l; break; } } else { if (t.r == du) { break; } else if (t.r.n != n) { t = t.r; } else { a = t.r; break; } } } return a; } public Nd Ra(int n) { return cnt >= n ? Fr(root, n) : du; } private Nd Fr(Nd t, int n) { if (t.l.c > n - 1) { return Fr(t.l, n); } if (t.l.c < n - 1) { return Fr(t.r, n - t.l.c - 1); } return t; } public Nd Lb(nint n) { return cnt != 0 ? Flb(root, n) : du; } private Nd Flb(Nd t, nint n) { if (t.n < n) { if (t.r == du) { return du; } return Flb(t.r, n); } if (t.n > n) { if (t.l == du) { return t; } Nd u = Flb(t.l, n); return u == du ? t : u; } return t; } public Nd Ub(nint n) { return cnt != 0 ? Fub(root, n) : du; } private Nd Fub(Nd t, nint n) { if (t.n > n) { if (t.l == du) { return du; } return Fub(t.l, n); } if (t.n < n) { if (t.r == du) { return t; } Nd u = Fub(t.r, n); return u == du ? t : u; } return t; } public int Rg(nint a, nint b) { return cnt != 0 ? Frg(root, a, b, false, false) : 0; } private int Frg(Nd t, nint a, nint b, bool l, bool r) { if (t.h == 0) { return 0; } if (l && r) { return t.c; } if (t.n < a) { return Frg(t.r, a, b, t.n >= a, r); } if (t.n > b) { return Frg(t.l, a, b, l, t.n <= b); } return Frg(t.l, a, b, l, t.n <= b) + Frg(t.r, a, b, t.n >= a, r) + 1; } public Nd Rd(nint a, nint b) { return cnt != 0 ? Frd(root, a, b, false, false) : du; } private Nd Frd(Nd t, nint a, nint b, bool l, bool r) { if (t.h == 0) { return du; } if (l && r) { return t.nx; } if (t.n < a) { return Frd(t.r, a, b, t.n >= a, r); } if (t.n > b) { return Frd(t.l, a, b, l, t.n <= b); } var e1 = Frd(t.l, a, b, l, t.n <= b); var e2 = Frd(t.r, a, b, t.n >= a, r); e1 = compare(e1.d, e2.d) ? e1 : e2; return compare(t.d, e1.d) ? t : e1; } public Nd Gl(nint a, nint b, long d) { return cnt == 0 ? du : Fgl(root, a, b, d); } private Nd Fgl(Nd t, nint a, nint b, long d) { Nd p = du; if (a <= t.n && t.n <= b && compare(t.d, d)) { p = t; } if (a <= t.n && compare(t.l.nx.d, d)) { var z = Fgl(t.l, a, b, d); if (z != du) { p = z; } } if (p == du && t.n <= b && compare(t.r.nx.d, d)) { p = Fgl(t.r, a, b, d); } return p; } public Nd Gr(nint a, nint b, long d) { return cnt == 0 ? du : Fgr(root, a, b, d); } private Nd Fgr(Nd t, nint a, nint b, long d) { Nd p = du; if (a <= t.n && t.n <= b && compare(t.d, d)) { p = t; } if (t.n <= b && compare(t.r.nx.d, d)) { var z = Fgr(t.r, a, b, d); if (z != du) { p = z; } } if (p == du && a <= t.n && compare(t.l.nx.d, d)) { p = Fgr(t.l, a, b, d); } return p; } public void En(Action<Nd> f) { if (cnt > 0) { Fen(root, f); } } private void Fen(Nd t, Action<Nd> f) { f(t); if (t.l != du) { Fen(t.l, f); } if (t.r != du) { Fen(t.r, f); } } } public class Sc { public int I { get { return int.Parse(Console.ReadLine()); } } public long L { get { return long.Parse(Console.ReadLine()); } } public double D { get { return double.Parse(Console.ReadLine()); } } public string S { get { return Console.ReadLine(); } } public int[] Ia { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } } public long[] La { get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); } } public double[] Da { get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); } } public string[] Sa { get { return Console.ReadLine().Split(); } } public object[] Oa { get { return Console.ReadLine().Split(); } } public int[] Ia2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), int.Parse); } } public int[] Ia3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), int.Parse); } public int[] Ia3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), int.Parse); } public long[] La2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), long.Parse); } } public long[] La3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), long.Parse); } public long[] La3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), long.Parse); } public double[] Da2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), double.Parse); } } public double[] Da3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), double.Parse); } public double[] Da3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), double.Parse); } public T[] Arr<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(); } return a; } public T[] Arr<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(i); } return a; } public T[] Arr<T>(int n, Func<string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(Console.ReadLine().Split()); } return a; } public T[] Arr<T>(int n, Func<int, string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(i, Console.ReadLine().Split()); } return a; } }
using System; using System.Collections.Generic; using System.Collections; using System.Collections.Specialized; using System.Linq; using System.Text; using System.IO; using System.Reflection; using static System.Math; using System.Numerics; using nint = System.Int64; static class Program { const int mod = (int)1e9 + 7; const long inf = (long)1e18; static List<int>[] li; static bool[] b; static int[] h, ans; static Avls avl = new Avls(true, true); static void Main() { Sc sc = new Sc(); var s = sc.Ia; int n = s[0], m = n - 1; li = new List<int>[n + 1]; b = new bool[n + 1]; h = sc.Ia2; ans = new int[n]; for (int i = 1; i <= n; i++) { li[i] = new List<int>(); } for (int i = 0; i < m; i++) { var e = sc.Ia; li[e[0]].Add(e[1]); li[e[1]].Add(e[0]); } Fu(1, 1); Console.WriteLine("{0}", String.Join("\n", ans)); } static void Fu(int a, int g) { b[a] = true; var e = avl.Rd(0, h[a] - 1); var p = e.d < 0 ? 1 : (e.d + 1); g = Max((int)p, g); ans[a - 1] = g; avl.Ud(h[a], a, p); for (int i = 0; i < li[a].Count; i++) { if (!b[li[a][i]]) { Fu(li[a][i], g); } } avl.Dl(h[a], a); } } public class Avls { private const int m = 20, f = (1 << m) - 1; private readonly(long n, long k, long d) dv = (-1, -1, -1); private Avl avl; public Avls(bool bo, bool bb) { avl = new Avl(bo, bb); } public void Ud(nint n, int k, long d) { avl.Ud((n << m) + k, d); } public bool Dl(nint n, int k) { return avl.Dl((n << m) + k); } public (long n, long k, long d) Rd(nint a, nint b) { var e = avl.Rd(a << m, ((b + 1) << m) - 1); return e != avl.du ? (e.n >> m, e.n & f, e.d) : dv; } public (long n, long k, long d) Hs(nint n) { var e = avl.Lb(n << m); return e.n >> m == n ? (e.n >> m, e.n & f, e.d) : dv; } public (long n, long k, long d) Hs(nint n, int k) { var e = avl.Hs((n << m) + k); return e != avl.du ? (e.n >> m, e.n & f, e.d) : dv; } public (long n, long k, long d) Lb(nint n) { var e = avl.Lb(n << m); return e != avl.du ? (e.n >> m, e.n & f, e.d) : dv; } public (long n, long k, long d) Ub(nint n) { var e = avl.Ub(((n + 1) << m) - 1); return e != avl.du ? (e.n >> m, e.n & f, e.d) : dv; } public int Rg(nint a, nint b) { return avl.Rg(a << m, ((b + 1) << m) - 1); } public (long n, long k, long d) Gl(nint a, nint b, long d) { var e = avl.Gl(a << m, ((b + 1) << m) - 1, d); return e != avl.du ? (e.n >> m, e.n & f, e.d) : dv; } public (long n, long k, long d) Gr(nint a, nint b, long d) { var e = avl.Gr(a << m, ((b + 1) << m) - 1, d); return e != avl.du ? (e.n >> m, e.n & f, e.d) : dv; } } public class Avl { public class Nd { public int h = 1, c = 1; public readonly nint n; public long d; public Nd l, r, nx; public Nd(nint n, long d, Nd du) { this.n = n; this.d = d; nx = this; l = du; r = du; } public override string ToString() => "n:" + n.ToString() + " d:" + d.ToString(); } private static Func<long, long, bool> compare; private static Action<Nd> compare2; public Nd root, du; public int cnt = 0; public bool bb; public Avl(bool bo, bool bb) { if (bo) { du = new Nd(nint.MinValue, long.MinValue, du); compare = CoMax; compare2 = CoMax; } else { du = new Nd(nint.MinValue, long.MaxValue, du); compare = CoMin; compare2 = CoMin; } this.bb = bb; du.h = 0; du.c = 0; root = du; } private bool CoMax(long a, long b) { return a >= b; } private bool CoMin(long a, long b) { return a <= b; } private void CoMax(Nd t) { t.nx = t; if (t.nx.d < t.l.nx.d) { t.nx = t.l.nx; } if (t.nx.d < t.r.nx.d) { t.nx = t.r.nx; } } private void CoMin(Nd t) { t.nx = t; if (t.nx.d > t.l.nx.d) { t.nx = t.l.nx; } if (t.nx.d > t.r.nx.d) { t.nx = t.r.nx; } } public void Ud(nint n, long d) { if (root == du) { root = new Nd(n, d, du); cnt++; } else if (root.n == n) { if (bb) { root.d += d; } else { root.d = d; } compare2(root); } else if (Fu(root, n, d)) { if (Abs(root.l.h - root.r.h) > 1) { root = Rotate(root); } cnt++; } } private bool Fu(Nd t, nint n, long d) { bool bo = false; if (t.n > n) { if (t.l != du) { if (t.l.n == n) { if (bb) { t.l.d += d; } else { t.l.d = d; } compare2(t.l); } else if (bo = Fu(t.l, n, d)) { t.c++; if (Abs(t.l.l.h - t.l.r.h) > 1) { t.l = Rotate(t.l); } t.h = Max(t.l.h, t.r.h) + 1; } compare2(t); } else { t.l = new Nd(n, d, du); bo = true; t.c++; t.h = Max(t.l.h, t.r.h) + 1; t.nx = compare(t.nx.d, t.l.d) ? t.nx : t.l; } } else { if (t.r != du) { if (t.r.n == n) { if (bb) { t.r.d += d; } else { t.r.d = d; } compare2(t.r); } else if (bo = Fu(t.r, n, d)) { t.c++; if (Abs(t.r.l.h - t.r.r.h) > 1) { t.r = Rotate(t.r); } t.h = Max(t.l.h, t.r.h) + 1; } compare2(t); } else { t.r = new Nd(n, d, du); bo = true; t.c++; t.h = Max(t.l.h, t.r.h) + 1; t.nx = compare(t.nx.d, t.r.d) ? t.nx : t.r; } } return bo; } private Nd Rotate(Nd t) { Nd nd = du; if (t.l.h > t.r.h) { if (t.l.l.h > t.l.r.h) { nd = t.l; t.l = t.l.r; nd.r = t; Ft(t); } else { nd = t.l.r; t.l.r = nd.l; nd.l = t.l; Ft(t.l); t.l = nd.r; nd.r = t; Ft(t); } } else { if (t.r.l.h > t.r.r.h) { nd = t.r.l; t.r.l = nd.r; nd.r = t.r; Ft(t.r); t.r = nd.l; nd.l = t; Ft(t); } else { nd = t.r; t.r = t.r.l; nd.l = t; Ft(t); } } Ft(nd); return nd; } private void Ft(Nd t) { t.h = Max(t.l.h, t.r.h) + 1; t.c = t.l.c + t.r.c + 1; compare2(t); } public bool Dl(nint n) { if (cnt == 0) { return false; } Nd t = root; if (t.n == n) { root = Fd2(root); if (cnt == 0) { return true; } else if (Abs(root.l.h - root.r.h) > 1) { root = Rotate(root); } else { Ft(root); } return true; } bool bo = Fd1(root, n); if (Abs(root.l.h - root.r.h) > 1) { root = Rotate(root); } else { Ft(root); } return bo; } private bool Fd1(Nd t, nint n) { if (t.n > n) { if (t.l == du) { return false; } else if (t.l.n != n) { bool bo = Fd1(t.l, n); if (Abs(t.l.l.h - t.l.r.h) > 1) { t.l = Rotate(t.l); } else { Ft(t.l); } return bo; } else { t.l = Fd2(t.l); Ft(t); return true; } } else { if (t.r == du) { return false; } else if (t.r.n != n) { bool bo = Fd1(t.r, n); if (Abs(t.r.l.h - t.r.r.h) > 1) { t.r = Rotate(t.r); } else { Ft(t.r); } return bo; } else { t.r = Fd2(t.r); Ft(t); return true; } } } private Nd Fd2(Nd dn) { cnt--; if (dn.l == du) { return dn.r; } if (dn.r == du) { return dn.l; } Nd u = dn.l; if (u.r == du) { u.r = dn.r; Ft(u); return u; } u = Fd3(u, dn); if (Abs(dn.l.l.h - dn.l.r.h) > 1) { u.l = Rotate(dn.l); } else { Ft(dn.l); } Ft(u); return u; } private Nd Fd3(Nd u, Nd dn) { if (u.r.r != du) { Nd v = Fd3(u.r, dn); if (Abs(u.r.l.h - u.r.r.h) > 1) { u.r = Rotate(u.r); } else { Ft(u.r); } return v; } else { Nd v = u.r; u.r = u.r.l; v.l = dn.l; v.r = dn.r; return v; } } public Nd Hs(nint n) { Nd t = root; if (cnt == 0) { return du; } if (t.n == n) { return t; } Nd a = du; while (true) { if (t.n > n) { if (t.l == du) { break; } else if (t.l.n != n) { t = t.l; } else { a = t.l; break; } } else { if (t.r == du) { break; } else if (t.r.n != n) { t = t.r; } else { a = t.r; break; } } } return a; } public Nd Ra(int n) { return cnt >= n ? Fr(root, n) : du; } private Nd Fr(Nd t, int n) { if (t.l.c > n - 1) { return Fr(t.l, n); } if (t.l.c < n - 1) { return Fr(t.r, n - t.l.c - 1); } return t; } public Nd Lb(nint n) { return cnt != 0 ? Flb(root, n) : du; } private Nd Flb(Nd t, nint n) { if (t.n < n) { if (t.r == du) { return du; } return Flb(t.r, n); } if (t.n > n) { if (t.l == du) { return t; } Nd u = Flb(t.l, n); return u == du ? t : u; } return t; } public Nd Ub(nint n) { return cnt != 0 ? Fub(root, n) : du; } private Nd Fub(Nd t, nint n) { if (t.n > n) { if (t.l == du) { return du; } return Fub(t.l, n); } if (t.n < n) { if (t.r == du) { return t; } Nd u = Fub(t.r, n); return u == du ? t : u; } return t; } public int Rg(nint a, nint b) { return cnt != 0 ? Frg(root, a, b, false, false) : 0; } private int Frg(Nd t, nint a, nint b, bool l, bool r) { if (t.h == 0) { return 0; } if (l && r) { return t.c; } if (t.n < a) { return Frg(t.r, a, b, t.n >= a, r); } if (t.n > b) { return Frg(t.l, a, b, l, t.n <= b); } return Frg(t.l, a, b, l, t.n <= b) + Frg(t.r, a, b, t.n >= a, r) + 1; } public Nd Rd(nint a, nint b) { return cnt != 0 ? Frd(root, a, b, false, false) : du; } private Nd Frd(Nd t, nint a, nint b, bool l, bool r) { if (t.h == 0) { return du; } if (l && r) { return t.nx; } if (t.n < a) { return Frd(t.r, a, b, t.n >= a, r); } if (t.n > b) { return Frd(t.l, a, b, l, t.n <= b); } var e1 = Frd(t.l, a, b, l, t.n <= b); var e2 = Frd(t.r, a, b, t.n >= a, r); e1 = compare(e1.d, e2.d) ? e1 : e2; return compare(t.d, e1.d) ? t : e1; } public Nd Gl(nint a, nint b, long d) { return cnt == 0 ? du : Fgl(root, a, b, d); } private Nd Fgl(Nd t, nint a, nint b, long d) { Nd p = du; if (a <= t.n && t.n <= b && compare(t.d, d)) { p = t; } if (a <= t.n && compare(t.l.nx.d, d)) { var z = Fgl(t.l, a, b, d); if (z != du) { p = z; } } if (p == du && t.n <= b && compare(t.r.nx.d, d)) { p = Fgl(t.r, a, b, d); } return p; } public Nd Gr(nint a, nint b, long d) { return cnt == 0 ? du : Fgr(root, a, b, d); } private Nd Fgr(Nd t, nint a, nint b, long d) { Nd p = du; if (a <= t.n && t.n <= b && compare(t.d, d)) { p = t; } if (t.n <= b && compare(t.r.nx.d, d)) { var z = Fgr(t.r, a, b, d); if (z != du) { p = z; } } if (p == du && a <= t.n && compare(t.l.nx.d, d)) { p = Fgr(t.l, a, b, d); } return p; } public void En(Action<Nd> f) { if (cnt > 0) { Fen(root, f); } } private void Fen(Nd t, Action<Nd> f) { f(t); if (t.l != du) { Fen(t.l, f); } if (t.r != du) { Fen(t.r, f); } } } public class Sc { public int I { get { return int.Parse(Console.ReadLine()); } } public long L { get { return long.Parse(Console.ReadLine()); } } public double D { get { return double.Parse(Console.ReadLine()); } } public string S { get { return Console.ReadLine(); } } public int[] Ia { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } } public long[] La { get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); } } public double[] Da { get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); } } public string[] Sa { get { return Console.ReadLine().Split(); } } public object[] Oa { get { return Console.ReadLine().Split(); } } public int[] Ia2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), int.Parse); } } public int[] Ia3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), int.Parse); } public int[] Ia3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), int.Parse); } public long[] La2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), long.Parse); } } public long[] La3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), long.Parse); } public long[] La3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), long.Parse); } public double[] Da2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), double.Parse); } } public double[] Da3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), double.Parse); } public double[] Da3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), double.Parse); } public T[] Arr<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(); } return a; } public T[] Arr<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(i); } return a; } public T[] Arr<T>(int n, Func<string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(Console.ReadLine().Split()); } return a; } public T[] Arr<T>(int n, Func<int, string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(i, Console.ReadLine().Split()); } return a; } }
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
5,282
2
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Runtime.CompilerServices; using System.Text; using System.Diagnostics; using System.Numerics; using static System.Console; using static System.Convert; using static System.Math; using static Template; using Pi = Pair<int, int>; class Solver { int N; int[] A, res; List<int> lis; List<int>[] g; public void Solve(Scanner sc) { N = sc.Int; A = sc.ArrInt; g = Create(N, () => new List<int>()); for (var i = 0; i < N - 1; i++) { int a, b; sc.Make(out a, out b); a--; b--; g[a].Add(b); g[b].Add(a); } res = new int[N]; lis = new List<int>() { A[0] }; dfs(0, -1); Console.WriteLine(string.Join("\n", res)); } void dfs(int i, int p) { int q = -1, j = -1, last = -1; if (i != 0) { if (lis.Last() < A[i]) { q = 0; lis.Add(A[i]); } else { var lw = UpperBound(lis, A[i]); q = 1; j = lw; last = lis[lw]; lis[lw] = A[i]; } } res[i] = lis.Count; foreach (var e in g[i]) { if (e == p) continue; dfs(e, i); } if (i == 0) return; if (q == 0) lis.PopBack(); else lis[j] = last; } #region UpperBound / LowerBound public static int UpperBound<T>(IList<T> array, T value, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; var low = -1; var high = array.Count; while (high - low > 1) { var mid = (high + low) / 2; if (cmp(array[mid], value) == 1) high = mid; else low = mid; } return high; } public static int LowerBound<T>(IList<T> array, T value, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; var low = -1; var high = array.Count; while (high - low > 1) { var mid = (high + low) / 2; if (cmp(array[mid], value) != -1) high = mid; else low = mid; } return high; } #endregion } #region Template public static class Template { static void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new Solver().Solve(new Scanner()); Console.Out.Flush(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) > 0) { a = b; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void swap<T>(ref T a, ref T b) { var t = b; b = a; a = t; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void swap<T>(this IList<T> A, int i, int j) { var t = A[i]; A[i] = A[j]; A[j] = t; } public static T[] Create<T>(int n, Func<T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; } public static T[] Create<T>(int n, Func<int, T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; } public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> A) => A.OrderBy(v => Guid.NewGuid()); public static int CompareTo<T>(this T[] A, T[] B, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; for (var i = 0; i < Min(A.Length, B.Length); i++) { int c = cmp(A[i], B[i]); if (c > 0) return 1; else if (c < 0) return -1; } if (A.Length == B.Length) return 0; if (A.Length > B.Length) return 1; else return -1; } public static int MaxElement<T>(this IList<T> A, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; T max = A[0]; int rt = 0; for (int i = 1; i < A.Count; i++) if (cmp(max, A[i]) < 0) { max = A[i]; rt = i; } return rt; } public static T PopBack<T>(this List<T> A) { var v = A[A.Count - 1]; A.RemoveAt(A.Count - 1); return v; } public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); } } public class Scanner { public string Str => Console.ReadLine().Trim(); public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray(); public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray(); public char[][] Grid(int n) => Create(n, () => Str.ToCharArray()); public int[] ArrInt1D(int n) => Create(n, () => Int); public long[] ArrLong1D(int n) => Create(n, () => Long); public int[][] ArrInt2D(int n) => Create(n, () => ArrInt); public long[][] ArrLong2D(int n) => Create(n, () => ArrLong); private Queue<string> q = new Queue<string>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); } public void Make<T1>(out T1 v1) => v1 = Next<T1>(); public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); } public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); } public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); } // public (T1, T2) Make<T1, T2>() { Make(out T1 v1, out T2 v2); return (v1, // v2); } public (T1, T2, T3) Make<T1, T2, T3>() { Make(out T1 v1, out T2 v2, // out T3 v3); return (v1, v2, v3); } public (T1, T2, T3, T4) Make<T1, T2, T3, // T4>() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2, // v3, v4); } } public class Pair<T1, T2> : IComparable<Pair<T1, T2>> { public T1 v1; public T2 v2; public Pair() {} public Pair(T1 v1, T2 v2) { this.v1 = v1; this.v2 = v2; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2> p) { var c = Comparer<T1>.Default.Compare(v1, p.v1); if (c == 0) c = Comparer<T2>.Default.Compare(v2, p.v2); return c; } public override string ToString() => $"{v1.ToString()} {v2.ToString()}"; public void Deconstruct(out T1 a, out T2 b) { a = v1; b = v2; } } public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> { public T3 v3; public Pair() : base() {} public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2, T3> p) { var c = base.CompareTo(p); if (c == 0) c = Comparer<T3>.Default.Compare(v3, p.v3); return c; } public override string ToString() => $"{base.ToString()} {v3.ToString()}"; public void Deconstruct(out T1 a, out T2 b, out T3 c) { Deconstruct(out a, out b); c = v3; } } #endregion
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Runtime.CompilerServices; using System.Text; using System.Diagnostics; using System.Numerics; using static System.Console; using static System.Convert; using static System.Math; using static Template; using Pi = Pair<int, int>; class Solver { int N; int[] A, res; List<int> lis; List<int>[] g; public void Solve(Scanner sc) { N = sc.Int; A = sc.ArrInt; g = Create(N, () => new List<int>()); for (var i = 0; i < N - 1; i++) { int a, b; sc.Make(out a, out b); a--; b--; g[a].Add(b); g[b].Add(a); } res = new int[N]; lis = new List<int>() { A[0] }; dfs(0, -1); Console.WriteLine(string.Join("\n", res)); } void dfs(int i, int p) { int q = -1, j = -1, last = -1; if (i != 0) { if (lis.Last() < A[i]) { q = 0; lis.Add(A[i]); } else { var lw = LowerBound(lis, A[i]); q = 1; j = lw; last = lis[lw]; lis[lw] = A[i]; } } res[i] = lis.Count; foreach (var e in g[i]) { if (e == p) continue; dfs(e, i); } if (i == 0) return; if (q == 0) lis.PopBack(); else lis[j] = last; } #region UpperBound / LowerBound public static int UpperBound<T>(IList<T> array, T value, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; var low = -1; var high = array.Count; while (high - low > 1) { var mid = (high + low) / 2; if (cmp(array[mid], value) == 1) high = mid; else low = mid; } return high; } public static int LowerBound<T>(IList<T> array, T value, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; var low = -1; var high = array.Count; while (high - low > 1) { var mid = (high + low) / 2; if (cmp(array[mid], value) != -1) high = mid; else low = mid; } return high; } #endregion } #region Template public static class Template { static void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new Solver().Solve(new Scanner()); Console.Out.Flush(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) > 0) { a = b; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void swap<T>(ref T a, ref T b) { var t = b; b = a; a = t; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void swap<T>(this IList<T> A, int i, int j) { var t = A[i]; A[i] = A[j]; A[j] = t; } public static T[] Create<T>(int n, Func<T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; } public static T[] Create<T>(int n, Func<int, T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; } public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> A) => A.OrderBy(v => Guid.NewGuid()); public static int CompareTo<T>(this T[] A, T[] B, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; for (var i = 0; i < Min(A.Length, B.Length); i++) { int c = cmp(A[i], B[i]); if (c > 0) return 1; else if (c < 0) return -1; } if (A.Length == B.Length) return 0; if (A.Length > B.Length) return 1; else return -1; } public static int MaxElement<T>(this IList<T> A, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; T max = A[0]; int rt = 0; for (int i = 1; i < A.Count; i++) if (cmp(max, A[i]) < 0) { max = A[i]; rt = i; } return rt; } public static T PopBack<T>(this List<T> A) { var v = A[A.Count - 1]; A.RemoveAt(A.Count - 1); return v; } public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); } } public class Scanner { public string Str => Console.ReadLine().Trim(); public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray(); public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray(); public char[][] Grid(int n) => Create(n, () => Str.ToCharArray()); public int[] ArrInt1D(int n) => Create(n, () => Int); public long[] ArrLong1D(int n) => Create(n, () => Long); public int[][] ArrInt2D(int n) => Create(n, () => ArrInt); public long[][] ArrLong2D(int n) => Create(n, () => ArrLong); private Queue<string> q = new Queue<string>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); } public void Make<T1>(out T1 v1) => v1 = Next<T1>(); public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); } public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); } public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); } // public (T1, T2) Make<T1, T2>() { Make(out T1 v1, out T2 v2); return (v1, // v2); } public (T1, T2, T3) Make<T1, T2, T3>() { Make(out T1 v1, out T2 v2, // out T3 v3); return (v1, v2, v3); } public (T1, T2, T3, T4) Make<T1, T2, T3, // T4>() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2, // v3, v4); } } public class Pair<T1, T2> : IComparable<Pair<T1, T2>> { public T1 v1; public T2 v2; public Pair() {} public Pair(T1 v1, T2 v2) { this.v1 = v1; this.v2 = v2; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2> p) { var c = Comparer<T1>.Default.Compare(v1, p.v1); if (c == 0) c = Comparer<T2>.Default.Compare(v2, p.v2); return c; } public override string ToString() => $"{v1.ToString()} {v2.ToString()}"; public void Deconstruct(out T1 a, out T2 b) { a = v1; b = v2; } } public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> { public T3 v3; public Pair() : base() {} public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2, T3> p) { var c = base.CompareTo(p); if (c == 0) c = Comparer<T3>.Default.Compare(v3, p.v3); return c; } public override string ToString() => $"{base.ToString()} {v3.ToString()}"; public void Deconstruct(out T1 a, out T2 b, out T3 c) { Deconstruct(out a, out b); c = v3; } } #endregion
[["-", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22]]
8
2,298
2
using System; using System.Collections.Generic; using System.Linq; using CompLib.Util; public class Program { int N; int[] A; List<int>[] Edge; int Len; int[] Stack; int[] Ans; public void Solve() { var sc = new Scanner(); N = sc.NextInt(); A = sc.IntArray(); Edge = new List<int>[N]; for (int i = 0; i < N; i++) { Edge[i] = new List<int>(); } for (int i = 0; i < N - 1; i++) { int u = sc.NextInt() - 1; int v = sc.NextInt() - 1; Edge[u].Add(v); Edge[v].Add(u); } Stack = new int[N]; for (int i = 0; i < N; i++) { Stack[i] = int.MaxValue; } Len = 0; Ans = new int[N]; DFS(0, -1); Console.WriteLine(string.Join("\n", Ans)); } void DFS(int pos, int parent) { // 超えないところ int ok = -1; int ng = Len; while (ng - ok > 1) { int mid = (ok + ng) / 2; if (Stack[mid] <= A[pos]) ok = mid; else ng = mid; } int pLen = Len; int prev = Stack[ng]; if (ng >= Len) Len++; Stack[ng] = Math.Min(Stack[ng], A[pos]); Ans[pos] = Len; foreach (var to in Edge[pos]) { if (to == parent) continue; DFS(to, pos); } Len = pLen; Stack[ng] = prev; } public static void Main(string[] args) => new Program().Solve(); } namespace CompLib.Util { using System; using System.Linq; class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
using System; using System.Collections.Generic; using System.Linq; using CompLib.Util; public class Program { int N; int[] A; List<int>[] Edge; int Len; int[] Stack; int[] Ans; public void Solve() { var sc = new Scanner(); N = sc.NextInt(); A = sc.IntArray(); Edge = new List<int>[N]; for (int i = 0; i < N; i++) { Edge[i] = new List<int>(); } for (int i = 0; i < N - 1; i++) { int u = sc.NextInt() - 1; int v = sc.NextInt() - 1; Edge[u].Add(v); Edge[v].Add(u); } Stack = new int[N]; for (int i = 0; i < N; i++) { Stack[i] = int.MaxValue; } Len = 0; Ans = new int[N]; DFS(0, -1); Console.WriteLine(string.Join("\n", Ans)); } void DFS(int pos, int parent) { // 超えないところ int ok = -1; int ng = Len; while (ng - ok > 1) { int mid = (ok + ng) / 2; if (Stack[mid] < A[pos]) ok = mid; else ng = mid; } int pLen = Len; int prev = Stack[ng]; if (ng >= Len) Len++; Stack[ng] = Math.Min(Stack[ng], A[pos]); Ans[pos] = Len; foreach (var to in Edge[pos]) { if (to == parent) continue; DFS(to, pos); } Len = pLen; Stack[ng] = prev; } public static void Main(string[] args) => new Program().Solve(); } namespace CompLib.Util { using System; using System.Linq; class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
[["-", 0, 52, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 17, 18]]
8
734
2
using System; using static System.Console; using static System.Math; using System.Numerics; using System.Collections.Generic; using System.Linq; public class Program { public static void Main(string[] args) { var s = myRead.readIntArray(); var ans = (s[0] > 2 * s[1]) ? "safe" : "unsafe"; WriteLine(ans); } } public static class myRead { public static int readInt() { return int.Parse(ReadLine()); } public static long readLong() { return long.Parse(ReadLine()); } public static string reatStr() { return ReadLine(); } public static int[] readIntArray() { return ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long[] readLongArray() { return ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static string[] readStrArray() { return ReadLine().Split(' '); } } public static class MyMath { public static long Factorical(long n) { return n <= 1 ? 1L : n * Factorical(n - 1); } public static long Permutation(long n, long m) { return m == 0 ? 1L : (m == n) ? Permutation(n, m - 1) : n * Permutation(n - 1, m - 1); } public static long Combination(long n, long m) { return n - m > m ? Permutation(n, m) / Factorical(m) : Permutation(n, n - m) / Factorical(n - m); } public static long Gcd(long n, long m) { return n % m == 0 ? m : Gcd(m, n % m); } public static long Lcm(long n, long m) { return n * m / Gcd(n, m); } public static long Pow(long n, long m) { return m == 0 ? 1L : m == 1 ? n : n * Pow(n, m - 1); } }
using System; using static System.Console; using static System.Math; using System.Numerics; using System.Collections.Generic; using System.Linq; public class Program { public static void Main(string[] args) { var s = myRead.readIntArray(); var ans = (s[0] > s[1]) ? "safe" : "unsafe"; WriteLine(ans); } } public static class myRead { public static int readInt() { return int.Parse(ReadLine()); } public static long readLong() { return long.Parse(ReadLine()); } public static string reatStr() { return ReadLine(); } public static int[] readIntArray() { return ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long[] readLongArray() { return ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static string[] readStrArray() { return ReadLine().Split(' '); } } public static class MyMath { public static long Factorical(long n) { return n <= 1 ? 1L : n * Factorical(n - 1); } public static long Permutation(long n, long m) { return m == 0 ? 1L : (m == n) ? Permutation(n, m - 1) : n * Permutation(n - 1, m - 1); } public static long Combination(long n, long m) { return n - m > m ? Permutation(n, m) / Factorical(m) : Permutation(n, n - m) / Factorical(n - m); } public static long Gcd(long n, long m) { return n % m == 0 ? m : Gcd(m, n % m); } public static long Lcm(long n, long m) { return n * m / Gcd(n, m); } public static long Pow(long n, long m) { return m == 0 ? 1L : m == 1 ? n : n * Pow(n, m - 1); } }
[["-", 0, 41, 15, 23, 0, 16, 12, 16, 31, 203], ["-", 0, 41, 15, 23, 0, 16, 12, 16, 17, 48]]
8
452
2
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { var S = cin.ReadInt; var W = cin.ReadInt; WriteLine(S <= W ? "safe" : "unsafe"); } public void Display(int[] array) { var txt = ""; foreach (var item in array) { txt += " " + item.ToString(); } WriteLine("{0}", txt); } public void Display(int index, int[] array) { var txt = ""; foreach (var item in array) { txt += " " + item.ToString(); } WriteLine("{0} : {1}", index, txt); } public void Display(List<int>[] list) { for (int i = 0; i < list.Length; i++) { Display(i, list[i].ToArray()); } } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; i++) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { var S = cin.ReadInt; var W = cin.ReadInt; WriteLine(S > W ? "safe" : "unsafe"); } public void Display(int[] array) { var txt = ""; foreach (var item in array) { txt += " " + item.ToString(); } WriteLine("{0}", txt); } public void Display(int index, int[] array) { var txt = ""; foreach (var item in array) { txt += " " + item.ToString(); } WriteLine("{0} : {1}", index, txt); } public void Display(List<int>[] list) { for (int i = 0; i < list.Length; i++) { Display(i, list[i].ToArray()); } } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; i++) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
[["-", 3, 4, 0, 28, 0, 41, 15, 16, 17, 19], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 47]]
8
598
2
using System; using System.Collections.Generic; using System.Linq; using System.Numerics; namespace atcoder { class Program { static void Main(string[] args) { var sw = Console.ReadLine().Split(' ').Select(num => int.Parse(num)).ToArray(); Console.WriteLine(sw[0] >= sw[1] ? "safe" : "unsafe"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Numerics; namespace atcoder { class Program { static void Main(string[] args) { var sw = Console.ReadLine().Split(' ').Select(num => int.Parse(num)).ToArray(); Console.WriteLine(sw[0] > sw[1] ? "safe" : "unsafe"); } } }
[["-", 3, 4, 0, 28, 0, 41, 15, 16, 17, 20], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 47]]
8
94
2
using System; namespace abc164A { class MainClass { public static void Main(string[] args) { string[] str = Console.ReadLine().Split(); int A = int.Parse(str[0]); int B = int.Parse(str[1]); if (A > B) Console.WriteLine("Safe"); else Console.WriteLine("Unsafe"); } } }
using System; namespace abc164A { class MainClass { public static void Main(string[] args) { string[] str = Console.ReadLine().Split(); int A = int.Parse(str[0]); int B = int.Parse(str[1]); if (A > B) Console.WriteLine("safe"); else Console.WriteLine("unsafe"); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
89
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; namespace ABC { class Program { static void Main(string[] args) { if (args.Length > 0) { Console.SetIn(new StreamReader(args[0])); } var line = Console.ReadLine(); var sa = line.Split(' '); int s = int.Parse(sa[0]); int w = int.Parse(sa[1]); proc(s, w); } private static void proc(int s, int w) { Console.WriteLine(s / 2 > w ? "safe" : "unsafe"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; namespace ABC { class Program { static void Main(string[] args) { if (args.Length > 0) { Console.SetIn(new StreamReader(args[0])); } var line = Console.ReadLine(); var sa = line.Split(' '); int s = int.Parse(sa[0]); int w = int.Parse(sa[1]); proc(s, w); } private static void proc(int s, int w) { Console.WriteLine(s > w ? "safe" : "unsafe"); } } }
[["-", 0, 28, 0, 41, 15, 16, 31, 16, 17, 85], ["-", 0, 28, 0, 41, 15, 16, 31, 16, 12, 203]]
8
161
2
using System; class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); int Sheep = int.Parse(str[0]); int Wolves = int.Parse(str[1]); if (Wolves > Sheep) { Console.WriteLine("safe"); } else { Console.WriteLine("unsafe"); } } }
using System; class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); int Sheep = int.Parse(str[0]); int Wolves = int.Parse(str[1]); if (Wolves < Sheep) { Console.WriteLine("safe"); } else { Console.WriteLine("unsafe"); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18]]
8
91
2
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; namespace Atcoder { public class Program { public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); } private static object GetResult() { var input = ReadLongs(); long sheepcnt = input[0]; long wolfcnt = input[1]; if (sheepcnt < wolfcnt) { return "unsafe"; } return "safe"; } #region Console 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 List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); } #endregion } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; namespace Atcoder { public class Program { public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); } private static object GetResult() { var input = ReadLongs(); long sheepcnt = input[0]; long wolfcnt = input[1]; if (sheepcnt <= wolfcnt) { return "unsafe"; } return "safe"; } #region Console 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 List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); } #endregion } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19]]
8
217
2
using System; using System.Linq; namespace ConsoleApp1 { public class Class1 { static void Main(string[] args) { int[] nums = Console.ReadLine() .Trim() .Split(' ') .Select(_ => int.Parse(_)) .ToArray(); if (nums[0] < nums[1]) { Console.Write("safe"); } else { Console.Write("unsafe"); } } } }
using System; using System.Linq; namespace ConsoleApp1 { public class Class1 { static void Main(string[] args) { int[] nums = Console.ReadLine() .Trim() .Split(' ') .Select(_ => int.Parse(_)) .ToArray(); if (nums[0] > nums[1]) { Console.Write("safe"); } else { Console.Write("unsafe"); } } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47]]
8
101
2
// ABC164 // a.cs using System; class A { public static void Main() { int sheep; int wolf; string[] str = Console.ReadLine().Split(' '); sheep = int.Parse(str[0]); wolf = int.Parse(str[1]); if (sheep >= wolf) { Console.WriteLine("safe"); } else { Console.WriteLine("unsafe"); } } }
// ABC164 // a.cs using System; class A { public static void Main() { int sheep; int wolf; string[] str = Console.ReadLine().Split(' '); sheep = int.Parse(str[0]); wolf = int.Parse(str[1]); if (sheep > wolf) { Console.WriteLine("safe"); } else { Console.WriteLine("unsafe"); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47]]
8
94
2
using System; using System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.Contracts; using System.Linq; namespace at_coder { #if TEST [TestClass] #endif public class Test_164_a { #if TEST public static void Test_Main() #else public static void Main() #endif { int s, w; ReadInt(out s, out w); if (w > s) { Write("unsafe"); } else { Write("safe"); } } private static void Write(string s) { Console.WriteLine(s); } private static int[] ReadIntArray() { string[] ss = Console.ReadLine().Split( new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); int[] ar = new int[ss.Length]; for (int i = 0; i < ss.Length; i++) { ar[i] = int.Parse(ss[i]); } return ar; } private static int ReadInt() { return int.Parse(Console.ReadLine()); } private static void ReadInt(out int a, out int b) { var ar = ReadIntArray(); a = ar[0]; b = ar[1]; } private static void ReadInt(out int a, out int b, out int c) { var ar = ReadIntArray(); a = ar[0]; b = ar[1]; c = ar[2]; } private static string ReadString() { return Console.ReadLine(); } private static string[] ReadStringArray() { string[] ss = Console.ReadLine().Split( new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); return ss; } #if !TEST } } #endif
using System; using System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.Contracts; using System.Linq; namespace at_coder { #if TEST [TestClass] #endif public class Test_164_a { #if TEST public static void Test_Main() #else public static void Main() #endif { int s, w; ReadInt(out s, out w); if (w >= s) { Write("unsafe"); } else { Write("safe"); } } private static void Write(string s) { Console.WriteLine(s); } private static int[] ReadIntArray() { string[] ss = Console.ReadLine().Split( new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); int[] ar = new int[ss.Length]; for (int i = 0; i < ss.Length; i++) { ar[i] = int.Parse(ss[i]); } return ar; } private static int ReadInt() { return int.Parse(Console.ReadLine()); } private static void ReadInt(out int a, out int b) { var ar = ReadIntArray(); a = ar[0]; b = ar[1]; } private static void ReadInt(out int a, out int b, out int c) { var ar = ReadIntArray(); a = ar[0]; b = ar[1]; c = ar[2]; } private static string ReadString() { return Console.ReadLine(); } private static string[] ReadStringArray() { string[] ss = Console.ReadLine().Split( new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); return ss; } #if !TEST } } #endif
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20]]
8
374
2
using System; using System.Linq; using System.Collections.Generic; namespace AtCoder { class Program { public static void Main() { var intArray = IO.ReadIntArray(); IO.Write(intArray[0] > intArray[1] ? "unsafe" : "safe"); } } public static class IO { public static string Read() { return Console.ReadLine(); } public static string[] ReadArray(char iSplitter = ' ') { return Read().Split(iSplitter); } public static int ReadInt() { return int.Parse(Read()); } public static int[] ReadIntArray(char iSplitter = ' ') { return ReadArray().Select(iText => int.Parse(iText)).ToArray(); } public static long ReadLong() { return int.Parse(Read()); } public static long[] ReadLongArray(char iSplitter = ' ') { return ReadArray().Select(iText => long.Parse(iText)).ToArray(); } public static double ReadDouble() { return double.Parse(Read()); } public static double[] ReadDoubleArray(char iSplitter = ' ') { return ReadArray().Select(iText => double.Parse(iText)).ToArray(); } public static char[] ReadCharArray() { return Read().ToCharArray(); } public static void Write(string iValue) { Console.WriteLine(iValue); } public static void Write(int iValue) { Console.WriteLine(iValue); } public static void Write(IEnumerable<int> iValue, string iJoinWord = " ") { Console.WriteLine(string.Join(iJoinWord, iValue)); } public static void Write(long iValue) { Console.WriteLine(iValue); } public static void Write(double iValue) { Console.WriteLine(iValue); } public static void Write(decimal iValue) { Console.WriteLine(iValue); } public static void Write(bool iValue) { Console.WriteLine(iValue ? "Yes" : "No"); } } public static class Util { public static long Gcd(long i0, long i1) { return (i0 > i1) ? _Gcd(i0, i1) : _Gcd(i1, i0); } public static long Lcm(long i0, long i1) { return (i0 * i1) / Gcd(i0, i1); } public static long ModPow(long iBaseNumber, long iPow, long iModNumber) { var num = 1L; while (iPow != 0) { if ((iPow & 0x1) != 0) { num = (num * iBaseNumber) % iModNumber; } iBaseNumber = (iBaseNumber * iBaseNumber) % iModNumber; iPow >>= 1; } return num; } public static long CombinationNum(int iLeftNumber, int iRightNumber) { if (iRightNumber == 0) { return 1; } if (iLeftNumber == 0) { return 0; } return iLeftNumber * CombinationNum(iLeftNumber - 1, iRightNumber - 1) / iRightNumber; } private static long _Gcd(long i0, long i1) { return (i1 == 0) ? i0 : _Gcd(i1, i0 % i1); } } }
using System; using System.Linq; using System.Collections.Generic; namespace AtCoder { class Program { public static void Main() { var intArray = IO.ReadIntArray(); IO.Write(intArray[0] > intArray[1] ? "safe" : "unsafe"); } } public static class IO { public static string Read() { return Console.ReadLine(); } public static string[] ReadArray(char iSplitter = ' ') { return Read().Split(iSplitter); } public static int ReadInt() { return int.Parse(Read()); } public static int[] ReadIntArray(char iSplitter = ' ') { return ReadArray().Select(iText => int.Parse(iText)).ToArray(); } public static long ReadLong() { return int.Parse(Read()); } public static long[] ReadLongArray(char iSplitter = ' ') { return ReadArray().Select(iText => long.Parse(iText)).ToArray(); } public static double ReadDouble() { return double.Parse(Read()); } public static double[] ReadDoubleArray(char iSplitter = ' ') { return ReadArray().Select(iText => double.Parse(iText)).ToArray(); } public static char[] ReadCharArray() { return Read().ToCharArray(); } public static void Write(string iValue) { Console.WriteLine(iValue); } public static void Write(int iValue) { Console.WriteLine(iValue); } public static void Write(IEnumerable<int> iValue, string iJoinWord = " ") { Console.WriteLine(string.Join(iJoinWord, iValue)); } public static void Write(long iValue) { Console.WriteLine(iValue); } public static void Write(double iValue) { Console.WriteLine(iValue); } public static void Write(decimal iValue) { Console.WriteLine(iValue); } public static void Write(bool iValue) { Console.WriteLine(iValue ? "Yes" : "No"); } } public static class Util { public static long Gcd(long i0, long i1) { return (i0 > i1) ? _Gcd(i0, i1) : _Gcd(i1, i0); } public static long Lcm(long i0, long i1) { return (i0 * i1) / Gcd(i0, i1); } public static long ModPow(long iBaseNumber, long iPow, long iModNumber) { var num = 1L; while (iPow != 0) { if ((iPow & 0x1) != 0) { num = (num * iBaseNumber) % iModNumber; } iBaseNumber = (iBaseNumber * iBaseNumber) % iModNumber; iPow >>= 1; } return num; } public static long CombinationNum(int iLeftNumber, int iRightNumber) { if (iRightNumber == 0) { return 1; } if (iLeftNumber == 0) { return 0; } return iLeftNumber * CombinationNum(iLeftNumber - 1, iRightNumber - 1) / iRightNumber; } private static long _Gcd(long i0, long i1) { return (i1 == 0) ? i0 : _Gcd(i1, i0 % i1); } } }
[["-", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["-", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222]]
8
655
4
using System; namespace test1 { class Program { static void Main(string[] args) { string ab = Console.ReadLine(); if (int.Parse(ab.Split(' ')[0]) < int.Parse(ab.Split(' ')[1])) { Console.WriteLine("unsafe"); } else { Console.WriteLine("safe"); } } } }
using System; namespace ConsoleApp1 { class Program { static void Main(string[] args) { string ab = Console.ReadLine(); if (int.Parse(ab.Split(' ')[0]) <= int.Parse(ab.Split(' ')[1])) { Console.WriteLine("unsafe"); } else { Console.WriteLine("safe"); } } } }
[["-", 36, 36, 36, 36, 0, 208, 0, 209, 141, 22], ["+", 36, 36, 36, 36, 0, 208, 0, 209, 141, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19]]
8
90
4
using System; using System.Linq; namespace AtCoderMake.ABC161 { class ABC161C { static void Main(string[] args) { var input = Console.ReadLine().Split(' ').Select((x) => int.Parse(x)).ToArray(); int par = input[0] % input[1]; int bar = input[1] - par; if (par >= bar) { Console.WriteLine(bar.ToString()); } else { Console.WriteLine(par.ToString()); } } } }
using System; using System.Linq; namespace AtCoderMake.ABC161 { class ABC161C { static void Main(string[] args) { var input = Console.ReadLine().Split(' ').Select((x) => long.Parse(x)).ToArray(); long par = input[0] % input[1]; long bar = input[1] - par; if (par >= bar) { Console.WriteLine(bar.ToString()); } else { Console.WriteLine(par.ToString()); } } } }
[["-", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199], ["+", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
119
6
using System.Collections; using System.Text; using System.Threading.Tasks; using static System.Math; using static System.Console; using System.Collections.Generic; using System.Linq; using System; using System.Numerics; class Program { static void Main() { int[] NK = ReadInts; int N = NK[0]; int K = NK[1]; N %= K; WriteLine(Min(N, K - N)); ReadLine(); } public static long GetInv(long a, long mod) { return PowerMod(a, mod - 2, mod); } public static long Combination(long a, long b, long mod) { if (b < 0 || b > a) return 0; if (b > a / 2) b = a - b; long numerator = Factorial(a, mod); long denominator = (Factorial(b, mod) * Factorial(a - b, mod)) % mod; return (numerator * GetInv(denominator, mod)) % mod; } public static long Factorial(long n, long mod) { if (n == 0) return 1; if (n == 1) return 1; long ans = n; for (int i = 2; i < n; i++) { ans = (ans * i) % mod; } return ans; } private static long PowerMod(long a, long n, long mod) { if (n == 1) return a; long p = PowerMod(a, n / 2, mod); if (n % 2 == 1) return ((p * p) % mod * a) % mod; else return (p * p) % mod; } struct Vector2Int { public Vector2Int(int x, int y) { X = x; Y = y; } public int X; public int Y; public double Magnitude => Math.Sqrt(X * X + Y * Y); public static Vector2Int zero => new Vector2Int(0, 0); public static Vector2Int u => new Vector2Int(0, 1); public static Vector2Int r => new Vector2Int(1, 0); public static Vector2Int d => new Vector2Int(0, -1); public static Vector2Int l => new Vector2Int(-1, 0); public static Vector2Int[] AllDirections => new Vector2Int[4] { u, r, d, l }; public static Vector2Int[] AllDirections8 => new Vector2Int[8] { u, r, d, l, u + r, r + d, d + l, l + u }; public static Vector2Int operator +(Vector2Int a, Vector2Int b) { return new Vector2Int(a.X + b.X, a.Y + b.Y); } public static Vector2Int operator -(Vector2Int a, Vector2Int b) { return new Vector2Int(a.X - b.X, a.Y - b.Y); } public static bool operator ==(Vector2Int a, Vector2Int b) { return a.X == b.X && a.Y == b.Y; } public static bool operator !=(Vector2Int a, Vector2Int b) { return a.X != b.X || a.Y != b.Y; } public static Vector2Int operator *(Vector2Int v, int n) { return new Vector2Int(v.X * n, v.Y * n); } public static Vector2Int operator *(int n, Vector2Int v) { return new Vector2Int(v.X * n, v.Y * n); } } struct Vector3Int { public Vector3Int(int x, int y, int z) { X = x; Y = y; Z = z; } public int X; public int Y; public int Z; public double Magnitude => Math.Sqrt(X * X + Y * Y + Z * Z); public static Vector3Int zero => new Vector3Int(0, 0, 0); public static Vector3Int u => new Vector3Int(0, 1, 0); public static Vector3Int r => new Vector3Int(1, 0, 0); public static Vector3Int d => new Vector3Int(0, -1, 0); public static Vector3Int l => new Vector3Int(-1, 0, 0); public static Vector3Int operator +(Vector3Int a, Vector3Int b) { return new Vector3Int(a.X + b.X, a.Y + b.Y, a.Z + b.Z); } public static Vector3Int operator -(Vector3Int a, Vector3Int b) { return new Vector3Int(a.X - b.X, a.Y - b.Y, a.Z - b.Z); } public static bool operator ==(Vector3Int a, Vector3Int b) { return a.X == b.X && a.Y == b.Y && a.Z == b.Z; } public static bool operator !=(Vector3Int a, Vector3Int b) { return a.X != b.X || a.Y != b.Y || a.Z != b.Z; } public static Vector3Int operator *(Vector3Int v, int n) { return new Vector3Int(v.X * n, v.Y * n, v.Z * n); } public static Vector3Int operator *(int n, Vector3Int v) { return new Vector3Int(v.X * n, v.Y * n, v.Z * n); } } #region Reader static Vector2Int ReadVec2Int { get { string[] s = Console.ReadLine().Split(' '); return new Vector2Int(int.Parse(s[0]), int.Parse(s[1])); } } static Vector2Int[] ReadVec2Ints(int n) { List<Vector2Int> list = new List<Vector2Int>(); for (int i = 0; i < n; ++i) { var ab = ReadInts; list.Add(new Vector2Int(ab[0], ab[1])); } return list.ToArray(); } static HashSet<Vector2Int> ReadVec2IntHash(int n) { HashSet<Vector2Int> hash = new HashSet<Vector2Int>(); for (int i = 0; i < n; ++i) { var ab = ReadInts; hash.Add(new Vector2Int(ab[0], ab[1])); } return hash; } static string ReadStr => Console.ReadLine(); static string[] ReadStrs => Console.ReadLine().Split(' '); static int ReadInt => Convert.ToInt32(Console.ReadLine()); static int[] ReadInts => Console.ReadLine().Split(' ').Select(s => Convert.ToInt32(s)).ToArray(); static long ReadLong => Convert.ToInt64(Console.ReadLine()); static long[] ReadLongs => Console.ReadLine().Split(' ').Select(s => Convert.ToInt64(s)).ToArray(); static long[,] ReLongMatrix(int r, int c) { var mat = new long[r, c]; for (int i = 0; i < r; ++i) { var x = ReadLongs; for (int j = 0; j < c; ++j) { mat[i, j] = x[j]; } } return mat; } static Tuple<string, string>[] ReTupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = ReadStrs; list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<long, long>[] ReTupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = ReadLongs; list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<int, int>[] ReadTupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = ReadInts; list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<double, double>[] ReTupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = ReadLongs; list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); } static Dictionary<int, HashSet<int>> ReAdjacencyList(int N, int M) { Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new HashSet<int>()); } for (int i = 0; i < M; ++i) { var ab = ReadInts; dict[ab[0]].Add(ab[1]); dict[ab[1]].Add(ab[0]); } return dict; } #endregion static void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } static long mod = (int)Pow(10, 9) + 7; }
using System.Collections; using System.Text; using System.Threading.Tasks; using static System.Math; using static System.Console; using System.Collections.Generic; using System.Linq; using System; using System.Numerics; class Program { static void Main() { long[] NK = ReadLongs; long N = NK[0]; long K = NK[1]; N %= K; WriteLine(Min(N, K - N)); ReadLine(); } public static long GetInv(long a, long mod) { return PowerMod(a, mod - 2, mod); } public static long Combination(long a, long b, long mod) { if (b < 0 || b > a) return 0; if (b > a / 2) b = a - b; long numerator = Factorial(a, mod); long denominator = (Factorial(b, mod) * Factorial(a - b, mod)) % mod; return (numerator * GetInv(denominator, mod)) % mod; } public static long Factorial(long n, long mod) { if (n == 0) return 1; if (n == 1) return 1; long ans = n; for (int i = 2; i < n; i++) { ans = (ans * i) % mod; } return ans; } private static long PowerMod(long a, long n, long mod) { if (n == 1) return a; long p = PowerMod(a, n / 2, mod); if (n % 2 == 1) return ((p * p) % mod * a) % mod; else return (p * p) % mod; } struct Vector2Int { public Vector2Int(int x, int y) { X = x; Y = y; } public int X; public int Y; public double Magnitude => Math.Sqrt(X * X + Y * Y); public static Vector2Int zero => new Vector2Int(0, 0); public static Vector2Int u => new Vector2Int(0, 1); public static Vector2Int r => new Vector2Int(1, 0); public static Vector2Int d => new Vector2Int(0, -1); public static Vector2Int l => new Vector2Int(-1, 0); public static Vector2Int[] AllDirections => new Vector2Int[4] { u, r, d, l }; public static Vector2Int[] AllDirections8 => new Vector2Int[8] { u, r, d, l, u + r, r + d, d + l, l + u }; public static Vector2Int operator +(Vector2Int a, Vector2Int b) { return new Vector2Int(a.X + b.X, a.Y + b.Y); } public static Vector2Int operator -(Vector2Int a, Vector2Int b) { return new Vector2Int(a.X - b.X, a.Y - b.Y); } public static bool operator ==(Vector2Int a, Vector2Int b) { return a.X == b.X && a.Y == b.Y; } public static bool operator !=(Vector2Int a, Vector2Int b) { return a.X != b.X || a.Y != b.Y; } public static Vector2Int operator *(Vector2Int v, int n) { return new Vector2Int(v.X * n, v.Y * n); } public static Vector2Int operator *(int n, Vector2Int v) { return new Vector2Int(v.X * n, v.Y * n); } } struct Vector3Int { public Vector3Int(int x, int y, int z) { X = x; Y = y; Z = z; } public int X; public int Y; public int Z; public double Magnitude => Math.Sqrt(X * X + Y * Y + Z * Z); public static Vector3Int zero => new Vector3Int(0, 0, 0); public static Vector3Int u => new Vector3Int(0, 1, 0); public static Vector3Int r => new Vector3Int(1, 0, 0); public static Vector3Int d => new Vector3Int(0, -1, 0); public static Vector3Int l => new Vector3Int(-1, 0, 0); public static Vector3Int operator +(Vector3Int a, Vector3Int b) { return new Vector3Int(a.X + b.X, a.Y + b.Y, a.Z + b.Z); } public static Vector3Int operator -(Vector3Int a, Vector3Int b) { return new Vector3Int(a.X - b.X, a.Y - b.Y, a.Z - b.Z); } public static bool operator ==(Vector3Int a, Vector3Int b) { return a.X == b.X && a.Y == b.Y && a.Z == b.Z; } public static bool operator !=(Vector3Int a, Vector3Int b) { return a.X != b.X || a.Y != b.Y || a.Z != b.Z; } public static Vector3Int operator *(Vector3Int v, int n) { return new Vector3Int(v.X * n, v.Y * n, v.Z * n); } public static Vector3Int operator *(int n, Vector3Int v) { return new Vector3Int(v.X * n, v.Y * n, v.Z * n); } } #region Reader static Vector2Int ReadVec2Int { get { string[] s = Console.ReadLine().Split(' '); return new Vector2Int(int.Parse(s[0]), int.Parse(s[1])); } } static Vector2Int[] ReadVec2Ints(int n) { List<Vector2Int> list = new List<Vector2Int>(); for (int i = 0; i < n; ++i) { var ab = ReadInts; list.Add(new Vector2Int(ab[0], ab[1])); } return list.ToArray(); } static HashSet<Vector2Int> ReadVec2IntHash(int n) { HashSet<Vector2Int> hash = new HashSet<Vector2Int>(); for (int i = 0; i < n; ++i) { var ab = ReadInts; hash.Add(new Vector2Int(ab[0], ab[1])); } return hash; } static string ReadStr => Console.ReadLine(); static string[] ReadStrs => Console.ReadLine().Split(' '); static int ReadInt => Convert.ToInt32(Console.ReadLine()); static int[] ReadInts => Console.ReadLine().Split(' ').Select(s => Convert.ToInt32(s)).ToArray(); static long ReadLong => Convert.ToInt64(Console.ReadLine()); static long[] ReadLongs => Console.ReadLine().Split(' ').Select(s => Convert.ToInt64(s)).ToArray(); static long[,] ReLongMatrix(int r, int c) { var mat = new long[r, c]; for (int i = 0; i < r; ++i) { var x = ReadLongs; for (int j = 0; j < c; ++j) { mat[i, j] = x[j]; } } return mat; } static Tuple<string, string>[] ReTupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = ReadStrs; list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<long, long>[] ReTupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = ReadLongs; list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<int, int>[] ReadTupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = ReadInts; list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<double, double>[] ReTupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = ReadLongs; list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); } static Dictionary<int, HashSet<int>> ReAdjacencyList(int N, int M) { Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new HashSet<int>()); } for (int i = 0; i < M; ++i) { var ab = ReadInts; dict[ab[0]].Add(ab[1]); dict[ab[1]].Add(ab[0]); } return dict; } #endregion static void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } static long mod = (int)Pow(10, 9) + 7; }
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
2,051
8
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() { int N; int K; Multi(out N, out K); var ans = Math.Min(N % K, Math.Abs(N % K - K)); 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() { long N; long K; Multi(out N, out K); var ans = Math.Min(N % K, Math.Abs(N % K - K)); 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, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
1,530
4
using System; using System.Collections.Generic; using System.IO; using System.Linq; class C { static StreamWriter Out = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; static void Main(string[] args) { int N, K; Input(out N, out K); int min1 = N % K; int min2 = Math.Abs(min1 - K); Print(Math.Min(min1, min2)); Out.Flush(); } static T ChangeT<T>(string s) => (T)Convert.ChangeType(s, typeof(T)); static void Input<A>(out A a) { var words = Console.ReadLine().Split( new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries); a = ChangeT<A>(words[0]); } static void Input<A, B>(out A a, out B b) { var words = Console.ReadLine().Split( new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries); a = ChangeT<A>(words[0]); b = ChangeT<B>(words[1]); } static void Input<A, B, C>(out A a, out B b, out C c) { var words = Console.ReadLine().Split( new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries); a = ChangeT<A>(words[0]); b = ChangeT<B>(words[1]); c = ChangeT<C>(words[2]); } static void Input<A, B, C, D>(out A a, out B b, out C c, out D d) { var words = Console.ReadLine().Split( new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries); a = ChangeT<A>(words[0]); b = ChangeT<B>(words[1]); c = ChangeT<C>(words[2]); d = ChangeT<D>(words[3]); } static void Input<A, B, C, D, E>(out A a, out B b, out C c, out D d, out E e) { var words = Console.ReadLine().Split( new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries); a = ChangeT<A>(words[0]); b = ChangeT<B>(words[1]); c = ChangeT<C>(words[2]); d = ChangeT<D>(words[3]); e = ChangeT<E>(words[4]); } static void Input<A, B, C, D, E, F>(out A a, out B b, out C c, out D d, out E e, out F f) { var words = Console.ReadLine().Split( new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries); a = ChangeT<A>(words[0]); b = ChangeT<B>(words[1]); c = ChangeT<C>(words[2]); d = ChangeT<D>(words[3]); e = ChangeT<E>(words[4]); f = ChangeT<F>(words[5]); } static void Inputs<T>(out T[] array) { array = Console.ReadLine() .Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries) .Select(s => ChangeT<T>(s)) .ToArray(); } static void Print<T>(T s) => Out.WriteLine(s); static void Print<T>(params T[] s) => Out.WriteLine(string.Join(" ", s)); static void Print<T>(IEnumerable<T> e) => Out.WriteLine(string.Join(" ", e)); }
using System; using System.Collections.Generic; using System.IO; using System.Linq; class C { static StreamWriter Out = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; static void Main(string[] args) { long N, K; Input(out N, out K); long min1 = N % K; long min2 = Math.Abs(min1 - K); Print(Math.Min(min1, min2)); Out.Flush(); } static T ChangeT<T>(string s) => (T)Convert.ChangeType(s, typeof(T)); static void Input<A>(out A a) { var words = Console.ReadLine().Split( new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries); a = ChangeT<A>(words[0]); } static void Input<A, B>(out A a, out B b) { var words = Console.ReadLine().Split( new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries); a = ChangeT<A>(words[0]); b = ChangeT<B>(words[1]); } static void Input<A, B, C>(out A a, out B b, out C c) { var words = Console.ReadLine().Split( new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries); a = ChangeT<A>(words[0]); b = ChangeT<B>(words[1]); c = ChangeT<C>(words[2]); } static void Input<A, B, C, D>(out A a, out B b, out C c, out D d) { var words = Console.ReadLine().Split( new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries); a = ChangeT<A>(words[0]); b = ChangeT<B>(words[1]); c = ChangeT<C>(words[2]); d = ChangeT<D>(words[3]); } static void Input<A, B, C, D, E>(out A a, out B b, out C c, out D d, out E e) { var words = Console.ReadLine().Split( new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries); a = ChangeT<A>(words[0]); b = ChangeT<B>(words[1]); c = ChangeT<C>(words[2]); d = ChangeT<D>(words[3]); e = ChangeT<E>(words[4]); } static void Input<A, B, C, D, E, F>(out A a, out B b, out C c, out D d, out E e, out F f) { var words = Console.ReadLine().Split( new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries); a = ChangeT<A>(words[0]); b = ChangeT<B>(words[1]); c = ChangeT<C>(words[2]); d = ChangeT<D>(words[3]); e = ChangeT<E>(words[4]); f = ChangeT<F>(words[5]); } static void Inputs<T>(out T[] array) { array = Console.ReadLine() .Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries) .Select(s => ChangeT<T>(s)) .ToArray(); } static void Print<T>(T s) => Out.WriteLine(s); static void Print<T>(params T[] s) => Out.WriteLine(string.Join(" ", s)); static void Print<T>(IEnumerable<T> e) => Out.WriteLine(string.Join(" ", e)); }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
870
6
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main(string[] args) { int input = int.Parse(Console.ReadLine()); if (input <= 9) { Console.WriteLine(input); return; } List<double> list = new List<double>(); for (int i = 1; i <= 9; i++) { list.Add(i); } int count = 9; bool countbl = true; double ans = 0; while (countbl) { List<double> ketaList = new List<double>(); foreach (int ele in list) { int last = ele % 10; if (last == 0) { ketaList.Add(ele * 10); count++; if (count == input) { countbl = false; ans = ketaList[ketaList.Count() - 1]; break; } ketaList.Add(ele * 10 + 1); count++; if (count == input) { countbl = false; ans = ketaList[ketaList.Count() - 1]; break; } } else if (last == 9) { ketaList.Add(ele * 10 + 8); count++; if (count == input) { countbl = false; ans = ketaList[ketaList.Count() - 1]; break; } ketaList.Add(ele * 10 + 9); count++; if (count == input) { countbl = false; ans = ketaList[ketaList.Count() - 1]; break; } } else { ketaList.Add(ele * 10 + last - 1); count++; if (count == input) { countbl = false; ans = ketaList[ketaList.Count() - 1]; break; } ketaList.Add(ele * 10 + last); count++; if (count == input) { countbl = false; ans = ketaList[ketaList.Count() - 1]; break; } ketaList.Add(ele * 10 + last + 1); count++; if (count == input) { countbl = false; ans = ketaList[ketaList.Count() - 1]; break; } } } count++; list = new List<double>(ketaList); } Console.WriteLine(ans); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main(string[] args) { int input = int.Parse(Console.ReadLine()); if (input <= 9) { Console.WriteLine(input); return; } List<double> list = new List<double>(); for (int i = 1; i <= 9; i++) { list.Add(i); } int count = 9; bool countbl = true; double ans = 0; while (countbl) { List<double> ketaList = new List<double>(); foreach (double ele in list) { double last = ele % 10; if (last == 0) { ketaList.Add(ele * 10); count++; if (count == input) { countbl = false; ans = ketaList[ketaList.Count() - 1]; break; } ketaList.Add(ele * 10 + 1); count++; if (count == input) { countbl = false; ans = ketaList[ketaList.Count() - 1]; break; } } else if (last == 9) { ketaList.Add(ele * 10 + 8); count++; if (count == input) { countbl = false; ans = ketaList[ketaList.Count() - 1]; break; } ketaList.Add(ele * 10 + 9); count++; if (count == input) { countbl = false; ans = ketaList[ketaList.Count() - 1]; break; } } else { ketaList.Add(ele * 10 + last - 1); count++; if (count == input) { countbl = false; ans = ketaList[ketaList.Count() - 1]; break; } ketaList.Add(ele * 10 + last); count++; if (count == input) { countbl = false; ans = ketaList[ketaList.Count() - 1]; break; } ketaList.Add(ele * 10 + last + 1); count++; if (count == input) { countbl = false; ans = ketaList[ketaList.Count() - 1]; break; } } } list = new List<double>(ketaList); } Console.WriteLine(ans); } }
[["-", 8, 196, 0, 52, 8, 196, 0, 210, 39, 199], ["+", 8, 196, 0, 52, 8, 196, 0, 210, 39, 199], ["-", 0, 210, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 210, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 52, 8, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 52, 8, 196, 0, 1, 0, 223, 0, 29], ["-", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35]]
8
484
7
using System; using System.Collections.Generic; using System.Linq; using static System.Math; using static ABC161.D.Cin; using static ABC161.D.Util; using Pair = ABC161.D.VTuple<long, long>; using Graph = System.Collections.Generic.List<System.Collections.Generic.List<long>>; using System.Text; namespace ABC161 { public class D { public static void Write(int[] s, int depth) { string ans = ""; for (int i = 0; i <= depth; i++) { ans += s[i]; } Console.WriteLine(ans); Environment.Exit(0); } public static void Main(string[] args) { long K = rl; if (K <= 9) { Console.WriteLine(K); return; } int cnt = 9; int[] s = new int[20]; Action<int, int> rec = null; rec = (depth, max) => { if (depth == max) { cnt++; if (cnt == K) Write(s, depth); return; } for (int i = -1; i < 1; i++) { if (s[depth] + i < 0 || 10 <= s[depth] + i) continue; s[depth + 1] = s[depth] + i; rec(depth + 1, max); } }; for (int max = 1; max < 20; max++) { for (int i = 1; i <= 9; i++) { s[0] = i; rec(0, max); } } } public struct Mint : System.IComparable<Mint>, System.IEquatable<Mint> { public static readonly long MOD = (long)1e9 + 7; public long Value; public Mint(long a) { Value = a % MOD; if (Value < 0) Value += MOD; } static Mint i(long a) { return new Mint() { Value = a }; } public static Mint operator +(Mint a, Mint b) { long c = a.Value + b.Value; if (c > MOD) c -= MOD; return i(c); } public static Mint operator -(Mint a, Mint b) { long c = a.Value - b.Value; if (c < 0) c += MOD; return i(c); } public static Mint operator *(Mint a, Mint b) { long c = a.Value * b.Value; if (c > MOD) c %= MOD; return i(c); } public static Mint operator /(Mint a, Mint b) { return a * Inv(b); } public override bool Equals(object a) { return a is Mint && Value == ((Mint)a).Value; } public override int GetHashCode() { return Value.GetHashCode(); } public static implicit operator Mint(long a) { return new Mint(a); } public static explicit operator long(Mint a) { return a.Value; } public static Mint Pow(Mint a, long b) { if (b == 0) return new Mint(1); Mint c = Pow(a, b >> 1); c *= c; if ((b & 1) == 1) c *= a; return c; } public static Mint Inv(Mint a) { long b = a.Value; long c = MOD; long d = 1; long e = 0; while (c != 0) { long f = b / c; long g = e; e = d - f * e; d = g; long h = b; b = c; c = h - (f * c); } return new Mint(d); } public bool Equals(Mint a) { return Value == a.Value; } public int CompareTo(Mint a) { return Comparer<long>.Default.Compare(Value, a.Value); } } public struct VTuple<T1, T2> : System.IComparable<VTuple<T1, T2>>, System.IEquatable<VTuple<T1, T2>> { public T1 Item1; public T2 Item2; public T1 First { get { return Item1; } } public T2 Second { get { return Item2; } } public VTuple(T1 a, T2 b) { Item1 = a; Item2 = b; } public override bool Equals(object a) { return a is VTuple<T1, T2> && Equals((VTuple<T1, T2>)a); } public override int GetHashCode() { int a = Item1 != null ? Item1.GetHashCode() : 0; int b = Item2 != null ? Item2.GetHashCode() : 0; return HashHelpers.CombineHashCodes(a, b); } public bool Equals(VTuple<T1, T2> a) { return EqualityComparer<T1>.Default.Equals(Item1, a.Item1) && EqualityComparer<T2>.Default.Equals(Item2, a.Item2); } public int CompareTo(VTuple<T1, T2> a) { int b = Comparer<T1>.Default.Compare(Item1, a.Item1); if (b != 0) return b; return Comparer<T2>.Default.Compare(Item2, a.Item2); } } public struct VTuple<T1, T2, T3> : System.IComparable<VTuple<T1, T2, T3>>, System.IEquatable<VTuple<T1, T2, T3>> { public T1 Item1; public T2 Item2; public T3 Item3; public VTuple(T1 a, T2 b, T3 c) { Item1 = a; Item2 = b; Item3 = c; } public override bool Equals(object a) { return a is VTuple<T1, T2, T3> && Equals((VTuple<T1, T2, T3>)a); } public override int GetHashCode() { int a = Item1 != null ? Item1.GetHashCode() : 0; int b = Item2 != null ? Item2.GetHashCode() : 0; int c = Item3 != null ? Item3.GetHashCode() : 0; return HashHelpers.CombineHashCodes(a, b, c); } public bool Equals(VTuple<T1, T2, T3> a) { return EqualityComparer<T1>.Default.Equals(Item1, a.Item1) && EqualityComparer<T2>.Default.Equals(Item2, a.Item2) && EqualityComparer<T3>.Default.Equals(Item3, a.Item3); } public int CompareTo(VTuple<T1, T2, T3> a) { int b = Comparer<T1>.Default.Compare(Item1, a.Item1); if (b != 0) return b; b = Comparer<T2>.Default.Compare(Item2, a.Item2); if (b != 0) return b; return Comparer<T3>.Default.Compare(Item3, a.Item3); } } public struct VTuple<T1, T2, T3, T4> : System.IComparable<VTuple<T1, T2, T3, T4>>, System.IEquatable<VTuple<T1, T2, T3, T4>> { public T1 Item1; public T2 Item2; public T3 Item3; public T4 Item4; public VTuple(T1 a, T2 b, T3 c, T4 d) { Item1 = a; Item2 = b; Item3 = c; Item4 = d; } public override bool Equals(object a) { return a is VTuple<T1, T2, T3, T4> && Equals((VTuple<T1, T2, T3, T4>)a); } public override int GetHashCode() { int a = Item1 != null ? Item1.GetHashCode() : 0; int b = Item2 != null ? Item2.GetHashCode() : 0; int c = Item3 != null ? Item3.GetHashCode() : 0; int d = Item3 != null ? Item4.GetHashCode() : 0; return HashHelpers.CombineHashCodes(a, b, c, d); } public bool Equals(VTuple<T1, T2, T3, T4> a) { return EqualityComparer<T1>.Default.Equals(Item1, a.Item1) && EqualityComparer<T2>.Default.Equals(Item2, a.Item2) && EqualityComparer<T3>.Default.Equals(Item3, a.Item3) && EqualityComparer<T4>.Default.Equals(Item4, a.Item4); } public int CompareTo(VTuple<T1, T2, T3, T4> a) { int b = Comparer<T1>.Default.Compare(Item1, a.Item1); if (b != 0) return b; b = Comparer<T2>.Default.Compare(Item2, a.Item2); if (b != 0) return b; b = Comparer<T3>.Default.Compare(Item3, a.Item3); if (b != 0) return b; return Comparer<T4>.Default.Compare(Item4, a.Item4); } } public static class HashHelpers { public static readonly int RandomSeed = new System.Random().Next(int.MinValue, int.MaxValue); public static int Combine(int a, int b) { uint c = ((uint)a << 5) | ((uint)a >> 27); return ((int)c + a) ^ b; } public static int CombineHashCodes(int a, int b) { return Combine(Combine(RandomSeed, a), b); } public static int CombineHashCodes(int a, int b, int c) { return Combine(CombineHashCodes(a, b), c); } public static int CombineHashCodes(int a, int b, int c, int d) { return Combine(CombineHashCodes(a, b, c), d); } } public class HashMap<K, V> : System.Collections.Generic.Dictionary<K, V> { V i; static Func<V> j = System.Linq.Expressions.Expression .Lambda<Func<V>>(System.Linq.Expressions.Expression.New(typeof(V))) .Compile(); public HashMap() {} public HashMap(V a) { i = a; } new public V this[K a] { get { V b; if (TryGetValue(a, out b)) return b; else return base[a] = i != null ? i : j(); } set { base[a] = value; } } } public static class Util { public static readonly long INF = (long)1e17; public readonly static long MOD = (long)1e9 + 7; public readonly static int[] DXY4 = { 0, 1, 0, -1, 0 }; public readonly static int[] DXY8 = { 1, 1, 0, 1, -1, 0, -1, -1, 1 }; public static void DontAutoFlush() { var a = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(a); } public static void Flush() { Console.Out.Flush(); } public static T[] Sort<T>(T[] a) { Array.Sort<T>(a); return a; } public static T[] SortDecend<T>(T[] a) { Array.Sort<T>(a); Array.Reverse(a); return a; } public static void Swap<T>(ref T a, ref T b) { T c = a; a = b; b = c; } public static long GCD(long a, long b) { while (b != 0) { long c = a; a = b; b = c % b; } return a; } public static long LCM(long a, long b) { if (a == 0 || b == 0) return 0; return a * b / GCD(a, b); } public static void ChMax(ref long a, long b) { if (a < b) a = b; } public static void ChMin(ref long a, long b) { if (a > b) a = b; } public static void ChMax(ref int a, int b) { if (a < b) a = b; } public static void ChMin(ref int a, int b) { if (a > b) a = b; } public static void FillArray<T>(T[] a, T b) { int c = a.Length; for (int d = 0; d < c; d++) a[d] = b; } public static void FillArray<T>(T[,] a, T b) { int c = a.GetLength(0); int d = a.GetLength(1); for (int e = 0; e < c; e++) for (int f = 0; f < d; f++) { a[e, f] = b; } } public static void FillArray<T>(T[,,] a, T b) { int c = a.GetLength(0); int d = a.GetLength(1); int e = a.GetLength(2); for (int f = 0; f < c; f++) for (int g = 0; g < d; g++) { for (int h = 0; h < e; h++) { a[f, g, h] = b; } } } public static long[] Accumulate(long[] a) { long[] b = new long[a.Length + 1]; for (int c = 0; c < a.Length; c++) b[c + 1] = b[c] + a[c]; return b; } public static double[] Accumulate(double[] a) { double[] b = new double[a.Length + 1]; for (int c = 0; c < a.Length; c++) b[c + 1] = b[c] + a[c]; return b; } } public static class Cin { public static int ri { get { return ReadInt(); } } public static int[] ria { get { return ReadIntArray(); } } public static long rl { get { return ReadLong(); } } public static long[] rla { get { return ReadLongArray(); } } public static double rd { get { return ReadDouble(); } } public static double[] rda { get { return ReadDoubleArray(); } } public static string rs { get { return ReadString(); } } public static string[] rsa { get { return ReadStringArray(); } } public static int ReadInt() { return int.Parse(i()); } public static long ReadLong() { return long.Parse(i()); } public static double ReadDouble() { return double.Parse(i()); } public static string ReadString() { return i(); } public static int[] ReadIntArray() { g = null; return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long[] ReadLongArray() { g = null; return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static double[] ReadDoubleArray() { g = null; return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse); } public static string[] ReadStringArray() { g = null; return Console.ReadLine().Split(' '); } public static void ReadCol(out long[] a, long b) { a = new long[b]; for (int c = 0; c < b; c++) a[c] = ReadLong(); } public static void ReadCols(out long[] a, out long[] b, long c) { a = new long[c]; b = new long[c]; for (int d = 0; d < c; d++) { a[d] = ReadLong(); b[d] = ReadLong(); } } public static void ReadCols(out long[] a, out long[] b, out long[] c, long d) { a = new long[d]; b = new long[d]; c = new long[d]; for (int e = 0; e < d; e++) { a[e] = ReadLong(); b[e] = ReadLong(); c[e] = ReadLong(); } } public static int[,] ReadIntTable(int a, int b) { g = null; int[,] c = new int[a, b]; for (int d = 0; d < a; d++) for (int e = 0; e < b; e++) { c[d, e] = ReadInt(); } return c; } public static long[,] ReadLongTable(long a, long b) { g = null; long[,] c = new long[a, b]; for (int d = 0; d < a; d++) for (int e = 0; e < b; e++) { c[d, e] = ReadLong(); } return c; } public static char[,] ReadCharTable(int a, int b) { g = null; char[,] c = new char[a, b]; for (int d = 0; d < a; d++) { var e = ReadString(); for (int f = 0; f < b; f++) c[d, f] = e[f]; } return c; } static string[] g; static int h; static string i() { if (g == null || g.Length <= h) { g = Console.ReadLine().Split(' '); h = 0; } return g[h++]; } } } }
using System; using System.Collections.Generic; using System.Linq; using static System.Math; using static ABC161.D.Cin; using static ABC161.D.Util; using Pair = ABC161.D.VTuple<long, long>; using Graph = System.Collections.Generic.List<System.Collections.Generic.List<long>>; using System.Text; namespace ABC161 { public class D { public static void Write(int[] s, int depth) { string ans = ""; for (int i = 0; i <= depth; i++) { ans += s[i]; } Console.WriteLine(ans); Environment.Exit(0); } public static void Main(string[] args) { long K = rl; if (K <= 9) { Console.WriteLine(K); return; } int cnt = 9; int[] s = new int[20]; Action<int, int> rec = null; rec = (depth, max) => { if (depth == max) { cnt++; if (cnt == K) Write(s, depth); return; } for (int i = -1; i <= 1; i++) { if (s[depth] + i < 0 || 10 <= s[depth] + i) continue; s[depth + 1] = s[depth] + i; rec(depth + 1, max); } }; for (int max = 1; max < 20; max++) { for (int i = 1; i <= 9; i++) { s[0] = i; rec(0, max); } } } public struct Mint : System.IComparable<Mint>, System.IEquatable<Mint> { public static readonly long MOD = (long)1e9 + 7; public long Value; public Mint(long a) { Value = a % MOD; if (Value < 0) Value += MOD; } static Mint i(long a) { return new Mint() { Value = a }; } public static Mint operator +(Mint a, Mint b) { long c = a.Value + b.Value; if (c > MOD) c -= MOD; return i(c); } public static Mint operator -(Mint a, Mint b) { long c = a.Value - b.Value; if (c < 0) c += MOD; return i(c); } public static Mint operator *(Mint a, Mint b) { long c = a.Value * b.Value; if (c > MOD) c %= MOD; return i(c); } public static Mint operator /(Mint a, Mint b) { return a * Inv(b); } public override bool Equals(object a) { return a is Mint && Value == ((Mint)a).Value; } public override int GetHashCode() { return Value.GetHashCode(); } public static implicit operator Mint(long a) { return new Mint(a); } public static explicit operator long(Mint a) { return a.Value; } public static Mint Pow(Mint a, long b) { if (b == 0) return new Mint(1); Mint c = Pow(a, b >> 1); c *= c; if ((b & 1) == 1) c *= a; return c; } public static Mint Inv(Mint a) { long b = a.Value; long c = MOD; long d = 1; long e = 0; while (c != 0) { long f = b / c; long g = e; e = d - f * e; d = g; long h = b; b = c; c = h - (f * c); } return new Mint(d); } public bool Equals(Mint a) { return Value == a.Value; } public int CompareTo(Mint a) { return Comparer<long>.Default.Compare(Value, a.Value); } } public struct VTuple<T1, T2> : System.IComparable<VTuple<T1, T2>>, System.IEquatable<VTuple<T1, T2>> { public T1 Item1; public T2 Item2; public T1 First { get { return Item1; } } public T2 Second { get { return Item2; } } public VTuple(T1 a, T2 b) { Item1 = a; Item2 = b; } public override bool Equals(object a) { return a is VTuple<T1, T2> && Equals((VTuple<T1, T2>)a); } public override int GetHashCode() { int a = Item1 != null ? Item1.GetHashCode() : 0; int b = Item2 != null ? Item2.GetHashCode() : 0; return HashHelpers.CombineHashCodes(a, b); } public bool Equals(VTuple<T1, T2> a) { return EqualityComparer<T1>.Default.Equals(Item1, a.Item1) && EqualityComparer<T2>.Default.Equals(Item2, a.Item2); } public int CompareTo(VTuple<T1, T2> a) { int b = Comparer<T1>.Default.Compare(Item1, a.Item1); if (b != 0) return b; return Comparer<T2>.Default.Compare(Item2, a.Item2); } } public struct VTuple<T1, T2, T3> : System.IComparable<VTuple<T1, T2, T3>>, System.IEquatable<VTuple<T1, T2, T3>> { public T1 Item1; public T2 Item2; public T3 Item3; public VTuple(T1 a, T2 b, T3 c) { Item1 = a; Item2 = b; Item3 = c; } public override bool Equals(object a) { return a is VTuple<T1, T2, T3> && Equals((VTuple<T1, T2, T3>)a); } public override int GetHashCode() { int a = Item1 != null ? Item1.GetHashCode() : 0; int b = Item2 != null ? Item2.GetHashCode() : 0; int c = Item3 != null ? Item3.GetHashCode() : 0; return HashHelpers.CombineHashCodes(a, b, c); } public bool Equals(VTuple<T1, T2, T3> a) { return EqualityComparer<T1>.Default.Equals(Item1, a.Item1) && EqualityComparer<T2>.Default.Equals(Item2, a.Item2) && EqualityComparer<T3>.Default.Equals(Item3, a.Item3); } public int CompareTo(VTuple<T1, T2, T3> a) { int b = Comparer<T1>.Default.Compare(Item1, a.Item1); if (b != 0) return b; b = Comparer<T2>.Default.Compare(Item2, a.Item2); if (b != 0) return b; return Comparer<T3>.Default.Compare(Item3, a.Item3); } } public struct VTuple<T1, T2, T3, T4> : System.IComparable<VTuple<T1, T2, T3, T4>>, System.IEquatable<VTuple<T1, T2, T3, T4>> { public T1 Item1; public T2 Item2; public T3 Item3; public T4 Item4; public VTuple(T1 a, T2 b, T3 c, T4 d) { Item1 = a; Item2 = b; Item3 = c; Item4 = d; } public override bool Equals(object a) { return a is VTuple<T1, T2, T3, T4> && Equals((VTuple<T1, T2, T3, T4>)a); } public override int GetHashCode() { int a = Item1 != null ? Item1.GetHashCode() : 0; int b = Item2 != null ? Item2.GetHashCode() : 0; int c = Item3 != null ? Item3.GetHashCode() : 0; int d = Item3 != null ? Item4.GetHashCode() : 0; return HashHelpers.CombineHashCodes(a, b, c, d); } public bool Equals(VTuple<T1, T2, T3, T4> a) { return EqualityComparer<T1>.Default.Equals(Item1, a.Item1) && EqualityComparer<T2>.Default.Equals(Item2, a.Item2) && EqualityComparer<T3>.Default.Equals(Item3, a.Item3) && EqualityComparer<T4>.Default.Equals(Item4, a.Item4); } public int CompareTo(VTuple<T1, T2, T3, T4> a) { int b = Comparer<T1>.Default.Compare(Item1, a.Item1); if (b != 0) return b; b = Comparer<T2>.Default.Compare(Item2, a.Item2); if (b != 0) return b; b = Comparer<T3>.Default.Compare(Item3, a.Item3); if (b != 0) return b; return Comparer<T4>.Default.Compare(Item4, a.Item4); } } public static class HashHelpers { public static readonly int RandomSeed = new System.Random().Next(int.MinValue, int.MaxValue); public static int Combine(int a, int b) { uint c = ((uint)a << 5) | ((uint)a >> 27); return ((int)c + a) ^ b; } public static int CombineHashCodes(int a, int b) { return Combine(Combine(RandomSeed, a), b); } public static int CombineHashCodes(int a, int b, int c) { return Combine(CombineHashCodes(a, b), c); } public static int CombineHashCodes(int a, int b, int c, int d) { return Combine(CombineHashCodes(a, b, c), d); } } public class HashMap<K, V> : System.Collections.Generic.Dictionary<K, V> { V i; static Func<V> j = System.Linq.Expressions.Expression .Lambda<Func<V>>(System.Linq.Expressions.Expression.New(typeof(V))) .Compile(); public HashMap() {} public HashMap(V a) { i = a; } new public V this[K a] { get { V b; if (TryGetValue(a, out b)) return b; else return base[a] = i != null ? i : j(); } set { base[a] = value; } } } public static class Util { public static readonly long INF = (long)1e17; public readonly static long MOD = (long)1e9 + 7; public readonly static int[] DXY4 = { 0, 1, 0, -1, 0 }; public readonly static int[] DXY8 = { 1, 1, 0, 1, -1, 0, -1, -1, 1 }; public static void DontAutoFlush() { var a = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(a); } public static void Flush() { Console.Out.Flush(); } public static T[] Sort<T>(T[] a) { Array.Sort<T>(a); return a; } public static T[] SortDecend<T>(T[] a) { Array.Sort<T>(a); Array.Reverse(a); return a; } public static void Swap<T>(ref T a, ref T b) { T c = a; a = b; b = c; } public static long GCD(long a, long b) { while (b != 0) { long c = a; a = b; b = c % b; } return a; } public static long LCM(long a, long b) { if (a == 0 || b == 0) return 0; return a * b / GCD(a, b); } public static void ChMax(ref long a, long b) { if (a < b) a = b; } public static void ChMin(ref long a, long b) { if (a > b) a = b; } public static void ChMax(ref int a, int b) { if (a < b) a = b; } public static void ChMin(ref int a, int b) { if (a > b) a = b; } public static void FillArray<T>(T[] a, T b) { int c = a.Length; for (int d = 0; d < c; d++) a[d] = b; } public static void FillArray<T>(T[,] a, T b) { int c = a.GetLength(0); int d = a.GetLength(1); for (int e = 0; e < c; e++) for (int f = 0; f < d; f++) { a[e, f] = b; } } public static void FillArray<T>(T[,,] a, T b) { int c = a.GetLength(0); int d = a.GetLength(1); int e = a.GetLength(2); for (int f = 0; f < c; f++) for (int g = 0; g < d; g++) { for (int h = 0; h < e; h++) { a[f, g, h] = b; } } } public static long[] Accumulate(long[] a) { long[] b = new long[a.Length + 1]; for (int c = 0; c < a.Length; c++) b[c + 1] = b[c] + a[c]; return b; } public static double[] Accumulate(double[] a) { double[] b = new double[a.Length + 1]; for (int c = 0; c < a.Length; c++) b[c + 1] = b[c] + a[c]; return b; } } public static class Cin { public static int ri { get { return ReadInt(); } } public static int[] ria { get { return ReadIntArray(); } } public static long rl { get { return ReadLong(); } } public static long[] rla { get { return ReadLongArray(); } } public static double rd { get { return ReadDouble(); } } public static double[] rda { get { return ReadDoubleArray(); } } public static string rs { get { return ReadString(); } } public static string[] rsa { get { return ReadStringArray(); } } public static int ReadInt() { return int.Parse(i()); } public static long ReadLong() { return long.Parse(i()); } public static double ReadDouble() { return double.Parse(i()); } public static string ReadString() { return i(); } public static int[] ReadIntArray() { g = null; return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long[] ReadLongArray() { g = null; return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static double[] ReadDoubleArray() { g = null; return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse); } public static string[] ReadStringArray() { g = null; return Console.ReadLine().Split(' '); } public static void ReadCol(out long[] a, long b) { a = new long[b]; for (int c = 0; c < b; c++) a[c] = ReadLong(); } public static void ReadCols(out long[] a, out long[] b, long c) { a = new long[c]; b = new long[c]; for (int d = 0; d < c; d++) { a[d] = ReadLong(); b[d] = ReadLong(); } } public static void ReadCols(out long[] a, out long[] b, out long[] c, long d) { a = new long[d]; b = new long[d]; c = new long[d]; for (int e = 0; e < d; e++) { a[e] = ReadLong(); b[e] = ReadLong(); c[e] = ReadLong(); } } public static int[,] ReadIntTable(int a, int b) { g = null; int[,] c = new int[a, b]; for (int d = 0; d < a; d++) for (int e = 0; e < b; e++) { c[d, e] = ReadInt(); } return c; } public static long[,] ReadLongTable(long a, long b) { g = null; long[,] c = new long[a, b]; for (int d = 0; d < a; d++) for (int e = 0; e < b; e++) { c[d, e] = ReadLong(); } return c; } public static char[,] ReadCharTable(int a, int b) { g = null; char[,] c = new char[a, b]; for (int d = 0; d < a; d++) { var e = ReadString(); for (int f = 0; f < b; f++) c[d, f] = e[f]; } return c; } static string[] g; static int h; static string i() { if (g == null || g.Length <= h) { g = Console.ReadLine().Split(' '); h = 0; } return g[h++]; } } } }
[["-", 12, 218, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 12, 218, 8, 196, 0, 7, 15, 16, 17, 19]]
8
3,784
2
using System; using System.Collections.Generic; namespace abc161 { class Program { static void Main() { var n = int.Parse(Console.ReadLine()); var lun = new List<int>(); lun.Add(0); for (var i = 0; i < n; ++i) { Inc(lun, 0); } Write(lun); } static void Inc(List<int> lun, int level) { if (level < lun.Count - 1 && lun[level] > lun[level + 1]) { // 判定を上位に Inc(lun, level + 1); return; } if (level == lun.Count - 1 && lun[level] == 9) { // くりあげ lun[level] = 0; lun.Add(1); } else if (lun[level] == 9) { // 判定を上位に lun[level] = 0; Inc(lun, level + 1); } else { ++lun[level]; } for (var l = level - 1; l >= 0; --l) { lun[l] = 0 > (lun[l + 1] - 1) ? 0 : lun[l + 1] - 1; } } static void Write(List<int> lun) { for (var l = lun.Count - 1; l >= 0; --l) { Console.Write(lun[l] + " "); } Console.WriteLine(""); } } }
using System; using System.Collections.Generic; namespace abc161 { class Program { static void Main() { var n = int.Parse(Console.ReadLine()); var lun = new List<int>(); lun.Add(0); for (var i = 0; i < n; ++i) { Inc(lun, 0); } Write(lun); } static void Inc(List<int> lun, int level) { if (level < lun.Count - 1 && lun[level] > lun[level + 1]) { // 判定を上位に Inc(lun, level + 1); return; } if (level == lun.Count - 1 && lun[level] == 9) { // くりあげ lun[level] = 0; lun.Add(1); } else if (lun[level] == 9) { // 判定を上位に lun[level] = 0; Inc(lun, level + 1); } else { ++lun[level]; } for (var l = level - 1; l >= 0; --l) { lun[l] = 0 > (lun[l + 1] - 1) ? 0 : lun[l + 1] - 1; } } static void Write(List<int> lun) { for (var l = lun.Count - 1; l >= 0; --l) { Console.Write(lun[l]); } Console.WriteLine(""); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 3, 4, 0, 28, 0, 16, 12, 5, 0, 62], ["-", 3, 4, 0, 28, 0, 16, 12, 5, 0, 222]]
8
309
4